From: guenther Date: Mon, 6 Dec 2021 21:21:10 +0000 (+0000) Subject: Start to delete emulation support: since we're Just ELF, make X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=682e3c9402648a8662f9bfe1020029b23ac97ecc;p=openbsd Start to delete emulation support: since we're Just ELF, make copyargs() return 0/1 and merge elf_copyargs() into it. Rename ep_emul_arg and ep_emul_argp to have clearer meaning and type and eliminate ep_emul_argsize as no longer necessary. Make sure ep_auxinfo (nee ep_emul_argp) is initialized as powerpc64 always uses it in setregs(). ok semarie@ deraadt@ kettenis@ --- diff --git a/sys/arch/powerpc64/powerpc64/machdep.c b/sys/arch/powerpc64/powerpc64/machdep.c index 9629cb0eda0..36929b11d7b 100644 --- a/sys/arch/powerpc64/powerpc64/machdep.c +++ b/sys/arch/powerpc64/powerpc64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.70 2021/10/06 15:46:03 claudio Exp $ */ +/* $OpenBSD: machdep.c,v 1.71 2021/12/06 21:21:10 guenther Exp $ */ /* * Copyright (c) 2020 Mark Kettenis @@ -900,7 +900,7 @@ setregs(struct proc *p, struct exec_package *pack, u_long stack, frame->fixreg[3] = retval[0] = arginfo.ps_nargvstr; frame->fixreg[4] = retval[1] = (register_t)arginfo.ps_argvstr; frame->fixreg[5] = (register_t)arginfo.ps_envstr; - frame->fixreg[6] = (register_t)pack->ep_emul_argp; + frame->fixreg[6] = (register_t)pack->ep_auxinfo; frame->fixreg[12] = pack->ep_entry; frame->srr0 = pack->ep_entry; frame->srr1 = PSL_USER; diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c index c7571e3fac9..e192b265d52 100644 --- a/sys/kern/exec_elf.c +++ b/sys/kern/exec_elf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_elf.c,v 1.160 2021/03/10 10:21:47 jsg Exp $ */ +/* $OpenBSD: exec_elf.c,v 1.161 2021/12/06 21:21:10 guenther Exp $ */ /* * Copyright (c) 1996 Per Fogelstrom @@ -100,8 +100,6 @@ int elf_read_from(struct proc *, struct vnode *, u_long, void *, int); void elf_load_psection(struct exec_vmcmd_set *, struct vnode *, Elf_Phdr *, Elf_Addr *, Elf_Addr *, int *, int); int coredump_elf(struct proc *, void *); -void *elf_copyargs(struct exec_package *, struct ps_strings *, void *, - void *); int exec_elf_fixup(struct proc *, struct exec_package *); int elf_os_pt_note_name(Elf_Note *); int elf_os_pt_note(struct proc *, struct exec_package *, Elf_Ehdr *, int *); @@ -141,7 +139,6 @@ struct emul emul_elf = { NULL, #endif (sizeof(AuxInfo) * ELF_AUX_ENTRIES / sizeof(char *)), - elf_copyargs, setregs, exec_elf_fixup, coredump_elf, @@ -162,28 +159,6 @@ struct elf_note_name { #define ELFROUNDSIZE sizeof(Elf_Word) #define elfround(x) roundup((x), ELFROUNDSIZE) -/* - * Copy arguments onto the stack in the normal way, but add some - * space for extra information in case of dynamic binding. - */ -void * -elf_copyargs(struct exec_package *pack, struct ps_strings *arginfo, - void *stack, void *argp) -{ - stack = copyargs(pack, arginfo, stack, argp); - if (!stack) - return (NULL); - - /* - * Push space for extra arguments on the stack needed by - * dynamically linked binaries. - */ - if (pack->ep_emul_arg != NULL) { - pack->ep_emul_argp = stack; - stack = (char *)stack + ELF_AUX_ENTRIES * sizeof (AuxInfo); - } - return (stack); -} /* * Check header for validity; return 0 for ok, ENOEXEC if error @@ -770,8 +745,7 @@ exec_elf_makecmds(struct proc *p, struct exec_package *epp) ap->arg_entry = eh->e_entry + exe_base; ap->arg_interp = exe_base; - epp->ep_emul_arg = ap; - epp->ep_emul_argsize = sizeof *ap; + epp->ep_args = ap; } free(ph, M_TEMP, phsize); @@ -800,16 +774,16 @@ exec_elf_fixup(struct proc *p, struct exec_package *epp) struct elf_args *ap; AuxInfo ai[ELF_AUX_ENTRIES], *a; - if (epp->ep_emul_arg == NULL) { + ap = epp->ep_args; + if (ap == NULL) { return (0); } interp = epp->ep_interp; - ap = epp->ep_emul_arg; if (interp && (error = elf_load_file(p, interp, epp, ap)) != 0) { - free(ap, M_TEMP, epp->ep_emul_argsize); + free(ap, M_TEMP, sizeof *ap); pool_put(&namei_pool, interp); kill_vmcmds(&epp->ep_vmcmds); return (error); @@ -863,9 +837,9 @@ exec_elf_fixup(struct proc *p, struct exec_package *epp) a->au_v = 0; a++; - error = copyout(ai, epp->ep_emul_argp, sizeof ai); + error = copyout(ai, epp->ep_auxinfo, sizeof ai); } - free(ap, M_TEMP, epp->ep_emul_argsize); + free(ap, M_TEMP, sizeof *ap); if (interp) pool_put(&namei_pool, interp); return (error); diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 9d975b0de25..3d686f911fb 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.308 2021/06/30 12:21:02 bluhm Exp $ */ +/* $OpenBSD: init_main.c,v 1.309 2021/12/06 21:21:10 guenther Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -171,7 +171,6 @@ struct emul emul_native = { NULL, #endif 0, - copyargs, setregs, NULL, /* fixup */ NULL, /* coredump */ diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 674c62a53ed..1a6110c4ffd 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exec.c,v 1.223 2021/03/16 16:32:22 deraadt Exp $ */ +/* $OpenBSD: kern_exec.c,v 1.224 2021/12/06 21:21:10 guenther Exp $ */ /* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */ /*- @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -294,7 +295,8 @@ sys_execve(struct proc *p, void *v, register_t *retval) pack.ep_hdrvalid = 0; pack.ep_ndp = &nid; pack.ep_interp = NULL; - pack.ep_emul_arg = NULL; + pack.ep_args = NULL; + pack.ep_auxinfo = NULL; VMCMDSET_INIT(&pack.ep_vmcmds); pack.ep_vap = &attr; pack.ep_emul = &emul_native; @@ -490,7 +492,7 @@ sys_execve(struct proc *p, void *v, register_t *retval) stack = (char *)(vm->vm_minsaddr - len); #endif /* Now copy argc, args & environ to new stack */ - if (!(*pack.ep_emul->e_copyargs)(&pack, &arginfo, stack, argp)) + if (!copyargs(&pack, &arginfo, stack, argp)) goto exec_abort; /* copy out the process's ps_strings structure */ @@ -732,8 +734,7 @@ bad: } if (pack.ep_interp != NULL) pool_put(&namei_pool, pack.ep_interp); - if (pack.ep_emul_arg != NULL) - free(pack.ep_emul_arg, M_TEMP, pack.ep_emul_argsize); + free(pack.ep_args, M_TEMP, sizeof *pack.ep_args); /* close and put the exec'd file */ vn_close(pack.ep_vp, FREAD, cred, p); pool_put(&namei_pool, nid.ni_cnd.cn_pnbuf); @@ -755,8 +756,7 @@ exec_abort: uvm_unmap(&vm->vm_map, VM_MIN_ADDRESS, VM_MAXUSER_ADDRESS); if (pack.ep_interp != NULL) pool_put(&namei_pool, pack.ep_interp); - if (pack.ep_emul_arg != NULL) - free(pack.ep_emul_arg, M_TEMP, pack.ep_emul_argsize); + free(pack.ep_args, M_TEMP, sizeof *pack.ep_args); pool_put(&namei_pool, nid.ni_cnd.cn_pnbuf); vn_close(pack.ep_vp, FREAD, cred, p); km_free(argp, NCARGS, &kv_exec, &kp_pageable); @@ -772,7 +772,7 @@ free_pack_abort: } -void * +int copyargs(struct exec_package *pack, struct ps_strings *arginfo, void *stack, void *argp) { @@ -784,7 +784,7 @@ copyargs(struct exec_package *pack, struct ps_strings *arginfo, void *stack, int envc = arginfo->ps_nenvstr; if (copyout(&argc, cpp++, sizeof(argc))) - return (NULL); + return (0); dp = (char *) (cpp + argc + envc + 2 + pack->ep_emul->e_arglen); sp = argp; @@ -795,22 +795,26 @@ copyargs(struct exec_package *pack, struct ps_strings *arginfo, void *stack, for (; --argc >= 0; sp += len, dp += len) if (copyout(&dp, cpp++, sizeof(dp)) || copyoutstr(sp, dp, ARG_MAX, &len)) - return (NULL); + return (0); if (copyout(&nullp, cpp++, sizeof(nullp))) - return (NULL); + return (0); arginfo->ps_envstr = cpp; /* remember location of envp for later */ for (; --envc >= 0; sp += len, dp += len) if (copyout(&dp, cpp++, sizeof(dp)) || copyoutstr(sp, dp, ARG_MAX, &len)) - return (NULL); + return (0); if (copyout(&nullp, cpp++, sizeof(nullp))) - return (NULL); + return (0); + + /* if this process needs auxinfo, note where to place it */ + if (pack->ep_args != NULL) + pack->ep_auxinfo = cpp; - return (cpp); + return (1); } int diff --git a/sys/sys/exec.h b/sys/sys/exec.h index f6685ec55e6..61a91e00192 100644 --- a/sys/sys/exec.h +++ b/sys/sys/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.44 2021/04/23 15:53:07 drahn Exp $ */ +/* $OpenBSD: exec.h,v 1.45 2021/12/06 21:21:10 guenther Exp $ */ /* $NetBSD: exec.h,v 1.59 1996/02/09 18:25:09 christos Exp $ */ /*- @@ -111,6 +111,7 @@ struct exec_vmcmd_set { struct exec_vmcmd evs_start[EXEC_DEFAULT_VMCMD_SETSIZE]; }; +struct elf_args; struct exec_package { char *ep_name; /* file's name */ void *ep_hdr; /* file's exec header */ @@ -132,9 +133,8 @@ struct exec_package { char **ep_fa; /* a fake args vector for scripts */ int ep_fd; /* a file descriptor we're holding */ struct emul *ep_emul; /* os emulation */ - void *ep_emul_arg; /* emulation argument */ - size_t ep_emul_argsize; /* emulation argument size */ - void *ep_emul_argp; /* emulation argument pointer */ + struct elf_args *ep_args; /* ELF info */ + void *ep_auxinfo; /* userspace auxinfo address */ char *ep_interp; /* name of interpreter if any */ }; #define EXEC_INDIR 0x0001 /* script handling already done */ @@ -157,11 +157,8 @@ int vmcmd_map_pagedvn(struct proc *, struct exec_vmcmd *); int vmcmd_map_readvn(struct proc *, struct exec_vmcmd *); int vmcmd_map_zero(struct proc *, struct exec_vmcmd *); int vmcmd_randomize(struct proc *, struct exec_vmcmd *); -void *copyargs(struct exec_package *, - struct ps_strings *, - void *, void *); -void setregs(struct proc *, struct exec_package *, - u_long, register_t *); +int copyargs(struct exec_package *, struct ps_strings *, void *, void *); +void setregs(struct proc *, struct exec_package *, u_long, register_t *); int check_exec(struct proc *, struct exec_package *); int exec_setup_stack(struct proc *, struct exec_package *); int exec_process_vmcmds(struct proc *, struct exec_package *); diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 4aa36a48696..317b430c76d 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.317 2021/12/05 22:00:42 cheloha Exp $ */ +/* $OpenBSD: proc.h,v 1.318 2021/12/06 21:21:10 guenther Exp $ */ /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ /*- @@ -103,9 +103,6 @@ struct emul { char **e_syscallnames; /* System call name array */ int e_arglen; /* Extra argument size in words */ /* Copy arguments on the stack */ - void *(*e_copyargs)(struct exec_package *, struct ps_strings *, - void *, void *); - /* Set registers before execution */ void (*e_setregs)(struct proc *, struct exec_package *, u_long, register_t *); int (*e_fixup)(struct proc *, struct exec_package *);