user-offsets.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <stdio.h>
  2. #include <stddef.h>
  3. #include <signal.h>
  4. #define __FRAME_OFFSETS
  5. #include <asm/ptrace.h>
  6. #include <asm/types.h>
  7. /* For some reason, x86_64 defines u64 and u32 only in <pci/types.h>, which I
  8. * refuse to include here, even though they're used throughout the headers.
  9. * These are used in asm/user.h, and that include can't be avoided because of
  10. * the sizeof(struct user_regs_struct) below.
  11. */
  12. typedef __u64 u64;
  13. typedef __u32 u32;
  14. #include <asm/user.h>
  15. #define DEFINE(sym, val) \
  16. asm volatile("\n->" #sym " %0 " #val : : "i" (val))
  17. #define DEFINE_LONGS(sym, val) \
  18. asm volatile("\n->" #sym " %0 " #val : : "i" (val/sizeof(unsigned long)))
  19. #define OFFSET(sym, str, mem) \
  20. DEFINE(sym, offsetof(struct str, mem));
  21. void foo(void)
  22. {
  23. OFFSET(HOST_SC_RBX, sigcontext, rbx);
  24. OFFSET(HOST_SC_RCX, sigcontext, rcx);
  25. OFFSET(HOST_SC_RDX, sigcontext, rdx);
  26. OFFSET(HOST_SC_RSI, sigcontext, rsi);
  27. OFFSET(HOST_SC_RDI, sigcontext, rdi);
  28. OFFSET(HOST_SC_RBP, sigcontext, rbp);
  29. OFFSET(HOST_SC_RAX, sigcontext, rax);
  30. OFFSET(HOST_SC_R8, sigcontext, r8);
  31. OFFSET(HOST_SC_R9, sigcontext, r9);
  32. OFFSET(HOST_SC_R10, sigcontext, r10);
  33. OFFSET(HOST_SC_R11, sigcontext, r11);
  34. OFFSET(HOST_SC_R12, sigcontext, r12);
  35. OFFSET(HOST_SC_R13, sigcontext, r13);
  36. OFFSET(HOST_SC_R14, sigcontext, r14);
  37. OFFSET(HOST_SC_R15, sigcontext, r15);
  38. OFFSET(HOST_SC_IP, sigcontext, rip);
  39. OFFSET(HOST_SC_SP, sigcontext, rsp);
  40. OFFSET(HOST_SC_CR2, sigcontext, cr2);
  41. OFFSET(HOST_SC_ERR, sigcontext, err);
  42. OFFSET(HOST_SC_TRAPNO, sigcontext, trapno);
  43. OFFSET(HOST_SC_CS, sigcontext, cs);
  44. OFFSET(HOST_SC_FS, sigcontext, fs);
  45. OFFSET(HOST_SC_GS, sigcontext, gs);
  46. OFFSET(HOST_SC_EFLAGS, sigcontext, eflags);
  47. OFFSET(HOST_SC_SIGMASK, sigcontext, oldmask);
  48. #if 0
  49. OFFSET(HOST_SC_ORIG_RAX, sigcontext, orig_rax);
  50. OFFSET(HOST_SC_DS, sigcontext, ds);
  51. OFFSET(HOST_SC_ES, sigcontext, es);
  52. OFFSET(HOST_SC_SS, sigcontext, ss);
  53. #endif
  54. DEFINE_LONGS(HOST_FRAME_SIZE, FRAME_SIZE);
  55. DEFINE(HOST_FP_SIZE, 0);
  56. DEFINE(HOST_XFP_SIZE, 0);
  57. DEFINE_LONGS(HOST_RBX, RBX);
  58. DEFINE_LONGS(HOST_RCX, RCX);
  59. DEFINE_LONGS(HOST_RDI, RDI);
  60. DEFINE_LONGS(HOST_RSI, RSI);
  61. DEFINE_LONGS(HOST_RDX, RDX);
  62. DEFINE_LONGS(HOST_RBP, RBP);
  63. DEFINE_LONGS(HOST_RAX, RAX);
  64. DEFINE_LONGS(HOST_R8, R8);
  65. DEFINE_LONGS(HOST_R9, R9);
  66. DEFINE_LONGS(HOST_R10, R10);
  67. DEFINE_LONGS(HOST_R11, R11);
  68. DEFINE_LONGS(HOST_R12, R12);
  69. DEFINE_LONGS(HOST_R13, R13);
  70. DEFINE_LONGS(HOST_R14, R14);
  71. DEFINE_LONGS(HOST_R15, R15);
  72. DEFINE_LONGS(HOST_ORIG_RAX, ORIG_RAX);
  73. DEFINE_LONGS(HOST_CS, CS);
  74. DEFINE_LONGS(HOST_SS, SS);
  75. DEFINE_LONGS(HOST_EFLAGS, EFLAGS);
  76. #if 0
  77. DEFINE_LONGS(HOST_FS, FS);
  78. DEFINE_LONGS(HOST_GS, GS);
  79. DEFINE_LONGS(HOST_DS, DS);
  80. DEFINE_LONGS(HOST_ES, ES);
  81. #endif
  82. DEFINE_LONGS(HOST_IP, RIP);
  83. DEFINE_LONGS(HOST_SP, RSP);
  84. DEFINE(UM_FRAME_SIZE, sizeof(struct user_regs_struct));
  85. }