|
16 | 16 |
|
17 | 17 |
|
18 | 18 | #include "safeAccess.h" |
| 19 | +#include <ucontext.h> |
19 | 20 |
|
20 | | -SafeAccess::SafeFetch32 SafeAccess::_safeFetch32Func = nullptr; |
21 | | - |
22 | | -void SafeAccess::initSafeFetch(CodeCache* libjvm) { |
23 | | - // Hotspot JVM's safefetch implementation appears better, e.g. it actually returns errorValue, |
24 | | - // when the address is invalid. let's use it whenever possible. |
25 | | - // When the methods are not available, fallback to SafeAccess::load32() implementation. |
26 | | - _safeFetch32Func = (SafeFetch32)libjvm->findSymbol("SafeFetch32_impl"); |
27 | | - if (_safeFetch32Func == nullptr && !WX_MEMORY) { |
28 | | - // jdk11 stub implementation other than Macosx/aarch64 |
29 | | - void** entry = (void**)libjvm->findSymbol("_ZN12StubRoutines18_safefetch32_entryE"); |
30 | | - if (entry != nullptr && *entry != nullptr) { |
31 | | - _safeFetch32Func = (SafeFetch32)*entry; |
| 21 | + |
| 22 | +#ifdef __APPLE__ |
| 23 | + |
| 24 | +#if defined(__x86_64) |
| 25 | + #define context_pc context_rip |
| 26 | +#elif defined(__aarch64__) |
| 27 | + #define DU3_PREFIX(s, m) __ ## s.__ ## m |
| 28 | + #define context_pc uc_mcontext->DU3_PREFIX(ss,pc) |
| 29 | +#endif |
| 30 | + |
| 31 | +#endif |
| 32 | + |
| 33 | +extern "C" char _SafeFetch32_continuation[] __attribute__ ((visibility ("hidden"))); |
| 34 | +extern "C" char _SafeFetch32_fault[] __attribute__ ((visibility ("hidden"))); |
| 35 | + |
| 36 | +bool SafeAccess::handle_safefetch(int sig, uintptr_t pc, void* context) { |
| 37 | + ucontext_t* uc = (ucontext_t*)context; |
| 38 | + if ((sig == SIGSEGV || sig == SIGBUS) && uc != nullptr) { |
| 39 | + if (pc == (uintptr_t)_SafeFetch32_fault) { |
| 40 | + uc->context_pc == (uintptr_t)_SafeFetch32_continuation; |
| 41 | + return true; |
32 | 42 | } |
33 | 43 | } |
34 | | - // Fallback |
35 | | - if (_safeFetch32Func == nullptr) { |
36 | | - _safeFetch32Func = (SafeFetch32)load32; |
37 | | - } |
| 44 | + return false; |
38 | 45 | } |
0 commit comments