-/* $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 <kettenis@openbsd.org>
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;
-/* $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
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 *);
NULL,
#endif
(sizeof(AuxInfo) * ELF_AUX_ENTRIES / sizeof(char *)),
- elf_copyargs,
setregs,
exec_elf_fixup,
coredump_elf,
#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
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);
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);
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);
-/* $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 $ */
/*
NULL,
#endif
0,
- copyargs,
setregs,
NULL, /* fixup */
NULL, /* coredump */
-/* $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 $ */
/*-
#include <sys/file.h>
#include <sys/acct.h>
#include <sys/exec.h>
+#include <sys/exec_elf.h>
#include <sys/ktrace.h>
#include <sys/resourcevar.h>
#include <sys/wait.h>
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;
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 */
}
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);
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);
}
-void *
+int
copyargs(struct exec_package *pack, struct ps_strings *arginfo, void *stack,
void *argp)
{
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;
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
-/* $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 $ */
/*-
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 */
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 */
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 *);
-/* $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 $ */
/*-
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 *);