summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_exec.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2009-03-17 12:53:28 +0000
committerkib <kib@FreeBSD.org>2009-03-17 12:53:28 +0000
commite905171fbe93556305cb1fa0334861bd122339d2 (patch)
treed8727e59a354ad0a3bffae93cc41c3c6011692c8 /sys/kern/kern_exec.c
parent7695aca762c11a65c2cb77f36c495e0e77dcd2aa (diff)
downloadFreeBSD-src-e905171fbe93556305cb1fa0334861bd122339d2.zip
FreeBSD-src-e905171fbe93556305cb1fa0334861bd122339d2.tar.gz
Supply AT_EXECPATH auxinfo entry to the interpreter, both for native and
compat32 binaries. Tested by: pho Reviewed by: kan
Diffstat (limited to 'sys/kern/kern_exec.c')
-rw-r--r--sys/kern/kern_exec.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index af6c9e4..f36f803 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -379,6 +379,8 @@ do_execve(td, args, mac_p)
imgp->ps_strings = 0;
imgp->auxarg_size = 0;
imgp->args = args;
+ imgp->execpath = imgp->freepath = NULL;
+ imgp->execpathp = 0;
#ifdef MAC
error = mac_execve_enter(imgp, mac_p);
@@ -519,6 +521,15 @@ interpret:
* of the sv_copyout_strings/sv_fixup operations require the vnode.
*/
VOP_UNLOCK(imgp->vp, 0);
+
+ /*
+ * Do the best to calculate the full path to the image file.
+ */
+ if (imgp->auxargs != NULL &&
+ ((args->fname != NULL && args->fname[0] == '/') ||
+ vn_fullpath(td, imgp->vp, &imgp->execpath, &imgp->freepath) != 0))
+ imgp->execpath = args->fname;
+
/*
* Copy out strings (args and env) and initialize stack base
*/
@@ -859,6 +870,8 @@ exec_fail_dealloc:
if (imgp->object != NULL)
vm_object_deallocate(imgp->object);
+ free(imgp->freepath, M_TEMP);
+
if (error == 0) {
/*
* Stop the process here if its stop event mask has
@@ -1164,18 +1177,24 @@ exec_copyout_strings(imgp)
register_t *stack_base;
struct ps_strings *arginfo;
struct proc *p;
+ size_t execpath_len;
int szsigcode;
/*
* 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;
szsigcode = 0;
arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
if (p->p_sysent->sv_szsigcode != NULL)
szsigcode = *(p->p_sysent->sv_szsigcode);
destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
+ roundup(execpath_len, sizeof(char *)) -
roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *));
/*
@@ -1186,6 +1205,15 @@ exec_copyout_strings(imgp)
szsigcode), szsigcode);
/*
+ * Copy the image path for the rtld.
+ */
+ if (execpath_len != 0) {
+ imgp->execpathp = (uintptr_t)arginfo - szsigcode - execpath_len;
+ copyout(imgp->execpath, (void *)imgp->execpathp,
+ execpath_len);
+ }
+
+ /*
* If we have a valid auxargs ptr, prepare some room
* on the stack.
*/
@@ -1202,9 +1230,8 @@ exec_copyout_strings(imgp)
* for argument of Runtime loader.
*/
vectp = (char **)(destp - (imgp->args->argc +
- imgp->args->envc + 2 + imgp->auxarg_size) *
+ imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
sizeof(char *));
-
} else {
/*
* The '+ 2' is for the null pointers at the end of each of
OpenPOWER on IntegriCloud