Source-Changes-HG archive

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

[src/trunk]: src/sys/compat/irix IRIX provide a signal trampoline in libc, we...



details:   https://anonhg.NetBSD.org/src/rev/ea6acd7c1256
branches:  trunk
changeset: 525660:ea6acd7c1256
user:      manu <manu%NetBSD.org@localhost>
date:      Sun Apr 14 21:50:49 2002 +0000

description:
IRIX provide a signal trampoline in libc, we now use it.
- the signal trampoline address is given to the kernel by a sigaction()
  fourth argument
- we introduce an irix_emuldata structure to keep track of the signal
  trampoline address
- we don't support per-sigaction signal trampolines, we only do per-process
- now that we use the IRIX libc signal trampoline, we do not have to handle
  the errno update from the signal trampoline
- it is possible that IRIX 5 signal delivery works too, since theses binaries
  will come with their own signal trampoline

diffstat:

 sys/compat/irix/irix_exec.c        |   73 ++++++++++++--
 sys/compat/irix/irix_exec.h        |    7 +-
 sys/compat/irix/irix_signal.c      |  180 +++++++++++++++++++++++++++---------
 sys/compat/irix/irix_signal.h      |    7 +-
 sys/compat/irix/irix_syscall.h     |    6 +-
 sys/compat/irix/irix_syscallargs.h |   13 ++-
 sys/compat/irix/irix_syscalls.c    |    6 +-
 sys/compat/irix/irix_sysent.c      |   10 +-
 sys/compat/irix/syscalls.master    |    6 +-
 9 files changed, 232 insertions(+), 76 deletions(-)

diffs (truncated from 570 to 300 lines):

diff -r b97dee3e8aa5 -r ea6acd7c1256 sys/compat/irix/irix_exec.c
--- a/sys/compat/irix/irix_exec.c       Sun Apr 14 21:44:22 2002 +0000
+++ b/sys/compat/irix/irix_exec.c       Sun Apr 14 21:50:49 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: irix_exec.c,v 1.12 2002/02/21 21:53:00 manu Exp $ */
+/*     $NetBSD: irix_exec.c,v 1.13 2002/04/14 21:50:49 manu Exp $ */
 
 /*-
  * Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: irix_exec.c,v 1.12 2002/02/21 21:53:00 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: irix_exec.c,v 1.13 2002/04/14 21:50:49 manu Exp $");
 
 #ifndef ELFSIZE
 #define ELFSIZE                32      /* XXX should die */
@@ -61,10 +61,13 @@
 #include <compat/irix/irix_errno.h>
 
 static void setregs_n32 __P((struct proc *, struct exec_package *, u_long));
+static void irix_e_proc_exec __P((struct proc *, struct exec_package *));
+static void irix_e_proc_fork __P((struct proc *, struct proc *));
+static void irix_e_proc_exit __P((struct proc *));
+static void irix_e_proc_init __P((struct proc *, struct vmspace *));
 
 extern struct sysent irix_sysent[];
 extern const char * const irix_syscallnames[];
-extern char irix_sigcode[], irix_esigcode[];
 
 #ifndef __HAVE_SYSCALL_INTERN
 void irix_syscall __P((void));
@@ -89,12 +92,12 @@
 #endif
        irix_sendsig,
        trapsignal,
-       irix_sigcode,
-       irix_esigcode,
-       setregs,
        NULL,
        NULL,
-       NULL,
+       setregs,
+       irix_e_proc_exec,
+       irix_e_proc_fork,
+       irix_e_proc_exit,
 #ifdef __HAVE_SYSCALL_INTERN
        irix_syscall_intern,
 #else
@@ -119,12 +122,12 @@
 #endif
        irix_sendsig,
        trapsignal,
-       irix_sigcode,
-       irix_esigcode,
-       setregs_n32,
        NULL,
        NULL,
-       NULL,
+       setregs_n32,
+       irix_e_proc_exec,
+       irix_e_proc_fork,
+       irix_e_proc_exit,
 #ifdef __HAVE_SYSCALL_INTERN
        irix_syscall_intern,
 #else
@@ -237,3 +240,51 @@
 
        return;
 }
