Skip to content

Commit

Permalink
Fix rseq test
Browse files Browse the repository at this point in the history
* Implement the restartable sequence on aarch64
* Use hidden symbol to make sure we are refering to the correct one
  • Loading branch information
yuyichao authored and rocallahan committed May 16, 2022
1 parent 65906a9 commit e9fc71c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
26 changes: 21 additions & 5 deletions src/test/rseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ static struct rseq_cs rs_cs;

static const uint32_t RSEQ_SIG = 0x12345678;

extern char start_ip;
extern char end_ip;
extern char abort_ip;
// Use hidden symbols to make sure we refer to the assembly symbol
// rather than through GOT
__attribute__((visibility("hidden"))) extern char start_ip;
__attribute__((visibility("hidden"))) extern char end_ip;
__attribute__((visibility("hidden"))) extern char abort_ip;

static uint64_t aborts;
static uint64_t jump_aborts;
Expand All @@ -49,6 +51,22 @@ static void do_section(void) {
"movb $1,%1\n\t"
"1:\n\t"
: : "m"(dummy), "m"(did_abort));
#elif defined(__aarch64__)
int dummy2;
__asm__ __volatile__ (
"start_ip:\n\t"
"mov %1, 1234\n\t"
"str %1, %2\n\t"
"str %1, %2\n\t"
"str %1, %2\n\t"
"str %1, %2\n\t"
"b 1f\n\t"
"end_ip:\n\t"
".int 0x12345678\n\t"
"abort_ip:\n\t"
"mov %0, 1\n\t"
"1:\n\t"
: "+r"(did_abort), "=&r"(dummy2) : "m"(dummy));
#endif
if (did_abort) {
++jump_aborts;
Expand Down Expand Up @@ -90,11 +108,9 @@ static int main_child(void) {
test_assert(rs_ptr->cpu_id_start < 10000000);
test_assert(rs_ptr->cpu_id < 10000000);

#if defined(__x86_64__) || defined(__i386__)
rs_cs.start_ip = (uint64_t)(uintptr_t)&start_ip;
rs_cs.post_commit_offset = (uint64_t)(uintptr_t)&end_ip - rs_cs.start_ip;
rs_cs.abort_ip = (uint64_t)(uintptr_t)&abort_ip;
#endif

const size_t stack_size = 1 << 20;
void* stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
Expand Down
26 changes: 21 additions & 5 deletions src/test/rseq_syscallbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ static struct rseq_cs rs_cs;

static const uint32_t RSEQ_SIG = 0x12345678;

extern char start_ip;
extern char end_ip;
extern char abort_ip;
// Use hidden symbols to make sure we refer to the assembly symbol
// rather than through GOT
__attribute__((visibility("hidden"))) extern char start_ip;
__attribute__((visibility("hidden"))) extern char end_ip;
__attribute__((visibility("hidden"))) extern char abort_ip;

static uint64_t aborts;
static uint64_t jump_aborts;
Expand All @@ -49,6 +51,22 @@ static void do_section(void) {
"movb $1,%1\n\t"
"1:\n\t"
: : "m"(dummy), "m"(did_abort));
#elif defined(__aarch64__)
int dummy2;
__asm__ __volatile__ (
"start_ip:\n\t"
"mov %1, 1234\n\t"
"str %1, %2\n\t"
"str %1, %2\n\t"
"str %1, %2\n\t"
"str %1, %2\n\t"
"b 1f\n\t"
"end_ip:\n\t"
".int 0x12345678\n\t"
"abort_ip:\n\t"
"mov %0, 1\n\t"
"1:\n\t"
: "+r"(did_abort), "=&r"(dummy2) : "m"(dummy));
#endif
if (did_abort) {
++jump_aborts;
Expand Down Expand Up @@ -82,11 +100,9 @@ static int main_child(void) {
test_assert(rs_ptr->cpu_id_start < 10000000);
test_assert(rs_ptr->cpu_id < 10000000);

#if defined(__x86_64__) || defined(__i386__)
rs_cs.start_ip = (uint64_t)(uintptr_t)&start_ip;
rs_cs.post_commit_offset = (uint64_t)(uintptr_t)&end_ip - rs_cs.start_ip;
rs_cs.abort_ip = (uint64_t)(uintptr_t)&abort_ip;
#endif

child = fork();
if (!child) {
Expand Down

0 comments on commit e9fc71c

Please sign in to comment.