sysdep.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**********************************************************************
  2. sysdep.c
  3. Copyright (C) 1999 Lars Brinkhoff. See the file COPYING for licensing
  4. terms and conditions.
  5. **********************************************************************/
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <signal.h>
  10. #include <errno.h>
  11. #include <sys/types.h>
  12. #include <linux/unistd.h>
  13. #include "ptrace_user.h"
  14. #include "user_util.h"
  15. #include "user.h"
  16. int get_syscall(pid_t pid, long *arg1, long *arg2, long *arg3, long *arg4,
  17. long *arg5)
  18. {
  19. *arg1 = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_ARG1_OFFSET, 0);
  20. *arg2 = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_ARG2_OFFSET, 0);
  21. *arg3 = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_ARG3_OFFSET, 0);
  22. *arg4 = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_ARG4_OFFSET, 0);
  23. *arg5 = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_ARG5_OFFSET, 0);
  24. return(ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_NR_OFFSET, 0));
  25. }
  26. void syscall_cancel(pid_t pid, int result)
  27. {
  28. if((ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_NR_OFFSET,
  29. __NR_getpid) < 0) ||
  30. (ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) ||
  31. (wait_for_stop(pid, SIGTRAP, PTRACE_SYSCALL, NULL) < 0) ||
  32. (ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET, result) < 0) ||
  33. (ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0))
  34. printk("ptproxy: couldn't cancel syscall: errno = %d\n",
  35. errno);
  36. }
  37. void syscall_set_result(pid_t pid, long result)
  38. {
  39. ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET, result);
  40. }
  41. void syscall_continue(pid_t pid)
  42. {
  43. ptrace(PTRACE_SYSCALL, pid, 0, 0);
  44. }
  45. int syscall_pause(pid_t pid)
  46. {
  47. if(ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_NR_OFFSET, __NR_pause) < 0){
  48. printk("syscall_change - ptrace failed, errno = %d\n", errno);
  49. return(-1);
  50. }
  51. return(0);
  52. }
  53. /*
  54. * Overrides for Emacs so that we follow Linus's tabbing style.
  55. * Emacs will notice this stuff at the end of the file and automatically
  56. * adjust the settings for this buffer only. This must remain at the end
  57. * of the file.
  58. * ---------------------------------------------------------------------------
  59. * Local variables:
  60. * c-file-style: "linux"
  61. * End:
  62. */