From 8e8ce0955f7186fc66d9d16c334a43f6a502cead Mon Sep 17 00:00:00 2001 From: Sandboxed API Team Date: Tue, 7 Dec 2021 03:33:27 -0800 Subject: [PATCH] Fix unwind module for Android-ARM64 PiperOrigin-RevId: 414673588 Change-Id: Ib40e4f6b53692440591a1a1e9e069f974832f733 --- sandboxed_api/sandbox2/unwind/ptrace_hook.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/sandboxed_api/sandbox2/unwind/ptrace_hook.cc b/sandboxed_api/sandbox2/unwind/ptrace_hook.cc index e9bc80b..38cd83c 100644 --- a/sandboxed_api/sandbox2/unwind/ptrace_hook.cc +++ b/sandboxed_api/sandbox2/unwind/ptrace_hook.cc @@ -23,6 +23,13 @@ #include #include +// Android doesn't use an enum for __ptrace_request, use int instead. +#if defined(__ANDROID__) +using PtraceRequest = int; +#else +using PtraceRequest = __ptrace_request; +#endif + namespace sandbox2 { namespace { @@ -53,7 +60,7 @@ void EnablePtraceEmulationWithUserRegs(absl::string_view regs) { // issuing ptrace syscalls. Accesses to registers will be emulated, for this the // register values should be set via EnablePtraceEmulationWithUserRegs(). extern "C" long int ptrace_wrapped( // NOLINT - enum __ptrace_request request, pid_t pid, void* addr, void* data) { + PtraceRequest request, pid_t pid, void* addr, void* data) { if (!g_emulate_ptrace) { return ptrace(request, pid, addr, data); } @@ -75,15 +82,15 @@ extern "C" long int ptrace_wrapped( // NOLINT } return read_data; } - case PTRACE_PEEKUSER: + case PTRACE_PEEKUSER: { // Make sure read is in-bounds and aligned. - if (uintptr_t offset = reinterpret_cast(addr); - offset + kRegSize > g_registers->size() * kRegSize || + auto offset = reinterpret_cast(addr); + if (offset + kRegSize > g_registers->size() * kRegSize || offset % kRegSize != 0) { return -1; - } else { - return (*g_registers)[offset / kRegSize]; } + return (*g_registers)[offset / kRegSize]; + } default: fprintf(stderr, "ptrace_wrapped(): operation not permitted: %d\n", request);