ObjFW  Diff

Differences From Artifact [411c032d6c]:

To Artifact [2dc53da018]:


117
118
119
120
121
122
123

124
125
126
127
128
129
130
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131







+








#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_DeleteException(struct _Unwind_Exception*);
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*,
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
279
280

281
282
283
284
285

286
287

288
289

290
291
292
293
294

295
296

297
298

299
300
301
302
303

304
305
306
307
308
309
310
265
266
267
268
269
270
271

272
273
274
275
276
277

278
279

280
281
282
283
284

285
286

287
288

289
290
291
292
293

294
295

296
297

298
299
300
301


302
303
304
305
306
307
308
309







-
+





-


-
+




-
+

-
+

-
+




-
+

-
+

-
+



-
-
+







{
	uint64_t value;

	if (enc == DW_EH_PE_aligned)
		/* Not implemented */
		abort();

#define READ_TYPE(type)				\
#define READ(type)				\
	{					\
		value = *(type*)(void*)*ptr;	\
		*ptr += size_for_encoding(enc);	\
		break;				\
	}

	switch (enc & 0x0F) {
	case DW_EH_PE_absptr:
		READ_TYPE(uintptr_t)
		READ(uintptr_t)
	case DW_EH_PE_uleb128:
		value = read_uleb128(ptr);
		break;
	case DW_EH_PE_udata2:
		READ_TYPE(uint16_t)
		READ(uint16_t)
	case DW_EH_PE_udata4:
		READ_TYPE(uint32_t)
		READ(uint32_t)
	case DW_EH_PE_udata8:
		READ_TYPE(uint64_t)
		READ(uint64_t)
	case DW_EH_PE_sleb128:
		value = read_sleb128(ptr);
		break;
	case DW_EH_PE_sdata2:
		READ_TYPE(int16_t)
		READ(int16_t)
	case DW_EH_PE_sdata4:
		READ_TYPE(int32_t)
		READ(int32_t)
	case DW_EH_PE_sdata8:
		READ_TYPE(int64_t)
		READ(int64_t)
	default:
		abort();
	}

#undef READ_TYPE
#undef READ

	return value;
}

#if !defined(__arm__) && !defined(__ARM__)
static uint64_t
resolve_value(uint64_t value, uint8_t enc, const uint8_t *start, uint64_t base)
525
526
527
528
529
530
531
532

533
534
535
536
537
538
539
540
541
542
543
544
524
525
526
527
528
529
530

531
532
533



534
535
536
537
538
539
540







-
+


-
-
-







	bool foreign = (ex_class != objc_exception_class);
	const uint8_t *lsda_addr, *actionrecords;
	struct lsda lsda;
	uintptr_t landingpad = 0;
	uint8_t found = 0;
	intptr_t filter = 0;

	if (version != 1)
	if (version != 1 || ctx == NULL)
		return _URC_FATAL_PHASE1_ERROR;

	if (ctx == NULL)
		abort();

	/*
	 * We already cached everything we found in phase 1, so we only need
	 * to install the context in phase 2.
	 */
	if (actions & _UA_HANDLER_FRAME && !foreign) {
		/*
		 * For handlers, reg #0 must be the exception's object and reg
552
553
554
555
556
557
558
559

560
561
562
563
564
565
566
567
568
569
570
571
572
573

574
575
576
577


578
579
580
581
582
583
584
548
549
550
551
552
553
554

555
556
557
558
559
560
561
562
563
564
565
566
567
568

569


570
571
572
573
574
575
576
577
578
579
580







-
+













-
+
-
-


+
+







		_Unwind_SetIP(ctx, ex->barrier_cache.bitpattern[3]);
#else
		_Unwind_SetGR(ctx, __builtin_eh_return_data_regno(1),
		    e->filter);
		_Unwind_SetIP(ctx, e->landingpad);
#endif

		free(ex);
		_Unwind_DeleteException(ex);

		return _URC_INSTALL_CONTEXT;
	}

	/* No LSDA -> nothing to handle */
	if ((lsda_addr = _Unwind_GetLanguageSpecificData(ctx)) == NULL)
		CONTINUE_UNWIND;

	read_lsda(ctx, lsda_addr, &lsda);

	if (!find_callsite(ctx, &lsda, &landingpad, &actionrecords))
		CONTINUE_UNWIND;

	if (landingpad != 0 && actionrecords == NULL)
	if (landingpad != 0 && actionrecords != NULL)
		found = CLEANUP_FOUND;
	else if (landingpad != 0)
		found = find_actionrecord(actionrecords, &lsda, actions,
		    foreign, e, &filter);
	else if (landingpad != 0)
		found = CLEANUP_FOUND;

	if (!found)
		CONTINUE_UNWIND;

	if (actions & _UA_SEARCH_PHASE) {
		if (!(found & HANDLER_FOUND) || foreign)
			CONTINUE_UNWIND;
598
599
600
601
602
603
604


605
606
607
608
609
610
611
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609







+
+







		if (!(found & CLEANUP_FOUND))
			CONTINUE_UNWIND;

		_Unwind_SetGR(ctx, __builtin_eh_return_data_regno(0),
		    (uintptr_t)ex);
		_Unwind_SetGR(ctx, __builtin_eh_return_data_regno(1), filter);
		_Unwind_SetIP(ctx, landingpad);

		_Unwind_DeleteException(ex);

		return _URC_INSTALL_CONTEXT;
	}

	abort();
}