1 //===---------------------------- libunwind.h -----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
9 // Compatible with libunwind API documented at:
10 // http://www.nongnu.org/libunwind/man/libunwind(3).html
12 //===----------------------------------------------------------------------===//
17 #include <__libunwind_config.h>
24 #if __has_include(<Availability.h>)
25 #include <Availability.h>
27 #elif __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
28 #include <Availability.h>
32 #define LIBUNWIND_AVAIL __attribute__((unavailable))
33 #elif defined(__OSX_AVAILABLE_STARTING)
34 #define LIBUNWIND_AVAIL __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_5_0)
36 #include <AvailabilityMacros.h>
37 #ifdef AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
38 #define LIBUNWIND_AVAIL AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
40 #define LIBUNWIND_AVAIL __attribute__((unavailable))
44 #define LIBUNWIND_AVAIL
49 UNW_ESUCCESS = 0, /* no error */
50 UNW_EUNSPEC = -6540, /* unspecified (general) error */
51 UNW_ENOMEM = -6541, /* out of memory */
52 UNW_EBADREG = -6542, /* bad register number */
53 UNW_EREADONLYREG = -6543, /* attempt to write read-only register */
54 UNW_ESTOPUNWIND = -6544, /* stop unwinding */
55 UNW_EINVALIDIP = -6545, /* invalid IP */
56 UNW_EBADFRAME = -6546, /* bad frame */
57 UNW_EINVAL = -6547, /* unsupported operation or bad value */
58 UNW_EBADVERSION = -6548, /* unwind info has unsupported version */
59 UNW_ENOINFO = -6549 /* no unwind info found */
60 #if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY)
61 , UNW_ECROSSRASIGNING = -6550 /* cross unwind with return address signing */
65 struct unw_context_t {
66 uint64_t data[_LIBUNWIND_CONTEXT_SIZE];
68 typedef struct unw_context_t unw_context_t;
71 uint64_t data[_LIBUNWIND_CURSOR_SIZE];
73 typedef struct unw_cursor_t unw_cursor_t;
75 typedef struct unw_addr_space *unw_addr_space_t;
77 typedef int unw_regnum_t;
78 typedef uintptr_t unw_word_t;
80 typedef uint64_t unw_fpreg_t;
82 typedef double unw_fpreg_t;
85 struct unw_proc_info_t {
86 unw_word_t start_ip; /* start address of function */
87 unw_word_t end_ip; /* address after end of function */
88 unw_word_t lsda; /* address of language specific data area, */
89 /* or zero if not used */
90 unw_word_t handler; /* personality routine, or zero if not used */
91 unw_word_t gp; /* not used */
92 unw_word_t flags; /* not used */
93 uint32_t format; /* compact unwind encoding, or zero if none */
94 uint32_t unwind_info_size; /* size of DWARF unwind info, or zero if none */
95 unw_word_t unwind_info; /* address of DWARF unwind info, or zero */
96 unw_word_t extra; /* mach_header of mach-o image containing func */
98 typedef struct unw_proc_info_t unw_proc_info_t;
104 extern int unw_getcontext(unw_context_t *) LIBUNWIND_AVAIL;
105 extern int unw_init_local(unw_cursor_t *, unw_context_t *) LIBUNWIND_AVAIL;
106 extern int unw_step(unw_cursor_t *) LIBUNWIND_AVAIL;
107 extern int unw_get_reg(unw_cursor_t *, unw_regnum_t, unw_word_t *) LIBUNWIND_AVAIL;
108 extern int unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *) LIBUNWIND_AVAIL;
109 extern int unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t) LIBUNWIND_AVAIL;
110 extern int unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t) LIBUNWIND_AVAIL;
111 extern int unw_resume(unw_cursor_t *) LIBUNWIND_AVAIL;
114 /* Save VFP registers in FSTMX format (instead of FSTMD). */
115 extern void unw_save_vfp_as_X(unw_cursor_t *) LIBUNWIND_AVAIL;
119 extern const char *unw_regname(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
120 extern int unw_get_proc_info(unw_cursor_t *, unw_proc_info_t *) LIBUNWIND_AVAIL;
121 extern int unw_is_fpreg(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
122 extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL;
123 extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL;
124 //extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);
126 extern unw_addr_space_t unw_local_addr_space;
130 * Mac OS X "remote" API for unwinding other processes on same machine
133 extern unw_addr_space_t unw_create_addr_space_for_task(task_t);
134 extern void unw_destroy_addr_space(unw_addr_space_t);
135 extern int unw_init_remote_thread(unw_cursor_t *, unw_addr_space_t, thread_t *);
136 #endif /* UNW_REMOTE */
139 * traditional libunwind "remote" API
140 * NOT IMPLEMENTED on Mac OS X
142 * extern int unw_init_remote(unw_cursor_t*, unw_addr_space_t,
144 * extern unw_accessors_t unw_get_accessors(unw_addr_space_t);
145 * extern unw_addr_space_t unw_create_addr_space(unw_accessors_t, int);
146 * extern void unw_flush_cache(unw_addr_space_t, unw_word_t,
148 * extern int unw_set_caching_policy(unw_addr_space_t,
149 * unw_caching_policy_t);
150 * extern void _U_dyn_register(unw_dyn_info_t*);
151 * extern void _U_dyn_cancel(unw_dyn_info_t*);
158 // architecture independent register numbers
160 UNW_REG_IP = -1, // instruction pointer
161 UNW_REG_SP = -2, // stack pointer
164 // 32-bit x86 registers
176 // 64-bit x86_64 registers
195 UNW_X86_64_XMM0 = 17,
196 UNW_X86_64_XMM1 = 18,
197 UNW_X86_64_XMM2 = 19,
198 UNW_X86_64_XMM3 = 20,
199 UNW_X86_64_XMM4 = 21,
200 UNW_X86_64_XMM5 = 22,
201 UNW_X86_64_XMM6 = 23,
202 UNW_X86_64_XMM7 = 24,
203 UNW_X86_64_XMM8 = 25,
204 UNW_X86_64_XMM9 = 26,
205 UNW_X86_64_XMM10 = 27,
206 UNW_X86_64_XMM11 = 28,
207 UNW_X86_64_XMM12 = 29,
208 UNW_X86_64_XMM13 = 30,
209 UNW_X86_64_XMM14 = 31,
210 UNW_X86_64_XMM15 = 32,
214 // 32-bit ppc register numbers
325 UNW_PPC_VRSAVE = 109,
327 UNW_PPC_SPE_ACC = 111,
328 UNW_PPC_SPEFSCR = 112
331 // 64-bit ppc register numbers
442 // 109, 111-113: OpenPOWER ELF V2 ABI: reserved
443 // Borrowing VRSAVE number from PPC32.
444 UNW_PPC64_VRSAVE = 109,
445 UNW_PPC64_VSCR = 110,
446 UNW_PPC64_TFHAR = 114,
447 UNW_PPC64_TFIAR = 115,
448 UNW_PPC64_TEXASR = 116,
449 UNW_PPC64_VS0 = UNW_PPC64_F0,
450 UNW_PPC64_VS1 = UNW_PPC64_F1,
451 UNW_PPC64_VS2 = UNW_PPC64_F2,
452 UNW_PPC64_VS3 = UNW_PPC64_F3,
453 UNW_PPC64_VS4 = UNW_PPC64_F4,
454 UNW_PPC64_VS5 = UNW_PPC64_F5,
455 UNW_PPC64_VS6 = UNW_PPC64_F6,
456 UNW_PPC64_VS7 = UNW_PPC64_F7,
457 UNW_PPC64_VS8 = UNW_PPC64_F8,
458 UNW_PPC64_VS9 = UNW_PPC64_F9,
459 UNW_PPC64_VS10 = UNW_PPC64_F10,
460 UNW_PPC64_VS11 = UNW_PPC64_F11,
461 UNW_PPC64_VS12 = UNW_PPC64_F12,
462 UNW_PPC64_VS13 = UNW_PPC64_F13,
463 UNW_PPC64_VS14 = UNW_PPC64_F14,
464 UNW_PPC64_VS15 = UNW_PPC64_F15,
465 UNW_PPC64_VS16 = UNW_PPC64_F16,
466 UNW_PPC64_VS17 = UNW_PPC64_F17,
467 UNW_PPC64_VS18 = UNW_PPC64_F18,
468 UNW_PPC64_VS19 = UNW_PPC64_F19,
469 UNW_PPC64_VS20 = UNW_PPC64_F20,
470 UNW_PPC64_VS21 = UNW_PPC64_F21,
471 UNW_PPC64_VS22 = UNW_PPC64_F22,
472 UNW_PPC64_VS23 = UNW_PPC64_F23,
473 UNW_PPC64_VS24 = UNW_PPC64_F24,
474 UNW_PPC64_VS25 = UNW_PPC64_F25,
475 UNW_PPC64_VS26 = UNW_PPC64_F26,
476 UNW_PPC64_VS27 = UNW_PPC64_F27,
477 UNW_PPC64_VS28 = UNW_PPC64_F28,
478 UNW_PPC64_VS29 = UNW_PPC64_F29,
479 UNW_PPC64_VS30 = UNW_PPC64_F30,
480 UNW_PPC64_VS31 = UNW_PPC64_F31,
481 UNW_PPC64_VS32 = UNW_PPC64_V0,
482 UNW_PPC64_VS33 = UNW_PPC64_V1,
483 UNW_PPC64_VS34 = UNW_PPC64_V2,
484 UNW_PPC64_VS35 = UNW_PPC64_V3,
485 UNW_PPC64_VS36 = UNW_PPC64_V4,
486 UNW_PPC64_VS37 = UNW_PPC64_V5,
487 UNW_PPC64_VS38 = UNW_PPC64_V6,
488 UNW_PPC64_VS39 = UNW_PPC64_V7,
489 UNW_PPC64_VS40 = UNW_PPC64_V8,
490 UNW_PPC64_VS41 = UNW_PPC64_V9,
491 UNW_PPC64_VS42 = UNW_PPC64_V10,
492 UNW_PPC64_VS43 = UNW_PPC64_V11,
493 UNW_PPC64_VS44 = UNW_PPC64_V12,
494 UNW_PPC64_VS45 = UNW_PPC64_V13,
495 UNW_PPC64_VS46 = UNW_PPC64_V14,
496 UNW_PPC64_VS47 = UNW_PPC64_V15,
497 UNW_PPC64_VS48 = UNW_PPC64_V16,
498 UNW_PPC64_VS49 = UNW_PPC64_V17,
499 UNW_PPC64_VS50 = UNW_PPC64_V18,
500 UNW_PPC64_VS51 = UNW_PPC64_V19,
501 UNW_PPC64_VS52 = UNW_PPC64_V20,
502 UNW_PPC64_VS53 = UNW_PPC64_V21,
503 UNW_PPC64_VS54 = UNW_PPC64_V22,
504 UNW_PPC64_VS55 = UNW_PPC64_V23,
505 UNW_PPC64_VS56 = UNW_PPC64_V24,
506 UNW_PPC64_VS57 = UNW_PPC64_V25,
507 UNW_PPC64_VS58 = UNW_PPC64_V26,
508 UNW_PPC64_VS59 = UNW_PPC64_V27,
509 UNW_PPC64_VS60 = UNW_PPC64_V28,
510 UNW_PPC64_VS61 = UNW_PPC64_V29,
511 UNW_PPC64_VS62 = UNW_PPC64_V30,
512 UNW_PPC64_VS63 = UNW_PPC64_V31
515 // 64-bit ARM64 registers
553 UNW_ARM64_RA_SIGN_STATE = 34,
589 // 32-bit ARM registers. Numbers match DWARF for ARM spec #3.1 Table 1.
590 // Naming scheme uses recommendations given in Note 4 for VFP-v2 and VFP-v3.
591 // In this scheme, even though the 64-bit floating point registers D0-D31
592 // overlap physically with the 32-bit floating pointer registers S0-S31,
593 // they are given a non-overlapping range of register numbers.
595 // Commented out ranges are not preserved during unwinding.
610 UNW_ARM_SP = 13, // Logical alias for UNW_REG_SP
614 UNW_ARM_IP = 15, // Logical alias for UNW_REG_IP
616 // 16-63 -- OBSOLETE. Used in VFP1 to represent both S0-S31 and D0-D31.
649 // 96-103 -- OBSOLETE. F0-F7. Used by the FPA system. Superseded by VFP.
650 // 104-111 -- wCGR0-wCGR7, ACC0-ACC7 (Intel wireless MMX)
667 // 128-133 -- SPSR, SPSR_{FIQ|IRQ|ABT|UND|SVC}
668 // 134-143 -- Reserved
669 // 144-150 -- R8_USR-R14_USR
670 // 151-157 -- R8_FIQ-R14_FIQ
671 // 158-159 -- R13_IRQ-R14_IRQ
672 // 160-161 -- R13_ABT-R14_ABT
673 // 162-163 -- R13_UND-R14_UND
674 // 164-165 -- R13_SVC-R14_SVC
675 // 166-191 -- Reserved
680 // 196-199 -- wC4-wC7 (Intel wireless MMX control)
681 // 200-255 -- Reserved
714 // 288-319 -- Reserved for VFP/Neon
715 // 320-8191 -- Reserved
716 // 8192-16383 -- Unspecified vendor co-processor register.
719 // OpenRISC1000 register numbers
756 // 64-bit RISC-V registers