1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//
8// Extensions to libunwind API.
9//
10//===----------------------------------------------------------------------===//
11
12#ifndef __LIBUNWIND_EXT__
13#define __LIBUNWIND_EXT__
14
15#include "config.h"
16#include <libunwind.h>
17#include <unwind.h>
18
19#define UNW_STEP_SUCCESS 1
20#define UNW_STEP_END 0
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26extern int __unw_getcontext(unw_context_t *);
27extern int __unw_init_local(unw_cursor_t *, unw_context_t *);
28extern int __unw_step(unw_cursor_t *);
29extern int __unw_step_stage2(unw_cursor_t *);
30extern int __unw_get_reg(unw_cursor_t *, unw_regnum_t, unw_word_t *);
31extern int __unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *);
32extern int __unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t);
33extern int __unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t);
34_LIBUNWIND_TRACE_NO_INLINE
35 extern int __unw_resume_with_frames_walked(unw_cursor_t *, unsigned);
36// `__unw_resume` is a legacy function. Use `__unw_resume_with_frames_walked` instead.
37_LIBUNWIND_TRACE_NO_INLINE
38 extern int __unw_resume(unw_cursor_t *);
39
40#ifdef __arm__
41/* Save VFP registers in FSTMX format (instead of FSTMD). */
42extern void __unw_save_vfp_as_X(unw_cursor_t *);
43#endif
44
45extern const char *__unw_regname(unw_cursor_t *, unw_regnum_t);
46extern int __unw_get_proc_info(unw_cursor_t *, unw_proc_info_t *);
47extern int __unw_is_fpreg(unw_cursor_t *, unw_regnum_t);
48extern int __unw_is_signal_frame(unw_cursor_t *);
49extern int __unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *);
50extern const char *__unw_strerror(int);
51
52#if defined(_AIX)
53extern uintptr_t __unw_get_data_rel_base(unw_cursor_t *);
54#endif
55
56// SPI
57extern void __unw_iterate_dwarf_unwind_cache(void (*func)(
58 unw_word_t ip_start, unw_word_t ip_end, unw_word_t fde, unw_word_t mh));
59
60// IPI
61extern void __unw_add_dynamic_fde(unw_word_t fde);
62extern void __unw_remove_dynamic_fde(unw_word_t fde);
63
64extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start);
65extern void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start);
66
67#ifdef __APPLE__
68
69// Holds a description of the object-format-header (if any) and unwind info
70// sections for a given address:
71//
72// * dso_base should point to a header for the JIT'd object containing the
73// given address. The header's type should match the format type that
74// libunwind was compiled for (so a mach_header or mach_header_64 on Darwin).
75// A value of zero indicates that no such header exists.
76//
77// * dwarf_section and dwarf_section_length hold the address range of a DWARF
78// eh-frame section associated with the given address, if any. If the
79// dwarf_section_length field is zero it indicates that no such section
80// exists (and in this case dwarf_section should also be set to zero).
81//
82// * compact_unwind_section and compact_unwind_section_length hold the address
83// range of a compact-unwind info section associated with the given address,
84// if any. If the compact_unwind_section_length field is zero it indicates
85// that no such section exists (and in this case compact_unwind_section
86// should also be set to zero).
87//
88// See the unw_find_dynamic_unwind_sections type below for more details.
89struct unw_dynamic_unwind_sections {
90 unw_word_t dso_base;
91 unw_word_t dwarf_section;
92 size_t dwarf_section_length;
93 unw_word_t compact_unwind_section;
94 size_t compact_unwind_section_length;
95};
96
97// Typedef for unwind-info lookup callbacks. Functions of this type can be
98// registered and deregistered using __unw_add_find_dynamic_unwind_sections
99// and __unw_remove_find_dynamic_unwind_sections respectively.
100//
101// An unwind-info lookup callback should return 1 to indicate that it found
102// unwind-info for the given address, or 0 to indicate that it did not find
103// unwind-info for the given address. If found, the callback should populate
104// some or all of the fields of the info argument (which is guaranteed to be
105// non-null with all fields zero-initialized):
106typedef int (*unw_find_dynamic_unwind_sections)(
107 unw_word_t addr, struct unw_dynamic_unwind_sections *info);
108
109// Register a dynamic unwind-info lookup callback. If libunwind does not find
110// unwind info for a given frame in the executable program or normal dynamic
111// shared objects then it will call all registered dynamic lookup functions
112// in registration order until either one of them returns true, or the end
113// of the list is reached. This lookup will happen before libunwind searches
114// any eh-frames registered via __register_frame or
115// __unw_add_dynamic_eh_frame_section.
116//
117// Returns UNW_ESUCCESS for successful registrations. If the given callback
118// has already been registered then UNW_EINVAL will be returned. If all
119// available callback entries are in use then UNW_ENOMEM will be returned.
120extern int __unw_add_find_dynamic_unwind_sections(
121 unw_find_dynamic_unwind_sections find_dynamic_unwind_sections);
122
123// Deregister a dynamic unwind-info lookup callback.
124//
125// Returns UNW_ESUCCESS for successful deregistrations. If the given callback
126// is not present then UNW_EINVAL will be returned.
127extern int __unw_remove_find_dynamic_unwind_sections(
128 unw_find_dynamic_unwind_sections find_dynamic_unwind_sections);
129
130#endif
131
132#if defined(_LIBUNWIND_ARM_EHABI)
133extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*);
134extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context,
135 const uint32_t *data,
136 size_t offset, size_t len);
137#endif
138
139#ifdef __cplusplus
140}
141#endif
142
143#endif // __LIBUNWIND_EXT__
144