Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/usermode/usermode rearrange ptrace_getregs and have...
details: https://anonhg.NetBSD.org/src/rev/0f87c8c3ecc9
branches: trunk
changeset: 769277:0f87c8c3ecc9
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Mon Sep 05 13:28:17 2011 +0000
description:
rearrange ptrace_getregs and have the child raise(SIGSTOP) instead of wait()
diffstat:
sys/arch/usermode/usermode/urkelvisor.c | 29 +++++++++++++++--------------
1 files changed, 15 insertions(+), 14 deletions(-)
diffs (95 lines):
diff -r cd9cd8d42374 -r 0f87c8c3ecc9 sys/arch/usermode/usermode/urkelvisor.c
--- a/sys/arch/usermode/usermode/urkelvisor.c Mon Sep 05 12:49:33 2011 +0000
+++ b/sys/arch/usermode/usermode/urkelvisor.c Mon Sep 05 13:28:17 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: urkelvisor.c,v 1.4 2011/09/05 12:49:33 jmcneill Exp $ */
+/* $NetBSD: urkelvisor.c,v 1.5 2011/09/05 13:28:17 jmcneill Exp $ */
/*-
* Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -32,13 +32,14 @@
#include <sys/cdefs.h>
#ifdef __NetBSD__
-__RCSID("$NetBSD: urkelvisor.c,v 1.4 2011/09/05 12:49:33 jmcneill Exp $");
+__RCSID("$NetBSD: urkelvisor.c,v 1.5 2011/09/05 13:28:17 jmcneill Exp $");
#endif
#include <sys/types.h>
#include <sys/param.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
+#include <sys/syscall.h>
#ifdef __linux__
#include <sys/user.h>
@@ -50,6 +51,7 @@
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
+#include <signal.h>
#include <unistd.h>
#include "../include/urkelvisor.h"
@@ -98,27 +100,24 @@
static void
ptrace_getregs(pid_t urkel_pid, struct reg_struct *puregs)
{
+ errno = 0;
#ifdef __linux__
ptrace(PT_GETREGS, urkel_pid, NULL, puregs);
#else
ptrace(PT_GETREGS, urkel_pid, puregs, 0);
#endif
+ if (errno)
+ err(EXIT_FAILURE, "ptrace(PT_GETREGS, %d, &uregs, 0) failed",
+ urkel_pid);
}
static int
-handle_syscall(pid_t urkel_pid)
+handle_syscall(struct reg_struct *puregs, pid_t urkel_pid)
{
- struct reg_struct uregs;
int sig = 0;
- errno = 0;
- ptrace_getregs(urkel_pid, &uregs);
- if (errno)
- err(EXIT_FAILURE, "ptrace(PT_GETREGS, %d, &uregs, 0) failed",
- urkel_pid);
-
- if (R_PC(&uregs) >= kmem_user_start && R_PC(&uregs) < kmem_user_end) {
- fprintf(stderr, "caught syscall %d\n", (int)R_SYSCALL(&uregs));
+ if (R_PC(puregs) >= kmem_user_start && R_PC(puregs) < kmem_user_end) {
+ fprintf(stderr, "caught syscall %d\n", (int)R_SYSCALL(puregs));
errno = 0;
ptrace(PT_SYSCALLEMU, urkel_pid, NULL, 0);
if (errno)
@@ -134,6 +133,7 @@
static int
urkelvisor(pid_t urkel_pid)
{
+ struct reg_struct uregs;
int status, insyscall, sig;
insyscall = 0;
@@ -156,7 +156,8 @@
if (WSTOPSIG(status) == SIGTRAP) {
insyscall = !insyscall;
if (insyscall) {
- sig = handle_syscall(urkel_pid);
+ ptrace_getregs(urkel_pid, &uregs);
+ sig = handle_syscall(&uregs, urkel_pid);
if (sig)
insyscall = !insyscall;
}
@@ -191,7 +192,7 @@
if (errno)
err(EXIT_FAILURE,
"ptrace(PT_TRACE_ME, 0, NULL, 0) failed");
- wait(&status);
+ raise(SIGSTOP);
break;
default:
status = urkelvisor(child_pid);
Home |
Main Index |
Thread Index |
Old Index