Skip to content

Commit 66c69ad

Browse files
committed
Cleanup
1 parent ca9c47b commit 66c69ad

1 file changed

Lines changed: 24 additions & 20 deletions

File tree

ddprof-lib/src/main/cpp/safeAccess.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@
1919
#include <signal.h>
2020
#include <ucontext.h>
2121

22+
extern "C" int safefetch32_cont(int* adr, int errValue);
23+
2224
#ifdef __APPLE__
2325
#if defined(__x86_64__)
24-
#define context_pc context_rip
26+
#define current_pc context_rip
2527
#elif defined(__aarch64__)
2628
#define DU3_PREFIX(s, m) __ ## s.__ ## m
27-
#define context_pc uc_mcontext->DU3_PREFIX(ss,pc)
29+
#define current_pc uc_mcontext->DU3_PREFIX(ss,pc)
2830
#endif
2931
#else
3032
#if defined(__x86_64__)
31-
#define context_pc uc_mcontext.gregs[REG_RIP]
33+
#define current_pc uc_mcontext.gregs[REG_RIP]
3234
#elif defined(__aarch64__)
33-
#define context_pc uc_mcontext.pc
35+
#define current_pc uc_mcontext.pc
3436
#endif
3537
#endif
3638

@@ -42,24 +44,25 @@
4244
_safefetch32_impl:
4345
movl (%rdi), %eax
4446
ret
45-
.globl _safefetch32_continuation
46-
.private_extern _safefetch32_continuation
47-
_safefetch32_continuation:
47+
.globl _safefetch32_cont
48+
.private_extern _safefetch32_cont
49+
_safefetch32_cont:
4850
movl %esi, %eax
4951
ret
5052
)");
5153
#else
5254
asm(R"(
55+
.text
5356
.globl safefetch32_impl
5457
.hidden safefetch32_impl
5558
.type safefetch32_imp, %function
5659
safefetch32_impl:
5760
movl (%rdi), %eax
5861
ret
59-
.globl safefetch32_continuation
60-
.hidden safefetch32_continuation
61-
.type safefetch32_continuation, %function
62-
safefetch32_continuation:
62+
.globl safefetch32_cont
63+
.hidden safefetch32_cont
64+
.type safefetch32_cont, %function
65+
safefetch32_cont:
6366
movl %esi, %eax
6467
ret
6568
)");
@@ -72,24 +75,25 @@
7275
_safefetch32_impl:
7376
ldr w0, [x0]
7477
ret
75-
.globl _safefetch32_continuation
76-
.private_extern _safefetch32_continuation
77-
_safefetch32_continuation:
78+
.globl _safefetch32_cont
79+
.private_extern _safefetch32_cont
80+
_safefetch32_cont:
7881
mov x0, x1
7982
ret
8083
)");
8184
#else
8285
asm(R"(
86+
.text
8387
.globl safefetch32_impl
8488
.hidden safefetch32_impl
8589
.type safefetch32_impl, %function
8690
safefetch32_impl:
8791
ldr w0, [x0]
8892
ret
89-
.globl safefetch32_continuation
90-
.hidden safefetch32_continuation
91-
.type safefetch32_continuation, %function
92-
safefetch32_continuation:
93+
.globl safefetch32_cont
94+
.hidden safefetch32_cont
95+
.type safefetch32_cont, %function
96+
safefetch32_cont:
9397
mov x0, x1
9498
ret
9599
)");
@@ -98,10 +102,10 @@
98102

99103
bool SafeAccess::handle_safefetch(int sig, void* context) {
100104
ucontext_t* uc = (ucontext_t*)context;
101-
uintptr_t pc = uc->context_pc;
105+
uintptr_t pc = uc->current_pc;
102106
if ((sig == SIGSEGV || sig == SIGBUS) && uc != nullptr) {
103107
if (pc == (uintptr_t)safefetch32_impl) {
104-
uc->context_pc = (uintptr_t)safefetch32_continuation;
108+
uc->current_pc = (uintptr_t)safefetch32_cont;
105109
return true;
106110
}
107111
}

0 commit comments

Comments
 (0)