stub.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com)
  3. * Licensed under the GPL
  4. */
  5. #ifndef __SYSDEP_STUB_H
  6. #define __SYSDEP_STUB_H
  7. #include <asm/ptrace.h>
  8. #include <asm/unistd.h>
  9. #include <sysdep/ptrace_user.h>
  10. extern void stub_segv_handler(int sig);
  11. extern void stub_clone_handler(void);
  12. #define STUB_SYSCALL_RET PT_INDEX(RAX)
  13. #define STUB_MMAP_NR __NR_mmap
  14. #define MMAP_OFFSET(o) (o)
  15. #define __syscall_clobber "r11","rcx","memory"
  16. #define __syscall "syscall"
  17. static inline long stub_syscall2(long syscall, long arg1, long arg2)
  18. {
  19. long ret;
  20. __asm__ volatile (__syscall
  21. : "=a" (ret)
  22. : "0" (syscall), "D" (arg1), "S" (arg2) : __syscall_clobber );
  23. return ret;
  24. }
  25. static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
  26. {
  27. long ret;
  28. __asm__ volatile (__syscall
  29. : "=a" (ret)
  30. : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3)
  31. : __syscall_clobber );
  32. return ret;
  33. }
  34. static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
  35. long arg4)
  36. {
  37. long ret;
  38. __asm__ volatile ("movq %5,%%r10 ; " __syscall
  39. : "=a" (ret)
  40. : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
  41. "g" (arg4)
  42. : __syscall_clobber, "r10" );
  43. return ret;
  44. }
  45. static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
  46. long arg4, long arg5)
  47. {
  48. long ret;
  49. __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall
  50. : "=a" (ret)
  51. : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
  52. "g" (arg4), "g" (arg5)
  53. : __syscall_clobber, "r10", "r8" );
  54. return ret;
  55. }
  56. static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3,
  57. long arg4, long arg5, long arg6)
  58. {
  59. long ret;
  60. __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; "
  61. "movq %7, %%r9; " __syscall : "=a" (ret)
  62. : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
  63. "g" (arg4), "g" (arg5), "g" (arg6)
  64. : __syscall_clobber, "r10", "r8", "r9" );
  65. return ret;
  66. }
  67. static inline void trap_myself(void)
  68. {
  69. __asm("int3");
  70. }
  71. #endif