Apply some style(9) to Linuxulator linux_sysvec.c comments

This commit is contained in:
emaste 2018-03-13 00:40:05 +00:00
parent c303c68d6a
commit bc4d21ce60
3 changed files with 73 additions and 179 deletions

View File

@ -101,10 +101,9 @@ SYSCTL_PROC(_compat_linux, OID_AUTO, debug,
#endif #endif
/* /*
* Allow the this functions to use the ldebug() facility * Allow the sendsig functions to use the ldebug() facility even though they
* even though they are not syscalls themselves. Map them * are not syscalls themselves. Map them to syscall 0. This is slightly less
* to syscall 0. This is slightly less bogus than using * bogus than using ldebug(sigreturn).
* ldebug(sigreturn).
*/ */
#define LINUX_SYS_linux_rt_sendsig 0 #define LINUX_SYS_linux_rt_sendsig 0
@ -253,8 +252,7 @@ linux_set_syscall_retval(struct thread *td, int error)
/* /*
* On Linux only %rcx and %r11 values are not preserved across * On Linux only %rcx and %r11 values are not preserved across
* the syscall. * the syscall. So, do not clobber %rdx and %r10.
* So, do not clobber %rdx and %r10
*/ */
td->td_retval[1] = frame->tf_rdx; td->td_retval[1] = frame->tf_rdx;
frame->tf_r10 = frame->tf_rcx; frame->tf_r10 = frame->tf_rcx;
@ -335,9 +333,7 @@ linux_copyout_strings(struct image_params *imgp)
size_t execpath_len; size_t execpath_len;
struct proc *p; struct proc *p;
/* /* Calculate string base and vector table pointers. */
* Calculate string base and vector table pointers.
*/
if (imgp->execpath != NULL && imgp->auxargs != NULL) if (imgp->execpath != NULL && imgp->auxargs != NULL)
execpath_len = strlen(imgp->execpath) + 1; execpath_len = strlen(imgp->execpath) + 1;
else else
@ -345,7 +341,7 @@ linux_copyout_strings(struct image_params *imgp)
p = imgp->proc; p = imgp->proc;
arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings; arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
destp = (caddr_t)arginfo - SPARE_USRSPACE - destp = (caddr_t)arginfo - SPARE_USRSPACE -
roundup(sizeof(canary), sizeof(char *)) - roundup(sizeof(canary), sizeof(char *)) -
roundup(execpath_len, sizeof(char *)) - roundup(execpath_len, sizeof(char *)) -
roundup(ARG_MAX - imgp->args->stringspace, sizeof(char *)); roundup(ARG_MAX - imgp->args->stringspace, sizeof(char *));
@ -355,19 +351,14 @@ linux_copyout_strings(struct image_params *imgp)
copyout(imgp->execpath, (void *)imgp->execpathp, execpath_len); copyout(imgp->execpath, (void *)imgp->execpathp, execpath_len);
} }
/* /* Prepare the canary for SSP. */
* Prepare the canary for SSP.
*/
arc4rand(canary, sizeof(canary), 0); arc4rand(canary, sizeof(canary), 0);
imgp->canary = (uintptr_t)arginfo - imgp->canary = (uintptr_t)arginfo -
roundup(execpath_len, sizeof(char *)) - roundup(execpath_len, sizeof(char *)) -
roundup(sizeof(canary), sizeof(char *)); roundup(sizeof(canary), sizeof(char *));
copyout(canary, (void *)imgp->canary, sizeof(canary)); copyout(canary, (void *)imgp->canary, sizeof(canary));
/* /* If we have a valid auxargs ptr, prepare some room on the stack. */
* If we have a valid auxargs ptr, prepare some room
* on the stack.
*/
if (imgp->auxargs) { if (imgp->auxargs) {
/* /*
* 'AT_COUNT*2' is size for the ELF Auxargs data. This is for * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
@ -393,29 +384,21 @@ linux_copyout_strings(struct image_params *imgp)
imgp->args->envc + 2) * sizeof(char *)); imgp->args->envc + 2) * sizeof(char *));
} }
/* /* vectp also becomes our initial stack base. */
* vectp also becomes our initial stack base
*/
stack_base = (register_t *)vectp; stack_base = (register_t *)vectp;
stringp = imgp->args->begin_argv; stringp = imgp->args->begin_argv;
argc = imgp->args->argc; argc = imgp->args->argc;
envc = imgp->args->envc; envc = imgp->args->envc;
/* /* Copy out strings - arguments and environment. */
* Copy out strings - arguments and environment.
*/
copyout(stringp, destp, ARG_MAX - imgp->args->stringspace); copyout(stringp, destp, ARG_MAX - imgp->args->stringspace);
/* /* Fill in "ps_strings" struct for ps, w, etc. */
* Fill in "ps_strings" struct for ps, w, etc.
*/
suword(&arginfo->ps_argvstr, (long)(intptr_t)vectp); suword(&arginfo->ps_argvstr, (long)(intptr_t)vectp);
suword(&arginfo->ps_nargvstr, argc); suword(&arginfo->ps_nargvstr, argc);
/* /* Fill in argument portion of vector table. */
* Fill in argument portion of vector table.
*/
for (; argc > 0; --argc) { for (; argc > 0; --argc) {
suword(vectp++, (long)(intptr_t)destp); suword(vectp++, (long)(intptr_t)destp);
while (*stringp++ != 0) while (*stringp++ != 0)
@ -423,15 +406,13 @@ linux_copyout_strings(struct image_params *imgp)
destp++; destp++;
} }
/* a null vector table pointer separates the argp's from the envp's */ /* A null vector table pointer separates the argp's from the envp's. */
suword(vectp++, 0); suword(vectp++, 0);
suword(&arginfo->ps_envstr, (long)(intptr_t)vectp); suword(&arginfo->ps_envstr, (long)(intptr_t)vectp);
suword(&arginfo->ps_nenvstr, envc); suword(&arginfo->ps_nenvstr, envc);
/* /* Fill in environment portion of vector table. */
* Fill in environment portion of vector table.
*/
for (; envc > 0; --envc) { for (; envc > 0; --envc) {
suword(vectp++, (long)(intptr_t)destp); suword(vectp++, (long)(intptr_t)destp);
while (*stringp++ != 0) while (*stringp++ != 0)
@ -439,7 +420,7 @@ linux_copyout_strings(struct image_params *imgp)
destp++; destp++;
} }
/* end of vector table is a null pointer */ /* The end of the vector table is a null pointer. */
suword(vectp, 0); suword(vectp, 0);
return (stack_base); return (stack_base);
} }
@ -681,12 +662,10 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
regs->tf_rdx = (register_t)&sfp->sf_sc; /* arg 3 in %rdx */ regs->tf_rdx = (register_t)&sfp->sf_sc; /* arg 3 in %rdx */
sf.sf_handler = catcher; sf.sf_handler = catcher;
/* Fill in POSIX parts */ /* Fill in POSIX parts. */
ksiginfo_to_lsiginfo(ksi, &sf.sf_si, sig); ksiginfo_to_lsiginfo(ksi, &sf.sf_si, sig);
/* /* Copy the sigframe out to the user's stack. */
* Copy the sigframe out to the user's stack.
*/
if (copyout(&sf, sfp, sizeof(*sfp)) != 0) { if (copyout(&sf, sfp, sizeof(*sfp)) != 0) {
#ifdef DEBUG #ifdef DEBUG
printf("process %ld has trashed its stack\n", (long)p->p_pid); printf("process %ld has trashed its stack\n", (long)p->p_pid);
@ -762,7 +741,7 @@ linux_vsyscall(struct thread *td)
frame = td->td_frame; frame = td->td_frame;
/* Check %rip for vsyscall area */ /* Check %rip for vsyscall area. */
if (__predict_true(frame->tf_rip < LINUX_VSYSCALL_START)) if (__predict_true(frame->tf_rip < LINUX_VSYSCALL_START))
return (EINVAL); return (EINVAL);
if ((frame->tf_rip & (LINUX_VSYSCALL_SZ - 1)) != 0) if ((frame->tf_rip & (LINUX_VSYSCALL_SZ - 1)) != 0)
@ -773,7 +752,7 @@ linux_vsyscall(struct thread *td)
/* /*
* vsyscall called as callq *(%rax), so we must * vsyscall called as callq *(%rax), so we must
* use return address from %rsp and also fixup %rsp * use return address from %rsp and also fixup %rsp.
*/ */
error = copyin((void *)frame->tf_rsp, &retqaddr, sizeof(retqaddr)); error = copyin((void *)frame->tf_rsp, &retqaddr, sizeof(retqaddr));
if (error) if (error)

View File

@ -102,10 +102,9 @@ MODULE_VERSION(linux, 1);
#endif #endif
/* /*
* Allow the sendsig functions to use the ldebug() facility * Allow the sendsig functions to use the ldebug() facility even though they
* even though they are not syscalls themselves. Map them * are not syscalls themselves. Map them to syscall 0. This is slightly less
* to syscall 0. This is slightly less bogus than using * bogus than using ldebug(sigreturn).
* ldebug(sigreturn).
*/ */
#define LINUX32_SYS_linux_rt_sendsig 0 #define LINUX32_SYS_linux_rt_sendsig 0
#define LINUX32_SYS_linux_sendsig 0 #define LINUX32_SYS_linux_sendsig 0
@ -312,9 +311,7 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
printf(ARGS(rt_sendsig, "%p, %d, %p, %u"), printf(ARGS(rt_sendsig, "%p, %d, %p, %u"),
catcher, sig, (void*)mask, code); catcher, sig, (void*)mask, code);
#endif #endif
/* /* Allocate space for the signal handler context. */
* Allocate space for the signal handler context.
*/
if ((td->td_pflags & TDP_ALTSTACK) && !oonstack && if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) { SIGISMEMBER(psp->ps_sigonstack, sig)) {
fp = (struct l_rt_sigframe *)((uintptr_t)td->td_sigstk.ss_sp + fp = (struct l_rt_sigframe *)((uintptr_t)td->td_sigstk.ss_sp +
@ -323,9 +320,7 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
fp = (struct l_rt_sigframe *)regs->tf_rsp - 1; fp = (struct l_rt_sigframe *)regs->tf_rsp - 1;
mtx_unlock(&psp->ps_mtx); mtx_unlock(&psp->ps_mtx);
/* /* Build the argument list for the signal handler. */
* Build the argument list for the signal handler.
*/
sig = bsd_to_linux_signal(sig); sig = bsd_to_linux_signal(sig);
bzero(&frame, sizeof(frame)); bzero(&frame, sizeof(frame));
@ -335,12 +330,11 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
frame.sf_siginfo = PTROUT(&fp->sf_si); frame.sf_siginfo = PTROUT(&fp->sf_si);
frame.sf_ucontext = PTROUT(&fp->sf_sc); frame.sf_ucontext = PTROUT(&fp->sf_sc);
/* Fill in POSIX parts */ /* Fill in POSIX parts. */
ksiginfo_to_lsiginfo(ksi, &frame.sf_si, sig); ksiginfo_to_lsiginfo(ksi, &frame.sf_si, sig);
/* /*
* Build the signal context to be used by sigreturn * Build the signal context to be used by sigreturn and libgcc unwind.
* and libgcc unwind.
*/ */
frame.sf_sc.uc_flags = 0; /* XXX ??? */ frame.sf_sc.uc_flags = 0; /* XXX ??? */
frame.sf_sc.uc_link = 0; /* XXX ??? */ frame.sf_sc.uc_link = 0; /* XXX ??? */
@ -396,9 +390,7 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
sigexit(td, SIGILL); sigexit(td, SIGILL);
} }
/* /* Build context to run handler in. */
* Build context to run handler in.
*/
regs->tf_rsp = PTROUT(fp); regs->tf_rsp = PTROUT(fp);
regs->tf_rip = linux32_rt_sigcode; regs->tf_rip = linux32_rt_sigcode;
regs->tf_rflags &= ~(PSL_T | PSL_D); regs->tf_rflags &= ~(PSL_T | PSL_D);
@ -457,9 +449,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
catcher, sig, (void*)mask, code); catcher, sig, (void*)mask, code);
#endif #endif
/* /* Allocate space for the signal handler context. */
* Allocate space for the signal handler context.
*/
if ((td->td_pflags & TDP_ALTSTACK) && !oonstack && if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) { SIGISMEMBER(psp->ps_sigonstack, sig)) {
fp = (struct l_sigframe *)((uintptr_t)td->td_sigstk.ss_sp + fp = (struct l_sigframe *)((uintptr_t)td->td_sigstk.ss_sp +
@ -469,9 +459,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
mtx_unlock(&psp->ps_mtx); mtx_unlock(&psp->ps_mtx);
PROC_UNLOCK(p); PROC_UNLOCK(p);
/* /* Build the argument list for the signal handler. */
* Build the argument list for the signal handler.
*/
sig = bsd_to_linux_signal(sig); sig = bsd_to_linux_signal(sig);
bzero(&frame, sizeof(frame)); bzero(&frame, sizeof(frame));
@ -481,9 +469,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
bsd_to_linux_sigset(mask, &lmask); bsd_to_linux_sigset(mask, &lmask);
/* /* Build the signal context to be used by sigreturn. */
* Build the signal context to be used by sigreturn.
*/
frame.sf_sc.sc_mask = lmask.__mask; frame.sf_sc.sc_mask = lmask.__mask;
frame.sf_sc.sc_gs = regs->tf_gs; frame.sf_sc.sc_gs = regs->tf_gs;
frame.sf_sc.sc_fs = regs->tf_fs; frame.sf_sc.sc_fs = regs->tf_fs;
@ -517,9 +503,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
sigexit(td, SIGILL); sigexit(td, SIGILL);
} }
/* /* Build context to run handler in. */
* Build context to run handler in.
*/
regs->tf_rsp = PTROUT(fp); regs->tf_rsp = PTROUT(fp);
regs->tf_rip = linux32_sigcode; regs->tf_rip = linux32_sigcode;
regs->tf_rflags &= ~(PSL_T | PSL_D); regs->tf_rflags &= ~(PSL_T | PSL_D);
@ -569,9 +553,7 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
if (copyin(args->sfp, &frame, sizeof(frame)) != 0) if (copyin(args->sfp, &frame, sizeof(frame)) != 0)
return (EFAULT); return (EFAULT);
/* /* Check for security violations. */
* Check for security violations.
*/
#define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0) #define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0)
eflags = frame.sf_sc.sc_eflags; eflags = frame.sf_sc.sc_eflags;
if (!EFLAGS_SECURE(eflags, regs->tf_rflags)) if (!EFLAGS_SECURE(eflags, regs->tf_rflags))
@ -598,9 +580,7 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
linux_to_bsd_sigset(&lmask, &bmask); linux_to_bsd_sigset(&lmask, &bmask);
kern_sigprocmask(td, SIG_SETMASK, &bmask, NULL, 0); kern_sigprocmask(td, SIG_SETMASK, &bmask, NULL, 0);
/* /* Restore signal context. */
* Restore signal context.
*/
regs->tf_rdi = frame.sf_sc.sc_edi; regs->tf_rdi = frame.sf_sc.sc_edi;
regs->tf_rsi = frame.sf_sc.sc_esi; regs->tf_rsi = frame.sf_sc.sc_esi;
regs->tf_rbp = frame.sf_sc.sc_ebp; regs->tf_rbp = frame.sf_sc.sc_ebp;
@ -660,9 +640,7 @@ linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args)
context = &uc.uc_mcontext; context = &uc.uc_mcontext;
/* /* Check for security violations. */
* Check for security violations.
*/
#define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0) #define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0)
eflags = context->sc_eflags; eflags = context->sc_eflags;
if (!EFLAGS_SECURE(eflags, regs->tf_rflags)) if (!EFLAGS_SECURE(eflags, regs->tf_rflags))
@ -850,9 +828,7 @@ linux_copyout_strings(struct image_params *imgp)
char canary[LINUX_AT_RANDOM_LEN]; char canary[LINUX_AT_RANDOM_LEN];
size_t execpath_len; size_t execpath_len;
/* /* Calculate string base and vector table pointers. */
* Calculate string base and vector table pointers.
*/
if (imgp->execpath != NULL && imgp->auxargs != NULL) if (imgp->execpath != NULL && imgp->auxargs != NULL)
execpath_len = strlen(imgp->execpath) + 1; execpath_len = strlen(imgp->execpath) + 1;
else else
@ -869,19 +845,14 @@ linux_copyout_strings(struct image_params *imgp)
copyout(imgp->execpath, (void *)imgp->execpathp, execpath_len); copyout(imgp->execpath, (void *)imgp->execpathp, execpath_len);
} }
/* /* Prepare the canary for SSP. */
* Prepare the canary for SSP.
*/
arc4rand(canary, sizeof(canary), 0); arc4rand(canary, sizeof(canary), 0);
imgp->canary = (uintptr_t)arginfo - imgp->canary = (uintptr_t)arginfo -
roundup(execpath_len, sizeof(char *)) - roundup(execpath_len, sizeof(char *)) -
roundup(sizeof(canary), sizeof(char *)); roundup(sizeof(canary), sizeof(char *));
copyout(canary, (void *)imgp->canary, sizeof(canary)); copyout(canary, (void *)imgp->canary, sizeof(canary));
/* /* If we have a valid auxargs ptr, prepare some room on the stack. */
* If we have a valid auxargs ptr, prepare some room
* on the stack.
*/
if (imgp->auxargs) { if (imgp->auxargs) {
/* /*
* 'AT_COUNT*2' is size for the ELF Auxargs data. This is for * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
@ -906,28 +877,20 @@ linux_copyout_strings(struct image_params *imgp)
vectp = (u_int32_t *)(destp - (imgp->args->argc + vectp = (u_int32_t *)(destp - (imgp->args->argc +
imgp->args->envc + 2) * sizeof(u_int32_t)); imgp->args->envc + 2) * sizeof(u_int32_t));
/* /* vectp also becomes our initial stack base. */
* vectp also becomes our initial stack base
*/
stack_base = vectp; stack_base = vectp;
stringp = imgp->args->begin_argv; stringp = imgp->args->begin_argv;
argc = imgp->args->argc; argc = imgp->args->argc;
envc = imgp->args->envc; envc = imgp->args->envc;
/* /* Copy out strings - arguments and environment. */
* Copy out strings - arguments and environment.
*/
copyout(stringp, destp, ARG_MAX - imgp->args->stringspace); copyout(stringp, destp, ARG_MAX - imgp->args->stringspace);
/* /* Fill in "ps_strings" struct for ps, w, etc. */
* Fill in "ps_strings" struct for ps, w, etc.
*/
suword32(&arginfo->ps_argvstr, (uint32_t)(intptr_t)vectp); suword32(&arginfo->ps_argvstr, (uint32_t)(intptr_t)vectp);
suword32(&arginfo->ps_nargvstr, argc); suword32(&arginfo->ps_nargvstr, argc);
/* /* Fill in argument portion of vector table. */
* Fill in argument portion of vector table.
*/
for (; argc > 0; --argc) { for (; argc > 0; --argc) {
suword32(vectp++, (uint32_t)(intptr_t)destp); suword32(vectp++, (uint32_t)(intptr_t)destp);
while (*stringp++ != 0) while (*stringp++ != 0)
@ -935,15 +898,13 @@ linux_copyout_strings(struct image_params *imgp)
destp++; destp++;
} }
/* a null vector table pointer separates the argp's from the envp's */ /* A null vector table pointer separates the argp's from the envp's. */
suword32(vectp++, 0); suword32(vectp++, 0);
suword32(&arginfo->ps_envstr, (uint32_t)(intptr_t)vectp); suword32(&arginfo->ps_envstr, (uint32_t)(intptr_t)vectp);
suword32(&arginfo->ps_nenvstr, envc); suword32(&arginfo->ps_nenvstr, envc);
/* /* Fill in environment portion of vector table. */
* Fill in environment portion of vector table.
*/
for (; envc > 0; --envc) { for (; envc > 0; --envc) {
suword32(vectp++, (uint32_t)(intptr_t)destp); suword32(vectp++, (uint32_t)(intptr_t)destp);
while (*stringp++ != 0) while (*stringp++ != 0)
@ -951,7 +912,7 @@ linux_copyout_strings(struct image_params *imgp)
destp++; destp++;
} }
/* end of vector table is a null pointer */ /* The end of the vector table is a null pointer. */
suword32(vectp, 0); suword32(vectp, 0);
return ((register_t *)stack_base); return ((register_t *)stack_base);

View File

@ -88,10 +88,9 @@ SYSCTL_PROC(_compat_linux, OID_AUTO, debug, CTLTYPE_STRING | CTLFLAG_RW, 0, 0,
#endif #endif
/* /*
* Allow the sendsig functions to use the ldebug() facility * Allow the sendsig functions to use the ldebug() facility even though they
* even though they are not syscalls themselves. Map them * are not syscalls themselves. Map them to syscall 0. This is slightly less
* to syscall 0. This is slightly less bogus than using * bogus than using ldebug(sigreturn).
* ldebug(sigreturn).
*/ */
#define LINUX_SYS_linux_rt_sendsig 0 #define LINUX_SYS_linux_rt_sendsig 0
#define LINUX_SYS_linux_sendsig 0 #define LINUX_SYS_linux_sendsig 0
@ -306,9 +305,7 @@ linux_copyout_strings(struct image_params *imgp)
size_t execpath_len; size_t execpath_len;
struct proc *p; struct proc *p;
/* /* Calculate string base and vector table pointers. */
* Calculate string base and vector table pointers.
*/
p = imgp->proc; p = imgp->proc;
if (imgp->execpath != NULL && imgp->auxargs != NULL) if (imgp->execpath != NULL && imgp->auxargs != NULL)
execpath_len = strlen(imgp->execpath) + 1; execpath_len = strlen(imgp->execpath) + 1;
@ -320,9 +317,7 @@ linux_copyout_strings(struct image_params *imgp)
roundup(execpath_len, sizeof(char *)) - roundup(execpath_len, sizeof(char *)) -
roundup(ARG_MAX - imgp->args->stringspace, sizeof(char *)); roundup(ARG_MAX - imgp->args->stringspace, sizeof(char *));
/* /* Install LINUX_PLATFORM. */
* install LINUX_PLATFORM
*/
copyout(linux_kplatform, ((caddr_t)arginfo - linux_szplatform), copyout(linux_kplatform, ((caddr_t)arginfo - linux_szplatform),
linux_szplatform); linux_szplatform);
@ -332,19 +327,14 @@ linux_copyout_strings(struct image_params *imgp)
copyout(imgp->execpath, (void *)imgp->execpathp, execpath_len); copyout(imgp->execpath, (void *)imgp->execpathp, execpath_len);
} }
/* /* Prepare the canary for SSP. */
* Prepare the canary for SSP.
*/
arc4rand(canary, sizeof(canary), 0); arc4rand(canary, sizeof(canary), 0);
imgp->canary = (uintptr_t)arginfo - linux_szplatform - imgp->canary = (uintptr_t)arginfo - linux_szplatform -
roundup(execpath_len, sizeof(char *)) - roundup(execpath_len, sizeof(char *)) -
roundup(sizeof(canary), sizeof(char *)); roundup(sizeof(canary), sizeof(char *));
copyout(canary, (void *)imgp->canary, sizeof(canary)); copyout(canary, (void *)imgp->canary, sizeof(canary));
/* /* If we have a valid auxargs ptr, prepare some room on the stack. */
* If we have a valid auxargs ptr, prepare some room
* on the stack.
*/
if (imgp->auxargs) { if (imgp->auxargs) {
/* /*
* 'AT_COUNT*2' is size for the ELF Auxargs data. This is for * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
@ -368,29 +358,21 @@ linux_copyout_strings(struct image_params *imgp)
sizeof(char *)); sizeof(char *));
} }
/* /* vectp also becomes our initial stack base. */
* vectp also becomes our initial stack base
*/
stack_base = (register_t *)vectp; stack_base = (register_t *)vectp;
stringp = imgp->args->begin_argv; stringp = imgp->args->begin_argv;
argc = imgp->args->argc; argc = imgp->args->argc;
envc = imgp->args->envc; envc = imgp->args->envc;
/* /* Copy out strings - arguments and environment. */
* Copy out strings - arguments and environment.
*/
copyout(stringp, destp, ARG_MAX - imgp->args->stringspace); copyout(stringp, destp, ARG_MAX - imgp->args->stringspace);
/* /* Fill in "ps_strings" struct for ps, w, etc. */
* Fill in "ps_strings" struct for ps, w, etc.
*/
suword(&arginfo->ps_argvstr, (long)(intptr_t)vectp); suword(&arginfo->ps_argvstr, (long)(intptr_t)vectp);
suword(&arginfo->ps_nargvstr, argc); suword(&arginfo->ps_nargvstr, argc);
/* /* Fill in argument portion of vector table. */
* Fill in argument portion of vector table.
*/
for (; argc > 0; --argc) { for (; argc > 0; --argc) {
suword(vectp++, (long)(intptr_t)destp); suword(vectp++, (long)(intptr_t)destp);
while (*stringp++ != 0) while (*stringp++ != 0)
@ -398,15 +380,13 @@ linux_copyout_strings(struct image_params *imgp)
destp++; destp++;
} }
/* a null vector table pointer separates the argp's from the envp's */ /* A null vector table pointer separates the argp's from the envp's. */
suword(vectp++, 0); suword(vectp++, 0);
suword(&arginfo->ps_envstr, (long)(intptr_t)vectp); suword(&arginfo->ps_envstr, (long)(intptr_t)vectp);
suword(&arginfo->ps_nenvstr, envc); suword(&arginfo->ps_nenvstr, envc);
/* /* Fill in environment portion of vector table. */
* Fill in environment portion of vector table.
*/
for (; envc > 0; --envc) { for (; envc > 0; --envc) {
suword(vectp++, (long)(intptr_t)destp); suword(vectp++, (long)(intptr_t)destp);
while (*stringp++ != 0) while (*stringp++ != 0)
@ -414,7 +394,7 @@ linux_copyout_strings(struct image_params *imgp)
destp++; destp++;
} }
/* end of vector table is a null pointer */ /* The end of the vector table is a null pointer. */
suword(vectp, 0); suword(vectp, 0);
return (stack_base); return (stack_base);
@ -444,9 +424,7 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
printf(ARGS(rt_sendsig, "%p, %d, %p, %u"), printf(ARGS(rt_sendsig, "%p, %d, %p, %u"),
catcher, sig, (void*)mask, code); catcher, sig, (void*)mask, code);
#endif #endif
/* /* Allocate space for the signal handler context. */
* Allocate space for the signal handler context.
*/
if ((td->td_pflags & TDP_ALTSTACK) && !oonstack && if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) { SIGISMEMBER(psp->ps_sigonstack, sig)) {
fp = (struct l_rt_sigframe *)((uintptr_t)td->td_sigstk.ss_sp + fp = (struct l_rt_sigframe *)((uintptr_t)td->td_sigstk.ss_sp +
@ -455,9 +433,7 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
fp = (struct l_rt_sigframe *)regs->tf_esp - 1; fp = (struct l_rt_sigframe *)regs->tf_esp - 1;
mtx_unlock(&psp->ps_mtx); mtx_unlock(&psp->ps_mtx);
/* /* Build the argument list for the signal handler. */
* Build the argument list for the signal handler.
*/
sig = bsd_to_linux_signal(sig); sig = bsd_to_linux_signal(sig);
bzero(&frame, sizeof(frame)); bzero(&frame, sizeof(frame));
@ -467,12 +443,10 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
frame.sf_siginfo = &fp->sf_si; frame.sf_siginfo = &fp->sf_si;
frame.sf_ucontext = &fp->sf_sc; frame.sf_ucontext = &fp->sf_sc;
/* Fill in POSIX parts */ /* Fill in POSIX parts. */
ksiginfo_to_lsiginfo(ksi, &frame.sf_si, sig); ksiginfo_to_lsiginfo(ksi, &frame.sf_si, sig);
/* /* Build the signal context to be used by sigreturn. */
* Build the signal context to be used by sigreturn.
*/
frame.sf_sc.uc_flags = 0; /* XXX ??? */ frame.sf_sc.uc_flags = 0; /* XXX ??? */
frame.sf_sc.uc_link = NULL; /* XXX ??? */ frame.sf_sc.uc_link = NULL; /* XXX ??? */
@ -527,9 +501,7 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
sigexit(td, SIGILL); sigexit(td, SIGILL);
} }
/* /* Build context to run handler in. */
* Build context to run handler in.
*/
regs->tf_esp = (int)fp; regs->tf_esp = (int)fp;
regs->tf_eip = linux_rt_sigcode; regs->tf_eip = linux_rt_sigcode;
regs->tf_eflags &= ~(PSL_T | PSL_VM | PSL_D); regs->tf_eflags &= ~(PSL_T | PSL_VM | PSL_D);
@ -584,9 +556,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
catcher, sig, (void*)mask, code); catcher, sig, (void*)mask, code);
#endif #endif
/* /* Allocate space for the signal handler context. */
* Allocate space for the signal handler context.
*/
if ((td->td_pflags & TDP_ALTSTACK) && !oonstack && if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) { SIGISMEMBER(psp->ps_sigonstack, sig)) {
fp = (struct l_sigframe *)((uintptr_t)td->td_sigstk.ss_sp + fp = (struct l_sigframe *)((uintptr_t)td->td_sigstk.ss_sp +
@ -596,9 +566,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
mtx_unlock(&psp->ps_mtx); mtx_unlock(&psp->ps_mtx);
PROC_UNLOCK(p); PROC_UNLOCK(p);
/* /* Build the argument list for the signal handler. */
* Build the argument list for the signal handler.
*/
sig = bsd_to_linux_signal(sig); sig = bsd_to_linux_signal(sig);
bzero(&frame, sizeof(frame)); bzero(&frame, sizeof(frame));
@ -608,9 +576,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
bsd_to_linux_sigset(mask, &lmask); bsd_to_linux_sigset(mask, &lmask);
/* /* Build the signal context to be used by sigreturn. */
* Build the signal context to be used by sigreturn.
*/
frame.sf_sc.sc_mask = lmask.__mask; frame.sf_sc.sc_mask = lmask.__mask;
frame.sf_sc.sc_gs = rgs(); frame.sf_sc.sc_gs = rgs();
frame.sf_sc.sc_fs = regs->tf_fs; frame.sf_sc.sc_fs = regs->tf_fs;
@ -644,9 +610,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
sigexit(td, SIGILL); sigexit(td, SIGILL);
} }
/* /* Build context to run handler in. */
* Build context to run handler in.
*/
regs->tf_esp = (int)fp; regs->tf_esp = (int)fp;
regs->tf_eip = linux_sigcode; regs->tf_eip = linux_sigcode;
regs->tf_eflags &= ~(PSL_T | PSL_VM | PSL_D); regs->tf_eflags &= ~(PSL_T | PSL_VM | PSL_D);
@ -693,9 +657,7 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
if (copyin(args->sfp, &frame, sizeof(frame)) != 0) if (copyin(args->sfp, &frame, sizeof(frame)) != 0)
return (EFAULT); return (EFAULT);
/* /* Check for security violations. */
* Check for security violations.
*/
#define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0) #define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0)
eflags = frame.sf_sc.sc_eflags; eflags = frame.sf_sc.sc_eflags;
if (!EFLAGS_SECURE(eflags, regs->tf_eflags)) if (!EFLAGS_SECURE(eflags, regs->tf_eflags))
@ -721,9 +683,7 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
linux_to_bsd_sigset(&lmask, &bmask); linux_to_bsd_sigset(&lmask, &bmask);
kern_sigprocmask(td, SIG_SETMASK, &bmask, NULL, 0); kern_sigprocmask(td, SIG_SETMASK, &bmask, NULL, 0);
/* /* Restore signal context. */
* Restore signal context.
*/
/* %gs was restored by the trampoline. */ /* %gs was restored by the trampoline. */
regs->tf_fs = frame.sf_sc.sc_fs; regs->tf_fs = frame.sf_sc.sc_fs;
regs->tf_es = frame.sf_sc.sc_es; regs->tf_es = frame.sf_sc.sc_es;
@ -782,9 +742,7 @@ linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args)
context = &uc.uc_mcontext; context = &uc.uc_mcontext;
/* /* Check for security violations. */
* Check for security violations.
*/
#define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0) #define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0)
eflags = context->sc_eflags; eflags = context->sc_eflags;
if (!EFLAGS_SECURE(eflags, regs->tf_eflags)) if (!EFLAGS_SECURE(eflags, regs->tf_eflags))
@ -809,9 +767,7 @@ linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args)
linux_to_bsd_sigset(&uc.uc_sigmask, &bmask); linux_to_bsd_sigset(&uc.uc_sigmask, &bmask);
kern_sigprocmask(td, SIG_SETMASK, &bmask, NULL, 0); kern_sigprocmask(td, SIG_SETMASK, &bmask, NULL, 0);
/* /* Restore signal context. */
* Restore signal context
*/
/* %gs was restored by the trampoline. */ /* %gs was restored by the trampoline. */
regs->tf_fs = context->sc_fs; regs->tf_fs = context->sc_fs;
regs->tf_es = context->sc_es; regs->tf_es = context->sc_es;
@ -829,9 +785,7 @@ linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args)
regs->tf_esp = context->sc_esp_at_signal; regs->tf_esp = context->sc_esp_at_signal;
regs->tf_ss = context->sc_ss; regs->tf_ss = context->sc_ss;
/* /* Call sigaltstack & ignore results. */
* call sigaltstack & ignore results..
*/
lss = &uc.uc_stack; lss = &uc.uc_stack;
ss.ss_sp = lss->ss_sp; ss.ss_sp = lss->ss_sp;
ss.ss_size = lss->ss_size; ss.ss_size = lss->ss_size;
@ -928,7 +882,7 @@ exec_linux_setregs(struct thread *td, struct image_params *imgp, u_long stack)
exec_setregs(td, imgp, stack); exec_setregs(td, imgp, stack);
/* Linux sets %gs to 0, we default to _udatasel */ /* Linux sets %gs to 0, we default to _udatasel. */
pcb->pcb_gs = 0; pcb->pcb_gs = 0;
load_gs(0); load_gs(0);