Deleted Added
full compact
kern_exec.c (189076) kern_exec.c (189927)
1/*-
2 * Copyright (c) 1993, David Greenman
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1993, David Greenman
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/kern/kern_exec.c 189076 2009-02-26 16:32:48Z ed $");
28__FBSDID("$FreeBSD: head/sys/kern/kern_exec.c 189927 2009-03-17 12:53:28Z kib $");
29
30#include "opt_hwpmc_hooks.h"
31#include "opt_kdtrace.h"
32#include "opt_ktrace.h"
33#include "opt_mac.h"
34#include "opt_vm.h"
35
36#include <sys/param.h>

--- 337 unchanged lines hidden (view full) ---

374 imgp->interpreter_name = args->buf + PATH_MAX + ARG_MAX;
375 imgp->auxargs = NULL;
376 imgp->vp = NULL;
377 imgp->object = NULL;
378 imgp->firstpage = NULL;
379 imgp->ps_strings = 0;
380 imgp->auxarg_size = 0;
381 imgp->args = args;
29
30#include "opt_hwpmc_hooks.h"
31#include "opt_kdtrace.h"
32#include "opt_ktrace.h"
33#include "opt_mac.h"
34#include "opt_vm.h"
35
36#include <sys/param.h>

--- 337 unchanged lines hidden (view full) ---

374 imgp->interpreter_name = args->buf + PATH_MAX + ARG_MAX;
375 imgp->auxargs = NULL;
376 imgp->vp = NULL;
377 imgp->object = NULL;
378 imgp->firstpage = NULL;
379 imgp->ps_strings = 0;
380 imgp->auxarg_size = 0;
381 imgp->args = args;
382 imgp->execpath = imgp->freepath = NULL;
383 imgp->execpathp = 0;
382
383#ifdef MAC
384 error = mac_execve_enter(imgp, mac_p);
385 if (error)
386 goto exec_fail;
387#endif
388
389 imgp->image_header = NULL;

--- 124 unchanged lines hidden (view full) ---

514 goto interpret;
515 }
516
517 /*
518 * NB: We unlock the vnode here because it is believed that none
519 * of the sv_copyout_strings/sv_fixup operations require the vnode.
520 */
521 VOP_UNLOCK(imgp->vp, 0);
384
385#ifdef MAC
386 error = mac_execve_enter(imgp, mac_p);
387 if (error)
388 goto exec_fail;
389#endif
390
391 imgp->image_header = NULL;

--- 124 unchanged lines hidden (view full) ---

516 goto interpret;
517 }
518
519 /*
520 * NB: We unlock the vnode here because it is believed that none
521 * of the sv_copyout_strings/sv_fixup operations require the vnode.
522 */
523 VOP_UNLOCK(imgp->vp, 0);
524
522 /*
525 /*
526 * Do the best to calculate the full path to the image file.
527 */
528 if (imgp->auxargs != NULL &&
529 ((args->fname != NULL && args->fname[0] == '/') ||
530 vn_fullpath(td, imgp->vp, &imgp->execpath, &imgp->freepath) != 0))
531 imgp->execpath = args->fname;
532
533 /*
523 * Copy out strings (args and env) and initialize stack base
524 */
525 if (p->p_sysent->sv_copyout_strings)
526 stack_base = (*p->p_sysent->sv_copyout_strings)(imgp);
527 else
528 stack_base = exec_copyout_strings(imgp);
529
530 /*

--- 323 unchanged lines hidden (view full) ---

854 if (imgp->opened)
855 VOP_CLOSE(imgp->vp, FREAD, td->td_ucred, td);
856 vput(imgp->vp);
857 }
858
859 if (imgp->object != NULL)
860 vm_object_deallocate(imgp->object);
861
534 * Copy out strings (args and env) and initialize stack base
535 */
536 if (p->p_sysent->sv_copyout_strings)
537 stack_base = (*p->p_sysent->sv_copyout_strings)(imgp);
538 else
539 stack_base = exec_copyout_strings(imgp);
540
541 /*

--- 323 unchanged lines hidden (view full) ---

865 if (imgp->opened)
866 VOP_CLOSE(imgp->vp, FREAD, td->td_ucred, td);
867 vput(imgp->vp);
868 }
869
870 if (imgp->object != NULL)
871 vm_object_deallocate(imgp->object);
872
873 free(imgp->freepath, M_TEMP);
874
862 if (error == 0) {
863 /*
864 * Stop the process here if its stop event mask has
865 * the S_EXEC bit set.
866 */
867 STOPEVENT(p, S_EXEC, 0);
868 goto done2;
869 }

