ObjFW  Check-in [8b0ab1157c]

Overview
Comment:Simplify detection of exception type
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8b0ab1157cdedadf3d057b9674d609b86a76368a3a0a66fab42b033220dd690c
User & Date: js on 2024-04-24 22:39:00
Other Links: manifest | tags
Context
2024-04-24
22:52
Add SerenityOS to platform.h check-in: 4853f41b75 user: js tags: trunk
22:39
Simplify detection of exception type check-in: 8b0ab1157c user: js tags: trunk
2024-04-23
01:00
Simplify calls to objfw-embed check-in: 569a7aa657 user: js tags: trunk
Changes

Modified configure.ac from [63f2b5a434] to [aab515e691].

584
585
586
587
588
589
590
591
592

593
594
595


596
597

598
599
600
601
602
603
604


605
606
607
608
609


610
611
612
613
614
615







616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640





641
642
643
644
645
646
647
584
585
586
587
588
589
590


591



592
593


594



595



596
597





598
599






600
601
602
603
604
605
606








607
















608
609
610
611
612
613
614
615
616
617
618
619







-
-
+
-
-
-
+
+
-
-
+
-
-
-

-
-
-
+
+
-
-
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+







	])

	AS_IF([test x"$enable_seluid24" = x"yes"], [
		AC_DEFINE(OF_SELUID24, 1, [Whether to use 24 bit selector UIDs])
	])

	AC_MSG_CHECKING(for exception type)
	AC_COMPILE_IFELSE([
		AC_LANG_PROGRAM([
	AC_EGREP_CPP(egrep_cpp_yes, [
			extern void foo();
		], [
			@try {
		#ifdef __SEH__
		egrep_cpp_yes
				foo();
			} @finally {
		#endif
				foo();
			}
		])
	], [
		AS_IF([$SED 's/[[^[:print:]]]//g' <conftest.$ac_objext | \
		    $EGREP __gnu_objc_personality_v0 >/dev/null], [
			exception_type="DWARF"
		AC_MSG_RESULT(SEH)
		exception_type="SEH"
		])
		AS_IF([$SED 's/[[^[:print:]]]//g' <conftest.$ac_objext | \
		    $EGREP __gnu_objc_personality_sj0 >/dev/null], [
			exception_type="SjLj"
		])
		raise_exception="_Unwind_RaiseException"
	], [
		AS_IF([$SED 's/[[^[:print:]]]//g' <conftest.$ac_objext | \
		    $EGREP __gnu_objc_personality_seh0 >/dev/null], [
			exception_type="SEH"
		])

		case "$exception_type" in
		AC_EGREP_CPP(egrep_cpp_yes, [
			#ifdef __USING_SJLJ_EXCEPTIONS__
			egrep_cpp_yes
			#endif
		], [
			AC_MSG_RESULT(SjLj)
			exception_type="SjLj"
		DWARF)
			AC_DEFINE(HAVE_DWARF_EXCEPTIONS, 1,
				[Whether DWARF exceptions are used])
			raise_exception="_Unwind_RaiseException"
			;;
		SjLj)
			AC_DEFINE(HAVE_SJLJ_EXCEPTIONS, 1,
				[Whether SjLj exceptions are used])
			raise_exception="_Unwind_SjLj_RaiseException"
			;;
		SEH)
			AC_DEFINE(HAVE_SEH_EXCEPTIONS, 1,
				[Whether SEH exceptions are used])
			raise_exception="_Unwind_RaiseException"
			;;
		*)
			AC_MSG_RESULT(unknown)
			AC_MSG_ERROR([Exception type not detected!])
			;;
		esac

		AC_MSG_RESULT($exception_type)
	], [
		AC_MSG_RESULT(exceptions unavailable!)
		AC_MSG_ERROR([Exceptions not accepted by compiler!])
		], [
			AC_MSG_RESULT(DWARF)
			exception_type="DWARF"
			raise_exception="_Unwind_RaiseException"
		])
	])

	AC_SEARCH_LIBS($raise_exception, [c++abi gcc_s gcc unwind], [
		dnl c++abi requires pthread on OpenBSD
		AS_IF([test x"$ac_lib" = x"c++abi"], [LIBS="$LIBS -lpthread"])
	], [
		AC_MSG_ERROR([$raise_exception missing!])

Modified src/runtime/exception.m from [2f0f690e96] to [a631c06b73].

29
30
31
32
33
34
35
36

37
38
39
40
41


42
43

44
45
46
47
48
49
50
51


52
53
54
55
56
57
58
29
30
31
32
33
34
35

36
37
38
39


40
41


42
43
44
45
46


47

48
49
50
51
52
53
54
55
56







-
+



-
-
+
+
-
-
+




-
-

-
+
+







#import "private.h"

#import "macros.h"
#ifdef OF_HAVE_THREADS
# import "OFPlainMutex.h"
#endif

#ifdef HAVE_SEH_EXCEPTIONS
#ifdef __SEH__
# include <windows.h>
#endif

#if defined(HAVE_DWARF_EXCEPTIONS)
# define PERSONALITY __gnu_objc_personality_v0
#if defined(__SEH__)
# define PERSONALITY	 gnu_objc_personality
# define CXX_PERSONALITY_STR "__gxx_personality_v0"
#elif defined(HAVE_SJLJ_EXCEPTIONS)
#elif defined(__USING_SJLJ_EXCEPTIONS__)
# define PERSONALITY __gnu_objc_personality_sj0
# define CXX_PERSONALITY_STR "__gxx_personality_sj0"
# define _Unwind_RaiseException _Unwind_SjLj_RaiseException
# define __builtin_eh_return_data_regno(i) (i)
#elif defined(HAVE_SEH_EXCEPTIONS)
# define PERSONALITY	 gnu_objc_personality
#else
# error Unknown exception type!
# define PERSONALITY __gnu_objc_personality_v0
# define CXX_PERSONALITY_STR "__gxx_personality_v0"
#endif

#if defined(OF_ARM) && !defined(__ARM_DWARF_EH__)
# define HAVE_ARM_EHABI_EXCEPTIONS
#endif

#ifndef HAVE_ARM_EHABI_EXCEPTIONS
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138







-
+








struct objc_exception {
	struct _Unwind_Exception {
		uint64_t class;
		void (*cleanup)(
		    _Unwind_Reason_Code, struct _Unwind_Exception *);
#ifndef HAVE_ARM_EHABI_EXCEPTIONS
# ifndef HAVE_SEH_EXCEPTIONS
# ifndef __SEH__
		/*
		 * The Itanium Exception ABI says to have those and never touch
		 * them.
		 */
		uint64_t private1, private2;
# else
		uint64_t private[6];
239
240
241
242
243
244
245
246

247
248
249
250
251
252
253
237
238
239
240
241
242
243

244
245
246
247
248
249
250
251







-
+







}
#endif

#ifdef CXX_PERSONALITY
static PERSONALITY_FUNC(cxx_personality) OF_WEAK_REF(CXX_PERSONALITY_STR);
#endif

#ifdef HAVE_SEH_EXCEPTIONS
#ifdef __SEH__
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 uncaughtExceptionHandler;
static struct objc_exception emergencyExceptions[numEmergencyExceptions];
442
443
444
445
446
447
448
449

450
451
452
453
454
455
456
440
441
442
443
444
445
446

447
448
449
450
451
452
453
454







-
+







{
	uintptr_t IP = _Unwind_GetIP(ctx);
	const uint8_t *ptr = LSDA->callsites;

	*landingpad = 0;
	*actionRecords = NULL;

#ifndef HAVE_SJLJ_EXCEPTIONS
#ifndef __USING_SJLJ_EXCEPTIONS__
	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);
576
577
578
579
580
581
582
583

584
585
586
587
588
589
590
574
575
576
577
578
579
580

581
582
583
584
585
586
587
588







-
+







		else if (filter < 0)
			OBJC_ERROR("Invalid filter!");
	} while (displacement != 0);

	return 0;
}

#ifdef HAVE_SEH_EXCEPTIONS
#ifdef __SEH__
static
#endif
PERSONALITY_FUNC(PERSONALITY)
{
#ifdef HAVE_ARM_EHABI_EXCEPTIONS
	int version = 1;
	uint64_t exClass = ex->class;
782
783
784
785
786
787
788
789

790
791
792
793
794
795
796
780
781
782
783
784
785
786

787
788
789
790
791
792
793
794







-
+







{
	objc_uncaught_exception_handler old = uncaughtExceptionHandler;
	uncaughtExceptionHandler = handler;

	return old;
}

#ifdef HAVE_SEH_EXCEPTIONS
#ifdef __SEH__
typedef EXCEPTION_DISPOSITION (*seh_personality_fn)(PEXCEPTION_RECORD, void *,
    PCONTEXT, PDISPATCHER_CONTEXT);
static seh_personality_fn __gxx_personality_seh0;

OF_CONSTRUCTOR()
{
	/*