vserver 1.9.3
[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 <errno.h>
13 #include <sys/types.h>
14 #include <sys/ptrace.h>
15 #include <asm/ptrace.h>
16 #include <linux/unistd.h>
17 #include "ptrace_user.h"
18 #include "user_util.h"
19 #include "user.h"
20
21 int get_syscall(pid_t pid, long *arg1, long *arg2, long *arg3, long *arg4, 
22                 long *arg5)
23 {
24         *arg1 = ptrace(PTRACE_PEEKUSER, pid, PT_SYSCALL_ARG1_OFFSET, 0);
25         *arg2 = ptrace(PTRACE_PEEKUSER, pid, PT_SYSCALL_ARG2_OFFSET, 0);
26         *arg3 = ptrace(PTRACE_PEEKUSER, pid, PT_SYSCALL_ARG3_OFFSET, 0);
27         *arg4 = ptrace(PTRACE_PEEKUSER, pid, PT_SYSCALL_ARG4_OFFSET, 0);
28         *arg5 = ptrace(PTRACE_PEEKUSER, pid, PT_SYSCALL_ARG5_OFFSET, 0);
29         return(ptrace(PTRACE_PEEKUSER, pid, PT_SYSCALL_NR_OFFSET, 0));
30 }
31
32 void syscall_cancel(pid_t pid, int result)
33 {
34         if((ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_NR_OFFSET, 
35                    __NR_getpid) < 0) ||
36            (ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) ||
37            (wait_for_stop(pid, SIGTRAP, PTRACE_SYSCALL, NULL) < 0) ||
38            (ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_RET_OFFSET, result) < 0) ||
39            (ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0))
40                 printk("ptproxy: couldn't cancel syscall: errno = %d\n", 
41                        errno);
42 }
43
44 void syscall_set_result(pid_t pid, long result)
45 {
46         ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_RET_OFFSET, result);
47 }
48
49 void syscall_continue(pid_t pid)
50 {
51         ptrace(PTRACE_SYSCALL, pid, 0, 0);
52 }
53
54 int syscall_pause(pid_t pid) 
55 {
56         if(ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_NR_OFFSET, __NR_pause) < 0){
57                 printk("syscall_change - ptrace failed, errno = %d\n", errno);
58                 return(-1);
59         }
60         return(0);
61 }
62
63 /*
64  * Overrides for Emacs so that we follow Linus's tabbing style.
65  * Emacs will notice this stuff at the end of the file and automatically
66  * adjust the settings for this buffer only.  This must remain at the end
67  * of the file.
68  * ---------------------------------------------------------------------------
69  * Local variables:
70  * c-file-style: "linux"
71  * End:
72  */