sysdep.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include "os.h"
  17. int get_syscall(pid_t pid, long *arg1, long *arg2, long *arg3, long *arg4,
  18. long *arg5)
  19. {
  20. *arg1 = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_ARG1_OFFSET, 0);
  21. *arg2 = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_ARG2_OFFSET, 0);
  22. *arg3 = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_ARG3_OFFSET, 0);
  23. *arg4 = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_ARG4_OFFSET, 0);
  24. *arg5 = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_ARG5_OFFSET, 0);
  25. return(ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_NR_OFFSET, 0));
  26. }
  27. void syscall_cancel(pid_t pid, int result)
  28. {
  29. if((ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_NR_OFFSET,
  30. __NR_getpid) < 0) ||
  31. (ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) ||
  32. (wait_for_stop(pid, SIGTRAP, PTRACE_SYSCALL, NULL) < 0) ||
  33. (ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET, result) < 0) ||
  34. (ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0))
  35. printk("ptproxy: couldn't cancel syscall: errno = %d\n",
  36. errno);
  37. }
  38. void syscall_set_result(pid_t pid, long result)
  39. {
  40. ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET, result);
  41. }
  42. void syscall_continue(pid_t pid)
  43. {
  44. ptrace(PTRACE_SYSCALL, pid, 0, 0);
  45. }
  46. int syscall_pause(pid_t pid)
  47. {
  48. if(ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_NR_OFFSET, __NR_pause) < 0){
  49. printk("syscall_change - ptrace failed, errno = %d\n", errno);
  50. return(-1);
  51. }
  52. return(0);
  53. }
  54. /*
  55. * Overrides for Emacs so that we follow Linus's tabbing style.
  56. * Emacs will notice this stuff at the end of the file and automatically
  57. * adjust the settings for this buffer only. This must remain at the end
  58. * of the file.
  59. * ---------------------------------------------------------------------------
  60. * Local variables:
  61. * c-file-style: "linux"
  62. * End:
  63. */