Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the sigaction syscall directly on arm64 #805

Merged
merged 2 commits into from
May 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# NEXT RELEASE

### Bugfixes:

* Fixed encryption on Android ARM64 devices.

----------------------------------------------

# 0.89.1 Release notes

### Bugfixes:
Expand Down
30 changes: 28 additions & 2 deletions src/realm/util/file_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
# include <mach/exc.h>
#endif

#ifdef REALM_ANDROID
#include <linux/unistd.h>
#include <sys/syscall.h>
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would have been nice with some indentation here, like above.


using namespace realm;
using namespace realm::util;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
Expand Down
1 change: 1 addition & 0 deletions test/test_encrypted_file_mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "test.hpp"

#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>

// Test independence and thread-safety
Expand Down