Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/usermode Have the urkel maintain a 'cpu_lwp_inkerne...



details:   https://anonhg.NetBSD.org/src/rev/f83925e0b8db
branches:  trunk
changeset: 769291:f83925e0b8db
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Mon Sep 05 20:54:47 2011 +0000

description:
Have the urkel maintain a 'cpu_lwp_inkernel' variable and read it from the
urkelvisor to determine the origin of a syscall.

diffstat:

 sys/arch/usermode/dev/cpu.c             |   7 +++++--
 sys/arch/usermode/usermode/urkelvisor.c |  17 ++++++++++++++---
 2 files changed, 19 insertions(+), 5 deletions(-)

diffs (75 lines):

diff -r 585754601f18 -r f83925e0b8db sys/arch/usermode/dev/cpu.c
--- a/sys/arch/usermode/dev/cpu.c       Mon Sep 05 19:28:32 2011 +0000
+++ b/sys/arch/usermode/dev/cpu.c       Mon Sep 05 20:54:47 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.32 2011/09/05 19:28:32 reinoud Exp $ */
+/* $NetBSD: cpu.c,v 1.33 2011/09/05 20:54:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
 #include "opt_cpu.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.32 2011/09/05 19:28:32 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.33 2011/09/05 20:54:47 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -58,6 +58,8 @@
 #define cpu_unreachable()      do { thunk_abort(); } while (0)
 #endif
 
+int cpu_lwp_inkernel = 1;
+
 static int     cpu_match(device_t, cfdata_t, void *);
 static void    cpu_attach(device_t, device_t, void *);
 
@@ -186,6 +188,7 @@
 
        ci->ci_stash = oldlwp;
        curlwp = newlwp;
+       cpu_lwp_inkernel = curproc->p_vmspace->vm_map.pmap == pmap_kernel();
 
        if (oldpcb) {
                oldpcb->pcb_errno = thunk_geterrno();
diff -r 585754601f18 -r f83925e0b8db sys/arch/usermode/usermode/urkelvisor.c
--- a/sys/arch/usermode/usermode/urkelvisor.c   Mon Sep 05 19:28:32 2011 +0000
+++ b/sys/arch/usermode/usermode/urkelvisor.c   Mon Sep 05 20:54:47 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: urkelvisor.c,v 1.6 2011/09/05 18:16:34 jmcneill Exp $ */
+/* $NetBSD: urkelvisor.c,v 1.7 2011/09/05 20:54:48 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __NetBSD__
-__RCSID("$NetBSD: urkelvisor.c,v 1.6 2011/09/05 18:16:34 jmcneill Exp $");
+__RCSID("$NetBSD: urkelvisor.c,v 1.7 2011/09/05 20:54:48 jmcneill Exp $");
 #endif
 
 #include <sys/types.h>
@@ -114,9 +114,20 @@
 static int
 handle_syscall(struct reg_struct *puregs, pid_t urkel_pid)
 {
+       extern int cpu_lwp_inkernel;
        int sig = 0;
+       int inkernel;
 
-       if (R_PC(puregs) >= kmem_user_start && R_PC(puregs) < kmem_user_end) {
+       errno = 0;
+       inkernel = ptrace(PT_READ_D, urkel_pid, &cpu_lwp_inkernel, 0);
+       if (errno)
+               err(EXIT_FAILURE, "ptrace(PT_READ_D, %d, %p, 0) failed",
+                   urkel_pid, &cpu_lwp_inkernel);
+
+       //fprintf(stderr, "%s: pid=%d pc=%p inkernel=%d\n",
+       //    __func__, urkel_pid, (void *)R_PC(puregs), inkernel);
+
+       if (!inkernel) {
                fprintf(stderr, "caught syscall %d\n", (int)R_SYSCALL(puregs));
                errno = 0;
                ptrace(PT_SYSCALLEMU, urkel_pid, NULL, 0);



Home | Main Index | Thread Index | Old Index