From 4fe88fe6374ee0fd17b670ac28b16cf1c9790832 Mon Sep 17 00:00:00 2001 From: John Polstra Date: Sat, 3 Apr 1999 22:20:03 +0000 Subject: [PATCH] Restore support for executing BSD/OS binaries on the i386 by passing the address of the ps_strings structure to the process via %ebx. For other kinds of binaries, %ebx is still zeroed as before. Submitted by: Thomas Stephens Reviewed by: jdp --- sys/alpha/alpha/machdep.c | 4 ++-- sys/alpha/include/reg.h | 4 ++-- sys/amd64/amd64/machdep.c | 8 ++++++-- sys/amd64/include/reg.h | 4 ++-- sys/i386/i386/machdep.c | 8 ++++++-- sys/i386/include/reg.h | 4 ++-- sys/i386/svr4/svr4_machdep.c | 2 +- sys/kern/imgact_aout.c | 5 ++++- sys/kern/kern_exec.c | 8 +++++--- sys/pc98/i386/machdep.c | 5 +++-- sys/pc98/pc98/machdep.c | 5 +++-- sys/sys/imgact.h | 3 ++- 12 files changed, 38 insertions(+), 22 deletions(-) diff --git a/sys/alpha/alpha/machdep.c b/sys/alpha/alpha/machdep.c index 9dfbb8f95ef8..f513a6326f96 100644 --- a/sys/alpha/alpha/machdep.c +++ b/sys/alpha/alpha/machdep.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: machdep.c,v 1.33 1999/02/27 18:41:40 dfr Exp $ + * $Id: machdep.c,v 1.34 1999/03/06 04:46:10 wollman Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -1508,7 +1508,7 @@ cpu_halt(void) * Clear registers on exec */ void -setregs(struct proc *p, u_long entry, u_long stack) +setregs(struct proc *p, u_long entry, u_long stack, u_long ps_strings) { struct trapframe *tfp = p->p_md.md_tf; diff --git a/sys/alpha/include/reg.h b/sys/alpha/include/reg.h index 3bbc69f41eb1..47e18c8d6507 100644 --- a/sys/alpha/include/reg.h +++ b/sys/alpha/include/reg.h @@ -1,4 +1,4 @@ -/* $Id: reg.h,v 1.1.1.1 1998/03/09 05:43:16 jb Exp $ */ +/* $Id: reg.h,v 1.2 1998/06/10 10:55:26 dfr Exp $ */ /* From: NetBSD: reg.h,v 1.3 1997/04/06 08:47:40 cgd Exp */ /* @@ -94,7 +94,7 @@ struct fpreg { #ifdef KERNEL void restorefpstate __P((struct fpreg *)); void savefpstate __P((struct fpreg *)); -void setregs __P((struct proc *, u_long, u_long)); +void setregs __P((struct proc *, u_long, u_long, u_long)); #endif #endif /* _ALPHA_REG_H_ */ diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 41584f514cf7..6ed318243bee 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.326 1999/02/13 17:45:15 bde Exp $ + * $Id: machdep.c,v 1.327 1999/03/06 04:46:18 wollman Exp $ */ #include "apm.h" @@ -806,10 +806,11 @@ cpu_halt(void) * Clear registers on exec */ void -setregs(p, entry, stack) +setregs(p, entry, stack, ps_strings) struct proc *p; u_long entry; u_long stack; + u_long ps_strings; { struct trapframe *regs = p->p_md.md_regs; struct pcb *pcb = &p->p_addr->u_pcb; @@ -836,6 +837,9 @@ setregs(p, entry, stack) regs->tf_es = _udatasel; regs->tf_cs = _ucodesel; + /* PS_STRINGS value for BSD/OS binaries. It is 0 for non-BSD/OS. */ + regs->tf_ebx = ps_strings; + /* reset %fs and %gs as well */ pcb->pcb_fs = _udatasel; pcb->pcb_gs = _udatasel; diff --git a/sys/amd64/include/reg.h b/sys/amd64/include/reg.h index 3e97fc1aa6fc..28466a838bc8 100644 --- a/sys/amd64/include/reg.h +++ b/sys/amd64/include/reg.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)reg.h 5.5 (Berkeley) 1/18/91 - * $Id: reg.h,v 1.15 1997/06/07 04:36:06 bde Exp $ + * $Id: reg.h,v 1.16 1998/09/14 22:43:40 jdp Exp $ */ #ifndef _MACHINE_REG_H_ @@ -124,7 +124,7 @@ struct fpreg { */ int set_fpregs __P((struct proc *, struct fpreg *)); int set_regs __P((struct proc *p, struct reg *regs)); -void setregs __P((struct proc *, u_long, u_long)); +void setregs __P((struct proc *, u_long, u_long, u_long)); #endif #endif /* !_MACHINE_REG_H_ */ diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index 41584f514cf7..6ed318243bee 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.326 1999/02/13 17:45:15 bde Exp $ + * $Id: machdep.c,v 1.327 1999/03/06 04:46:18 wollman Exp $ */ #include "apm.h" @@ -806,10 +806,11 @@ cpu_halt(void) * Clear registers on exec */ void -setregs(p, entry, stack) +setregs(p, entry, stack, ps_strings) struct proc *p; u_long entry; u_long stack; + u_long ps_strings; { struct trapframe *regs = p->p_md.md_regs; struct pcb *pcb = &p->p_addr->u_pcb; @@ -836,6 +837,9 @@ setregs(p, entry, stack) regs->tf_es = _udatasel; regs->tf_cs = _ucodesel; + /* PS_STRINGS value for BSD/OS binaries. It is 0 for non-BSD/OS. */ + regs->tf_ebx = ps_strings; + /* reset %fs and %gs as well */ pcb->pcb_fs = _udatasel; pcb->pcb_gs = _udatasel; diff --git a/sys/i386/include/reg.h b/sys/i386/include/reg.h index 3e97fc1aa6fc..28466a838bc8 100644 --- a/sys/i386/include/reg.h +++ b/sys/i386/include/reg.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)reg.h 5.5 (Berkeley) 1/18/91 - * $Id: reg.h,v 1.15 1997/06/07 04:36:06 bde Exp $ + * $Id: reg.h,v 1.16 1998/09/14 22:43:40 jdp Exp $ */ #ifndef _MACHINE_REG_H_ @@ -124,7 +124,7 @@ struct fpreg { */ int set_fpregs __P((struct proc *, struct fpreg *)); int set_regs __P((struct proc *p, struct reg *regs)); -void setregs __P((struct proc *, u_long, u_long)); +void setregs __P((struct proc *, u_long, u_long, u_long)); #endif #endif /* !_MACHINE_REG_H_ */ diff --git a/sys/i386/svr4/svr4_machdep.c b/sys/i386/svr4/svr4_machdep.c index 381a9bc7d59d..a94f45e78cf8 100644 --- a/sys/i386/svr4/svr4_machdep.c +++ b/sys/i386/svr4/svr4_machdep.c @@ -95,7 +95,7 @@ svr4_setregs(p, epp, stack) register struct pcb *pcb = &p->p_addr->u_pcb; pcb->pcb_savefpu.sv_env.en_cw = __SVR4_NPXCW__; - setregs(p, epp, stack); + setregs(p, epp, stack, 0UL); } #endif /* __NetBSD__ */ diff --git a/sys/kern/imgact_aout.c b/sys/kern/imgact_aout.c index 871efe8c1b79..0092aeb0e053 100644 --- a/sys/kern/imgact_aout.c +++ b/sys/kern/imgact_aout.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: imgact_aout.c,v 1.47 1999/03/04 18:04:40 alc Exp $ + * $Id: imgact_aout.c,v 1.48 1999/03/10 07:07:42 alc Exp $ */ #include @@ -119,6 +119,9 @@ exec_aout_imgact(imgp) case QMAGIC: virtual_offset = PAGE_SIZE; file_offset = 0; + /* Pass PS_STRINGS for BSD/OS binaries only. */ + if (N_GETMID(*a_out) == MID_ZERO) + imgp->ps_strings = PS_STRINGS; break; default: /* NetBSD compatibility */ diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index f961a3a9eb40..c96055d90bd3 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: kern_exec.c,v 1.95 1999/01/28 00:57:47 dillon Exp $ + * $Id: kern_exec.c,v 1.96 1999/02/19 14:25:34 luoqi Exp $ */ #include @@ -117,6 +117,7 @@ execve(p, uap) imgp->auxargs = NULL; imgp->vp = NULL; imgp->firstpage = NULL; + imgp->ps_strings = 0; /* * Allocate temporary demand zeroed space for argument and @@ -309,8 +310,9 @@ interpret: /* clear "fork but no exec" flag, as we _are_ execing */ p->p_acflag &= ~AFORK; - /* Set entry address */ - setregs(p, imgp->entry_addr, (u_long)(uintptr_t)stack_base); + /* Set values passed into the program in registers. */ + setregs(p, imgp->entry_addr, (u_long)(uintptr_t)stack_base, + imgp->ps_strings); exec_fail_dealloc: diff --git a/sys/pc98/i386/machdep.c b/sys/pc98/i386/machdep.c index bd513836a456..812c577f9736 100644 --- a/sys/pc98/i386/machdep.c +++ b/sys/pc98/i386/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.109 1999/02/16 11:07:06 kato Exp $ + * $Id: machdep.c,v 1.110 1999/03/06 09:43:01 kato Exp $ */ #include "apm.h" @@ -819,10 +819,11 @@ cpu_halt(void) * Clear registers on exec */ void -setregs(p, entry, stack) +setregs(p, entry, stack, ps_strings) struct proc *p; u_long entry; u_long stack; + u_long ps_strings; { struct trapframe *regs = p->p_md.md_regs; struct pcb *pcb = &p->p_addr->u_pcb; diff --git a/sys/pc98/pc98/machdep.c b/sys/pc98/pc98/machdep.c index bd513836a456..812c577f9736 100644 --- a/sys/pc98/pc98/machdep.c +++ b/sys/pc98/pc98/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.109 1999/02/16 11:07:06 kato Exp $ + * $Id: machdep.c,v 1.110 1999/03/06 09:43:01 kato Exp $ */ #include "apm.h" @@ -819,10 +819,11 @@ cpu_halt(void) * Clear registers on exec */ void -setregs(p, entry, stack) +setregs(p, entry, stack, ps_strings) struct proc *p; u_long entry; u_long stack; + u_long ps_strings; { struct trapframe *regs = p->p_md.md_regs; struct pcb *pcb = &p->p_addr->u_pcb; diff --git a/sys/sys/imgact.h b/sys/sys/imgact.h index 04bafbadd31f..d206f268a18d 100644 --- a/sys/sys/imgact.h +++ b/sys/sys/imgact.h @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: imgact.h,v 1.17 1998/03/02 05:47:43 peter Exp $ + * $Id: imgact.h,v 1.18 1998/12/30 10:38:59 dfr Exp $ */ #ifndef _SYS_IMGACT_H_ @@ -54,6 +54,7 @@ struct image_params { void *auxargs; /* ELF Auxinfo structure pointer */ struct vm_page *firstpage; /* first page that we mapped */ char *fname; /* pointer to filename of executable (user space) */ + unsigned long ps_strings; /* PS_STRINGS for BSD/OS binaries */ }; #ifdef KERNEL