Source-Changes-HG archive

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

[src/trunk]: src/sys/compat Start to implement another strange feature: signa...



details:   https://anonhg.NetBSD.org/src/rev/b185e7b5c031
branches:  trunk
changeset: 555524:b185e7b5c031
user:      manu <manu%NetBSD.org@localhost>
date:      Thu Nov 20 07:12:34 2003 +0000

description:
Start to implement another strange feature: signals as Mach software
exceptions. This can be requested with ptrace, and cause signals to
be transformed into a particular kind of exception.

diffstat:

 sys/compat/darwin/darwin_exec.h        |    5 +-
 sys/compat/darwin/darwin_ptrace.c      |  156 ++++++++++++++++++++++++++
 sys/compat/darwin/darwin_ptrace.h      |   61 ++++++++++
 sys/compat/darwin/darwin_signal.c      |   22 +++-
 sys/compat/darwin/darwin_syscall.h     |   23 +++-
 sys/compat/darwin/darwin_syscallargs.h |  191 ++++++++++++++++++++++++++++++++-
 sys/compat/darwin/darwin_syscalls.c    |    4 +-
 sys/compat/darwin/darwin_sysent.c      |    8 +-
 sys/compat/darwin/files.darwin         |    3 +-
 sys/compat/darwin/syscalls.master      |    6 +-
 sys/compat/mach/mach_notify.c          |   46 +++---
 sys/compat/mach/mach_notify.h          |    8 +-
 sys/compat/mach/mach_syscall.h         |    2 +-
 sys/compat/mach/mach_syscallargs.h     |   33 +++++-
 sys/compat/mach/mach_syscalls.c        |    4 +-
 sys/compat/mach/mach_sysent.c          |    4 +-
 sys/compat/mach/mach_task.c            |    8 +-
 17 files changed, 529 insertions(+), 55 deletions(-)

diffs (truncated from 1183 to 300 lines):

diff -r de40d72c0c69 -r b185e7b5c031 sys/compat/darwin/darwin_exec.h
--- a/sys/compat/darwin/darwin_exec.h   Thu Nov 20 07:08:02 2003 +0000
+++ b/sys/compat/darwin/darwin_exec.h   Thu Nov 20 07:12:34 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_exec.h,v 1.8 2003/10/25 10:43:45 manu Exp $ */
+/*     $NetBSD: darwin_exec.h,v 1.9 2003/11/20 07:12:34 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -50,8 +50,11 @@
        pid_t ded_fakepid;
        dev_t ded_wsdev;        /* display to restore on exit */
        int *ded_hidsystem_finished;    /* iohidsystem thread finished flag */
+       int ded_flags;          /* flags, see below */
 };
 
+#define DARWIN_DED_SIGEXC      1       /* Mach exceptions instead of signals */
+
 int exec_darwin_copyargs(struct proc *, struct exec_package *, 
     struct ps_strings *, char **, void *);
 int exec_darwin_probe(char **);
