user-offsets.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <stdio.h>
  2. #include <stddef.h>
  3. #include <signal.h>
  4. #include <sys/poll.h>
  5. #include <sys/user.h>
  6. #include <sys/mman.h>
  7. #include <asm/ptrace.h>
  8. #define DEFINE(sym, val) \
  9. asm volatile("\n->" #sym " %0 " #val : : "i" (val))
  10. #define DEFINE_LONGS(sym, val) \
  11. asm volatile("\n->" #sym " %0 " #val : : "i" (val/sizeof(unsigned long)))
  12. #define OFFSET(sym, str, mem) \
  13. DEFINE(sym, offsetof(struct str, mem));
  14. void foo(void)
  15. {
  16. OFFSET(HOST_SC_TRAPNO, sigcontext, trapno);
  17. OFFSET(HOST_SC_ERR, sigcontext, err);
  18. OFFSET(HOST_SC_CR2, sigcontext, cr2);
  19. DEFINE_LONGS(HOST_FP_SIZE, sizeof(struct user_fpregs_struct));
  20. DEFINE_LONGS(HOST_FPX_SIZE, sizeof(struct user_fpxregs_struct));
  21. DEFINE(HOST_IP, EIP);
  22. DEFINE(HOST_SP, UESP);
  23. DEFINE(HOST_EFLAGS, EFL);
  24. DEFINE(HOST_EAX, EAX);
  25. DEFINE(HOST_EBX, EBX);
  26. DEFINE(HOST_ECX, ECX);
  27. DEFINE(HOST_EDX, EDX);
  28. DEFINE(HOST_ESI, ESI);
  29. DEFINE(HOST_EDI, EDI);
  30. DEFINE(HOST_EBP, EBP);
  31. DEFINE(HOST_CS, CS);
  32. DEFINE(HOST_SS, SS);
  33. DEFINE(HOST_DS, DS);
  34. DEFINE(HOST_FS, FS);
  35. DEFINE(HOST_ES, ES);
  36. DEFINE(HOST_GS, GS);
  37. DEFINE(UM_FRAME_SIZE, sizeof(struct user_regs_struct));
  38. /* XXX Duplicated between i386 and x86_64 */
  39. DEFINE(UM_POLLIN, POLLIN);
  40. DEFINE(UM_POLLPRI, POLLPRI);
  41. DEFINE(UM_POLLOUT, POLLOUT);
  42. DEFINE(UM_PROT_READ, PROT_READ);
  43. DEFINE(UM_PROT_WRITE, PROT_WRITE);
  44. DEFINE(UM_PROT_EXEC, PROT_EXEC);
  45. }