From 7f6fbd890eb0bd6c51d0d092bf164d9ed9eb1ae2 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Thu, 15 Apr 2004 00:22:43 +0000 Subject: rework access to emulations slightly in an effort to both merge and separate exec format from emulation. consistent naming of freebsd emuls. not much in the way of functional changes yet. testing and ok deraadt@ and others along the way. --- sys/arch/i386/i386/trap.c | 8 +-- sys/compat/freebsd/freebsd_exec.c | 19 +++++-- sys/compat/freebsd/freebsd_exec.h | 3 +- sys/compat/linux/linux_exec.c | 10 +++- sys/compat/linux/linux_exec.h | 4 +- sys/compat/netbsd/netbsd_exec.c | 6 +-- sys/kern/exec_conf.c | 105 ++++++++++++++++---------------------- sys/kern/kern_sysctl.c | 10 ++-- sys/sys/exec.h | 3 +- 9 files changed, 86 insertions(+), 82 deletions(-) diff --git a/sys/arch/i386/i386/trap.c b/sys/arch/i386/i386/trap.c index f5d7a3d0555..5c25f2ba8da 100644 --- a/sys/arch/i386/i386/trap.c +++ b/sys/arch/i386/i386/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.61 2003/07/29 18:24:36 mickey Exp $ */ +/* $OpenBSD: trap.c,v 1.62 2004/04/15 00:22:42 tedu Exp $ */ /* $NetBSD: trap.c,v 1.95 1996/05/05 06:50:02 mycroft Exp $ */ /*- @@ -82,7 +82,7 @@ extern struct emul emul_ibcs2; extern struct emul emul_linux_aout, emul_linux_elf; #endif #ifdef COMPAT_FREEBSD -extern struct emul emul_aout_freebsd, emul_elf_freebsd; +extern struct emul emul_freebsd_aout, emul_freebsd_elf; #endif #ifdef COMPAT_BSDOS extern struct emul emul_bsdos; @@ -647,8 +647,8 @@ syscall(frame) */ if (callp != sysent #ifdef COMPAT_FREEBSD - && p->p_emul != &emul_aout_freebsd - && p->p_emul != &emul_elf_freebsd + && p->p_emul != &emul_freebsd_aout + && p->p_emul != &emul_freebsd_elf #endif #ifdef COMPAT_AOUT && p->p_emul != &emul_aout diff --git a/sys/compat/freebsd/freebsd_exec.c b/sys/compat/freebsd/freebsd_exec.c index 9c41c48103d..f8f496577a6 100644 --- a/sys/compat/freebsd/freebsd_exec.c +++ b/sys/compat/freebsd/freebsd_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: freebsd_exec.c,v 1.15 2003/05/16 05:30:47 millert Exp $ */ +/* $OpenBSD: freebsd_exec.c,v 1.16 2004/04/15 00:22:42 tedu Exp $ */ /* $NetBSD: freebsd_exec.c,v 1.2 1996/05/18 16:02:08 christos Exp $ */ /* @@ -55,7 +55,7 @@ extern char *freebsd_syscallnames[]; extern const char freebsd_emul_path[]; -struct emul emul_aout_freebsd = { +struct emul emul_freebsd_aout = { "freebsd", NULL, freebsd_sendsig, @@ -75,7 +75,7 @@ struct emul emul_aout_freebsd = { freebsd_esigcode, }; -struct emul emul_elf_freebsd = { +struct emul emul_freebsd_elf = { "freebsd", NULL, freebsd_sendsig, @@ -137,13 +137,22 @@ exec_freebsd_aout_makecmds(p, epp) break; } if (error == 0) - epp->ep_emul = &emul_aout_freebsd; + epp->ep_emul = &emul_freebsd_aout; else kill_vmcmds(&epp->ep_vmcmds); return error; } +int +exec_freebsd_elf32_makecmds(struct proc *p, struct exec_package *epp) +{ + if (!(emul_freebsd_elf.e_flags & EMUL_ENABLED)) + return (ENOEXEC); + return exec_elf32_makecmds(p, epp); + +} + int freebsd_elf_probe(p, epp, itp, pos, os) struct proc *p; @@ -172,7 +181,7 @@ freebsd_elf_probe(p, epp, itp, pos, os) return (error); free(bp, M_TEMP); } - epp->ep_emul = &emul_elf_freebsd; + epp->ep_emul = &emul_freebsd_elf; *pos = ELF32_NO_ADDR; if (*os == OOS_NULL) *os = OOS_FREEBSD; diff --git a/sys/compat/freebsd/freebsd_exec.h b/sys/compat/freebsd/freebsd_exec.h index b54da90c843..c708541f92b 100644 --- a/sys/compat/freebsd/freebsd_exec.h +++ b/sys/compat/freebsd/freebsd_exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: freebsd_exec.h,v 1.6 2003/06/02 23:28:00 millert Exp $ */ +/* $OpenBSD: freebsd_exec.h,v 1.7 2004/04/15 00:22:42 tedu Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -93,6 +93,7 @@ #define FREEBSD_AOUT_HDR_SIZE sizeof(struct exec) int exec_freebsd_aout_makecmds(struct proc *, struct exec_package *); +int exec_freebsd_elf32_makecmds(struct proc *, struct exec_package *); int freebsd_elf_probe(struct proc *, struct exec_package *, char *, u_long *, u_int8_t *); diff --git a/sys/compat/linux/linux_exec.c b/sys/compat/linux/linux_exec.c index b0203f6f956..7b40114a0ac 100644 --- a/sys/compat/linux/linux_exec.c +++ b/sys/compat/linux/linux_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: linux_exec.c,v 1.22 2003/08/21 18:56:07 tedu Exp $ */ +/* $OpenBSD: linux_exec.c,v 1.23 2004/04/15 00:22:42 tedu Exp $ */ /* $NetBSD: linux_exec.c,v 1.13 1996/04/05 00:01:10 christos Exp $ */ /*- @@ -458,6 +458,14 @@ exec_linux_aout_prep_qmagic(p, epp) return (exec_setup_stack(p, epp)); } +int +exec_linux_elf32_makecmds(struct proc *p, struct exec_package *epp) +{ + if (!(emul_linux_elf.e_flags & EMUL_ENABLED)) + return (ENOEXEC); + return exec_elf32_makecmds(p, epp); +} + int linux_elf_probe(p, epp, itp, pos, os) struct proc *p; diff --git a/sys/compat/linux/linux_exec.h b/sys/compat/linux/linux_exec.h index a8d60a7ca29..2450a37a928 100644 --- a/sys/compat/linux/linux_exec.h +++ b/sys/compat/linux/linux_exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: linux_exec.h,v 1.4 2002/03/14 01:26:50 millert Exp $ */ +/* $OpenBSD: linux_exec.h,v 1.5 2004/04/15 00:22:42 tedu Exp $ */ /* $NetBSD: linux_exec.h,v 1.5 1995/10/07 06:27:01 mycroft Exp $ */ /* @@ -67,7 +67,7 @@ #define LINUX_N_BSSADDR(x,m) (LINUX_N_DATADDR(x,m) + (x).a_data) int exec_linux_aout_makecmds(struct proc *, struct exec_package *); -int exec_linux_elf_makecmds(struct proc *, struct exec_package *); +int exec_linux_elf32_makecmds(struct proc *, struct exec_package *); int linux_elf_probe(struct proc *, struct exec_package *, char *, u_long *, u_int8_t *); diff --git a/sys/compat/netbsd/netbsd_exec.c b/sys/compat/netbsd/netbsd_exec.c index 0999972b333..d6c7f9e2910 100644 --- a/sys/compat/netbsd/netbsd_exec.c +++ b/sys/compat/netbsd/netbsd_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netbsd_exec.c,v 1.10 2001/11/06 19:53:17 miod Exp $ */ +/* $OpenBSD: netbsd_exec.c,v 1.11 2004/04/15 00:22:42 tedu Exp $ */ /* $NetBSD: svr4_exec.c,v 1.16 1995/10/14 20:24:20 christos Exp $ */ /* @@ -58,7 +58,7 @@ extern struct sysent netbsd_sysent[]; extern char *netbsd_syscallnames[]; #endif -struct emul emul_elf64_netbsd = { +struct emul emul_netbsd_elf64 = { "netbsd", NULL, netbsd_sendsig, @@ -101,7 +101,7 @@ netbsd_elf64_probe(p, epp, itp, pos, os) return (error); free(bp, M_TEMP); } - epp->ep_emul = &emul_elf64_netbsd; + epp->ep_emul = &emul_netbsd_elf64; *pos = ELF64_NO_ADDR; if (*os == OOS_NULL) *os = OOS_NETBSD; diff --git a/sys/kern/exec_conf.c b/sys/kern/exec_conf.c index 8325e2ea0cb..d18812af095 100644 --- a/sys/kern/exec_conf.c +++ b/sys/kern/exec_conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_conf.c,v 1.16 2003/08/23 20:27:30 tedu Exp $ */ +/* $OpenBSD: exec_conf.c,v 1.17 2004/04/15 00:22:42 tedu Exp $ */ /* $NetBSD: exec_conf.c,v 1.16 1995/12/09 05:34:47 cgd Exp $ */ /* @@ -75,95 +75,78 @@ #include #endif +extern struct emul emul_native, emul_elf32, emul_elf64, emul_aout, + emul_bsdos, emul_freebsd_aout, emul_freebsd_elf, emul_hpux, + emul_ibcs2, emul_linux_elf, emul_linux_aout, emul_netbsd_elf64, + emul_osf1, emul_sunos, emul_svr4, emul_ultrix; + struct execsw execsw[] = { -#ifdef LKM - { 0, NULL, }, /* entries for LKMs */ - { 0, NULL, }, - { 0, NULL, }, - { 0, NULL, }, - { 0, NULL, }, -#endif - { MAXINTERP, exec_script_makecmds, }, /* shell scripts */ + { MAXINTERP, exec_script_makecmds, &emul_native, }, /* shell scripts */ #ifdef _KERN_DO_AOUT - { sizeof(struct exec), exec_aout_makecmds, }, /* a.out binaries */ +#ifdef COMPAT_AOUT + { sizeof(struct exec), exec_aout_makecmds, &emul_aout }, +#else + { sizeof(struct exec), exec_aout_makecmds, &emul_native }, /* a.out binaries */ +#endif #endif #ifdef _KERN_DO_ECOFF - { ECOFF_HDR_SIZE, exec_ecoff_makecmds, }, /* ecoff binaries */ + { ECOFF_HDR_SIZE, exec_ecoff_makecmds, &emul_native }, /* ecoff binaries */ #endif #ifdef _KERN_DO_ELF - { sizeof(Elf32_Ehdr), exec_elf32_makecmds, }, /* elf binaries */ + { sizeof(Elf32_Ehdr), exec_elf32_makecmds, &emul_native }, /* elf binaries */ #endif #ifdef _KERN_DO_ELF64 - { sizeof(Elf64_Ehdr), exec_elf64_makecmds, }, /* elf binaries */ + { sizeof(Elf64_Ehdr), exec_elf64_makecmds, &emul_native }, /* elf binaries */ +#ifdef COMPAT_NETBSD + { sizeof(Elf64_Ehdr), exec_elf64_makecmds, &emul_netbsd_elf64 }, +#endif +#ifdef COMPAT_OSF1 + { sizeof(Elf64_Ehdr), exec_elf64_makecmds, &emul_osf1 }, #endif +#endif /* ELF64 */ #ifdef COMPAT_LINUX - { LINUX_AOUT_HDR_SIZE, exec_linux_aout_makecmds, }, /* linux a.out */ + { LINUX_AOUT_HDR_SIZE, exec_linux_aout_makecmds, &emul_linux_aout }, /* linux a.out */ + { sizeof(Elf32_Ehdr), exec_linux_elf32_makecmds, &emul_linux_elf }, #endif #ifdef COMPAT_IBCS2 - { COFF_HDR_SIZE, exec_ibcs2_coff_makecmds, }, /* coff binaries */ - { XOUT_HDR_SIZE, exec_ibcs2_xout_makecmds, }, /* x.out binaries */ + { COFF_HDR_SIZE, exec_ibcs2_coff_makecmds, &emul_ibcs2 }, /* coff binaries */ + { XOUT_HDR_SIZE, exec_ibcs2_xout_makecmds, &emul_ibcs2 }, /* x.out binaries */ #endif #ifdef COMPAT_BSDOS - { BSDOS_AOUT_HDR_SIZE, exec_bsdos_aout_makecmds, }, /* bsdos */ + { BSDOS_AOUT_HDR_SIZE, exec_bsdos_aout_makecmds, &emul_bsdos }, /* bsdos */ #endif #ifdef COMPAT_FREEBSD - { FREEBSD_AOUT_HDR_SIZE, exec_freebsd_aout_makecmds, }, /* freebsd */ + { FREEBSD_AOUT_HDR_SIZE, exec_freebsd_aout_makecmds, &emul_freebsd_aout }, /* freebsd */ + { sizeof(Elf32_Ehdr), exec_freebsd_elf32_makecmds, &emul_freebsd_elf }, #endif #ifdef COMPAT_HPUX - { HPUX_EXEC_HDR_SIZE, exec_hpux_makecmds, }, /* HP-UX a.out */ + { HPUX_EXEC_HDR_SIZE, exec_hpux_makecmds, &emul_hpux }, /* HP-UX a.out */ #endif #ifdef COMPAT_M68K4K - { sizeof(struct exec), exec_m68k4k_makecmds, }, /* m68k4k a.out */ + { sizeof(struct exec), exec_m68k4k_makecmds, &emul_native }, /* m68k4k a.out */ #endif #ifdef COMPAT_VAX1K - { sizeof(struct exec), exec_vax1k_makecmds, }, /* vax1k a.out */ -#endif -}; -int nexecs = (sizeof execsw / sizeof(*execsw)); -int exec_maxhdrsz; - -extern struct emul emul_native, emul_elf32, emul_elf64, emul_aout, - emul_bsdos, emul_aout_freebsd, emul_elf_freebsd, emul_hpux, - emul_ibcs2, emul_linux_elf, emul_linux_aout, emul_elf64_netbsd, - emul_osf1, emul_sunos, emul_svr4, emul_ultrix; -struct emul *emulsw[] = { -#if defined (_KERN_DO_AOUT) && defined (COMPAT_AOUT) - &emul_aout, -#endif -#ifdef COMPAT_BSDOS - &emul_bsdos, + { sizeof(struct exec), exec_vax1k_makecmds, &emul_native }, /* vax1k a.out */ #endif -#ifdef COMPAT_FREEBSD - &emul_aout_freebsd, - &emul_elf_freebsd, -#endif -#ifdef COMPAT_HPUX - &emul_hpux, -#endif -#ifdef COMPAT_IBCS2 - &emul_ibcs2, -#endif -#ifdef COMPAT_LINUX - &emul_linux_elf, - &emul_linux_aout, -#endif -#if defined (COMPAT_NETBSD) && defined (_KERN_DO_ELF64) - &emul_elf64_netbsd, +#ifdef COMPAT_ULTRIX + { ECOFF_HDR_SIZE, exec_ecoff_makecmds, &emul_ultrix }, /* ecoff binaries */ #endif -#ifdef COMPAT_OSF1 - &emul_osf1, +#ifdef COMPAT_SVR4 + { sizeof(Elf32_Ehdr), exec_elf32_makecmds, &emul_svr4 }, /* elf binaries */ #endif #ifdef COMPAT_SUNOS - &emul_sunos, -#endif -#ifdef COMPAT_SVR4 - &emul_svr4, + { sizeof(struct exec), exec_aout_makecmds, &emul_sunos }, #endif -#ifdef COMPAT_ULTRIX - &emul_ultrix, +#ifdef LKM + { 0, NULL, NULL }, /* entries for LKMs */ + { 0, NULL, NULL }, + { 0, NULL, NULL }, + { 0, NULL, NULL }, + { 0, NULL, NULL }, #endif }; -int nemuls = sizeof(emulsw) / sizeof(*emulsw); +int nexecs = (sizeof execsw / sizeof(*execsw)); +int exec_maxhdrsz; void init_exec(void); diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 6cfce5efb8c..0d785eb7b39 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.104 2004/02/29 12:14:05 weingart Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.105 2004/04/15 00:22:42 tedu Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -1800,14 +1800,16 @@ sysctl_emul(int *name, u_int namelen, void *oldp, size_t *oldlenp, if (name[0] == KERN_EMUL_NUM) { if (namelen != 1) return (ENOTDIR); - return (sysctl_rdint(oldp, oldlenp, newp, nemuls)); + return (sysctl_rdint(oldp, oldlenp, newp, nexecs)); } if (namelen != 2) return (ENOTDIR); - if (name[0] > nemuls || name[0] < 0) + if (name[0] > nexecs || name[0] < 0) + return (EINVAL); + e = execsw[name[0] - 1].es_emul; + if (e == NULL) return (EINVAL); - e = emulsw[name[0] - 1]; switch (name[1]) { case KERN_EMUL_NAME: diff --git a/sys/sys/exec.h b/sys/sys/exec.h index 2d2e409e46d..19746da53f3 100644 --- a/sys/sys/exec.h +++ b/sys/sys/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.21 2003/06/02 23:28:21 millert Exp $ */ +/* $OpenBSD: exec.h,v 1.22 2004/04/15 00:22:42 tedu Exp $ */ /* $NetBSD: exec.h,v 1.59 1996/02/09 18:25:09 christos Exp $ */ /*- @@ -104,6 +104,7 @@ typedef int (*exec_makecmds_fcn)(struct proc *, struct exec_package *); struct execsw { u_int es_hdrsz; /* size of header for this format */ exec_makecmds_fcn es_check; /* function to check exec format */ + struct emul *es_emul; /* emulation */ }; struct exec_vmcmd { -- cgit v1.2.3