@@ -54,13 +54,13 @@ #endif #ifndef HAVE_ARM_EHABI_EXCEPTIONS # define PERSONALITY_FUNC(func) \ _Unwind_Reason_Code \ - func(int version, int actions, uint64_t ex_class, \ + func(int version, int actions, uint64_t exClass, \ struct _Unwind_Exception *ex, struct _Unwind_Context *ctx) -# define CALL_PERSONALITY(func) func(version, actions, ex_class, ex, ctx) +# define CALL_PERSONALITY(func) func(version, actions, exClass, ex, ctx) #else # define PERSONALITY_FUNC(func) \ _Unwind_Reason_Code \ func(uint32_t state, struct _Unwind_Exception *ex, \ struct _Unwind_Context *ctx) @@ -134,24 +134,24 @@ #else /* From "Exception Handling ABI for the ARM(R) Architecture" */ struct { uint32_t reserved1, reserved2, reserved3, reserved4; uint32_t reserved; - } unwinder_cache; + } unwinderCache; struct { uint32_t sp; - uint32_t bitpattern[5]; - } barrier_cache; + uint32_t bitPattern[5]; + } barrierCache; struct { - uint32_t bitpattern[4]; - } cleanup_cache; + uint32_t bitPattern[4]; + } cleanupCache; struct { uint32_t fnstart; uint32_t *ehtp; uint32_t additional; uint32_t reserved1; - } pr_cache; + } PRCache; long long int : 0; #endif } exception; id object; #ifndef HAVE_ARM_EHABI_EXCEPTIONS @@ -159,16 +159,16 @@ intptr_t filter; #endif }; struct lsda { - uintptr_t region_start, landingpads_start; - uint8_t typestable_enc; - const uint8_t *typestable; - uintptr_t typestable_base; - uint8_t callsites_enc; - const uint8_t *callsites, *actiontable; + uintptr_t regionStart, landingpadsStart; + uint8_t typesTableEnc; + const uint8_t *typesTable; + uintptr_t typesTableBase; + uint8_t callsitesEnc; + const uint8_t *callsites, *actionTable; }; extern _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *); extern void _Unwind_DeleteException(struct _Unwind_Exception *); extern void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context *); @@ -202,14 +202,14 @@ \ return _URC_CONTINUE_UNWIND; \ } static inline uintptr_t -_Unwind_GetGR(struct _Unwind_Context *ctx, int regno) +_Unwind_GetGR(struct _Unwind_Context *ctx, int regNo) { uintptr_t value; - _Unwind_VRS_Get(ctx, 0, regno, 0, &value); + _Unwind_VRS_Get(ctx, 0, regNo, 0, &value); return value; } static inline uintptr_t _Unwind_GetIP(struct _Unwind_Context *ctx) @@ -216,13 +216,13 @@ { return _Unwind_GetGR(ctx, 15) & ~1; } static inline void -_Unwind_SetGR(struct _Unwind_Context *ctx, int regno, uintptr_t value) +_Unwind_SetGR(struct _Unwind_Context *ctx, int regNo, uintptr_t value) { - _Unwind_VRS_Set(ctx, 0, regno, 0, &value); + _Unwind_VRS_Set(ctx, 0, regNo, 0, &value); } static inline void _Unwind_SetIP(struct _Unwind_Context *ctx, uintptr_t value) { @@ -239,24 +239,24 @@ extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT, PDISPATCHER_CONTEXT, _Unwind_Reason_Code (*)(int, int, uint64_t, struct _Unwind_Exception *, struct _Unwind_Context *)); #endif -static objc_uncaught_exception_handler uncaught_exception_handler; -static struct objc_exception emergency_exceptions[NUM_EMERGENCY_EXCEPTIONS]; +static objc_uncaught_exception_handler uncaughtExceptionHandler; +static struct objc_exception emergencyExceptions[NUM_EMERGENCY_EXCEPTIONS]; #ifdef OF_HAVE_THREADS -static of_spinlock_t emergency_exceptions_spinlock; +static of_spinlock_t emergencyExceptionsSpinlock; OF_CONSTRUCTOR() { - if (!of_spinlock_new(&emergency_exceptions_spinlock)) + if (!of_spinlock_new(&emergencyExceptionsSpinlock)) OBJC_ERROR("Cannot create spinlock!") } #endif static uint64_t -read_uleb128(const uint8_t **ptr) +readULEB128(const uint8_t **ptr) { uint64_t value = 0; uint8_t shift = 0; do { @@ -267,27 +267,27 @@ return value; } static int64_t -read_sleb128(const uint8_t **ptr) +readSLEB128(const uint8_t **ptr) { - const uint8_t *oldptr = *ptr; + const uint8_t *oldPtr = *ptr; uint8_t bits; int64_t value; - value = read_uleb128(ptr); - bits = (*ptr - oldptr) * 7; + value = readULEB128(ptr); + bits = (*ptr - oldPtr) * 7; if (bits < 64 && value & (1 << (bits - 1))) value |= -(1 << bits); return value; } static uintptr_t -get_base(struct _Unwind_Context *ctx, uint8_t enc) +getBase(struct _Unwind_Context *ctx, uint8_t enc) { if (enc == DW_EH_PE_omit) return 0; switch (enc & 0x70) { @@ -312,11 +312,11 @@ OBJC_ERROR("Unknown encoding!") } static size_t -size_for_encoding(uint8_t enc) +sizeForEncoding(uint8_t enc) { if (enc == DW_EH_PE_omit) return 0; switch (enc & 0x07) { @@ -332,11 +332,11 @@ OBJC_ERROR("Unknown encoding!") } static uint64_t -read_value(uint8_t enc, const uint8_t **ptr) +readValue(uint8_t enc, const uint8_t **ptr) { uint64_t value; if (enc == DW_EH_PE_aligned) OBJC_ERROR("DW_EH_PE_aligned is not implemented!") @@ -344,27 +344,27 @@ #define READ(type) \ { \ type tmp; \ memcpy(&tmp, *ptr, sizeof(type)); \ value = tmp; \ - *ptr += size_for_encoding(enc); \ + *ptr += sizeForEncoding(enc); \ break; \ } switch (enc & 0x0F) { case DW_EH_PE_absptr: READ(uintptr_t) case DW_EH_PE_uleb128: - value = read_uleb128(ptr); + value = readULEB128(ptr); break; case DW_EH_PE_udata2: READ(uint16_t) case DW_EH_PE_udata4: READ(uint32_t) case DW_EH_PE_udata8: READ(uint64_t) case DW_EH_PE_sleb128: - value = read_sleb128(ptr); + value = readSLEB128(ptr); break; case DW_EH_PE_sdata2: READ(int16_t) case DW_EH_PE_sdata4: READ(int32_t) @@ -378,11 +378,11 @@ return value; } #ifndef HAVE_ARM_EHABI_EXCEPTIONS static uint64_t -resolve_value(uint64_t value, uint8_t enc, const uint8_t *start, uint64_t base) +resolveValue(uint64_t value, uint8_t enc, const uint8_t *start, uint64_t base) { if (value == 0) return 0; value += ((enc & 0x70) == DW_EH_PE_pcrel ? (uintptr_t)start : base); @@ -393,97 +393,97 @@ return value; } #endif static void -read_lsda(struct _Unwind_Context *ctx, const uint8_t *ptr, struct lsda *lsda) -{ - uint8_t landingpads_start_enc; - uintptr_t callsites_size; - - lsda->region_start = _Unwind_GetRegionStart(ctx); - lsda->landingpads_start = lsda->region_start; - lsda->typestable = NULL; - - if ((landingpads_start_enc = *ptr++) != DW_EH_PE_omit) - lsda->landingpads_start = - (uintptr_t)read_value(landingpads_start_enc, &ptr); - - if ((lsda->typestable_enc = *ptr++) != DW_EH_PE_omit) { - uintptr_t tmp = (uintptr_t)read_uleb128(&ptr); - lsda->typestable = ptr + tmp; - } - - lsda->typestable_base = get_base(ctx, lsda->typestable_enc); - - lsda->callsites_enc = *ptr++; - callsites_size = (uintptr_t)read_uleb128(&ptr); - lsda->callsites = ptr; - - lsda->actiontable = lsda->callsites + callsites_size; +readLSDA(struct _Unwind_Context *ctx, const uint8_t *ptr, struct lsda *LSDA) +{ + uint8_t landingpadsStartEnc; + uintptr_t callsitesSize; + + LSDA->regionStart = _Unwind_GetRegionStart(ctx); + LSDA->landingpadsStart = LSDA->regionStart; + LSDA->typesTable = NULL; + + if ((landingpadsStartEnc = *ptr++) != DW_EH_PE_omit) + LSDA->landingpadsStart = + (uintptr_t)readValue(landingpadsStartEnc, &ptr); + + if ((LSDA->typesTableEnc = *ptr++) != DW_EH_PE_omit) { + uintptr_t tmp = (uintptr_t)readULEB128(&ptr); + LSDA->typesTable = ptr + tmp; + } + + LSDA->typesTableBase = getBase(ctx, LSDA->typesTableEnc); + + LSDA->callsitesEnc = *ptr++; + callsitesSize = (uintptr_t)readULEB128(&ptr); + LSDA->callsites = ptr; + + LSDA->actionTable = LSDA->callsites + callsitesSize; } static bool -find_callsite(struct _Unwind_Context *ctx, struct lsda *lsda, - uintptr_t *landingpad, const uint8_t **actionrecords) +findCallsite(struct _Unwind_Context *ctx, struct lsda *LSDA, + uintptr_t *landingpad, const uint8_t **actionRecords) { - uintptr_t ip = _Unwind_GetIP(ctx); - const uint8_t *ptr = lsda->callsites; + uintptr_t IP = _Unwind_GetIP(ctx); + const uint8_t *ptr = LSDA->callsites; *landingpad = 0; - *actionrecords = NULL; + *actionRecords = NULL; #ifndef HAVE_SJLJ_EXCEPTIONS - while (ptr < lsda->actiontable) { - uintptr_t callsite_start, callsite_len, callsite_landingpad; - uintptr_t callsite_action; - - callsite_start = lsda->region_start + - (uintptr_t)read_value(lsda->callsites_enc, &ptr); - callsite_len = (uintptr_t)read_value(lsda->callsites_enc, &ptr); - callsite_landingpad = - (uintptr_t)read_value(lsda->callsites_enc, &ptr); - callsite_action = (uintptr_t)read_uleb128(&ptr); + while (ptr < LSDA->actionTable) { + uintptr_t callsiteStart, callsiteLength, callsiteLandingpad; + uintptr_t callsiteAction; + + callsiteStart = LSDA->regionStart + + (uintptr_t)readValue(LSDA->callsitesEnc, &ptr); + callsiteLength = (uintptr_t)readValue(LSDA->callsitesEnc, &ptr); + callsiteLandingpad = + (uintptr_t)readValue(LSDA->callsitesEnc, &ptr); + callsiteAction = (uintptr_t)readULEB128(&ptr); /* We can stop if we passed IP, as the table is sorted */ - if (callsite_start >= ip) + if (callsiteStart >= IP) break; - if (callsite_start + callsite_len >= ip) { - if (callsite_landingpad != 0) - *landingpad = lsda->landingpads_start + - callsite_landingpad; - if (callsite_action != 0) - *actionrecords = lsda->actiontable + - callsite_action - 1; + if (callsiteStart + callsiteLength >= IP) { + if (callsiteLandingpad != 0) + *landingpad = LSDA->landingpadsStart + + callsiteLandingpad; + if (callsiteAction != 0) + *actionRecords = LSDA->actionTable + + callsiteAction - 1; return true; } } return false; #else - uintptr_t callsite_landingpad, callsite_action; + uintptr_t callsiteLandingpad, callsiteAction; if ((intptr_t)ip < 1) return false; do { - callsite_landingpad = (uintptr_t)read_uleb128(&ptr); - callsite_action = (uintptr_t)read_uleb128(&ptr); + callsiteLandingpad = (uintptr_t)readULEB128(&ptr); + callsiteAction = (uintptr_t)readULEB128(&ptr); } while (--ip > 1); - *landingpad = callsite_landingpad + 1; - if (callsite_action != 0) - *actionrecords = lsda->actiontable + callsite_action - 1; + *landingpad = callsiteLandingpad + 1; + if (callsiteAction != 0) + *actionRecords = LSDA->actionTable + callsiteAction - 1; return true; #endif } static bool -class_matches(Class class, id object) +classMatches(Class class, id object) { Class iter; if (class == Nil) return true; @@ -498,28 +498,28 @@ return false; } static uint8_t -find_actionrecord(const uint8_t *actionrecords, struct lsda *lsda, int actions, - bool foreign, struct objc_exception *e, intptr_t *filtervalue) +findActionRecord(const uint8_t *actionRecords, struct lsda *LSDA, int actions, + bool foreign, struct objc_exception *e, intptr_t *filterPtr) { const uint8_t *ptr; intptr_t filter, displacement; do { - ptr = actionrecords; - filter = (intptr_t)read_sleb128(&ptr); + ptr = actionRecords; + filter = (intptr_t)readSLEB128(&ptr); /* - * Get the next action record. Since read_sleb128 modifies ptr, + * Get the next action record. Since readSLEB128() modifies ptr, * we first set the actionrecord to the current ptr and then * add the displacement. */ - actionrecords = ptr; - displacement = (intptr_t)read_sleb128(&ptr); - actionrecords += displacement; + actionRecords = ptr; + displacement = (intptr_t)readSLEB128(&ptr); + actionRecords += displacement; if (filter > 0 && !(actions & _UA_FORCE_UNWIND) && !foreign) { Class class; const char *className; uintptr_t c; @@ -526,17 +526,17 @@ const uint8_t *tmp; #ifndef HAVE_ARM_EHABI_EXCEPTIONS uintptr_t i; - i = filter * size_for_encoding(lsda->typestable_enc); - tmp = lsda->typestable - i; - c = (uintptr_t)read_value(lsda->typestable_enc, &tmp); - c = (uintptr_t)resolve_value(c, lsda->typestable_enc, - lsda->typestable - i, lsda->typestable_base); + i = filter * sizeForEncoding(LSDA->typesTableEnc); + tmp = LSDA->typesTable - i; + c = (uintptr_t)readValue(LSDA->typesTableEnc, &tmp); + c = (uintptr_t)resolveValue(c, LSDA->typesTableEnc, + LSDA->typesTable - i, LSDA->typesTableBase); #else - tmp = lsda->typestable - (filter * 4); + tmp = LSDA->typesTable - (filter * 4); c = *(uintptr_t *)(void *)tmp; if (c != 0) { c += (uintptr_t)tmp; # if defined(OF_LINUX) || defined(OF_NETBSD) @@ -551,12 +551,12 @@ strcmp(className, "@id") != 0) class = objc_getRequiredClass(className); else class = Nil; - if (class_matches(class, e->object)) { - *filtervalue = filter; + if (classMatches(class, e->object)) { + *filterPtr = filter; return HANDLER_FOUND; } } else if (filter == 0) return CLEANUP_FOUND; else if (filter < 0) @@ -571,20 +571,20 @@ #endif PERSONALITY_FUNC(PERSONALITY) { #ifdef HAVE_ARM_EHABI_EXCEPTIONS int version = 1; - uint64_t ex_class = ex->class; + uint64_t exClass = ex->class; int actions; switch (state) { case 0: /* _US_VIRTUAL_UNWIND_FRAME */ actions = _UA_SEARCH_PHASE; break; case 1: /* _US_UNWIND_FRAME_STARTING */ actions = _UA_CLEANUP_PHASE; - if ((ex->barrier_cache.sp == _Unwind_GetGR(ctx, 13)) != 0) + if ((ex->barrierCache.sp == _Unwind_GetGR(ctx, 13)) != 0) actions |= _UA_HANDLER_FRAME; break; case 2: /* _US_UNWIND_FRAME_RESUME */ CONTINUE_UNWIND; default: @@ -592,19 +592,19 @@ } _Unwind_SetGR(ctx, 12, (uintptr_t)ex); #endif struct objc_exception *e = (struct objc_exception *)ex; - bool foreign = (ex_class != GNUCOBJC_EXCEPTION_CLASS); - const uint8_t *lsda_addr, *actionrecords; - struct lsda lsda; + bool foreign = (exClass != GNUCOBJC_EXCEPTION_CLASS); + const uint8_t *LSDAAddr, *actionRecords; + struct lsda LSDA; uintptr_t landingpad = 0; uint8_t found = 0; intptr_t filter = 0; if (foreign) { - switch (ex_class) { + switch (exClass) { #ifdef CXX_PERSONALITY case GNUCCXX0_EXCEPTION_CLASS: case CLNGCXX0_EXCEPTION_CLASS: if (cxx_personality != NULL) return CALL_PERSONALITY(cxx_personality); @@ -636,30 +636,30 @@ _Unwind_SetGR(ctx, __builtin_eh_return_data_regno(1), e->filter); _Unwind_SetIP(ctx, e->landingpad); #else _Unwind_SetGR(ctx, __builtin_eh_return_data_regno(1), - ex->barrier_cache.bitpattern[1]); - _Unwind_SetIP(ctx, ex->barrier_cache.bitpattern[3]); + ex->barrierCache.bitPattern[1]); + _Unwind_SetIP(ctx, ex->barrierCache.bitPattern[3]); #endif _Unwind_DeleteException(ex); return _URC_INSTALL_CONTEXT; } /* No LSDA -> nothing to handle */ - if ((lsda_addr = _Unwind_GetLanguageSpecificData(ctx)) == NULL) + if ((LSDAAddr = _Unwind_GetLanguageSpecificData(ctx)) == NULL) CONTINUE_UNWIND; - read_lsda(ctx, lsda_addr, &lsda); + readLSDA(ctx, LSDAAddr, &LSDA); - if (!find_callsite(ctx, &lsda, &landingpad, &actionrecords)) + if (!findCallsite(ctx, &LSDA, &landingpad, &actionRecords)) CONTINUE_UNWIND; - if (landingpad != 0 && actionrecords != NULL) - found = find_actionrecord(actionrecords, &lsda, actions, + if (landingpad != 0 && actionRecords != NULL) + found = findActionRecord(actionRecords, &LSDA, actions, foreign, e, &filter); else if (landingpad != 0) found = CLEANUP_FOUND; if (found == 0) @@ -672,13 +672,13 @@ /* Cache it so we don't have to search it again in phase 2 */ #ifndef HAVE_ARM_EHABI_EXCEPTIONS e->landingpad = landingpad; e->filter = filter; #else - ex->barrier_cache.sp = _Unwind_GetGR(ctx, 13); - ex->barrier_cache.bitpattern[1] = filter; - ex->barrier_cache.bitpattern[3] = landingpad; + ex->barrierCache.sp = _Unwind_GetGR(ctx, 13); + ex->barrierCache.bitPattern[1] = filter; + ex->barrierCache.bitPattern[3] = landingpad; #endif return _URC_HANDLER_FOUND; } else if (actions & _UA_CLEANUP_PHASE) { if (!(found & CLEANUP_FOUND)) @@ -700,21 +700,22 @@ { free(ex); } static void -cleanup_emergency(_Unwind_Reason_Code reason, struct _Unwind_Exception *ex) +emergencyExceptionCleanup(_Unwind_Reason_Code reason, + struct _Unwind_Exception *ex) { #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&emergency_exceptions_spinlock)) + if (!of_spinlock_lock(&emergencyExceptionsSpinlock)) OBJC_ERROR("Cannot lock spinlock!"); #endif ex->class = 0; #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&emergency_exceptions_spinlock)) + if (!of_spinlock_unlock(&emergencyExceptionsSpinlock)) OBJC_ERROR("Cannot unlock spinlock!"); #endif } void @@ -723,49 +724,50 @@ struct objc_exception *e = calloc(1, sizeof(*e)); bool emergency = false; if (e == NULL) { #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&emergency_exceptions_spinlock)) + if (!of_spinlock_lock(&emergencyExceptionsSpinlock)) OBJC_ERROR("Cannot lock spinlock!"); #endif for (uint_fast8_t i = 0; i < NUM_EMERGENCY_EXCEPTIONS; i++) { - if (emergency_exceptions[i].exception.class == 0) { - e = &emergency_exceptions[i]; + if (emergencyExceptions[i].exception.class == 0) { + e = &emergencyExceptions[i]; e->exception.class = GNUCOBJC_EXCEPTION_CLASS; emergency = true; break; } } #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&emergency_exceptions_spinlock)) + if (!of_spinlock_unlock(&emergencyExceptionsSpinlock)) OBJC_ERROR("Cannot lock spinlock!"); #endif } if (e == NULL) OBJC_ERROR("Not enough memory to allocate exception!") e->exception.class = GNUCOBJC_EXCEPTION_CLASS; - e->exception.cleanup = (emergency ? cleanup_emergency : cleanup); + e->exception.cleanup = (emergency + ? emergencyExceptionCleanup : cleanup); e->object = object; if (_Unwind_RaiseException(&e->exception) == _URC_END_OF_STACK && - uncaught_exception_handler != NULL) - uncaught_exception_handler(object); + uncaughtExceptionHandler != NULL) + uncaughtExceptionHandler(object); OBJC_ERROR("_Unwind_RaiseException() returned!") } objc_uncaught_exception_handler objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler handler) { - objc_uncaught_exception_handler old = uncaught_exception_handler; - uncaught_exception_handler = handler; + objc_uncaught_exception_handler old = uncaughtExceptionHandler; + uncaughtExceptionHandler = handler; return old; } #ifdef HAVE_SEH_EXCEPTIONS