First cut at adding arm64 Linux / Android support to Breakpad.

This is an initial attempt to add Arm64 (aarch64) support to Breakpad for
Linux / Android platforms.  This CL adds the Arm64 data structures, but does
not yet implement the Android getcontext support or CPUFillFromThreadInfo /
CPUFillFromUContext.

BUG=354405,335641
R=mark@chromium.org

Review URL: https://breakpad.appspot.com/1354002

git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1301 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
rmcilroy@chromium.org 2014-04-02 23:12:40 +00:00
parent 46aba5a43a
commit 83b9a28cf9
16 changed files with 118 additions and 19 deletions

View file

@ -398,8 +398,8 @@ bool ExceptionHandler::HandleSignal(int sig, siginfo_t* info, void* uc) {
CrashContext context; CrashContext context;
memcpy(&context.siginfo, info, sizeof(siginfo_t)); memcpy(&context.siginfo, info, sizeof(siginfo_t));
memcpy(&context.context, uc, sizeof(struct ucontext)); memcpy(&context.context, uc, sizeof(struct ucontext));
#if !defined(__ARM_EABI__) && !defined(__mips__) #if !defined(__ARM_EABI__) && !defined(__aarch64__) && !defined(__mips__)
// FP state is not part of user ABI on ARM Linux. // FP state is not part of user ABI on ARM or ARM64 Linux.
// In case of MIPS Linux FP state is already part of struct ucontext // In case of MIPS Linux FP state is already part of struct ucontext
// and 'float_state' is not a member of CrashContext. // and 'float_state' is not a member of CrashContext.
struct ucontext *uc_ptr = (struct ucontext*)uc; struct ucontext *uc_ptr = (struct ucontext*)uc;
@ -608,7 +608,7 @@ bool ExceptionHandler::WriteMinidump() {
} }
#endif #endif
#if !defined(__ARM_EABI__) && !defined(__mips__) #if !defined(__ARM_EABI__) && !defined(__aarch64__) && !defined(__mips__)
// FPU state is not part of ARM EABI ucontext_t. // FPU state is not part of ARM EABI ucontext_t.
memcpy(&context.float_state, context.context.uc_mcontext.fpregs, memcpy(&context.float_state, context.context.uc_mcontext.fpregs,
sizeof(context.float_state)); sizeof(context.float_state));
@ -627,6 +627,9 @@ bool ExceptionHandler::WriteMinidump() {
#elif defined(__arm__) #elif defined(__arm__)
context.siginfo.si_addr = context.siginfo.si_addr =
reinterpret_cast<void*>(context.context.uc_mcontext.arm_pc); reinterpret_cast<void*>(context.context.uc_mcontext.arm_pc);
#elif defined(__aarch64__)
context.siginfo.si_addr =
reinterpret_cast<void*>(context.context.uc_mcontext.pc);
#elif defined(__mips__) #elif defined(__mips__)
context.siginfo.si_addr = context.siginfo.si_addr =
reinterpret_cast<void*>(context.context.uc_mcontext.pc); reinterpret_cast<void*>(context.context.uc_mcontext.pc);

View file

@ -190,10 +190,10 @@ class ExceptionHandler {
siginfo_t siginfo; siginfo_t siginfo;
pid_t tid; // the crashing thread. pid_t tid; // the crashing thread.
struct ucontext context; struct ucontext context;
#if !defined(__ARM_EABI__) && !defined(__mips__) #if !defined(__ARM_EABI__) && !defined(__aarch64__) && !defined(__mips__)
// #ifdef this out because FP state is not part of user ABI for Linux ARM. // #ifdef this out because FP state is not part of user ABI for Linux ARM
// In case of MIPS Linux FP state is already part of struct ucontext // or ARM64. In case of MIPS Linux FP state is already part of struct
// so 'float_state' is not required. // ucontext so 'float_state' is not required.
struct _libc_fpstate float_state; struct _libc_fpstate float_state;
#endif #endif
}; };

