2011-12-08 13:01:39 +08:00
|
|
|
/*===---- unwind.h - Stack unwinding ----------------------------------------===
|
|
|
|
*
|
2019-04-09 04:51:30 +08:00
|
|
|
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
* See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-12-08 13:01:39 +08:00
|
|
|
*
|
|
|
|
*===-----------------------------------------------------------------------===
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* See "Data Definitions for libgcc_s" in the Linux Standard Base.*/
|
|
|
|
|
2013-01-10 03:54:57 +08:00
|
|
|
#ifndef __CLANG_UNWIND_H
|
|
|
|
#define __CLANG_UNWIND_H
|
|
|
|
|
2014-12-29 21:29:38 +08:00
|
|
|
#if defined(__APPLE__) && __has_include_next(<unwind.h>)
|
|
|
|
/* Darwin (from 11.x on) provide an unwind.h. If that's available,
|
2013-08-29 07:16:49 +08:00
|
|
|
* use it. libunwind wraps some of its definitions in #ifdef _GNU_SOURCE,
|
2012-02-22 00:20:12 +08:00
|
|
|
* so define that around the include.*/
|
|
|
|
# ifndef _GNU_SOURCE
|
|
|
|
# define _SHOULD_UNDEFINE_GNU_SOURCE
|
|
|
|
# define _GNU_SOURCE
|
|
|
|
# endif
|
2012-03-29 11:37:17 +08:00
|
|
|
// libunwind's unwind.h reflects the current visibility. However, Mozilla
|
|
|
|
// builds with -fvisibility=hidden and relies on gcc's unwind.h to reset the
|
|
|
|
// visibility to default and export its contents. gcc also allows users to
|
|
|
|
// override its override by #defining HIDE_EXPORTS (but note, this only obeys
|
|
|
|
// the user's -fvisibility setting; it doesn't hide any exports on its own). We
|
|
|
|
// imitate gcc's header here:
|
|
|
|
# ifdef HIDE_EXPORTS
|
|
|
|
# include_next <unwind.h>
|
|
|
|
# else
|
|
|
|
# pragma GCC visibility push(default)
|
|
|
|
# include_next <unwind.h>
|
|
|
|
# pragma GCC visibility pop
|
|
|
|
# endif
|
2012-02-22 00:20:12 +08:00
|
|
|
# ifdef _SHOULD_UNDEFINE_GNU_SOURCE
|
|
|
|
# undef _GNU_SOURCE
|
|
|
|
# undef _SHOULD_UNDEFINE_GNU_SOURCE
|
|
|
|
# endif
|
2011-12-08 13:01:39 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2011-12-09 08:08:01 +08:00
|
|
|
/* It is a bit strange for a header to play with the visibility of the
|
|
|
|
symbols it declares, but this matches gcc's behavior and some programs
|
|
|
|
depend on it */
|
2013-01-10 03:54:57 +08:00
|
|
|
#ifndef HIDE_EXPORTS
|
2011-12-09 08:08:01 +08:00
|
|
|
#pragma GCC visibility push(default)
|
2013-01-10 03:54:57 +08:00
|
|
|
#endif
|
2011-12-09 08:08:01 +08:00
|
|
|
|
2019-02-14 02:27:09 +08:00
|
|
|
typedef uintptr_t _Unwind_Word __attribute__((__mode__(__unwind_word__)));
|
|
|
|
typedef intptr_t _Unwind_Sword __attribute__((__mode__(__unwind_word__)));
|
2013-08-29 07:16:49 +08:00
|
|
|
typedef uintptr_t _Unwind_Ptr;
|
|
|
|
typedef uintptr_t _Unwind_Internal_Ptr;
|
|
|
|
typedef uint64_t _Unwind_Exception_Class;
|
|
|
|
|
2013-08-29 09:56:22 +08:00
|
|
|
typedef intptr_t _sleb128_t;
|
|
|
|
typedef uintptr_t _uleb128_t;
|
|
|
|
|
2011-12-08 13:01:39 +08:00
|
|
|
struct _Unwind_Context;
|
2017-10-19 15:40:45 +08:00
|
|
|
#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__))
|
2017-07-27 06:55:23 +08:00
|
|
|
struct _Unwind_Control_Block;
|
|
|
|
typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
|
|
|
|
#else
|
2013-08-29 07:16:49 +08:00
|
|
|
struct _Unwind_Exception;
|
2017-07-27 06:55:23 +08:00
|
|
|
typedef struct _Unwind_Exception _Unwind_Exception;
|
|
|
|
#endif
|
2011-12-08 13:01:39 +08:00
|
|
|
typedef enum {
|
|
|
|
_URC_NO_REASON = 0,
|
2016-02-28 23:01:42 +08:00
|
|
|
#if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
|
|
|
|
!defined(__ARM_DWARF_EH__)
|
|
|
|
_URC_OK = 0, /* used by ARM EHABI */
|
|
|
|
#endif
|
2011-12-08 13:01:39 +08:00
|
|
|
_URC_FOREIGN_EXCEPTION_CAUGHT = 1,
|
|
|
|
|
|
|
|
_URC_FATAL_PHASE2_ERROR = 2,
|
|
|
|
_URC_FATAL_PHASE1_ERROR = 3,
|
|
|
|
_URC_NORMAL_STOP = 4,
|
|
|
|
|
|
|
|
_URC_END_OF_STACK = 5,
|
|
|
|
_URC_HANDLER_FOUND = 6,
|
|
|
|
_URC_INSTALL_CONTEXT = 7,
|
2016-02-28 23:01:42 +08:00
|
|
|
_URC_CONTINUE_UNWIND = 8,
|
|
|
|
#if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
|
|
|
|
!defined(__ARM_DWARF_EH__)
|
|
|
|
_URC_FAILURE = 9 /* used by ARM EHABI */
|
|
|
|
#endif
|
2011-12-08 13:01:39 +08:00
|
|
|
} _Unwind_Reason_Code;
|
|
|
|
|
2013-08-29 07:16:49 +08:00
|
|
|
typedef enum {
|
|
|
|
_UA_SEARCH_PHASE = 1,
|
|
|
|
_UA_CLEANUP_PHASE = 2,
|
|
|
|
|
|
|
|
_UA_HANDLER_FRAME = 4,
|
|
|
|
_UA_FORCE_UNWIND = 8,
|
|
|
|
_UA_END_OF_STACK = 16 /* gcc extension to C++ ABI */
|
|
|
|
} _Unwind_Action;
|
|
|
|
|
|
|
|
typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code,
|
2017-07-27 06:55:23 +08:00
|
|
|
_Unwind_Exception *);
|
|
|
|
|
2017-10-19 15:40:45 +08:00
|
|
|
#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__))
|
2017-07-27 06:55:23 +08:00
|
|
|
typedef struct _Unwind_Control_Block _Unwind_Control_Block;
|
|
|
|
typedef uint32_t _Unwind_EHT_Header;
|
|
|
|
|
|
|
|
struct _Unwind_Control_Block {
|
|
|
|
uint64_t exception_class;
|
|
|
|
void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Control_Block *);
|
|
|
|
/* unwinder cache (private fields for the unwinder's use) */
|
|
|
|
struct {
|
|
|
|
uint32_t reserved1; /* forced unwind stop function, 0 if not forced */
|
|
|
|
uint32_t reserved2; /* personality routine */
|
|
|
|
uint32_t reserved3; /* callsite */
|
|
|
|
uint32_t reserved4; /* forced unwind stop argument */
|
|
|
|
uint32_t reserved5;
|
|
|
|
} unwinder_cache;
|
|
|
|
/* propagation barrier cache (valid after phase 1) */
|
|
|
|
struct {
|
|
|
|
uint32_t sp;
|
|
|
|
uint32_t bitpattern[5];
|
|
|
|
} barrier_cache;
|
|
|
|
/* cleanup cache (preserved over cleanup) */
|
|
|
|
struct {
|
|
|
|
uint32_t bitpattern[4];
|
|
|
|
} cleanup_cache;
|
|
|
|
/* personality cache (for personality's benefit) */
|
|
|
|
struct {
|
|
|
|
uint32_t fnstart; /* function start address */
|
|
|
|
_Unwind_EHT_Header *ehtp; /* pointer to EHT entry header word */
|
|
|
|
uint32_t additional; /* additional data */
|
|
|
|
uint32_t reserved1;
|
|
|
|
} pr_cache;
|
|
|
|
long long int : 0; /* force alignment of next item to 8-byte boundary */
|
2017-08-24 00:57:55 +08:00
|
|
|
} __attribute__((__aligned__(8)));
|
2017-07-27 06:55:23 +08:00
|
|
|
#else
|
2013-08-29 07:16:49 +08:00
|
|
|
struct _Unwind_Exception {
|
|
|
|
_Unwind_Exception_Class exception_class;
|
|
|
|
_Unwind_Exception_Cleanup_Fn exception_cleanup;
|
2018-08-08 04:02:40 +08:00
|
|
|
#if !defined (__USING_SJLJ_EXCEPTIONS__) && defined (__SEH__)
|
|
|
|
_Unwind_Word private_[6];
|
|
|
|
#else
|
2013-08-29 07:16:49 +08:00
|
|
|
_Unwind_Word private_1;
|
|
|
|
_Unwind_Word private_2;
|
2018-08-08 04:02:40 +08:00
|
|
|
#endif
|
2013-08-29 07:16:49 +08:00
|
|
|
/* The Itanium ABI requires that _Unwind_Exception objects are "double-word
|
|
|
|
* aligned". GCC has interpreted this to mean "use the maximum useful
|
|
|
|
* alignment for the target"; so do we. */
|
|
|
|
} __attribute__((__aligned__));
|
2017-07-27 06:55:23 +08:00
|
|
|
#endif
|
2013-08-29 07:16:49 +08:00
|
|
|
|
|
|
|
typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)(int, _Unwind_Action,
|
|
|
|
_Unwind_Exception_Class,
|
2017-07-27 06:55:23 +08:00
|
|
|
_Unwind_Exception *,
|
2013-08-29 07:16:49 +08:00
|
|
|
struct _Unwind_Context *,
|
|
|
|
void *);
|
|
|
|
|
2017-07-27 06:55:23 +08:00
|
|
|
typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(int, _Unwind_Action,
|
|
|
|
_Unwind_Exception_Class,
|
|
|
|
_Unwind_Exception *,
|
|
|
|
struct _Unwind_Context *);
|
2013-08-29 07:16:49 +08:00
|
|
|
typedef _Unwind_Personality_Fn __personality_routine;
|
|
|
|
|
2013-08-29 07:32:22 +08:00
|
|
|
typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,
|
|
|
|
void *);
|
2012-01-19 19:39:05 +08:00
|
|
|
|
2017-10-19 15:40:45 +08:00
|
|
|
#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__))
|
2012-11-14 14:33:58 +08:00
|
|
|
typedef enum {
|
|
|
|
_UVRSC_CORE = 0, /* integer register */
|
|
|
|
_UVRSC_VFP = 1, /* vfp */
|
|
|
|
_UVRSC_WMMXD = 3, /* Intel WMMX data register */
|
|
|
|
_UVRSC_WMMXC = 4 /* Intel WMMX control register */
|
|
|
|
} _Unwind_VRS_RegClass;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
_UVRSD_UINT32 = 0,
|
|
|
|
_UVRSD_VFPX = 1,
|
|
|
|
_UVRSD_UINT64 = 3,
|
|
|
|
_UVRSD_FLOAT = 4,
|
|
|
|
_UVRSD_DOUBLE = 5
|
|
|
|
} _Unwind_VRS_DataRepresentation;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
_UVRSR_OK = 0,
|
|
|
|
_UVRSR_NOT_IMPLEMENTED = 1,
|
|
|
|
_UVRSR_FAILED = 2
|
|
|
|
} _Unwind_VRS_Result;
|
2012-01-19 19:39:05 +08:00
|
|
|
|
2016-02-28 23:01:42 +08:00
|
|
|
typedef uint32_t _Unwind_State;
|
|
|
|
#define _US_VIRTUAL_UNWIND_FRAME ((_Unwind_State)0)
|
|
|
|
#define _US_UNWIND_FRAME_STARTING ((_Unwind_State)1)
|
|
|
|
#define _US_UNWIND_FRAME_RESUME ((_Unwind_State)2)
|
|
|
|
#define _US_ACTION_MASK ((_Unwind_State)3)
|
|
|
|
#define _US_FORCE_UNWIND ((_Unwind_State)8)
|
|
|
|
|
2013-01-17 07:08:36 +08:00
|
|
|
_Unwind_VRS_Result _Unwind_VRS_Get(struct _Unwind_Context *__context,
|
|
|
|
_Unwind_VRS_RegClass __regclass,
|
|
|
|
uint32_t __regno,
|
|
|
|
_Unwind_VRS_DataRepresentation __representation,
|
|
|
|
void *__valuep);
|
2012-01-19 19:39:05 +08:00
|
|
|
|
2013-09-26 06:34:03 +08:00
|
|
|
_Unwind_VRS_Result _Unwind_VRS_Set(struct _Unwind_Context *__context,
|
|
|
|
_Unwind_VRS_RegClass __regclass,
|
|
|
|
uint32_t __regno,
|
|
|
|
_Unwind_VRS_DataRepresentation __representation,
|
|
|
|
void *__valuep);
|
2013-08-29 07:16:49 +08:00
|
|
|
|
2013-09-26 06:34:03 +08:00
|
|
|
static __inline__
|
|
|
|
_Unwind_Word _Unwind_GetGR(struct _Unwind_Context *__context, int __index) {
|
|
|
|
_Unwind_Word __value;
|
|
|
|
_Unwind_VRS_Get(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value);
|
|
|
|
return __value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__
|
|
|
|
void _Unwind_SetGR(struct _Unwind_Context *__context, int __index,
|
|
|
|
_Unwind_Word __value) {
|
|
|
|
_Unwind_VRS_Set(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__
|
|
|
|
_Unwind_Word _Unwind_GetIP(struct _Unwind_Context *__context) {
|
|
|
|
_Unwind_Word __ip = _Unwind_GetGR(__context, 15);
|
|
|
|
return __ip & ~(_Unwind_Word)(0x1); /* Remove thumb mode bit. */
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__
|
|
|
|
void _Unwind_SetIP(struct _Unwind_Context *__context, _Unwind_Word __value) {
|
|
|
|
_Unwind_Word __thumb_mode_bit = _Unwind_GetGR(__context, 15) & 0x1;
|
|
|
|
_Unwind_SetGR(__context, 15, __value | __thumb_mode_bit);
|
|
|
|
}
|
|
|
|
#else
|
2013-08-29 07:16:49 +08:00
|
|
|
_Unwind_Word _Unwind_GetGR(struct _Unwind_Context *, int);
|
|
|
|
void _Unwind_SetGR(struct _Unwind_Context *, int, _Unwind_Word);
|
|
|
|
|
|
|
|
_Unwind_Word _Unwind_GetIP(struct _Unwind_Context *);
|
|
|
|
void _Unwind_SetIP(struct _Unwind_Context *, _Unwind_Word);
|
2013-09-26 06:34:03 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
_Unwind_Word _Unwind_GetIPInfo(struct _Unwind_Context *, int *);
|
2013-08-29 07:16:49 +08:00
|
|
|
|
|
|
|
_Unwind_Word _Unwind_GetCFA(struct _Unwind_Context *);
|
|
|
|
|
2014-12-29 21:29:36 +08:00
|
|
|
_Unwind_Word _Unwind_GetBSP(struct _Unwind_Context *);
|
|
|
|
|
2013-08-29 07:16:49 +08:00
|
|
|
void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context *);
|
|
|
|
|
|
|
|
_Unwind_Ptr _Unwind_GetRegionStart(struct _Unwind_Context *);
|
|
|
|
|
|
|
|
/* DWARF EH functions; currently not available on Darwin/ARM */
|
|
|
|
#if !defined(__APPLE__) || !defined(__arm__)
|
2017-07-27 06:55:23 +08:00
|
|
|
_Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Exception *);
|
|
|
|
_Unwind_Reason_Code _Unwind_ForcedUnwind(_Unwind_Exception *, _Unwind_Stop_Fn,
|
|
|
|
void *);
|
|
|
|
void _Unwind_DeleteException(_Unwind_Exception *);
|
|
|
|
void _Unwind_Resume(_Unwind_Exception *);
|
|
|
|
_Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *);
|
2013-08-29 07:16:49 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);
|
|
|
|
|
|
|
|
/* setjmp(3)/longjmp(3) stuff */
|
|
|
|
typedef struct SjLj_Function_Context *_Unwind_FunctionContext_t;
|
|
|
|
|
|
|
|
void _Unwind_SjLj_Register(_Unwind_FunctionContext_t);
|
|
|
|
void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t);
|
2017-07-27 06:55:23 +08:00
|
|
|
_Unwind_Reason_Code _Unwind_SjLj_RaiseException(_Unwind_Exception *);
|
|
|
|
_Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind(_Unwind_Exception *,
|
2013-08-29 07:32:22 +08:00
|
|
|
_Unwind_Stop_Fn, void *);
|
2017-07-27 06:55:23 +08:00
|
|
|
void _Unwind_SjLj_Resume(_Unwind_Exception *);
|
|
|
|
_Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow(_Unwind_Exception *);
|
2013-08-29 07:16:49 +08:00
|
|
|
|
|
|
|
void *_Unwind_FindEnclosingFunction(void *);
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
2013-08-29 07:32:22 +08:00
|
|
|
_Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *)
|
2015-02-04 08:26:10 +08:00
|
|
|
__attribute__((__unavailable__));
|
2013-08-29 07:32:22 +08:00
|
|
|
_Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *)
|
2015-02-04 08:26:10 +08:00
|
|
|
__attribute__((__unavailable__));
|
2013-08-29 07:16:49 +08:00
|
|
|
|
|
|
|
/* Darwin-specific functions */
|
|
|
|
void __register_frame(const void *);
|
|
|
|
void __deregister_frame(const void *);
|
|
|
|
|
|
|
|
struct dwarf_eh_bases {
|
|
|
|
uintptr_t tbase;
|
|
|
|
uintptr_t dbase;
|
|
|
|
uintptr_t func;
|
|
|
|
};
|
|
|
|
void *_Unwind_Find_FDE(const void *, struct dwarf_eh_bases *);
|
|
|
|
|
|
|
|
void __register_frame_info_bases(const void *, void *, void *, void *)
|
2015-02-04 08:26:10 +08:00
|
|
|
__attribute__((__unavailable__));
|
|
|
|
void __register_frame_info(const void *, void *) __attribute__((__unavailable__));
|
2013-08-29 07:16:49 +08:00
|
|
|
void __register_frame_info_table_bases(const void *, void*, void *, void *)
|
2015-02-04 08:26:10 +08:00
|
|
|
__attribute__((__unavailable__));
|
2013-08-29 07:32:22 +08:00
|
|
|
void __register_frame_info_table(const void *, void *)
|
2015-02-04 08:26:10 +08:00
|
|
|
__attribute__((__unavailable__));
|
|
|
|
void __register_frame_table(const void *) __attribute__((__unavailable__));
|
|
|
|
void __deregister_frame_info(const void *) __attribute__((__unavailable__));
|
|
|
|
void __deregister_frame_info_bases(const void *)__attribute__((__unavailable__));
|
2013-08-29 07:16:49 +08:00
|
|
|
|
2012-01-19 19:39:05 +08:00
|
|
|
#else
|
|
|
|
|
2013-08-29 07:16:49 +08:00
|
|
|
_Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *);
|
|
|
|
_Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *);
|
2012-01-19 19:39:05 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-12-08 13:01:39 +08:00
|
|
|
|
2013-01-10 03:54:57 +08:00
|
|
|
#ifndef HIDE_EXPORTS
|
2011-12-09 08:08:01 +08:00
|
|
|
#pragma GCC visibility pop
|
2013-01-10 03:54:57 +08:00
|
|
|
#endif
|
2011-12-09 08:08:01 +08:00
|
|
|
|
2011-12-08 13:01:39 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2013-01-10 03:54:57 +08:00
|
|
|
|
|
|
|
#endif /* __CLANG_UNWIND_H */
|