jitdump.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * jitdump.h: jitted code info encapsulation file format
  4. *
  5. * Adapted from OProfile GPLv2 support jidump.h:
  6. * Copyright 2007 OProfile authors
  7. * Jens Wilke
  8. * Daniel Hansel
  9. * Copyright IBM Corporation 2007
  10. */
  11. #ifndef JITDUMP_H
  12. #define JITDUMP_H
  13. #include <sys/time.h>
  14. #include <time.h>
  15. #include <stdint.h>
  16. /* JiTD */
  17. #define JITHEADER_MAGIC 0x4A695444
  18. #define JITHEADER_MAGIC_SW 0x4454694A
  19. #define PADDING_8ALIGNED(x) ((((x) + 7) & 7) ^ 7)
  20. #define ALIGN_8(x) (((x) + 7) & (~7))
  21. #define JITHEADER_VERSION 1
  22. enum jitdump_flags_bits {
  23. JITDUMP_FLAGS_ARCH_TIMESTAMP_BIT,
  24. JITDUMP_FLAGS_MAX_BIT,
  25. };
  26. #define JITDUMP_FLAGS_ARCH_TIMESTAMP (1ULL << JITDUMP_FLAGS_ARCH_TIMESTAMP_BIT)
  27. #define JITDUMP_FLAGS_RESERVED (JITDUMP_FLAGS_MAX_BIT < 64 ? \
  28. (~((1ULL << JITDUMP_FLAGS_MAX_BIT) - 1)) : 0)
  29. struct jitheader {
  30. uint32_t magic; /* characters "jItD" */
  31. uint32_t version; /* header version */
  32. uint32_t total_size; /* total size of header */
  33. uint32_t elf_mach; /* elf mach target */
  34. uint32_t pad1; /* reserved */
  35. uint32_t pid; /* JIT process id */
  36. uint64_t timestamp; /* timestamp */
  37. uint64_t flags; /* flags */
  38. };
  39. enum jit_record_type {
  40. JIT_CODE_LOAD = 0,
  41. JIT_CODE_MOVE = 1,
  42. JIT_CODE_DEBUG_INFO = 2,
  43. JIT_CODE_CLOSE = 3,
  44. JIT_CODE_UNWINDING_INFO = 4,
  45. JIT_CODE_MAX,
  46. };
  47. /* record prefix (mandatory in each record) */
  48. struct jr_prefix {
  49. uint32_t id;
  50. uint32_t total_size;
  51. uint64_t timestamp;
  52. };
  53. struct jr_code_load {
  54. struct jr_prefix p;
  55. uint32_t pid;
  56. uint32_t tid;
  57. uint64_t vma;
  58. uint64_t code_addr;
  59. uint64_t code_size;
  60. uint64_t code_index;
  61. };
  62. struct jr_code_close {
  63. struct jr_prefix p;
  64. };
  65. struct jr_code_move {
  66. struct jr_prefix p;
  67. uint32_t pid;
  68. uint32_t tid;
  69. uint64_t vma;
  70. uint64_t old_code_addr;
  71. uint64_t new_code_addr;
  72. uint64_t code_size;
  73. uint64_t code_index;
  74. };
  75. struct debug_entry {
  76. uint64_t addr;
  77. int lineno; /* source line number starting at 1 */
  78. int discrim; /* column discriminator, 0 is default */
  79. const char name[]; /* null terminated filename, \xff\0 if same as previous entry */
  80. };
  81. struct jr_code_debug_info {
  82. struct jr_prefix p;
  83. uint64_t code_addr;
  84. uint64_t nr_entry;
  85. struct debug_entry entries[];
  86. };
  87. struct jr_code_unwinding_info {
  88. struct jr_prefix p;
  89. uint64_t unwinding_size;
  90. uint64_t eh_frame_hdr_size;
  91. uint64_t mapped_size;
  92. const char unwinding_data[];
  93. };
  94. union jr_entry {
  95. struct jr_code_debug_info info;
  96. struct jr_code_close close;
  97. struct jr_code_load load;
  98. struct jr_code_move move;
  99. struct jr_prefix prefix;
  100. struct jr_code_unwinding_info unwinding;
  101. };
  102. static inline struct debug_entry *
  103. debug_entry_next(struct debug_entry *ent)
  104. {
  105. void *a = ent + 1;
  106. size_t l = strlen(ent->name) + 1;
  107. return a + l;
  108. }
  109. static inline char *
  110. debug_entry_file(struct debug_entry *ent)
  111. {
  112. void *a = ent + 1;
  113. return a;
  114. }
  115. #endif /* !JITDUMP_H */