|
|||||||||||
|
a.out dynamic binaries emulation
From: Marc Espie <espie(at)nerim.net>
Date: Thu Apr 24 2003 - 09:19:23 EDT
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.
Comments on style and code welcome, I'm not that familiar with kernel
coding.
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:
(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 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@@ -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
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 # 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@@ -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@@ -41,6 +41,9 @@ #include <uvm/uvm_extern.h>
#if defined(_KERN_DO_AOUT)
/*
if (error) kill_vmcmds(&epp->ep_vmcmds);+#endif
return error;
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 }; +#ifdef COMPAT_AOUT_TRANSLATE
/*
* 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");
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 fi 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 ''; thenIndex: 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 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 |
||||||||||
|
|||||||||||