Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

a.out dynamic binaries emulation

From: Marc Espie <espie(at)nerim.net>
Date: Thu Apr 24 2003 - 09:19:23 EDT


The following patch translates a few paths in a.out mode if option COMPAT_AOUT_TRANSLATE

This allows dynamic a.out binaries to run, provided libraries and ld.so are dumped in the appropriate directories of /emul/a.out

the path translation is minimalistic, mostly enough is done to allow

ldconfig and ld.so to perform normally.
It works good enough for cvsup, and I have high hopes I will be able to use it to bootstrap ada in gcc 3.2...

Comments on style and code welcome, I'm not that familiar with kernel coding.
(yep, exec_aout_translate.c is missing a BSD copyright, I'll add it before committing, oops)

A small glob of shell code would be needed in update.sh if we want 3.3 -> 3.4 updates to proceed more semlessly.

A bit like:
warning do you want to keep a.out compatility.

(process rc.conf to get to shlib_dirs)
(move a.out shlib_dirs)
(do the update, restore dirs if fail (?))

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 24 Apr 2003 13:12:33 -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
Do you need help?X

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 24 Apr 2003 13:12:38 -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 24 Apr 2003 13:12:55 -0000
@@ -12,7 +12,7 @@ MACHINE_ARCH= ${XMACHINE_ARCH} 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
+ vfs_syscalls_25.c vfs_syscalls_43.c vm_43.c exec_aout_translate.c

 # really, all machines where sizeof(int) != sizeof(long)  .if (${MACHINE_ARCH} != "alpha") && (${MACHINE_ARCH} != "sparc64") 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 24 Apr 2003 13:12:55 -0000
@@ -0,0 +1,138 @@
+#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+1];
+
+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)
+void
+aout_translate_init()
+{
+ memcpy(aout_translate_sysent, sysent, sizeof aout_translate_sysent);
+ printf("Copied %lu bytes\n", 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 24 Apr 2003 13:12:59 -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 24 Apr 2003 13:12:59 -0000
@@ -159,6 +159,31 @@ struct emul emul_native = { esigcode,

 };  
Do you need more help?X

+#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 */
Can we help you?X
tty_init(); /* initialise tty's */

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 24 Apr 2003 13:13:11 -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 24 Apr 2003 13:13:11 -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" Received on Thu Apr 24 09:23:01 2003

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:48:38 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library