--- 289 unchanged lines hidden (view full) ---

1159 struct image_params *imgp;
1160{
1161 int argc, envc;
1162 char **vectp;
1163 char *stringp, *destp;
1164 register_t *stack_base;
1165 struct ps_strings *arginfo;
1166 struct proc *p;
875 if (error == 0) {
876 /*
877 * Stop the process here if its stop event mask has
878 * the S_EXEC bit set.
879 */
880 STOPEVENT(p, S_EXEC, 0);
881 goto done2;
882 }

--- 289 unchanged lines hidden (view full) ---

1172 struct image_params *imgp;
1173{
1174 int argc, envc;
1175 char **vectp;
1176 char *stringp, *destp;
1177 register_t *stack_base;
1178 struct ps_strings *arginfo;
1179 struct proc *p;
1180 size_t execpath_len;
1167 int szsigcode;
1168
1169 /*
1170 * Calculate string base and vector table pointers.
1171 * Also deal with signal trampoline code for this exec type.
1172 */
1181 int szsigcode;
1182
1183 /*
1184 * Calculate string base and vector table pointers.
1185 * Also deal with signal trampoline code for this exec type.
1186 */
1187 if (imgp->execpath != NULL && imgp->auxargs != NULL)
1188 execpath_len = strlen(imgp->execpath) + 1;
1189 else
1190 execpath_len = 0;
1173 p = imgp->proc;
1174 szsigcode = 0;
1175 arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
1176 if (p->p_sysent->sv_szsigcode != NULL)
1177 szsigcode = *(p->p_sysent->sv_szsigcode);
1178 destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
1191 p = imgp->proc;
1192 szsigcode = 0;
1193 arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
1194 if (p->p_sysent->sv_szsigcode != NULL)
1195 szsigcode = *(p->p_sysent->sv_szsigcode);
1196 destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
1197 roundup(execpath_len, sizeof(char *)) -
1179 roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *));
1180
1181 /*
1182 * install sigcode
1183 */
1184 if (szsigcode)
1185 copyout(p->p_sysent->sv_sigcode, ((caddr_t)arginfo -
1186 szsigcode), szsigcode);
1187
1188 /*
1198 roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *));
1199
1200 /*
1201 * install sigcode
1202 */
1203 if (szsigcode)
1204 copyout(p->p_sysent->sv_sigcode, ((caddr_t)arginfo -
1205 szsigcode), szsigcode);
1206
1207 /*
1208 * Copy the image path for the rtld.
1209 */
1210 if (execpath_len != 0) {
1211 imgp->execpathp = (uintptr_t)arginfo - szsigcode - execpath_len;
1212 copyout(imgp->execpath, (void *)imgp->execpathp,
1213 execpath_len);
1214 }
1215
1216 /*
1189 * If we have a valid auxargs ptr, prepare some room
1190 * on the stack.
1191 */
1192 if (imgp->auxargs) {
1193 /*
1194 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
1195 * lower compatibility.
1196 */
1197 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size :
1198 (AT_COUNT * 2);
1199 /*
1200 * The '+ 2' is for the null pointers at the end of each of
1201 * the arg and env vector sets,and imgp->auxarg_size is room
1202 * for argument of Runtime loader.
1203 */
1204 vectp = (char **)(destp - (imgp->args->argc +
1217 * If we have a valid auxargs ptr, prepare some room
1218 * on the stack.
1219 */
1220 if (imgp->auxargs) {
1221 /*
1222 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
1223 * lower compatibility.
1224 */
1225 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size :
1226 (AT_COUNT * 2);
1227 /*
1228 * The '+ 2' is for the null pointers at the end of each of
1229 * the arg and env vector sets,and imgp->auxarg_size is room
1230 * for argument of Runtime loader.
1231 */
1232 vectp = (char **)(destp - (imgp->args->argc +
1205 imgp->args->envc + 2 + imgp->auxarg_size) *
1233 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
1206 sizeof(char *));
1234 sizeof(char *));
1207
1208 } else {
1209 /*
1210 * The '+ 2' is for the null pointers at the end of each of
1211 * the arg and env vector sets
1212 */
1213 vectp = (char **)(destp - (imgp->args->argc + imgp->args->envc + 2) *
1214 sizeof(char *));
1215 }

--- 183 unchanged lines hidden ---
1235 } else {
1236 /*
1237 * The '+ 2' is for the null pointers at the end of each of
1238 * the arg and env vector sets
1239 */
1240 vectp = (char **)(destp - (imgp->args->argc + imgp->args->envc + 2) *
1241 sizeof(char *));
1242 }

--- 183 unchanged lines hidden ---