blob: bc7fd802dcc7ff3c6e5083564b5062fa38261c90 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* By Ross Biro 1/23/92 */
2/*
3 * Pentium III FXSR, SSE support
4 * Gareth Hughes <gareth@valinux.com>, May 2000
5 */
6
7#include <linux/kernel.h>
8#include <linux/sched.h>
9#include <linux/mm.h>
10#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/errno.h>
12#include <linux/ptrace.h>
13#include <linux/user.h>
14#include <linux/security.h>
15#include <linux/audit.h>
16#include <linux/seccomp.h>
Jesper Juhl7ed20e12005-05-01 08:59:14 -070017#include <linux/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#include <asm/uaccess.h>
20#include <asm/pgtable.h>
21#include <asm/system.h>
22#include <asm/processor.h>
23#include <asm/i387.h>
24#include <asm/debugreg.h>
25#include <asm/ldt.h>
26#include <asm/desc.h>
27
28/*
29 * does not yet catch signals sent when the child dies.
30 * in exit.c or in signal.c.
31 */
32
Chuck Ebbert9f155b92006-01-05 23:11:29 -050033/*
34 * Determines which flags the user has access to [1 = access, 0 = no access].
Chuck Ebbert3c36c6a2006-03-23 02:59:39 -080035 * Prohibits changing ID(21), VIP(20), VIF(19), VM(17), NT(14), IOPL(12-13), IF(9).
Chuck Ebbert9f155b92006-01-05 23:11:29 -050036 * Also masks reserved bits (31-22, 15, 5, 3, 1).
37 */
Chuck Ebbert3c36c6a2006-03-23 02:59:39 -080038#define FLAG_MASK 0x00050dd5
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040/*
41 * Offset of eflags on child stack..
42 */
Jeremy Fitzhardinge8701ea92006-12-22 01:11:21 -080043#define EFL_OFFSET offsetof(struct pt_regs, eflags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45static inline struct pt_regs *get_child_regs(struct task_struct *task)
46{
47 void *stack_top = (void *)task->thread.esp0;
48 return stack_top - sizeof(struct pt_regs);
49}
50
51/*
Jeremy Fitzhardinge8701ea92006-12-22 01:11:21 -080052 * This routine will get a word off of the processes privileged stack.
53 * the offset is bytes into the pt_regs structure on the stack.
54 * This routine assumes that all the privileged stacks are in our
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 * data space.
56 */
57static inline int get_stack_long(struct task_struct *task, int offset)
58{
59 unsigned char *stack;
60
Jeremy Fitzhardinge8701ea92006-12-22 01:11:21 -080061 stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 stack += offset;
63 return (*((int *)stack));
64}
65
66/*
Jeremy Fitzhardinge8701ea92006-12-22 01:11:21 -080067 * This routine will put a word on the processes privileged stack.
68 * the offset is bytes into the pt_regs structure on the stack.
69 * This routine assumes that all the privileged stacks are in our
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 * data space.
71 */
72static inline int put_stack_long(struct task_struct *task, int offset,
73 unsigned long data)
74{
75 unsigned char * stack;
76
Jeremy Fitzhardinge8701ea92006-12-22 01:11:21 -080077 stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 stack += offset;
79 *(unsigned long *) stack = data;
80 return 0;
81}
82
83static int putreg(struct task_struct *child,
84 unsigned long regno, unsigned long value)
85{
86 switch (regno >> 2) {
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010087 case GS:
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 if (value && (value & 3) != 3)
89 return -EIO;
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010090 child->thread.gs = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 case DS:
93 case ES:
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010094 case FS:
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 if (value && (value & 3) != 3)
96 return -EIO;
97 value &= 0xffff;
98 break;
99 case SS:
100 case CS:
101 if ((value & 3) != 3)
102 return -EIO;
103 value &= 0xffff;
104 break;
105 case EFL:
106 value &= FLAG_MASK;
Roland McGrathe1f28772008-01-30 13:30:50 +0100107 /*
108 * If the user value contains TF, mark that
109 * it was not "us" (the debugger) that set it.
110 * If not, make sure it stays set if we had.
111 */
112 if (value & X86_EFLAGS_TF)
113 clear_tsk_thread_flag(child, TIF_FORCED_TF);
114 else if (test_tsk_thread_flag(child, TIF_FORCED_TF))
115 value |= X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 value |= get_stack_long(child, EFL_OFFSET) & ~FLAG_MASK;
117 break;
118 }
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100119 if (regno > FS*4)
Jeremy Fitzhardinge66e10a42006-12-07 02:14:02 +0100120 regno -= 1*4;
Jeremy Fitzhardinge8701ea92006-12-22 01:11:21 -0800121 put_stack_long(child, regno, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return 0;
123}
124
125static unsigned long getreg(struct task_struct *child,
126 unsigned long regno)
127{
128 unsigned long retval = ~0UL;
129
130 switch (regno >> 2) {
Roland McGrathe1f28772008-01-30 13:30:50 +0100131 case EFL:
132 /*
133 * If the debugger set TF, hide it from the readout.
134 */
135 retval = get_stack_long(child, EFL_OFFSET);
136 if (test_tsk_thread_flag(child, TIF_FORCED_TF))
137 retval &= ~X86_EFLAGS_TF;
138 break;
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100139 case GS:
140 retval = child->thread.gs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 case DS:
143 case ES:
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100144 case FS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 case SS:
146 case CS:
147 retval = 0xffff;
148 /* fall through */
149 default:
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100150 if (regno > FS*4)
Jeremy Fitzhardinge66e10a42006-12-07 02:14:02 +0100151 regno -= 1*4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 retval &= get_stack_long(child, regno);
153 }
154 return retval;
155}
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157/*
158 * Called by kernel/ptrace.c when detaching..
159 *
160 * Make sure the single step bit is not set.
161 */
162void ptrace_disable(struct task_struct *child)
163{
Roland McGrath7f232342008-01-30 13:30:48 +0100164 user_disable_single_step(child);
Bodo Stroesserab1c23c2005-09-03 15:57:21 -0700165 clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166}
167
Christoph Hellwig481bed42005-11-07 00:59:47 -0800168long arch_ptrace(struct task_struct *child, long request, long addr, long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 struct user * dummy = NULL;
171 int i, ret;
172 unsigned long __user *datap = (unsigned long __user *)data;
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 switch (request) {
175 /* when I and D space are separate, these will need to be fixed. */
176 case PTRACE_PEEKTEXT: /* read word at location addr. */
Alexey Dobriyan76647322007-07-17 04:03:43 -0700177 case PTRACE_PEEKDATA:
178 ret = generic_ptrace_peekdata(child, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 /* read the word at location addr in the USER area. */
182 case PTRACE_PEEKUSR: {
183 unsigned long tmp;
184
185 ret = -EIO;
186 if ((addr & 3) || addr < 0 ||
187 addr > sizeof(struct user) - 3)
188 break;
189
190 tmp = 0; /* Default return condition */
191 if(addr < FRAME_SIZE*sizeof(long))
192 tmp = getreg(child, addr);
193 if(addr >= (long) &dummy->u_debugreg[0] &&
194 addr <= (long) &dummy->u_debugreg[7]){
195 addr -= (long) &dummy->u_debugreg[0];
196 addr = addr >> 2;
197 tmp = child->thread.debugreg[addr];
198 }
199 ret = put_user(tmp, datap);
200 break;
201 }
202
203 /* when I and D space are separate, this will have to be fixed. */
204 case PTRACE_POKETEXT: /* write the word at location addr. */
205 case PTRACE_POKEDATA:
Alexey Dobriyanf284ce72007-07-17 04:03:44 -0700206 ret = generic_ptrace_pokedata(child, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 break;
208
209 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
210 ret = -EIO;
211 if ((addr & 3) || addr < 0 ||
212 addr > sizeof(struct user) - 3)
213 break;
214
215 if (addr < FRAME_SIZE*sizeof(long)) {
216 ret = putreg(child, addr, data);
217 break;
218 }
219 /* We need to be very careful here. We implicitly
220 want to modify a portion of the task_struct, and we
221 have to be selective about what portions we allow someone
222 to modify. */
223
224 ret = -EIO;
225 if(addr >= (long) &dummy->u_debugreg[0] &&
226 addr <= (long) &dummy->u_debugreg[7]){
227
228 if(addr == (long) &dummy->u_debugreg[4]) break;
229 if(addr == (long) &dummy->u_debugreg[5]) break;
230 if(addr < (long) &dummy->u_debugreg[4] &&
231 ((unsigned long) data) >= TASK_SIZE-3) break;
232
233 /* Sanity-check data. Take one half-byte at once with
234 * check = (val >> (16 + 4*i)) & 0xf. It contains the
235 * R/Wi and LENi bits; bits 0 and 1 are R/Wi, and bits
236 * 2 and 3 are LENi. Given a list of invalid values,
237 * we do mask |= 1 << invalid_value, so that
238 * (mask >> check) & 1 is a correct test for invalid
239 * values.
240 *
241 * R/Wi contains the type of the breakpoint /
242 * watchpoint, LENi contains the length of the watched
243 * data in the watchpoint case.
244 *
245 * The invalid values are:
246 * - LENi == 0x10 (undefined), so mask |= 0x0f00.
247 * - R/Wi == 0x10 (break on I/O reads or writes), so
248 * mask |= 0x4444.
249 * - R/Wi == 0x00 && LENi != 0x00, so we have mask |=
250 * 0x1110.
251 *
252 * Finally, mask = 0x0f00 | 0x4444 | 0x1110 == 0x5f54.
253 *
254 * See the Intel Manual "System Programming Guide",
255 * 15.2.4
256 *
257 * Note that LENi == 0x10 is defined on x86_64 in long
258 * mode (i.e. even for 32-bit userspace software, but
259 * 64-bit kernel), so the x86_64 mask value is 0x5454.
260 * See the AMD manual no. 24593 (AMD64 System
261 * Programming)*/
262
263 if(addr == (long) &dummy->u_debugreg[7]) {
264 data &= ~DR_CONTROL_RESERVED;
265 for(i=0; i<4; i++)
266 if ((0x5f54 >> ((data >> (16 + 4*i)) & 0xf)) & 1)
267 goto out_tsk;
Stephane Eranianb3cf2572006-07-09 21:12:39 -0400268 if (data)
269 set_tsk_thread_flag(child, TIF_DEBUG);
270 else
271 clear_tsk_thread_flag(child, TIF_DEBUG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 addr -= (long) &dummy->u_debugreg;
274 addr = addr >> 2;
275 child->thread.debugreg[addr] = data;
276 ret = 0;
277 }
278 break;
279
Laurent Viviered75e8d2005-09-03 15:57:18 -0700280 case PTRACE_SYSEMU: /* continue and stop at next syscall, which will not be executed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
282 case PTRACE_CONT: /* restart after signal. */
283 ret = -EIO;
Jesper Juhl7ed20e12005-05-01 08:59:14 -0700284 if (!valid_signal(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 break;
Laurent Viviered75e8d2005-09-03 15:57:18 -0700286 if (request == PTRACE_SYSEMU) {
287 set_tsk_thread_flag(child, TIF_SYSCALL_EMU);
Bodo Stroesserc8c86ce2005-09-03 15:57:19 -0700288 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
289 } else if (request == PTRACE_SYSCALL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
Bodo Stroesserc8c86ce2005-09-03 15:57:19 -0700291 clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
Laurent Viviered75e8d2005-09-03 15:57:18 -0700292 } else {
Bodo Stroesserc8c86ce2005-09-03 15:57:19 -0700293 clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
295 }
296 child->exit_code = data;
297 /* make sure the single step bit is not set. */
Roland McGrath7f232342008-01-30 13:30:48 +0100298 user_disable_single_step(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 wake_up_process(child);
300 ret = 0;
301 break;
302
303/*
304 * make the child exit. Best I can do is send it a sigkill.
305 * perhaps it should be put in the status that it wants to
306 * exit.
307 */
308 case PTRACE_KILL:
309 ret = 0;
310 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
311 break;
312 child->exit_code = SIGKILL;
313 /* make sure the single step bit is not set. */
Roland McGrath7f232342008-01-30 13:30:48 +0100314 user_disable_single_step(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 wake_up_process(child);
316 break;
317
Bodo Stroesser1b38f002005-09-03 15:57:20 -0700318 case PTRACE_SYSEMU_SINGLESTEP: /* Same as SYSEMU, but singlestep if not syscall */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 case PTRACE_SINGLESTEP: /* set the trap flag. */
320 ret = -EIO;
Jesper Juhl7ed20e12005-05-01 08:59:14 -0700321 if (!valid_signal(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 break;
Bodo Stroesser1b38f002005-09-03 15:57:20 -0700323
324 if (request == PTRACE_SYSEMU_SINGLESTEP)
325 set_tsk_thread_flag(child, TIF_SYSCALL_EMU);
326 else
327 clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
Roland McGrath7f232342008-01-30 13:30:48 +0100330 user_enable_single_step(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 child->exit_code = data;
332 /* give it a chance to run. */
333 wake_up_process(child);
334 ret = 0;
335 break;
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
338 if (!access_ok(VERIFY_WRITE, datap, FRAME_SIZE*sizeof(long))) {
339 ret = -EIO;
340 break;
341 }
342 for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) {
343 __put_user(getreg(child, i), datap);
344 datap++;
345 }
346 ret = 0;
347 break;
348 }
349
350 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
351 unsigned long tmp;
352 if (!access_ok(VERIFY_READ, datap, FRAME_SIZE*sizeof(long))) {
353 ret = -EIO;
354 break;
355 }
356 for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) {
357 __get_user(tmp, datap);
358 putreg(child, i, tmp);
359 datap++;
360 }
361 ret = 0;
362 break;
363 }
364
365 case PTRACE_GETFPREGS: { /* Get the child FPU state. */
366 if (!access_ok(VERIFY_WRITE, datap,
367 sizeof(struct user_i387_struct))) {
368 ret = -EIO;
369 break;
370 }
371 ret = 0;
372 if (!tsk_used_math(child))
373 init_fpu(child);
374 get_fpregs((struct user_i387_struct __user *)data, child);
375 break;
376 }
377
378 case PTRACE_SETFPREGS: { /* Set the child FPU state. */
379 if (!access_ok(VERIFY_READ, datap,
380 sizeof(struct user_i387_struct))) {
381 ret = -EIO;
382 break;
383 }
384 set_stopped_child_used_math(child);
385 set_fpregs(child, (struct user_i387_struct __user *)data);
386 ret = 0;
387 break;
388 }
389
390 case PTRACE_GETFPXREGS: { /* Get the child extended FPU state. */
391 if (!access_ok(VERIFY_WRITE, datap,
392 sizeof(struct user_fxsr_struct))) {
393 ret = -EIO;
394 break;
395 }
396 if (!tsk_used_math(child))
397 init_fpu(child);
398 ret = get_fpxregs((struct user_fxsr_struct __user *)data, child);
399 break;
400 }
401
402 case PTRACE_SETFPXREGS: { /* Set the child extended FPU state. */
403 if (!access_ok(VERIFY_READ, datap,
404 sizeof(struct user_fxsr_struct))) {
405 ret = -EIO;
406 break;
407 }
408 set_stopped_child_used_math(child);
409 ret = set_fpxregs(child, (struct user_fxsr_struct __user *)data);
410 break;
411 }
412
413 case PTRACE_GET_THREAD_AREA:
Roland McGrathefd1ca52008-01-30 13:30:46 +0100414 if (addr < 0)
415 return -EIO;
416 ret = do_get_thread_area(child, addr,
417 (struct user_desc __user *) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 break;
419
420 case PTRACE_SET_THREAD_AREA:
Roland McGrathefd1ca52008-01-30 13:30:46 +0100421 if (addr < 0)
422 return -EIO;
423 ret = do_set_thread_area(child, addr,
424 (struct user_desc __user *) data, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 break;
426
427 default:
428 ret = ptrace_request(child, request, addr, data);
429 break;
430 }
Christoph Hellwig481bed42005-11-07 00:59:47 -0800431 out_tsk:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 return ret;
433}
434
435void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code)
436{
437 struct siginfo info;
438
439 tsk->thread.trap_no = 1;
440 tsk->thread.error_code = error_code;
441
442 memset(&info, 0, sizeof(info));
443 info.si_signo = SIGTRAP;
444 info.si_code = TRAP_BRKPT;
445
446 /* User-mode eip? */
Vincent Hanquezfa1e1bd2005-06-23 00:08:44 -0700447 info.si_addr = user_mode_vm(regs) ? (void __user *) regs->eip : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Simon Arlott27b46d72007-10-20 01:13:56 +0200449 /* Send us the fake SIGTRAP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 force_sig_info(SIGTRAP, &info, tsk);
451}
452
453/* notification of system call entry/exit
454 * - triggered by current->work.syscall_trace
455 */
456__attribute__((regparm(3)))
Laurent Viviered75e8d2005-09-03 15:57:18 -0700457int do_syscall_trace(struct pt_regs *regs, int entryexit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
Andrea Arcangeli4c7fc722005-09-09 13:01:51 -0700459 int is_sysemu = test_thread_flag(TIF_SYSCALL_EMU);
460 /*
461 * With TIF_SYSCALL_EMU set we want to ignore TIF_SINGLESTEP for syscall
462 * interception
463 */
Bodo Stroesser1b38f002005-09-03 15:57:20 -0700464 int is_singlestep = !is_sysemu && test_thread_flag(TIF_SINGLESTEP);
Andrea Arcangeli4c7fc722005-09-09 13:01:51 -0700465 int ret = 0;
Bodo Stroesser1b38f002005-09-03 15:57:20 -0700466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 /* do the secure computing check first */
Andrea Arcangeli4c7fc722005-09-09 13:01:51 -0700468 if (!entryexit)
469 secure_computing(regs->orig_eax);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Bodo Stroesserab1c23c2005-09-03 15:57:21 -0700471 if (unlikely(current->audit_context)) {
472 if (entryexit)
Al Viro5411be52006-03-29 20:23:36 -0500473 audit_syscall_exit(AUDITSC_RESULT(regs->eax),
Andrea Arcangeli4c7fc722005-09-09 13:01:51 -0700474 regs->eax);
Bodo Stroesserab1c23c2005-09-03 15:57:21 -0700475 /* Debug traps, when using PTRACE_SINGLESTEP, must be sent only
476 * on the syscall exit path. Normally, when TIF_SYSCALL_AUDIT is
477 * not used, entry.S will call us only on syscall exit, not
478 * entry; so when TIF_SYSCALL_AUDIT is used we must avoid
479 * calling send_sigtrap() on syscall entry.
480 *
481 * Note that when PTRACE_SYSEMU_SINGLESTEP is used,
482 * is_singlestep is false, despite his name, so we will still do
483 * the correct thing.
484 */
485 else if (is_singlestep)
486 goto out;
487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 if (!(current->ptrace & PT_PTRACED))
2fd6f582005-04-29 16:08:28 +0100490 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Bodo Stroesser1b38f002005-09-03 15:57:20 -0700492 /* If a process stops on the 1st tracepoint with SYSCALL_TRACE
493 * and then is resumed with SYSEMU_SINGLESTEP, it will come in
494 * here. We have to check this and return */
495 if (is_sysemu && entryexit)
496 return 0;
Laurent Viviered75e8d2005-09-03 15:57:18 -0700497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 /* Fake a debug trap */
Bodo Stroesserc8c86ce2005-09-03 15:57:19 -0700499 if (is_singlestep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 send_sigtrap(current, regs, 0);
501
Bodo Stroesserc8c86ce2005-09-03 15:57:19 -0700502 if (!test_thread_flag(TIF_SYSCALL_TRACE) && !is_sysemu)
2fd6f582005-04-29 16:08:28 +0100503 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 /* the 0x80 provides a way for the tracing parent to distinguish
506 between a syscall stop and SIGTRAP delivery */
Laurent Viviered75e8d2005-09-03 15:57:18 -0700507 /* Note that the debugger could change the result of test_thread_flag!*/
Andrea Arcangeli4c7fc722005-09-09 13:01:51 -0700508 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) ? 0x80:0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 /*
511 * this isn't the same as continuing with a signal, but it will do
512 * for normal use. strace only continues with a signal if the
513 * stopping signal is not SIGTRAP. -brl
514 */
515 if (current->exit_code) {
516 send_sig(current->exit_code, current, 1);
517 current->exit_code = 0;
518 }
Laurent Viviered75e8d2005-09-03 15:57:18 -0700519 ret = is_sysemu;
Andrea Arcangeli4c7fc722005-09-09 13:01:51 -0700520out:
2fd6f582005-04-29 16:08:28 +0100521 if (unlikely(current->audit_context) && !entryexit)
Al Viro5411be52006-03-29 20:23:36 -0500522 audit_syscall_entry(AUDIT_ARCH_I386, regs->orig_eax,
2fd6f582005-04-29 16:08:28 +0100523 regs->ebx, regs->ecx, regs->edx, regs->esi);
Bodo Stroesserc8c86ce2005-09-03 15:57:19 -0700524 if (ret == 0)
525 return 0;
526
Bodo Stroesser1b38f002005-09-03 15:57:20 -0700527 regs->orig_eax = -1; /* force skip of syscall restarting */
Bodo Stroesserc8c86ce2005-09-03 15:57:19 -0700528 if (unlikely(current->audit_context))
Al Viro5411be52006-03-29 20:23:36 -0500529 audit_syscall_exit(AUDITSC_RESULT(regs->eax), regs->eax);
Bodo Stroesserc8c86ce2005-09-03 15:57:19 -0700530 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531}