diff --git a/sys/compat/darwin/darwin_exec.c b/sys/compat/darwin/darwin_exec.c index bb390a46ac51..edec759709f5 100644 --- a/sys/compat/darwin/darwin_exec.c +++ b/sys/compat/darwin/darwin_exec.c @@ -1,4 +1,4 @@ -/* $NetBSD: darwin_exec.c,v 1.20 2003/09/30 19:49:00 manu Exp $ */ +/* $NetBSD: darwin_exec.c,v 1.21 2003/10/19 07:52:22 manu Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include "opt_compat_darwin.h" /* For COMPAT_DARWIN in mach_port.h */ #include -__KERNEL_RCSID(0, "$NetBSD: darwin_exec.c,v 1.20 2003/09/30 19:49:00 manu Exp $"); +__KERNEL_RCSID(0, "$NetBSD: darwin_exec.c,v 1.21 2003/10/19 07:52:22 manu Exp $"); #include "opt_syscall_debug.h" @@ -154,10 +154,14 @@ exec_darwin_copyargs(p, pack, arginfo, stackp, argp) *stackp = (char *)(((unsigned long)*stackp - 1) & ~0xfUL); emea = (struct exec_macho_emul_arg *)pack->ep_emul_arg; - macho_hdr = (struct exec_macho_object_header *)emea->macho_hdr; - if ((error = copyout(&macho_hdr, *stackp, sizeof(macho_hdr))) != 0) - return error; - *stackp += sizeof(macho_hdr); + + if (emea->dynamic == 1) { + macho_hdr = (struct exec_macho_object_header *)emea->macho_hdr; + error = copyout(&macho_hdr, *stackp, sizeof(macho_hdr)); + if (error != 0) + return error; + *stackp += sizeof(macho_hdr); + } cpp = (char **)*stackp; argc = arginfo->ps_nargvstr; diff --git a/sys/kern/exec_conf.c b/sys/kern/exec_conf.c index fb2e20347cc4..fcb1c0d01731 100644 --- a/sys/kern/exec_conf.c +++ b/sys/kern/exec_conf.c @@ -1,4 +1,4 @@ -/* $NetBSD: exec_conf.c,v 1.83 2003/08/08 18:53:13 christos Exp $ */ +/* $NetBSD: exec_conf.c,v 1.84 2003/10/19 07:52:22 manu Exp $ */ /* * Copyright (c) 1993, 1994 Christopher G. Demetriou @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: exec_conf.c,v 1.83 2003/08/08 18:53:13 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: exec_conf.c,v 1.84 2003/10/19 07:52:22 manu Exp $"); #include "opt_execfmt.h" #include "opt_compat_freebsd.h" @@ -507,20 +507,6 @@ const struct execsw execsw_builtin[] = { #endif /* EXEC_ELF64 */ #if defined(EXEC_MACHO) -#ifdef COMPAT_MACH - /* Mach MACH-O (native word size) */ - { sizeof (struct exec_macho_fat_header), - exec_macho_makecmds, - { .mach_probe_func = exec_mach_probe }, - &emul_mach, - EXECSW_PRIO_ANY, - MAXPATHLEN + 1, - exec_mach_copyargs, - NULL, - coredump_netbsd, - exec_setup_stack }, -#endif - #ifdef COMPAT_DARWIN /* Darwin Mach-O (native word size) */ { sizeof (struct exec_macho_fat_header), @@ -534,6 +520,20 @@ const struct execsw execsw_builtin[] = { coredump_netbsd, exec_setup_stack }, #endif + +#ifdef COMPAT_MACH + /* Mach MACH-O (native word size) */ + { sizeof (struct exec_macho_fat_header), + exec_macho_makecmds, + { .mach_probe_func = exec_mach_probe }, + &emul_mach, + EXECSW_PRIO_ANY, + MAXPATHLEN + 1, + exec_mach_copyargs, + NULL, + coredump_netbsd, + exec_setup_stack }, +#endif #endif /* EXEC_MACHO */ #ifdef COMPAT_SUNOS diff --git a/sys/kern/exec_macho.c b/sys/kern/exec_macho.c index 33256ccba086..9c6fb889ae84 100644 --- a/sys/kern/exec_macho.c +++ b/sys/kern/exec_macho.c @@ -1,4 +1,4 @@ -/* $NetBSD: exec_macho.c,v 1.27 2003/09/07 11:16:59 manu Exp $ */ +/* $NetBSD: exec_macho.c,v 1.28 2003/10/19 07:52:22 manu Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: exec_macho.c,v 1.27 2003/09/07 11:16:59 manu Exp $"); +__KERNEL_RCSID(0, "$NetBSD: exec_macho.c,v 1.28 2003/10/19 07:52:22 manu Exp $"); #include #include @@ -421,6 +421,7 @@ exec_macho_load_vnode(p, epp, vp, fat, entry, type, recursive, depth) struct exec_macho_fat_arch arch; struct exec_macho_object_header hdr; struct exec_macho_load_command lc; + struct exec_macho_emul_arg *emea; int error = ENOEXEC, i; size_t size; void *buf = &lc; @@ -540,6 +541,8 @@ exec_macho_load_vnode(p, epp, vp, fat, entry, type, recursive, depth) DPRINTF(("load linker failed\n")); goto bad; } + emea = (struct exec_macho_emul_arg *)epp->ep_emul_arg; + emea->dynamic = 1; break; case MACHO_LC_LOAD_DYLIB: /* @@ -625,6 +628,7 @@ exec_macho_makecmds(p, epp) emea = malloc(sizeof(struct exec_macho_emul_arg), M_EXEC, M_WAITOK); epp->ep_emul_arg = (void *)emea; + emea->dynamic = 0; if (!epp->ep_esch->u.mach_probe_func) emea->path = "/"; @@ -633,6 +637,13 @@ exec_macho_makecmds(p, epp) &emea->path)) != 0) goto bad2; } + + /* + * Make sure the underlying functions will not get + * a random value here. 0 means that no entry point + * has been found yet. + */ + epp->ep_entry = 0; if ((error = exec_macho_load_vnode(p, epp, epp->ep_vp, fat, &epp->ep_entry, MACHO_MOH_EXECUTE, 1, 0)) != 0) diff --git a/sys/sys/exec_macho.h b/sys/sys/exec_macho.h index 0e6b810fd011..6c31c22f593e 100644 --- a/sys/sys/exec_macho.h +++ b/sys/sys/exec_macho.h @@ -1,4 +1,4 @@ -/* $NetBSD: exec_macho.h,v 1.13 2003/08/08 18:54:16 christos Exp $ */ +/* $NetBSD: exec_macho.h,v 1.14 2003/10/19 07:52:22 manu Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -246,6 +246,7 @@ struct exec_macho_emul_arg { char *path; char filename[MAXPATHLEN]; struct exec_macho_object_header *macho_hdr; + int dynamic; }; #ifndef _LKM