stub.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_syscall2(long syscall, long arg1, long arg2)
  15. {
  16. long ret;
  17. __asm__("movl %0, %%ecx; " : : "g" (arg2) : "%ecx");
  18. __asm__("movl %0, %%ebx; " : : "g" (arg1) : "%ebx");
  19. __asm__("movl %0, %%eax; " : : "g" (syscall) : "%eax");
  20. __asm__("int $0x80;" : : : "%eax");
  21. __asm__ __volatile__("movl %%eax, %0; " : "=g" (ret) :);
  22. return(ret);
  23. }
  24. static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
  25. {
  26. __asm__("movl %0, %%edx; " : : "g" (arg3) : "%edx");
  27. return(stub_syscall2(syscall, arg1, arg2));
  28. }
  29. static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
  30. long arg4)
  31. {
  32. __asm__("movl %0, %%esi; " : : "g" (arg4) : "%esi");
  33. return(stub_syscall3(syscall, arg1, arg2, arg3));
  34. }
  35. static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3,
  36. long arg4, long arg5, long arg6)
  37. {
  38. long ret;
  39. __asm__("movl %0, %%eax; " : : "g" (syscall) : "%eax");
  40. __asm__("movl %0, %%ebx; " : : "g" (arg1) : "%ebx");
  41. __asm__("movl %0, %%ecx; " : : "g" (arg2) : "%ecx");
  42. __asm__("movl %0, %%edx; " : : "g" (arg3) : "%edx");
  43. __asm__("movl %0, %%esi; " : : "g" (arg4) : "%esi");
  44. __asm__("movl %0, %%edi; " : : "g" (arg5) : "%edi");
  45. __asm__ __volatile__("pushl %%ebp ; movl %1, %%ebp; "
  46. "int $0x80; popl %%ebp ; "
  47. "movl %%eax, %0; " : "=g" (ret) : "g" (arg6) : "%eax");
  48. return(ret);
  49. }
  50. static inline void trap_myself(void)
  51. {
  52. __asm("int3");
  53. }
  54. #endif