diff -r de40d72c0c69 -r b185e7b5c031 sys/compat/darwin/darwin_ptrace.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/darwin/darwin_ptrace.c Thu Nov 20 07:12:34 2003 +0000
@@ -0,0 +1,156 @@
+/*     $NetBSD: darwin_ptrace.c,v 1.1 2003/11/20 07:12:34 manu Exp $ */
+
+/*-
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * 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. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: darwin_ptrace.c,v 1.1 2003/11/20 07:12:34 manu Exp $");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mount.h>
+#include <sys/proc.h>
+#include <sys/ptrace.h>
+#include <sys/sa.h>
+
+#include <sys/syscallargs.h>
+
+#include <compat/mach/mach_types.h>
+#include <compat/mach/mach_vm.h>
+
+#include <compat/darwin/darwin_exec.h>
+#include <compat/darwin/darwin_ptrace.h>
+#include <compat/darwin/darwin_syscallargs.h>
+
+#if 0
+#define ISSET(t, f)     ((t) & (f))
+
+static inline int ptrace_sanity_check(struct proc *, struct proc *);
+
+/* Sanity checks copied from native sys_ptrace() */
+static inline int 
+ptrace_sanity_check(p, t)
+       struct proc *p;
+       struct proc *t;
+{
+       /*
+        * You can't do what you want to the process if:
+        *      (1) It's not being traced at all,
+        */
+       if (!ISSET(t->p_flag, P_TRACED))
+               return (EPERM);
+
+       /*
+        *      (2) it's being traced by procfs (which has
+        *          different signal delivery semantics),
+        */
+       if (ISSET(t->p_flag, P_FSTRACE))
+               return (EBUSY);
+
+       /*
+        *      (3) it's not being traced by _you_, or
+        */
+       if (t->p_pptr != p)
+               return (EBUSY);
+
+       /*
+        *      (4) it's not currently stopped.
+        */
+       if (t->p_stat != SSTOP || !ISSET(t->p_flag, P_WAITED))
+               return (EBUSY);
+
+       return 0;
+}
+#endif
+
+int
+darwin_sys_ptrace(l, v, retval)
+       struct lwp *l;
+       void *v;
+       register_t *retval;
+{
+       struct darwin_sys_ptrace_args /* {
+               syscallarg(int) req;
+               syscallarg(pid_t) pid;
+               syscallarg(caddr_t) addr;
+               syscallarg(int) data;
+       } */ *uap = v;
+       int req = SCARG(uap, req);
+       struct proc *p = l->l_proc;
+       struct darwin_emuldata *ded = NULL;
+       struct proc *t;                 /* target process */
+       int error;
+
+       switch (req) {
+       case DARWIN_PT_SIGEXC:
+               ded = (struct darwin_emuldata *)p->p_emuldata;
+               ded->ded_flags |= DARWIN_DED_SIGEXC;
+               break;
+
+       case DARWIN_PT_DETACH:
+               if ((t = pfind(SCARG(uap, pid))) == NULL)
+                       return (ESRCH);
+
+               /* 
+                * Clear signal-as-exceptions flag if detaching is 
+                * successful and if it is a Darwin process.
+                */
+               if (((error = sys_ptrace(l, v, retval)) == 0) &&
+                   (t->p_emul != &emul_darwin)) {
+                       ded = (struct darwin_emuldata *)t->p_emuldata;
+                       ded->ded_flags &= ~DARWIN_DED_SIGEXC;
+               }
+               break;
+
+       case DARWIN_PT_READ_U:
+       case DARWIN_PT_WRITE_U:
+       case DARWIN_PT_STEP:
+       case DARWIN_PT_THUPDATE:
+       case DARWIN_PT_ATTACHEXC:
+       case DARWIN_PT_FORCEQUOTA:
+       case DARWIN_PT_DENY_ATTACH:
+               printf("darwin_sys_ptrace: unimplemented command %d\n", req);
+               break;
+
+       /* The other ptrace commands are the same on NetBSD */
+       default:
+               return sys_ptrace(l, v, retval);
+               break;
+       }
+       
+       return 0;
+}
diff -r de40d72c0c69 -r b185e7b5c031 sys/compat/darwin/darwin_ptrace.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/darwin/darwin_ptrace.h Thu Nov 20 07:12:34 2003 +0000
@@ -0,0 +1,61 @@
+/*     $NetBSD: darwin_ptrace.h,v 1.1 2003/11/20 07:12:34 manu Exp $ */
+
+/*-
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus
+ *
+ * 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. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+#ifndef        _DARWIN_PTRACE_H_
+#define        _DARWIN_PTRACE_H_
+
+#define DARWIN_PT_TRACE_ME     0
+#define DARWIN_PT_READ_I       1
+#define DARWIN_PT_READ_D       2
+#define DARWIN_PT_READ_U       3
+#define DARWIN_PT_WRITE_I      4
+#define DARWIN_PT_WRITE_D      5
+#define DARWIN_PT_WRITE_U      6
+#define DARWIN_PT_CONTINUE     7
+#define DARWIN_PT_KILL         8
+#define DARWIN_PT_STEP         9
+#define DARWIN_PT_ATTACH       10
+#define DARWIN_PT_DETACH       11
+#define DARWIN_PT_SIGEXC       12
+#define DARWIN_PT_THUPDATE     13
+#define DARWIN_PT_ATTACHEXC    14
+
+#define DARWIN_PT_FORCEQUOTA   30
+#define DARWIN_PT_DENY_ATTACH  31
+
+#endif /* _DARWIN_PTRACE_H_ */
diff -r de40d72c0c69 -r b185e7b5c031 sys/compat/darwin/darwin_signal.c
--- a/sys/compat/darwin/darwin_signal.c Thu Nov 20 07:08:02 2003 +0000
+++ b/sys/compat/darwin/darwin_signal.c Thu Nov 20 07:12:34 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_signal.c,v 1.8 2003/11/17 01:52:14 manu Exp $ */
+/*     $NetBSD: darwin_signal.c,v 1.9 2003/11/20 07:12:34 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_signal.c,v 1.8 2003/11/17 01:52:14 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_signal.c,v 1.9 2003/11/20 07:12:34 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -55,6 +55,7 @@
 #include <compat/mach/mach_port.h>
 #include <compat/mach/mach_notify.h>
 
+#include <compat/darwin/darwin_exec.h>
 #include <compat/darwin/darwin_signal.h>
 #include <compat/darwin/darwin_syscallargs.h>
 
@@ -129,9 +130,24 @@
        struct lwp *l;
        const struct ksiginfo *ksi;
 {
+       struct darwin_emuldata *ded;
+       int code[2];
+
+       /* 
+        * Send signals as software exception if the process requested that
+        * XXX this skips various checks (signal masks...)
+        */
+       ded = (struct darwin_emuldata *)l->l_proc->p_emuldata;
+       if (ded->ded_flags & DARWIN_DED_SIGEXC) {
+               code[0] = MACH_SOFT_SIGNAL;
+               code[1] = ksi->ksi_signo;
+               mach_exception(l, MACH_EXC_SOFTWARE, code);
+               return;
+       }
+
        /* 
         * If mach_trapsignal1 returns 0, the exception was intercepted at
-        * the Mach level, n signal is to be sent. if it returns an error,
+        * the Mach level, no signal is to be sent. if it returns an error,
         * we call native trapsignal to fire a UNIX signal.
         */
        if (mach_trapsignal1(l, ksi) != 0)
diff -r de40d72c0c69 -r b185e7b5c031 sys/compat/darwin/darwin_syscall.h
--- a/sys/compat/darwin/darwin_syscall.h        Thu Nov 20 07:08:02 2003 +0000



Home | Main Index | Thread Index | Old Index