Implement ARM EH support, fix objc_msgSend() to work on ARM.

This commit is contained in:
theraven 2011-11-09 21:03:35 +00:00
parent 2a3a93ec38
commit 9490b1b84e
8 changed files with 489 additions and 197 deletions

View File

@ -34,7 +34,7 @@ LIBOBJC = libobjc
LIBOBJCLIBNAME = objc
LIBOBJCXX = libobjcxx
LIBRARY_NAME = ${LIBOBJC} ${LIBOBJCXX}
LIBRARY_NAME = ${LIBOBJC}
${LIBOBJC}_OBJC_FILES = \
NSBlocks.m\

View File

@ -6,6 +6,8 @@
#include <class.h>
#include <stdarg.h>
//#define assert(x) if (!(x)) { printf("Failed %d\n", __LINE__); }
id objc_msgSend(id, SEL, ...);
typedef struct { int a,b,c,d,e; } s;
@ -48,6 +50,7 @@ Class TestCls;
vasprintf(&s, str, ap);
va_end(ap);
//fprintf(stderr, "String: '%s'\n", s);
assert(strcmp(s, "Format string 42 42.000000\n") ==0);
}
+ (void)initialize
@ -68,7 +71,7 @@ int main(void)
assert((TestCls == e) && "Exceptions propagate out of +initialize");
exceptionThrown = 1;
}
assert(exceptionThrown);
assert(exceptionThrown && "An exception was thrown");
assert((id)0x42 == objc_msgSend(TestCls, @selector(foo)));
objc_msgSend(TestCls, @selector(nothing));
objc_msgSend(TestCls, @selector(missing));

View File

