summaryrefslogtreecommitdiff
path: root/sys/compat
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2003-06-24 22:45:34 +0000
committerMarc Espie <espie@cvs.openbsd.org>2003-06-24 22:45:34 +0000
commitdd8eccf37911c51bb235e0ad7d25c02751b60d48 (patch)
tree7590edabc47b149518074fee40008c1d79f953fe /sys/compat
parent817ecac2e2ca954de96eab1d2a48544a1d6f8524 (diff)
a.out emulation for dynamic binaries: intercept the right system calls
so that they look in /emul/a.out first. This allows a.out's ld.so to find its own libraries without interfering with ELF at all. Many comments from various people. okay deraadt@
Diffstat (limited to 'sys/compat')
-rw-r--r--sys/compat/aout/compat_aout.c195
-rw-r--r--sys/compat/aout/files.aout6
-rw-r--r--sys/compat/common/Makefile6
3 files changed, 204 insertions, 3 deletions
diff --git a/sys/compat/aout/compat_aout.c b/sys/compat/aout/compat_aout.c
new file mode 100644
index 00000000000..075524cde75
--- /dev/null
+++ b/sys/compat/aout/compat_aout.c
@@ -0,0 +1,195 @@
+/* $OpenBSD: compat_aout.c,v 1.1 2003/06/24 22:45:33 espie Exp $ */
+
+/*
+ * Copyright (c) 2003 Marc Espie
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include <sys/param.h>
+#include <sys/syscall.h>
+#include <sys/signalvar.h>
+#include <sys/mount.h>
+#include <sys/syscallargs.h>
+#include <sys/fcntl.h>
+#include <compat/common/compat_util.h>
+
+void aout_compat_setup(struct exec_package *epp);
+
+extern char sigcode[], esigcode[];
+
+struct sysent aout_sysent[SYS_MAXSYSCALL];
+
+struct emul emul_aout = {
+ "native",
+ NULL,
+ sendsig,
+ SYS_syscall,
+ SYS_MAXSYSCALL,
+ NULL,
+#ifdef SYSCALL_DEBUG
+ syscallnames,
+#else
+ NULL,
+#endif
+ 0,
+ copyargs,
+ setregs,
+ NULL,
+ sigcode,
+ esigcode,
+};
+
+#ifdef syscallarg
+#undef syscallarg
+#endif
+
+#define syscallarg(x) \
+ union { \
+ register_t pad; \
+ struct { x datum; } le; \
+ struct { \
+ int8_t pad[ (sizeof (register_t) < sizeof (x)) \
+ ? 0 \
+ : sizeof (register_t) - sizeof (x)]; \
+ x datum; \
+ } be; \
+ }
+
+
+struct aout_sys_open_args {
+ syscallarg(char *) path;
+ syscallarg(int) flags;
+ syscallarg(int) mode;
+};
+
+struct aout_sys_link_args {
+ syscallarg(char *) path;
+ syscallarg(char *) link;
+};
+
+struct aout_sys_unlink_args {
+ syscallarg(char *) path;
+};
+
+struct aout_sys_rename_args {
+ syscallarg(char *) from;
+ syscallarg(char *) to;
+};
+
+int aout_sys_open(struct proc *, void *, register_t *);
+int aout_sys_link(struct proc *, void *, register_t *);
+int aout_sys_unlink(struct proc *, void *, register_t *);
+int aout_sys_rename(struct proc *, void *, register_t *);
+
+const char aout_path[] = "/emul/a.out";
+
+#define AOUT_CHECK_ALT_EXIST(p, sgp, path) \
+ CHECK_ALT_EXIST(p, sgp, aout_path, path)
+
+#define AOUT_CHECK_ALT_CREAT(p, sgp, path) \
+ CHECK_ALT_CREAT(p, sgp, aout_path, path)
+
+/* XXX We just translate enough calls to allow ldconfig and ld.so to work. */
+
+void
+aout_compat_setup(struct exec_package *epp)
+{
+ if (emul_aout.e_sysent == NULL) {
+ memcpy(aout_sysent, sysent, sizeof aout_sysent);
+ aout_sysent[SYS_open].sy_call = aout_sys_open;
+ aout_sysent[SYS_link].sy_call = aout_sys_link;
+ aout_sysent[SYS_unlink].sy_call = aout_sys_unlink;
+ aout_sysent[SYS_rename].sy_call = aout_sys_rename;
+ emul_aout.e_sysent = aout_sysent;
+ }
+ epp->ep_emul = &emul_aout;
+}
+
+int
+aout_sys_open(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ struct aout_sys_open_args /* {
+ syscallarg(char *) path;
+ syscallarg(int) flags;
+ syscallarg(int) mode;
+ } */ *uap = v;
+ caddr_t sg = stackgap_init(p->p_emul);
+
+ if (SCARG(uap, flags) & O_CREAT)
+ AOUT_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
+ else
+ AOUT_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
+ return sys_open(p, uap, retval);
+}
+
+int
+aout_sys_link(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ struct aout_sys_link_args /* {
+ syscallarg(char *) path;
+ syscallarg(char *) link;
+ } */ *uap = v;
+ caddr_t sg = stackgap_init(p->p_emul);
+
+ AOUT_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
+ AOUT_CHECK_ALT_CREAT(p, &sg, SCARG(uap, link));
+ return sys_link(p, uap, retval);
+}
+
+int
+aout_sys_unlink(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ struct aout_sys_unlink_args /* {
+ syscallarg(char *) path;
+ } */ *uap = v;
+ caddr_t sg = stackgap_init(p->p_emul);
+
+ AOUT_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
+ return sys_unlink(p, uap, retval);
+}
+
+
+int
+aout_sys_rename(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ struct aout_sys_rename_args /* {
+ syscallarg(char *) from;
+ syscallarg(char *) to;
+ } */ *uap = v;
+ caddr_t sg = stackgap_init(p->p_emul);
+
+ AOUT_CHECK_ALT_EXIST(p, &sg, SCARG(uap, from));
+ AOUT_CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
+ return sys_rename(p, uap, retval);
+}
diff --git a/sys/compat/aout/files.aout b/sys/compat/aout/files.aout
new file mode 100644
index 00000000000..131b526ea60
--- /dev/null
+++ b/sys/compat/aout/files.aout
@@ -0,0 +1,6 @@
+# $OpenBSD: files.aout,v 1.1 2003/06/24 22:45:33 espie Exp $
+#
+# machine-independent a.out compat code.
+# Included by ports that need it.
+
+file compat/aout/compat_aout.c compat_aout
diff --git a/sys/compat/common/Makefile b/sys/compat/common/Makefile
index 558d5d3898c..49e3098dc34 100644
--- a/sys/compat/common/Makefile
+++ b/sys/compat/common/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.13 2003/01/30 03:29:49 millert Exp $
+# $OpenBSD: Makefile,v 1.14 2003/06/24 22:45:33 espie Exp $
# $NetBSD: Makefile,v 1.8 1996/05/18 15:52:19 christos Exp $
LIB= compat
@@ -9,8 +9,8 @@ MACHINE_ARCH= ${XMACHINE_ARCH}
.PATH: ${COMPATDIR}
-SRCS= compat_exec.c compat_util.c compat_dir.c compat_vm.c kern_exit_43.c \
- kern_ipc_23.c kern_info_09.c kern_info_43.c \
+SRCS= compat_exec.c compat_util.c compat_dir.c compat_vm.c \
+ kern_exit_43.c kern_ipc_23.c kern_info_09.c kern_info_43.c \
kern_resource_43.c kern_sig_43.c tty_43.c uipc_syscalls_43.c \
vfs_syscalls_25.c vfs_syscalls_43.c vm_43.c