ptrace_32.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /* By Ross Biro 1/23/92 */
  2. /*
  3. * Pentium III FXSR, SSE support
  4. * Gareth Hughes <gareth@valinux.com>, May 2000
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/sched.h>
  8. #include <linux/mm.h>
  9. #include <linux/smp.h>
  10. #include <linux/errno.h>
  11. #include <linux/ptrace.h>
  12. #include <linux/user.h>
  13. #include <linux/security.h>
  14. #include <linux/audit.h>
  15. #include <linux/seccomp.h>
  16. #include <linux/signal.h>
  17. #include <asm/uaccess.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/system.h>
  20. #include <asm/processor.h>
  21. #include <asm/i387.h>
  22. #include <asm/debugreg.h>
  23. #include <asm/ldt.h>
  24. #include <asm/desc.h>
  25. /*
  26. * does not yet catch signals sent when the child dies.
  27. * in exit.c or in signal.c.
  28. */
  29. /*
  30. * Determines which flags the user has access to [1 = access, 0 = no access].
  31. * Prohibits changing ID(21), VIP(20), VIF(19), VM(17), NT(14), IOPL(12-13), IF(9).
  32. * Also masks reserved bits (31-22, 15, 5, 3, 1).
  33. */
  34. #define FLAG_MASK 0x00050dd5
  35. /* set's the trap flag. */
  36. #define TRAP_FLAG 0x100
  37. /*
  38. * Offset of eflags on child stack..
  39. */
  40. #define EFL_OFFSET offsetof(struct pt_regs, eflags)
  41. static inline struct pt_regs *get_child_regs(struct task_struct *task)
  42. {
  43. void *stack_top = (void *)task->thread.esp0;
  44. return stack_top - sizeof(struct pt_regs);
  45. }
  46. /*
  47. * This routine will get a word off of the processes privileged stack.
  48. * the offset is bytes into the pt_regs structure on the stack.
  49. * This routine assumes that all the privileged stacks are in our
  50. * data space.
  51. */
  52. static inline int get_stack_long(struct task_struct *task, int offset)
  53. {
  54. unsigned char *stack;
  55. stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs);
  56. stack += offset;
  57. return (*((int *)stack));
  58. }
  59. /*
  60. * This routine will put a word on the processes privileged stack.
  61. * the offset is bytes into the pt_regs structure on the stack.
  62. * This routine assumes that all the privileged stacks are in our
  63. * data space.
  64. */
  65. static inline int put_stack_long(struct task_struct *task, int offset,
  66. unsigned long data)
  67. {
  68. unsigned char * stack;
  69. stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs);
  70. stack += offset;
  71. *(unsigned long *) stack = data;
  72. return 0;
  73. }
  74. static int putreg(struct task_struct *child,
  75. unsigned long regno, unsigned long value)
  76. {
  77. switch (regno >> 2) {
  78. case GS:
  79. if (value && (value & 3) != 3)
  80. return -EIO;
  81. child->thread.gs = value;
  82. return 0;
  83. case DS:
  84. case ES:
  85. case FS:
  86. if (value && (value & 3) != 3)
  87. return -EIO;
  88. value &= 0xffff;
  89. break;
  90. case SS:
  91. case CS:
  92. if ((value & 3) != 3)
  93. return -EIO;
  94. value &= 0xffff;
  95. break;
  96. case EFL:
  97. value &= FLAG_MASK;
  98. value |= get_stack_long(child, EFL_OFFSET) & ~FLAG_MASK;
  99. break;
  100. }
  101. if (regno > FS*4)
  102. regno -= 1*4;
  103. put_stack_long(child, regno, value);
  104. return 0;
  105. }
  106. static unsigned long getreg(struct task_struct *child,
  107. unsigned long regno)
  108. {
  109. unsigned long retval = ~0UL;
  110. switch (regno >> 2) {
  111. case GS:
  112. retval = child->thread.gs;
  113. break;
  114. case DS:
  115. case ES:
  116. case FS:
  117. case SS:
  118. case CS:
  119. retval = 0xffff;
  120. /* fall through */
  121. default:
  122. if (regno > FS*4)
  123. regno -= 1*4;
  124. retval &= get_stack_long(child, regno);
  125. }
  126. return retval;
  127. }
  128. #define LDT_SEGMENT 4
  129. static unsigned long convert_eip_to_linear(struct task_struct *child, struct pt_regs *regs)
  130. {
  131. unsigned long addr, seg;
  132. addr = regs->eip;
  133. seg = regs->xcs & 0xffff;
  134. if (regs->eflags & VM_MASK) {
  135. addr = (addr & 0xffff) + (seg << 4);
  136. return addr;
  137. }
  138. /*
  139. * We'll assume that the code segments in the GDT
  140. * are all zero-based. That is largely true: the
  141. * TLS segments are used for data, and the PNPBIOS
  142. * and APM bios ones we just ignore here.
  143. */
  144. if (seg & LDT_SEGMENT) {
  145. u32 *desc;
  146. unsigned long base;
  147. seg &= ~7UL;
  148. down(&child->mm->context.sem);
  149. if (unlikely((seg >> 3) >= child->mm->context.size))
  150. addr = -1L; /* bogus selector, access would fault */
  151. else {
  152. desc = child->mm->context.ldt + seg;
  153. base = ((desc[0] >> 16) |
  154. ((desc[1] & 0xff) << 16) |
  155. (desc[1] & 0xff000000));
  156. /* 16-bit code segment? */
  157. if (!((desc[1] >> 22) & 1))
  158. addr &= 0xffff;
  159. addr += base;
  160. }
  161. up(&child->mm->context.sem);
  162. }
  163. return addr;
  164. }
  165. static inline int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
  166. {
  167. int i, copied;
  168. unsigned char opcode[15];
  169. unsigned long addr = convert_eip_to_linear(child, regs);
  170. copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
  171. for (i = 0; i < copied; i++) {
  172. switch (opcode[i]) {
  173. /* popf and iret */
  174. case 0x9d: case 0xcf:
  175. return 1;
  176. /* opcode and address size prefixes */
  177. case 0x66: case 0x67:
  178. continue;
  179. /* irrelevant prefixes (segment overrides and repeats) */
  180. case 0x26: case 0x2e:
  181. case 0x36: case 0x3e:
  182. case 0x64: case 0x65:
  183. case 0xf0: case 0xf2: case 0xf3:
  184. continue;
  185. /*
  186. * pushf: NOTE! We should probably not let
  187. * the user see the TF bit being set. But
  188. * it's more pain than it's worth to avoid
  189. * it, and a debugger could emulate this
  190. * all in user space if it _really_ cares.
  191. */
  192. case 0x9c:
  193. default:
  194. return 0;
  195. }
  196. }
  197. return 0;
  198. }
  199. static void set_singlestep(struct task_struct *child)
  200. {
  201. struct pt_regs *regs = get_child_regs(child);
  202. /*
  203. * Always set TIF_SINGLESTEP - this guarantees that
  204. * we single-step system calls etc.. This will also
  205. * cause us to set TF when returning to user mode.
  206. */
  207. set_tsk_thread_flag(child, TIF_SINGLESTEP);
  208. /*
  209. * If TF was already set, don't do anything else
  210. */
  211. if (regs->eflags & TRAP_FLAG)
  212. return;
  213. /* Set TF on the kernel stack.. */
  214. regs->eflags |= TRAP_FLAG;
  215. /*
  216. * ..but if TF is changed by the instruction we will trace,
  217. * don't mark it as being "us" that set it, so that we
  218. * won't clear it by hand later.
  219. */
  220. if (is_setting_trap_flag(child, regs))
  221. return;
  222. child->ptrace |= PT_DTRACE;
  223. }
  224. static void clear_singlestep(struct task_struct *child)
  225. {
  226. /* Always clear TIF_SINGLESTEP... */
  227. clear_tsk_thread_flag(child, TIF_SINGLESTEP);
  228. /* But touch TF only if it was set by us.. */
  229. if (child->ptrace & PT_DTRACE) {
  230. struct pt_regs *regs = get_child_regs(child);
  231. regs->eflags &= ~TRAP_FLAG;
  232. child->ptrace &= ~PT_DTRACE;
  233. }
  234. }
  235. /*
  236. * Called by kernel/ptrace.c when detaching..
  237. *
  238. * Make sure the single step bit is not set.
  239. */
  240. void ptrace_disable(struct task_struct *child)
  241. {
  242. clear_singlestep(child);
  243. clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
  244. }
  245. /*
  246. * Perform get_thread_area on behalf of the traced child.
  247. */
  248. static int
  249. ptrace_get_thread_area(struct task_struct *child,
  250. int idx, struct user_desc __user *user_desc)
  251. {
  252. struct user_desc info;
  253. struct desc_struct *desc;
  254. /*
  255. * Get the current Thread-Local Storage area:
  256. */
  257. #define GET_BASE(desc) ( \
  258. (((desc)->a >> 16) & 0x0000ffff) | \
  259. (((desc)->b << 16) & 0x00ff0000) | \
  260. ( (desc)->b & 0xff000000) )
  261. #define GET_LIMIT(desc) ( \
  262. ((desc)->a & 0x0ffff) | \
  263. ((desc)->b & 0xf0000) )
  264. #define GET_32BIT(desc) (((desc)->b >> 22) & 1)
  265. #define GET_CONTENTS(desc) (((desc)->b >> 10) & 3)
  266. #define GET_WRITABLE(desc) (((desc)->b >> 9) & 1)
  267. #define GET_LIMIT_PAGES(desc) (((desc)->b >> 23) & 1)
  268. #define GET_PRESENT(desc) (((desc)->b >> 15) & 1)
  269. #define GET_USEABLE(desc) (((desc)->b >> 20) & 1)
  270. if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
  271. return -EINVAL;
  272. desc = child->thread.tls_array + idx - GDT_ENTRY_TLS_MIN;
  273. info.entry_number = idx;
  274. info.base_addr = GET_BASE(desc);
  275. info.limit = GET_LIMIT(desc);
  276. info.seg_32bit = GET_32BIT(desc);
  277. info.contents = GET_CONTENTS(desc);
  278. info.read_exec_only = !GET_WRITABLE(desc);
  279. info.limit_in_pages = GET_LIMIT_PAGES(desc);
  280. info.seg_not_present = !GET_PRESENT(desc);
  281. info.useable = GET_USEABLE(desc);
  282. if (copy_to_user(user_desc, &info, sizeof(info)))
  283. return -EFAULT;
  284. return 0;
  285. }
  286. /*
  287. * Perform set_thread_area on behalf of the traced child.
  288. */
  289. static int
  290. ptrace_set_thread_area(struct task_struct *child,
  291. int idx, struct user_desc __user *user_desc)
  292. {
  293. struct user_desc info;
  294. struct desc_struct *desc;
  295. if (copy_from_user(&info, user_desc, sizeof(info)))
  296. return -EFAULT;
  297. if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
  298. return -EINVAL;
  299. desc = child->thread.tls_array + idx - GDT_ENTRY_TLS_MIN;
  300. if (LDT_empty(&info)) {
  301. desc->a = 0;
  302. desc->b = 0;
  303. } else {
  304. desc->a = LDT_entry_a(&info);
  305. desc->b = LDT_entry_b(&info);
  306. }
  307. return 0;
  308. }
  309. long arch_ptrace(struct task_struct *child, long request, long addr, long data)
  310. {
  311. struct user * dummy = NULL;
  312. int i, ret;
  313. unsigned long __user *datap = (unsigned long __user *)data;
  314. switch (request) {
  315. /* when I and D space are separate, these will need to be fixed. */
  316. case PTRACE_PEEKTEXT: /* read word at location addr. */
  317. case PTRACE_PEEKDATA:
  318. ret = generic_ptrace_peekdata(child, addr, data);
  319. break;
  320. /* read the word at location addr in the USER area. */
  321. case PTRACE_PEEKUSR: {
  322. unsigned long tmp;
  323. ret = -EIO;
  324. if ((addr & 3) || addr < 0 ||
  325. addr > sizeof(struct user) - 3)
  326. break;
  327. tmp = 0; /* Default return condition */
  328. if(addr < FRAME_SIZE*sizeof(long))
  329. tmp = getreg(child, addr);
  330. if(addr >= (long) &dummy->u_debugreg[0] &&
  331. addr <= (long) &dummy->u_debugreg[7]){
  332. addr -= (long) &dummy->u_debugreg[0];
  333. addr = addr >> 2;
  334. tmp = child->thread.debugreg[addr];
  335. }
  336. ret = put_user(tmp, datap);
  337. break;
  338. }
  339. /* when I and D space are separate, this will have to be fixed. */
  340. case PTRACE_POKETEXT: /* write the word at location addr. */
  341. case PTRACE_POKEDATA:
  342. ret = generic_ptrace_pokedata(child, addr, data);
  343. break;
  344. case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
  345. ret = -EIO;
  346. if ((addr & 3) || addr < 0 ||
  347. addr > sizeof(struct user) - 3)
  348. break;
  349. if (addr < FRAME_SIZE*sizeof(long)) {
  350. ret = putreg(child, addr, data);
  351. break;
  352. }
  353. /* We need to be very careful here. We implicitly
  354. want to modify a portion of the task_struct, and we
  355. have to be selective about what portions we allow someone
  356. to modify. */
  357. ret = -EIO;
  358. if(addr >= (long) &dummy->u_debugreg[0] &&
  359. addr <= (long) &dummy->u_debugreg[7]){
  360. if(addr == (long) &dummy->u_debugreg[4]) break;
  361. if(addr == (long) &dummy->u_debugreg[5]) break;
  362. if(addr < (long) &dummy->u_debugreg[4] &&
  363. ((unsigned long) data) >= TASK_SIZE-3) break;
  364. /* Sanity-check data. Take one half-byte at once with
  365. * check = (val >> (16 + 4*i)) & 0xf. It contains the
  366. * R/Wi and LENi bits; bits 0 and 1 are R/Wi, and bits
  367. * 2 and 3 are LENi. Given a list of invalid values,
  368. * we do mask |= 1 << invalid_value, so that
  369. * (mask >> check) & 1 is a correct test for invalid
  370. * values.
  371. *
  372. * R/Wi contains the type of the breakpoint /
  373. * watchpoint, LENi contains the length of the watched
  374. * data in the watchpoint case.
  375. *
  376. * The invalid values are:
  377. * - LENi == 0x10 (undefined), so mask |= 0x0f00.
  378. * - R/Wi == 0x10 (break on I/O reads or writes), so
  379. * mask |= 0x4444.
  380. * - R/Wi == 0x00 && LENi != 0x00, so we have mask |=
  381. * 0x1110.
  382. *
  383. * Finally, mask = 0x0f00 | 0x4444 | 0x1110 == 0x5f54.
  384. *
  385. * See the Intel Manual "System Programming Guide",
  386. * 15.2.4
  387. *
  388. * Note that LENi == 0x10 is defined on x86_64 in long
  389. * mode (i.e. even for 32-bit userspace software, but
  390. * 64-bit kernel), so the x86_64 mask value is 0x5454.
  391. * See the AMD manual no. 24593 (AMD64 System
  392. * Programming)*/
  393. if(addr == (long) &dummy->u_debugreg[7]) {
  394. data &= ~DR_CONTROL_RESERVED;
  395. for(i=0; i<4; i++)
  396. if ((0x5f54 >> ((data >> (16 + 4*i)) & 0xf)) & 1)
  397. goto out_tsk;
  398. if (data)
  399. set_tsk_thread_flag(child, TIF_DEBUG);
  400. else
  401. clear_tsk_thread_flag(child, TIF_DEBUG);
  402. }
  403. addr -= (long) &dummy->u_debugreg;
  404. addr = addr >> 2;
  405. child->thread.debugreg[addr] = data;
  406. ret = 0;
  407. }
  408. break;
  409. case PTRACE_SYSEMU: /* continue and stop at next syscall, which will not be executed */
  410. case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
  411. case PTRACE_CONT: /* restart after signal. */
  412. ret = -EIO;
  413. if (!valid_signal(data))
  414. break;
  415. if (request == PTRACE_SYSEMU) {
  416. set_tsk_thread_flag(child, TIF_SYSCALL_EMU);
  417. clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  418. } else if (request == PTRACE_SYSCALL) {
  419. set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  420. clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
  421. } else {
  422. clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
  423. clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  424. }
  425. child->exit_code = data;
  426. /* make sure the single step bit is not set. */
  427. clear_singlestep(child);
  428. wake_up_process(child);
  429. ret = 0;
  430. break;
  431. /*
  432. * make the child exit. Best I can do is send it a sigkill.
  433. * perhaps it should be put in the status that it wants to
  434. * exit.
  435. */
  436. case PTRACE_KILL:
  437. ret = 0;
  438. if (child->exit_state == EXIT_ZOMBIE) /* already dead */
  439. break;
  440. child->exit_code = SIGKILL;
  441. /* make sure the single step bit is not set. */
  442. clear_singlestep(child);
  443. wake_up_process(child);
  444. break;
  445. case PTRACE_SYSEMU_SINGLESTEP: /* Same as SYSEMU, but singlestep if not syscall */
  446. case PTRACE_SINGLESTEP: /* set the trap flag. */
  447. ret = -EIO;
  448. if (!valid_signal(data))
  449. break;
  450. if (request == PTRACE_SYSEMU_SINGLESTEP)
  451. set_tsk_thread_flag(child, TIF_SYSCALL_EMU);
  452. else
  453. clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
  454. clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  455. set_singlestep(child);
  456. child->exit_code = data;
  457. /* give it a chance to run. */
  458. wake_up_process(child);
  459. ret = 0;
  460. break;
  461. case PTRACE_DETACH:
  462. /* detach a process that was attached. */
  463. ret = ptrace_detach(child, data);
  464. break;
  465. case PTRACE_GETREGS: { /* Get all gp regs from the child. */
  466. if (!access_ok(VERIFY_WRITE, datap, FRAME_SIZE*sizeof(long))) {
  467. ret = -EIO;
  468. break;
  469. }
  470. for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) {
  471. __put_user(getreg(child, i), datap);
  472. datap++;
  473. }
  474. ret = 0;
  475. break;
  476. }
  477. case PTRACE_SETREGS: { /* Set all gp regs in the child. */
  478. unsigned long tmp;
  479. if (!access_ok(VERIFY_READ, datap, FRAME_SIZE*sizeof(long))) {
  480. ret = -EIO;
  481. break;
  482. }
  483. for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) {
  484. __get_user(tmp, datap);
  485. putreg(child, i, tmp);
  486. datap++;
  487. }
  488. ret = 0;
  489. break;
  490. }
  491. case PTRACE_GETFPREGS: { /* Get the child FPU state. */
  492. if (!access_ok(VERIFY_WRITE, datap,
  493. sizeof(struct user_i387_struct))) {
  494. ret = -EIO;
  495. break;
  496. }
  497. ret = 0;
  498. if (!tsk_used_math(child))
  499. init_fpu(child);
  500. get_fpregs((struct user_i387_struct __user *)data, child);
  501. break;
  502. }
  503. case PTRACE_SETFPREGS: { /* Set the child FPU state. */
  504. if (!access_ok(VERIFY_READ, datap,
  505. sizeof(struct user_i387_struct))) {
  506. ret = -EIO;
  507. break;
  508. }
  509. set_stopped_child_used_math(child);
  510. set_fpregs(child, (struct user_i387_struct __user *)data);
  511. ret = 0;
  512. break;
  513. }
  514. case PTRACE_GETFPXREGS: { /* Get the child extended FPU state. */
  515. if (!access_ok(VERIFY_WRITE, datap,
  516. sizeof(struct user_fxsr_struct))) {
  517. ret = -EIO;
  518. break;
  519. }
  520. if (!tsk_used_math(child))
  521. init_fpu(child);
  522. ret = get_fpxregs((struct user_fxsr_struct __user *)data, child);
  523. break;
  524. }
  525. case PTRACE_SETFPXREGS: { /* Set the child extended FPU state. */
  526. if (!access_ok(VERIFY_READ, datap,
  527. sizeof(struct user_fxsr_struct))) {
  528. ret = -EIO;
  529. break;
  530. }
  531. set_stopped_child_used_math(child);
  532. ret = set_fpxregs(child, (struct user_fxsr_struct __user *)data);
  533. break;
  534. }
  535. case PTRACE_GET_THREAD_AREA:
  536. ret = ptrace_get_thread_area(child, addr,
  537. (struct user_desc __user *) data);
  538. break;
  539. case PTRACE_SET_THREAD_AREA:
  540. ret = ptrace_set_thread_area(child, addr,
  541. (struct user_desc __user *) data);
  542. break;
  543. default:
  544. ret = ptrace_request(child, request, addr, data);
  545. break;
  546. }
  547. out_tsk:
  548. return ret;
  549. }
  550. void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code)
  551. {
  552. struct siginfo info;
  553. tsk->thread.trap_no = 1;
  554. tsk->thread.error_code = error_code;
  555. memset(&info, 0, sizeof(info));
  556. info.si_signo = SIGTRAP;
  557. info.si_code = TRAP_BRKPT;
  558. /* User-mode eip? */
  559. info.si_addr = user_mode_vm(regs) ? (void __user *) regs->eip : NULL;
  560. /* Send us the fakey SIGTRAP */
  561. force_sig_info(SIGTRAP, &info, tsk);
  562. }
  563. /* notification of system call entry/exit
  564. * - triggered by current->work.syscall_trace
  565. */
  566. __attribute__((regparm(3)))
  567. int do_syscall_trace(struct pt_regs *regs, int entryexit)
  568. {
  569. int is_sysemu = test_thread_flag(TIF_SYSCALL_EMU);
  570. /*
  571. * With TIF_SYSCALL_EMU set we want to ignore TIF_SINGLESTEP for syscall
  572. * interception
  573. */
  574. int is_singlestep = !is_sysemu && test_thread_flag(TIF_SINGLESTEP);
  575. int ret = 0;
  576. /* do the secure computing check first */
  577. if (!entryexit)
  578. secure_computing(regs->orig_eax);
  579. if (unlikely(current->audit_context)) {
  580. if (entryexit)
  581. audit_syscall_exit(AUDITSC_RESULT(regs->eax),
  582. regs->eax);
  583. /* Debug traps, when using PTRACE_SINGLESTEP, must be sent only
  584. * on the syscall exit path. Normally, when TIF_SYSCALL_AUDIT is
  585. * not used, entry.S will call us only on syscall exit, not
  586. * entry; so when TIF_SYSCALL_AUDIT is used we must avoid
  587. * calling send_sigtrap() on syscall entry.
  588. *
  589. * Note that when PTRACE_SYSEMU_SINGLESTEP is used,
  590. * is_singlestep is false, despite his name, so we will still do
  591. * the correct thing.
  592. */
  593. else if (is_singlestep)
  594. goto out;
  595. }
  596. if (!(current->ptrace & PT_PTRACED))
  597. goto out;
  598. /* If a process stops on the 1st tracepoint with SYSCALL_TRACE
  599. * and then is resumed with SYSEMU_SINGLESTEP, it will come in
  600. * here. We have to check this and return */
  601. if (is_sysemu && entryexit)
  602. return 0;
  603. /* Fake a debug trap */
  604. if (is_singlestep)
  605. send_sigtrap(current, regs, 0);
  606. if (!test_thread_flag(TIF_SYSCALL_TRACE) && !is_sysemu)
  607. goto out;
  608. /* the 0x80 provides a way for the tracing parent to distinguish
  609. between a syscall stop and SIGTRAP delivery */
  610. /* Note that the debugger could change the result of test_thread_flag!*/
  611. ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) ? 0x80:0));
  612. /*
  613. * this isn't the same as continuing with a signal, but it will do
  614. * for normal use. strace only continues with a signal if the
  615. * stopping signal is not SIGTRAP. -brl
  616. */
  617. if (current->exit_code) {
  618. send_sig(current->exit_code, current, 1);
  619. current->exit_code = 0;
  620. }
  621. ret = is_sysemu;
  622. out:
  623. if (unlikely(current->audit_context) && !entryexit)
  624. audit_syscall_entry(AUDIT_ARCH_I386, regs->orig_eax,
  625. regs->ebx, regs->ecx, regs->edx, regs->esi);
  626. if (ret == 0)
  627. return 0;
  628. regs->orig_eax = -1; /* force skip of syscall restarting */
  629. if (unlikely(current->audit_context))
  630. audit_syscall_exit(AUDITSC_RESULT(regs->eax), regs->eax);
  631. return 1;
  632. }