syscall_user.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include <unistd.h>
  6. #include <signal.h>
  7. #include <errno.h>
  8. #include <asm/unistd.h>
  9. #include "sysdep/ptrace.h"
  10. #include "sigcontext.h"
  11. #include "ptrace_user.h"
  12. #include "task.h"
  13. #include "user_util.h"
  14. #include "kern_util.h"
  15. #include "syscall_user.h"
  16. #include "tt.h"
  17. void syscall_handler_tt(int sig, union uml_pt_regs *regs)
  18. {
  19. void *sc;
  20. long result;
  21. int syscall;
  22. #ifdef UML_CONFIG_DEBUG_SYSCALL
  23. int index;
  24. #endif
  25. syscall = UPT_SYSCALL_NR(regs);
  26. sc = UPT_SC(regs);
  27. SC_START_SYSCALL(sc);
  28. #ifdef UML_CONFIG_DEBUG_SYSCALL
  29. index = record_syscall_start(syscall);
  30. #endif
  31. syscall_trace(regs, 0);
  32. result = execute_syscall_tt(regs);
  33. /* regs->sc may have changed while the system call ran (there may
  34. * have been an interrupt or segfault), so it needs to be refreshed.
  35. */
  36. UPT_SC(regs) = sc;
  37. SC_SET_SYSCALL_RETURN(sc, result);
  38. syscall_trace(regs, 1);
  39. #ifdef UML_CONFIG_DEBUG_SYSCALL
  40. record_syscall_end(index, result);
  41. #endif
  42. }
  43. void do_sigtrap(void *task)
  44. {
  45. UPT_SYSCALL_NR(TASK_REGS(task)) = -1;
  46. }
  47. void do_syscall(void *task, int pid, int local_using_sysemu)
  48. {
  49. unsigned long proc_regs[FRAME_SIZE];
  50. if(ptrace_getregs(pid, proc_regs) < 0)
  51. tracer_panic("Couldn't read registers");
  52. UPT_SYSCALL_NR(TASK_REGS(task)) = PT_SYSCALL_NR(proc_regs);
  53. #ifdef UPT_ORIGGPR2
  54. UPT_ORIGGPR2(TASK_REGS(task)) = REGS_ORIGGPR2(proc_regs);
  55. #endif
  56. if(((unsigned long *) PT_IP(proc_regs) >= &_stext) &&
  57. ((unsigned long *) PT_IP(proc_regs) <= &_etext))
  58. tracer_panic("I'm tracing myself and I can't get out");
  59. /* advanced sysemu mode set syscall number to -1 automatically */
  60. if (local_using_sysemu==2)
  61. return;
  62. /* syscall number -1 in sysemu skips syscall restarting in host */
  63. if(ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_NR_OFFSET,
  64. local_using_sysemu ? -1 : __NR_getpid) < 0)
  65. tracer_panic("do_syscall : Nullifying syscall failed, "
  66. "errno = %d", errno);
  67. }
  68. /*
  69. * Overrides for Emacs so that we follow Linus's tabbing style.
  70. * Emacs will notice this stuff at the end of the file and automatically
  71. * adjust the settings for this buffer only. This must remain at the end
  72. * of the file.
  73. * ---------------------------------------------------------------------------
  74. * Local variables:
  75. * c-file-style: "linux"
  76. * End:
  77. */