@ -48,6 +48,68 @@ typedef enum
handler_class
} handler_type;
/**
* Saves the result of the landing pad that we have found. For ARM, this is
* stored in the generic unwind structure, while on other platforms it is
* stored in the Objective-C exception.
*/
static void saveLandingPad(struct _Unwind_Context *context,
struct _Unwind_Exception *ucb,
struct objc_exception *ex,
int selector,
dw_eh_ptr_t landingPad)
{
#ifdef __arm__
// On ARM, we store the saved exception in the generic part of the structure
ucb->barrier_cache.sp = _Unwind_GetGR(context, 13);
ucb->barrier_cache.bitpattern[1] = (uint32_t)selector;
ucb->barrier_cache.bitpattern[3] = (uint32_t)landingPad;
#else
// Cache the results for the phase 2 unwind, if we found a handler
// and this is not a foreign exception. We can't cache foreign exceptions
// because we don't know their structure (although we could cache C++
// exceptions...)
if (ex)
{
ex->handlerSwitchValue = selector;
ex->landingPad = landingPad;
}
#endif
}
/**
* Loads the saved landing pad. Returns 1 on success, 0 on failure.
*/
static int loadLandingPad(struct _Unwind_Context *context,
struct _Unwind_Exception *ucb,
struct objc_exception *ex,
unsigned long *selector,
dw_eh_ptr_t *landingPad)
{
#ifdef __arm__
*selector = ucb->barrier_cache.bitpattern[1];
*landingPad = (dw_eh_ptr_t)ucb->barrier_cache.bitpattern[3];
return 1;
#else
if (ex)
{
*selector = ex->handlerSwitchValue;
*landingPad = ex->landingPad;
return 0;
}
return 0;
#endif
}
static inline _Unwind_Reason_Code continueUnwinding(struct _Unwind_Exception *ex,
struct _Unwind_Context *context)
{
#ifdef __arm__
if (__gnu_unwind_frame(ex, context) != _URC_OK) { return _URC_FAILURE; }
#endif
return _URC_CONTINUE_UNWIND;
}
static void cleanup(_Unwind_Reason_Code reason, struct _Unwind_Exception *e)
{
/*
@ -92,6 +154,7 @@ void objc_exception_throw(id object)
{
_objc_unexpected_exception(object);
}
fprintf(stderr, "Throw returned %d\n",(int) err);
abort();
}
@ -199,15 +262,33 @@ static handler_type check_action_record(struct _Unwind_Context *context,
return handler_none;
}
_Unwind_Reason_Code
__gnu_objc_personality_v01(_Unwind_State state,
struct _Unwind_Exception *ue_header,
struct _Unwind_Context *context)
{
fprintf(stderr, "LSDA: %p\n", (void*)_Unwind_GetLanguageSpecificData(context));
unsigned char *lsda_addr = (void*)_Unwind_GetLanguageSpecificData(context);
fprintf(stderr, "Encoding: %x\n", (int)*lsda_addr);
return 0;
}
typedef uint32_t _uw;
/**
* The Objective-C exception personality function.
*/
_Unwind_Reason_Code __gnu_objc_personality_v0(int version,
_Unwind_Action actions,
uint64_t exceptionClass,
struct _Unwind_Exception *exceptionObject,
struct _Unwind_Context *context)
{
BEGIN_PERSONALITY_FUNCTION(__gnu_objc_personality_v0)
fprintf(stderr, "Personality function called\n");
_uw *ptr = (_uw *) exceptionObject->pr_cache.ehtp;
/* Skip the personality routine address. */
ptr++;
/* Skip the unwind opcodes. */
ptr += (((*ptr) >> 24) & 0xff) + 1;
fprintf(stderr, "Maybe this is the LSDA? 0x%x\n", ptr);
// This personality function is for version 1 of the ABI. If you use it
// with a future version of the ABI, it won't know what to do, so it
// reports a fatal error and give up before it breaks anything.
@ -216,8 +297,9 @@ _Unwind_Reason_Code __gnu_objc_personality_v0(int version,
return _URC_FATAL_PHASE1_ERROR;
}
struct objc_exception *ex = 0;
//char *cls = (char*)&exceptionClass;
#ifndef fprintf
char *cls = (char*)&exceptionClass;
#endif
fprintf(stderr, "Class: %c%c%c%c%c%c%c%c\n", cls[7], cls[6], cls[5], cls[4], cls[3], cls[2], cls[1], cls[0]);
// Check if this is a foreign exception. If it is a C++ exception, then we
@ -266,6 +348,7 @@ _Unwind_Reason_Code __gnu_objc_personality_v0(int version,
fprintf(stderr, "Foreign class: %p\n", thrown_class);
}
unsigned char *lsda_addr = (void*)_Unwind_GetLanguageSpecificData(context);
fprintf(stderr, "LSDA: %p\n", lsda_addr);
// No LSDA implies no landing pads - try the next frame
if (0 == lsda_addr) { return _URC_CONTINUE_UNWIND; }
@ -276,6 +359,7 @@ _Unwind_Reason_Code __gnu_objc_personality_v0(int version,
if (actions & _UA_SEARCH_PHASE)
{
fprintf(stderr, "Search phase...\n");
struct dwarf_eh_lsda lsda = parse_lsda(context, lsda_addr);
action = dwarf_eh_find_callsite(context, &lsda);
handler_type handler = check_action_record(context, foreignException,
@ -286,13 +370,7 @@ _Unwind_Reason_Code __gnu_objc_personality_v0(int version,
((handler == handler_catchall_id) && !foreignException) ||
(handler == handler_catchall))
{
// Cache the results for the phase 2 unwind, if we found a handler
// and this is not a foreign exception.
if (ex)
{
ex->handlerSwitchValue = selector;
ex->landingPad = action.landing_pad;
}
saveLandingPad(context, exceptionObject, ex, selector, action.landing_pad);
fprintf(stderr, "Found handler! %d\n", handler);
return _URC_HANDLER_FOUND;
}
@ -353,8 +431,7 @@ _Unwind_Reason_Code __gnu_objc_personality_v0(int version,
else
{
// Restore the saved info if we saved some last time.
action.landing_pad = ex->landingPad;
selector = ex->handlerSwitchValue;
loadLandingPad(context, exceptionObject, ex, &selector, &action.landing_pad);
object = ex->object;
free(ex);
}
@ -367,12 +444,9 @@ _Unwind_Reason_Code __gnu_objc_personality_v0(int version,
return _URC_INSTALL_CONTEXT;
}
_Unwind_Reason_Code __gnustep_objcxx_personality_v0(int version,
_Unwind_Action actions,
uint64_t exceptionClass,
struct _Unwind_Exception *exceptionObject,
struct _Unwind_Context *context)
{
// FIXME!
#ifndef __arm__
BEGIN_PERSONALITY_FUNCTION(__gnustep_objcxx_personality_v0)
if (exceptionClass == objc_exception_class)
{
struct objc_exception *ex = (struct objc_exception*)
@ -391,7 +465,6 @@ _Unwind_Reason_Code __gnustep_objcxx_personality_v0(int version,
exceptionObject = ex->cxx_exception;
exceptionClass = cxx_exception_class;
}
return __gxx_personality_v0(version, actions, exceptionClass,
exceptionObject, context);
return CALL_PERSONALITY_FUNCTION(__gxx_personality_v0);
}
#endif

View File

@ -4,6 +4,7 @@
#define DATA_OFFSET 12
#define SLOT_OFFSET 16
.syntax unified
.fpu neon
// Macro for testing: logs a register value to standard error
.macro LOG reg
@ -14,14 +15,15 @@
.endm
.macro MSGSEND receiver, sel
.cfi_startproc
.fnstart
teq \receiver, 0
beq 4f // Skip everything if the receiver is nil
push {r4-r6} // We're going to use these three as
.cfi_adjust_cfa_offset 12 // scratch registers, so save them now.
.cfi_rel_offset r4, 0 // These are callee-save, so the unwind library
.cfi_rel_offset r5, 4 // must be able to restore them, so we need CFI
.cfi_rel_offset r6, 8 // directives for them, but not for any other pushes
.save {r4-r6}
// scratch registers, so save them now.
// These are callee-save, so the unwind library
// must be able to restore them, so we need CFI
// directives for them, but not for any other pushes
tst \receiver, SMALLOBJ_MASK // Sets Z if this is not a small int
@ -73,21 +75,22 @@
mov r1, 0
mov pc, lr
5: // Slow lookup
push {r0-r3, lr} // Save anything that will be clobbered by the call
push {r0-r4, lr} // Save anything that will be clobbered by the call
.save {r0-r4, lr}
push {\receiver} // &self, _cmd in arguments
mov r0, sp
.save {\receiver}
mov r1, \sel
.cfi_adjust_cfa_offset 24 // pushed 6 more 4-byte words onto the stack.
bl slowMsgLookup(PLT) // This is the only place where the CFI directives have to be accurate...
mov ip, r0 // IMP -> ip
pop {r5} // restore (modified) self to r5
pop {r0-r3, lr} // Load clobbered registers
pop {r0-r4, lr} // Load clobbered registers
mov \receiver, r5
b 3b
.cfi_endproc
.fnend
.endm
.globl objc_msgSend

View File

@ -19,12 +19,7 @@ struct _Unwind_Exception *objc_init_cxx_exception(void *thrown_exception);
* The GNU C++ exception personality function, provided by libsupc++ (GNU) or
* libcxxrt (PathScale).
*/
__attribute__((weak))
_Unwind_Reason_Code __gxx_personality_v0(int version,
_Unwind_Action actions,
uint64_t exceptionClass,
struct _Unwind_Exception *exceptionObject,
struct _Unwind_Context *context);
__attribute__((weak)) DECLARE_PERSONALITY_FUNCTION(__gxx_personality_v0);
/**
* Frees an exception object allocated by __cxa_allocate_exception(). Part of
* the Itanium C++ ABI.

197
unwind-arm.h Normal file
View File

@ -0,0 +1,197 @@
/**
* ARM-specific unwind definitions. These are taken from the ARM EHABI
* specification.
*/
typedef enum
{
_URC_OK = 0, /* operation completed successfully */
_URC_FOREIGN_EXCEPTION_CAUGHT = 1,
_URC_END_OF_STACK = 5,
_URC_HANDLER_FOUND = 6,
_URC_INSTALL_CONTEXT = 7,
_URC_CONTINUE_UNWIND = 8,
_URC_FAILURE = 9, /* unspecified failure of some kind */
_URC_FATAL_PHASE1_ERROR = _URC_FAILURE
} _Unwind_Reason_Code;
typedef uint32_t _Unwind_State;
#ifdef __clang__
static const _Unwind_State _US_VIRTUAL_UNWIND_FRAME = 0;
static const _Unwind_State _US_UNWIND_FRAME_STARTING = 1;
static const _Unwind_State _US_UNWIND_FRAME_RESUME = 2;
#else // GCC fails at knowing what a constant expression is
# define _US_VIRTUAL_UNWIND_FRAME 0
# define _US_UNWIND_FRAME_STARTING 1
# define _US_UNWIND_FRAME_RESUME 2
#endif
typedef struct _Unwind_Context _Unwind_Context;
typedef uint32_t _Unwind_EHT_Header;
struct _Unwind_Exception
{
uint64_t exception_class;
void (*exception_cleanup)(_Unwind_Reason_Code, struct _Unwind_Exception *);
/* Unwinder cache, private fields for the unwinder's use */
struct
{
uint32_t reserved1;
uint32_t reserved2;
uint32_t reserved3;
uint32_t reserved4;
uint32_t reserved5;
/* init reserved1 to 0, then don't touch */
} 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;
/* Pr cache (for pr's benefit): */
struct
{
/** function start address */
uint32_t fnstart;
/** pointer to EHT entry header word */
_Unwind_EHT_Header *ehtp;
/** additional data */
uint32_t additional;
uint32_t reserved1;
} pr_cache;
/** Force alignment of next item to 8-byte boundary */
long long int :0;
};
/* Unwinding functions */
_Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *ucbp);
void _Unwind_Resume(struct _Unwind_Exception *ucbp);
void _Unwind_Complete(struct _Unwind_Exception *ucbp);
void _Unwind_DeleteException(struct _Unwind_Exception *ucbp);
void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context*);
typedef enum
{
_UVRSR_OK = 0,
_UVRSR_NOT_IMPLEMENTED = 1,
_UVRSR_FAILED = 2
} _Unwind_VRS_Result;
typedef enum
{
_UVRSC_CORE = 0,
_UVRSC_VFP = 1,
_UVRSC_WMMXD = 3,
_UVRSC_WMMXC = 4
} _Unwind_VRS_RegClass;
typedef enum
{
_UVRSD_UINT32 = 0,
_UVRSD_VFPX = 1,
_UVRSD_UINT64 = 3,
_UVRSD_FLOAT = 4,
_UVRSD_DOUBLE = 5
} _Unwind_VRS_DataRepresentation;
_Unwind_VRS_Result _Unwind_VRS_Get(_Unwind_Context *context,
_Unwind_VRS_RegClass regclass,
uint32_t regno,
_Unwind_VRS_DataRepresentation representation,
void *valuep);
_Unwind_VRS_Result _Unwind_VRS_Set(_Unwind_Context *context,
_Unwind_VRS_RegClass regclass,
uint32_t regno,
_Unwind_VRS_DataRepresentation representation,
void *valuep);
/* Return the base-address for data references. */
extern unsigned long _Unwind_GetDataRelBase(struct _Unwind_Context *);
/* Return the base-address for text references. */
extern unsigned long _Unwind_GetTextRelBase(struct _Unwind_Context *);
extern unsigned long _Unwind_GetRegionStart(struct _Unwind_Context *);
/**
* The next set of functions are compatibility extensions, implementing Itanium
* ABI functions on top of ARM ones.
*/
#define _UA_SEARCH_PHASE 1
#define _UA_CLEANUP_PHASE 2
#define _UA_HANDLER_FRAME 4
#define _UA_FORCE_UNWIND 8
static inline unsigned long _Unwind_GetGR(struct _Unwind_Context *context, int reg)
{
unsigned long val;
_Unwind_VRS_Get(context, 0, reg, 0, &val);
return val;
}
static inline void _Unwind_SetGR(struct _Unwind_Context *context, int reg, unsigned long val)
{
_Unwind_VRS_Set(context, 0, reg, 0, &val);
}
static inline unsigned long _Unwind_GetIP(_Unwind_Context *context)
{
// Low bit store the thumb state - discard it
return _Unwind_GetGR(context, 15) & ~1;
}
static inline void _Unwind_SetIP(_Unwind_Context *context, unsigned long val)
{
// The lowest bit of the instruction pointer indicates whether we're in
// thumb or ARM mode. This is assumed to be fixed throughout a function,
// so must be propagated when setting the program counter.
unsigned long thumbState = _Unwind_GetGR(context, 15) & 1;
_Unwind_SetGR(context, 15, (val | thumbState));
}
/** GNU API function that unwinds the frame */
_Unwind_Reason_Code __gnu_unwind_frame(struct _Unwind_Exception*, struct _Unwind_Context*);
#define DECLARE_PERSONALITY_FUNCTION(name) \
_Unwind_Reason_Code name(_Unwind_State state,\
struct _Unwind_Exception *exceptionObject,\
struct _Unwind_Context *context);
#define BEGIN_PERSONALITY_FUNCTION(name) \
_Unwind_Reason_Code name(_Unwind_State state,\
struct _Unwind_Exception *exceptionObject,\
struct _Unwind_Context *context)\
{\
fprintf(stderr, "LSDA: %p\n", (void*)_Unwind_GetLanguageSpecificData(context));\
fprintf(stderr, "IP: %p\n", (void*)_Unwind_GetIP(context));\
int version = 1;\
uint64_t exceptionClass = exceptionObject->exception_class;\
int actions;\
switch (state)\
{\
default: return _URC_FAILURE;\
case _US_VIRTUAL_UNWIND_FRAME:\
{\
actions = _UA_SEARCH_PHASE;\
break;\
}\
case _US_UNWIND_FRAME_STARTING:\
{\
actions = _UA_CLEANUP_PHASE;\
if (exceptionObject->barrier_cache.sp == _Unwind_GetGR(context, 13))\
{\
actions |= _UA_HANDLER_FRAME;\
}\
break;\
}\
case _US_UNWIND_FRAME_RESUME:\
{\
return continueUnwinding(exceptionObject, context);\
break;\
}\
}\
_Unwind_SetGR (context, 12, (unsigned long)exceptionObject);
#define CALL_PERSONALITY_FUNCTION(name) name(state,exceptionObject,context)

170
unwind-itanium.h Normal file
View File

@ -0,0 +1,170 @@
/* libunwind - a platform-independent unwind library
Copyright (C) 2003 Hewlett-Packard Co
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
This file is part of libunwind.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#ifndef _UNWIND_H
#define _UNWIND_H
/* For uint64_t */
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Minimal interface as per C++ ABI draft standard:
http://www.codesourcery.com/cxx-abi/abi-eh.html */
typedef enum
{
_URC_NO_REASON = 0,
_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,
_URC_CONTINUE_UNWIND = 8
}
_Unwind_Reason_Code;
typedef int _Unwind_Action;
#define _UA_SEARCH_PHASE 1
#define _UA_CLEANUP_PHASE 2
#define _UA_HANDLER_FRAME 4
#define _UA_FORCE_UNWIND 8
struct _Unwind_Context; /* opaque data-structure */
struct _Unwind_Exception; /* forward-declaration */
typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
struct _Unwind_Exception *);
typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action,
uint64_t,
struct _Unwind_Exception *,
struct _Unwind_Context *,
void *);
/* The C++ ABI requires exception_class, private_1, and private_2 to
be of type uint64 and the entire structure to be
double-word-aligned. Please note that exception_class stays 64-bit
even on 32-bit machines for gcc compatibility. */
struct _Unwind_Exception
{
uint64_t exception_class;
_Unwind_Exception_Cleanup_Fn exception_cleanup;
unsigned long private_1;
unsigned long private_2;
} __attribute__((__aligned__));
extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
_Unwind_Stop_Fn, void *);
extern void _Unwind_Resume (struct _Unwind_Exception *);
extern void _Unwind_DeleteException (struct _Unwind_Exception *);
extern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int);
extern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long);
extern unsigned long _Unwind_GetIP (struct _Unwind_Context *);
extern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
extern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long);
extern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*);
extern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *);
#ifdef _GNU_SOURCE
/* Callback for _Unwind_Backtrace(). The backtrace stops immediately
if the callback returns any value other than _URC_NO_REASON. */
typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *,
void *);
/* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why
_UA_END_OF_STACK exists. */
# define _UA_END_OF_STACK 16
/* If the unwind was initiated due to a forced unwind, resume that
operation, else re-raise the exception. This is used by
__cxa_rethrow(). */
extern _Unwind_Reason_Code
_Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
/* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why
_Unwind_GetBSP() exists. */
extern unsigned long _Unwind_GetBSP (struct _Unwind_Context *);
/* Return the "canonical frame address" for the given context.
This is used by NPTL... */
extern unsigned long _Unwind_GetCFA (struct _Unwind_Context *);
/* Return the base-address for data references. */
extern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *);
/* Return the base-address for text references. */
extern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *);
/* Call _Unwind_Trace_Fn once for each stack-frame, without doing any
cleanup. The first frame for which the callback is invoked is the
one for the caller of _Unwind_Backtrace(). _Unwind_Backtrace()
returns _URC_END_OF_STACK when the backtrace stopped due to
reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it
stops for any other reason. */
extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
/* Find the start-address of the procedure containing the specified IP
or NULL if it cannot be found (e.g., because the function has no
unwind info). Note: there is not necessarily a one-to-one
correspondence between source-level functions and procedures: some
functions don't have unwind-info and others are split into multiple
procedures. */
extern void *_Unwind_FindEnclosingFunction (void *);
/* See also Linux Standard Base Spec:
http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */
#endif /* _GNU_SOURCE */
#define DECLARE_PERSONALITY_FUNCTION(name) \
_Unwind_Reason_Code name(int version,\
_Unwind_Action actions,\
uint64_t exceptionClass,\
struct _Unwind_Exception *exceptionObject,\
struct _Unwind_Context *context);
#define BEGIN_PERSONALITY_FUNCTION(name) \
_Unwind_Reason_Code name(int version,\
_Unwind_Action actions,\
uint64_t exceptionClass,\
struct _Unwind_Exception *exceptionObject,\
struct _Unwind_Context *context)\
{
#define CALL_PERSONALITY_FUNCTION(name) name(version, actions, exceptionClass, exceptionObject, context)
#ifdef __cplusplus
}
#endif
#endif /* _UNWIND_H */

