Module Name: src
Committed By: jmcneill
Date: Mon Sep 5 20:54:48 UTC 2011
Modified Files:
src/sys/arch/usermode/dev: cpu.c
src/sys/arch/usermode/usermode: urkelvisor.c
Log Message:
Have the urkel maintain a 'cpu_lwp_inkernel' variable and read it from the
urkelvisor to determine the origin of a syscall.
To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/usermode/dev/cpu.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/usermode/usermode/urkelvisor.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/usermode/dev/cpu.c
diff -u src/sys/arch/usermode/dev/cpu.c:1.32 src/sys/arch/usermode/dev/cpu.c:1.33
--- src/sys/arch/usermode/dev/cpu.c:1.32 Mon Sep 5 19:28:32 2011
+++ src/sys/arch/usermode/dev/cpu.c Mon Sep 5 20:54:47 2011
@@ -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 <[email protected]>
@@ -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();
Index: src/sys/arch/usermode/usermode/urkelvisor.c
diff -u src/sys/arch/usermode/usermode/urkelvisor.c:1.6 src/sys/arch/usermode/usermode/urkelvisor.c:1.7
--- src/sys/arch/usermode/usermode/urkelvisor.c:1.6 Mon Sep 5 18:16:34 2011
+++ src/sys/arch/usermode/usermode/urkelvisor.c Mon Sep 5 20:54:48 2011
@@ -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 <[email protected]>
@@ -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);