Skip to content

Commit e9fc71c

Browse files
yuyichaorocallahan
authored andcommitted
Fix rseq test
* Implement the restartable sequence on aarch64 * Use hidden symbol to make sure we are refering to the correct one
1 parent 65906a9 commit e9fc71c

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

src/test/rseq.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ static struct rseq_cs rs_cs;
2222

2323
static const uint32_t RSEQ_SIG = 0x12345678;
2424

25-
extern char start_ip;
26-
extern char end_ip;
27-
extern char abort_ip;
25+
// Use hidden symbols to make sure we refer to the assembly symbol
26+
// rather than through GOT
27+
__attribute__((visibility("hidden"))) extern char start_ip;
28+
__attribute__((visibility("hidden"))) extern char end_ip;
29+
__attribute__((visibility("hidden"))) extern char abort_ip;
2830

2931
static uint64_t aborts;
3032
static uint64_t jump_aborts;
@@ -49,6 +51,22 @@ static void do_section(void) {
4951
"movb $1,%1\n\t"
5052
"1:\n\t"
5153
: : "m"(dummy), "m"(did_abort));
54+
#elif defined(__aarch64__)
55+
int dummy2;
56+
__asm__ __volatile__ (
57+
"start_ip:\n\t"
58+
"mov %1, 1234\n\t"
59+
"str %1, %2\n\t"
60+
"str %1, %2\n\t"
61+
"str %1, %2\n\t"
62+
"str %1, %2\n\t"
63+
"b 1f\n\t"
64+
"end_ip:\n\t"
65+
".int 0x12345678\n\t"
66+
"abort_ip:\n\t"
67+
"mov %0, 1\n\t"
68+
"1:\n\t"
69+
: "+r"(did_abort), "=&r"(dummy2) : "m"(dummy));
5270
#endif
5371
if (did_abort) {
5472
++jump_aborts;
@@ -90,11 +108,9 @@ static int main_child(void) {
90108
test_assert(rs_ptr->cpu_id_start < 10000000);
91109
test_assert(rs_ptr->cpu_id < 10000000);
92110

93-
#if defined(__x86_64__) || defined(__i386__)
94111
rs_cs.start_ip = (uint64_t)(uintptr_t)&start_ip;
95112
rs_cs.post_commit_offset = (uint64_t)(uintptr_t)&end_ip - rs_cs.start_ip;
96113
rs_cs.abort_ip = (uint64_t)(uintptr_t)&abort_ip;
97-
#endif
98114

99115
const size_t stack_size = 1 << 20;
100116
void* stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,

src/test/rseq_syscallbuf.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ static struct rseq_cs rs_cs;
2222

2323
static const uint32_t RSEQ_SIG = 0x12345678;
2424

25-
extern char start_ip;
26-
extern char end_ip;
27-
extern char abort_ip;
25+
// Use hidden symbols to make sure we refer to the assembly symbol
26+
// rather than through GOT
27+
__attribute__((visibility("hidden"))) extern char start_ip;
28+
__attribute__((visibility("hidden"))) extern char end_ip;
29+
__attribute__((visibility("hidden"))) extern char abort_ip;
2830

2931
static uint64_t aborts;
3032
static uint64_t jump_aborts;
@@ -49,6 +51,22 @@ static void do_section(void) {
4951
"movb $1,%1\n\t"
5052
"1:\n\t"
5153
: : "m"(dummy), "m"(did_abort));
54+
#elif defined(__aarch64__)
55+
int dummy2;
56+
__asm__ __volatile__ (
57+
"start_ip:\n\t"
58+
"mov %1, 1234\n\t"
59+
"str %1, %2\n\t"
60+
"str %1, %2\n\t"
61+
"str %1, %2\n\t"
62+
"str %1, %2\n\t"
63+
"b 1f\n\t"
64+
"end_ip:\n\t"
65+
".int 0x12345678\n\t"
66+
"abort_ip:\n\t"
67+
"mov %0, 1\n\t"
68+
"1:\n\t"
69+
: "+r"(did_abort), "=&r"(dummy2) : "m"(dummy));
5270
#endif
5371
if (did_abort) {
5472
++jump_aborts;
@@ -82,11 +100,9 @@ static int main_child(void) {
82100
test_assert(rs_ptr->cpu_id_start < 10000000);
83101
test_assert(rs_ptr->cpu_id < 10000000);
84102

85-
#if defined(__x86_64__) || defined(__i386__)
86103
rs_cs.start_ip = (uint64_t)(uintptr_t)&start_ip;
87104
rs_cs.post_commit_offset = (uint64_t)(uintptr_t)&end_ip - rs_cs.start_ip;
88105
rs_cs.abort_ip = (uint64_t)(uintptr_t)&abort_ip;
89-
#endif
90106

91107
child = fork();
92108
if (!child) {

0 commit comments

Comments
 (0)