ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / um / kernel / tt / ptproxy / sysdep.c
1 /**********************************************************************
2 sysdep.c
3
4 Copyright (C) 1999 Lars Brinkhoff.  See the file COPYING for licensing
5 terms and conditions.
6 **********************************************************************/
7
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <signal.h>
12 #include <sys/types.h>
13 #include <sys/ptrace.h>
14 #include <asm/ptrace.h>
15 #include <linux/unistd.h>
16 #include "ptrace_user.h"
17 #include "user_util.h"
18 #include "user.h"
19
20 int get_syscall(pid_t pid, long *arg1, long *arg2, long *arg3, long *arg4, 
21                 long *arg5)
22 {
23         *arg1 = ptrace(PTRACE_PEEKUSER, pid, PT_SYSCALL_ARG1_OFFSET, 0);
24         *arg2 = ptrace(PTRACE_PEEKUSER, pid, PT_SYSCALL_ARG2_OFFSET, 0);
25         *arg3 = ptrace(PTRACE_PEEKUSER, pid, PT_SYSCALL_ARG3_OFFSET, 0);
26         *arg4 = ptrace(PTRACE_PEEKUSER, pid, PT_SYSCALL_ARG4_OFFSET, 0);
27         *arg5 = ptrace(PTRACE_PEEKUSER, pid, PT_SYSCALL_ARG5_OFFSET, 0);
28         return(ptrace(PTRACE_PEEKUSER, pid, PT_SYSCALL_NR_OFFSET, 0));
29 }
30
31 void syscall_cancel(pid_t pid, int result)
32 {
33         if((ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_NR_OFFSET, 
34                    __NR_getpid) < 0) ||
35            (ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) ||
36            (wait_for_stop(pid, SIGTRAP, PTRACE_SYSCALL, NULL) < 0) ||
37            (ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_RET_OFFSET, result) < 0) ||
38            (ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0))
39                 printk("ptproxy: couldn't cancel syscall: errno = %d\n", 
40                        errno);
41 }
42
43 void syscall_set_result(pid_t pid, long result)
44 {
45         ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_RET_OFFSET, result);
46 }
47
48 void syscall_continue(pid_t pid)
49 {
50         ptrace(PTRACE_SYSCALL, pid, 0, 0);
51 }
52
53 int syscall_pause(pid_t pid) 
54 {
55         if(ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_NR_OFFSET, __NR_pause) < 0){
56                 printk("syscall_change - ptrace failed, errno = %d\n", errno);
57                 return(-1);
58         }
59         return(0);
60 }
61
62 /*
63  * Overrides for Emacs so that we follow Linus's tabbing style.
64  * Emacs will notice this stuff at the end of the file and automatically
65  * adjust the settings for this buffer only.  This must remain at the end
66  * of the file.
67  * ---------------------------------------------------------------------------
68  * Local variables:
69  * c-file-style: "linux"
70  * End:
71  */