stub.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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/unistd.h>
  9. #include <sysdep/ptrace_user.h>
  10. #include "as-layout.h"
  11. #include "stub-data.h"
  12. #include "kern_constants.h"
  13. #include "uml-config.h"
  14. extern void stub_segv_handler(int sig);
  15. extern void stub_clone_handler(void);
  16. #define STUB_SYSCALL_RET PT_INDEX(RAX)
  17. #define STUB_MMAP_NR __NR_mmap
  18. #define MMAP_OFFSET(o) (o)
  19. #define __syscall_clobber "r11","rcx","memory"
  20. #define __syscall "syscall"
  21. static inline long stub_syscall0(long syscall)
  22. {
  23. long ret;
  24. __asm__ volatile (__syscall
  25. : "=a" (ret)
  26. : "0" (syscall) : __syscall_clobber );
  27. return ret;
  28. }
  29. static inline long stub_syscall2(long syscall, long arg1, long arg2)
  30. {
  31. long ret;
  32. __asm__ volatile (__syscall
  33. : "=a" (ret)
  34. : "0" (syscall), "D" (arg1), "S" (arg2) : __syscall_clobber );
  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 (__syscall
  41. : "=a" (ret)
  42. : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3)
  43. : __syscall_clobber );
  44. return ret;
  45. }
  46. static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
  47. long arg4)
  48. {
  49. long ret;
  50. __asm__ volatile ("movq %5,%%r10 ; " __syscall
  51. : "=a" (ret)
  52. : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
  53. "g" (arg4)
  54. : __syscall_clobber, "r10" );
  55. return ret;
  56. }
  57. static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
  58. long arg4, long arg5)
  59. {
  60. long ret;
  61. __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall
  62. : "=a" (ret)
  63. : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
  64. "g" (arg4), "g" (arg5)
  65. : __syscall_clobber, "r10", "r8" );
  66. return ret;
  67. }
  68. static inline void trap_myself(void)
  69. {
  70. __asm("int3");
  71. }
  72. static inline void remap_stack(long fd, unsigned long offset)
  73. {
  74. __asm__ volatile ("movq %4,%%r10 ; movq %5,%%r8 ; "
  75. "movq %6, %%r9; " __syscall "; movq %7, %%rbx ; "
  76. "movq %%rax, (%%rbx)":
  77. : "a" (STUB_MMAP_NR), "D" (STUB_DATA),
  78. "S" (UM_KERN_PAGE_SIZE),
  79. "d" (PROT_READ | PROT_WRITE),
  80. "g" (MAP_FIXED | MAP_SHARED), "g" (fd),
  81. "g" (offset),
  82. "i" (&((struct stub_data *) STUB_DATA)->err)
  83. : __syscall_clobber, "r10", "r8", "r9" );
  84. }
  85. #endif