|
19 | 19 | #include <signal.h> |
20 | 20 | #include <ucontext.h> |
21 | 21 |
|
| 22 | +extern "C" int safefetch32_cont(int* adr, int errValue); |
| 23 | + |
22 | 24 | #ifdef __APPLE__ |
23 | 25 | #if defined(__x86_64__) |
24 | | - #define context_pc context_rip |
| 26 | + #define current_pc context_rip |
25 | 27 | #elif defined(__aarch64__) |
26 | 28 | #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) |
28 | 30 | #endif |
29 | 31 | #else |
30 | 32 | #if defined(__x86_64__) |
31 | | - #define context_pc uc_mcontext.gregs[REG_RIP] |
| 33 | + #define current_pc uc_mcontext.gregs[REG_RIP] |
32 | 34 | #elif defined(__aarch64__) |
33 | | - #define context_pc uc_mcontext.pc |
| 35 | + #define current_pc uc_mcontext.pc |
34 | 36 | #endif |
35 | 37 | #endif |
36 | 38 |
|
|
42 | 44 | _safefetch32_impl: |
43 | 45 | movl (%rdi), %eax |
44 | 46 | 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: |
48 | 50 | movl %esi, %eax |
49 | 51 | ret |
50 | 52 | )"); |
51 | 53 | #else |
52 | 54 | asm(R"( |
| 55 | + .text |
53 | 56 | .globl safefetch32_impl |
54 | 57 | .hidden safefetch32_impl |
55 | 58 | .type safefetch32_imp, %function |
56 | 59 | safefetch32_impl: |
57 | 60 | movl (%rdi), %eax |
58 | 61 | 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: |
63 | 66 | movl %esi, %eax |
64 | 67 | ret |
65 | 68 | )"); |
|
72 | 75 | _safefetch32_impl: |
73 | 76 | ldr w0, [x0] |
74 | 77 | 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: |
78 | 81 | mov x0, x1 |
79 | 82 | ret |
80 | 83 | )"); |
81 | 84 | #else |
82 | 85 | asm(R"( |
| 86 | + .text |
83 | 87 | .globl safefetch32_impl |
84 | 88 | .hidden safefetch32_impl |
85 | 89 | .type safefetch32_impl, %function |
86 | 90 | safefetch32_impl: |
87 | 91 | ldr w0, [x0] |
88 | 92 | 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: |
93 | 97 | mov x0, x1 |
94 | 98 | ret |
95 | 99 | )"); |
|
98 | 102 |
|
99 | 103 | bool SafeAccess::handle_safefetch(int sig, void* context) { |
100 | 104 | ucontext_t* uc = (ucontext_t*)context; |
101 | | - uintptr_t pc = uc->context_pc; |
| 105 | + uintptr_t pc = uc->current_pc; |
102 | 106 | if ((sig == SIGSEGV || sig == SIGBUS) && uc != nullptr) { |
103 | 107 | if (pc == (uintptr_t)safefetch32_impl) { |
104 | | - uc->context_pc = (uintptr_t)safefetch32_continuation; |
| 108 | + uc->current_pc = (uintptr_t)safefetch32_cont; |
105 | 109 | return true; |
106 | 110 | } |
107 | 111 | } |
|
0 commit comments