stub.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. extern void stub_segv_handler(int sig);
  10. extern void stub_clone_handler(void);
  11. #define STUB_SYSCALL_RET EAX
  12. #define STUB_MMAP_NR __NR_mmap2
  13. #define MMAP_OFFSET(o) ((o) >> PAGE_SHIFT)
  14. static inline long stub_syscall0(long syscall)
  15. {
  16. long ret;
  17. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall));
  18. return ret;
  19. }
  20. static inline long stub_syscall1(long syscall, long arg1)
  21. {
  22. long ret;
  23. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1));
  24. return ret;
  25. }
  26. static inline long stub_syscall2(long syscall, long arg1, long arg2)
  27. {
  28. long ret;
  29. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
  30. "c" (arg2));
  31. return ret;
  32. }
  33. static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
  34. {
  35. long ret;
  36. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
  37. "c" (arg2), "d" (arg3));
  38. return ret;
  39. }
  40. static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
  41. long arg4)
  42. {
  43. long ret;
  44. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
  45. "c" (arg2), "d" (arg3), "S" (arg4));
  46. return ret;
  47. }
  48. static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
  49. long arg4, long arg5)
  50. {
  51. long ret;
  52. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
  53. "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5));
  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 ("push %%ebp ; movl %%eax,%%ebp ; movl %1,%%eax ; "
  61. "int $0x80 ; pop %%ebp"
  62. : "=a" (ret)
  63. : "g" (syscall), "b" (arg1), "c" (arg2), "d" (arg3),
  64. "S" (arg4), "D" (arg5), "0" (arg6));
  65. return ret;
  66. }
  67. static inline void trap_myself(void)
  68. {
  69. __asm("int3");
  70. }
  71. #endif