]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/um/sys-i386/ptrace_user.c
Pull button into release branch
[mirror_ubuntu-bionic-kernel.git] / arch / um / sys-i386 / ptrace_user.c
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 #include "uml-config.h"
18
19 int ptrace_getregs(long pid, unsigned long *regs_out)
20 {
21 if (ptrace(PTRACE_GETREGS, pid, 0, regs_out) < 0)
22 return -errno;
23 return 0;
24 }
25
26 int ptrace_setregs(long pid, unsigned long *regs)
27 {
28 if (ptrace(PTRACE_SETREGS, pid, 0, regs) < 0)
29 return -errno;
30 return 0;
31 }
32
33 int ptrace_getfpregs(long pid, unsigned long *regs)
34 {
35 if (ptrace(PTRACE_GETFPREGS, pid, 0, regs) < 0)
36 return -errno;
37 return 0;
38 }
39
40 int ptrace_setfpregs(long pid, unsigned long *regs)
41 {
42 if (ptrace(PTRACE_SETFPREGS, pid, 0, regs) < 0)
43 return -errno;
44 return 0;
45 }
46
47 /* All the below stuff is of interest for TT mode only */
48 static void write_debugregs(int pid, unsigned long *regs)
49 {
50 struct user *dummy;
51 int nregs, i;
52
53 dummy = NULL;
54 nregs = sizeof(dummy->u_debugreg)/sizeof(dummy->u_debugreg[0]);
55 for(i = 0; i < nregs; i++){
56 if((i == 4) || (i == 5)) continue;
57 if(ptrace(PTRACE_POKEUSR, pid, &dummy->u_debugreg[i],
58 regs[i]) < 0)
59 printk("write_debugregs - ptrace failed on "
60 "register %d, value = 0x%lx, errno = %d\n", i,
61 regs[i], errno);
62 }
63 }
64
65 static void read_debugregs(int pid, unsigned long *regs)
66 {
67 struct user *dummy;
68 int nregs, i;
69
70 dummy = NULL;
71 nregs = sizeof(dummy->u_debugreg)/sizeof(dummy->u_debugreg[0]);
72 for(i = 0; i < nregs; i++){
73 regs[i] = ptrace(PTRACE_PEEKUSR, pid,
74 &dummy->u_debugreg[i], 0);
75 }
76 }
77
78 /* Accessed only by the tracing thread */
79 static unsigned long kernel_debugregs[8] = { [ 0 ... 7 ] = 0 };
80
81 void arch_enter_kernel(void *task, int pid)
82 {
83 read_debugregs(pid, TASK_DEBUGREGS(task));
84 write_debugregs(pid, kernel_debugregs);
85 }
86
87 void arch_leave_kernel(void *task, int pid)
88 {
89 read_debugregs(pid, kernel_debugregs);
90 write_debugregs(pid, TASK_DEBUGREGS(task));
91 }
92
93 #ifdef UML_CONFIG_PT_PROXY
94 /* Accessed only by the tracing thread */
95 static int debugregs_seq;
96
97 /* Only called by the ptrace proxy */
98 void ptrace_pokeuser(unsigned long addr, unsigned long data)
99 {
100 if((addr < offsetof(struct user, u_debugreg[0])) ||
101 (addr > offsetof(struct user, u_debugreg[7])))
102 return;
103 addr -= offsetof(struct user, u_debugreg[0]);
104 addr = addr >> 2;
105 if(kernel_debugregs[addr] == data) return;
106
107 kernel_debugregs[addr] = data;
108 debugregs_seq++;
109 }
110
111 static void update_debugregs_cb(void *arg)
112 {
113 int pid = *((int *) arg);
114
115 write_debugregs(pid, kernel_debugregs);
116 }
117
118 /* Optimized out in its header when not defined */
119 void update_debugregs(int seq)
120 {
121 int me;
122
123 if(seq == debugregs_seq) return;
124
125 me = os_getpid();
126 initial_thread_cb(update_debugregs_cb, &me);
127 }
128 #endif
129
130 /*
131 * Overrides for Emacs so that we follow Linus's tabbing style.
132 * Emacs will notice this stuff at the end of the file and automatically
133 * adjust the settings for this buffer only. This must remain at the end
134 * of the file.
135 * ---------------------------------------------------------------------------
136 * Local variables:
137 * c-file-style: "linux"
138 * End:
139 */