22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#include <string.h>
#import "ObjFWRT.h"
#import "private.h"
#import "macros.h"
#ifdef OF_HAVE_THREADS
# include "mutex.h"
#endif
#ifdef HAVE_SEH_EXCEPTIONS
# include <windows.h>
#endif
#if defined(HAVE_DWARF_EXCEPTIONS)
|
|
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#include <string.h>
#import "ObjFWRT.h"
#import "private.h"
#import "macros.h"
#ifdef OF_HAVE_THREADS
# include "OFPlainMutex.h"
#endif
#ifdef HAVE_SEH_EXCEPTIONS
# include <windows.h>
#endif
#if defined(HAVE_DWARF_EXCEPTIONS)
|
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
PCONTEXT, PDISPATCHER_CONTEXT, _Unwind_Reason_Code (*)(int, int, uint64_t,
struct _Unwind_Exception *, struct _Unwind_Context *));
#endif
static objc_uncaught_exception_handler_t uncaughtExceptionHandler;
static struct objc_exception emergencyExceptions[NUM_EMERGENCY_EXCEPTIONS];
#ifdef OF_HAVE_THREADS
static of_spinlock_t emergencyExceptionsSpinlock;
OF_CONSTRUCTOR()
{
if (of_spinlock_new(&emergencyExceptionsSpinlock) != 0)
OBJC_ERROR("Cannot create spinlock!");
}
#endif
static uint64_t
readULEB128(const uint8_t **ptr)
{
|
|
|
|
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
PCONTEXT, PDISPATCHER_CONTEXT, _Unwind_Reason_Code (*)(int, int, uint64_t,
struct _Unwind_Exception *, struct _Unwind_Context *));
#endif
static objc_uncaught_exception_handler_t uncaughtExceptionHandler;
static struct objc_exception emergencyExceptions[NUM_EMERGENCY_EXCEPTIONS];
#ifdef OF_HAVE_THREADS
static OFSpinlock emergencyExceptionsSpinlock;
OF_CONSTRUCTOR()
{
if (OFSpinlockNew(&emergencyExceptionsSpinlock) != 0)
OBJC_ERROR("Cannot create spinlock!");
}
#endif
static uint64_t
readULEB128(const uint8_t **ptr)
{
|
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
static uint64_t
readValue(uint8_t enc, const uint8_t **ptr)
{
uint64_t value;
if (enc == DW_EH_PE_aligned) {
const uintptr_t *aligned = (const uintptr_t *)
OF_ROUND_UP_POW2(sizeof(void *), (uintptr_t)*ptr);
*ptr = (const uint8_t *)(aligned + 1);
return *aligned;
}
#define READ(type) \
|
|
|
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
static uint64_t
readValue(uint8_t enc, const uint8_t **ptr)
{
uint64_t value;
if (enc == DW_EH_PE_aligned) {
const uintptr_t *aligned = (const uintptr_t *)
OFRoundUpToPowerOf2(sizeof(void *), (uintptr_t)*ptr);
*ptr = (const uint8_t *)(aligned + 1);
return *aligned;
}
#define READ(type) \
|
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
|
}
static void
emergencyExceptionCleanup(_Unwind_Reason_Code reason,
struct _Unwind_Exception *ex)
{
#ifdef OF_HAVE_THREADS
if (of_spinlock_lock(&emergencyExceptionsSpinlock) != 0)
OBJC_ERROR("Cannot lock spinlock!");
#endif
ex->class = 0;
#ifdef OF_HAVE_THREADS
if (of_spinlock_unlock(&emergencyExceptionsSpinlock) != 0)
OBJC_ERROR("Cannot unlock spinlock!");
#endif
}
void
objc_exception_throw(id object)
{
struct objc_exception *e = calloc(1, sizeof(*e));
bool emergency = false;
if (e == NULL) {
#ifdef OF_HAVE_THREADS
if (of_spinlock_lock(&emergencyExceptionsSpinlock) != 0)
OBJC_ERROR("Cannot lock spinlock!");
#endif
for (uint_fast8_t i = 0; i < NUM_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(&emergencyExceptionsSpinlock) != 0)
OBJC_ERROR("Cannot lock spinlock!");
#endif
}
if (e == NULL)
OBJC_ERROR("Not enough memory to allocate exception!");
|
|
|
|
|
|
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
|
}
static void
emergencyExceptionCleanup(_Unwind_Reason_Code reason,
struct _Unwind_Exception *ex)
{
#ifdef OF_HAVE_THREADS
if (OFSpinlockLock(&emergencyExceptionsSpinlock) != 0)
OBJC_ERROR("Cannot lock spinlock!");
#endif
ex->class = 0;
#ifdef OF_HAVE_THREADS
if (OFSpinlockUnlock(&emergencyExceptionsSpinlock) != 0)
OBJC_ERROR("Cannot unlock spinlock!");
#endif
}
void
objc_exception_throw(id object)
{
struct objc_exception *e = calloc(1, sizeof(*e));
bool emergency = false;
if (e == NULL) {
#ifdef OF_HAVE_THREADS
if (OFSpinlockLock(&emergencyExceptionsSpinlock) != 0)
OBJC_ERROR("Cannot lock spinlock!");
#endif
for (uint_fast8_t i = 0; i < NUM_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 (OFSpinlockUnlock(&emergencyExceptionsSpinlock) != 0)
OBJC_ERROR("Cannot lock spinlock!");
#endif
}
if (e == NULL)
OBJC_ERROR("Not enough memory to allocate exception!");
|