aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/sys-i386/ptrace_user.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/sys-i386/ptrace_user.c')
-rw-r--r--arch/um/sys-i386/ptrace_user.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/arch/um/sys-i386/ptrace_user.c b/arch/um/sys-i386/ptrace_user.c
new file mode 100644
index 000000000000..7c376c95de50
--- /dev/null
+++ b/arch/um/sys-i386/ptrace_user.c
@@ -0,0 +1,131 @@
1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#include <stdio.h>
7#include <errno.h>
8#include <unistd.h>
9#include <linux/stddef.h>
10#include "ptrace_user.h"
11/* Grr, asm/user.h includes asm/ptrace.h, so has to follow ptrace_user.h */
12#include <asm/user.h>
13#include "kern_util.h"
14#include "sysdep/thread.h"
15#include "user.h"
16#include "os.h"
17
18int ptrace_getregs(long pid, unsigned long *regs_out)
19{
20 if (ptrace(PTRACE_GETREGS, pid, 0, regs_out) < 0)
21 return -errno;
22 return 0;
23}
24
25int ptrace_setregs(long pid, unsigned long *regs)
26{
27 if (ptrace(PTRACE_SETREGS, pid, 0, regs) < 0)
28 return -errno;
29 return 0;
30}
31
32int ptrace_getfpregs(long pid, unsigned long *regs)
33{
34 if (ptrace(PTRACE_GETFPREGS, pid, 0, regs) < 0)
35 return -errno;
36 return 0;
37}
38
39int ptrace_setfpregs(long pid, unsigned long *regs)
40{
41 if (ptrace(PTRACE_SETFPREGS, pid, 0, regs) < 0)
42 return -errno;
43 return 0;
44}
45
46static void write_debugregs(int pid, unsigned long *regs)
47{
48 struct user *dummy;
49 int nregs, i;
50
51 dummy = NULL;
52 nregs = sizeof(dummy->u_debugreg)/sizeof(dummy->u_debugreg[0]);
53 for(i = 0; i < nregs; i++){
54 if((i == 4) || (i == 5)) continue;
55 if(ptrace(PTRACE_POKEUSR, pid, &dummy->u_debugreg[i],
56 regs[i]) < 0)
57 printk("write_debugregs - ptrace failed on "
58 "register %d, value = 0x%x, errno = %d\n", i,
59 regs[i], errno);
60 }
61}
62
63static void read_debugregs(int pid, unsigned long *regs)
64{
65 struct user *dummy;
66 int nregs, i;
67
68 dummy = NULL;
69 nregs = sizeof(dummy->u_debugreg)/sizeof(dummy->u_debugreg[0]);
70 for(i = 0; i < nregs; i++){
71 regs[i] = ptrace(PTRACE_PEEKUSR, pid,
72 &dummy->u_debugreg[i], 0);
73 }
74}
75
76/* Accessed only by the tracing thread */
77static unsigned long kernel_debugregs[8] = { [ 0 ... 7 ] = 0 };
78static int debugregs_seq = 0;
79
80void arch_enter_kernel(void *task, int pid)
81{
82 read_debugregs(pid, TASK_DEBUGREGS(task));
83 write_debugregs(pid, kernel_debugregs);
84}
85
86void arch_leave_kernel(void *task, int pid)
87{
88 read_debugregs(pid, kernel_debugregs);
89 write_debugregs(pid, TASK_DEBUGREGS(task));
90}
91
92void ptrace_pokeuser(unsigned long addr, unsigned long data)
93{
94 if((addr < offsetof(struct user, u_debugreg[0])) ||
95 (addr > offsetof(struct user, u_debugreg[7])))
96 return;
97 addr -= offsetof(struct user, u_debugreg[0]);
98 addr = addr >> 2;
99 if(kernel_debugregs[addr] == data) return;
100
101 kernel_debugregs[addr] = data;
102 debugregs_seq++;
103}
104
105static void update_debugregs_cb(void *arg)
106{
107 int pid = *((int *) arg);
108
109 write_debugregs(pid, kernel_debugregs);
110}
111
112void update_debugregs(int seq)
113{
114 int me;
115
116 if(seq == debugregs_seq) return;
117
118 me = os_getpid();
119 initial_thread_cb(update_debugregs_cb, &me);
120}
121
122/*
123 * Overrides for Emacs so that we follow Linus's tabbing style.
124 * Emacs will notice this stuff at the end of the file and automatically
125 * adjust the settings for this buffer only. This must remain at the end
126 * of the file.
127 * ---------------------------------------------------------------------------
128 * Local variables:
129 * c-file-style: "linux"
130 * End:
131 */