diff options
author | Roland McGrath <roland@redhat.com> | 2008-01-30 07:31:02 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-01-30 07:31:02 -0500 |
commit | 25149b62d3e6a3e737af39bd4a0b4e97de0811b7 (patch) | |
tree | fc65eb48e7c6254b22f9a5e97056d55ad3c499dc | |
parent | cbc9d9d98215f08ed998228e7bce88502d1ce360 (diff) |
x86: x86 ptrace merge removals
This removes the old separate 64-bit and ia32 ptrace source files.
They are no longer used.
Signed-off-by: Roland McGrath <roland@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
-rw-r--r-- | arch/x86/ia32/ptrace32.c | 411 | ||||
-rw-r--r-- | arch/x86/kernel/ptrace_64.c | 470 |
2 files changed, 0 insertions, 881 deletions
diff --git a/arch/x86/ia32/ptrace32.c b/arch/x86/ia32/ptrace32.c deleted file mode 100644 index d5663e295330..000000000000 --- a/arch/x86/ia32/ptrace32.c +++ /dev/null | |||
@@ -1,411 +0,0 @@ | |||
1 | /* | ||
2 | * 32bit ptrace for x86-64. | ||
3 | * | ||
4 | * Copyright 2001,2002 Andi Kleen, SuSE Labs. | ||
5 | * Some parts copied from arch/i386/kernel/ptrace.c. See that file for earlier | ||
6 | * copyright. | ||
7 | * | ||
8 | * This allows to access 64bit processes too; but there is no way to | ||
9 | * see the extended register contents. | ||
10 | */ | ||
11 | |||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/stddef.h> | ||
14 | #include <linux/sched.h> | ||
15 | #include <linux/syscalls.h> | ||
16 | #include <linux/unistd.h> | ||
17 | #include <linux/mm.h> | ||
18 | #include <linux/err.h> | ||
19 | #include <linux/ptrace.h> | ||
20 | #include <asm/ptrace.h> | ||
21 | #include <asm/compat.h> | ||
22 | #include <asm/uaccess.h> | ||
23 | #include <asm/user32.h> | ||
24 | #include <asm/user.h> | ||
25 | #include <asm/errno.h> | ||
26 | #include <asm/debugreg.h> | ||
27 | #include <asm/i387.h> | ||
28 | #include <asm/fpu32.h> | ||
29 | #include <asm/ia32.h> | ||
30 | |||
31 | /* | ||
32 | * Determines which flags the user has access to [1 = access, 0 = no access]. | ||
33 | * Prohibits changing ID(21), VIP(20), VIF(19), VM(17), IOPL(12-13), IF(9). | ||
34 | * Also masks reserved bits (31-22, 15, 5, 3, 1). | ||
35 | */ | ||
36 | #define FLAG_MASK 0x54dd5UL | ||
37 | |||
38 | #define R32(l,q) \ | ||
39 | case offsetof(struct user32, regs.l): \ | ||
40 | regs->q = val; break; | ||
41 | |||
42 | static int putreg32(struct task_struct *child, unsigned regno, u32 val) | ||
43 | { | ||
44 | struct pt_regs *regs = task_pt_regs(child); | ||
45 | |||
46 | switch (regno) { | ||
47 | case offsetof(struct user32, regs.fs): | ||
48 | if (val && (val & 3) != 3) | ||
49 | return -EIO; | ||
50 | child->thread.fsindex = val & 0xffff; | ||
51 | if (child == current) | ||
52 | loadsegment(fs, child->thread.fsindex); | ||
53 | break; | ||
54 | case offsetof(struct user32, regs.gs): | ||
55 | if (val && (val & 3) != 3) | ||
56 | return -EIO; | ||
57 | child->thread.gsindex = val & 0xffff; | ||
58 | if (child == current) | ||
59 | load_gs_index(child->thread.gsindex); | ||
60 | break; | ||
61 | case offsetof(struct user32, regs.ds): | ||
62 | if (val && (val & 3) != 3) | ||
63 | return -EIO; | ||
64 | child->thread.ds = val & 0xffff; | ||
65 | if (child == current) | ||
66 | loadsegment(ds, child->thread.ds); | ||
67 | break; | ||
68 | case offsetof(struct user32, regs.es): | ||
69 | child->thread.es = val & 0xffff; | ||
70 | if (child == current) | ||
71 | loadsegment(es, child->thread.ds); | ||
72 | break; | ||
73 | case offsetof(struct user32, regs.ss): | ||
74 | if ((val & 3) != 3) | ||
75 | return -EIO; | ||
76 | regs->ss = val & 0xffff; | ||
77 | break; | ||
78 | case offsetof(struct user32, regs.cs): | ||
79 | if ((val & 3) != 3) | ||
80 | return -EIO; | ||
81 | regs->cs = val & 0xffff; | ||
82 | break; | ||
83 | |||
84 | R32(ebx, bx); | ||
85 | R32(ecx, cx); | ||
86 | R32(edx, dx); | ||
87 | R32(edi, di); | ||
88 | R32(esi, si); | ||
89 | R32(ebp, bp); | ||
90 | R32(eax, ax); | ||
91 | R32(orig_eax, orig_ax); | ||
92 | R32(eip, ip); | ||
93 | R32(esp, sp); | ||
94 | |||
95 | case offsetof(struct user32, regs.eflags): | ||
96 | val &= FLAG_MASK; | ||
97 | /* | ||
98 | * If the user value contains TF, mark that | ||
99 | * it was not "us" (the debugger) that set it. | ||
100 | * If not, make sure it stays set if we had. | ||
101 | */ | ||
102 | if (val & X86_EFLAGS_TF) | ||
103 | clear_tsk_thread_flag(child, TIF_FORCED_TF); | ||
104 | else if (test_tsk_thread_flag(child, TIF_FORCED_TF)) | ||
105 | val |= X86_EFLAGS_TF; | ||
106 | regs->flags = val | (regs->flags & ~FLAG_MASK); | ||
107 | break; | ||
108 | |||
109 | case offsetof(struct user32, u_debugreg[0]) ... | ||
110 | offsetof(struct user32, u_debugreg[7]): | ||
111 | regno -= offsetof(struct user32, u_debugreg[0]); | ||
112 | return ptrace_set_debugreg(child, regno / 4, val); | ||
113 | |||
114 | default: | ||
115 | if (regno > sizeof(struct user32) || (regno & 3)) | ||
116 | return -EIO; | ||
117 | |||
118 | /* | ||
119 | * Other dummy fields in the virtual user structure | ||
120 | * are ignored | ||
121 | */ | ||
122 | break; | ||
123 | } | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | #undef R32 | ||
128 | |||
129 | #define R32(l,q) \ | ||
130 | case offsetof(struct user32, regs.l): \ | ||
131 | *val = regs->q; break | ||
132 | |||
133 | static int getreg32(struct task_struct *child, unsigned regno, u32 *val) | ||
134 | { | ||
135 | struct pt_regs *regs = task_pt_regs(child); | ||
136 | |||
137 | switch (regno) { | ||
138 | case offsetof(struct user32, regs.fs): | ||
139 | *val = child->thread.fsindex; | ||
140 | if (child == current) | ||
141 | asm("movl %%fs,%0" : "=r" (*val)); | ||
142 | break; | ||
143 | case offsetof(struct user32, regs.gs): | ||
144 | *val = child->thread.gsindex; | ||
145 | if (child == current) | ||
146 | asm("movl %%gs,%0" : "=r" (*val)); | ||
147 | break; | ||
148 | case offsetof(struct user32, regs.ds): | ||
149 | *val = child->thread.ds; | ||
150 | if (child == current) | ||
151 | asm("movl %%ds,%0" : "=r" (*val)); | ||
152 | break; | ||
153 | case offsetof(struct user32, regs.es): | ||
154 | *val = child->thread.es; | ||
155 | if (child == current) | ||
156 | asm("movl %%es,%0" : "=r" (*val)); | ||
157 | break; | ||
158 | |||
159 | R32(cs, cs); | ||
160 | R32(ss, ss); | ||
161 | R32(ebx, bx); | ||
162 | R32(ecx, cx); | ||
163 | R32(edx, dx); | ||
164 | R32(edi, di); | ||
165 | R32(esi, si); | ||
166 | R32(ebp, bp); | ||
167 | R32(eax, ax); | ||
168 | R32(orig_eax, orig_ax); | ||
169 | R32(eip, ip); | ||
170 | R32(esp, sp); | ||
171 | |||
172 | case offsetof(struct user32, regs.eflags): | ||
173 | /* | ||
174 | * If the debugger set TF, hide it from the readout. | ||
175 | */ | ||
176 | *val = regs->flags; | ||
177 | if (test_tsk_thread_flag(child, TIF_FORCED_TF)) | ||
178 | *val &= ~X86_EFLAGS_TF; | ||
179 | break; | ||
180 | |||
181 | case offsetof(struct user32, u_debugreg[0]) ... | ||
182 | offsetof(struct user32, u_debugreg[7]): | ||
183 | regno -= offsetof(struct user32, u_debugreg[0]); | ||
184 | *val = ptrace_get_debugreg(child, regno / 4); | ||
185 | break; | ||
186 | |||
187 | default: | ||
188 | if (regno > sizeof(struct user32) || (regno & 3)) | ||
189 | return -EIO; | ||
190 | |||
191 | /* | ||
192 | * Other dummy fields in the virtual user structure | ||
193 | * are ignored | ||
194 | */ | ||
195 | *val = 0; | ||
196 | break; | ||
197 | } | ||
198 | return 0; | ||
199 | } | ||
200 | |||
201 | #undef R32 | ||
202 | |||
203 | static long ptrace32_siginfo(unsigned request, u32 pid, u32 addr, u32 data) | ||
204 | { | ||
205 | siginfo_t __user *si = compat_alloc_user_space(sizeof(siginfo_t)); | ||
206 | compat_siginfo_t __user *si32 = compat_ptr(data); | ||
207 | siginfo_t ssi; | ||
208 | int ret; | ||
209 | |||
210 | if (request == PTRACE_SETSIGINFO) { | ||
211 | memset(&ssi, 0, sizeof(siginfo_t)); | ||
212 | ret = copy_siginfo_from_user32(&ssi, si32); | ||
213 | if (ret) | ||
214 | return ret; | ||
215 | if (copy_to_user(si, &ssi, sizeof(siginfo_t))) | ||
216 | return -EFAULT; | ||
217 | } | ||
218 | ret = sys_ptrace(request, pid, addr, (unsigned long)si); | ||
219 | if (ret) | ||
220 | return ret; | ||
221 | if (request == PTRACE_GETSIGINFO) { | ||
222 | if (copy_from_user(&ssi, si, sizeof(siginfo_t))) | ||
223 | return -EFAULT; | ||
224 | ret = copy_siginfo_to_user32(si32, &ssi); | ||
225 | } | ||
226 | return ret; | ||
227 | } | ||
228 | |||
229 | asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data) | ||
230 | { | ||
231 | struct task_struct *child; | ||
232 | struct pt_regs *childregs; | ||
233 | void __user *datap = compat_ptr(data); | ||
234 | int ret; | ||
235 | __u32 val; | ||
236 | |||
237 | switch (request) { | ||
238 | case PTRACE_TRACEME: | ||
239 | case PTRACE_ATTACH: | ||
240 | case PTRACE_KILL: | ||
241 | case PTRACE_CONT: | ||
242 | case PTRACE_SINGLESTEP: | ||
243 | case PTRACE_SINGLEBLOCK: | ||
244 | case PTRACE_DETACH: | ||
245 | case PTRACE_SYSCALL: | ||
246 | case PTRACE_OLDSETOPTIONS: | ||
247 | case PTRACE_SETOPTIONS: | ||
248 | case PTRACE_SET_THREAD_AREA: | ||
249 | case PTRACE_GET_THREAD_AREA: | ||
250 | return sys_ptrace(request, pid, addr, data); | ||
251 | |||
252 | default: | ||
253 | return -EINVAL; | ||
254 | |||
255 | case PTRACE_PEEKTEXT: | ||
256 | case PTRACE_PEEKDATA: | ||
257 | case PTRACE_POKEDATA: | ||
258 | case PTRACE_POKETEXT: | ||
259 | case PTRACE_POKEUSR: | ||
260 | case PTRACE_PEEKUSR: | ||
261 | case PTRACE_GETREGS: | ||
262 | case PTRACE_SETREGS: | ||
263 | case PTRACE_SETFPREGS: | ||
264 | case PTRACE_GETFPREGS: | ||
265 | case PTRACE_SETFPXREGS: | ||
266 | case PTRACE_GETFPXREGS: | ||
267 | case PTRACE_GETEVENTMSG: | ||
268 | break; | ||
269 | |||
270 | case PTRACE_SETSIGINFO: | ||
271 | case PTRACE_GETSIGINFO: | ||
272 | return ptrace32_siginfo(request, pid, addr, data); | ||
273 | } | ||
274 | |||
275 | child = ptrace_get_task_struct(pid); | ||
276 | if (IS_ERR(child)) | ||
277 | return PTR_ERR(child); | ||
278 | |||
279 | ret = ptrace_check_attach(child, request == PTRACE_KILL); | ||
280 | if (ret < 0) | ||
281 | goto out; | ||
282 | |||
283 | childregs = task_pt_regs(child); | ||
284 | |||
285 | switch (request) { | ||
286 | case PTRACE_PEEKDATA: | ||
287 | case PTRACE_PEEKTEXT: | ||
288 | ret = 0; | ||
289 | if (access_process_vm(child, addr, &val, sizeof(u32), 0) != | ||
290 | sizeof(u32)) | ||
291 | ret = -EIO; | ||
292 | else | ||
293 | ret = put_user(val, (unsigned int __user *)datap); | ||
294 | break; | ||
295 | |||
296 | case PTRACE_POKEDATA: | ||
297 | case PTRACE_POKETEXT: | ||
298 | ret = 0; | ||
299 | if (access_process_vm(child, addr, &data, sizeof(u32), 1) != | ||
300 | sizeof(u32)) | ||
301 | ret = -EIO; | ||
302 | break; | ||
303 | |||
304 | case PTRACE_PEEKUSR: | ||
305 | ret = getreg32(child, addr, &val); | ||
306 | if (ret == 0) | ||
307 | ret = put_user(val, (__u32 __user *)datap); | ||
308 | break; | ||
309 | |||
310 | case PTRACE_POKEUSR: | ||
311 | ret = putreg32(child, addr, data); | ||
312 | break; | ||
313 | |||
314 | case PTRACE_GETREGS: { /* Get all gp regs from the child. */ | ||
315 | int i; | ||
316 | |||
317 | if (!access_ok(VERIFY_WRITE, datap, 16*4)) { | ||
318 | ret = -EIO; | ||
319 | break; | ||
320 | } | ||
321 | ret = 0; | ||
322 | for (i = 0; i <= 16*4; i += sizeof(__u32)) { | ||
323 | getreg32(child, i, &val); | ||
324 | ret |= __put_user(val, (u32 __user *)datap); | ||
325 | datap += sizeof(u32); | ||
326 | } | ||
327 | break; | ||
328 | } | ||
329 | |||
330 | case PTRACE_SETREGS: { /* Set all gp regs in the child. */ | ||
331 | unsigned long tmp; | ||
332 | int i; | ||
333 | |||
334 | if (!access_ok(VERIFY_READ, datap, 16*4)) { | ||
335 | ret = -EIO; | ||
336 | break; | ||
337 | } | ||
338 | ret = 0; | ||
339 | for (i = 0; i <= 16*4; i += sizeof(u32)) { | ||
340 | ret |= __get_user(tmp, (u32 __user *)datap); | ||
341 | putreg32(child, i, tmp); | ||
342 | datap += sizeof(u32); | ||
343 | } | ||
344 | break; | ||
345 | } | ||
346 | |||
347 | case PTRACE_GETFPREGS: | ||
348 | ret = -EIO; | ||
349 | if (!access_ok(VERIFY_READ, compat_ptr(data), | ||
350 | sizeof(struct user_i387_struct))) | ||
351 | break; | ||
352 | save_i387_ia32(child, datap, childregs, 1); | ||
353 | ret = 0; | ||
354 | break; | ||
355 | |||
356 | case PTRACE_SETFPREGS: | ||
357 | ret = -EIO; | ||
358 | if (!access_ok(VERIFY_WRITE, datap, | ||
359 | sizeof(struct user_i387_struct))) | ||
360 | break; | ||
361 | ret = 0; | ||
362 | /* don't check EFAULT to be bug-to-bug compatible to i386 */ | ||
363 | restore_i387_ia32(child, datap, 1); | ||
364 | break; | ||
365 | |||
366 | case PTRACE_GETFPXREGS: { | ||
367 | struct user32_fxsr_struct __user *u = datap; | ||
368 | |||
369 | init_fpu(child); | ||
370 | ret = -EIO; | ||
371 | if (!access_ok(VERIFY_WRITE, u, sizeof(*u))) | ||
372 | break; | ||
373 | ret = -EFAULT; | ||
374 | if (__copy_to_user(u, &child->thread.i387.fxsave, sizeof(*u))) | ||
375 | break; | ||
376 | ret = __put_user(childregs->cs, &u->fcs); | ||
377 | ret |= __put_user(child->thread.ds, &u->fos); | ||
378 | break; | ||
379 | } | ||
380 | case PTRACE_SETFPXREGS: { | ||
381 | struct user32_fxsr_struct __user *u = datap; | ||
382 | |||
383 | unlazy_fpu(child); | ||
384 | ret = -EIO; | ||
385 | if (!access_ok(VERIFY_READ, u, sizeof(*u))) | ||
386 | break; | ||
387 | /* | ||
388 | * no checking to be bug-to-bug compatible with i386. | ||
389 | * but silence warning | ||
390 | */ | ||
391 | if (__copy_from_user(&child->thread.i387.fxsave, u, sizeof(*u))) | ||
392 | ; | ||
393 | set_stopped_child_used_math(child); | ||
394 | child->thread.i387.fxsave.mxcsr &= mxcsr_feature_mask; | ||
395 | ret = 0; | ||
396 | break; | ||
397 | } | ||
398 | |||
399 | case PTRACE_GETEVENTMSG: | ||
400 | ret = put_user(child->ptrace_message, | ||
401 | (unsigned int __user *)compat_ptr(data)); | ||
402 | break; | ||
403 | |||
404 | default: | ||
405 | BUG(); | ||
406 | } | ||
407 | |||
408 | out: | ||
409 | put_task_struct(child); | ||
410 | return ret; | ||
411 | } | ||
diff --git a/arch/x86/kernel/ptrace_64.c b/arch/x86/kernel/ptrace_64.c deleted file mode 100644 index 5979dbe8e0a2..000000000000 --- a/arch/x86/kernel/ptrace_64.c +++ /dev/null | |||
@@ -1,470 +0,0 @@ | |||
1 | /* By Ross Biro 1/23/92 */ | ||
2 | /* | ||
3 | * Pentium III FXSR, SSE support | ||
4 | * Gareth Hughes <gareth@valinux.com>, May 2000 | ||
5 | * | ||
6 | * x86-64 port 2000-2002 Andi Kleen | ||
7 | */ | ||
8 | |||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/sched.h> | ||
11 | #include <linux/mm.h> | ||
12 | #include <linux/smp.h> | ||
13 | #include <linux/errno.h> | ||
14 | #include <linux/ptrace.h> | ||
15 | #include <linux/user.h> | ||
16 | #include <linux/security.h> | ||
17 | #include <linux/audit.h> | ||
18 | #include <linux/seccomp.h> | ||
19 | #include <linux/signal.h> | ||
20 | |||
21 | #include <asm/uaccess.h> | ||
22 | #include <asm/pgtable.h> | ||
23 | #include <asm/system.h> | ||
24 | #include <asm/processor.h> | ||
25 | #include <asm/prctl.h> | ||
26 | #include <asm/i387.h> | ||
27 | #include <asm/debugreg.h> | ||
28 | #include <asm/ldt.h> | ||
29 | #include <asm/desc.h> | ||
30 | #include <asm/proto.h> | ||
31 | #include <asm/ia32.h> | ||
32 | |||
33 | /* | ||
34 | * does not yet catch signals sent when the child dies. | ||
35 | * in exit.c or in signal.c. | ||
36 | */ | ||
37 | |||
38 | /* | ||
39 | * Determines which flags the user has access to [1 = access, 0 = no access]. | ||
40 | * Prohibits changing ID(21), VIP(20), VIF(19), VM(17), IOPL(12-13), IF(9). | ||
41 | * Also masks reserved bits (63-22, 15, 5, 3, 1). | ||
42 | */ | ||
43 | #define FLAG_MASK 0x54dd5UL | ||
44 | |||
45 | /* | ||
46 | * Called by kernel/ptrace.c when detaching.. | ||
47 | * | ||
48 | * Make sure the single step bit is not set. | ||
49 | */ | ||
50 | void ptrace_disable(struct task_struct *child) | ||
51 | { | ||
52 | user_disable_single_step(child); | ||
53 | } | ||
54 | |||
55 | static unsigned long *pt_regs_access(struct pt_regs *regs, unsigned long offset) | ||
56 | { | ||
57 | BUILD_BUG_ON(offsetof(struct pt_regs, r15) != 0); | ||
58 | return ®s->r15 + (offset / sizeof(regs->r15)); | ||
59 | } | ||
60 | |||
61 | static int putreg(struct task_struct *child, | ||
62 | unsigned long regno, unsigned long value) | ||
63 | { | ||
64 | struct pt_regs *regs = task_pt_regs(child); | ||
65 | switch (regno) { | ||
66 | case offsetof(struct user_regs_struct,fs): | ||
67 | if (value && (value & 3) != 3) | ||
68 | return -EIO; | ||
69 | child->thread.fsindex = value & 0xffff; | ||
70 | if (child == current) | ||
71 | loadsegment(fs, child->thread.fsindex); | ||
72 | return 0; | ||
73 | case offsetof(struct user_regs_struct,gs): | ||
74 | if (value && (value & 3) != 3) | ||
75 | return -EIO; | ||
76 | child->thread.gsindex = value & 0xffff; | ||
77 | if (child == current) | ||
78 | load_gs_index(child->thread.gsindex); | ||
79 | return 0; | ||
80 | case offsetof(struct user_regs_struct,ds): | ||
81 | if (value && (value & 3) != 3) | ||
82 | return -EIO; | ||
83 | child->thread.ds = value & 0xffff; | ||
84 | if (child == current) | ||
85 | loadsegment(ds, child->thread.ds); | ||
86 | return 0; | ||
87 | case offsetof(struct user_regs_struct,es): | ||
88 | if (value && (value & 3) != 3) | ||
89 | return -EIO; | ||
90 | child->thread.es = value & 0xffff; | ||
91 | if (child == current) | ||
92 | loadsegment(es, child->thread.es); | ||
93 | return 0; | ||
94 | case offsetof(struct user_regs_struct,ss): | ||
95 | if ((value & 3) != 3) | ||
96 | return -EIO; | ||
97 | value &= 0xffff; | ||
98 | return 0; | ||
99 | case offsetof(struct user_regs_struct,fs_base): | ||
100 | if (value >= TASK_SIZE_OF(child)) | ||
101 | return -EIO; | ||
102 | /* | ||
103 | * When changing the segment base, use do_arch_prctl | ||
104 | * to set either thread.fs or thread.fsindex and the | ||
105 | * corresponding GDT slot. | ||
106 | */ | ||
107 | if (child->thread.fs != value) | ||
108 | return do_arch_prctl(child, ARCH_SET_FS, value); | ||
109 | return 0; | ||
110 | case offsetof(struct user_regs_struct,gs_base): | ||
111 | /* | ||
112 | * Exactly the same here as the %fs handling above. | ||
113 | */ | ||
114 | if (value >= TASK_SIZE_OF(child)) | ||
115 | return -EIO; | ||
116 | if (child->thread.gs != value) | ||
117 | return do_arch_prctl(child, ARCH_SET_GS, value); | ||
118 | return 0; | ||
119 | case offsetof(struct user_regs_struct,flags): | ||
120 | value &= FLAG_MASK; | ||
121 | /* | ||
122 | * If the user value contains TF, mark that | ||
123 | * it was not "us" (the debugger) that set it. | ||
124 | * If not, make sure it stays set if we had. | ||
125 | */ | ||
126 | if (value & X86_EFLAGS_TF) | ||
127 | clear_tsk_thread_flag(child, TIF_FORCED_TF); | ||
128 | else if (test_tsk_thread_flag(child, TIF_FORCED_TF)) | ||
129 | value |= X86_EFLAGS_TF; | ||
130 | value |= regs->flags & ~FLAG_MASK; | ||
131 | break; | ||
132 | case offsetof(struct user_regs_struct,cs): | ||
133 | if ((value & 3) != 3) | ||
134 | return -EIO; | ||
135 | value &= 0xffff; | ||
136 | break; | ||
137 | } | ||
138 | *pt_regs_access(regs, regno) = value; | ||
139 | return 0; | ||
140 | } | ||
141 | |||
142 | static unsigned long getreg(struct task_struct *child, unsigned long regno) | ||
143 | { | ||
144 | struct pt_regs *regs = task_pt_regs(child); | ||
145 | unsigned long val; | ||
146 | unsigned int seg; | ||
147 | switch (regno) { | ||
148 | case offsetof(struct user_regs_struct, fs): | ||
149 | if (child == current) { | ||
150 | /* Older gas can't assemble movq %?s,%r?? */ | ||
151 | asm("movl %%fs,%0" : "=r" (seg)); | ||
152 | return seg; | ||
153 | } | ||
154 | return child->thread.fsindex; | ||
155 | case offsetof(struct user_regs_struct, gs): | ||
156 | if (child == current) { | ||
157 | asm("movl %%gs,%0" : "=r" (seg)); | ||
158 | return seg; | ||
159 | } | ||
160 | return child->thread.gsindex; | ||
161 | case offsetof(struct user_regs_struct, ds): | ||
162 | if (child == current) { | ||
163 | asm("movl %%ds,%0" : "=r" (seg)); | ||
164 | return seg; | ||
165 | } | ||
166 | return child->thread.ds; | ||
167 | case offsetof(struct user_regs_struct, es): | ||
168 | if (child == current) { | ||
169 | asm("movl %%es,%0" : "=r" (seg)); | ||
170 | return seg; | ||
171 | } | ||
172 | return child->thread.es; | ||
173 | case offsetof(struct user_regs_struct, fs_base): | ||
174 | /* | ||
175 | * do_arch_prctl may have used a GDT slot instead of | ||
176 | * the MSR. To userland, it appears the same either | ||
177 | * way, except the %fs segment selector might not be 0. | ||
178 | */ | ||
179 | if (child->thread.fs != 0) | ||
180 | return child->thread.fs; | ||
181 | seg = child->thread.fsindex; | ||
182 | if (child == current) | ||
183 | asm("movl %%fs,%0" : "=r" (seg)); | ||
184 | if (seg != FS_TLS_SEL) | ||
185 | return 0; | ||
186 | return get_desc_base(&child->thread.tls_array[FS_TLS]); | ||
187 | case offsetof(struct user_regs_struct, gs_base): | ||
188 | /* | ||
189 | * Exactly the same here as the %fs handling above. | ||
190 | */ | ||
191 | if (child->thread.gs != 0) | ||
192 | return child->thread.gs; | ||
193 | seg = child->thread.gsindex; | ||
194 | if (child == current) | ||
195 | asm("movl %%gs,%0" : "=r" (seg)); | ||
196 | if (seg != GS_TLS_SEL) | ||
197 | return 0; | ||
198 | return get_desc_base(&child->thread.tls_array[GS_TLS]); | ||
199 | case offsetof(struct user_regs_struct, flags): | ||
200 | /* | ||
201 | * If the debugger set TF, hide it from the readout. | ||
202 | */ | ||
203 | val = regs->flags; | ||
204 | if (test_tsk_thread_flag(child, TIF_IA32)) | ||
205 | val &= 0xffffffff; | ||
206 | if (test_tsk_thread_flag(child, TIF_FORCED_TF)) | ||
207 | val &= ~X86_EFLAGS_TF; | ||
208 | return val; | ||
209 | default: | ||
210 | val = *pt_regs_access(regs, regno); | ||
211 | if (test_tsk_thread_flag(child, TIF_IA32)) | ||
212 | val &= 0xffffffff; | ||
213 | return val; | ||
214 | } | ||
215 | |||
216 | } | ||
217 | |||
218 | unsigned long ptrace_get_debugreg(struct task_struct *child, int n) | ||
219 | { | ||
220 | switch (n) { | ||
221 | case 0: return child->thread.debugreg0; | ||
222 | case 1: return child->thread.debugreg1; | ||
223 | case 2: return child->thread.debugreg2; | ||
224 | case 3: return child->thread.debugreg3; | ||
225 | case 6: return child->thread.debugreg6; | ||
226 | case 7: return child->thread.debugreg7; | ||
227 | } | ||
228 | return 0; | ||
229 | } | ||
230 | |||
231 | int ptrace_set_debugreg(struct task_struct *child, int n, unsigned long data) | ||
232 | { | ||
233 | int i; | ||
234 | |||
235 | if (n < 4) { | ||
236 | int dsize = test_tsk_thread_flag(child, TIF_IA32) ? 3 : 7; | ||
237 | if (unlikely(data >= TASK_SIZE_OF(child) - dsize)) | ||
238 | return -EIO; | ||
239 | } | ||
240 | |||
241 | switch (n) { | ||
242 | case 0: child->thread.debugreg0 = data; break; | ||
243 | case 1: child->thread.debugreg1 = data; break; | ||
244 | case 2: child->thread.debugreg2 = data; break; | ||
245 | case 3: child->thread.debugreg3 = data; break; | ||
246 | |||
247 | case 6: | ||
248 | if (data >> 32) | ||
249 | return -EIO; | ||
250 | child->thread.debugreg6 = data; | ||
251 | break; | ||
252 | |||
253 | case 7: | ||
254 | /* | ||
255 | * See ptrace_32.c for an explanation of this awkward check. | ||
256 | */ | ||
257 | data &= ~DR_CONTROL_RESERVED; | ||
258 | for (i = 0; i < 4; i++) | ||
259 | if ((0x5554 >> ((data >> (16 + 4*i)) & 0xf)) & 1) | ||
260 | return -EIO; | ||
261 | child->thread.debugreg7 = data; | ||
262 | if (data) | ||
263 | set_tsk_thread_flag(child, TIF_DEBUG); | ||
264 | else | ||
265 | clear_tsk_thread_flag(child, TIF_DEBUG); | ||
266 | break; | ||
267 | } | ||
268 | |||
269 | return 0; | ||
270 | } | ||
271 | |||
272 | long arch_ptrace(struct task_struct *child, long request, long addr, long data) | ||
273 | { | ||
274 | long ret; | ||
275 | unsigned ui; | ||
276 | |||
277 | switch (request) { | ||
278 | /* when I and D space are separate, these will need to be fixed. */ | ||
279 | case PTRACE_PEEKTEXT: /* read word at location addr. */ | ||
280 | case PTRACE_PEEKDATA: | ||
281 | ret = generic_ptrace_peekdata(child, addr, data); | ||
282 | break; | ||
283 | |||
284 | /* read the word at location addr in the USER area. */ | ||
285 | case PTRACE_PEEKUSR: { | ||
286 | unsigned long tmp; | ||
287 | |||
288 | ret = -EIO; | ||
289 | if ((addr & 7) || | ||
290 | addr > sizeof(struct user) - 7) | ||
291 | break; | ||
292 | |||
293 | tmp = 0; | ||
294 | if (addr < sizeof(struct user_regs_struct)) | ||
295 | tmp = getreg(child, addr); | ||
296 | else if (addr >= offsetof(struct user, u_debugreg[0])) { | ||
297 | addr -= offsetof(struct user, u_debugreg[0]); | ||
298 | tmp = ptrace_get_debugreg(child, addr / sizeof(long)); | ||
299 | } | ||
300 | |||
301 | ret = put_user(tmp,(unsigned long __user *) data); | ||
302 | break; | ||
303 | } | ||
304 | |||
305 | /* when I and D space are separate, this will have to be fixed. */ | ||
306 | case PTRACE_POKETEXT: /* write the word at location addr. */ | ||
307 | case PTRACE_POKEDATA: | ||
308 | ret = generic_ptrace_pokedata(child, addr, data); | ||
309 | break; | ||
310 | |||
311 | case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ | ||
312 | ret = -EIO; | ||
313 | if ((addr & 7) || | ||
314 | addr > sizeof(struct user) - 7) | ||
315 | break; | ||
316 | |||
317 | if (addr < sizeof(struct user_regs_struct)) | ||
318 | ret = putreg(child, addr, data); | ||
319 | else if (addr >= offsetof(struct user, u_debugreg[0])) { | ||
320 | addr -= offsetof(struct user, u_debugreg[0]); | ||
321 | ret = ptrace_set_debugreg(child, | ||
322 | addr / sizeof(long), data); | ||
323 | } | ||
324 | break; | ||
325 | |||
326 | #ifdef CONFIG_IA32_EMULATION | ||
327 | /* This makes only sense with 32bit programs. Allow a | ||
328 | 64bit debugger to fully examine them too. Better | ||
329 | don't use it against 64bit processes, use | ||
330 | PTRACE_ARCH_PRCTL instead. */ | ||
331 | case PTRACE_GET_THREAD_AREA: | ||
332 | if (addr < 0) | ||
333 | return -EIO; | ||
334 | ret = do_get_thread_area(child, addr, | ||
335 | (struct user_desc __user *) data); | ||
336 | |||
337 | break; | ||
338 | case PTRACE_SET_THREAD_AREA: | ||
339 | if (addr < 0) | ||
340 | return -EIO; | ||
341 | ret = do_set_thread_area(child, addr, | ||
342 | (struct user_desc __user *) data, 0); | ||
343 | break; | ||
344 | #endif | ||
345 | /* normal 64bit interface to access TLS data. | ||
346 | Works just like arch_prctl, except that the arguments | ||
347 | are reversed. */ | ||
348 | case PTRACE_ARCH_PRCTL: | ||
349 | ret = do_arch_prctl(child, data, addr); | ||
350 | break; | ||
351 | |||
352 | case PTRACE_GETREGS: { /* Get all gp regs from the child. */ | ||
353 | if (!access_ok(VERIFY_WRITE, (unsigned __user *)data, | ||
354 | sizeof(struct user_regs_struct))) { | ||
355 | ret = -EIO; | ||
356 | break; | ||
357 | } | ||
358 | ret = 0; | ||
359 | for (ui = 0; ui < sizeof(struct user_regs_struct); ui += sizeof(long)) { | ||
360 | ret |= __put_user(getreg(child, ui),(unsigned long __user *) data); | ||
361 | data += sizeof(long); | ||
362 | } | ||
363 | break; | ||
364 | } | ||
365 | |||
366 | case PTRACE_SETREGS: { /* Set all gp regs in the child. */ | ||
367 | unsigned long tmp; | ||
368 | if (!access_ok(VERIFY_READ, (unsigned __user *)data, | ||
369 | sizeof(struct user_regs_struct))) { | ||
370 | ret = -EIO; | ||
371 | break; | ||
372 | } | ||
373 | ret = 0; | ||
374 | for (ui = 0; ui < sizeof(struct user_regs_struct); ui += sizeof(long)) { | ||
375 | ret = __get_user(tmp, (unsigned long __user *) data); | ||
376 | if (ret) | ||
377 | break; | ||
378 | ret = putreg(child, ui, tmp); | ||
379 | if (ret) | ||
380 | break; | ||
381 | data += sizeof(long); | ||
382 | } | ||
383 | break; | ||
384 | } | ||
385 | |||
386 | case PTRACE_GETFPREGS: { /* Get the child extended FPU state. */ | ||
387 | if (!access_ok(VERIFY_WRITE, (unsigned __user *)data, | ||
388 | sizeof(struct user_i387_struct))) { | ||
389 | ret = -EIO; | ||
390 | break; | ||
391 | } | ||
392 | ret = get_fpregs((struct user_i387_struct __user *)data, child); | ||
393 | break; | ||
394 | } | ||
395 | |||
396 | case PTRACE_SETFPREGS: { /* Set the child extended FPU state. */ | ||
397 | if (!access_ok(VERIFY_READ, (unsigned __user *)data, | ||
398 | sizeof(struct user_i387_struct))) { | ||
399 | ret = -EIO; | ||
400 | break; | ||
401 | } | ||
402 | set_stopped_child_used_math(child); | ||
403 | ret = set_fpregs(child, (struct user_i387_struct __user *)data); | ||
404 | break; | ||
405 | } | ||
406 | |||
407 | default: | ||
408 | ret = ptrace_request(child, request, addr, data); | ||
409 | break; | ||
410 | } | ||
411 | return ret; | ||
412 | } | ||
413 | |||
414 | static void syscall_trace(struct pt_regs *regs) | ||
415 | { | ||
416 | |||
417 | #if 0 | ||
418 | printk("trace %s ip %lx sp %lx ax %d origrax %d caller %lx tiflags %x ptrace %x\n", | ||
419 | current->comm, | ||
420 | regs->ip, regs->sp, regs->ax, regs->orig_ax, __builtin_return_address(0), | ||
421 | current_thread_info()->flags, current->ptrace); | ||
422 | #endif | ||
423 | |||
424 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) | ||
425 | ? 0x80 : 0)); | ||
426 | /* | ||
427 | * this isn't the same as continuing with a signal, but it will do | ||
428 | * for normal use. strace only continues with a signal if the | ||
429 | * stopping signal is not SIGTRAP. -brl | ||
430 | */ | ||
431 | if (current->exit_code) { | ||
432 | send_sig(current->exit_code, current, 1); | ||
433 | current->exit_code = 0; | ||
434 | } | ||
435 | } | ||
436 | |||
437 | asmlinkage void syscall_trace_enter(struct pt_regs *regs) | ||
438 | { | ||
439 | /* do the secure computing check first */ | ||
440 | secure_computing(regs->orig_ax); | ||
441 | |||
442 | if (test_thread_flag(TIF_SYSCALL_TRACE) | ||
443 | && (current->ptrace & PT_PTRACED)) | ||
444 | syscall_trace(regs); | ||
445 | |||
446 | if (unlikely(current->audit_context)) { | ||
447 | if (test_thread_flag(TIF_IA32)) { | ||
448 | audit_syscall_entry(AUDIT_ARCH_I386, | ||
449 | regs->orig_ax, | ||
450 | regs->bx, regs->cx, | ||
451 | regs->dx, regs->si); | ||
452 | } else { | ||
453 | audit_syscall_entry(AUDIT_ARCH_X86_64, | ||
454 | regs->orig_ax, | ||
455 | regs->di, regs->si, | ||
456 | regs->dx, regs->r10); | ||
457 | } | ||
458 | } | ||
459 | } | ||
460 | |||
461 | asmlinkage void syscall_trace_leave(struct pt_regs *regs) | ||
462 | { | ||
463 | if (unlikely(current->audit_context)) | ||
464 | audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax); | ||
465 | |||
466 | if ((test_thread_flag(TIF_SYSCALL_TRACE) | ||
467 | || test_thread_flag(TIF_SINGLESTEP)) | ||
468 | && (current->ptrace & PT_PTRACED)) | ||
469 | syscall_trace(regs); | ||
470 | } | ||