Fix unwind module for Android-ARM64

PiperOrigin-RevId: 414673588
Change-Id: Ib40e4f6b53692440591a1a1e9e069f974832f733
This commit is contained in:
Sandboxed API Team 2021-12-07 03:33:27 -08:00 committed by Copybara-Service
parent 8562306c97
commit 8e8ce0955f

View File

@ -23,6 +23,13 @@
#include <cstring> #include <cstring>
#include <vector> #include <vector>
// 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 sandbox2 {
namespace { namespace {
@ -53,7 +60,7 @@ void EnablePtraceEmulationWithUserRegs(absl::string_view regs) {
// issuing ptrace syscalls. Accesses to registers will be emulated, for this the // issuing ptrace syscalls. Accesses to registers will be emulated, for this the
// register values should be set via EnablePtraceEmulationWithUserRegs(). // register values should be set via EnablePtraceEmulationWithUserRegs().
extern "C" long int ptrace_wrapped( // NOLINT 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) { if (!g_emulate_ptrace) {
return ptrace(request, pid, addr, data); return ptrace(request, pid, addr, data);
} }
@ -75,13 +82,13 @@ extern "C" long int ptrace_wrapped( // NOLINT
} }
return read_data; return read_data;
} }
case PTRACE_PEEKUSER: case PTRACE_PEEKUSER: {
// Make sure read is in-bounds and aligned. // Make sure read is in-bounds and aligned.
if (uintptr_t offset = reinterpret_cast<uintptr_t>(addr); auto offset = reinterpret_cast<uintptr_t>(addr);
offset + kRegSize > g_registers->size() * kRegSize || if (offset + kRegSize > g_registers->size() * kRegSize ||
offset % kRegSize != 0) { offset % kRegSize != 0) {
return -1; return -1;
} else { }
return (*g_registers)[offset / kRegSize]; return (*g_registers)[offset / kRegSize];
} }
default: default: