stub.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/unistd.h>
  8. #include <sysdep/ptrace_user.h>
  9. extern void stub_segv_handler(int sig);
  10. extern void stub_clone_handler(void);
  11. #define STUB_SYSCALL_RET PT_INDEX(RAX)
  12. #define STUB_MMAP_NR __NR_mmap
  13. #define MMAP_OFFSET(o) (o)
  14. #define __syscall_clobber "r11","rcx","memory"
  15. #define __syscall "syscall"
  16. static inline long stub_syscall0(long syscall)
  17. {
  18. long ret;
  19. __asm__ volatile (__syscall
  20. : "=a" (ret)
  21. : "0" (syscall) : __syscall_clobber );
  22. return ret;
  23. }
  24. static inline long stub_syscall2(long syscall, long arg1, long arg2)
  25. {
  26. long ret;
  27. __asm__ volatile (__syscall
  28. : "=a" (ret)
  29. : "0" (syscall), "D" (arg1), "S" (arg2) : __syscall_clobber );
  30. return ret;
  31. }
  32. static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
  33. {
  34. long ret;
  35. __asm__ volatile (__syscall
  36. : "=a" (ret)
  37. : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3)
  38. : __syscall_clobber );
  39. return ret;
  40. }
  41. static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
  42. long arg4)
  43. {
  44. long ret;
  45. __asm__ volatile ("movq %5,%%r10 ; " __syscall
  46. : "=a" (ret)
  47. : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
  48. "g" (arg4)
  49. : __syscall_clobber, "r10" );
  50. return ret;
  51. }
  52. static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
  53. long arg4, long arg5)
  54. {
  55. long ret;
  56. __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall
  57. : "=a" (ret)
  58. : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
  59. "g" (arg4), "g" (arg5)
  60. : __syscall_clobber, "r10", "r8" );
  61. return ret;
  62. }
  63. static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3,
  64. long arg4, long arg5, long arg6)
  65. {
  66. long ret;
  67. __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; "
  68. "movq %7, %%r9; " __syscall : "=a" (ret)
  69. : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
  70. "g" (arg4), "g" (arg5), "g" (arg6)
  71. : __syscall_clobber, "r10", "r8", "r9" );
  72. return ret;
  73. }
  74. static inline void trap_myself(void)
  75. {
  76. __asm("int3");
  77. }
  78. #endif