ObjFW  Diff

Differences From Artifact [33f7be3a9f]:

To Artifact [337aac59db]:


111
112
113
114
115
116
117

118




119
120
121
122
123
124
125
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130







+

+
+
+
+







	uint8_t typestable_enc;
	const uint8_t *typestable;
	uintptr_t typestable_base;
	uint8_t callsites_enc;
	const uint8_t *callsites, *actiontable;
};

#ifndef HAVE_SJLJ_EXCEPTIONS
extern _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception*);
#else
extern _Unwind_Reason_Code _Unwind_SjLj_RaiseException(
    struct _Unwind_Exception*);
#endif
extern void* _Unwind_GetLanguageSpecificData(struct _Unwind_Context*);
extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context*);
extern uintptr_t _Unwind_GetDataRelBase(struct _Unwind_Context*);
extern uintptr_t _Unwind_GetTextRelBase(struct _Unwind_Context*);

#if defined(__arm__) || defined(__ARM__)
extern _Unwind_Reason_Code __gnu_unwind_frame(struct _Unwind_Exception*,
164
165
166
167
168
169
170










171
172
173
174
175
176
177
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192







+
+
+
+
+
+
+
+
+
+







#else
# define CONTINUE_UNWIND return _URC_CONTINUE_UNWIND

extern uintptr_t _Unwind_GetIP(struct _Unwind_Context*);
extern void _Unwind_SetIP(struct _Unwind_Context*, uintptr_t);
extern void _Unwind_SetGR(struct _Unwind_Context*, int, uintptr_t);
#endif

#if defined(HAVE_DWARF_EXCEPTIONS)
# define PERSONALITY __gnu_objc_personality_v0
# define RAISE_EXCEPTION _Unwind_RaiseException
#elif defined(HAVE_SJLJ_EXCEPTIONS)
# define PERSONALITY __gnu_objc_personality_sj0
# define RAISE_EXCEPTION _Unwind_SjLj_RaiseException
#else
# error Unknown exception type!
#endif

static objc_uncaught_exception_handler uncaught_exception_handler;

static uint64_t
read_uleb128(const uint8_t **ptr)
{
	uint64_t value = 0;
335
336
337
338
339
340
341
342

343
344
345
346
347

348
349
350
351
352
353
354
350
351
352
353
354
355
356

357
358
359
360
361

362
363
364
365
366
367
368
369







-
+




-
+







}

static bool
find_callsite(struct _Unwind_Context *ctx, struct lsda *lsda,
    uintptr_t *landingpad, const uint8_t **actionrecords)
{
	uintptr_t ip = _Unwind_GetIP(ctx);
	const uint8_t *ptr;
	const uint8_t *ptr = lsda->callsites;

	*landingpad = 0;
	*actionrecords = NULL;

	ptr = lsda->callsites;
#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);
369
370
371
372
373
374
375

















376
377
378
379
380
381
382
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







				    callsite_action - 1;

			return true;
		}
	}

	return false;
#else
	uintptr_t callsite_landingpad, callsite_action;

	if ((uintptr_t)ip < 1)
		return false;

	do {
		callsite_landingpad = (uintptr_t)read_uleb128(&ptr);
		callsite_action = (uintptr_t)read_uleb128(&ptr);
	} while (--ip > 1);

	*landingpad = callsite_landingpad + 1;
	if (callsite_action != 0)
		*actionrecords = lsda->actiontable + callsite_action - 1;

	return true;
#endif
}

static bool
class_matches(Class class, id object)
{
	Class iter;

456
457
458
459
460
461
462
463

464
465
466
467
468
469
470
488
489
490
491
492
493
494

495
496
497
498
499
500
501
502







-
+







	} while (displacement != 0);

	return 0;
}

#if defined(__arm__) || defined(__ARM__)
_Unwind_Reason_Code
__gnu_objc_personality_v0(uint32_t state, struct _Unwind_Exception *ex,
PERSONALITY(uint32_t state, struct _Unwind_Exception *ex,
    struct _Unwind_Context *ctx)
{
	int version = 1;
	uint64_t ex_class = ex->class;
	int actions;

	switch (state) {
481
482
483
484
485
486
487
488

489
490
491
492
493
494
495
513
514
515
516
517
518
519

520
521
522
523
524
525
526
527







-
+







	default:
		return _URC_FAILURE;
	}

	_Unwind_SetGR(ctx, 12, (uintptr_t)ex);
#else
_Unwind_Reason_Code
__gnu_objc_personality_v0(int version, int actions, uint64_t ex_class,
PERSONALITY(int version, int actions, uint64_t ex_class,
    struct _Unwind_Exception *ex, struct _Unwind_Context *ctx)
{
#endif
	struct objc_exception *e = (struct objc_exception*)ex;
	bool foreign = (ex_class != objc_exception_class);
	const uint8_t *lsda_addr, *actionrecords;
	struct lsda lsda;
592
593
594
595
596
597
598
599

600
601
602
603
604
605
606
624
625
626
627
628
629
630

631
632
633
634
635
636
637
638







-
+







		abort();

	memset(e, 0, sizeof(*e));
	e->exception.class = objc_exception_class;
	e->exception.cleanup = cleanup;
	e->object = object;

	if (_Unwind_RaiseException(&e->exception) == _URC_END_OF_STACK &&
	if (RAISE_EXCEPTION(&e->exception) == _URC_END_OF_STACK &&
	    uncaught_exception_handler != NULL)
		uncaught_exception_handler(object);

	abort();
}

objc_uncaught_exception_handler