[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

2nd try Re: a.out dynamic binaries emulation



Here's a new one, with a few fixes based on people comments.

I'd like to be able to commit this soon... so I'd need some okay,
and if people can check I didn't break any arch, I'd love it.

Index: sys/arch/i386/conf/GENERIC
===================================================================
RCS file: /cvs/src/sys/arch/i386/conf/GENERIC,v
retrieving revision 1.332
diff -u -p -r1.332 GENERIC
--- sys/arch/i386/conf/GENERIC	28 Mar 2003 00:49:13 -0000	1.332
+++ sys/arch/i386/conf/GENERIC	26 Apr 2003 14:42:00 -0000
@@ -30,6 +30,7 @@ option		COMPAT_IBCS2	# binary compatibil
 option		COMPAT_LINUX	# binary compatibility with Linux
 option		COMPAT_FREEBSD	# binary compatibility with FreeBSD
 option		COMPAT_BSDOS	# binary compatibility with BSD/OS
+option		COMPAT_AOUT_TRANSLATE #a.out binary are emulated
 
 maxusers	32		# estimated number of users
 
Index: sys/arch/i386/i386/trap.c
===================================================================
RCS file: /cvs/src/sys/arch/i386/i386/trap.c,v
retrieving revision 1.53
diff -u -p -r1.53 trap.c
--- sys/arch/i386/i386/trap.c	16 Jan 2003 04:15:17 -0000	1.53
+++ sys/arch/i386/i386/trap.c	26 Apr 2003 14:42:01 -0000
@@ -91,6 +91,9 @@ extern struct emul emul_aout_freebsd, em
 #ifdef COMPAT_BSDOS
 extern struct emul emul_bsdos;
 #endif
+#ifdef COMPAT_AOUT_TRANSLATE
+extern struct emul emul_aout_translate;
+#endif
 
 #include "npx.h"
 
@@ -643,6 +646,9 @@ syscall(frame)
 #ifdef COMPAT_FREEBSD
 		    && p->p_emul != &emul_aout_freebsd
 		    && p->p_emul != &emul_elf_freebsd
+#endif
+#ifdef COMPAT_AOUT_TRANSLATE
+		    && p->p_emul != &emul_aout_translate
 #endif
 #ifdef COMPAT_BSDOS
 		    && p->p_emul != &emul_bsdos
Index: sys/compat/common/Makefile
===================================================================
RCS file: /cvs/src/sys/compat/common/Makefile,v
retrieving revision 1.13
diff -u -p -r1.13 Makefile
--- sys/compat/common/Makefile	30 Jan 2003 03:29:49 -0000	1.13
+++ sys/compat/common/Makefile	26 Apr 2003 14:42:03 -0000
@@ -9,7 +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 \
+SRCS=	compat_exec.c compat_util.c compat_dir.c compat_vm.c \
+	exec_aout_translate.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
Index: sys/compat/common/exec_aout_translate.c
===================================================================
RCS file: sys/compat/common/exec_aout_translate.c
diff -N sys/compat/common/exec_aout_translate.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sys/compat/common/exec_aout_translate.c	26 Apr 2003 14:42:03 -0000
@@ -0,0 +1,166 @@
+/* 	$OpenBSD$ */
+
+/*
+ * 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/mount.h>
+#include <sys/syscallargs.h>
+#include <sys/fcntl.h>
+#include <compat/common/compat_util.h>
+
+#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_translate_sys_open_args {
+	syscallarg(char *) path;
+	syscallarg(int) flags;
+	syscallarg(int) mode;
+};
+
+struct aout_translate_sys_link_args {
+	syscallarg(char *) path;
+	syscallarg(char *) link;
+};
+
+struct aout_translate_sys_unlink_args {
+	syscallarg(char *) path;
+};
+
+struct aout_translate_sys_rename_args {
+	syscallarg(char *) from;
+	syscallarg(char *) to;
+};
+
+void aout_translate_init(void);
+int aout_translate_sys_open(struct proc *, void *, register_t *);
+int aout_translate_sys_link(struct proc *, void *, register_t *);
+int aout_translate_sys_unlink(struct proc *, void *, register_t *);
+int aout_translate_sys_rename(struct proc *, void *, register_t *);
+
+struct sysent aout_translate_sysent[SYS_MAXSYSCALL];
+
+const char aout_translate_path[] = "/emul/a.out";
+
+#define AOUT_TRANSLATE_CHECK_ALT_EXIST(p, sgp, path) \
+    CHECK_ALT_EXIST(p, sgp, aout_translate_path, path)
+
+#define  AOUT_TRANSLATE_CHECK_ALT_CREAT(p, sgp, path) \
+    CHECK_ALT_CREAT(p, sgp, aout_translate_path, path)
+
+/* XXX We just translate enough calls to allow ldconfig and ld.so to work. */
+
+void
+aout_translate_init()
+{
+	memcpy(aout_translate_sysent, sysent, sizeof aout_translate_sysent); 
+	aout_translate_sysent[SYS_open].sy_call = aout_translate_sys_open;
+	aout_translate_sysent[SYS_link].sy_call = aout_translate_sys_link;
+	aout_translate_sysent[SYS_unlink].sy_call = aout_translate_sys_unlink;
+	aout_translate_sysent[SYS_rename].sy_call = aout_translate_sys_rename;
+}
+
+int
+aout_translate_sys_open(p, v, retval)
+	struct proc *p;
+	void *v;
+	register_t *retval;
+{
+	struct aout_translate_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_TRANSLATE_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
+	else
+		AOUT_TRANSLATE_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
+	return sys_open(p, uap, retval);
+}
+
+int
+aout_translate_sys_link(p, v, retval)
+	struct proc *p;
+	void *v;
+	register_t *retval;
+{
+	struct aout_translate_sys_link_args /* {
+		syscallarg(char *) path;
+		syscallarg(char *) link;
+	} */ *uap = v;
+	caddr_t sg = stackgap_init(p->p_emul);
+
+	AOUT_TRANSLATE_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
+	AOUT_TRANSLATE_CHECK_ALT_CREAT(p, &sg, SCARG(uap, link));
+	return sys_link(p, uap, retval);
+}
+
+int
+aout_translate_sys_unlink(p, v, retval)
+	struct proc *p;
+	void *v;
+	register_t *retval;
+{
+	struct aout_translate_sys_unlink_args /* {
+		syscallarg(char *) path;
+	} */ *uap = v;
+	caddr_t sg = stackgap_init(p->p_emul);
+
+	AOUT_TRANSLATE_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
+	return sys_unlink(p, uap, retval);
+}
+
+
+int
+aout_translate_sys_rename(p, v, retval)
+	struct proc *p;
+	void *v;
+	register_t *retval;
+{
+	struct aout_translate_sys_rename_args /* {
+		syscallarg(char *) from;
+		syscallarg(char *) to;
+	} */ *uap = v;
+	caddr_t sg = stackgap_init(p->p_emul);
+
+	AOUT_TRANSLATE_CHECK_ALT_EXIST(p, &sg, SCARG(uap, from));
+	AOUT_TRANSLATE_CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
+	return sys_rename(p, uap, retval);
+}
Index: sys/kern/exec_aout.c
===================================================================
RCS file: /cvs/src/sys/kern/exec_aout.c,v
retrieving revision 1.8
diff -u -p -r1.8 exec_aout.c
--- sys/kern/exec_aout.c	26 Jul 2002 23:32:50 -0000	1.8
+++ sys/kern/exec_aout.c	26 Apr 2003 14:42:04 -0000
@@ -41,6 +41,9 @@
 #include <uvm/uvm_extern.h>
 
 #if defined(_KERN_DO_AOUT)
+#if defined(COMPAT_AOUT_TRANSLATE)
+extern struct emul emul_aout_translate;
+#endif
 
 /*
  * exec_aout_makecmds(): Check if it's an a.out-format executable.
@@ -89,6 +92,9 @@ exec_aout_makecmds(p, epp)
 
 	if (error)
 		kill_vmcmds(&epp->ep_vmcmds);
+#ifdef COMPAT_AOUT_TRANSLATE
+	epp->ep_emul = &emul_aout_translate;
+#endif
 
 	return error;
 }
Index: sys/kern/init_main.c
===================================================================
RCS file: /cvs/src/sys/kern/init_main.c,v
retrieving revision 1.101
diff -u -p -r1.101 init_main.c
--- sys/kern/init_main.c	6 Mar 2003 17:06:18 -0000	1.101
+++ sys/kern/init_main.c	26 Apr 2003 14:42:05 -0000
@@ -159,6 +159,31 @@ struct emul emul_native = {
 	esigcode,
 };
 
+#ifdef COMPAT_AOUT_TRANSLATE
+extern struct sysent aout_translate_sysent[];
+extern void aout_translate_init(void);
+
+struct emul emul_aout_translate = {
+	"native",
+	NULL,
+	sendsig,
+	SYS_syscall,
+	SYS_MAXSYSCALL,
+	aout_translate_sysent,
+#ifdef SYSCALL_DEBUG
+	syscallnames,
+#else
+	NULL,
+#endif
+	0,
+	copyargs,
+	setregs,
+	NULL,
+	sigcode,
+	esigcode,
+};
+#endif
+
 /*
  * System startup; initialize the world, create process 0, mount root
  * filesystem, and fork to create init and pagedaemon.  Most of the
@@ -197,6 +222,9 @@ main(framep)
 	printf(copyright);
 	printf("\n");
 
+#ifdef COMPAT_AOUT_TRANSLATE
+	aout_translate_init();
+#endif
 	uvm_init();
 	disk_init();		/* must come before autoconfiguration */
 	tty_init();		/* initialise tty's */
Index: share/man/man4/options.4
===================================================================
RCS file: /cvs/src/share/man/man4/options.4,v
retrieving revision 1.120
diff -u -p -r1.120 options.4
--- share/man/man4/options.4	3 Apr 2003 06:47:59 -0000	1.120
+++ share/man/man4/options.4	26 Apr 2003 14:42:07 -0000
@@ -164,6 +164,12 @@ applications built for the same architec
 This option is available on the alpha architecture.
 See
 .Xr compat_osf1 8 .
+.It Cd Option COMPAT_AOUT_TRANSLATE
+On those ELF architectures that require it, this enables
+full compatibility with old a.out binaries, by allowing the
+a.out dynamic linking system to reside under
+.Pa /emul/a.out .
+This option is available on the i386 architecture.
 .It Cd option COMPAT_43
 Use of this option is discouraged.
 It enables compatibility with
Index: etc/rc
===================================================================
RCS file: /cvs/src/etc/rc,v
retrieving revision 1.226
diff -u -p -r1.226 rc
--- etc/rc	8 Apr 2003 01:53:43 -0000	1.226
+++ etc/rc	26 Apr 2003 14:42:08 -0000
@@ -401,6 +401,19 @@ if [ -f /sbin/ldconfig ]; then
 	ldconfig $shlib_dirs
 fi
 
+if [ -f /emul/a.out/sbin/ldconfig ]; then
+# XXX make sure normal configuration won't get disrupted
+	mkdir -p /emul/a.out/usr/lib /emul/a.out/var/run
+	echo 'creating a.out runtime link editor directory cache.'
+	if [ -d /emul/a.out/usr/local/lib ]; then
+		aout_shlib_dirs="/usr/local/lib $aout_shlib_dirs"
+	fi
+	if [ -d /emul/a.out/usr/X11R6/lib ]; then
+		aout_shlib_dirs="/usr/X11R6/lib $aout_shlib_dirs"
+	fi
+	/emul/a.out/sbin/ldconfig $aout_shlib_dirs
+fi
+
 if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
 	echo -n "ssh-keygen: generating new DSA host key... "
 	if /usr/bin/ssh-keygen -q -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''; then
Index: etc/rc.conf
===================================================================
RCS file: /cvs/src/etc/rc.conf,v
retrieving revision 1.86
diff -u -p -r1.86 rc.conf
--- etc/rc.conf	10 Mar 2003 01:05:28 -0000	1.86
+++ etc/rc.conf	26 Apr 2003 14:42:08 -0000
@@ -83,6 +83,7 @@ afs_mount_point=/afs		# Mountpoint for A
 afs_device=/dev/xfs0		# Device used by afsd
 afsd_flags=-z			# Flags passed to afsd
 shlib_dirs=			# extra directories for ldconfig
+aout_shlib_dirs=		# extra directories for compat a.out ldconfig
 
 local_rcconf="/etc/rc.conf.local"