157
unwind.h
View File

@ -1,154 +1,5 @@
/* libunwind - a platform-independent unwind library
Copyright (C) 2003 Hewlett-Packard Co
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
This file is part of libunwind.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#ifndef _UNWIND_H
#define _UNWIND_H
/* For uint64_t */
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#ifdef __arm__
#include "unwind-arm.h"
#else
#include "unwind-itanium.h"
#endif
/* Minimal interface as per C++ ABI draft standard:
http://www.codesourcery.com/cxx-abi/abi-eh.html */
typedef enum
{
_URC_NO_REASON = 0,
_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,
_URC_CONTINUE_UNWIND = 8
}
_Unwind_Reason_Code;
typedef int _Unwind_Action;
#define _UA_SEARCH_PHASE 1
#define _UA_CLEANUP_PHASE 2
#define _UA_HANDLER_FRAME 4
#define _UA_FORCE_UNWIND 8
struct _Unwind_Context; /* opaque data-structure */
struct _Unwind_Exception; /* forward-declaration */
typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
struct _Unwind_Exception *);
typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action,
uint64_t,
struct _Unwind_Exception *,
struct _Unwind_Context *,
void *);
/* The C++ ABI requires exception_class, private_1, and private_2 to
be of type uint64 and the entire structure to be
double-word-aligned. Please note that exception_class stays 64-bit
even on 32-bit machines for gcc compatibility. */
struct _Unwind_Exception
{
uint64_t exception_class;
_Unwind_Exception_Cleanup_Fn exception_cleanup;
unsigned long private_1;
unsigned long private_2;
} __attribute__((__aligned__));
extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
_Unwind_Stop_Fn, void *);
extern void _Unwind_Resume (struct _Unwind_Exception *);
extern void _Unwind_DeleteException (struct _Unwind_Exception *);
extern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int);
extern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long);
extern unsigned long _Unwind_GetIP (struct _Unwind_Context *);
extern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
extern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long);
extern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*);
extern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *);
#ifdef _GNU_SOURCE
/* Callback for _Unwind_Backtrace(). The backtrace stops immediately
if the callback returns any value other than _URC_NO_REASON. */
typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *,
void *);
/* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why
_UA_END_OF_STACK exists. */
# define _UA_END_OF_STACK 16
/* If the unwind was initiated due to a forced unwind, resume that
operation, else re-raise the exception. This is used by
__cxa_rethrow(). */
extern _Unwind_Reason_Code
_Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
/* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why
_Unwind_GetBSP() exists. */
extern unsigned long _Unwind_GetBSP (struct _Unwind_Context *);
/* Return the "canonical frame address" for the given context.
This is used by NPTL... */
extern unsigned long _Unwind_GetCFA (struct _Unwind_Context *);
/* Return the base-address for data references. */
extern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *);
/* Return the base-address for text references. */
extern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *);
/* Call _Unwind_Trace_Fn once for each stack-frame, without doing any
cleanup. The first frame for which the callback is invoked is the
one for the caller of _Unwind_Backtrace(). _Unwind_Backtrace()
returns _URC_END_OF_STACK when the backtrace stopped due to
reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it
stops for any other reason. */
extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
/* Find the start-address of the procedure containing the specified IP
or NULL if it cannot be found (e.g., because the function has no
unwind info). Note: there is not necessarily a one-to-one
correspondence between source-level functions and procedures: some
functions don't have unwind-info and others are split into multiple
procedures. */
extern void *_Unwind_FindEnclosingFunction (void *);
/* See also Linux Standard Base Spec:
http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */
#endif /* _GNU_SOURCE */
#ifdef __cplusplus
}
#endif
#endif /* _UNWIND_H */