2 * Branch target identification, basic notskip cases.
15 static void skip2_sigill(int sig
, siginfo_t
*info
, void *vuc
)
18 uc
->uc_mcontext
.pc
+= 8;
19 uc
->uc_mcontext
.pstate
= 1;
23 #define BTI_N "hint #32"
24 #define BTI_C "hint #34"
25 #define BTI_J "hint #36"
26 #define BTI_JC "hint #38"
28 #define BTYPE_1(DEST) \
35 #define BTYPE_2(DEST) \
42 #define BTYPE_3(DEST) \
49 #define TEST(WHICH, DEST, EXPECT) \
51 ".if " #EXPECT "\n\t" \
52 "eor x1, x1," #EXPECT "\n" \
63 TEST(BTYPE_1
, BTI_N
, 1)
64 TEST(BTYPE_1
, BTI_C
, 0)
65 TEST(BTYPE_1
, BTI_J
, 0)
66 TEST(BTYPE_1
, BTI_JC
, 0)
69 TEST(BTYPE_2
, BTI_N
, 1)
70 TEST(BTYPE_2
, BTI_C
, 0)
71 TEST(BTYPE_2
, BTI_J
, 1)
72 TEST(BTYPE_2
, BTI_JC
, 0)
75 TEST(BTYPE_3
, BTI_N
, 1)
76 TEST(BTYPE_3
, BTI_C
, 1)
77 TEST(BTYPE_3
, BTI_J
, 0)
78 TEST(BTYPE_3
, BTI_JC
, 0)
89 void *p
= mmap(0, getpagesize(),
90 PROT_EXEC
| PROT_READ
| PROT_WRITE
| PROT_BTI
,
91 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
92 if (p
== MAP_FAILED
) {
97 memset(&sa
, 0, sizeof(sa
));
98 sa
.sa_sigaction
= skip2_sigill
;
99 sa
.sa_flags
= SA_SIGINFO
;
100 if (sigaction(SIGILL
, &sa
, NULL
) < 0) {
106 * ??? With "extern char test_begin[]", some compiler versions
107 * will use :got references, and some linker versions will
108 * resolve this reference to a static symbol incorrectly.
109 * Bypass this error by using a pc-relative reference directly.
111 asm("adr %0, test_begin; adr %1, test_end" : "=r"(tb
), "=r"(te
));
113 memcpy(p
, tb
, te
- tb
);
115 return ((int (*)(void))p
)();