stub.h 2.3 KB

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