user-offsets.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #define DEFINE(sym, val) \
  11. asm volatile("\n->" #sym " %0 " #val : : "i" (val))
  12. #define DEFINE_LONGS(sym, val) \
  13. asm volatile("\n->" #sym " %0 " #val : : "i" (val/sizeof(unsigned long)))
  14. #define OFFSET(sym, str, mem) \
  15. DEFINE(sym, offsetof(struct str, mem));
  16. void foo(void)
  17. {
  18. OFFSET(HOST_SC_CR2, sigcontext, cr2);
  19. OFFSET(HOST_SC_ERR, sigcontext, err);
  20. OFFSET(HOST_SC_TRAPNO, sigcontext, trapno);
  21. DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long));
  22. DEFINE_LONGS(HOST_RBX, RBX);
  23. DEFINE_LONGS(HOST_RCX, RCX);
  24. DEFINE_LONGS(HOST_RDI, RDI);
  25. DEFINE_LONGS(HOST_RSI, RSI);
  26. DEFINE_LONGS(HOST_RDX, RDX);
  27. DEFINE_LONGS(HOST_RBP, RBP);
  28. DEFINE_LONGS(HOST_RAX, RAX);
  29. DEFINE_LONGS(HOST_R8, R8);
  30. DEFINE_LONGS(HOST_R9, R9);
  31. DEFINE_LONGS(HOST_R10, R10);
  32. DEFINE_LONGS(HOST_R11, R11);
  33. DEFINE_LONGS(HOST_R12, R12);
  34. DEFINE_LONGS(HOST_R13, R13);
  35. DEFINE_LONGS(HOST_R14, R14);
  36. DEFINE_LONGS(HOST_R15, R15);
  37. DEFINE_LONGS(HOST_ORIG_RAX, ORIG_RAX);
  38. DEFINE_LONGS(HOST_CS, CS);
  39. DEFINE_LONGS(HOST_SS, SS);
  40. DEFINE_LONGS(HOST_EFLAGS, EFLAGS);
  41. #if 0
  42. DEFINE_LONGS(HOST_FS, FS);
  43. DEFINE_LONGS(HOST_GS, GS);
  44. DEFINE_LONGS(HOST_DS, DS);
  45. DEFINE_LONGS(HOST_ES, ES);
  46. #endif
  47. DEFINE_LONGS(HOST_IP, RIP);
  48. DEFINE_LONGS(HOST_SP, RSP);
  49. DEFINE(UM_FRAME_SIZE, sizeof(struct user_regs_struct));
  50. /* XXX Duplicated between i386 and x86_64 */
  51. DEFINE(UM_POLLIN, POLLIN);
  52. DEFINE(UM_POLLPRI, POLLPRI);
  53. DEFINE(UM_POLLOUT, POLLOUT);
  54. DEFINE(UM_PROT_READ, PROT_READ);
  55. DEFINE(UM_PROT_WRITE, PROT_WRITE);
  56. DEFINE(UM_PROT_EXEC, PROT_EXEC);
  57. }