Changeset View
Changeset View
Standalone View
Standalone View
head/sys/compat/freebsd32/freebsd32_misc.c
Show First 20 Lines • Show All 3,113 Lines • ▼ Show 20 Lines | |||||
int | int | ||||
syscall32_helper_unregister(struct syscall_helper_data *sd) | syscall32_helper_unregister(struct syscall_helper_data *sd) | ||||
{ | { | ||||
return (kern_syscall_helper_unregister(freebsd32_sysent, sd)); | return (kern_syscall_helper_unregister(freebsd32_sysent, sd)); | ||||
} | } | ||||
register_t * | int | ||||
freebsd32_copyout_strings(struct image_params *imgp) | freebsd32_copyout_strings(struct image_params *imgp, register_t **stack_base) | ||||
{ | { | ||||
int argc, envc, i; | int argc, envc, i; | ||||
u_int32_t *vectp; | u_int32_t *vectp; | ||||
char *stringp; | char *stringp; | ||||
uintptr_t destp; | uintptr_t destp; | ||||
u_int32_t *stack_base; | |||||
struct freebsd32_ps_strings *arginfo; | struct freebsd32_ps_strings *arginfo; | ||||
char canary[sizeof(long) * 8]; | char canary[sizeof(long) * 8]; | ||||
int32_t pagesizes32[MAXPAGESIZES]; | int32_t pagesizes32[MAXPAGESIZES]; | ||||
size_t execpath_len; | size_t execpath_len; | ||||
int szsigcode; | int error, szsigcode; | ||||
/* | /* | ||||
* Calculate string base and vector table pointers. | * Calculate string base and vector table pointers. | ||||
* Also deal with signal trampoline code for this exec type. | * Also deal with signal trampoline code for this exec type. | ||||
*/ | */ | ||||
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 | ||||
execpath_len = 0; | execpath_len = 0; | ||||
arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent-> | arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent-> | ||||
sv_psstrings; | sv_psstrings; | ||||
if (imgp->proc->p_sysent->sv_sigcode_base == 0) | if (imgp->proc->p_sysent->sv_sigcode_base == 0) | ||||
szsigcode = *(imgp->proc->p_sysent->sv_szsigcode); | szsigcode = *(imgp->proc->p_sysent->sv_szsigcode); | ||||
else | else | ||||
szsigcode = 0; | szsigcode = 0; | ||||
destp = (uintptr_t)arginfo; | destp = (uintptr_t)arginfo; | ||||
/* | /* | ||||
* install sigcode | * install sigcode | ||||
*/ | */ | ||||
if (szsigcode != 0) { | if (szsigcode != 0) { | ||||
destp -= szsigcode; | destp -= szsigcode; | ||||
destp = rounddown2(destp, sizeof(uint32_t)); | destp = rounddown2(destp, sizeof(uint32_t)); | ||||
copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp, | error = copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp, | ||||
szsigcode); | szsigcode); | ||||
if (error != 0) | |||||
return (error); | |||||
} | } | ||||
/* | /* | ||||
* Copy the image path for the rtld. | * Copy the image path for the rtld. | ||||
*/ | */ | ||||
if (execpath_len != 0) { | if (execpath_len != 0) { | ||||
destp -= execpath_len; | destp -= execpath_len; | ||||
imgp->execpathp = destp; | imgp->execpathp = destp; | ||||
copyout(imgp->execpath, (void *)destp, execpath_len); | error = copyout(imgp->execpath, (void *)destp, execpath_len); | ||||
if (error != 0) | |||||
return (error); | |||||
} | } | ||||
/* | /* | ||||
* Prepare the canary for SSP. | * Prepare the canary for SSP. | ||||
*/ | */ | ||||
arc4rand(canary, sizeof(canary), 0); | arc4rand(canary, sizeof(canary), 0); | ||||
destp -= sizeof(canary); | destp -= sizeof(canary); | ||||
imgp->canary = destp; | imgp->canary = destp; | ||||
copyout(canary, (void *)destp, sizeof(canary)); | error = copyout(canary, (void *)destp, sizeof(canary)); | ||||
if (error != 0) | |||||
return (error); | |||||
imgp->canarylen = sizeof(canary); | imgp->canarylen = sizeof(canary); | ||||
/* | /* | ||||
* Prepare the pagesizes array. | * Prepare the pagesizes array. | ||||
*/ | */ | ||||
for (i = 0; i < MAXPAGESIZES; i++) | for (i = 0; i < MAXPAGESIZES; i++) | ||||
pagesizes32[i] = (uint32_t)pagesizes[i]; | pagesizes32[i] = (uint32_t)pagesizes[i]; | ||||
destp -= sizeof(pagesizes32); | destp -= sizeof(pagesizes32); | ||||
destp = rounddown2(destp, sizeof(uint32_t)); | destp = rounddown2(destp, sizeof(uint32_t)); | ||||
imgp->pagesizes = destp; | imgp->pagesizes = destp; | ||||
copyout(pagesizes32, (void *)destp, sizeof(pagesizes32)); | error = copyout(pagesizes32, (void *)destp, sizeof(pagesizes32)); | ||||
if (error != 0) | |||||
return (error); | |||||
imgp->pagesizeslen = sizeof(pagesizes32); | imgp->pagesizeslen = sizeof(pagesizes32); | ||||
destp -= ARG_MAX - imgp->args->stringspace; | destp -= ARG_MAX - imgp->args->stringspace; | ||||
destp = rounddown2(destp, sizeof(uint32_t)); | destp = rounddown2(destp, sizeof(uint32_t)); | ||||
vectp = (uint32_t *)destp; | vectp = (uint32_t *)destp; | ||||
if (imgp->sysent->sv_stackgap != NULL) | if (imgp->sysent->sv_stackgap != NULL) | ||||
imgp->sysent->sv_stackgap(imgp, (u_long *)&vectp); | imgp->sysent->sv_stackgap(imgp, (u_long *)&vectp); | ||||
if (imgp->auxargs) | if (imgp->auxargs) { | ||||
imgp->sysent->sv_copyout_auxargs(imgp, (u_long *)&vectp); | error = imgp->sysent->sv_copyout_auxargs(imgp, | ||||
(u_long *)&vectp); | |||||
if (error != 0) | |||||
return (error); | |||||
} | |||||
/* | /* | ||||
* Allocate room for the argv[] and env vectors including the | * Allocate room for the argv[] and env vectors including the | ||||
* terminating NULL pointers. | * terminating NULL pointers. | ||||
*/ | */ | ||||
vectp -= imgp->args->argc + 1 + imgp->args->envc + 1; | vectp -= imgp->args->argc + 1 + imgp->args->envc + 1; | ||||
/* | /* | ||||
* vectp also becomes our initial stack base | * vectp also becomes our initial stack base | ||||
*/ | */ | ||||
stack_base = 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, (void *)destp, ARG_MAX - imgp->args->stringspace); | error = copyout(stringp, (void *)destp, | ||||
ARG_MAX - imgp->args->stringspace); | |||||
if (error != 0) | |||||
return (error); | |||||
/* | /* | ||||
* Fill in "ps_strings" struct for ps, w, etc. | * Fill in "ps_strings" struct for ps, w, etc. | ||||
*/ | */ | ||||
suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp); | if (suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp) != 0 || | ||||
suword32(&arginfo->ps_nargvstr, argc); | suword32(&arginfo->ps_nargvstr, argc) != 0) | ||||
return (EFAULT); | |||||
/* | /* | ||||
* Fill in argument portion of vector table. | * Fill in argument portion of vector table. | ||||
*/ | */ | ||||
for (; argc > 0; --argc) { | for (; argc > 0; --argc) { | ||||
suword32(vectp++, (u_int32_t)(intptr_t)destp); | if (suword32(vectp++, (u_int32_t)(intptr_t)destp) != 0) | ||||
return (EFAULT); | |||||
while (*stringp++ != 0) | while (*stringp++ != 0) | ||||
destp++; | destp++; | ||||
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); | if (suword32(vectp++, 0) != 0) | ||||
return (EFAULT); | |||||
suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp); | if (suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp) != 0 || | ||||
suword32(&arginfo->ps_nenvstr, envc); | suword32(&arginfo->ps_nenvstr, envc) != 0) | ||||
return (EFAULT); | |||||
/* | /* | ||||
* Fill in environment portion of vector table. | * Fill in environment portion of vector table. | ||||
*/ | */ | ||||
for (; envc > 0; --envc) { | for (; envc > 0; --envc) { | ||||
suword32(vectp++, (u_int32_t)(intptr_t)destp); | if (suword32(vectp++, (u_int32_t)(intptr_t)destp) != 0) | ||||
return (EFAULT); | |||||
while (*stringp++ != 0) | while (*stringp++ != 0) | ||||
destp++; | destp++; | ||||
destp++; | destp++; | ||||
} | } | ||||
/* end of vector table is a null pointer */ | /* end of vector table is a null pointer */ | ||||
suword32(vectp, 0); | if (suword32(vectp, 0) != 0) | ||||
return (EFAULT); | |||||
return ((register_t *)stack_base); | return (0); | ||||
} | } | ||||
int | int | ||||
freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap) | freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap) | ||||
{ | { | ||||
struct kld_file_stat *stat; | struct kld_file_stat *stat; | ||||
struct kld32_file_stat *stat32; | struct kld32_file_stat *stat32; | ||||
int error, version; | int error, version; | ||||
▲ Show 20 Lines • Show All 247 Lines • Show Last 20 Lines |