• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===---------------------------- libunwind.h -----------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //
9 // Compatible with libuwind API documented at:
10 //   http://www.nongnu.org/libunwind/man/libunwind(3).html
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef __LIBUNWIND__
15 #define __LIBUNWIND__
16 
17 #include <stdint.h>
18 #include <stddef.h>
19 
20 // TODO(danakj): This is also in unwind.h and cxxabi.h, can we consolidate?
21 #if !defined(__USING_SJLJ_EXCEPTIONS__) && defined(__arm__) && \
22     !defined(__ARM_DWARF_EH__) && !defined(__APPLE__)
23 #define LIBCXXABI_ARM_EHABI 1
24 #else
25 #define LIBCXXABI_ARM_EHABI 0
26 #endif
27 
28 #if __APPLE__
29   #include <Availability.h>
30     #if __arm__
31        #define LIBUNWIND_AVAIL __attribute__((unavailable))
32     #else
33       #define LIBUNWIND_AVAIL __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_5_0)
34     #endif
35 #else
36   #define LIBUNWIND_AVAIL
37 #endif
38 
39 /* error codes */
40 enum {
41   UNW_ESUCCESS      = 0,     /* no error */
42   UNW_EUNSPEC       = -6540, /* unspecified (general) error */
43   UNW_ENOMEM        = -6541, /* out of memory */
44   UNW_EBADREG       = -6542, /* bad register number */
45   UNW_EREADONLYREG  = -6543, /* attempt to write read-only register */
46   UNW_ESTOPUNWIND   = -6544, /* stop unwinding */
47   UNW_EINVALIDIP    = -6545, /* invalid IP */
48   UNW_EBADFRAME     = -6546, /* bad frame */
49   UNW_EINVAL        = -6547, /* unsupported operation or bad value */
50   UNW_EBADVERSION   = -6548, /* unwind info has unsupported version */
51   UNW_ENOINFO       = -6549  /* no unwind info found */
52 };
53 
54 struct unw_context_t {
55   uint64_t data[128];
56 };
57 typedef struct unw_context_t unw_context_t;
58 
59 struct unw_cursor_t {
60   uint64_t data[140];
61 };
62 typedef struct unw_cursor_t unw_cursor_t;
63 
64 typedef struct unw_addr_space *unw_addr_space_t;
65 
66 typedef int unw_regnum_t;
67 #if __arm__
68 typedef uint32_t unw_word_t;
69 #else
70 typedef uint64_t unw_word_t;
71 #endif
72 
73 #if __arm__
74 typedef uint64_t unw_fpreg_t;
75 #else
76 typedef double unw_fpreg_t;
77 #endif
78 
79 struct unw_proc_info_t {
80   unw_word_t  start_ip;         /* start address of function */
81   unw_word_t  end_ip;           /* address after end of function */
82   unw_word_t  lsda;             /* address of language specific data area, */
83                                 /*  or zero if not used */
84   unw_word_t  handler;          /* personality routine, or zero if not used */
85   unw_word_t  gp;               /* not used */
86   unw_word_t  flags;            /* not used */
87   uint32_t    format;           /* compact unwind encoding, or zero if none */
88   uint32_t    unwind_info_size; /* size of dwarf unwind info, or zero if none */
89   unw_word_t  unwind_info;      /* address of dwarf unwind info, or zero */
90   unw_word_t  extra;            /* mach_header of mach-o image containing func */
91 };
92 typedef struct unw_proc_info_t unw_proc_info_t;
93 
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97 
98 extern int unw_getcontext(unw_context_t *) LIBUNWIND_AVAIL;
99 extern int unw_init_local(unw_cursor_t *, unw_context_t *) LIBUNWIND_AVAIL;
100 extern int unw_step(unw_cursor_t *) LIBUNWIND_AVAIL;
101 extern int unw_get_reg(unw_cursor_t *, unw_regnum_t, unw_word_t *) LIBUNWIND_AVAIL;
102 extern int unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *) LIBUNWIND_AVAIL;
103 extern int unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t) LIBUNWIND_AVAIL;
104 extern int unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t)  LIBUNWIND_AVAIL;
105 extern int unw_resume(unw_cursor_t *) LIBUNWIND_AVAIL;
106 
107 #if __arm__
108 /* Save VFP registers in FSTMX format (instead of FSTMD). */
109 extern void unw_save_vfp_as_X(unw_cursor_t *) LIBUNWIND_AVAIL;
110 #endif
111 
112 
113 extern const char *unw_regname(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
114 extern int unw_get_proc_info(unw_cursor_t *, unw_proc_info_t *) LIBUNWIND_AVAIL;
115 extern int unw_is_fpreg(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
116 extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL;
117 extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL;
118 //extern int       unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);
119 
120 #if UNW_REMOTE
121 /*
122  * Mac OS X "remote" API for unwinding other processes on same machine
123  *
124  */
125 extern unw_addr_space_t unw_local_addr_space;
126 extern unw_addr_space_t unw_create_addr_space_for_task(task_t);
127 extern void unw_destroy_addr_space(unw_addr_space_t);
128 extern int unw_init_remote_thread(unw_cursor_t *, unw_addr_space_t, thread_t *);
129 #endif
130 
131 /*
132  * traditional libuwind "remote" API
133  *   NOT IMPLEMENTED on Mac OS X
134  *
135  * extern int               unw_init_remote(unw_cursor_t*, unw_addr_space_t,
136  *                                          thread_t*);
137  * extern unw_accessors_t   unw_get_accessors(unw_addr_space_t);
138  * extern unw_addr_space_t  unw_create_addr_space(unw_accessors_t, int);
139  * extern void              unw_flush_cache(unw_addr_space_t, unw_word_t,
140  *                                          unw_word_t);
141  * extern int               unw_set_caching_policy(unw_addr_space_t,
142  *                                                 unw_caching_policy_t);
143  * extern void              _U_dyn_register(unw_dyn_info_t*);
144  * extern void              _U_dyn_cancel(unw_dyn_info_t*);
145  */
146 
147 #ifdef __cplusplus
148 }
149 #endif
150 
151 // architecture independent register numbers
152 enum {
153   UNW_REG_IP = -1, // instruction pointer
154   UNW_REG_SP = -2, // stack pointer
155 };
156 
157 // 32-bit x86 registers
158 enum {
159   UNW_X86_EAX = 0,
160   UNW_X86_ECX = 1,
161   UNW_X86_EDX = 2,
162   UNW_X86_EBX = 3,
163   UNW_X86_EBP = 4,
164   UNW_X86_ESP = 5,
165   UNW_X86_ESI = 6,
166   UNW_X86_EDI = 7
167 };
168 
169 // 64-bit x86_64 registers
170 enum {
171   UNW_X86_64_RAX = 0,
172   UNW_X86_64_RDX = 1,
173   UNW_X86_64_RCX = 2,
174   UNW_X86_64_RBX = 3,
175   UNW_X86_64_RSI = 4,
176   UNW_X86_64_RDI = 5,
177   UNW_X86_64_RBP = 6,
178   UNW_X86_64_RSP = 7,
179   UNW_X86_64_R8  = 8,
180   UNW_X86_64_R9  = 9,
181   UNW_X86_64_R10 = 10,
182   UNW_X86_64_R11 = 11,
183   UNW_X86_64_R12 = 12,
184   UNW_X86_64_R13 = 13,
185   UNW_X86_64_R14 = 14,
186   UNW_X86_64_R15 = 15
187 };
188 
189 
190 // 32-bit ppc register numbers
191 enum {
192   UNW_PPC_R0  = 0,
193   UNW_PPC_R1  = 1,
194   UNW_PPC_R2  = 2,
195   UNW_PPC_R3  = 3,
196   UNW_PPC_R4  = 4,
197   UNW_PPC_R5  = 5,
198   UNW_PPC_R6  = 6,
199   UNW_PPC_R7  = 7,
200   UNW_PPC_R8  = 8,
201   UNW_PPC_R9  = 9,
202   UNW_PPC_R10 = 10,
203   UNW_PPC_R11 = 11,
204   UNW_PPC_R12 = 12,
205   UNW_PPC_R13 = 13,
206   UNW_PPC_R14 = 14,
207   UNW_PPC_R15 = 15,
208   UNW_PPC_R16 = 16,
209   UNW_PPC_R17 = 17,
210   UNW_PPC_R18 = 18,
211   UNW_PPC_R19 = 19,
212   UNW_PPC_R20 = 20,
213   UNW_PPC_R21 = 21,
214   UNW_PPC_R22 = 22,
215   UNW_PPC_R23 = 23,
216   UNW_PPC_R24 = 24,
217   UNW_PPC_R25 = 25,
218   UNW_PPC_R26 = 26,
219   UNW_PPC_R27 = 27,
220   UNW_PPC_R28 = 28,
221   UNW_PPC_R29 = 29,
222   UNW_PPC_R30 = 30,
223   UNW_PPC_R31 = 31,
224   UNW_PPC_F0  = 32,
225   UNW_PPC_F1  = 33,
226   UNW_PPC_F2  = 34,
227   UNW_PPC_F3  = 35,
228   UNW_PPC_F4  = 36,
229   UNW_PPC_F5  = 37,
230   UNW_PPC_F6  = 38,
231   UNW_PPC_F7  = 39,
232   UNW_PPC_F8  = 40,
233   UNW_PPC_F9  = 41,
234   UNW_PPC_F10 = 42,
235   UNW_PPC_F11 = 43,
236   UNW_PPC_F12 = 44,
237   UNW_PPC_F13 = 45,
238   UNW_PPC_F14 = 46,
239   UNW_PPC_F15 = 47,
240   UNW_PPC_F16 = 48,
241   UNW_PPC_F17 = 49,
242   UNW_PPC_F18 = 50,
243   UNW_PPC_F19 = 51,
244   UNW_PPC_F20 = 52,
245   UNW_PPC_F21 = 53,
246   UNW_PPC_F22 = 54,
247   UNW_PPC_F23 = 55,
248   UNW_PPC_F24 = 56,
249   UNW_PPC_F25 = 57,
250   UNW_PPC_F26 = 58,
251   UNW_PPC_F27 = 59,
252   UNW_PPC_F28 = 60,
253   UNW_PPC_F29 = 61,
254   UNW_PPC_F30 = 62,
255   UNW_PPC_F31 = 63,
256   UNW_PPC_MQ  = 64,
257   UNW_PPC_LR  = 65,
258   UNW_PPC_CTR = 66,
259   UNW_PPC_AP  = 67,
260   UNW_PPC_CR0 = 68,
261   UNW_PPC_CR1 = 69,
262   UNW_PPC_CR2 = 70,
263   UNW_PPC_CR3 = 71,
264   UNW_PPC_CR4 = 72,
265   UNW_PPC_CR5 = 73,
266   UNW_PPC_CR6 = 74,
267   UNW_PPC_CR7 = 75,
268   UNW_PPC_XER = 76,
269   UNW_PPC_V0  = 77,
270   UNW_PPC_V1  = 78,
271   UNW_PPC_V2  = 79,
272   UNW_PPC_V3  = 80,
273   UNW_PPC_V4  = 81,
274   UNW_PPC_V5  = 82,
275   UNW_PPC_V6  = 83,
276   UNW_PPC_V7  = 84,
277   UNW_PPC_V8  = 85,
278   UNW_PPC_V9  = 86,
279   UNW_PPC_V10 = 87,
280   UNW_PPC_V11 = 88,
281   UNW_PPC_V12 = 89,
282   UNW_PPC_V13 = 90,
283   UNW_PPC_V14 = 91,
284   UNW_PPC_V15 = 92,
285   UNW_PPC_V16 = 93,
286   UNW_PPC_V17 = 94,
287   UNW_PPC_V18 = 95,
288   UNW_PPC_V19 = 96,
289   UNW_PPC_V20 = 97,
290   UNW_PPC_V21 = 98,
291   UNW_PPC_V22 = 99,
292   UNW_PPC_V23 = 100,
293   UNW_PPC_V24 = 101,
294   UNW_PPC_V25 = 102,
295   UNW_PPC_V26 = 103,
296   UNW_PPC_V27 = 104,
297   UNW_PPC_V28 = 105,
298   UNW_PPC_V29 = 106,
299   UNW_PPC_V30 = 107,
300   UNW_PPC_V31 = 108,
301   UNW_PPC_VRSAVE  = 109,
302   UNW_PPC_VSCR    = 110,
303   UNW_PPC_SPE_ACC = 111,
304   UNW_PPC_SPEFSCR = 112
305 };
306 
307 // 64-bit ARM64 registers
308 enum {
309   UNW_ARM64_X0  = 0,
310   UNW_ARM64_X1  = 1,
311   UNW_ARM64_X2  = 2,
312   UNW_ARM64_X3  = 3,
313   UNW_ARM64_X4  = 4,
314   UNW_ARM64_X5  = 5,
315   UNW_ARM64_X6  = 6,
316   UNW_ARM64_X7  = 7,
317   UNW_ARM64_X8  = 8,
318   UNW_ARM64_X9  = 9,
319   UNW_ARM64_X10 = 10,
320   UNW_ARM64_X11 = 11,
321   UNW_ARM64_X12 = 12,
322   UNW_ARM64_X13 = 13,
323   UNW_ARM64_X14 = 14,
324   UNW_ARM64_X15 = 15,
325   UNW_ARM64_X16 = 16,
326   UNW_ARM64_X17 = 17,
327   UNW_ARM64_X18 = 18,
328   UNW_ARM64_X19 = 19,
329   UNW_ARM64_X20 = 20,
330   UNW_ARM64_X21 = 21,
331   UNW_ARM64_X22 = 22,
332   UNW_ARM64_X23 = 23,
333   UNW_ARM64_X24 = 24,
334   UNW_ARM64_X25 = 25,
335   UNW_ARM64_X26 = 26,
336   UNW_ARM64_X27 = 27,
337   UNW_ARM64_X28 = 28,
338   UNW_ARM64_X29 = 29,
339   UNW_ARM64_FP  = 29,
340   UNW_ARM64_X30 = 30,
341   UNW_ARM64_LR  = 30,
342   UNW_ARM64_X31 = 31,
343   UNW_ARM64_SP  = 31,
344   // reserved block
345   UNW_ARM64_D0  = 64,
346   UNW_ARM64_D1  = 65,
347   UNW_ARM64_D2  = 66,
348   UNW_ARM64_D3  = 67,
349   UNW_ARM64_D4  = 68,
350   UNW_ARM64_D5  = 69,
351   UNW_ARM64_D6  = 70,
352   UNW_ARM64_D7  = 71,
353   UNW_ARM64_D8  = 72,
354   UNW_ARM64_D9  = 73,
355   UNW_ARM64_D10 = 74,
356   UNW_ARM64_D11 = 75,
357   UNW_ARM64_D12 = 76,
358   UNW_ARM64_D13 = 77,
359   UNW_ARM64_D14 = 78,
360   UNW_ARM64_D15 = 79,
361   UNW_ARM64_D16 = 80,
362   UNW_ARM64_D17 = 81,
363   UNW_ARM64_D18 = 82,
364   UNW_ARM64_D19 = 83,
365   UNW_ARM64_D20 = 84,
366   UNW_ARM64_D21 = 85,
367   UNW_ARM64_D22 = 86,
368   UNW_ARM64_D23 = 87,
369   UNW_ARM64_D24 = 88,
370   UNW_ARM64_D25 = 89,
371   UNW_ARM64_D26 = 90,
372   UNW_ARM64_D27 = 91,
373   UNW_ARM64_D28 = 92,
374   UNW_ARM64_D29 = 93,
375   UNW_ARM64_D30 = 94,
376   UNW_ARM64_D31 = 95,
377 };
378 
379 // 32-bit ARM registers. Numbers match DWARF for ARM spec #3.1 Table 1.
380 // Naming scheme uses recommendations given in Note 4 for VFP-v2 and VFP-v3.
381 // In this scheme, even though the 64-bit floating point registers D0-D31
382 // overlap physically with the 32-bit floating pointer registers S0-S31,
383 // they are given a non-overlapping range of register numbers.
384 //
385 // Commented out ranges are not preserved during unwinding.
386 enum {
387   UNW_ARM_R0  = 0,
388   UNW_ARM_R1  = 1,
389   UNW_ARM_R2  = 2,
390   UNW_ARM_R3  = 3,
391   UNW_ARM_R4  = 4,
392   UNW_ARM_R5  = 5,
393   UNW_ARM_R6  = 6,
394   UNW_ARM_R7  = 7,
395   UNW_ARM_R8  = 8,
396   UNW_ARM_R9  = 9,
397   UNW_ARM_R10 = 10,
398   UNW_ARM_R11 = 11,
399   UNW_ARM_R12 = 12,
400   UNW_ARM_SP  = 13,  // Logical alias for UNW_REG_SP
401   UNW_ARM_R13 = 13,
402   UNW_ARM_LR  = 14,
403   UNW_ARM_R14 = 14,
404   UNW_ARM_IP  = 15,  // Logical alias for UNW_REG_IP
405   UNW_ARM_R15 = 15,
406   // 16-63 -- OBSOLETE. Used in VFP1 to represent both S0-S31 and D0-D31.
407   UNW_ARM_S0  = 64,
408   UNW_ARM_S1  = 65,
409   UNW_ARM_S2  = 66,
410   UNW_ARM_S3  = 67,
411   UNW_ARM_S4  = 68,
412   UNW_ARM_S5  = 69,
413   UNW_ARM_S6  = 70,
414   UNW_ARM_S7  = 71,
415   UNW_ARM_S8  = 72,
416   UNW_ARM_S9  = 73,
417   UNW_ARM_S10 = 74,
418   UNW_ARM_S11 = 75,
419   UNW_ARM_S12 = 76,
420   UNW_ARM_S13 = 77,
421   UNW_ARM_S14 = 78,
422   UNW_ARM_S15 = 79,
423   UNW_ARM_S16 = 80,
424   UNW_ARM_S17 = 81,
425   UNW_ARM_S18 = 82,
426   UNW_ARM_S19 = 83,
427   UNW_ARM_S20 = 84,
428   UNW_ARM_S21 = 85,
429   UNW_ARM_S22 = 86,
430   UNW_ARM_S23 = 87,
431   UNW_ARM_S24 = 88,
432   UNW_ARM_S25 = 89,
433   UNW_ARM_S26 = 90,
434   UNW_ARM_S27 = 91,
435   UNW_ARM_S28 = 92,
436   UNW_ARM_S29 = 93,
437   UNW_ARM_S30 = 94,
438   UNW_ARM_S31 = 95,
439   //  96-103 -- OBSOLETE. F0-F7. Used by the FPA system. Superseded by VFP.
440   // 104-111 -- wCGR0-wCGR7, ACC0-ACC7 (Intel wireless MMX)
441   UNW_ARM_WR0 = 112,
442   UNW_ARM_WR1 = 113,
443   UNW_ARM_WR2 = 114,
444   UNW_ARM_WR3 = 115,
445   UNW_ARM_WR4 = 116,
446   UNW_ARM_WR5 = 117,
447   UNW_ARM_WR6 = 118,
448   UNW_ARM_WR7 = 119,
449   UNW_ARM_WR8 = 120,
450   UNW_ARM_WR9 = 121,
451   UNW_ARM_WR10 = 122,
452   UNW_ARM_WR11 = 123,
453   UNW_ARM_WR12 = 124,
454   UNW_ARM_WR13 = 125,
455   UNW_ARM_WR14 = 126,
456   UNW_ARM_WR15 = 127,
457   // 128-133 -- SPSR, SPSR_{FIQ|IRQ|ABT|UND|SVC}
458   // 134-143 -- Reserved
459   // 144-150 -- R8_USR–R14_USR
460   // 151-157 -- R8_FIQ–R14_FIQ
461   // 158-159 -- R13_IRQ–R14_IRQ
462   // 160-161 -- R13_ABT–R14_ABT
463   // 162-163 -- R13_UND–R14_UND
464   // 164-165 -- R13_SVC–R14_SVC
465   // 166-191 -- Reserved
466   UNW_ARM_WC0 = 192,
467   UNW_ARM_WC1 = 193,
468   UNW_ARM_WC2 = 194,
469   UNW_ARM_WC3 = 195,
470   // 196-199 -- wC4-wC7 (Intel wireless MMX control)
471   // 200-255 -- Reserved
472   UNW_ARM_D0  = 256,
473   UNW_ARM_D1  = 257,
474   UNW_ARM_D2  = 258,
475   UNW_ARM_D3  = 259,
476   UNW_ARM_D4  = 260,
477   UNW_ARM_D5  = 261,
478   UNW_ARM_D6  = 262,
479   UNW_ARM_D7  = 263,
480   UNW_ARM_D8  = 264,
481   UNW_ARM_D9  = 265,
482   UNW_ARM_D10 = 266,
483   UNW_ARM_D11 = 267,
484   UNW_ARM_D12 = 268,
485   UNW_ARM_D13 = 269,
486   UNW_ARM_D14 = 270,
487   UNW_ARM_D15 = 271,
488   UNW_ARM_D16 = 272,
489   UNW_ARM_D17 = 273,
490   UNW_ARM_D18 = 274,
491   UNW_ARM_D19 = 275,
492   UNW_ARM_D20 = 276,
493   UNW_ARM_D21 = 277,
494   UNW_ARM_D22 = 278,
495   UNW_ARM_D23 = 279,
496   UNW_ARM_D24 = 280,
497   UNW_ARM_D25 = 281,
498   UNW_ARM_D26 = 282,
499   UNW_ARM_D27 = 283,
500   UNW_ARM_D28 = 284,
501   UNW_ARM_D29 = 285,
502   UNW_ARM_D30 = 286,
503   UNW_ARM_D31 = 287,
504   // 288-319 -- Reserved for VFP/Neon
505   // 320-8191 -- Reserved
506   // 8192-16383 -- Unspecified vendor co-processor register.
507 };
508 
509 #endif
510