stub.h 2.2 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 <asm/page.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 EAX
  17. #define STUB_MMAP_NR __NR_mmap2
  18. #define MMAP_OFFSET(o) ((o) >> PAGE_SHIFT)
  19. static inline long stub_syscall0(long syscall)
  20. {
  21. long ret;
  22. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall));
  23. return ret;
  24. }
  25. static inline long stub_syscall1(long syscall, long arg1)
  26. {
  27. long ret;
  28. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1));
  29. return ret;
  30. }
  31. static inline long stub_syscall2(long syscall, long arg1, long arg2)
  32. {
  33. long ret;
  34. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
  35. "c" (arg2));
  36. return ret;
  37. }
  38. static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
  39. {
  40. long ret;
  41. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
  42. "c" (arg2), "d" (arg3));
  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 ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
  50. "c" (arg2), "d" (arg3), "S" (arg4));
  51. return ret;
  52. }
  53. static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
  54. long arg4, long arg5)
  55. {
  56. long ret;
  57. __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
  58. "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5));
  59. return ret;
  60. }
  61. static inline void trap_myself(void)
  62. {
  63. __asm("int3");
  64. }
  65. static inline void remap_stack(int fd, unsigned long offset)
  66. {
  67. __asm__ volatile ("movl %%eax,%%ebp ; movl %0,%%eax ; int $0x80 ;"
  68. "movl %7, %%ebx ; movl %%eax, (%%ebx)"
  69. : : "g" (STUB_MMAP_NR), "b" (UML_CONFIG_STUB_DATA),
  70. "c" (UM_KERN_PAGE_SIZE),
  71. "d" (PROT_READ | PROT_WRITE),
  72. "S" (MAP_FIXED | MAP_SHARED), "D" (fd),
  73. "a" (offset),
  74. "i" (&((struct stub_data *) UML_CONFIG_STUB_DATA)->err)
  75. : "memory");
  76. }
  77. #endif