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

Android/i686 support #86

Merged
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
2 changes: 1 addition & 1 deletion src/linux/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn parse_loaded_elf_program_headers(
pub fn late_process_mappings(pid: Pid, mappings: &mut [MappingInfo]) -> Result<()> {
// Only consider exec mappings that indicate a file path was mapped, and
// where the ELF header indicates a mapped shared library.
for mut map in mappings
for map in mappings
.iter_mut()
.filter(|m| m.is_executable() && m.name_is_path())
{
Expand Down
4 changes: 2 additions & 2 deletions src/linux/auxv_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ impl Iterator for ProcfsAuxvIter {
};

let at_null;
#[cfg(target_arch = "arm")]
#[cfg(any(target_arch = "arm", all(target_os = "android", target_arch = "x86")))]
{
at_null = 0;
}
#[cfg(not(target_arch = "arm"))]
#[cfg(not(any(target_arch = "arm", all(target_os = "android", target_arch = "x86"))))]
{
at_null = libc::AT_NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/linux/crash_context/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl CrashContext {

{
let fs = &self.inner.float_state;
let mut out = &mut out.float_save;
let out = &mut out.float_save;
out.control_word = fs.cw;
out.status_word = fs.sw;
out.tag_word = fs.tag;
Expand Down
4 changes: 2 additions & 2 deletions src/linux/dso_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ pub fn write_dso_debug_stream(
) -> Result<MDRawDirectory> {
let at_phnum;
let at_phdr;
#[cfg(target_arch = "arm")]
#[cfg(any(target_arch = "arm", all(target_os = "android", target_arch = "x86")))]
{
at_phdr = 3;
at_phnum = 5;
}
#[cfg(not(target_arch = "arm"))]
#[cfg(not(any(target_arch = "arm", all(target_os = "android", target_arch = "x86"))))]
{
at_phdr = libc::AT_PHDR;
at_phnum = libc::AT_PHNUM;
Expand Down
2 changes: 1 addition & 1 deletion src/linux/dumper_cpu_info/x86_mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn write_cpu_information(sys_info: &mut MDRawSystemInfo) -> Result<()> {
};

let mut is_first_entry = true;
for mut entry in cpu_info_table.iter_mut() {
for entry in cpu_info_table.iter_mut() {
if !is_first_entry && entry.found {
// except for the 'processor' field, ignore repeated values.
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/linux/ptrace_dumper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ impl PtraceDumper {
// guaranteed (see http://crosbug.com/25355); therefore, try to use the
// actual entry point to find the mapping.
let at_entry;
#[cfg(target_arch = "arm")]
#[cfg(any(target_arch = "arm", all(target_os = "android", target_arch = "x86")))]
{
at_entry = 9;
}
#[cfg(not(target_arch = "arm"))]
#[cfg(not(any(target_arch = "arm", all(target_os = "android", target_arch = "x86"))))]
{
at_entry = libc::AT_ENTRY;
}
Expand Down
105 changes: 94 additions & 11 deletions src/linux/thread_info/x86.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,124 @@
use super::{CommonThreadInfo, NT_Elf, Pid};
use crate::{errors::ThreadInfoError, minidump_cpu::RawContextCPU, minidump_format::format};
use core::mem::size_of_val;
use libc::user;
#[cfg(all(not(target_os = "android"), target_arch = "x86"))]
use libc::user_fpxregs_struct;
#[cfg(not(all(target_os = "android", target_arch = "x86")))]
use libc::{user, user_fpregs_struct, user_regs_struct};
use nix::sys::ptrace;
use scroll::Pwrite;

type Result<T> = std::result::Result<T, ThreadInfoError>;

// Not defined by libc on Android
#[cfg(all(target_os = "android", target_arch = "x86"))]
#[allow(non_camel_case_types)]
#[repr(C)]
pub struct user_regs_struct {
pub ebx: libc::c_long,
pub ecx: libc::c_long,
pub edx: libc::c_long,
pub esi: libc::c_long,
pub edi: libc::c_long,
pub ebp: libc::c_long,
pub eax: libc::c_long,
pub xds: libc::c_long,
pub xes: libc::c_long,
pub xfs: libc::c_long,
pub xgs: libc::c_long,
pub orig_eax: libc::c_long,
pub eip: libc::c_long,
pub xcs: libc::c_long,
pub eflags: libc::c_long,
pub esp: libc::c_long,
pub xss: libc::c_long,
}

// Not defined by libc on Android
#[cfg(all(target_os = "android", target_arch = "x86"))]
#[allow(non_camel_case_types)]
#[repr(C)]
pub struct user_fpxregs_struct {
pub cwd: libc::c_ushort,
pub swd: libc::c_ushort,
pub twd: libc::c_ushort,
pub fop: libc::c_ushort,
pub fip: libc::c_long,
pub fcs: libc::c_long,
pub foo: libc::c_long,
pub fos: libc::c_long,
pub mxcsr: libc::c_long,
__reserved: libc::c_long,
pub st_space: [libc::c_long; 32],
pub xmm_space: [libc::c_long; 32],
padding: [libc::c_long; 56],
}

// Not defined by libc on Android
#[cfg(all(target_os = "android", target_arch = "x86"))]
#[allow(non_camel_case_types)]
#[repr(C)]
pub struct user_fpregs_struct {
pub cwd: libc::c_long,
pub swd: libc::c_long,
pub twd: libc::c_long,
pub fip: libc::c_long,
pub fcs: libc::c_long,
pub foo: libc::c_long,
pub fos: libc::c_long,
pub st_space: [libc::c_long; 20],
}

#[cfg(all(target_os = "android", target_arch = "x86"))]
#[allow(non_camel_case_types)]
#[repr(C)]
pub struct user {
pub regs: user_regs_struct,
pub u_fpvalid: libc::c_long,
pub i387: user_fpregs_struct,
pub u_tsize: libc::c_ulong,
pub u_dsize: libc::c_ulong,
pub u_ssize: libc::c_ulong,
pub start_code: libc::c_ulong,
pub start_stack: libc::c_ulong,
pub signal: libc::c_long,
__reserved: libc::c_int,
pub u_ar0: *mut user_regs_struct,
pub u_fpstate: *mut user_fpregs_struct,
pub magic: libc::c_ulong,
pub u_comm: [libc::c_char; 32],
pub u_debugreg: [libc::c_int; 8],
}

const NUM_DEBUG_REGISTERS: usize = 8;

pub struct ThreadInfoX86 {
pub stack_pointer: usize,
pub tgid: Pid, // thread group id
pub ppid: Pid, // parent process
pub regs: libc::user_regs_struct,
pub fpregs: libc::user_fpregs_struct,
pub regs: user_regs_struct,
pub fpregs: user_fpregs_struct,
#[cfg(target_arch = "x86_64")]
pub dregs: [libc::c_ulonglong; NUM_DEBUG_REGISTERS],
#[cfg(target_arch = "x86")]
pub dregs: [libc::c_int; NUM_DEBUG_REGISTERS],
#[cfg(target_arch = "x86")]
pub fpxregs: libc::user_fpxregs_struct,
pub fpxregs: user_fpxregs_struct,
}

impl CommonThreadInfo for ThreadInfoX86 {}

impl ThreadInfoX86 {
// nix currently doesn't support PTRACE_GETREGSET, so we have to do it ourselves
fn getregset(pid: Pid) -> Result<libc::user_regs_struct> {
fn getregset(pid: Pid) -> Result<user_regs_struct> {
Self::ptrace_get_data_via_io(
0x4204 as ptrace::RequestType, // PTRACE_GETREGSET
Some(NT_Elf::NT_PRSTATUS),
nix::unistd::Pid::from_raw(pid),
)
}

pub fn getregs(pid: Pid) -> Result<libc::user_regs_struct> {
pub fn getregs(pid: Pid) -> Result<user_regs_struct> {
// TODO: nix restricts PTRACE_GETREGS to arm android for some reason
Self::ptrace_get_data(
12 as ptrace::RequestType, // PTRACE_GETREGS
Expand All @@ -45,7 +128,7 @@ impl ThreadInfoX86 {
}

// nix currently doesn't support PTRACE_GETREGSET, so we have to do it ourselves
fn getfpregset(pid: Pid) -> Result<libc::user_fpregs_struct> {
fn getfpregset(pid: Pid) -> Result<user_fpregs_struct> {
Self::ptrace_get_data_via_io(
0x4204 as ptrace::RequestType, // PTRACE_GETREGSET
Some(NT_Elf::NT_PRFPREGSET),
Expand All @@ -54,7 +137,7 @@ impl ThreadInfoX86 {
}

// nix currently doesn't support PTRACE_GETFPREGS, so we have to do it ourselves
fn getfpregs(pid: Pid) -> Result<libc::user_fpregs_struct> {
fn getfpregs(pid: Pid) -> Result<user_fpregs_struct> {
Self::ptrace_get_data(
14 as ptrace::RequestType, // PTRACE_GETFPREGS
None,
Expand All @@ -64,9 +147,9 @@ impl ThreadInfoX86 {

// nix currently doesn't support PTRACE_GETFPXREGS, so we have to do it ourselves
#[cfg(target_arch = "x86")]
fn getfpxregs(pid: Pid) -> Result<libc::user_fpxregs_struct> {
fn getfpxregs(pid: Pid) -> Result<user_fpxregs_struct> {
Self::ptrace_get_data(
ptrace::Request::PTRACE_GETFPXREGS as ptrace::RequestType,
18 as ptrace::RequestType, // PTRACE_GETFPXREGS
None,
nix::unistd::Pid::from_raw(pid),
)
Expand All @@ -86,7 +169,7 @@ impl ThreadInfoX86 {
let regs = Self::getregset(tid).or_else(|_| Self::getregs(tid))?;
let fpregs = Self::getfpregset(tid).or_else(|_| Self::getfpregs(tid))?;
#[cfg(target_arch = "x86")]
let fpxregs: libc::user_fpxregs_struct;
let fpxregs: user_fpxregs_struct;
#[cfg(target_arch = "x86")]
{
if cfg!(target_feature = "fxsr") {
Expand Down
Loading