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