stub.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 <sys/mman.h>
  8. #include <asm/ptrace.h>
  9. #include <asm/unistd.h>
  10. #include "as-layout.h"
  11. #include "stub-data.h"
  12. extern void stub_segv_handler(int sig);
  13. extern void stub_clone_handler(void);
  14. #define STUB_SYSCALL_RET EAX
  15. #define STUB_MMAP_NR __NR_mmap2
  16. #define MMAP_OFFSET(o) ((o) >> UM_KERN_PAGE_SHIFT)
  17. static inline long stub_syscall0(long syscall)
  18. {
  19. long ret;
  20. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall));
  21. return ret;
  22. }
  23. static inline long stub_syscall1(long syscall, long arg1)
  24. {
  25. long ret;
  26. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1));
  27. return ret;
  28. }
  29. static inline long stub_syscall2(long syscall, long arg1, long arg2)
  30. {
  31. long ret;
  32. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
  33. "c" (arg2));
  34. return ret;
  35. }
  36. static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
  37. {
  38. long ret;
  39. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
  40. "c" (arg2), "d" (arg3));
  41. return ret;
  42. }
  43. static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
  44. long arg4)
  45. {
  46. long ret;
  47. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
  48. "c" (arg2), "d" (arg3), "S" (arg4));
  49. return ret;
  50. }
  51. static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
  52. long arg4, long arg5)
  53. {
  54. long ret;
  55. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
  56. "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5));
  57. return ret;
  58. }
  59. static inline void trap_myself(void)
  60. {
  61. __asm("int3");
  62. }
  63. static inline void remap_stack(int fd, unsigned long offset)
  64. {
  65. __asm__ volatile ("movl %%eax,%%ebp ; movl %0,%%eax ; int $0x80 ;"
  66. "movl %7, %%ebx ; movl %%eax, (%%ebx)"
  67. : : "g" (STUB_MMAP_NR), "b" (STUB_DATA),
  68. "c" (UM_KERN_PAGE_SIZE),
  69. "d" (PROT_READ | PROT_WRITE),
  70. "S" (MAP_FIXED | MAP_SHARED), "D" (fd),
  71. "a" (offset),
  72. "i" (&((struct stub_data *) STUB_DATA)->err)
  73. : "memory");
  74. }
  75. #endif