user-offsets.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <stdio.h>
  2. #include <stddef.h>
  3. #include <signal.h>
  4. #include <sys/poll.h>
  5. #include <sys/mman.h>
  6. #include <sys/user.h>
  7. #define __FRAME_OFFSETS
  8. #include <asm/ptrace.h>
  9. #include <asm/types.h>
  10. #ifdef __i386__
  11. #define __SYSCALL_I386(nr, sym, qual) [nr] = 1,
  12. static char syscalls[] = {
  13. #include <asm/syscalls_32.h>
  14. };
  15. #else
  16. #define __SYSCALL_64(nr, sym, qual) [nr] = 1,
  17. static char syscalls[] = {
  18. #include <asm/syscalls_64.h>
  19. };
  20. #endif
  21. #define DEFINE(sym, val) \
  22. asm volatile("\n->" #sym " %0 " #val : : "i" (val))
  23. #define DEFINE_LONGS(sym, val) \
  24. asm volatile("\n->" #sym " %0 " #val : : "i" (val/sizeof(unsigned long)))
  25. void foo(void)
  26. {
  27. #ifdef __i386__
  28. DEFINE_LONGS(HOST_FP_SIZE, sizeof(struct user_fpregs_struct));
  29. DEFINE_LONGS(HOST_FPX_SIZE, sizeof(struct user_fpxregs_struct));
  30. DEFINE(HOST_IP, EIP);
  31. DEFINE(HOST_SP, UESP);
  32. DEFINE(HOST_EFLAGS, EFL);
  33. DEFINE(HOST_AX, EAX);
  34. DEFINE(HOST_BX, EBX);
  35. DEFINE(HOST_CX, ECX);
  36. DEFINE(HOST_DX, EDX);
  37. DEFINE(HOST_SI, ESI);
  38. DEFINE(HOST_DI, EDI);
  39. DEFINE(HOST_BP, EBP);
  40. DEFINE(HOST_CS, CS);
  41. DEFINE(HOST_SS, SS);
  42. DEFINE(HOST_DS, DS);
  43. DEFINE(HOST_FS, FS);
  44. DEFINE(HOST_ES, ES);
  45. DEFINE(HOST_GS, GS);
  46. DEFINE(HOST_ORIG_AX, ORIG_EAX);
  47. #else
  48. DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long));
  49. DEFINE_LONGS(HOST_BX, RBX);
  50. DEFINE_LONGS(HOST_CX, RCX);
  51. DEFINE_LONGS(HOST_DI, RDI);
  52. DEFINE_LONGS(HOST_SI, RSI);
  53. DEFINE_LONGS(HOST_DX, RDX);
  54. DEFINE_LONGS(HOST_BP, RBP);
  55. DEFINE_LONGS(HOST_AX, RAX);
  56. DEFINE_LONGS(HOST_R8, R8);
  57. DEFINE_LONGS(HOST_R9, R9);
  58. DEFINE_LONGS(HOST_R10, R10);
  59. DEFINE_LONGS(HOST_R11, R11);
  60. DEFINE_LONGS(HOST_R12, R12);
  61. DEFINE_LONGS(HOST_R13, R13);
  62. DEFINE_LONGS(HOST_R14, R14);
  63. DEFINE_LONGS(HOST_R15, R15);
  64. DEFINE_LONGS(HOST_ORIG_AX, ORIG_RAX);
  65. DEFINE_LONGS(HOST_CS, CS);
  66. DEFINE_LONGS(HOST_SS, SS);
  67. DEFINE_LONGS(HOST_EFLAGS, EFLAGS);
  68. #if 0
  69. DEFINE_LONGS(HOST_FS, FS);
  70. DEFINE_LONGS(HOST_GS, GS);
  71. DEFINE_LONGS(HOST_DS, DS);
  72. DEFINE_LONGS(HOST_ES, ES);
  73. #endif
  74. DEFINE_LONGS(HOST_IP, RIP);
  75. DEFINE_LONGS(HOST_SP, RSP);
  76. #endif
  77. DEFINE(UM_FRAME_SIZE, sizeof(struct user_regs_struct));
  78. DEFINE(UM_POLLIN, POLLIN);
  79. DEFINE(UM_POLLPRI, POLLPRI);
  80. DEFINE(UM_POLLOUT, POLLOUT);
  81. DEFINE(UM_PROT_READ, PROT_READ);
  82. DEFINE(UM_PROT_WRITE, PROT_WRITE);
  83. DEFINE(UM_PROT_EXEC, PROT_EXEC);
  84. DEFINE(__NR_syscall_max, sizeof(syscalls) - 1);
  85. DEFINE(NR_syscalls, sizeof(syscalls));
  86. }