View file

@ -99,6 +99,8 @@ bool LinuxCoreDumper::GetThreadInfoByIndex(size_t index, ThreadInfo* info) {
memcpy(&stack_pointer, &info->regs.rsp, sizeof(info->regs.rsp)); memcpy(&stack_pointer, &info->regs.rsp, sizeof(info->regs.rsp));
#elif defined(__ARM_EABI__) #elif defined(__ARM_EABI__)
memcpy(&stack_pointer, &info->regs.ARM_sp, sizeof(info->regs.ARM_sp)); memcpy(&stack_pointer, &info->regs.ARM_sp, sizeof(info->regs.ARM_sp));
#elif defined(__aarch64__)
memcpy(&stack_pointer, &info->regs.sp, sizeof(info->regs.sp));
#elif defined(__mips__) #elif defined(__mips__)
stack_pointer = stack_pointer =
reinterpret_cast<uint8_t*>(info->regs.regs[MD_CONTEXT_MIPS_REG_SP]); reinterpret_cast<uint8_t*>(info->regs.regs[MD_CONTEXT_MIPS_REG_SP]);

View file

@ -56,7 +56,7 @@ typedef typeof(((struct user*) 0)->u_debugreg[0]) debugreg_t;
// Typedef for our parsing of the auxv variables in /proc/pid/auxv. // Typedef for our parsing of the auxv variables in /proc/pid/auxv.
#if defined(__i386) || defined(__ARM_EABI__) || defined(__mips__) #if defined(__i386) || defined(__ARM_EABI__) || defined(__mips__)
typedef Elf32_auxv_t elf_aux_entry; typedef Elf32_auxv_t elf_aux_entry;
#elif defined(__x86_64) #elif defined(__x86_64) || defined(__aarch64__)
typedef Elf64_auxv_t elf_aux_entry; typedef Elf64_auxv_t elf_aux_entry;
#endif #endif
@ -88,6 +88,10 @@ struct ThreadInfo {
// Mimicking how strace does this(see syscall.c, search for GETREGS) // Mimicking how strace does this(see syscall.c, search for GETREGS)
struct user_regs regs; struct user_regs regs;
struct user_fpregs fpregs; struct user_fpregs fpregs;
#elif defined(__aarch64__)
// Use the structures defined in <asm/ptrace.h>
struct user_pt_regs regs;
struct user_fpsimd_state fpregs;
#elif defined(__mips__) #elif defined(__mips__)
user_regs_struct regs; user_regs_struct regs;
user_fpregs_struct fpregs; user_fpregs_struct fpregs;

View file

@ -47,6 +47,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
#include <sys/uio.h>
#include <sys/wait.h> #include <sys/wait.h>
#if defined(__i386) #if defined(__i386)
@ -186,6 +187,20 @@ bool LinuxPtraceDumper::GetThreadInfoByIndex(size_t index, ThreadInfo* info) {
if (info->ppid == -1 || info->tgid == -1) if (info->ppid == -1 || info->tgid == -1)
return false; return false;
#ifdef PTRACE_GETREGSET
struct iovec io;
io.iov_base = &info->regs;
io.iov_len = sizeof(info->regs);
if (sys_ptrace(PTRACE_GETREGSET, tid, (void*)NT_PRSTATUS, (void*)&io) == -1) {
return false;
}
io.iov_base = &info->fpregs;
io.iov_len = sizeof(info->fpregs);
if (sys_ptrace(PTRACE_GETREGSET, tid, (void*)NT_FPREGSET, (void*)&io) == -1) {
return false;
}
#else
if (sys_ptrace(PTRACE_GETREGS, tid, NULL, &info->regs) == -1) { if (sys_ptrace(PTRACE_GETREGS, tid, NULL, &info->regs) == -1) {
return false; return false;
} }
@ -193,6 +208,7 @@ bool LinuxPtraceDumper::GetThreadInfoByIndex(size_t index, ThreadInfo* info) {
if (sys_ptrace(PTRACE_GETFPREGS, tid, NULL, &info->fpregs) == -1) { if (sys_ptrace(PTRACE_GETFPREGS, tid, NULL, &info->fpregs) == -1) {
return false; return false;
} }
#endif
#if defined(__i386) #if defined(__i386)
#if !defined(bit_FXSAVE) // e.g. Clang #if !defined(bit_FXSAVE) // e.g. Clang
@ -241,6 +257,8 @@ bool LinuxPtraceDumper::GetThreadInfoByIndex(size_t index, ThreadInfo* info) {
my_memcpy(&stack_pointer, &info->regs.rsp, sizeof(info->regs.rsp)); my_memcpy(&stack_pointer, &info->regs.rsp, sizeof(info->regs.rsp));
#elif defined(__ARM_EABI__) #elif defined(__ARM_EABI__)
my_memcpy(&stack_pointer, &info->regs.ARM_sp, sizeof(info->regs.ARM_sp)); my_memcpy(&stack_pointer, &info->regs.ARM_sp, sizeof(info->regs.ARM_sp));
#elif defined(__aarch64__)
my_memcpy(&stack_pointer, &info->regs.sp, sizeof(info->regs.sp));
#elif defined(__mips__) #elif defined(__mips__)
stack_pointer = stack_pointer =
reinterpret_cast<uint8_t*>(info->regs.regs[MD_CONTEXT_MIPS_REG_SP]); reinterpret_cast<uint8_t*>(info->regs.regs[MD_CONTEXT_MIPS_REG_SP]);

View file

@ -374,6 +374,19 @@ void CPUFillFromUContext(MDRawContextARM* out, const ucontext* uc,
my_memset(&out->float_save.extra, 0, sizeof(out->float_save.extra)); my_memset(&out->float_save.extra, 0, sizeof(out->float_save.extra));
} }
#elif defined(__aarch64__)
typedef MDRawContextARM64 RawContextCPU;
void CPUFillFromThreadInfo(MDRawContextARM64* out,
const google_breakpad::ThreadInfo& info) {
// TODO(rmcilroy): Implement for arm64.
}
void CPUFillFromUContext(MDRawContextARM64* out, const ucontext* uc,
const struct _libc_fpstate* fpregs) {
// TODO(rmcilroy): Implement for arm64.
}
#elif defined(__mips__) #elif defined(__mips__)
typedef MDRawContextMIPS RawContextCPU; typedef MDRawContextMIPS RawContextCPU;
@ -470,7 +483,7 @@ class MinidumpWriter {
: fd_(minidump_fd), : fd_(minidump_fd),
path_(minidump_path), path_(minidump_path),
ucontext_(context ? &context->context : NULL), ucontext_(context ? &context->context : NULL),
#if !defined(__ARM_EABI__) && !defined(__mips__) #if !defined(__ARM_EABI__) && !defined(__mips__) && !defined(__aarch64__)
float_state_(context ? &context->float_state : NULL), float_state_(context ? &context->float_state : NULL),
#else #else
// TODO: fix this after fixing ExceptionHandler // TODO: fix this after fixing ExceptionHandler
@ -1271,6 +1284,18 @@ class MinidumpWriter {
uintptr_t GetInstructionPointer(const ThreadInfo& info) { uintptr_t GetInstructionPointer(const ThreadInfo& info) {
return info.regs.uregs[15]; return info.regs.uregs[15];
} }
#elif defined(__aarch64__)
uintptr_t GetStackPointer() {
return ucontext_->uc_mcontext.sp;
}
uintptr_t GetInstructionPointer() {
return ucontext_->uc_mcontext.pc;
}
uintptr_t GetInstructionPointer(const ThreadInfo& info) {
return info.regs.pc;
}
#elif defined(__mips__) #elif defined(__mips__)
uintptr_t GetStackPointer() { uintptr_t GetStackPointer() {
return ucontext_->uc_mcontext.gregs[MD_CONTEXT_MIPS_REG_SP]; return ucontext_->uc_mcontext.gregs[MD_CONTEXT_MIPS_REG_SP];
@ -1581,6 +1606,11 @@ class MinidumpWriter {
return true; return true;
} }
#elif defined(__aarch64__)
bool WriteCPUInformation(MDRawSystemInfo* sys_info) {
// TODO(rmcilroy): Implement for arm64.
return false;
}
#else #else
# error "Unsupported CPU" # error "Unsupported CPU"
#endif #endif

View file

@ -140,6 +140,10 @@ breakpad_getcontext:
.size breakpad_getcontext, . - breakpad_getcontext .size breakpad_getcontext, . - breakpad_getcontext
#elif defined(__aarch64__)
// TODO(rmcilroy): Implement for arm64.
#elif defined(__mips__) #elif defined(__mips__)
#if _MIPS_SIM != _ABIO32 #if _MIPS_SIM != _ABIO32

View file

@ -110,9 +110,14 @@ typedef struct {
// __WORDSIZE is GLibc-specific and used by Google Breakpad on Linux. // __WORDSIZE is GLibc-specific and used by Google Breakpad on Linux.
// All Android platforms are 32-bit for now.
#ifndef __WORDSIZE #ifndef __WORDSIZE
#if defined(__i386__) || defined(__ARM_EABI__) || defined(__mips__)
#define __WORDSIZE 32 #define __WORDSIZE 32
#elif defined(__x86_64__) || defined(__aarch64__)
#define __WORDSIZE 64
#else
#error "Unsupported Android CPU ABI"
#endif
#endif #endif
// The Android headers don't always define this constant. // The Android headers don't always define this constant.

View file

@ -34,6 +34,10 @@
Provide custom version here. */ Provide custom version here. */
#include_next <link.h> #include_next <link.h>
// TODO(rmcilroy): Remove this file once the ndk is updated for other
// architectures - crbug.com/358831
#if !defined(__aarch64__) && !defined(__x86_64__)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif // __cplusplus #endif // __cplusplus
@ -61,4 +65,6 @@ struct link_map {
} // extern "C" } // extern "C"
#endif // __cplusplus #endif // __cplusplus
#endif // !defined(__aarch64__) && !defined(__x86_64__)
#endif /* GOOGLE_BREAKPAD_ANDROID_INCLUDE_LINK_H */ #endif /* GOOGLE_BREAKPAD_ANDROID_INCLUDE_LINK_H */

View file

@ -44,7 +44,7 @@
extern "C" { extern "C" {
#endif // __cplusplus #endif // __cplusplus
#ifdef __x86_64__ #if defined(__x86_64__) || defined(__aarch64__)
typedef unsigned long long elf_greg_t; typedef unsigned long long elf_greg_t;
#else #else
typedef unsigned long elf_greg_t; typedef unsigned long elf_greg_t;
@ -52,6 +52,8 @@ typedef unsigned long elf_greg_t;
#ifdef __arm__ #ifdef __arm__
#define ELF_NGREG (sizeof(struct user_regs) / sizeof(elf_greg_t)) #define ELF_NGREG (sizeof(struct user_regs) / sizeof(elf_greg_t))
#elif defined(__aarch64__)
#define ELF_NGREG (sizeof(struct user_pt_regs) / sizeof(elf_greg_t))
#else #else
#define ELF_NGREG (sizeof(struct user_regs_struct) / sizeof(elf_greg_t)) #define ELF_NGREG (sizeof(struct user_regs_struct) / sizeof(elf_greg_t))
#endif #endif

View file

@ -62,6 +62,19 @@ typedef struct ucontext {
// Other fields are not used by Google Breakpad. Don't define them. // Other fields are not used by Google Breakpad. Don't define them.
} ucontext_t; } ucontext_t;
#elif defined(__aarch64__)
#include <asm/sigcontext.h>
typedef struct sigcontext mcontext_t;
typedef struct ucontext {
unsigned long uc_flags;
struct ucontext *uc_link;
stack_t uc_stack;
sigset_t uc_sigmask;
mcontext_t uc_mcontext;
} ucontext_t;
#elif defined(__i386__) #elif defined(__i386__)
/* 80-bit floating-point register */ /* 80-bit floating-point register */

View file

@ -75,6 +75,11 @@ struct user_vfpregs {
unsigned long fpscr; unsigned long fpscr;
}; };
#elif defined(__aarch64__)
// aarch64 does not have user_regs definitions in <asm/user.h>, instead
// use the definitions in <asm/ptrace.h>, which we don't need to redefine here.
#elif defined(__i386__) #elif defined(__i386__)
#define _I386_USER_H 1 // Prevent <asm/user.h> conflicts #define _I386_USER_H 1 // Prevent <asm/user.h> conflicts

View file

@ -45,6 +45,11 @@
#define MCONTEXT_GREGS_OFFSET 32 #define MCONTEXT_GREGS_OFFSET 32
#define UCONTEXT_SIGMASK_OFFSET 104 #define UCONTEXT_SIGMASK_OFFSET 104
#elif defined(__aarch64__)
#define MCONTEXT_GREGS_OFFSET 56
#define UCONTEXT_SIGMASK_OFFSET 40
#elif defined(__i386__) #elif defined(__i386__)
#define MCONTEXT_GREGS_OFFSET 20 #define MCONTEXT_GREGS_OFFSET 20

View file

@ -62,7 +62,7 @@ bool MemoryMappedFile::Map(const char* path) {
return false; return false;
} }
#if defined(__x86_64__) #if defined(__x86_64__) || defined(__aarch64__)
struct kernel_stat st; struct kernel_stat st;
if (sys_fstat(fd, &st) == -1 || st.st_size < 0) { if (sys_fstat(fd, &st) == -1 || st.st_size < 0) {
#else #else
@ -81,7 +81,7 @@ bool MemoryMappedFile::Map(const char* path) {
return true; return true;
} }
#if defined(__x86_64__) #if defined(__x86_64__) || defined(__aarch64__)
void* data = sys_mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); void* data = sys_mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
#else #else
void* data = sys_mmap2(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); void* data = sys_mmap2(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);

View file

@ -110,7 +110,7 @@ class PageAllocator {
private: private:
uint8_t *GetNPages(size_t num_pages) { uint8_t *GetNPages(size_t num_pages) {
#ifdef __x86_64 #if defined(__x86_64__) || defined(__aarch64__)
void *a = sys_mmap(NULL, page_size_ * num_pages, PROT_READ | PROT_WRITE, void *a = sys_mmap(NULL, page_size_ * num_pages, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
#else #else

View file

@ -154,7 +154,8 @@
#endif #endif
/* The size of `long', as computed by sizeof. */ /* The size of `long', as computed by sizeof. */
#if defined(_M_X64) || (defined(__x86_64__) && !defined(__ILP32__)) #if defined(_M_X64) || (defined(__x86_64__) && !defined(__ILP32__)) || \
defined(__aarch64__)
#define CURL_SIZEOF_LONG 8 #define CURL_SIZEOF_LONG 8
#else #else
#define CURL_SIZEOF_LONG 4 #define CURL_SIZEOF_LONG 4
@ -170,7 +171,8 @@
typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t; typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t;
/* Signed integral data type used for curl_off_t. */ /* Signed integral data type used for curl_off_t. */
#if defined(_M_X64) || (defined(__x86_64__) && !defined(__ILP32__)) #if defined(_M_X64) || (defined(__x86_64__) && !defined(__ILP32__)) || \
defined(__aarch64__)
#define CURL_TYPEOF_CURL_OFF_T long #define CURL_TYPEOF_CURL_OFF_T long
#else #else
#define CURL_TYPEOF_CURL_OFF_T int64_t #define CURL_TYPEOF_CURL_OFF_T int64_t