/* * We return the user space TLS data ptr as sys-call return code * Ideally it should be copy to user. * However we can cheat by the fact that some sys-calls do return * absurdly high values * Since the tls dat aptr is not going to be in range of 0xFFFF_xxxx * it won't be considered a sys-call error * and it will be loads better than copy-to-user, which is a definite * D-TLB Miss
*/
SYSCALL_DEFINE0(arc_gettls)
{ return task_thread_info(current)->thr_ptr;
}
SYSCALL_DEFINE3(arc_usr_cmpxchg, int __user *, uaddr, int, expected, int, new)
{ struct pt_regs *regs = current_pt_regs();
u32 uval; int ret;
/* * This is only for old cores lacking LLOCK/SCOND, which by definition * can't possibly be SMP. Thus doesn't need to be SMP safe. * And this also helps reduce the overhead for serializing in * the UP case
*/
WARN_ON_ONCE(IS_ENABLED(CONFIG_SMP));
/* Z indicates to userspace if operation succeeded */
regs->status32 &= ~STATUS_Z_MASK;
ret = access_ok(uaddr, sizeof(*uaddr)); if (!ret) goto fail;
again:
preempt_disable();
ret = __get_user(uval, uaddr); if (ret) goto fault;
if (uval != expected) goto out;
ret = __put_user(new, uaddr); if (ret) goto fault;
regs->status32 |= STATUS_Z_MASK;
out:
preempt_enable(); return uval;
fault:
preempt_enable();
if (unlikely(ret != -EFAULT)) goto fail;
mmap_read_lock(current->mm);
ret = fixup_user_fault(current->mm, (unsignedlong) uaddr,
FAULT_FLAG_WRITE, NULL);
mmap_read_unlock(current->mm);
__asm__ __volatile__( "sleep %0 \n"
:
:"I"(arg)); /* can't be "r" has to be embedded const */
raw_local_irq_disable();
}
#else/* ARC700 */
void arch_cpu_idle(void)
{ /* sleep, but enable both set E1/E2 (levels of interrupts) before committing */
__asm__ __volatile__("sleep 0x3 \n");
raw_local_irq_disable();
}
#endif
asmlinkage void ret_from_fork(void);
/* * Copy architecture-specific thread state * * Layout of Child kernel mode stack as setup at the end of this function is * * | ... | * | ... | * | unused | * | | * ------------------ * | r25 | <==== top of Stack (thread_info.ksp) * ~ ~ * | --to-- | (CALLEE Regs of kernel mode) * | r13 | * ------------------ * | fp | * | blink | @ret_from_fork * ------------------ * | | * ~ ~ * ~ ~ * | | * ------------------ * | r12 | * ~ ~ * | --to-- | (scratch Regs of user mode) * | r0 | * ------------------ * | SP | * | orig_r0 | * | event/ECR | * ------------------ <===== END of PAGE
*/ int copy_thread(struct task_struct *p, conststruct kernel_clone_args *args)
{
u64 clone_flags = args->flags; unsignedlong usp = args->stack; unsignedlong tls = args->tls; struct pt_regs *c_regs; /* child's pt_regs */ unsignedlong *childksp; /* to unwind out of __switch_to() */ struct callee_regs *c_callee; /* child's callee regs */ struct callee_regs *parent_callee; /* paren't callee */ struct pt_regs *regs = current_pt_regs();
/* Mark the specific anchors to begin with (see pic above) */
c_regs = task_pt_regs(p);
childksp = (unsignedlong *)c_regs - 2; /* 2 words for FP/BLINK */
c_callee = ((struct callee_regs *)childksp) - 1;
/* * __switch_to() uses thread_info.ksp to start unwinding stack * For kernel threads we don't need to create callee regs, the * stack layout nevertheless needs to remain the same. * Also, since __switch_to anyways unwinds callee regs, we use * this to populate kernel thread entry-pt/args into callee regs, * so that ret_from_kernel_thread() becomes simpler.
*/
task_thread_info(p)->ksp = (unsignedlong)c_callee; /* THREAD_INFO_KSP */
/* __switch_to expects FP(0), BLINK(return addr) at top of stack */
childksp[0] = 0; /* for POP fp */
childksp[1] = (unsignedlong)ret_from_fork; /* for POP blink */
if (unlikely(clone_flags & CLONE_SETTLS)) { /* * set task's userland tls data ptr from 4th arg * clone C-lib call is difft from clone sys-call
*/
task_thread_info(p)->thr_ptr = tls;
} else { /* Normal fork case: set parent's TLS ptr in child */
task_thread_info(p)->thr_ptr =
task_thread_info(current)->thr_ptr;
}
/* * setup usermode thread pointer #1: * when child is picked by scheduler, __switch_to() uses @c_callee to * populate usermode callee regs: this works (despite being in a kernel * function) since special return path for child @ret_from_fork() * ensures those regs are not clobbered all the way to RTIE to usermode
*/
c_callee->r25 = task_thread_info(p)->thr_ptr;
return 0;
}
/* * Do necessary setup to start up a new user task
*/ void start_thread(struct pt_regs *regs, unsignedlong pc, unsignedlong usp)
{
regs->sp = usp;
regs->ret = pc;
/* * [U]ser Mode bit set * [L] ZOL loop inhibited to begin with - cleared by a LP insn * Interrupts enabled
*/
regs->status32 = STATUS_U_MASK | STATUS_L_MASK | ISA_INIT_STATUS_BITS;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.