|
| 1 | +#ifndef Py_INTERNAL_JIT_UNWIND_H |
| 2 | +#define Py_INTERNAL_JIT_UNWIND_H |
| 3 | + |
| 4 | +#ifndef Py_BUILD_CORE |
| 5 | +# error "this header requires Py_BUILD_CORE define" |
| 6 | +#endif |
| 7 | + |
| 8 | +#include <stddef.h> |
| 9 | +#include <stdint.h> |
| 10 | + |
| 11 | +#if defined(_Py_JIT) && defined(__linux__) && defined(__ELF__) |
| 12 | +# define PY_HAVE_JIT_GDB_UNWIND |
| 13 | +#endif |
| 14 | + |
| 15 | +#if defined(PY_HAVE_PERF_TRAMPOLINE) || defined(PY_HAVE_JIT_GDB_UNWIND) |
| 16 | + |
| 17 | +#if defined(PY_HAVE_JIT_GDB_UNWIND) |
| 18 | +extern PyMutex _Py_jit_debug_mutex; |
| 19 | +#endif |
| 20 | + |
| 21 | +/* DWARF exception-handling pointer encodings shared by JIT unwind users. */ |
| 22 | +enum { |
| 23 | + DWRF_EH_PE_absptr = 0x00, |
| 24 | + DWRF_EH_PE_omit = 0xff, |
| 25 | + |
| 26 | + /* Data type encodings */ |
| 27 | + DWRF_EH_PE_uleb128 = 0x01, |
| 28 | + DWRF_EH_PE_udata2 = 0x02, |
| 29 | + DWRF_EH_PE_udata4 = 0x03, |
| 30 | + DWRF_EH_PE_udata8 = 0x04, |
| 31 | + DWRF_EH_PE_sleb128 = 0x09, |
| 32 | + DWRF_EH_PE_sdata2 = 0x0a, |
| 33 | + DWRF_EH_PE_sdata4 = 0x0b, |
| 34 | + DWRF_EH_PE_sdata8 = 0x0c, |
| 35 | + DWRF_EH_PE_signed = 0x08, |
| 36 | + |
| 37 | + /* Reference type encodings */ |
| 38 | + DWRF_EH_PE_pcrel = 0x10, |
| 39 | + DWRF_EH_PE_textrel = 0x20, |
| 40 | + DWRF_EH_PE_datarel = 0x30, |
| 41 | + DWRF_EH_PE_funcrel = 0x40, |
| 42 | + DWRF_EH_PE_aligned = 0x50, |
| 43 | + DWRF_EH_PE_indirect = 0x80 |
| 44 | +}; |
| 45 | + |
| 46 | +/* Return the size of the generated .eh_frame data for the given encoding. */ |
| 47 | +size_t _PyJitUnwind_EhFrameSize(int absolute_addr); |
| 48 | + |
| 49 | +/* |
| 50 | + * Build DWARF .eh_frame data for JIT code; returns size written or 0 on error. |
| 51 | + * absolute_addr selects the FDE address encoding: |
| 52 | + * - 0: PC-relative offsets (perf jitdump synthesized DSO). |
| 53 | + * - nonzero: absolute addresses (GDB JIT in-memory ELF). |
| 54 | + */ |
| 55 | +size_t _PyJitUnwind_BuildEhFrame(uint8_t *buffer, size_t buffer_size, |
| 56 | + const void *code_addr, size_t code_size, |
| 57 | + int absolute_addr); |
| 58 | + |
| 59 | +void *_PyJitUnwind_GdbRegisterCode(const void *code_addr, |
| 60 | + size_t code_size, |
| 61 | + const char *entry, |
| 62 | + const char *filename); |
| 63 | + |
| 64 | +void _PyJitUnwind_GdbUnregisterCode(void *handle); |
| 65 | + |
| 66 | +#endif // defined(PY_HAVE_PERF_TRAMPOLINE) || defined(PY_HAVE_JIT_GDB_UNWIND) |
| 67 | + |
| 68 | +#endif // Py_INTERNAL_JIT_UNWIND_H |
0 commit comments