stub.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. static inline long stub_syscall2(long syscall, long arg1, long arg2)
  16. {
  17. long ret;
  18. __asm__("movq %0, %%rsi; " : : "g" (arg2) : "%rsi");
  19. __asm__("movq %0, %%rdi; " : : "g" (arg1) : "%rdi");
  20. __asm__("movq %0, %%rax; " : : "g" (syscall) : "%rax");
  21. __asm__("syscall;" : : : "%rax", "%r11", "%rcx");
  22. __asm__ __volatile__("movq %%rax, %0; " : "=g" (ret) :);
  23. return(ret);
  24. }
  25. static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
  26. {
  27. __asm__("movq %0, %%rdx; " : : "g" (arg3) : "%rdx");
  28. return(stub_syscall2(syscall, arg1, arg2));
  29. }
  30. static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
  31. long arg4)
  32. {
  33. __asm__("movq %0, %%r10; " : : "g" (arg4) : "%r10");
  34. return(stub_syscall3(syscall, arg1, arg2, arg3));
  35. }
  36. static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3,
  37. long arg4, long arg5, long arg6)
  38. {
  39. __asm__("movq %0, %%r9; " : : "g" (arg6) : "%r9");
  40. __asm__("movq %0, %%r8; " : : "g" (arg5) : "%r8");
  41. return(stub_syscall4(syscall, arg1, arg2, arg3, arg4));
  42. }
  43. static inline void trap_myself(void)
  44. {
  45. __asm("int3");
  46. }
  47. #endif