+
+/*
+ * per-process emuldata allocation
+ */
+static void
+irix_e_proc_init(p, vmspace)
+       struct proc *p;
+       struct vmspace *vmspace;
+{
+       if (!p->p_emuldata)
+               MALLOC(p->p_emuldata, void *, sizeof(struct irix_emuldata),
+                       M_EMULDATA, M_WAITOK | M_ZERO);
+}  
+
+/* 
+ * exec() hook used to allocate per process structures
+ */
+static void
+irix_e_proc_exec(p, epp)
+       struct proc *p;
+       struct exec_package *epp;
+{
+       irix_e_proc_init(p, p->p_vmspace);
+}
+
+/*
+ * exit() hook used to free per process data structures
+ */
+static void
+irix_e_proc_exit(p)
+       struct proc *p;
+{
+       FREE(p->p_emuldata, M_EMULDATA);
+       p->p_emuldata = NULL;
+}
+
+/*
+ * fork() hook used to allocate per process structures
+ */
+static void
+irix_e_proc_fork(p, parent)
+        struct proc *p, *parent;
+{
+        p->p_emuldata = NULL;
+
+       /* Use parent's vmspace beacause our vmspace may not be setup yet) */
+        irix_e_proc_init(p, parent->p_vmspace);
+}
diff -r b97dee3e8aa5 -r ea6acd7c1256 sys/compat/irix/irix_exec.h
--- a/sys/compat/irix/irix_exec.h       Sun Apr 14 21:44:22 2002 +0000
+++ b/sys/compat/irix/irix_exec.h       Sun Apr 14 21:50:49 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: irix_exec.h,v 1.5 2002/02/21 21:53:00 manu Exp $ */
+/*     $NetBSD: irix_exec.h,v 1.6 2002/04/14 21:50:50 manu Exp $ */
 
 /*-
  * Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
@@ -43,6 +43,11 @@
 #include <sys/exec.h>
 #include <sys/exec_elf.h>
 
+/* IRIX specific per-process data */
+struct irix_emuldata {
+       void *ied_sigtramp;     /* Address of signal trampoline */
+};
+
 /* e_flags used by IRIX for ABI selection */
 #define IRIX_EF_IRIX_ABI64     0x00000010
 #define IRIX_EF_IRIX_ABIN32    0x00000020
diff -r b97dee3e8aa5 -r ea6acd7c1256 sys/compat/irix/irix_signal.c
--- a/sys/compat/irix/irix_signal.c     Sun Apr 14 21:44:22 2002 +0000
+++ b/sys/compat/irix/irix_signal.c     Sun Apr 14 21:50:49 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: irix_signal.c,v 1.13 2002/04/13 10:53:00 manu Exp $ */
+/*     $NetBSD: irix_signal.c,v 1.14 2002/04/14 21:50:50 manu Exp $ */
 
 /*-
  * Copyright (c) 1994, 2001-2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: irix_signal.c,v 1.13 2002/04/13 10:53:00 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: irix_signal.c,v 1.14 2002/04/14 21:50:50 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/signal.h>
@@ -64,6 +64,7 @@
 #include <compat/svr4/svr4_syscallargs.h>
 
 #include <compat/irix/irix_signal.h>
+#include <compat/irix/irix_exec.h>
 #include <compat/irix/irix_syscallargs.h>
 
 extern const int native_to_svr4_signo[];
@@ -181,7 +182,6 @@
        u_long code;
 {
        struct proc *p = curproc;
-       void *fp;
        void *sp;
        struct frame *f;
        int onstack;
@@ -226,41 +226,16 @@
        else
                irix_set_sigcontext(&sf.isf_ctx.isc, mask, code, p);
        
-       sf.isf_signo = native_to_svr4_signo[sig];
-
        /*
-        * XXX On, IRIX, the sigframe holds a pointer to 
-        * errno in userspace. This is used by the signal
-        * trampoline. No idea how to emulate this for now...
-        */
-       /* sf.isf_uep = NULL; */
-       /* sf.isf_errno = 0 */
-
-       /*
-        * Compute the new stack address after copying sigframe (hold by sp),
-        * and the address of the sigcontext/ucontext (hold by fp)
+        * Compute the new stack address after copying sigframe
         */
-       sp = (void *)((unsigned long)sp - sizeof(sf));
+       sp = (void *)((unsigned long)sp - sizeof(sf.isf_ctx));
        sp = (void *)((unsigned long)sp & ~0xfUL); /* 16 bytes alignement */
