A dynamic tracer for Linux

arch-x86_64.c 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <assert.h>
  2. #include <linux/ptrace.h>
  3. #include "type.h"
  4. #define arch_typedef(_a, _t) { \
  5. .ttype = T_TYPEDEF, \
  6. .t = { .tdef = { .name = #_a, .type = _t } }, \
  7. }
  8. type_t t_s8 = arch_typedef(s8, &t_char);
  9. type_t t_u8 = arch_typedef(u8, &t_uchar);
  10. type_t t_s16 = arch_typedef(s16, &t_short);
  11. type_t t_u16 = arch_typedef(u16, &t_ushort);
  12. type_t t_s32 = arch_typedef(s32, &t_int);
  13. type_t t_u32 = arch_typedef(u32, &t_uint);
  14. type_t t_s64 = arch_typedef(s64, &t_long);
  15. type_t t_u64 = arch_typedef(u64, &t_ulong);
  16. field_t f_pt_regs_fields[] = {
  17. { .name = "r15", .type = &t_ulong },
  18. { .name = "r14", .type = &t_ulong },
  19. { .name = "r13", .type = &t_ulong },
  20. { .name = "r12", .type = &t_ulong },
  21. { .name = "rbp", .type = &t_ulong },
  22. { .name = "rbx", .type = &t_ulong },
  23. { .name = "r11", .type = &t_ulong },
  24. { .name = "r10", .type = &t_ulong },
  25. { .name = "r9", .type = &t_ulong },
  26. { .name = "r8", .type = &t_ulong },
  27. { .name = "rax", .type = &t_ulong },
  28. { .name = "rcx", .type = &t_ulong },
  29. { .name = "rdx", .type = &t_ulong },
  30. { .name = "rsi", .type = &t_ulong },
  31. { .name = "rdi", .type = &t_ulong },
  32. { .name = "orig_rax", .type = &t_ulong },
  33. { .name = "rip", .type = &t_ulong },
  34. { .name = "cs", .type = &t_ulong },
  35. { .name = "eflags", .type = &t_ulong },
  36. { .name = "rsp", .type = &t_ulong },
  37. { .name = "ss", .type = &t_ulong },
  38. { .type = NULL }
  39. };
  40. type_t t_pt_regs = {
  41. .ttype = T_STRUCT,
  42. .t.sou = {
  43. .name = "pt_regs",
  44. .fields = f_pt_regs_fields,
  45. },
  46. };
  47. type_t *arch_types[] = {
  48. &t_s8, &t_u8,
  49. &t_s16, &t_u16,
  50. &t_s32, &t_u32,
  51. &t_s64, &t_u64,
  52. &t_pt_regs,
  53. NULL
  54. };
  55. __attribute__((constructor))
  56. static void arch_init(void)
  57. {
  58. type_add_list(arch_types);
  59. assert(t_pt_regs.size == sizeof(struct pt_regs));
  60. }