diff --git a/Cargo.toml b/Cargo.toml index 8d6a0f8..5d3ff1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,9 +8,9 @@ members = [ [workspace.dependencies] anyhow = "1.0" libc = "0.2" -nix = { version = "0.26", default-features = false, features = ["fs", "feature", "process", "ptrace", "uio"] } +nix = { version = "0.29", default-features = false, features = ["fs", "feature", "process", "ptrace", "uio"] } smallvec = "1.8" -thiserror = "1.0" +thiserror = "2.0" tracing = "0.1" tracing-subscriber = "0.3.17" -zerocopy = { version = "0.7.32", features = ["derive"] } +zerocopy = { version = "0.8", features = ["derive"] } diff --git a/elfcore-sample/src/main.rs b/elfcore-sample/src/main.rs index c41e304..7ee0ebc 100644 --- a/elfcore-sample/src/main.rs +++ b/elfcore-sample/src/main.rs @@ -20,7 +20,7 @@ use tracing::Level; pub fn main() -> anyhow::Result<()> { let mut args = std::env::args().skip(1).peekable(); - let level = if args.peek().map_or(false, |x| x == "-v") { + let level = if args.peek().is_some_and(|x| x == "-v") { args.next(); Level::DEBUG } else { diff --git a/elfcore/src/arch/aarch64.rs b/elfcore/src/arch/aarch64.rs index c394fa2..cbcfaf3 100644 --- a/elfcore/src/arch/aarch64.rs +++ b/elfcore/src/arch/aarch64.rs @@ -3,13 +3,12 @@ //! Aarch64 specifics for ELF core dump files. -#![cfg(target_arch = "aarch64")] - use super::ArchComponentState; use crate::ptrace::ptrace_get_reg_set; use crate::CoreError; use nix::unistd::Pid; -use zerocopy::AsBytes; +use zerocopy::Immutable; +use zerocopy::IntoBytes; // aarch64 machine pub const EM_AARCH64: u16 = 183; @@ -21,7 +20,7 @@ pub const NT_ARM_HW_WATCH: u32 = 0x403; pub const NT_ARM_SYSTEM_CALL: u32 = 0x404; #[repr(C, packed)] -#[derive(Clone, Copy, Debug, AsBytes)] +#[derive(Clone, Copy, Debug, IntoBytes, Immutable)] pub struct elf_gregset_t { pub regs: [u64; 31], pub sp: u64, diff --git a/elfcore/src/arch/mod.rs b/elfcore/src/arch/mod.rs index a56ce85..fee8eec 100644 --- a/elfcore/src/arch/mod.rs +++ b/elfcore/src/arch/mod.rs @@ -21,6 +21,7 @@ pub use aarch64::elf_gregset_t; #[derive(Debug)] pub struct ArchComponentState { + #[allow(unused)] pub name: &'static str, pub note_type: u32, pub note_name: &'static [u8], @@ -31,6 +32,7 @@ pub trait Arch { const EM_ELF_MACHINE: u16; fn new(pid: Pid) -> Result, CoreError>; + #[allow(unused)] fn name() -> &'static str; fn greg_set(&self) -> elf_gregset_t; fn components(&self) -> &Vec; diff --git a/elfcore/src/arch/x86_64.rs b/elfcore/src/arch/x86_64.rs index 8e3bba4..19f0690 100644 --- a/elfcore/src/arch/x86_64.rs +++ b/elfcore/src/arch/x86_64.rs @@ -3,13 +3,12 @@ //! x86_64 specifics for ELF core dump files. -#![cfg(target_arch = "x86_64")] - use super::ArchComponentState; use crate::ptrace::ptrace_get_reg_set; use crate::CoreError; use nix::unistd::Pid; -use zerocopy::AsBytes; +use zerocopy::Immutable; +use zerocopy::IntoBytes; // amd64 machine pub const EM_X86_64: u16 = 62; @@ -18,7 +17,7 @@ pub const EM_X86_64: u16 = 62; pub const NT_X86_XSTATE: u32 = 0x202; #[repr(C, packed)] -#[derive(Clone, Copy, Debug, AsBytes)] +#[derive(Clone, Copy, Debug, IntoBytes, Immutable)] pub struct elf_gregset_t { r15: u64, r14: u64, diff --git a/elfcore/src/coredump.rs b/elfcore/src/coredump.rs index b7712c5..f8603eb 100644 --- a/elfcore/src/coredump.rs +++ b/elfcore/src/coredump.rs @@ -32,8 +32,9 @@ use std::io::Read; use std::io::Seek; use std::io::Write; use std::slice; -use zerocopy::AsBytes; -use zerocopy::FromZeroes; +use zerocopy::FromZeros; +use zerocopy::Immutable; +use zerocopy::IntoBytes; const ELF_HEADER_ALIGN: usize = 8; const ELF_NOTE_ALIGN: usize = 4; @@ -91,14 +92,14 @@ where } } -#[derive(AsBytes)] +#[derive(IntoBytes, Immutable)] #[repr(C, packed)] struct MappedFilesNoteIntro { file_count: u64, page_size: u64, } -#[derive(AsBytes)] +#[derive(IntoBytes, Immutable)] #[repr(C, packed)] struct MappedFilesNoteItem { start_addr: u64, @@ -437,7 +438,7 @@ fn get_aux_vector(pid: Pid) -> Result, CoreError> { a_val: 0, }; - match file.read_exact(aux.as_bytes_mut()) { + match file.read_exact(aux.as_mut_bytes()) { Ok(_) => auxv.push(aux), Err(_) => break, } @@ -541,7 +542,7 @@ fn get_va_regions(pid: Pid) -> Result<(Vec, Vec, u64), Cor let mut elf_hdr = Elf64_Ehdr::new_zeroed(); match process_vm_readv( pid, - &mut [IoSliceMut::new(elf_hdr.as_bytes_mut())], + &mut [IoSliceMut::new(elf_hdr.as_mut_bytes())], &[RemoteIoVec { base: begin as usize, len: std::mem::size_of::(), diff --git a/elfcore/src/elf.rs b/elfcore/src/elf.rs index 0907023..06a48ca 100644 --- a/elfcore/src/elf.rs +++ b/elfcore/src/elf.rs @@ -6,9 +6,9 @@ //! constrained environment. use super::arch; -use zerocopy::AsBytes; use zerocopy::FromBytes; -use zerocopy::FromZeroes; +use zerocopy::Immutable; +use zerocopy::IntoBytes; pub const EI_MAG0: usize = 0; pub const EI_MAG1: usize = 1; @@ -63,7 +63,7 @@ pub const NT_SIGINFO: u32 = 0x53494749; pub const NT_FILE: u32 = 0x46494c45; /// Program status -#[derive(AsBytes)] +#[derive(IntoBytes, Immutable)] #[repr(C)] pub struct prpsinfo_t { // total size (bytes): 136 @@ -84,7 +84,7 @@ pub struct prpsinfo_t { } /// Signal information -#[derive(AsBytes)] +#[derive(IntoBytes, Immutable)] #[repr(C)] pub struct siginfo_t { // total size (bytes): 128 @@ -96,7 +96,7 @@ pub struct siginfo_t { } /// Kernel time value -#[derive(AsBytes)] +#[derive(IntoBytes, Immutable)] #[repr(C)] pub struct pr_timeval_t { pub tv_sec: u64, @@ -104,7 +104,7 @@ pub struct pr_timeval_t { } /// Program status -#[derive(AsBytes)] +#[derive(IntoBytes, Immutable)] #[repr(C)] pub struct prstatus_t { // total size (bytes): 336 (x86_64) @@ -129,7 +129,7 @@ pub struct prstatus_t { } /// ELF auxiliary vector note -#[derive(AsBytes, FromBytes, FromZeroes, Clone, Copy, Debug)] +#[derive(IntoBytes, FromBytes, Immutable, Clone, Copy, Debug)] #[repr(C)] pub struct Elf64_Auxv { pub a_type: u64, // from auxvec.h @@ -137,7 +137,7 @@ pub struct Elf64_Auxv { } /// ELF note header -#[derive(AsBytes)] +#[derive(IntoBytes, Immutable)] #[repr(C)] pub struct Elf64_Nhdr { pub namesz: u32, @@ -146,7 +146,7 @@ pub struct Elf64_Nhdr { } /// ELF header -#[derive(AsBytes, FromBytes, FromZeroes)] +#[derive(IntoBytes, FromBytes, Immutable)] #[repr(C)] pub struct Elf64_Ehdr { pub e_ident: [u8; 16], diff --git a/elfcore/src/ptrace.rs b/elfcore/src/ptrace.rs index da7fa0d..97eb100 100644 --- a/elfcore/src/ptrace.rs +++ b/elfcore/src/ptrace.rs @@ -13,10 +13,13 @@ use nix::sys; use nix::sys::ptrace::Request; use nix::sys::ptrace::RequestType; use nix::unistd::Pid; -use zerocopy::AsBytes; use zerocopy::FromBytes; +use zerocopy::IntoBytes; -pub fn ptrace_get_reg_set(pid: Pid, set: u32) -> Result, CoreError> { +pub fn ptrace_get_reg_set( + pid: Pid, + set: u32, +) -> Result, CoreError> { let mut data = Vec::with_capacity(0x1000 / std::mem::size_of::()); let vec = nix::libc::iovec { iov_base: data.as_mut_ptr() as *mut c_void,