-       fp = (void *)((unsigned long)sp + sizeof(sf) - sizeof(sf.isf_ctx));
-
-       
-       /* 
-        * If SA_SIGINFO is used, then ucp is used, and scp = NULL, 
-        * if it is not used, then scp is used, and ucp = scp
-        */
-       if (SIGACTION(p, sig).sa_flags & SA_SIGINFO) {
-               sf.isf_ucp = (struct irix_ucontext *)fp;
-               sf.isf_scp = NULL;
-       } else {
-               sf.isf_ucp = (struct irix_ucontext *)fp;
-               sf.isf_scp = (struct irix_sigcontext *)fp;
-       }
 
        /*
         * Install the sigframe onto the stack
         */
-       error = copyout(&sf, sp, sizeof(sf));
+       error = copyout(&sf.isf_ctx, sp, sizeof(sf.isf_ctx));
        if (error != 0) {
                /*
                 * Process has trashed its stack; give it an illegal
@@ -274,24 +249,37 @@
        }
 
        /* 
-        * Set up signal handler arguments. 
+        * Set up signal trampoline arguments. 
         */
        f->f_regs[A0] = native_to_svr4_signo[sig];      /* signo/signo */
        f->f_regs[A1] = 0;                      /* code/siginfo */
-       f->f_regs[A2] = (unsigned long)fp;      /* sigcontext/ucontext */
+       f->f_regs[A2] = (unsigned long)sp;      /* sigcontext/ucontext */
+       f->f_regs[A3] = (unsigned long)catcher; /* signal handler address */
 
+       /* 
+        * When siginfo is selected, the higher bit of A0 is set
+        * This is how the signal trampoline is able to discover if
+        * A2 points to a struct irix_sigcontext or struct irix_ucontext.
+        */
+       if (SIGACTION(p, sig).sa_flags & SA_SIGINFO) 
+               f->f_regs[A0] |= 0x80000000;
+
+       /*
+        * Set up the new stack pointer
+        */
+       f->f_regs[SP] = (unsigned long)sp;
 #ifdef DEBUG_IRIX
-       printf("sigcontext is at %p, stack pointer at %p\n", fp, sp);
+       printf("stack pointer at %p\n", sp);
 #endif /* DEBUG_IRIX */
 
        /* 
-        * Set up the registers to return to sigcode. 
+        * Set up the registers to jump to the signal trampoline 
+        * on return to userland.
+        * see irix_sys_sigaction for details about how we get 
+        * the signal trampoline address.
         */
-       f->f_regs[RA] = (unsigned long)p->p_sigctx.ps_sigcode;
-       f->f_regs[SP] = (unsigned long)sp;
-       f->f_regs[T9] = (unsigned long)catcher;
-       f->f_regs[A3] = (unsigned long)catcher;
-       f->f_regs[PC] = (unsigned long)catcher;
+       f->f_regs[PC] = (unsigned long)
+           (((struct irix_emuldata *)(p->p_emuldata))->ied_sigtramp);
 
        /* 
         * Remember that we're now on the signal stack. 
@@ -373,7 +361,7 @@
 #endif
        f = (struct frame *)p->p_md.md_regs;
        /*
-        * Build stack frame for signal trampoline.
+        * Save general purpose registers
         */
        native_to_irix_sigset(mask, &ucp->iuc_sigmask);
        memcpy(&ucp->iuc_mcontext.svr4___gregs, 
@@ -383,8 +371,6 @@
        ucp->iuc_mcontext.svr4___gregs[IRIX_CTX_MDHI] = f->f_regs[MULHI];
        ucp->iuc_mcontext.svr4___gregs[IRIX_CTX_EPC] = f->f_regs[PC];
 
-       ucp->iuc_flags = IRIX_UC_SIGMASK | IRIX_UC_MCONTEXT;
-
        /* 
         * Save the floating-pointstate, if necessary, then copy it. 
         */
@@ -404,7 +390,27 @@
            &p->p_addr->u_pcb.pcb_fpregs, 
            sizeof(ucp->iuc_mcontext.svr4___fpregs));
 #endif 
-       /* XXX Save signal stack */
+       /* 
+        * Save signal stack 
+        */
+       ucp->iuc_stack.ss_sp = p->p_sigctx.ps_sigstk.ss_sp;
+       ucp->iuc_stack.ss_size = p->p_sigctx.ps_sigstk.ss_size;
+
+       if (p->p_sigctx.ps_sigstk.ss_flags & SS_ONSTACK)
+               ucp->iuc_stack.ss_flags |= IRIX_SS_ONSTACK;
+       else
+               ucp->iuc_stack.ss_flags &= ~IRIX_SS_ONSTACK;
+



Home | Main Index | Thread Index | Old Index