exec: Simplify sv_copyout_strings implementations a bit
Simplify control flow around handling of the execpath length and signal trampoline. Cache the sysentvec pointer in a local variable. No functional change intended. Reviewed by: kib MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33703
This commit is contained in:
parent
757089f01e
commit
f04a096049
@ -358,17 +358,12 @@ linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
|
|||||||
size_t execpath_len;
|
size_t execpath_len;
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
|
|
||||||
/* Calculate string base and vector table pointers. */
|
|
||||||
if (imgp->execpath != NULL && imgp->auxargs != NULL)
|
|
||||||
execpath_len = strlen(imgp->execpath) + 1;
|
|
||||||
else
|
|
||||||
execpath_len = 0;
|
|
||||||
|
|
||||||
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 = (uintptr_t)arginfo;
|
destp = (uintptr_t)arginfo;
|
||||||
|
|
||||||
if (execpath_len != 0) {
|
if (imgp->execpath != NULL && imgp->auxargs != NULL) {
|
||||||
|
execpath_len = strlen(imgp->execpath) + 1;
|
||||||
destp -= execpath_len;
|
destp -= execpath_len;
|
||||||
destp = rounddown2(destp, sizeof(void *));
|
destp = rounddown2(destp, sizeof(void *));
|
||||||
imgp->execpathp = (void *)destp;
|
imgp->execpathp = (void *)destp;
|
||||||
|
@ -771,16 +771,11 @@ linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
|
|||||||
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. */
|
|
||||||
if (imgp->execpath != NULL && imgp->auxargs != NULL)
|
|
||||||
execpath_len = strlen(imgp->execpath) + 1;
|
|
||||||
else
|
|
||||||
execpath_len = 0;
|
|
||||||
|
|
||||||
arginfo = (struct linux32_ps_strings *)LINUX32_PS_STRINGS;
|
arginfo = (struct linux32_ps_strings *)LINUX32_PS_STRINGS;
|
||||||
destp = (uintptr_t)arginfo;
|
destp = (uintptr_t)arginfo;
|
||||||
|
|
||||||
if (execpath_len != 0) {
|
if (imgp->execpath != NULL && imgp->auxargs != NULL) {
|
||||||
|
execpath_len = strlen(imgp->execpath) + 1;
|
||||||
destp -= execpath_len;
|
destp -= execpath_len;
|
||||||
destp = rounddown2(destp, sizeof(uint32_t));
|
destp = rounddown2(destp, sizeof(uint32_t));
|
||||||
imgp->execpathp = (void *)destp;
|
imgp->execpathp = (void *)destp;
|
||||||
|
@ -255,17 +255,12 @@ linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
|
|||||||
struct proc *p;
|
struct proc *p;
|
||||||
int argc, envc, error;
|
int argc, envc, error;
|
||||||
|
|
||||||
/* Calculate string base and vector table pointers. */
|
|
||||||
if (imgp->execpath != NULL && imgp->auxargs != NULL)
|
|
||||||
execpath_len = strlen(imgp->execpath) + 1;
|
|
||||||
else
|
|
||||||
execpath_len = 0;
|
|
||||||
|
|
||||||
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 = (uintptr_t)arginfo;
|
destp = (uintptr_t)arginfo;
|
||||||
|
|
||||||
if (execpath_len != 0) {
|
if (imgp->execpath != NULL && imgp->auxargs != NULL) {
|
||||||
|
execpath_len = strlen(imgp->execpath) + 1;
|
||||||
destp -= execpath_len;
|
destp -= execpath_len;
|
||||||
destp = rounddown2(destp, sizeof(void *));
|
destp = rounddown2(destp, sizeof(void *));
|
||||||
imgp->execpathp = (void *)destp;
|
imgp->execpathp = (void *)destp;
|
||||||
|
@ -3391,6 +3391,7 @@ syscall32_helper_unregister(struct syscall_helper_data *sd)
|
|||||||
int
|
int
|
||||||
freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
|
freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
|
||||||
{
|
{
|
||||||
|
struct sysentvec *sysent;
|
||||||
int argc, envc, i;
|
int argc, envc, i;
|
||||||
uint32_t *vectp;
|
uint32_t *vectp;
|
||||||
char *stringp;
|
char *stringp;
|
||||||
@ -3401,30 +3402,20 @@ freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
|
|||||||
size_t execpath_len;
|
size_t execpath_len;
|
||||||
int error, szsigcode;
|
int error, szsigcode;
|
||||||
|
|
||||||
/*
|
sysent = imgp->sysent;
|
||||||
* Calculate string base and vector table pointers.
|
|
||||||
* Also deal with signal trampoline code for this exec type.
|
arginfo = (struct freebsd32_ps_strings *)sysent->sv_psstrings;
|
||||||
*/
|
|
||||||
if (imgp->execpath != NULL && imgp->auxargs != NULL)
|
|
||||||
execpath_len = strlen(imgp->execpath) + 1;
|
|
||||||
else
|
|
||||||
execpath_len = 0;
|
|
||||||
arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
|
|
||||||
sv_psstrings;
|
|
||||||
imgp->ps_strings = arginfo;
|
imgp->ps_strings = arginfo;
|
||||||
if (imgp->proc->p_sysent->sv_sigcode_base == 0)
|
|
||||||
szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
|
|
||||||
else
|
|
||||||
szsigcode = 0;
|
|
||||||
destp = (uintptr_t)arginfo;
|
destp = (uintptr_t)arginfo;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* install sigcode
|
* Install sigcode.
|
||||||
*/
|
*/
|
||||||
if (szsigcode != 0) {
|
if (sysent->sv_sigcode_base == 0) {
|
||||||
|
szsigcode = *sysent->sv_szsigcode;
|
||||||
destp -= szsigcode;
|
destp -= szsigcode;
|
||||||
destp = rounddown2(destp, sizeof(uint32_t));
|
destp = rounddown2(destp, sizeof(uint32_t));
|
||||||
error = copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp,
|
error = copyout(sysent->sv_sigcode, (void *)destp,
|
||||||
szsigcode);
|
szsigcode);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return (error);
|
return (error);
|
||||||
@ -3433,7 +3424,8 @@ freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
|
|||||||
/*
|
/*
|
||||||
* Copy the image path for the rtld.
|
* Copy the image path for the rtld.
|
||||||
*/
|
*/
|
||||||
if (execpath_len != 0) {
|
if (imgp->execpath != NULL && imgp->auxargs != NULL) {
|
||||||
|
execpath_len = strlen(imgp->execpath) + 1;
|
||||||
destp -= execpath_len;
|
destp -= execpath_len;
|
||||||
imgp->execpathp = (void *)destp;
|
imgp->execpathp = (void *)destp;
|
||||||
error = copyout(imgp->execpath, imgp->execpathp, execpath_len);
|
error = copyout(imgp->execpath, imgp->execpathp, execpath_len);
|
||||||
|
@ -289,16 +289,12 @@ linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
|
|||||||
size_t execpath_len;
|
size_t execpath_len;
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
|
|
||||||
/* Calculate string base and vector table pointers. */
|
|
||||||
p = imgp->proc;
|
p = imgp->proc;
|
||||||
if (imgp->execpath != NULL && imgp->auxargs != NULL)
|
|
||||||
execpath_len = strlen(imgp->execpath) + 1;
|
|
||||||
else
|
|
||||||
execpath_len = 0;
|
|
||||||
arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
|
arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
|
||||||
destp = (uintptr_t)arginfo;
|
destp = (uintptr_t)arginfo;
|
||||||
|
|
||||||
if (execpath_len != 0) {
|
if (imgp->execpath != NULL && imgp->auxargs != NULL) {
|
||||||
|
execpath_len = strlen(imgp->execpath) + 1;
|
||||||
destp -= execpath_len;
|
destp -= execpath_len;
|
||||||
destp = rounddown2(destp, sizeof(void *));
|
destp = rounddown2(destp, sizeof(void *));
|
||||||
imgp->execpathp = (void *)destp;
|
imgp->execpathp = (void *)destp;
|
||||||
|
@ -1616,37 +1616,26 @@ exec_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
|
|||||||
uintptr_t destp, ustringp;
|
uintptr_t destp, ustringp;
|
||||||
struct ps_strings *arginfo;
|
struct ps_strings *arginfo;
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
|
struct sysentvec *sysent;
|
||||||
size_t execpath_len;
|
size_t execpath_len;
|
||||||
int error, szsigcode, szps;
|
int error, szsigcode;
|
||||||
char canary[sizeof(long) * 8];
|
char canary[sizeof(long) * 8];
|
||||||
|
|
||||||
szps = sizeof(pagesizes[0]) * MAXPAGESIZES;
|
|
||||||
/*
|
|
||||||
* Calculate string base and vector table pointers.
|
|
||||||
* Also deal with signal trampoline code for this exec type.
|
|
||||||
*/
|
|
||||||
if (imgp->execpath != NULL && imgp->auxargs != NULL)
|
|
||||||
execpath_len = strlen(imgp->execpath) + 1;
|
|
||||||
else
|
|
||||||
execpath_len = 0;
|
|
||||||
p = imgp->proc;
|
p = imgp->proc;
|
||||||
szsigcode = 0;
|
sysent = p->p_sysent;
|
||||||
arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
|
|
||||||
imgp->ps_strings = arginfo;
|
arginfo = (struct ps_strings *)sysent->sv_psstrings;
|
||||||
if (p->p_sysent->sv_sigcode_base == 0) {
|
|
||||||
if (p->p_sysent->sv_szsigcode != NULL)
|
|
||||||
szsigcode = *(p->p_sysent->sv_szsigcode);
|
|
||||||
}
|
|
||||||
destp = (uintptr_t)arginfo;
|
destp = (uintptr_t)arginfo;
|
||||||
|
imgp->ps_strings = arginfo;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* install sigcode
|
* Install sigcode.
|
||||||
*/
|
*/
|
||||||
if (szsigcode != 0) {
|
if (sysent->sv_sigcode_base == 0 && sysent->sv_szsigcode != NULL) {
|
||||||
|
szsigcode = *(sysent->sv_szsigcode);
|
||||||
destp -= szsigcode;
|
destp -= szsigcode;
|
||||||
destp = rounddown2(destp, sizeof(void *));
|
destp = rounddown2(destp, sizeof(void *));
|
||||||
error = copyout(p->p_sysent->sv_sigcode, (void *)destp,
|
error = copyout(sysent->sv_sigcode, (void *)destp, szsigcode);
|
||||||
szsigcode);
|
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
@ -1654,7 +1643,8 @@ exec_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
|
|||||||
/*
|
/*
|
||||||
* Copy the image path for the rtld.
|
* Copy the image path for the rtld.
|
||||||
*/
|
*/
|
||||||
if (execpath_len != 0) {
|
if (imgp->execpath != NULL && imgp->auxargs != NULL) {
|
||||||
|
execpath_len = strlen(imgp->execpath) + 1;
|
||||||
destp -= execpath_len;
|
destp -= execpath_len;
|
||||||
destp = rounddown2(destp, sizeof(void *));
|
destp = rounddown2(destp, sizeof(void *));
|
||||||
imgp->execpathp = (void *)destp;
|
imgp->execpathp = (void *)destp;
|
||||||
@ -1677,13 +1667,13 @@ exec_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
|
|||||||
/*
|
/*
|
||||||
* Prepare the pagesizes array.
|
* Prepare the pagesizes array.
|
||||||
*/
|
*/
|
||||||
destp -= szps;
|
imgp->pagesizeslen = sizeof(pagesizes[0]) * MAXPAGESIZES;
|
||||||
|
destp -= imgp->pagesizeslen;
|
||||||
destp = rounddown2(destp, sizeof(void *));
|
destp = rounddown2(destp, sizeof(void *));
|
||||||
imgp->pagesizes = (void *)destp;
|
imgp->pagesizes = (void *)destp;
|
||||||
error = copyout(pagesizes, imgp->pagesizes, szps);
|
error = copyout(pagesizes, imgp->pagesizes, imgp->pagesizeslen);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return (error);
|
return (error);
|
||||||
imgp->pagesizeslen = szps;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate room for the argument and environment strings.
|
* Allocate room for the argument and environment strings.
|
||||||
|
Loading…
Reference in New Issue
Block a user