diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2017-02-08 05:09:27 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2017-02-08 05:09:27 +0000 |
commit | dce59fe6e1e128ed03c16e493686ecd655007b83 (patch) | |
tree | 1a0af8032f920fef5e6b02bd94aa273279586f40 | |
parent | eebfc47f73667f8b137ff4b393a24084a2a944fc (diff) |
In exec_elf.c: expand ELFNAME(), ELFNAME2(), and ELFNAMEEND() except
leaving out the size, so that
ELFNAME2(exec,makecmds)
becomes
exec_elf_makecmds
instead of
exec_elf{32,64}_makecmds
and then delete the ELFNAME2() and ELFNAMEEND() macros.
Move the prototypes for functions local to exec_elf.c to there from
exec_elf.h.
Simplify the SMALL_KERNEL conditionals around the ELF coredump code.
Change exec_conf.c to use the size-generic names and macros
Remove exec_elf{32,64}.c and just build exec_elf.c; delete the
_KERN_DO_ELF and _KERN_DO_ELF64 #defines.
ok jca@, encouragement from deraadt@ and tom@
-rw-r--r-- | sys/arch/alpha/include/exec.h | 4 | ||||
-rw-r--r-- | sys/arch/amd64/include/exec.h | 4 | ||||
-rw-r--r-- | sys/arch/arm/include/exec.h | 4 | ||||
-rw-r--r-- | sys/arch/arm64/include/exec.h | 5 | ||||
-rw-r--r-- | sys/arch/hppa/include/exec.h | 4 | ||||
-rw-r--r-- | sys/arch/i386/include/exec.h | 4 | ||||
-rw-r--r-- | sys/arch/m88k/include/exec.h | 4 | ||||
-rw-r--r-- | sys/arch/mips64/include/exec.h | 4 | ||||
-rw-r--r-- | sys/arch/powerpc/include/exec.h | 6 | ||||
-rw-r--r-- | sys/arch/sh/include/exec.h | 4 | ||||
-rw-r--r-- | sys/arch/sparc64/include/exec.h | 4 | ||||
-rw-r--r-- | sys/conf/files | 5 | ||||
-rw-r--r-- | sys/kern/exec_conf.c | 12 | ||||
-rw-r--r-- | sys/kern/exec_elf.c | 155 | ||||
-rw-r--r-- | sys/kern/exec_elf32.c | 11 | ||||
-rw-r--r-- | sys/kern/exec_elf64.c | 10 | ||||
-rw-r--r-- | sys/sys/exec_elf.h | 22 |
17 files changed, 95 insertions, 167 deletions
diff --git a/sys/arch/alpha/include/exec.h b/sys/arch/alpha/include/exec.h index bce4e79c9e5..ce6d3683920 100644 --- a/sys/arch/alpha/include/exec.h +++ b/sys/arch/alpha/include/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.16 2015/08/29 01:58:39 guenther Exp $ */ +/* $OpenBSD: exec.h,v 1.17 2017/02/08 05:09:25 guenther Exp $ */ /* $NetBSD: exec.h,v 1.1 1995/02/13 23:07:37 cgd Exp $ */ /* @@ -40,8 +40,6 @@ #define ELF_TARG_DATA ELFDATA2LSB #define ELF_TARG_MACH EM_ALPHA_EXP -#define _KERN_DO_ELF64 - /* Processor specific dynamic tag values. */ #define DT_ALPHA_PLTRO 0x70000000 diff --git a/sys/arch/amd64/include/exec.h b/sys/arch/amd64/include/exec.h index a16659e7bb0..227c37ad82a 100644 --- a/sys/arch/amd64/include/exec.h +++ b/sys/arch/amd64/include/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.5 2015/08/29 01:58:39 guenther Exp $ */ +/* $OpenBSD: exec.h,v 1.7 2017/02/08 05:09:25 guenther Exp $ */ /* * Written by Artur Grabowski <art@openbsd.org> Public Domain */ @@ -14,6 +14,4 @@ #define ELF_TARG_DATA ELFDATA2LSB #define ELF_TARG_MACH EM_AMD64 -#define _KERN_DO_ELF64 - #endif diff --git a/sys/arch/arm/include/exec.h b/sys/arch/arm/include/exec.h index 8c6c38cd047..154e1b2adbf 100644 --- a/sys/arch/arm/include/exec.h +++ b/sys/arch/arm/include/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.5 2016/09/16 18:52:25 kettenis Exp $ */ +/* $OpenBSD: exec.h,v 1.6 2017/02/08 05:09:25 guenther Exp $ */ /* $NetBSD: exec.h,v 1.6 1994/10/27 04:16:05 cgd Exp $ */ /* @@ -39,8 +39,6 @@ #define ELF_TARG_DATA ELFDATA2LSB #define ELF_TARG_MACH EM_ARM -#define _KERN_DO_ELF - #define PT_ARM_EXIDX 0x70000001 #endif /* _ARM_EXEC_H_ */ diff --git a/sys/arch/arm64/include/exec.h b/sys/arch/arm64/include/exec.h index 5d093d6d199..9f903b60e37 100644 --- a/sys/arch/arm64/include/exec.h +++ b/sys/arch/arm64/include/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ +/* $OpenBSD: exec.h,v 1.2 2017/02/08 05:09:25 guenther Exp $ */ /* * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se> * @@ -26,7 +26,4 @@ #define ELF_TARG_DATA ELFDATA2LSB #define ELF_TARG_MACH EM_AARCH64 -#define _NLIST_DO_ELF -#define _KERN_DO_ELF64 - #endif diff --git a/sys/arch/hppa/include/exec.h b/sys/arch/hppa/include/exec.h index ca2999b2bd4..c22a51ac3f0 100644 --- a/sys/arch/hppa/include/exec.h +++ b/sys/arch/hppa/include/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.13 2015/08/29 01:58:39 guenther Exp $ */ +/* $OpenBSD: exec.h,v 1.14 2017/02/08 05:09:25 guenther Exp $ */ /* * Copyright (c) 1994, The University of Utah and @@ -35,8 +35,6 @@ #define ELF_TARG_DATA ELFDATA2MSB #define ELF_TARG_MACH EM_PARISC -#define _KERN_DO_ELF - /* * the following MD ELF values definitions are from the: * "Processor-Specific ELF Supplement for PA-RISC. diff --git a/sys/arch/i386/include/exec.h b/sys/arch/i386/include/exec.h index 47b9e589446..be1af21cebd 100644 --- a/sys/arch/i386/include/exec.h +++ b/sys/arch/i386/include/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.13 2015/08/29 01:58:39 guenther Exp $ */ +/* $OpenBSD: exec.h,v 1.14 2017/02/08 05:09:25 guenther Exp $ */ /* $NetBSD: exec.h,v 1.6 1994/10/27 04:16:05 cgd Exp $ */ /* @@ -40,6 +40,4 @@ #define ELF_TARG_MACH EM_386 /* XXX - EM_486 is currently unused by all OSs/compilers/linkers */ -#define _KERN_DO_ELF - #endif /* _MACHINE_EXEC_H_ */ diff --git a/sys/arch/m88k/include/exec.h b/sys/arch/m88k/include/exec.h index 94da6aa03ae..4e8fd93d6f7 100644 --- a/sys/arch/m88k/include/exec.h +++ b/sys/arch/m88k/include/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.6 2015/08/29 01:58:39 guenther Exp $ */ +/* $OpenBSD: exec.h,v 1.7 2017/02/08 05:09:25 guenther Exp $ */ #ifndef _M88K_EXEC_H_ #define _M88K_EXEC_H_ @@ -10,8 +10,6 @@ #define ELF_TARG_DATA ELFDATA2MSB #define ELF_TARG_MACH EM_88K -#define _KERN_DO_ELF - /* Processor specific dynamic tag values. */ #define DT_88K_ADDRBASE 0x70000001 #define DT_88K_PLTSTART 0x70000002 diff --git a/sys/arch/mips64/include/exec.h b/sys/arch/mips64/include/exec.h index 8afad2b9f99..0d254343dcb 100644 --- a/sys/arch/mips64/include/exec.h +++ b/sys/arch/mips64/include/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.7 2015/08/29 01:58:39 guenther Exp $ */ +/* $OpenBSD: exec.h,v 1.8 2017/02/08 05:09:25 guenther Exp $ */ /* * Copyright (c) 1996-2004 Per Fogelstrom, Opsycon AB @@ -41,8 +41,6 @@ #endif #define ELF_TARG_MACH EM_MIPS -#define _KERN_DO_ELF64 - /* Information taken from MIPS ABI supplement */ /* Architecture dependent Segment types - p_type */ diff --git a/sys/arch/powerpc/include/exec.h b/sys/arch/powerpc/include/exec.h index 3ff1c88857e..06d8f5e0dbd 100644 --- a/sys/arch/powerpc/include/exec.h +++ b/sys/arch/powerpc/include/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.14 2015/08/29 01:58:39 guenther Exp $ */ +/* $OpenBSD: exec.h,v 1.15 2017/02/08 05:09:26 guenther Exp $ */ /* * Copyright (c) 1997 Per Fogelstrom, Opsycon AB. @@ -24,7 +24,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: exec.h,v 1.14 2015/08/29 01:58:39 guenther Exp $ + * $Id: exec.h,v 1.15 2017/02/08 05:09:26 guenther Exp $ */ #ifndef _POWERPC_EXEC_H_ @@ -38,8 +38,6 @@ #define ELF_TARG_DATA ELFDATA2MSB #define ELF_TARG_MACH EM_PPC -#define _KERN_DO_ELF - /* Processor sepcific dynamic tag values. */ #define DT_PPC_GOT 0x70000000 diff --git a/sys/arch/sh/include/exec.h b/sys/arch/sh/include/exec.h index a189a8f8aef..125287ec99a 100644 --- a/sys/arch/sh/include/exec.h +++ b/sys/arch/sh/include/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.4 2015/08/29 01:58:39 guenther Exp $ */ +/* $OpenBSD: exec.h,v 1.5 2017/02/08 05:09:26 guenther Exp $ */ /* $NetBSD: elf_machdep.h,v 1.8 2002/04/28 17:10:34 uch Exp $ */ #define __LDPGSZ 4096 @@ -12,8 +12,6 @@ #endif #define ELF_TARG_MACH EM_SH -#define _KERN_DO_ELF - /* * SuperH ELF header flags. */ diff --git a/sys/arch/sparc64/include/exec.h b/sys/arch/sparc64/include/exec.h index 23b49c5777c..692d5faa451 100644 --- a/sys/arch/sparc64/include/exec.h +++ b/sys/arch/sparc64/include/exec.h @@ -1,8 +1,6 @@ -/* $OpenBSD: exec.h,v 1.10 2015/08/29 01:58:39 guenther Exp $ */ +/* $OpenBSD: exec.h,v 1.11 2017/02/08 05:09:26 guenther Exp $ */ /* $NetBSD: elf_machdep.h,v 1.7 2001/02/11 00:18:49 eeh Exp $ */ -#define _KERN_DO_ELF64 - #define ARCH_ELFSIZE 64 /* MD native binary size */ #define ELF_TARG_CLASS ELFCLASS64 #define ELF_TARG_MACH EM_SPARCV9 diff --git a/sys/conf/files b/sys/conf/files index 923ce595ec5..988da36b099 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $OpenBSD: files,v 1.638 2017/01/22 20:08:10 reyk Exp $ +# $OpenBSD: files,v 1.639 2017/02/08 05:09:25 guenther Exp $ # $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -644,8 +644,7 @@ file isofs/udf/udf_vfsops.c udf file isofs/udf/udf_vnops.c udf file kern/clock_subr.c file kern/exec_conf.c -file kern/exec_elf32.c -file kern/exec_elf64.c +file kern/exec_elf.c file kern/exec_script.c file kern/exec_subr.c file kern/init_main.c diff --git a/sys/kern/exec_conf.c b/sys/kern/exec_conf.c index 209609062cc..20465504c31 100644 --- a/sys/kern/exec_conf.c +++ b/sys/kern/exec_conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_conf.c,v 1.34 2016/02/28 15:46:18 naddy Exp $ */ +/* $OpenBSD: exec_conf.c,v 1.35 2017/02/08 05:09:25 guenther Exp $ */ /* $NetBSD: exec_conf.c,v 1.16 1995/12/09 05:34:47 cgd Exp $ */ /* @@ -34,21 +34,13 @@ #include <sys/param.h> #include <sys/exec.h> #include <sys/exec_script.h> - -#if defined(_KERN_DO_ELF) || defined(_KERN_DO_ELF64) #include <sys/exec_elf.h> -#endif extern struct emul emul_native; struct execsw execsw[] = { { EXEC_SCRIPT_HDRSZ, exec_script_makecmds, &emul_native, }, /* shell scripts */ -#ifdef _KERN_DO_ELF - { sizeof(Elf32_Ehdr), exec_elf32_makecmds, &emul_native }, /* elf binaries */ -#endif -#ifdef _KERN_DO_ELF64 - { sizeof(Elf64_Ehdr), exec_elf64_makecmds, &emul_native }, /* elf binaries */ -#endif /* ELF64 */ + { sizeof(Elf_Ehdr), exec_elf_makecmds, &emul_native }, /* elf binaries */ }; int nexecs = (sizeof execsw / sizeof(*execsw)); int exec_maxhdrsz; diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c index e2ece9d652b..25a03a3763e 100644 --- a/sys/kern/exec_elf.c +++ b/sys/kern/exec_elf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_elf.c,v 1.135 2017/02/08 05:02:05 guenther Exp $ */ +/* $OpenBSD: exec_elf.c,v 1.136 2017/02/08 05:09:25 guenther Exp $ */ /* * Copyright (c) 1996 Per Fogelstrom @@ -93,13 +93,18 @@ #include <machine/reg.h> #include <machine/exec.h> -int ELFNAME(load_file)(struct proc *, char *, struct exec_package *, - struct elf_args *, Elf_Addr *); -int ELFNAME(check_header)(Elf_Ehdr *); -int ELFNAME(read_from)(struct proc *, struct vnode *, u_long, void *, int); -void ELFNAME(load_psection)(struct exec_vmcmd_set *, struct vnode *, - Elf_Phdr *, Elf_Addr *, Elf_Addr *, int *, int); -int ELFNAMEEND(coredump)(struct proc *, void *); +int elf_load_file(struct proc *, char *, struct exec_package *, + struct elf_args *, Elf_Addr *); +int elf_check_header(Elf_Ehdr *); +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(struct proc *, struct exec_package *, Elf_Ehdr *, + char *, size_t, size_t); extern char sigcode[], esigcode[], sigcoderet[]; #ifdef SYSCALL_DEBUG @@ -124,7 +129,7 @@ extern char *syscallnames[]; /* * This is the OpenBSD ELF emul */ -struct emul ELFNAMEEND(emul) = { +struct emul emul_elf = { "native", NULL, sendsig, @@ -137,10 +142,10 @@ struct emul ELFNAMEEND(emul) = { NULL, #endif (sizeof(AuxInfo) * ELF_AUX_ENTRIES / sizeof(char *)), - ELFNAME(copyargs), + elf_copyargs, setregs, - ELFNAME2(exec,fixup), - ELFNAMEEND(coredump), + exec_elf_fixup, + coredump_elf, sigcode, esigcode, sigcoderet, @@ -152,7 +157,7 @@ struct emul ELFNAMEEND(emul) = { * space for extra information in case of dynamic binding. */ void * -ELFNAME(copyargs)(struct exec_package *pack, struct ps_strings *arginfo, +elf_copyargs(struct exec_package *pack, struct ps_strings *arginfo, void *stack, void *argp) { stack = copyargs(pack, arginfo, stack, argp); @@ -174,7 +179,7 @@ ELFNAME(copyargs)(struct exec_package *pack, struct ps_strings *arginfo, * Check header for validity; return 0 for ok, ENOEXEC if error */ int -ELFNAME(check_header)(Elf_Ehdr *ehdr) +elf_check_header(Elf_Ehdr *ehdr) { /* * We need to check magic, class size, endianess, and version before @@ -203,8 +208,8 @@ ELFNAME(check_header)(Elf_Ehdr *ehdr) * Load a psection at the appropriate address */ void -ELFNAME(load_psection)(struct exec_vmcmd_set *vcset, struct vnode *vp, - Elf_Phdr *ph, Elf_Addr *addr, Elf_Addr *size, int *prot, int flags) +elf_load_psection(struct exec_vmcmd_set *vcset, struct vnode *vp, + Elf_Phdr *ph, Elf_Addr *addr, Elf_Addr *size, int *prot, int flags) { u_long msize, lsize, psize, rm, rf; long diff, offset, bdiff; @@ -284,8 +289,8 @@ ELFNAME(load_psection)(struct exec_vmcmd_set *vcset, struct vnode *vp, * Read from vnode into buffer at offset. */ int -ELFNAME(read_from)(struct proc *p, struct vnode *vp, u_long off, void *buf, - int size) +elf_read_from(struct proc *p, struct vnode *vp, u_long off, void *buf, + int size) { int error; size_t resid; @@ -306,8 +311,8 @@ ELFNAME(read_from)(struct proc *p, struct vnode *vp, u_long off, void *buf, * coff_load_shlib()]. Made slightly generic so it might be used externally. */ int -ELFNAME(load_file)(struct proc *p, char *path, struct exec_package *epp, - struct elf_args *ap, Elf_Addr *last) +elf_load_file(struct proc *p, char *path, struct exec_package *epp, + struct elf_args *ap, Elf_Addr *last) { int error, i; struct nameidata nd; @@ -345,10 +350,10 @@ ELFNAME(load_file)(struct proc *p, char *path, struct exec_package *epp, } if ((error = VOP_ACCESS(vp, VREAD, p->p_ucred, p)) != 0) goto bad1; - if ((error = ELFNAME(read_from)(p, nd.ni_vp, 0, &eh, sizeof(eh))) != 0) + if ((error = elf_read_from(p, nd.ni_vp, 0, &eh, sizeof(eh))) != 0) goto bad1; - if (ELFNAME(check_header)(&eh) || eh.e_type != ET_DYN) { + if (elf_check_header(&eh) || eh.e_type != ET_DYN) { error = ENOEXEC; goto bad1; } @@ -356,8 +361,7 @@ ELFNAME(load_file)(struct proc *p, char *path, struct exec_package *epp, ph = mallocarray(eh.e_phnum, sizeof(Elf_Phdr), M_TEMP, M_WAITOK); phsize = eh.e_phnum * sizeof(Elf_Phdr); - if ((error = ELFNAME(read_from)(p, nd.ni_vp, eh.e_phoff, ph, - phsize)) != 0) + if ((error = elf_read_from(p, nd.ni_vp, eh.e_phoff, ph, phsize)) != 0) goto bad1; for (i = 0; i < eh.e_phnum; i++) { @@ -454,7 +458,7 @@ ELFNAME(load_file)(struct proc *p, char *path, struct exec_package *epp, flags = VMCMD_RELATIVE; addr = ph[i].p_vaddr - base_ph->p_vaddr; } - ELFNAME(load_psection)(&epp->ep_vmcmds, nd.ni_vp, + elf_load_psection(&epp->ep_vmcmds, nd.ni_vp, &ph[i], &addr, &size, &prot, flags); /* If entry is within this section it must be text */ if (eh.e_entry >= ph[i].p_vaddr && @@ -508,7 +512,7 @@ bad: * stack segments. */ int -ELFNAME2(exec,makecmds)(struct proc *p, struct exec_package *epp) +exec_elf_makecmds(struct proc *p, struct exec_package *epp) { Elf_Ehdr *eh = epp->ep_hdr; Elf_Phdr *ph, *pp, *base_ph = NULL; @@ -521,7 +525,7 @@ ELFNAME2(exec,makecmds)(struct proc *p, struct exec_package *epp) if (epp->ep_hdrvalid < sizeof(Elf_Ehdr)) return (ENOEXEC); - if (ELFNAME(check_header)(eh) || + if (elf_check_header(eh) || (eh->e_type != ET_EXEC && eh->e_type != ET_DYN)) return (ENOEXEC); @@ -543,7 +547,7 @@ ELFNAME2(exec,makecmds)(struct proc *p, struct exec_package *epp) ph = mallocarray(eh->e_phnum, sizeof(Elf_Phdr), M_TEMP, M_WAITOK); phsize = eh->e_phnum * sizeof(Elf_Phdr); - if ((error = ELFNAME(read_from)(p, epp->ep_vp, eh->e_phoff, ph, + if ((error = elf_read_from(p, epp->ep_vp, eh->e_phoff, ph, phsize)) != 0) goto bad; @@ -555,7 +559,7 @@ ELFNAME2(exec,makecmds)(struct proc *p, struct exec_package *epp) if (pp->p_filesz < 2 || pp->p_filesz > MAXPATHLEN) goto bad; interp = pool_get(&namei_pool, PR_WAITOK); - if ((error = ELFNAME(read_from)(p, epp->ep_vp, + if ((error = elf_read_from(p, epp->ep_vp, pp->p_offset, interp, pp->p_filesz)) != 0) { goto bad; } @@ -587,7 +591,7 @@ ELFNAME2(exec,makecmds)(struct proc *p, struct exec_package *epp) * OK, we want a slightly different twist of the * standard emulation package for "real" elf. */ - epp->ep_emul = &ELFNAMEEND(emul); + epp->ep_emul = &emul_elf; pos = ELF_NO_ADDR; /* @@ -595,7 +599,7 @@ ELFNAME2(exec,makecmds)(struct proc *p, struct exec_package *epp) * via a PT_NOTE then also check for a PT_OPENBSD_WXNEEDED segment. */ if (eh->e_ident[EI_OSABI] != ELFOSABI_OPENBSD && (error = - ELFNAME(os_pt_note)(p, epp, epp->ep_hdr, "OpenBSD", 8, 4)) != 0) { + elf_os_pt_note(p, epp, epp->ep_hdr, "OpenBSD", 8, 4)) != 0) { goto bad; } @@ -627,7 +631,7 @@ ELFNAME2(exec,makecmds)(struct proc *p, struct exec_package *epp) * this is correct for BSS_PLT, but may not be * for DATA_PLT, is fine for TEXT_PLT. */ - ELFNAME(load_psection)(&epp->ep_vmcmds, epp->ep_vp, + elf_load_psection(&epp->ep_vmcmds, epp->ep_vp, pp, &addr, &size, &prot, flags); /* @@ -773,7 +777,7 @@ bad: * when loading the program is available for setup of the interpreter. */ int -ELFNAME2(exec,fixup)(struct proc *p, struct exec_package *epp) +exec_elf_fixup(struct proc *p, struct exec_package *epp) { char *interp; int error = 0; @@ -789,7 +793,7 @@ ELFNAME2(exec,fixup)(struct proc *p, struct exec_package *epp) ap = epp->ep_emul_arg; if (interp && - (error = ELFNAME(load_file)(p, interp, epp, ap, &pos)) != 0) { + (error = elf_load_file(p, interp, epp, ap, &pos)) != 0) { free(ap, M_TEMP, epp->ep_emul_argsize); pool_put(&namei_pool, interp); kill_vmcmds(&epp->ep_vmcmds); @@ -848,8 +852,8 @@ ELFNAME2(exec,fixup)(struct proc *p, struct exec_package *epp) } int -ELFNAME(os_pt_note)(struct proc *p, struct exec_package *epp, Elf_Ehdr *eh, - char *os_name, size_t name_size, size_t desc_size) +elf_os_pt_note(struct proc *p, struct exec_package *epp, Elf_Ehdr *eh, + char *os_name, size_t name_size, size_t desc_size) { char pathbuf[MAXPATHLEN]; Elf_Phdr *hph, *ph; @@ -859,7 +863,7 @@ ELFNAME(os_pt_note)(struct proc *p, struct exec_package *epp, Elf_Ehdr *eh, hph = mallocarray(eh->e_phnum, sizeof(Elf_Phdr), M_TEMP, M_WAITOK); phsize = eh->e_phnum * sizeof(Elf_Phdr); - if ((error = ELFNAME(read_from)(p, epp->ep_vp, eh->e_phoff, + if ((error = elf_read_from(p, epp->ep_vp, eh->e_phoff, hph, phsize)) != 0) goto out1; @@ -889,7 +893,7 @@ ELFNAME(os_pt_note)(struct proc *p, struct exec_package *epp, Elf_Ehdr *eh, continue; np = malloc(ph->p_filesz, M_TEMP, M_WAITOK); - if ((error = ELFNAME(read_from)(p, epp->ep_vp, ph->p_offset, + if ((error = elf_read_from(p, epp->ep_vp, ph->p_offset, np, ph->p_filesz)) != 0) goto out2; @@ -924,11 +928,24 @@ out1: return error; } +/* + * Start of routines related to dumping core + */ + +#ifdef SMALL_KERNEL +int +coredump_elf(struct proc *p, void *cookie) +{ + return EPERM; +} +#else /* !SMALL_KERNEL */ + + struct countsegs_state { int npsections; }; -int ELFNAMEEND(coredump_countsegs)(struct proc *, void *, +int coredump_countsegs_elf(struct proc *, void *, struct uvm_coredump_state *); struct writesegs_state { @@ -936,23 +953,20 @@ struct writesegs_state { off_t secoff; }; -int ELFNAMEEND(coredump_writeseghdrs)(struct proc *, void *, +int coredump_writeseghdrs_elf(struct proc *, void *, struct uvm_coredump_state *); -int ELFNAMEEND(coredump_notes)(struct proc *, void *, size_t *); -int ELFNAMEEND(coredump_note)(struct proc *, void *, size_t *); -int ELFNAMEEND(coredump_writenote)(struct proc *, void *, Elf_Note *, +int coredump_notes_elf(struct proc *, void *, size_t *); +int coredump_note_elf(struct proc *, void *, size_t *); +int coredump_writenote_elf(struct proc *, void *, Elf_Note *, const char *, void *); #define ELFROUNDSIZE 4 /* XXX Should it be sizeof(Elf_Word)? */ #define elfround(x) roundup((x), ELFROUNDSIZE) int -ELFNAMEEND(coredump)(struct proc *p, void *cookie) +coredump_elf(struct proc *p, void *cookie) { -#ifdef SMALL_KERNEL - return EPERM; -#else Elf_Ehdr ehdr; Elf_Phdr *psections = NULL; struct countsegs_state cs; @@ -974,8 +988,7 @@ ELFNAMEEND(coredump)(struct proc *p, void *cookie) /* Pass 1: count the entries. */ cs.npsections = 0; - error = uvm_coredump_walkmap(p, NULL, - ELFNAMEEND(coredump_countsegs), &cs); + error = uvm_coredump_walkmap(p, NULL, coredump_countsegs_elf, &cs); if (error) goto out; @@ -983,7 +996,7 @@ ELFNAMEEND(coredump)(struct proc *p, void *cookie) cs.npsections++; /* Get the size of the notes. */ - error = ELFNAMEEND(coredump_notes)(p, NULL, ¬esize); + error = coredump_notes_elf(p, NULL, ¬esize); if (error) goto out; @@ -1026,8 +1039,7 @@ ELFNAMEEND(coredump)(struct proc *p, void *cookie) /* Pass 2: now write the P-section headers. */ ws.secoff = secstart; ws.psections = psections; - error = uvm_coredump_walkmap(p, cookie, - ELFNAMEEND(coredump_writeseghdrs), &ws); + error = uvm_coredump_walkmap(p, cookie, coredump_writeseghdrs_elf, &ws); if (error) goto out; @@ -1053,7 +1065,7 @@ ELFNAMEEND(coredump)(struct proc *p, void *cookie) #endif /* Write out the notes. */ - error = ELFNAMEEND(coredump_notes)(p, cookie, ¬esize); + error = coredump_notes_elf(p, cookie, ¬esize); if (error) goto out; @@ -1093,26 +1105,22 @@ ELFNAMEEND(coredump)(struct proc *p, void *cookie) out: free(psections, M_TEMP, psectionslen); return (error); -#endif } int -ELFNAMEEND(coredump_countsegs)(struct proc *p, void *iocookie, +coredump_countsegs_elf(struct proc *p, void *iocookie, struct uvm_coredump_state *us) { -#ifndef SMALL_KERNEL struct countsegs_state *cs = us->cookie; cs->npsections++; -#endif return (0); } int -ELFNAMEEND(coredump_writeseghdrs)(struct proc *p, void *iocookie, +coredump_writeseghdrs_elf(struct proc *p, void *iocookie, struct uvm_coredump_state *us) { -#ifndef SMALL_KERNEL struct writesegs_state *ws = us->cookie; Elf_Phdr phdr; vsize_t size, realsize; @@ -1137,15 +1145,13 @@ ELFNAMEEND(coredump_writeseghdrs)(struct proc *p, void *iocookie, ws->secoff += phdr.p_filesz; *ws->psections++ = phdr; -#endif return (0); } int -ELFNAMEEND(coredump_notes)(struct proc *p, void *iocookie, size_t *sizep) +coredump_notes_elf(struct proc *p, void *iocookie, size_t *sizep) { -#ifndef SMALL_KERNEL struct ps_strings pss; struct iovec iov; struct uio uio; @@ -1196,7 +1202,7 @@ ELFNAMEEND(coredump_notes)(struct proc *p, void *iocookie, size_t *sizep) nhdr.descsz = sizeof(cpi); nhdr.type = NT_OPENBSD_PROCINFO; - error = ELFNAMEEND(coredump_writenote)(p, iocookie, &nhdr, + error = coredump_writenote_elf(p, iocookie, &nhdr, "OpenBSD", &cpi); if (error) return (error); @@ -1256,7 +1262,7 @@ ELFNAMEEND(coredump_notes)(struct proc *p, void *iocookie, size_t *sizep) nhdr.type = NT_OPENBSD_WCOOKIE; wcookie = process_get_wcookie(p); - error = ELFNAMEEND(coredump_writenote)(p, iocookie, &nhdr, + error = coredump_writenote_elf(p, iocookie, &nhdr, "OpenBSD", &wcookie); if (error) return (error); @@ -1268,7 +1274,7 @@ ELFNAMEEND(coredump_notes)(struct proc *p, void *iocookie, size_t *sizep) * Now write the register info for the thread that caused the * coredump. */ - error = ELFNAMEEND(coredump_note)(p, iocookie, ¬esize); + error = coredump_note_elf(p, iocookie, ¬esize); if (error) return (error); size += notesize; @@ -1282,21 +1288,19 @@ ELFNAMEEND(coredump_notes)(struct proc *p, void *iocookie, size_t *sizep) TAILQ_FOREACH(q, &pr->ps_threads, p_thr_link) { if (q == p) /* we've taken care of this thread */ continue; - error = ELFNAMEEND(coredump_note)(q, iocookie, ¬esize); + error = coredump_note_elf(q, iocookie, ¬esize); if (error) return (error); size += notesize; } *sizep = size; -#endif return (0); } int -ELFNAMEEND(coredump_note)(struct proc *p, void *iocookie, size_t *sizep) +coredump_note_elf(struct proc *p, void *iocookie, size_t *sizep) { -#ifndef SMALL_KERNEL Elf_Note nhdr; int size, notesize, error; int namesize; @@ -1323,7 +1327,7 @@ ELFNAMEEND(coredump_note)(struct proc *p, void *iocookie, size_t *sizep) nhdr.descsz = sizeof(intreg); nhdr.type = NT_OPENBSD_REGS; - error = ELFNAMEEND(coredump_writenote)(p, iocookie, &nhdr, + error = coredump_writenote_elf(p, iocookie, &nhdr, name, &intreg); if (error) return (error); @@ -1342,8 +1346,7 @@ ELFNAMEEND(coredump_note)(struct proc *p, void *iocookie, size_t *sizep) nhdr.descsz = sizeof(freg); nhdr.type = NT_OPENBSD_FPREGS; - error = ELFNAMEEND(coredump_writenote)(p, iocookie, &nhdr, - name, &freg); + error = coredump_writenote_elf(p, iocookie, &nhdr, name, &freg); if (error) return (error); } @@ -1352,17 +1355,13 @@ ELFNAMEEND(coredump_note)(struct proc *p, void *iocookie, size_t *sizep) *sizep = size; /* XXX Add hook for machdep per-LWP notes. */ -#endif return (0); } int -ELFNAMEEND(coredump_writenote)(struct proc *p, void *cookie, Elf_Note *nhdr, +coredump_writenote_elf(struct proc *p, void *cookie, Elf_Note *nhdr, const char *name, void *data) { -#ifdef SMALL_KERNEL - return EPERM; -#else int error; error = coredump_write(cookie, UIO_SYSSPACE, nhdr, sizeof(*nhdr)); @@ -1375,5 +1374,5 @@ ELFNAMEEND(coredump_writenote)(struct proc *p, void *cookie, Elf_Note *nhdr, return error; return coredump_write(cookie, UIO_SYSSPACE, data, nhdr->descsz); -#endif } +#endif /* !SMALL_KERNEL */ diff --git a/sys/kern/exec_elf32.c b/sys/kern/exec_elf32.c deleted file mode 100644 index 584667fa92e..00000000000 --- a/sys/kern/exec_elf32.c +++ /dev/null @@ -1,11 +0,0 @@ -/* $OpenBSD: exec_elf32.c,v 1.3 2015/01/20 04:41:01 krw Exp $ */ -/* - * Public domain. Author: Artur Grabowski <art@openbsd.org> - */ -#include <machine/exec.h> - -#ifdef _KERN_DO_ELF -#define ELFSIZE 32 -#include <kern/exec_elf.c> -#endif - diff --git a/sys/kern/exec_elf64.c b/sys/kern/exec_elf64.c deleted file mode 100644 index 517ee5d7a6b..00000000000 --- a/sys/kern/exec_elf64.c +++ /dev/null @@ -1,10 +0,0 @@ -/* $OpenBSD: exec_elf64.c,v 1.21 2015/01/20 04:41:01 krw Exp $ */ -/* - * Public domain. Author: Artur Grabowski <art@openbsd.org> - */ -#include <machine/exec.h> - -#ifdef _KERN_DO_ELF64 -#define ELFSIZE 64 -#include <kern/exec_elf.c> -#endif /* _KERN_DO_ELF64 */ diff --git a/sys/sys/exec_elf.h b/sys/sys/exec_elf.h index 8d4e72e52ba..3a69666f77e 100644 --- a/sys/sys/exec_elf.h +++ b/sys/sys/exec_elf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_elf.h,v 1.70 2017/02/08 05:02:05 guenther Exp $ */ +/* $OpenBSD: exec_elf.h,v 1.71 2017/02/08 05:09:25 guenther Exp $ */ /* * Copyright (c) 1995, 1996 Erik Theisen. All rights reserved. * @@ -657,8 +657,6 @@ struct elf_args { #if defined(ELFSIZE) #define CONCAT(x,y) __CONCAT(x,y) #define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x))) -#define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y)))) -#define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE)) #define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x))) #endif @@ -723,23 +721,7 @@ extern Elf_Dyn _DYNAMIC[]; #endif #ifdef _KERNEL -#ifdef _KERN_DO_ELF64 -int exec_elf64_makecmds(struct proc *, struct exec_package *); -void *elf64_copyargs(struct exec_package *, struct ps_strings *, - void *, void *); -int exec_elf64_fixup(struct proc *, struct exec_package *); -int elf64_os_pt_note(struct proc *, struct exec_package *, Elf64_Ehdr *, - char *, size_t, size_t); -#endif -#ifdef _KERN_DO_ELF -int exec_elf32_makecmds(struct proc *, struct exec_package *); -void *elf32_copyargs(struct exec_package *, struct ps_strings *, - void *, void *); -int exec_elf32_fixup(struct proc *, struct exec_package *); -int elf32_os_pt_note(struct proc *, struct exec_package *, Elf32_Ehdr *, - char *, size_t, size_t); -#endif - +int exec_elf_makecmds(struct proc *, struct exec_package *); #endif /* _KERNEL */ #define ELF_TARG_VER 1 /* The ver for which this code is intended */ |