Import libcxxrt master 00bc29eb6513624824a6d7db2ebc768a4216a604.
Interesting fixes: 76584a0 Reorganize code to use only 32bit atomic ops for 32bit platforms 30d2ae5 Implement __cxa_throw_bad_array_new_length Reviewed by: bapt MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D1390
This commit is contained in:
parent
a1a2c6c54c
commit
82d90d4880
@ -11,7 +11,7 @@
|
||||
*/
|
||||
#if __has_builtin(__c11_atomic_exchange)
|
||||
#define ATOMIC_SWAP(addr, val)\
|
||||
__c11_atomic_exchange((_Atomic(__typeof__(val))*)addr, val, __ATOMIC_ACQ_REL)
|
||||
__c11_atomic_exchange(reinterpret_cast<_Atomic(__typeof__(val))*>(addr), val, __ATOMIC_ACQ_REL)
|
||||
#elif __has_builtin(__sync_swap)
|
||||
#define ATOMIC_SWAP(addr, val)\
|
||||
__sync_swap(addr, val)
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
#if __has_builtin(__c11_atomic_load)
|
||||
#define ATOMIC_LOAD(addr)\
|
||||
__c11_atomic_load((_Atomic(__typeof__(*addr))*)addr, __ATOMIC_ACQUIRE)
|
||||
__c11_atomic_load(reinterpret_cast<_Atomic(__typeof__(*addr))*>(addr), __ATOMIC_ACQUIRE)
|
||||
#else
|
||||
#define ATOMIC_LOAD(addr)\
|
||||
(__sync_synchronize(), *addr)
|
||||
|
@ -110,7 +110,7 @@ struct __cxa_exception
|
||||
* handler count reaches 0 (which it doesn't with the top bit set).
|
||||
*/
|
||||
int handlerCount;
|
||||
#ifdef __arm__
|
||||
#if defined(__arm__) && !defined(__ARM_DWARF_EH__)
|
||||
/**
|
||||
* The ARM EH ABI requires the unwind library to keep track of exceptions
|
||||
* during cleanups. These support nesting, so we need to keep a list of
|
||||
|
@ -83,7 +83,7 @@ enum dwarf_data_encoding
|
||||
*/
|
||||
static inline enum dwarf_data_encoding get_encoding(unsigned char x)
|
||||
{
|
||||
return (enum dwarf_data_encoding)(x & 0xf);
|
||||
return static_cast<enum dwarf_data_encoding>(x & 0xf);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,7 +115,7 @@ enum dwarf_data_relative
|
||||
*/
|
||||
static inline enum dwarf_data_relative get_base(unsigned char x)
|
||||
{
|
||||
return (enum dwarf_data_relative)(x & 0x70);
|
||||
return static_cast<enum dwarf_data_relative>(x & 0x70);
|
||||
}
|
||||
/**
|
||||
* Returns whether an encoding represents an indirect address.
|
||||
@ -206,9 +206,9 @@ static int64_t read_sleb128(dw_eh_ptr_t *data)
|
||||
if ((uleb >> (bits-1)) == 1)
|
||||
{
|
||||
// Sign extend by setting all bits in front of it to 1
|
||||
uleb |= ((int64_t)-1) << bits;
|
||||
uleb |= static_cast<int64_t>(-1) << bits;
|
||||
}
|
||||
return (int64_t)uleb;
|
||||
return static_cast<int64_t>(uleb);
|
||||
}
|
||||
/**
|
||||
* Reads a value using the specified encoding from the address pointed to by
|
||||
@ -224,7 +224,7 @@ static uint64_t read_value(char encoding, dw_eh_ptr_t *data)
|
||||
// Read fixed-length types
|
||||
#define READ(dwarf, type) \
|
||||
case dwarf:\
|
||||
v = (uint64_t)(*(type*)(*data));\
|
||||
v = static_cast<uint64_t>(*reinterpret_cast<type*>(*data));\
|
||||
*data += sizeof(type);\
|
||||
break;
|
||||
READ(DW_EH_PE_udata2, uint16_t)
|
||||
@ -263,16 +263,16 @@ static uint64_t resolve_indirect_value(_Unwind_Context *c,
|
||||
switch (get_base(encoding))
|
||||
{
|
||||
case DW_EH_PE_pcrel:
|
||||
v += (uint64_t)start;
|
||||
v += reinterpret_cast<uint64_t>(start);
|
||||
break;
|
||||
case DW_EH_PE_textrel:
|
||||
v += (uint64_t)_Unwind_GetTextRelBase(c);
|
||||
v += static_cast<uint64_t>(static_cast<uintptr_t>(_Unwind_GetTextRelBase(c)));
|
||||
break;
|
||||
case DW_EH_PE_datarel:
|
||||
v += (uint64_t)_Unwind_GetDataRelBase(c);
|
||||
v += static_cast<uint64_t>(static_cast<uintptr_t>(_Unwind_GetDataRelBase(c)));
|
||||
break;
|
||||
case DW_EH_PE_funcrel:
|
||||
v += (uint64_t)_Unwind_GetRegionStart(c);
|
||||
v += static_cast<uint64_t>(static_cast<uintptr_t>(_Unwind_GetRegionStart(c)));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -282,7 +282,7 @@ static uint64_t resolve_indirect_value(_Unwind_Context *c,
|
||||
// be a GCC extensions, so not properly documented...
|
||||
if (is_indirect(encoding))
|
||||
{
|
||||
v = (uint64_t)(uintptr_t)*(void**)v;
|
||||
v = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(*reinterpret_cast<void**>(v)));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
@ -342,14 +342,14 @@ static inline struct dwarf_eh_lsda parse_lsda(_Unwind_Context *context,
|
||||
{
|
||||
struct dwarf_eh_lsda lsda;
|
||||
|
||||
lsda.region_start = (dw_eh_ptr_t)(uintptr_t)_Unwind_GetRegionStart(context);
|
||||
lsda.region_start = reinterpret_cast<dw_eh_ptr_t>(_Unwind_GetRegionStart(context));
|
||||
|
||||
// If the landing pads are relative to anything other than the start of
|
||||
// this region, find out where. This is @LPStart in the spec, although the
|
||||
// encoding that GCC uses does not quite match the spec.
|
||||
uint64_t v = (uint64_t)(uintptr_t)lsda.region_start;
|
||||
uint64_t v = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(lsda.region_start));
|
||||
read_value_with_encoding(context, &data, &v);
|
||||
lsda.landing_pads = (dw_eh_ptr_t)(uintptr_t)v;
|
||||
lsda.landing_pads = reinterpret_cast<dw_eh_ptr_t>(static_cast<uintptr_t>(v));
|
||||
|
||||
// If there is a type table, find out where it is. This is @TTBase in the
|
||||
// spec. Note: we find whether there is a type table pointer by checking
|
||||
@ -365,18 +365,18 @@ static inline struct dwarf_eh_lsda parse_lsda(_Unwind_Context *context,
|
||||
lsda.type_table = type_table;
|
||||
//lsda.type_table = (uintptr_t*)(data + v);
|
||||
}
|
||||
#if __arm__
|
||||
#if defined(__arm__) && !defined(__ARM_DWARF_EH__)
|
||||
lsda.type_table_encoding = (DW_EH_PE_pcrel | DW_EH_PE_indirect);
|
||||
#endif
|
||||
|
||||
lsda.callsite_encoding = (enum dwarf_data_encoding)(*(data++));
|
||||
lsda.callsite_encoding = static_cast<enum dwarf_data_encoding>(*(data++));
|
||||
|
||||
// Action table is immediately after the call site table
|
||||
lsda.action_table = data;
|
||||
uintptr_t callsite_size = (uintptr_t)read_uleb128(&data);
|
||||
uintptr_t callsite_size = static_cast<uintptr_t>(read_uleb128(&data));
|
||||
lsda.action_table = data + callsite_size;
|
||||
// Call site table is immediately after the header
|
||||
lsda.call_site_table = (dw_eh_ptr_t)data;
|
||||
lsda.call_site_table = static_cast<dw_eh_ptr_t>(data);
|
||||
|
||||
|
||||
return lsda;
|
||||
@ -413,7 +413,7 @@ static bool dwarf_eh_find_callsite(struct _Unwind_Context *context,
|
||||
result->landing_pad = 0;
|
||||
// The current instruction pointer offset within the region
|
||||
uint64_t ip = _Unwind_GetIP(context) - _Unwind_GetRegionStart(context);
|
||||
unsigned char *callsite_table = (unsigned char*)lsda->call_site_table;
|
||||
unsigned char *callsite_table = static_cast<unsigned char*>(lsda->call_site_table);
|
||||
|
||||
while (callsite_table <= lsda->action_table)
|
||||
{
|
||||
@ -463,17 +463,17 @@ static bool dwarf_eh_find_callsite(struct _Unwind_Context *context,
|
||||
|
||||
/// Defines an exception class from 8 bytes (endian independent)
|
||||
#define EXCEPTION_CLASS(a,b,c,d,e,f,g,h) \
|
||||
(((uint64_t)a << 56) +\
|
||||
((uint64_t)b << 48) +\
|
||||
((uint64_t)c << 40) +\
|
||||
((uint64_t)d << 32) +\
|
||||
((uint64_t)e << 24) +\
|
||||
((uint64_t)f << 16) +\
|
||||
((uint64_t)g << 8) +\
|
||||
((uint64_t)h))
|
||||
((static_cast<uint64_t>(a) << 56) +\
|
||||
(static_cast<uint64_t>(b) << 48) +\
|
||||
(static_cast<uint64_t>(c) << 40) +\
|
||||
(static_cast<uint64_t>(d) << 32) +\
|
||||
(static_cast<uint64_t>(e) << 24) +\
|
||||
(static_cast<uint64_t>(f) << 16) +\
|
||||
(static_cast<uint64_t>(g) << 8) +\
|
||||
(static_cast<uint64_t>(h)))
|
||||
|
||||
#define GENERIC_EXCEPTION_CLASS(e,f,g,h) \
|
||||
((uint32_t)e << 24) +\
|
||||
((uint32_t)f << 16) +\
|
||||
((uint32_t)g << 8) +\
|
||||
((uint32_t)h)
|
||||
(static_cast<uint32_t>(e) << 24) +\
|
||||
(static_cast<uint32_t>(f) << 16) +\
|
||||
(static_cast<uint32_t>(g) << 8) +\
|
||||
(static_cast<uint32_t>(h))
|
||||
|
@ -44,7 +44,7 @@ struct vtable_header
|
||||
* Simple macro that does pointer arithmetic in bytes but returns a value of
|
||||
* the same type as the original.
|
||||
*/
|
||||
#define ADD_TO_PTR(x, off) (__typeof__(x))(((char*)x) + off)
|
||||
#define ADD_TO_PTR(x, off) reinterpret_cast<__typeof__(x)>(reinterpret_cast<char*>(x) + off)
|
||||
|
||||
bool std::type_info::__do_catch(std::type_info const *ex_type,
|
||||
void **exception_object,
|
||||
@ -166,7 +166,7 @@ bool __vmi_class_type_info::__do_upcast(const __class_type_info *target,
|
||||
if (info->isVirtual())
|
||||
{
|
||||
// Object's vtable
|
||||
ptrdiff_t *off = *(ptrdiff_t**)obj;
|
||||
ptrdiff_t *off = *static_cast<ptrdiff_t**>(obj);
|
||||
// Offset location in vtable
|
||||
off = ADD_TO_PTR(off, offset);
|
||||
offset = *off;
|
||||
@ -202,9 +202,9 @@ extern "C" void* __dynamic_cast(const void *sub,
|
||||
const __class_type_info *dst,
|
||||
ptrdiff_t src2dst_offset)
|
||||
{
|
||||
char *vtable_location = *(char**)sub;
|
||||
const char *vtable_location = *static_cast<const char * const *>(sub);
|
||||
const vtable_header *header =
|
||||
(const vtable_header*)(vtable_location - sizeof(vtable_header));
|
||||
void *leaf = ADD_TO_PTR((void*)sub, header->leaf_offset);
|
||||
reinterpret_cast<const vtable_header*>(vtable_location - sizeof(vtable_header));
|
||||
void *leaf = ADD_TO_PTR(const_cast<void *>(sub), header->leaf_offset);
|
||||
return header->type->cast_to(leaf, dst);
|
||||
}
|
||||
|
@ -71,11 +71,11 @@ static void saveLandingPad(struct _Unwind_Context *context,
|
||||
int selector,
|
||||
dw_eh_ptr_t landingPad)
|
||||
{
|
||||
#ifdef __arm__
|
||||
#if defined(__arm__) && !defined(__ARM_DWARF_EH__)
|
||||
// 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;
|
||||
ucb->barrier_cache.bitpattern[1] = static_cast<uint32_t>(selector);
|
||||
ucb->barrier_cache.bitpattern[3] = reinterpret_cast<uint32_t>(landingPad);
|
||||
#endif
|
||||
// Cache the results for the phase 2 unwind, if we found a handler
|
||||
// and this is not a foreign exception.
|
||||
@ -95,15 +95,15 @@ static int loadLandingPad(struct _Unwind_Context *context,
|
||||
unsigned long *selector,
|
||||
dw_eh_ptr_t *landingPad)
|
||||
{
|
||||
#ifdef __arm__
|
||||
#if defined(__arm__) && !defined(__ARM_DWARF_EH__)
|
||||
*selector = ucb->barrier_cache.bitpattern[1];
|
||||
*landingPad = (dw_eh_ptr_t)ucb->barrier_cache.bitpattern[3];
|
||||
*landingPad = reinterpret_cast<dw_eh_ptr_t>(ucb->barrier_cache.bitpattern[3]);
|
||||
return 1;
|
||||
#else
|
||||
if (ex)
|
||||
{
|
||||
*selector = ex->handlerSwitchValue;
|
||||
*landingPad = (dw_eh_ptr_t)ex->catchTemp;
|
||||
*landingPad = reinterpret_cast<dw_eh_ptr_t>(ex->catchTemp);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
@ -113,7 +113,7 @@ static int loadLandingPad(struct _Unwind_Context *context,
|
||||
static inline _Unwind_Reason_Code continueUnwinding(struct _Unwind_Exception *ex,
|
||||
struct _Unwind_Context *context)
|
||||
{
|
||||
#ifdef __arm__
|
||||
#if defined(__arm__) && !defined(__ARM_DWARF_EH__)
|
||||
if (__gnu_unwind_frame(ex, context) != _URC_OK) { return _URC_FAILURE; }
|
||||
#endif
|
||||
return _URC_CONTINUE_UNWIND;
|
||||
@ -204,7 +204,7 @@ struct __cxa_dependent_exception
|
||||
terminate_handler terminateHandler;
|
||||
__cxa_exception *nextException;
|
||||
int handlerCount;
|
||||
#ifdef __arm__
|
||||
#if defined(__arm__) && !defined(__ARM_DWARF_EH__)
|
||||
_Unwind_Exception *nextCleanup;
|
||||
int cleanupCount;
|
||||
#endif
|
||||
@ -267,13 +267,13 @@ static bool isDependentException(uint64_t cls)
|
||||
|
||||
static __cxa_exception *exceptionFromPointer(void *ex)
|
||||
{
|
||||
return (__cxa_exception*)((char*)ex -
|
||||
return reinterpret_cast<__cxa_exception*>(static_cast<char*>(ex) -
|
||||
offsetof(struct __cxa_exception, unwindHeader));
|
||||
}
|
||||
static __cxa_exception *realExceptionFromException(__cxa_exception *ex)
|
||||
{
|
||||
if (!isDependentException(ex->unwindHeader.exception_class)) { return ex; }
|
||||
return ((__cxa_exception*)(((__cxa_dependent_exception*)ex)->primaryException))-1;
|
||||
return reinterpret_cast<__cxa_exception*>((reinterpret_cast<__cxa_dependent_exception*>(ex))->primaryException)-1;
|
||||
}
|
||||
|
||||
|
||||
@ -304,13 +304,13 @@ static pthread_key_t eh_key;
|
||||
static void exception_cleanup(_Unwind_Reason_Code reason,
|
||||
struct _Unwind_Exception *ex)
|
||||
{
|
||||
__cxa_free_exception((void*)ex);
|
||||
__cxa_free_exception(static_cast<void*>(ex));
|
||||
}
|
||||
static void dependent_exception_cleanup(_Unwind_Reason_Code reason,
|
||||
struct _Unwind_Exception *ex)
|
||||
{
|
||||
|
||||
__cxa_free_dependent_exception((void*)ex);
|
||||
__cxa_free_dependent_exception(static_cast<void*>(ex));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -333,13 +333,13 @@ static void free_exception_list(__cxa_exception *ex)
|
||||
*/
|
||||
static void thread_cleanup(void* thread_info)
|
||||
{
|
||||
__cxa_thread_info *info = (__cxa_thread_info*)thread_info;
|
||||
__cxa_thread_info *info = static_cast<__cxa_thread_info*>(thread_info);
|
||||
if (info->globals.caughtExceptions)
|
||||
{
|
||||
// If this is a foreign exception, ask it to clean itself up.
|
||||
if (info->foreign_exception_state != __cxa_thread_info::none)
|
||||
{
|
||||
_Unwind_Exception *e = (_Unwind_Exception*)info->globals.caughtExceptions;
|
||||
_Unwind_Exception *e = reinterpret_cast<_Unwind_Exception*>(info->globals.caughtExceptions);
|
||||
e->exception_cleanup(_URC_FOREIGN_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
else
|
||||
@ -379,8 +379,8 @@ static void init_key(void)
|
||||
return;
|
||||
}
|
||||
pthread_key_create(&eh_key, thread_cleanup);
|
||||
pthread_setspecific(eh_key, (void*)0x42);
|
||||
fakeTLS = (pthread_getspecific(eh_key) != (void*)0x42);
|
||||
pthread_setspecific(eh_key, reinterpret_cast<void *>(0x42));
|
||||
fakeTLS = (pthread_getspecific(eh_key) != reinterpret_cast<void *>(0x42));
|
||||
pthread_setspecific(eh_key, 0);
|
||||
}
|
||||
|
||||
@ -394,10 +394,10 @@ static __cxa_thread_info *thread_info()
|
||||
fakeTLS = true;
|
||||
}
|
||||
if (fakeTLS) { return &singleThreadInfo; }
|
||||
__cxa_thread_info *info = (__cxa_thread_info*)pthread_getspecific(eh_key);
|
||||
__cxa_thread_info *info = static_cast<__cxa_thread_info*>(pthread_getspecific(eh_key));
|
||||
if (0 == info)
|
||||
{
|
||||
info = (__cxa_thread_info*)calloc(1, sizeof(__cxa_thread_info));
|
||||
info = static_cast<__cxa_thread_info*>(calloc(1, sizeof(__cxa_thread_info)));
|
||||
pthread_setspecific(eh_key, info);
|
||||
}
|
||||
return info;
|
||||
@ -409,7 +409,7 @@ static __cxa_thread_info *thread_info()
|
||||
static __cxa_thread_info *thread_info_fast()
|
||||
{
|
||||
if (fakeTLS) { return &singleThreadInfo; }
|
||||
return (__cxa_thread_info*)pthread_getspecific(eh_key);
|
||||
return static_cast<__cxa_thread_info*>(pthread_getspecific(eh_key));
|
||||
}
|
||||
/**
|
||||
* ABI function returning the __cxa_eh_globals structure.
|
||||
@ -472,7 +472,7 @@ static char *emergency_malloc(size_t size)
|
||||
if (0 != m)
|
||||
{
|
||||
pthread_mutex_unlock(&emergency_malloc_lock);
|
||||
return (char*)m;
|
||||
return static_cast<char*>(m);
|
||||
}
|
||||
for (int i=0 ; i<16 ; i++)
|
||||
{
|
||||
@ -510,7 +510,7 @@ static void emergency_malloc_free(char *ptr)
|
||||
// Find the buffer corresponding to this pointer.
|
||||
for (int i=0 ; i<16 ; i++)
|
||||
{
|
||||
if (ptr == (void*)(emergency_buffer + (1024 * i)))
|
||||
if (ptr == static_cast<void*>(emergency_buffer + (1024 * i)))
|
||||
{
|
||||
buffer = i;
|
||||
break;
|
||||
@ -521,7 +521,7 @@ static void emergency_malloc_free(char *ptr)
|
||||
// emergency_malloc() is expected to return 0-initialized data. We don't
|
||||
// zero the buffer when allocating it, because the static buffers will
|
||||
// begin life containing 0 values.
|
||||
memset((void*)ptr, 0, 1024);
|
||||
memset(ptr, 0, 1024);
|
||||
// Signal the condition variable to wake up any threads that are blocking
|
||||
// waiting for some space in the emergency buffer
|
||||
pthread_mutex_lock(&emergency_malloc_lock);
|
||||
@ -535,7 +535,7 @@ static void emergency_malloc_free(char *ptr)
|
||||
|
||||
static char *alloc_or_die(size_t size)
|
||||
{
|
||||
char *buffer = (char*)calloc(1, size);
|
||||
char *buffer = static_cast<char*>(calloc(1, size));
|
||||
|
||||
// If calloc() doesn't want to give us any memory, try using an emergency
|
||||
// buffer.
|
||||
@ -597,7 +597,7 @@ extern "C" void *__cxa_allocate_dependent_exception(void)
|
||||
*/
|
||||
extern "C" void __cxa_free_exception(void *thrown_exception)
|
||||
{
|
||||
__cxa_exception *ex = ((__cxa_exception*)thrown_exception) - 1;
|
||||
__cxa_exception *ex = reinterpret_cast<__cxa_exception*>(thrown_exception) - 1;
|
||||
// Free the object that was thrown, calling its destructor
|
||||
if (0 != ex->exceptionDestructor)
|
||||
{
|
||||
@ -612,7 +612,7 @@ extern "C" void __cxa_free_exception(void *thrown_exception)
|
||||
}
|
||||
}
|
||||
|
||||
free_exception((char*)ex);
|
||||
free_exception(reinterpret_cast<char*>(ex));
|
||||
}
|
||||
|
||||
static void releaseException(__cxa_exception *exception)
|
||||
@ -633,13 +633,13 @@ static void releaseException(__cxa_exception *exception)
|
||||
|
||||
void __cxa_free_dependent_exception(void *thrown_exception)
|
||||
{
|
||||
__cxa_dependent_exception *ex = ((__cxa_dependent_exception*)thrown_exception) - 1;
|
||||
__cxa_dependent_exception *ex = reinterpret_cast<__cxa_dependent_exception*>(thrown_exception) - 1;
|
||||
assert(isDependentException(ex->unwindHeader.exception_class));
|
||||
if (ex->primaryException)
|
||||
{
|
||||
releaseException(realExceptionFromException((__cxa_exception*)ex));
|
||||
releaseException(realExceptionFromException(reinterpret_cast<__cxa_exception*>(ex)));
|
||||
}
|
||||
free_exception((char*)ex);
|
||||
free_exception(reinterpret_cast<char*>(ex));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -654,8 +654,8 @@ static _Unwind_Reason_Code trace(struct _Unwind_Context *context, void *c)
|
||||
{
|
||||
Dl_info myinfo;
|
||||
int mylookup =
|
||||
dladdr((void*)(uintptr_t)__cxa_current_exception_type, &myinfo);
|
||||
void *ip = (void*)_Unwind_GetIP(context);
|
||||
dladdr(reinterpret_cast<void *>(__cxa_current_exception_type), &myinfo);
|
||||
void *ip = reinterpret_cast<void*>(_Unwind_GetIP(context));
|
||||
Dl_info info;
|
||||
if (dladdr(ip, &info) != 0)
|
||||
{
|
||||
@ -673,6 +673,11 @@ static _Unwind_Reason_Code trace(struct _Unwind_Context *context, void *c)
|
||||
* If the failure happened by falling off the end of the stack without finding
|
||||
* a handler, prints a back trace before aborting.
|
||||
*/
|
||||
#if __GNUC__ > 3 && __GNUC_MINOR__ > 2
|
||||
extern "C" void *__cxa_begin_catch(void *e) throw();
|
||||
#else
|
||||
extern "C" void *__cxa_begin_catch(void *e);
|
||||
#endif
|
||||
static void report_failure(_Unwind_Reason_Code err, __cxa_exception *thrown_exception)
|
||||
{
|
||||
switch (err)
|
||||
@ -681,14 +686,16 @@ static void report_failure(_Unwind_Reason_Code err, __cxa_exception *thrown_exce
|
||||
case _URC_FATAL_PHASE1_ERROR:
|
||||
fprintf(stderr, "Fatal error during phase 1 unwinding\n");
|
||||
break;
|
||||
#ifndef __arm__
|
||||
#if !defined(__arm__) || defined(__ARM_DWARF_EH__)
|
||||
case _URC_FATAL_PHASE2_ERROR:
|
||||
fprintf(stderr, "Fatal error during phase 2 unwinding\n");
|
||||
break;
|
||||
#endif
|
||||
case _URC_END_OF_STACK:
|
||||
__cxa_begin_catch (&(thrown_exception->unwindHeader));
|
||||
std::terminate();
|
||||
fprintf(stderr, "Terminating due to uncaught exception %p",
|
||||
(void*)thrown_exception);
|
||||
static_cast<void*>(thrown_exception));
|
||||
thrown_exception = realExceptionFromException(thrown_exception);
|
||||
static const __class_type_info *e_ti =
|
||||
static_cast<const __class_type_info*>(&typeid(std::exception));
|
||||
@ -697,8 +704,8 @@ static void report_failure(_Unwind_Reason_Code err, __cxa_exception *thrown_exce
|
||||
if (throw_ti)
|
||||
{
|
||||
std::exception *e =
|
||||
(std::exception*)e_ti->cast_to((void*)(thrown_exception+1),
|
||||
throw_ti);
|
||||
static_cast<std::exception*>(e_ti->cast_to(static_cast<void*>(thrown_exception+1),
|
||||
throw_ti));
|
||||
if (e)
|
||||
{
|
||||
fprintf(stderr, " '%s'", e->what());
|
||||
@ -706,18 +713,21 @@ static void report_failure(_Unwind_Reason_Code err, __cxa_exception *thrown_exce
|
||||
}
|
||||
|
||||
size_t bufferSize = 128;
|
||||
char *demangled = (char*)malloc(bufferSize);
|
||||
char *demangled = static_cast<char*>(malloc(bufferSize));
|
||||
const char *mangled = thrown_exception->exceptionType->name();
|
||||
int status;
|
||||
demangled = __cxa_demangle(mangled, demangled, &bufferSize, &status);
|
||||
fprintf(stderr, " of type %s\n",
|
||||
status == 0 ? (const char*)demangled : mangled);
|
||||
status == 0 ? demangled : mangled);
|
||||
if (status == 0) { free(demangled); }
|
||||
// Print a back trace if no handler is found.
|
||||
// TODO: Make this optional
|
||||
#ifndef __arm__
|
||||
_Unwind_Backtrace(trace, 0);
|
||||
#endif
|
||||
|
||||
// Just abort. No need to call std::terminate for the second time
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
std::terminate();
|
||||
@ -755,7 +765,7 @@ extern "C" void __cxa_throw(void *thrown_exception,
|
||||
std::type_info *tinfo,
|
||||
void(*dest)(void*))
|
||||
{
|
||||
__cxa_exception *ex = ((__cxa_exception*)thrown_exception) - 1;
|
||||
__cxa_exception *ex = reinterpret_cast<__cxa_exception*>(thrown_exception) - 1;
|
||||
|
||||
ex->referenceCount = 1;
|
||||
ex->exceptionType = tinfo;
|
||||
@ -773,7 +783,7 @@ extern "C" void __cxa_rethrow_primary_exception(void* thrown_exception)
|
||||
if (NULL == thrown_exception) { return; }
|
||||
|
||||
__cxa_exception *original = exceptionFromPointer(thrown_exception);
|
||||
__cxa_dependent_exception *ex = ((__cxa_dependent_exception*)__cxa_allocate_dependent_exception())-1;
|
||||
__cxa_dependent_exception *ex = reinterpret_cast<__cxa_dependent_exception*>(__cxa_allocate_dependent_exception())-1;
|
||||
|
||||
ex->primaryException = thrown_exception;
|
||||
__cxa_increment_exception_refcount(thrown_exception);
|
||||
@ -782,7 +792,7 @@ extern "C" void __cxa_rethrow_primary_exception(void* thrown_exception)
|
||||
ex->unwindHeader.exception_class = dependent_exception_class;
|
||||
ex->unwindHeader.exception_cleanup = dependent_exception_cleanup;
|
||||
|
||||
throw_exception((__cxa_exception*)ex);
|
||||
throw_exception(reinterpret_cast<__cxa_exception*>(ex));
|
||||
}
|
||||
|
||||
extern "C" void *__cxa_current_primary_exception(void)
|
||||
@ -799,14 +809,14 @@ extern "C" void *__cxa_current_primary_exception(void)
|
||||
extern "C" void __cxa_increment_exception_refcount(void* thrown_exception)
|
||||
{
|
||||
if (NULL == thrown_exception) { return; }
|
||||
__cxa_exception *ex = ((__cxa_exception*)thrown_exception) - 1;
|
||||
__cxa_exception *ex = static_cast<__cxa_exception*>(thrown_exception) - 1;
|
||||
if (isDependentException(ex->unwindHeader.exception_class)) { return; }
|
||||
__sync_fetch_and_add(&ex->referenceCount, 1);
|
||||
}
|
||||
extern "C" void __cxa_decrement_exception_refcount(void* thrown_exception)
|
||||
{
|
||||
if (NULL == thrown_exception) { return; }
|
||||
__cxa_exception *ex = ((__cxa_exception*)thrown_exception) - 1;
|
||||
__cxa_exception *ex = static_cast<__cxa_exception*>(thrown_exception) - 1;
|
||||
releaseException(ex);
|
||||
}
|
||||
|
||||
@ -838,7 +848,7 @@ extern "C" void __cxa_rethrow()
|
||||
if (ti->foreign_exception_state != __cxa_thread_info::none)
|
||||
{
|
||||
ti->foreign_exception_state = __cxa_thread_info::rethrown;
|
||||
_Unwind_Exception *e = (_Unwind_Exception*)ex;
|
||||
_Unwind_Exception *e = reinterpret_cast<_Unwind_Exception*>(ex);
|
||||
_Unwind_Reason_Code err = _Unwind_Resume_or_Rethrow(e);
|
||||
report_failure(err, ex);
|
||||
return;
|
||||
@ -881,8 +891,8 @@ static std::type_info *get_type_info_entry(_Unwind_Context *context,
|
||||
if (offset == 0) { return 0; }
|
||||
|
||||
// ...so we need to resolve it
|
||||
return (std::type_info*)resolve_indirect_value(context,
|
||||
lsda->type_table_encoding, offset, start);
|
||||
return reinterpret_cast<std::type_info*>(resolve_indirect_value(context,
|
||||
lsda->type_table_encoding, offset, start));
|
||||
}
|
||||
|
||||
|
||||
@ -896,13 +906,13 @@ static bool check_type_signature(__cxa_exception *ex,
|
||||
const std::type_info *type,
|
||||
void *&adjustedPtr)
|
||||
{
|
||||
void *exception_ptr = (void*)(ex+1);
|
||||
void *exception_ptr = static_cast<void*>(ex+1);
|
||||
const std::type_info *ex_type = ex ? ex->exceptionType : 0;
|
||||
|
||||
bool is_ptr = ex ? ex_type->__is_pointer_p() : false;
|
||||
if (is_ptr)
|
||||
{
|
||||
exception_ptr = *(void**)exception_ptr;
|
||||
exception_ptr = *static_cast<void**>(exception_ptr);
|
||||
}
|
||||
// Always match a catchall, even with a foreign exception
|
||||
//
|
||||
@ -974,7 +984,7 @@ static handler_type check_action_record(_Unwind_Context *context,
|
||||
{
|
||||
bool matched = false;
|
||||
*selector = filter;
|
||||
#ifdef __arm__
|
||||
#if defined(__arm__) && !defined(__ARM_DWARF_EH__)
|
||||
filter++;
|
||||
std::type_info *handler_type = get_type_info_entry(context, lsda, filter--);
|
||||
while (handler_type)
|
||||
@ -987,7 +997,7 @@ static handler_type check_action_record(_Unwind_Context *context,
|
||||
handler_type = get_type_info_entry(context, lsda, filter--);
|
||||
}
|
||||
#else
|
||||
unsigned char *type_index = ((unsigned char*)lsda->type_table - filter - 1);
|
||||
unsigned char *type_index = reinterpret_cast<unsigned char*>(lsda->type_table) - filter - 1;
|
||||
while (*type_index)
|
||||
{
|
||||
std::type_info *handler_type = get_type_info_entry(context, lsda, *(type_index++));
|
||||
@ -1019,7 +1029,7 @@ static handler_type check_action_record(_Unwind_Context *context,
|
||||
static void pushCleanupException(_Unwind_Exception *exceptionObject,
|
||||
__cxa_exception *ex)
|
||||
{
|
||||
#ifdef __arm__
|
||||
#if defined(__arm__) && !defined(__ARM_DWARF_EH__)
|
||||
__cxa_thread_info *info = thread_info_fast();
|
||||
if (ex)
|
||||
{
|
||||
@ -1064,8 +1074,13 @@ BEGIN_PERSONALITY_FUNCTION(__gxx_personality_v0)
|
||||
realEx = realExceptionFromException(ex);
|
||||
}
|
||||
|
||||
#if defined(__arm__) && !defined(__ARM_DWARF_EH__)
|
||||
unsigned char *lsda_addr =
|
||||
(unsigned char*)_Unwind_GetLanguageSpecificData(context);
|
||||
static_cast<unsigned char*>(_Unwind_GetLanguageSpecificData(context));
|
||||
#else
|
||||
unsigned char *lsda_addr =
|
||||
reinterpret_cast<unsigned char*>(static_cast<uintptr_t>(_Unwind_GetLanguageSpecificData(context)));
|
||||
#endif
|
||||
|
||||
// No LSDA implies no landing pads - try the next frame
|
||||
if (0 == lsda_addr) { return continueUnwinding(exceptionObject, context); }
|
||||
@ -1114,8 +1129,8 @@ BEGIN_PERSONALITY_FUNCTION(__gxx_personality_v0)
|
||||
if (ex)
|
||||
{
|
||||
saveLandingPad(context, exceptionObject, ex, selector, action.landing_pad);
|
||||
ex->languageSpecificData = (const char*)lsda_addr;
|
||||
ex->actionRecord = (const char*)action.action_record;
|
||||
ex->languageSpecificData = reinterpret_cast<const char*>(lsda_addr);
|
||||
ex->actionRecord = reinterpret_cast<const char*>(action.action_record);
|
||||
// ex->adjustedPtr is set when finding the action record.
|
||||
}
|
||||
return _URC_HANDLER_FOUND;
|
||||
@ -1161,9 +1176,9 @@ BEGIN_PERSONALITY_FUNCTION(__gxx_personality_v0)
|
||||
}
|
||||
|
||||
|
||||
_Unwind_SetIP(context, (unsigned long)action.landing_pad);
|
||||
_Unwind_SetIP(context, reinterpret_cast<unsigned long>(action.landing_pad));
|
||||
_Unwind_SetGR(context, __builtin_eh_return_data_regno(0),
|
||||
(unsigned long)exceptionObject);
|
||||
reinterpret_cast<unsigned long>(exceptionObject));
|
||||
_Unwind_SetGR(context, __builtin_eh_return_data_regno(1), selector);
|
||||
|
||||
return _URC_INSTALL_CONTEXT;
|
||||
@ -1187,7 +1202,7 @@ extern "C" void *__cxa_begin_catch(void *e)
|
||||
__cxa_thread_info *ti = thread_info();
|
||||
__cxa_eh_globals *globals = &ti->globals;
|
||||
globals->uncaughtExceptions--;
|
||||
_Unwind_Exception *exceptionObject = (_Unwind_Exception*)e;
|
||||
_Unwind_Exception *exceptionObject = static_cast<_Unwind_Exception*>(e);
|
||||
|
||||
if (isCXXException(exceptionObject->exception_class))
|
||||
{
|
||||
@ -1241,12 +1256,12 @@ extern "C" void *__cxa_begin_catch(void *e)
|
||||
{
|
||||
std::terminate();
|
||||
}
|
||||
globals->caughtExceptions = (__cxa_exception*)exceptionObject;
|
||||
globals->caughtExceptions = reinterpret_cast<__cxa_exception*>(exceptionObject);
|
||||
ti->foreign_exception_state = __cxa_thread_info::caught;
|
||||
}
|
||||
// exceptionObject is the pointer to the _Unwind_Exception within the
|
||||
// __cxa_exception. The throw object is after this
|
||||
return ((char*)exceptionObject + sizeof(_Unwind_Exception));
|
||||
return (reinterpret_cast<char*>(exceptionObject) + sizeof(_Unwind_Exception));
|
||||
}
|
||||
|
||||
|
||||
@ -1270,7 +1285,7 @@ extern "C" void __cxa_end_catch()
|
||||
globals->caughtExceptions = 0;
|
||||
if (ti->foreign_exception_state != __cxa_thread_info::rethrown)
|
||||
{
|
||||
_Unwind_Exception *e = (_Unwind_Exception*)ti->globals.caughtExceptions;
|
||||
_Unwind_Exception *e = reinterpret_cast<_Unwind_Exception*>(ti->globals.caughtExceptions);
|
||||
e->exception_cleanup(_URC_FOREIGN_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
ti->foreign_exception_state = __cxa_thread_info::none;
|
||||
@ -1332,7 +1347,7 @@ extern "C" std::type_info *__cxa_current_exception_type()
|
||||
*/
|
||||
extern "C" void __cxa_call_unexpected(void*exception)
|
||||
{
|
||||
_Unwind_Exception *exceptionObject = (_Unwind_Exception*)exception;
|
||||
_Unwind_Exception *exceptionObject = static_cast<_Unwind_Exception*>(exception);
|
||||
if (exceptionObject->exception_class == exception_class)
|
||||
{
|
||||
__cxa_exception *ex = exceptionFromPointer(exceptionObject);
|
||||
@ -1483,7 +1498,7 @@ namespace std
|
||||
return ATOMIC_LOAD(&terminateHandler);
|
||||
}
|
||||
}
|
||||
#ifdef __arm__
|
||||
#if defined(__arm__) && !defined(__ARM_DWARF_EH__)
|
||||
extern "C" _Unwind_Exception *__cxa_get_cleanup(void)
|
||||
{
|
||||
__cxa_thread_info *info = thread_info_fast();
|
||||
|
@ -70,18 +70,45 @@
|
||||
#ifdef __arm__
|
||||
// ARM ABI - 32-bit guards.
|
||||
typedef uint32_t guard_t;
|
||||
static const uint32_t LOCKED = ((guard_t)1) << 31;
|
||||
typedef uint32_t guard_lock_t;
|
||||
static const uint32_t LOCKED = static_cast<guard_t>(1) << 31;
|
||||
static const uint32_t INITIALISED = 1;
|
||||
#else
|
||||
#define LOCK_PART(guard) (guard)
|
||||
#define INIT_PART(guard) (guard)
|
||||
#elif defined(_LP64)
|
||||
typedef uint64_t guard_t;
|
||||
typedef uint64_t guard_lock_t;
|
||||
# if defined(__LITTLE_ENDIAN__)
|
||||
static const guard_t LOCKED = ((guard_t)1) << 63;
|
||||
static const guard_t LOCKED = static_cast<guard_t>(1) << 63;
|
||||
static const guard_t INITIALISED = 1;
|
||||
# else
|
||||
static const guard_t LOCKED = 1;
|
||||
static const guard_t INITIALISED = ((guard_t)1) << 56;
|
||||
static const guard_t INITIALISED = static_cast<guard_t>(1) << 56;
|
||||
# endif
|
||||
#define LOCK_PART(guard) (guard)
|
||||
#define INIT_PART(guard) (guard)
|
||||
#else
|
||||
typedef uint32_t guard_lock_t;
|
||||
# if defined(__LITTLE_ENDIAN__)
|
||||
typedef struct {
|
||||
uint32_t init_half;
|
||||
uint32_t lock_half;
|
||||
} guard_t;
|
||||
static const uint32_t LOCKED = static_cast<guard_lock_t>(1) << 31;
|
||||
static const uint32_t INITIALISED = 1;
|
||||
# else
|
||||
typedef struct {
|
||||
uint32_t init_half;
|
||||
uint32_t lock_half;
|
||||
} guard_t;
|
||||
_Static_assert(sizeof(guard_t) == sizeof(uint64_t), "");
|
||||
static const uint32_t LOCKED = 1;
|
||||
static const uint32_t INITIALISED = static_cast<guard_lock_t>(1) << 24;
|
||||
# endif
|
||||
#define LOCK_PART(guard) (&(guard)->lock_half)
|
||||
#define INIT_PART(guard) (&(guard)->init_half)
|
||||
#endif
|
||||
static const guard_lock_t INITIAL = 0;
|
||||
|
||||
/**
|
||||
* Acquires a lock on a guard, returning 0 if the object has already been
|
||||
@ -90,42 +117,49 @@ static const guard_t INITIALISED = ((guard_t)1) << 56;
|
||||
*/
|
||||
extern "C" int __cxa_guard_acquire(volatile guard_t *guard_object)
|
||||
{
|
||||
guard_lock_t old;
|
||||
// Not an atomic read, doesn't establish a happens-before relationship, but
|
||||
// if one is already established and we end up seeing an initialised state
|
||||
// then it's a fast path, otherwise we'll do something more expensive than
|
||||
// this test anyway...
|
||||
if ((INITIALISED == *guard_object)) { return 0; }
|
||||
if (INITIALISED == *INIT_PART(guard_object))
|
||||
return 0;
|
||||
// Spin trying to do the initialisation
|
||||
while (1)
|
||||
for (;;)
|
||||
{
|
||||
// Loop trying to move the value of the guard from 0 (not
|
||||
// locked, not initialised) to the locked-uninitialised
|
||||
// position.
|
||||
switch (__sync_val_compare_and_swap(guard_object, 0, LOCKED))
|
||||
{
|
||||
// If the old value was 0, we succeeded, so continue
|
||||
// initialising
|
||||
case 0:
|
||||
old = __sync_val_compare_and_swap(LOCK_PART(guard_object),
|
||||
INITIAL, LOCKED);
|
||||
if (old == INITIAL) {
|
||||
// Lock obtained. If lock and init bit are
|
||||
// in separate words, check for init race.
|
||||
if (INIT_PART(guard_object) == LOCK_PART(guard_object))
|
||||
return 1;
|
||||
// If this was already initialised, return and let the caller skip
|
||||
// initialising it again.
|
||||
case INITIALISED:
|
||||
return 0;
|
||||
// If it is locked by another thread, relinquish the CPU and try
|
||||
// again later.
|
||||
case LOCKED:
|
||||
case LOCKED | INITIALISED:
|
||||
sched_yield();
|
||||
break;
|
||||
// If it is some other value, then something has gone badly wrong.
|
||||
// Give up.
|
||||
default:
|
||||
fprintf(stderr, "Invalid state detected attempting to lock static initialiser.\n");
|
||||
abort();
|
||||
if (INITIALISED != *INIT_PART(guard_object))
|
||||
return 1;
|
||||
|
||||
// No need for a memory barrier here,
|
||||
// see first comment.
|
||||
*LOCK_PART(guard_object) = INITIAL;
|
||||
return 0;
|
||||
}
|
||||
// If lock and init bit are in the same word, check again
|
||||
// if we are done.
|
||||
if (INIT_PART(guard_object) == LOCK_PART(guard_object) &&
|
||||
old == INITIALISED)
|
||||
return 0;
|
||||
|
||||
assert(old == LOCKED);
|
||||
// Another thread holds the lock.
|
||||
// If lock and init bit are in different words, check
|
||||
// if we are done before yielding and looping.
|
||||
if (INIT_PART(guard_object) != LOCK_PART(guard_object) &&
|
||||
INITIALISED == *INIT_PART(guard_object))
|
||||
return 0;
|
||||
sched_yield();
|
||||
}
|
||||
//__builtin_unreachable();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,7 +169,8 @@ extern "C" int __cxa_guard_acquire(volatile guard_t *guard_object)
|
||||
extern "C" void __cxa_guard_abort(volatile guard_t *guard_object)
|
||||
{
|
||||
__attribute__((unused))
|
||||
bool reset = __sync_bool_compare_and_swap(guard_object, LOCKED, 0);
|
||||
bool reset = __sync_bool_compare_and_swap(LOCK_PART(guard_object),
|
||||
LOCKED, INITIAL);
|
||||
assert(reset);
|
||||
}
|
||||
/**
|
||||
@ -144,9 +179,15 @@ extern "C" void __cxa_guard_abort(volatile guard_t *guard_object)
|
||||
*/
|
||||
extern "C" void __cxa_guard_release(volatile guard_t *guard_object)
|
||||
{
|
||||
guard_lock_t old;
|
||||
if (INIT_PART(guard_object) == LOCK_PART(guard_object))
|
||||
old = LOCKED;
|
||||
else
|
||||
old = INITIAL;
|
||||
__attribute__((unused))
|
||||
bool reset = __sync_bool_compare_and_swap(guard_object, LOCKED, INITIALISED);
|
||||
bool reset = __sync_bool_compare_and_swap(INIT_PART(guard_object),
|
||||
old, INITIALISED);
|
||||
assert(reset);
|
||||
if (INIT_PART(guard_object) != LOCK_PART(guard_object))
|
||||
*LOCK_PART(guard_object) = INITIAL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,7 +95,7 @@ bad_array_new_length& bad_array_new_length::operator=(const bad_array_new_length
|
||||
}
|
||||
|
||||
__attribute__((weak))
|
||||
const char *bad_array_new_length::what() const throw()
|
||||
const char* bad_array_new_length::what() const throw()
|
||||
{
|
||||
return "std::bad_array_new_length";
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ namespace std
|
||||
virtual const char* what() const throw();
|
||||
};
|
||||
|
||||
class bad_array_new_length: public exception
|
||||
class bad_array_new_length: public bad_alloc
|
||||
{
|
||||
public:
|
||||
bad_array_new_length() throw();
|
||||
|
@ -35,7 +35,7 @@ type_info::~type_info() {}
|
||||
|
||||
bool type_info::operator==(const type_info &other) const
|
||||
{
|
||||
#ifdef LIBCXXRT_MERGED_TYPEINFO
|
||||
#ifdef LIBCXXRT_MERGED_TYPEINFO
|
||||
return __type_name == other.__type_name;
|
||||
#else
|
||||
return __type_name == other.__type_name || strcmp(__type_name, other.__type_name) == 0;
|
||||
@ -104,7 +104,7 @@ extern "C" char* __cxa_demangle(const char* mangled_name,
|
||||
}
|
||||
if (*n < len+1)
|
||||
{
|
||||
buf = (char*)realloc(buf, len+1);
|
||||
buf = static_cast<char*>(realloc(buf, len+1));
|
||||
}
|
||||
if (0 != buf)
|
||||
{
|
||||
|
@ -218,6 +218,6 @@ _Unwind_Reason_Code name(_Unwind_State state,\
|
||||
break;\
|
||||
}\
|
||||
}\
|
||||
_Unwind_SetGR (context, 12, (unsigned long)exceptionObject);\
|
||||
_Unwind_SetGR (context, 12, reinterpret_cast<unsigned long>(exceptionObject));\
|
||||
|
||||
#define CALL_PERSONALITY_FUNCTION(name) name(state,exceptionObject,context)
|
||||
|
@ -27,7 +27,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __arm__
|
||||
#if defined(__arm__) && !defined(__ARM_DWARF_EH__)
|
||||
#include "unwind-arm.h"
|
||||
#else
|
||||
#include "unwind-itanium.h"
|
||||
|
Loading…
Reference in New Issue
Block a user