1349cc55cSDimitry Andric //===----------------------------------------------------------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric // 80b57cec5SDimitry Andric // Extensions to libunwind API. 90b57cec5SDimitry Andric // 100b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric #ifndef __LIBUNWIND_EXT__ 130b57cec5SDimitry Andric #define __LIBUNWIND_EXT__ 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric #include "config.h" 160b57cec5SDimitry Andric #include <libunwind.h> 170b57cec5SDimitry Andric #include <unwind.h> 180b57cec5SDimitry Andric 190b57cec5SDimitry Andric #define UNW_STEP_SUCCESS 1 200b57cec5SDimitry Andric #define UNW_STEP_END 0 210b57cec5SDimitry Andric 220b57cec5SDimitry Andric #ifdef __cplusplus 230b57cec5SDimitry Andric extern "C" { 240b57cec5SDimitry Andric #endif 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric extern int __unw_getcontext(unw_context_t *); 270b57cec5SDimitry Andric extern int __unw_init_local(unw_cursor_t *, unw_context_t *); 280b57cec5SDimitry Andric extern int __unw_step(unw_cursor_t *); 290b57cec5SDimitry Andric extern int __unw_get_reg(unw_cursor_t *, unw_regnum_t, unw_word_t *); 300b57cec5SDimitry Andric extern int __unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *); 310b57cec5SDimitry Andric extern int __unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t); 320b57cec5SDimitry Andric extern int __unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t); 330b57cec5SDimitry Andric extern int __unw_resume(unw_cursor_t *); 340b57cec5SDimitry Andric 350b57cec5SDimitry Andric #ifdef __arm__ 360b57cec5SDimitry Andric /* Save VFP registers in FSTMX format (instead of FSTMD). */ 370b57cec5SDimitry Andric extern void __unw_save_vfp_as_X(unw_cursor_t *); 380b57cec5SDimitry Andric #endif 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric extern const char *__unw_regname(unw_cursor_t *, unw_regnum_t); 410b57cec5SDimitry Andric extern int __unw_get_proc_info(unw_cursor_t *, unw_proc_info_t *); 420b57cec5SDimitry Andric extern int __unw_is_fpreg(unw_cursor_t *, unw_regnum_t); 430b57cec5SDimitry Andric extern int __unw_is_signal_frame(unw_cursor_t *); 440b57cec5SDimitry Andric extern int __unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *); 450b57cec5SDimitry Andric 4681ad6265SDimitry Andric #if defined(_AIX) 4781ad6265SDimitry Andric extern uintptr_t __unw_get_data_rel_base(unw_cursor_t *); 4881ad6265SDimitry Andric #endif 4981ad6265SDimitry Andric 500b57cec5SDimitry Andric // SPI 510b57cec5SDimitry Andric extern void __unw_iterate_dwarf_unwind_cache(void (*func)( 520b57cec5SDimitry Andric unw_word_t ip_start, unw_word_t ip_end, unw_word_t fde, unw_word_t mh)); 530b57cec5SDimitry Andric 540b57cec5SDimitry Andric // IPI 550b57cec5SDimitry Andric extern void __unw_add_dynamic_fde(unw_word_t fde); 560b57cec5SDimitry Andric extern void __unw_remove_dynamic_fde(unw_word_t fde); 570b57cec5SDimitry Andric 58349cc55cSDimitry Andric extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start); 59349cc55cSDimitry Andric extern void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start); 60349cc55cSDimitry Andric 61*06c3fb27SDimitry Andric #ifdef __APPLE__ 62*06c3fb27SDimitry Andric 63*06c3fb27SDimitry Andric // Holds a description of the object-format-header (if any) and unwind info 64*06c3fb27SDimitry Andric // sections for a given address: 65*06c3fb27SDimitry Andric // 66*06c3fb27SDimitry Andric // * dso_base should point to a header for the JIT'd object containing the 67*06c3fb27SDimitry Andric // given address. The header's type should match the format type that 68*06c3fb27SDimitry Andric // libunwind was compiled for (so a mach_header or mach_header_64 on Darwin). 69*06c3fb27SDimitry Andric // A value of zero indicates that no such header exists. 70*06c3fb27SDimitry Andric // 71*06c3fb27SDimitry Andric // * dwarf_section and dwarf_section_length hold the address range of a DWARF 72*06c3fb27SDimitry Andric // eh-frame section associated with the given address, if any. If the 73*06c3fb27SDimitry Andric // dwarf_section_length field is zero it indicates that no such section 74*06c3fb27SDimitry Andric // exists (and in this case dwarf_section should also be set to zero). 75*06c3fb27SDimitry Andric // 76*06c3fb27SDimitry Andric // * compact_unwind_section and compact_unwind_section_length hold the address 77*06c3fb27SDimitry Andric // range of a compact-unwind info section associated with the given address, 78*06c3fb27SDimitry Andric // if any. If the compact_unwind_section_length field is zero it indicates 79*06c3fb27SDimitry Andric // that no such section exists (and in this case compact_unwind_section 80*06c3fb27SDimitry Andric // should also be set to zero). 81*06c3fb27SDimitry Andric // 82*06c3fb27SDimitry Andric // See the unw_find_dynamic_unwind_sections type below for more details. 83*06c3fb27SDimitry Andric struct unw_dynamic_unwind_sections { 84*06c3fb27SDimitry Andric unw_word_t dso_base; 85*06c3fb27SDimitry Andric unw_word_t dwarf_section; 86*06c3fb27SDimitry Andric size_t dwarf_section_length; 87*06c3fb27SDimitry Andric unw_word_t compact_unwind_section; 88*06c3fb27SDimitry Andric size_t compact_unwind_section_length; 89*06c3fb27SDimitry Andric }; 90*06c3fb27SDimitry Andric 91*06c3fb27SDimitry Andric // Typedef for unwind-info lookup callbacks. Functions of this type can be 92*06c3fb27SDimitry Andric // registered and deregistered using __unw_add_find_dynamic_unwind_sections 93*06c3fb27SDimitry Andric // and __unw_remove_find_dynamic_unwind_sections respectively. 94*06c3fb27SDimitry Andric // 95*06c3fb27SDimitry Andric // An unwind-info lookup callback should return 1 to indicate that it found 96*06c3fb27SDimitry Andric // unwind-info for the given address, or 0 to indicate that it did not find 97*06c3fb27SDimitry Andric // unwind-info for the given address. If found, the callback should populate 98*06c3fb27SDimitry Andric // some or all of the fields of the info argument (which is guaranteed to be 99*06c3fb27SDimitry Andric // non-null with all fields zero-initialized): 100*06c3fb27SDimitry Andric typedef int (*unw_find_dynamic_unwind_sections)( 101*06c3fb27SDimitry Andric unw_word_t addr, struct unw_dynamic_unwind_sections *info); 102*06c3fb27SDimitry Andric 103*06c3fb27SDimitry Andric // Register a dynamic unwind-info lookup callback. If libunwind does not find 104*06c3fb27SDimitry Andric // unwind info for a given frame in the executable program or normal dynamic 105*06c3fb27SDimitry Andric // shared objects then it will call all registered dynamic lookup functions 106*06c3fb27SDimitry Andric // in registration order until either one of them returns true, or the end 107*06c3fb27SDimitry Andric // of the list is reached. This lookup will happen before libunwind searches 108*06c3fb27SDimitry Andric // any eh-frames registered via __register_frame or 109*06c3fb27SDimitry Andric // __unw_add_dynamic_eh_frame_section. 110*06c3fb27SDimitry Andric // 111*06c3fb27SDimitry Andric // Returns UNW_ESUCCESS for successful registrations. If the given callback 112*06c3fb27SDimitry Andric // has already been registered then UNW_EINVAL will be returned. If all 113*06c3fb27SDimitry Andric // available callback entries are in use then UNW_ENOMEM will be returned. 114*06c3fb27SDimitry Andric extern int __unw_add_find_dynamic_unwind_sections( 115*06c3fb27SDimitry Andric unw_find_dynamic_unwind_sections find_dynamic_unwind_sections); 116*06c3fb27SDimitry Andric 117*06c3fb27SDimitry Andric // Deregister a dynacim unwind-info lookup callback. 118*06c3fb27SDimitry Andric // 119*06c3fb27SDimitry Andric // Returns UNW_ESUCCESS for successful deregistrations. If the given callback 120*06c3fb27SDimitry Andric // has already been registered then UNW_EINVAL will be returned. 121*06c3fb27SDimitry Andric extern int __unw_remove_find_dynamic_unwind_sections( 122*06c3fb27SDimitry Andric unw_find_dynamic_unwind_sections find_dynamic_unwind_sections); 123*06c3fb27SDimitry Andric 124*06c3fb27SDimitry Andric #endif 125*06c3fb27SDimitry Andric 1260b57cec5SDimitry Andric #if defined(_LIBUNWIND_ARM_EHABI) 1270b57cec5SDimitry Andric extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*); 1280b57cec5SDimitry Andric extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context, 1290b57cec5SDimitry Andric const uint32_t *data, 1300b57cec5SDimitry Andric size_t offset, size_t len); 1310b57cec5SDimitry Andric #endif 1320b57cec5SDimitry Andric 1330b57cec5SDimitry Andric #ifdef __cplusplus 1340b57cec5SDimitry Andric } 1350b57cec5SDimitry Andric #endif 1360b57cec5SDimitry Andric 1370b57cec5SDimitry Andric #endif // __LIBUNWIND_EXT__ 138