| 1 |
cfg_if::cfg_if! { |
| 2 |
if #[cfg(any( |
| 3 |
target_arch = "x86_64", |
| 4 |
target_arch = "x86", |
| 5 |
target_arch = "mips", |
| 6 |
target_arch = "mips64" |
| 7 |
))] |
| 8 |
{ |
| 9 |
pub mod x86_mips; |
| 10 |
pub use x86_mips as imp; |
| 11 |
} else if #[cfg(any( |
| 12 |
target_arch = "arm", |
| 13 |
target_arch = "aarch64", |
| 14 |
))] |
| 15 |
{ |
| 16 |
pub mod arm; |
| 17 |
pub use arm as imp; |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
pub use imp::write_cpu_information; |
| 22 |
|
| 23 |
use crate::minidump_format::PlatformId; |
| 24 |
use nix::sys::utsname::uname; |
| 25 |
|
| 26 |
/// Retrieves the [`MDOSPlatform`] and synthesized version information |
| 27 |
pub fn os_information() -> (PlatformId, String) { |
| 28 |
let platform_id = if cfg!(target_os = "android") { |
| 29 |
PlatformId::Android |
| 30 |
} else { |
| 31 |
PlatformId::Linux |
| 32 |
}; |
| 33 |
|
| 34 |
// This is quite unfortunate, but the primary reason that uname could fail |
| 35 |
// would be if it failed to fill out the nodename (hostname) field, even |
| 36 |
// though we don't care about that particular field at all |
| 37 |
let info = uname().map_or_else( |
| 38 |
|_e| { |
| 39 |
let os = if platform_id == PlatformId::Linux { |
| 40 |
"Linux" |
| 41 |
} else { |
| 42 |
"Android" |
| 43 |
}; |
| 44 |
|
| 45 |
let machine = if cfg!(target_arch = "x86_64") { |
| 46 |
"x86_64" |
| 47 |
} else if cfg!(target_arch = "x86") { |
| 48 |
"x86" |
| 49 |
} else if cfg!(target_arch = "aarch64") { |
| 50 |
"aarch64" |
| 51 |
} else if cfg!(target_arch = "arm") { |
| 52 |
"arm" |
| 53 |
} else { |
| 54 |
"<unknown>" |
| 55 |
}; |
| 56 |
|
| 57 |
// TODO: Fallback to other sources of information, eg /etc/os-release |
| 58 |
format!("{os} <unknown> <unknown> {machine}") |
| 59 |
}, |
| 60 |
|info| { |
| 61 |
format!( |
| 62 |
"{} {} {} {}", |
| 63 |
info.sysname().to_str().unwrap_or("<unknown>"), |
| 64 |
info.release().to_str().unwrap_or("<unknown>"), |
| 65 |
info.version().to_str().unwrap_or("<unknown>"), |
| 66 |
info.machine().to_str().unwrap_or("<unknown>"), |
| 67 |
) |
| 68 |
}, |
| 69 |
); |
| 70 |
|
| 71 |
(platform_id, info) |
| 72 |
} |