x86: x86 ptrace getreg/putreg merge
[firefly-linux-kernel-4.4.55.git] / arch / x86 / kernel / ptrace.c
1 /* 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>
11 #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>
17 #include <linux/signal.h>
18
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 #include <asm/prctl.h>
28 #include <asm/proto.h>
29
30 /*
31  * does not yet catch signals sent when the child dies.
32  * in exit.c or in signal.c.
33  */
34
35 /*
36  * Determines which flags the user has access to [1 = access, 0 = no access].
37  */
38 #define FLAG_MASK_32            ((unsigned long)                        \
39                                  (X86_EFLAGS_CF | X86_EFLAGS_PF |       \
40                                   X86_EFLAGS_AF | X86_EFLAGS_ZF |       \
41                                   X86_EFLAGS_SF | X86_EFLAGS_TF |       \
42                                   X86_EFLAGS_DF | X86_EFLAGS_OF |       \
43                                   X86_EFLAGS_RF | X86_EFLAGS_AC))
44
45 /*
46  * Determines whether a value may be installed in a segment register.
47  */
48 static inline bool invalid_selector(u16 value)
49 {
50         return unlikely(value != 0 && (value & SEGMENT_RPL_MASK) != USER_RPL);
51 }
52
53 #ifdef CONFIG_X86_32
54
55 #define FLAG_MASK               FLAG_MASK_32
56
57 static long *pt_regs_access(struct pt_regs *regs, unsigned long regno)
58 {
59         BUILD_BUG_ON(offsetof(struct pt_regs, bx) != 0);
60         regno >>= 2;
61         if (regno > FS)
62                 --regno;
63         return &regs->bx + regno;
64 }
65
66 static u16 get_segment_reg(struct task_struct *task, unsigned long offset)
67 {
68         /*
69          * Returning the value truncates it to 16 bits.
70          */
71         unsigned int retval;
72         if (offset != offsetof(struct user_regs_struct, gs))
73                 retval = *pt_regs_access(task_pt_regs(task), offset);
74         else {
75                 retval = task->thread.gs;
76                 if (task == current)
77                         savesegment(gs, retval);
78         }
79         return retval;
80 }
81
82 static int set_segment_reg(struct task_struct *task,
83                            unsigned long offset, u16 value)
84 {
85         /*
86          * The value argument was already truncated to 16 bits.
87          */
88         if (invalid_selector(value))
89                 return -EIO;
90
91         if (offset != offsetof(struct user_regs_struct, gs))
92                 *pt_regs_access(task_pt_regs(task), offset) = value;
93         else {
94                 task->thread.gs = value;
95                 if (task == current)
96                         /*
97                          * The user-mode %gs is not affected by
98                          * kernel entry, so we must update the CPU.
99                          */
100                         loadsegment(gs, value);
101         }
102
103         return 0;
104 }
105
106 static unsigned long debugreg_addr_limit(struct task_struct *task)
107 {
108         return TASK_SIZE - 3;
109 }
110
111 #else  /* CONFIG_X86_64 */
112
113 #define FLAG_MASK               (FLAG_MASK_32 | X86_EFLAGS_NT)
114
115 static unsigned long *pt_regs_access(struct pt_regs *regs, unsigned long offset)
116 {
117         BUILD_BUG_ON(offsetof(struct pt_regs, r15) != 0);
118         return &regs->r15 + (offset / sizeof(regs->r15));
119 }
120
121 static u16 get_segment_reg(struct task_struct *task, unsigned long offset)
122 {
123         /*
124          * Returning the value truncates it to 16 bits.
125          */
126         unsigned int seg;
127
128         switch (offset) {
129         case offsetof(struct user_regs_struct, fs):
130                 if (task == current) {
131                         /* Older gas can't assemble movq %?s,%r?? */
132                         asm("movl %%fs,%0" : "=r" (seg));
133                         return seg;
134                 }
135                 return task->thread.fsindex;
136         case offsetof(struct user_regs_struct, gs):
137                 if (task == current) {
138                         asm("movl %%gs,%0" : "=r" (seg));
139                         return seg;
140                 }
141                 return task->thread.gsindex;
142         case offsetof(struct user_regs_struct, ds):
143                 if (task == current) {
144                         asm("movl %%ds,%0" : "=r" (seg));
145                         return seg;
146                 }
147                 return task->thread.ds;
148         case offsetof(struct user_regs_struct, es):
149                 if (task == current) {
150                         asm("movl %%es,%0" : "=r" (seg));
151                         return seg;
152                 }
153                 return task->thread.es;
154
155         case offsetof(struct user_regs_struct, cs):
156         case offsetof(struct user_regs_struct, ss):
157                 break;
158         }
159         return *pt_regs_access(task_pt_regs(task), offset);
160 }
161
162 static int set_segment_reg(struct task_struct *task,
163                            unsigned long offset, u16 value)
164 {
165         /*
166          * The value argument was already truncated to 16 bits.
167          */
168         if (invalid_selector(value))
169                 return -EIO;
170
171         switch (offset) {
172         case offsetof(struct user_regs_struct,fs):
173                 /*
174                  * If this is setting fs as for normal 64-bit use but
175                  * setting fs_base has implicitly changed it, leave it.
176                  */
177                 if ((value == FS_TLS_SEL && task->thread.fsindex == 0 &&
178                      task->thread.fs != 0) ||
179                     (value == 0 && task->thread.fsindex == FS_TLS_SEL &&
180                      task->thread.fs == 0))
181                         break;
182                 task->thread.fsindex = value;
183                 if (task == current)
184                         loadsegment(fs, task->thread.fsindex);
185                 break;
186         case offsetof(struct user_regs_struct,gs):
187                 /*
188                  * If this is setting gs as for normal 64-bit use but
189                  * setting gs_base has implicitly changed it, leave it.
190                  */
191                 if ((value == GS_TLS_SEL && task->thread.gsindex == 0 &&
192                      task->thread.gs != 0) ||
193                     (value == 0 && task->thread.gsindex == GS_TLS_SEL &&
194                      task->thread.gs == 0))
195                         break;
196                 task->thread.gsindex = value;
197                 if (task == current)
198                         load_gs_index(task->thread.gsindex);
199                 break;
200         case offsetof(struct user_regs_struct,ds):
201                 task->thread.ds = value;
202                 if (task == current)
203                         loadsegment(ds, task->thread.ds);
204                 break;
205         case offsetof(struct user_regs_struct,es):
206                 task->thread.es = value;
207                 if (task == current)
208                         loadsegment(es, task->thread.es);
209                 break;
210
211                 /*
212                  * Can't actually change these in 64-bit mode.
213                  */
214         case offsetof(struct user_regs_struct,cs):
215 #ifdef CONFIG_IA32_EMULATION
216                 if (test_tsk_thread_flag(task, TIF_IA32))
217                         task_pt_regs(task)->cs = value;
218                 break;
219 #endif
220         case offsetof(struct user_regs_struct,ss):
221 #ifdef CONFIG_IA32_EMULATION
222                 if (test_tsk_thread_flag(task, TIF_IA32))
223                         task_pt_regs(task)->ss = value;
224                 break;
225 #endif
226         }
227
228         return 0;
229 }
230
231 static unsigned long debugreg_addr_limit(struct task_struct *task)
232 {
233 #ifdef CONFIG_IA32_EMULATION
234         if (test_tsk_thread_flag(task, TIF_IA32))
235                 return IA32_PAGE_OFFSET - 3;
236 #endif
237         return TASK_SIZE64 - 7;
238 }
239
240 #endif  /* CONFIG_X86_32 */
241
242 static unsigned long get_flags(struct task_struct *task)
243 {
244         unsigned long retval = task_pt_regs(task)->flags;
245
246         /*
247          * If the debugger set TF, hide it from the readout.
248          */
249         if (test_tsk_thread_flag(task, TIF_FORCED_TF))
250                 retval &= ~X86_EFLAGS_TF;
251
252         return retval;
253 }
254
255 static int set_flags(struct task_struct *task, unsigned long value)
256 {
257         struct pt_regs *regs = task_pt_regs(task);
258
259         /*
260          * If the user value contains TF, mark that
261          * it was not "us" (the debugger) that set it.
262          * If not, make sure it stays set if we had.
263          */
264         if (value & X86_EFLAGS_TF)
265                 clear_tsk_thread_flag(task, TIF_FORCED_TF);
266         else if (test_tsk_thread_flag(task, TIF_FORCED_TF))
267                 value |= X86_EFLAGS_TF;
268
269         regs->flags = (regs->flags & ~FLAG_MASK) | (value & FLAG_MASK);
270
271         return 0;
272 }
273
274 static int putreg(struct task_struct *child,
275                   unsigned long offset, unsigned long value)
276 {
277         switch (offset) {
278         case offsetof(struct user_regs_struct, cs):
279         case offsetof(struct user_regs_struct, ds):
280         case offsetof(struct user_regs_struct, es):
281         case offsetof(struct user_regs_struct, fs):
282         case offsetof(struct user_regs_struct, gs):
283         case offsetof(struct user_regs_struct, ss):
284                 return set_segment_reg(child, offset, value);
285
286         case offsetof(struct user_regs_struct, flags):
287                 return set_flags(child, value);
288
289 #ifdef CONFIG_X86_64
290         case offsetof(struct user_regs_struct,fs_base):
291                 if (value >= TASK_SIZE_OF(child))
292                         return -EIO;
293                 /*
294                  * When changing the segment base, use do_arch_prctl
295                  * to set either thread.fs or thread.fsindex and the
296                  * corresponding GDT slot.
297                  */
298                 if (child->thread.fs != value)
299                         return do_arch_prctl(child, ARCH_SET_FS, value);
300                 return 0;
301         case offsetof(struct user_regs_struct,gs_base):
302                 /*
303                  * Exactly the same here as the %fs handling above.
304                  */
305                 if (value >= TASK_SIZE_OF(child))
306                         return -EIO;
307                 if (child->thread.gs != value)
308                         return do_arch_prctl(child, ARCH_SET_GS, value);
309                 return 0;
310 #endif
311         }
312
313         *pt_regs_access(task_pt_regs(child), offset) = value;
314         return 0;
315 }
316
317 static unsigned long getreg(struct task_struct *task, unsigned long offset)
318 {
319         switch (offset) {
320         case offsetof(struct user_regs_struct, cs):
321         case offsetof(struct user_regs_struct, ds):
322         case offsetof(struct user_regs_struct, es):
323         case offsetof(struct user_regs_struct, fs):
324         case offsetof(struct user_regs_struct, gs):
325         case offsetof(struct user_regs_struct, ss):
326                 return get_segment_reg(task, offset);
327
328         case offsetof(struct user_regs_struct, flags):
329                 return get_flags(task);
330
331 #ifdef CONFIG_X86_64
332         case offsetof(struct user_regs_struct, fs_base): {
333                 /*
334                  * do_arch_prctl may have used a GDT slot instead of
335                  * the MSR.  To userland, it appears the same either
336                  * way, except the %fs segment selector might not be 0.
337                  */
338                 unsigned int seg = task->thread.fsindex;
339                 if (task->thread.fs != 0)
340                         return task->thread.fs;
341                 if (task == current)
342                         asm("movl %%fs,%0" : "=r" (seg));
343                 if (seg != FS_TLS_SEL)
344                         return 0;
345                 return get_desc_base(&task->thread.tls_array[FS_TLS]);
346         }
347         case offsetof(struct user_regs_struct, gs_base): {
348                 /*
349                  * Exactly the same here as the %fs handling above.
350                  */
351                 unsigned int seg = task->thread.gsindex;
352                 if (task->thread.gs != 0)
353                         return task->thread.gs;
354                 if (task == current)
355                         asm("movl %%gs,%0" : "=r" (seg));
356                 if (seg != GS_TLS_SEL)
357                         return 0;
358                 return get_desc_base(&task->thread.tls_array[GS_TLS]);
359         }
360 #endif
361         }
362
363         return *pt_regs_access(task_pt_regs(task), offset);
364 }
365
366 /*
367  * This function is trivial and will be inlined by the compiler.
368  * Having it separates the implementation details of debug
369  * registers from the interface details of ptrace.
370  */
371 static unsigned long ptrace_get_debugreg(struct task_struct *child, int n)
372 {
373         switch (n) {
374         case 0:         return child->thread.debugreg0;
375         case 1:         return child->thread.debugreg1;
376         case 2:         return child->thread.debugreg2;
377         case 3:         return child->thread.debugreg3;
378         case 6:         return child->thread.debugreg6;
379         case 7:         return child->thread.debugreg7;
380         }
381         return 0;
382 }
383
384 static int ptrace_set_debugreg(struct task_struct *child,
385                                int n, unsigned long data)
386 {
387         int i;
388
389         if (unlikely(n == 4 || n == 5))
390                 return -EIO;
391
392         if (n < 4 && unlikely(data >= debugreg_addr_limit(child)))
393                 return -EIO;
394
395         switch (n) {
396         case 0:         child->thread.debugreg0 = data; break;
397         case 1:         child->thread.debugreg1 = data; break;
398         case 2:         child->thread.debugreg2 = data; break;
399         case 3:         child->thread.debugreg3 = data; break;
400
401         case 6:
402                 if ((data & ~0xffffffffUL) != 0)
403                         return -EIO;
404                 child->thread.debugreg6 = data;
405                 break;
406
407         case 7:
408                 /*
409                  * Sanity-check data. Take one half-byte at once with
410                  * check = (val >> (16 + 4*i)) & 0xf. It contains the
411                  * R/Wi and LENi bits; bits 0 and 1 are R/Wi, and bits
412                  * 2 and 3 are LENi. Given a list of invalid values,
413                  * we do mask |= 1 << invalid_value, so that
414                  * (mask >> check) & 1 is a correct test for invalid
415                  * values.
416                  *
417                  * R/Wi contains the type of the breakpoint /
418                  * watchpoint, LENi contains the length of the watched
419                  * data in the watchpoint case.
420                  *
421                  * The invalid values are:
422                  * - LENi == 0x10 (undefined), so mask |= 0x0f00.       [32-bit]
423                  * - R/Wi == 0x10 (break on I/O reads or writes), so
424                  *   mask |= 0x4444.
425                  * - R/Wi == 0x00 && LENi != 0x00, so we have mask |=
426                  *   0x1110.
427                  *
428                  * Finally, mask = 0x0f00 | 0x4444 | 0x1110 == 0x5f54.
429                  *
430                  * See the Intel Manual "System Programming Guide",
431                  * 15.2.4
432                  *
433                  * Note that LENi == 0x10 is defined on x86_64 in long
434                  * mode (i.e. even for 32-bit userspace software, but
435                  * 64-bit kernel), so the x86_64 mask value is 0x5454.
436                  * See the AMD manual no. 24593 (AMD64 System Programming)
437                  */
438 #ifdef CONFIG_X86_32
439 #define DR7_MASK        0x5f54
440 #else
441 #define DR7_MASK        0x5554
442 #endif
443                 data &= ~DR_CONTROL_RESERVED;
444                 for (i = 0; i < 4; i++)
445                         if ((DR7_MASK >> ((data >> (16 + 4*i)) & 0xf)) & 1)
446                                 return -EIO;
447                 child->thread.debugreg7 = data;
448                 if (data)
449                         set_tsk_thread_flag(child, TIF_DEBUG);
450                 else
451                         clear_tsk_thread_flag(child, TIF_DEBUG);
452                 break;
453         }
454
455         return 0;
456 }
457
458 /*
459  * Called by kernel/ptrace.c when detaching..
460  *
461  * Make sure the single step bit is not set.
462  */
463 void ptrace_disable(struct task_struct *child)
464 {
465         user_disable_single_step(child);
466         clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
467 }
468
469 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
470 {
471         struct user * dummy = NULL;
472         int i, ret;
473         unsigned long __user *datap = (unsigned long __user *)data;
474
475         switch (request) {
476         /* when I and D space are separate, these will need to be fixed. */
477         case PTRACE_PEEKTEXT: /* read word at location addr. */
478         case PTRACE_PEEKDATA:
479                 ret = generic_ptrace_peekdata(child, addr, data);
480                 break;
481
482         /* read the word at location addr in the USER area. */
483         case PTRACE_PEEKUSR: {
484                 unsigned long tmp;
485
486                 ret = -EIO;
487                 if ((addr & 3) || addr < 0 ||
488                     addr > sizeof(struct user) - 3)
489                         break;
490
491                 tmp = 0;  /* Default return condition */
492                 if(addr < FRAME_SIZE*sizeof(long))
493                         tmp = getreg(child, addr);
494                 if(addr >= (long) &dummy->u_debugreg[0] &&
495                    addr <= (long) &dummy->u_debugreg[7]){
496                         addr -= (long) &dummy->u_debugreg[0];
497                         addr = addr >> 2;
498                         tmp = ptrace_get_debugreg(child, addr);
499                 }
500                 ret = put_user(tmp, datap);
501                 break;
502         }
503
504         /* when I and D space are separate, this will have to be fixed. */
505         case PTRACE_POKETEXT: /* write the word at location addr. */
506         case PTRACE_POKEDATA:
507                 ret = generic_ptrace_pokedata(child, addr, data);
508                 break;
509
510         case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
511                 ret = -EIO;
512                 if ((addr & 3) || addr < 0 ||
513                     addr > sizeof(struct user) - 3)
514                         break;
515
516                 if (addr < FRAME_SIZE*sizeof(long)) {
517                         ret = putreg(child, addr, data);
518                         break;
519                 }
520                 /* We need to be very careful here.  We implicitly
521                    want to modify a portion of the task_struct, and we
522                    have to be selective about what portions we allow someone
523                    to modify. */
524
525                   ret = -EIO;
526                   if(addr >= (long) &dummy->u_debugreg[0] &&
527                      addr <= (long) &dummy->u_debugreg[7]){
528                           addr -= (long) &dummy->u_debugreg;
529                           addr = addr >> 2;
530                           ret = ptrace_set_debugreg(child, addr, data);
531                   }
532                   break;
533
534         case PTRACE_GETREGS: { /* Get all gp regs from the child. */
535                 if (!access_ok(VERIFY_WRITE, datap, FRAME_SIZE*sizeof(long))) {
536                         ret = -EIO;
537                         break;
538                 }
539                 for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) {
540                         __put_user(getreg(child, i), datap);
541                         datap++;
542                 }
543                 ret = 0;
544                 break;
545         }
546
547         case PTRACE_SETREGS: { /* Set all gp regs in the child. */
548                 unsigned long tmp;
549                 if (!access_ok(VERIFY_READ, datap, FRAME_SIZE*sizeof(long))) {
550                         ret = -EIO;
551                         break;
552                 }
553                 for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) {
554                         __get_user(tmp, datap);
555                         putreg(child, i, tmp);
556                         datap++;
557                 }
558                 ret = 0;
559                 break;
560         }
561
562         case PTRACE_GETFPREGS: { /* Get the child FPU state. */
563                 if (!access_ok(VERIFY_WRITE, datap,
564                                sizeof(struct user_i387_struct))) {
565                         ret = -EIO;
566                         break;
567                 }
568                 ret = 0;
569                 if (!tsk_used_math(child))
570                         init_fpu(child);
571                 get_fpregs((struct user_i387_struct __user *)data, child);
572                 break;
573         }
574
575         case PTRACE_SETFPREGS: { /* Set the child FPU state. */
576                 if (!access_ok(VERIFY_READ, datap,
577                                sizeof(struct user_i387_struct))) {
578                         ret = -EIO;
579                         break;
580                 }
581                 set_stopped_child_used_math(child);
582                 set_fpregs(child, (struct user_i387_struct __user *)data);
583                 ret = 0;
584                 break;
585         }
586
587         case PTRACE_GETFPXREGS: { /* Get the child extended FPU state. */
588                 if (!access_ok(VERIFY_WRITE, datap,
589                                sizeof(struct user_fxsr_struct))) {
590                         ret = -EIO;
591                         break;
592                 }
593                 if (!tsk_used_math(child))
594                         init_fpu(child);
595                 ret = get_fpxregs((struct user_fxsr_struct __user *)data, child);
596                 break;
597         }
598
599         case PTRACE_SETFPXREGS: { /* Set the child extended FPU state. */
600                 if (!access_ok(VERIFY_READ, datap,
601                                sizeof(struct user_fxsr_struct))) {
602                         ret = -EIO;
603                         break;
604                 }
605                 set_stopped_child_used_math(child);
606                 ret = set_fpxregs(child, (struct user_fxsr_struct __user *)data);
607                 break;
608         }
609
610         case PTRACE_GET_THREAD_AREA:
611                 if (addr < 0)
612                         return -EIO;
613                 ret = do_get_thread_area(child, addr,
614                                          (struct user_desc __user *) data);
615                 break;
616
617         case PTRACE_SET_THREAD_AREA:
618                 if (addr < 0)
619                         return -EIO;
620                 ret = do_set_thread_area(child, addr,
621                                          (struct user_desc __user *) data, 0);
622                 break;
623
624         default:
625                 ret = ptrace_request(child, request, addr, data);
626                 break;
627         }
628
629         return ret;
630 }
631
632 void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code)
633 {
634         struct siginfo info;
635
636         tsk->thread.trap_no = 1;
637         tsk->thread.error_code = error_code;
638
639         memset(&info, 0, sizeof(info));
640         info.si_signo = SIGTRAP;
641         info.si_code = TRAP_BRKPT;
642
643         /* User-mode ip? */
644         info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
645
646         /* Send us the fake SIGTRAP */
647         force_sig_info(SIGTRAP, &info, tsk);
648 }
649
650 /* notification of system call entry/exit
651  * - triggered by current->work.syscall_trace
652  */
653 __attribute__((regparm(3)))
654 int do_syscall_trace(struct pt_regs *regs, int entryexit)
655 {
656         int is_sysemu = test_thread_flag(TIF_SYSCALL_EMU);
657         /*
658          * With TIF_SYSCALL_EMU set we want to ignore TIF_SINGLESTEP for syscall
659          * interception
660          */
661         int is_singlestep = !is_sysemu && test_thread_flag(TIF_SINGLESTEP);
662         int ret = 0;
663
664         /* do the secure computing check first */
665         if (!entryexit)
666                 secure_computing(regs->orig_ax);
667
668         if (unlikely(current->audit_context)) {
669                 if (entryexit)
670                         audit_syscall_exit(AUDITSC_RESULT(regs->ax),
671                                                 regs->ax);
672                 /* Debug traps, when using PTRACE_SINGLESTEP, must be sent only
673                  * on the syscall exit path. Normally, when TIF_SYSCALL_AUDIT is
674                  * not used, entry.S will call us only on syscall exit, not
675                  * entry; so when TIF_SYSCALL_AUDIT is used we must avoid
676                  * calling send_sigtrap() on syscall entry.
677                  *
678                  * Note that when PTRACE_SYSEMU_SINGLESTEP is used,
679                  * is_singlestep is false, despite his name, so we will still do
680                  * the correct thing.
681                  */
682                 else if (is_singlestep)
683                         goto out;
684         }
685
686         if (!(current->ptrace & PT_PTRACED))
687                 goto out;
688
689         /* If a process stops on the 1st tracepoint with SYSCALL_TRACE
690          * and then is resumed with SYSEMU_SINGLESTEP, it will come in
691          * here. We have to check this and return */
692         if (is_sysemu && entryexit)
693                 return 0;
694
695         /* Fake a debug trap */
696         if (is_singlestep)
697                 send_sigtrap(current, regs, 0);
698
699         if (!test_thread_flag(TIF_SYSCALL_TRACE) && !is_sysemu)
700                 goto out;
701
702         /* the 0x80 provides a way for the tracing parent to distinguish
703            between a syscall stop and SIGTRAP delivery */
704         /* Note that the debugger could change the result of test_thread_flag!*/
705         ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) ? 0x80:0));
706
707         /*
708          * this isn't the same as continuing with a signal, but it will do
709          * for normal use.  strace only continues with a signal if the
710          * stopping signal is not SIGTRAP.  -brl
711          */
712         if (current->exit_code) {
713                 send_sig(current->exit_code, current, 1);
714                 current->exit_code = 0;
715         }
716         ret = is_sysemu;
717 out:
718         if (unlikely(current->audit_context) && !entryexit)
719                 audit_syscall_entry(AUDIT_ARCH_I386, regs->orig_ax,
720                                     regs->bx, regs->cx, regs->dx, regs->si);
721         if (ret == 0)
722                 return 0;
723
724         regs->orig_ax = -1; /* force skip of syscall restarting */
725         if (unlikely(current->audit_context))
726                 audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
727         return 1;
728 }