Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_exec.c
Show First 20 Lines • Show All 354 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
static int | static int | ||||
do_execve(struct thread *td, struct image_args *args, struct mac *mac_p) | do_execve(struct thread *td, struct image_args *args, struct mac *mac_p) | ||||
{ | { | ||||
struct proc *p = td->td_proc; | struct proc *p = td->td_proc; | ||||
struct nameidata nd; | struct nameidata nd; | ||||
struct ucred *oldcred; | struct ucred *oldcred; | ||||
struct uidinfo *euip = NULL; | struct uidinfo *euip = NULL; | ||||
register_t *stack_base; | uintptr_t stack_base; | ||||
int error, i; | int error, i; | ||||
struct image_params image_params, *imgp; | struct image_params image_params, *imgp; | ||||
struct vattr attr; | struct vattr attr; | ||||
int (*img_first)(struct image_params *); | int (*img_first)(struct image_params *); | ||||
struct pargs *oldargs = NULL, *newargs = NULL; | struct pargs *oldargs = NULL, *newargs = NULL; | ||||
struct sigacts *oldsigacts = NULL, *newsigacts = NULL; | struct sigacts *oldsigacts = NULL, *newsigacts = NULL; | ||||
#ifdef KTRACE | #ifdef KTRACE | ||||
struct vnode *tracevp = NULL; | struct vnode *tracevp = NULL; | ||||
▲ Show 20 Lines • Show All 488 Lines • ▼ Show 20 Lines | if (PMC_SYSTEM_SAMPLING_ACTIVE() || PMC_PROC_IS_USING_PMCS(p)) { | ||||
pe.pm_entryaddr = imgp->entry_addr; | pe.pm_entryaddr = imgp->entry_addr; | ||||
PMC_CALL_HOOK_X(td, PMC_FN_PROCESS_EXEC, (void *) &pe); | PMC_CALL_HOOK_X(td, PMC_FN_PROCESS_EXEC, (void *) &pe); | ||||
vn_lock(imgp->vp, LK_SHARED | LK_RETRY); | vn_lock(imgp->vp, LK_SHARED | LK_RETRY); | ||||
} | } | ||||
#endif | #endif | ||||
/* Set values passed into the program in registers. */ | /* Set values passed into the program in registers. */ | ||||
(*p->p_sysent->sv_setregs)(td, imgp, (u_long)(uintptr_t)stack_base); | (*p->p_sysent->sv_setregs)(td, imgp, stack_base); | ||||
vfs_mark_atime(imgp->vp, td->td_ucred); | vfs_mark_atime(imgp->vp, td->td_ucred); | ||||
SDT_PROBE1(proc, , , exec__success, args->fname); | SDT_PROBE1(proc, , , exec__success, args->fname); | ||||
exec_fail_dealloc: | exec_fail_dealloc: | ||||
if (imgp->firstpage != NULL) | if (imgp->firstpage != NULL) | ||||
exec_unmap_first_page(imgp); | exec_unmap_first_page(imgp); | ||||
▲ Show 20 Lines • Show All 684 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/* | /* | ||||
* Copy strings out to the new process address space, constructing new arg | * Copy strings out to the new process address space, constructing new arg | ||||
* and env vector tables. Return a pointer to the base so that it can be used | * and env vector tables. Return a pointer to the base so that it can be used | ||||
* as the initial stack pointer. | * as the initial stack pointer. | ||||
*/ | */ | ||||
int | int | ||||
exec_copyout_strings(struct image_params *imgp, register_t **stack_base) | exec_copyout_strings(struct image_params *imgp, uintptr_t *stack_base) | ||||
{ | { | ||||
int argc, envc; | int argc, envc; | ||||
char **vectp; | char **vectp; | ||||
char *stringp; | char *stringp; | ||||
uintptr_t destp; | uintptr_t destp; | ||||
struct ps_strings *arginfo; | struct ps_strings *arginfo; | ||||
struct proc *p; | struct proc *p; | ||||
size_t execpath_len; | size_t execpath_len; | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | if (error != 0) | ||||
return (error); | return (error); | ||||
imgp->pagesizeslen = szps; | imgp->pagesizeslen = szps; | ||||
destp -= ARG_MAX - imgp->args->stringspace; | destp -= ARG_MAX - imgp->args->stringspace; | ||||
destp = rounddown2(destp, sizeof(void *)); | destp = rounddown2(destp, sizeof(void *)); | ||||
vectp = (char **)destp; | vectp = (char **)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, (uintptr_t *)&vectp); | ||||
if (imgp->auxargs) { | if (imgp->auxargs) { | ||||
error = imgp->sysent->sv_copyout_auxargs(imgp, | error = imgp->sysent->sv_copyout_auxargs(imgp, | ||||
(u_long *)&vectp); | (uintptr_t *)&vectp); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | 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 = (register_t *)vectp; | *stack_base = (uintptr_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. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 180 Lines • Show Last 20 Lines |