stub.h 2.1 KB

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