diff --git a/release_notes.md b/release_notes.md index bc93e143a6c..21fffab70c6 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,3 +1,11 @@ +# NEXT RELEASE + +### Bugfixes: + +* Fixed encryption on Android ARM64 devices. + +---------------------------------------------- + # 0.89.1 Release notes ### Bugfixes: diff --git a/src/realm/util/file_mapper.cpp b/src/realm/util/file_mapper.cpp index aad82858af4..2c5e0ce6953 100644 --- a/src/realm/util/file_mapper.cpp +++ b/src/realm/util/file_mapper.cpp @@ -47,6 +47,11 @@ # include #endif +#ifdef REALM_ANDROID +#include +#include +#endif + using namespace realm; using namespace realm::util; @@ -364,6 +369,27 @@ void install_handler() #else // __APPLE__ +#if defined(REALM_ANDROID) && defined(__LP64__) +// bionic's sigaction() is broken on arm64, so use the syscall directly +int sigaction_wrapper(int signal, const struct sigaction* new_action, struct sigaction* old_action) { + __kernel_sigaction kernel_new_action; + kernel_new_action.sa_flags = new_action->sa_flags; + kernel_new_action.sa_handler = new_action->sa_handler; + kernel_new_action.sa_mask = new_action->sa_mask; + + __kernel_sigaction kernel_old_action; + int result = syscall(__NR_rt_sigaction, signal, &kernel_new_action, + &kernel_old_action, sizeof(sigset_t)); + old_action->sa_flags = kernel_old_action.sa_flags; + old_action->sa_handler = kernel_old_action.sa_handler; + old_action->sa_mask = kernel_old_action.sa_mask; + + return result; +} +#else +#define sigaction_wrapper sigaction +#endif + // The signal handlers which our handlers replaced, if any, for forwarding // signals for segfaults outside of our encrypted pages struct sigaction old_segv; @@ -406,9 +432,9 @@ void install_handler() action.sa_sigaction = signal_handler; action.sa_flags = SA_SIGINFO; - if (sigaction(SIGSEGV, &action, &old_segv) != 0) + if (sigaction_wrapper(SIGSEGV, &action, &old_segv) != 0) REALM_TERMINATE("sigaction SEGV failed"); - if (sigaction(SIGBUS, &action, &old_bus) != 0) + if (sigaction_wrapper(SIGBUS, &action, &old_bus) != 0) REALM_TERMINATE("sigaction SIGBUS"); } } diff --git a/test/test_encrypted_file_mapping.cpp b/test/test_encrypted_file_mapping.cpp index 93eac74f3e5..b3cebf00722 100644 --- a/test/test_encrypted_file_mapping.cpp +++ b/test/test_encrypted_file_mapping.cpp @@ -6,6 +6,7 @@ #include "test.hpp" #include +#include #include // Test independence and thread-safety