From 85d6d38cfaa03b1f1ad2006a641985d8ae0e1cef Mon Sep 17 00:00:00 2001 From: Steven Malis Date: Wed, 4 Mar 2026 12:01:14 -0500 Subject: [PATCH 1/2] Update deps --- Cargo.toml | 6 +++--- elfcore/src/arch/aarch64.rs | 12 +++++++----- elfcore/src/arch/x86_64.rs | 5 +++-- elfcore/src/coredump.rs | 7 ++++--- elfcore/src/elf.rs | 20 ++++++++++---------- elfcore/src/linux/process.rs | 8 ++++---- elfcore/src/linux/ptrace.rs | 7 +++++-- 7 files changed, 36 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8d6a0f8..d7c66cb 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.31", default-features = false, features = ["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/src/arch/aarch64.rs b/elfcore/src/arch/aarch64.rs index fea8e41..0059c56 100644 --- a/elfcore/src/arch/aarch64.rs +++ b/elfcore/src/arch/aarch64.rs @@ -5,14 +5,16 @@ #![cfg(target_arch = "aarch64")] +#[cfg(target_os = "linux")] use super::ArchComponentState; -use crate::CoreError; -use zerocopy::AsBytes; - #[cfg(target_os = "linux")] -use crate::ptrace::ptrace_get_reg_set; +use crate::linux::ptrace::ptrace_get_reg_set; +#[cfg(target_os = "linux")] +use crate::CoreError; #[cfg(target_os = "linux")] use nix::unistd::Pid; +use zerocopy::Immutable; +use zerocopy::IntoBytes; // aarch64 machine pub const EM_AARCH64: u16 = 183; @@ -24,7 +26,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/x86_64.rs b/elfcore/src/arch/x86_64.rs index 0ff2a56..0e1e8da 100644 --- a/elfcore/src/arch/x86_64.rs +++ b/elfcore/src/arch/x86_64.rs @@ -11,7 +11,8 @@ use crate::linux::ptrace::ptrace_get_reg_set; use crate::CoreError; #[cfg(target_os = "linux")] use nix::unistd::Pid; -use zerocopy::AsBytes; +use zerocopy::Immutable; +use zerocopy::IntoBytes; // amd64 machine pub const EM_X86_64: u16 = 62; @@ -21,7 +22,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 047ebb8..db3eda4 100644 --- a/elfcore/src/coredump.rs +++ b/elfcore/src/coredump.rs @@ -17,7 +17,8 @@ use smallvec::SmallVec; use std::io::Read; use std::io::Write; use std::slice; -use zerocopy::AsBytes; +use zerocopy::Immutable; +use zerocopy::IntoBytes; #[cfg(target_os = "linux")] use crate::{LinuxProcessMemoryReader, ProcessView}; @@ -78,14 +79,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, diff --git a/elfcore/src/elf.rs b/elfcore/src/elf.rs index 7e1afc3..2e84448 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; @@ -66,7 +66,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 @@ -87,7 +87,7 @@ pub struct prpsinfo_t { } /// Signal information -#[derive(AsBytes)] +#[derive(IntoBytes, Immutable)] #[repr(C)] pub struct siginfo_t { // total size (bytes): 128 @@ -99,7 +99,7 @@ pub struct siginfo_t { } /// Kernel time value -#[derive(AsBytes)] +#[derive(IntoBytes, Immutable)] #[repr(C)] pub struct pr_timeval_t { pub tv_sec: u64, @@ -107,7 +107,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) @@ -132,7 +132,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 { /// AUXV type @@ -142,7 +142,7 @@ pub struct Elf64_Auxv { } /// ELF note header -#[derive(AsBytes)] +#[derive(IntoBytes, Immutable)] #[repr(C)] pub struct Elf64_Nhdr { pub namesz: u32, @@ -151,7 +151,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], @@ -171,7 +171,7 @@ pub struct Elf64_Ehdr { } /// ELF program header -#[derive(AsBytes, FromBytes, FromZeroes)] +#[derive(IntoBytes, FromBytes, Immutable)] #[repr(C)] pub struct Elf64_Phdr { pub p_type: u32, diff --git a/elfcore/src/linux/process.rs b/elfcore/src/linux/process.rs index b2b6c98..1d13209 100644 --- a/elfcore/src/linux/process.rs +++ b/elfcore/src/linux/process.rs @@ -26,8 +26,8 @@ use std::collections::HashSet; use std::fs; use std::fs::File; use std::io::{BufRead, IoSliceMut, Read}; -use zerocopy::AsBytes; -use zerocopy::FromZeroes; +use zerocopy::FromZeros; +use zerocopy::IntoBytes; impl ThreadView { pub(crate) fn new(pid: Pid, tid: Pid) -> Result { @@ -210,7 +210,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, } @@ -314,7 +314,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/linux/ptrace.rs b/elfcore/src/linux/ptrace.rs index da4388c..93b4526 100644 --- a/elfcore/src/linux/ptrace.rs +++ b/elfcore/src/linux/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, From 5353028ed96cf3239079c973578e2828695fcf20 Mon Sep 17 00:00:00 2001 From: Steven Malis Date: Fri, 6 Mar 2026 13:23:10 -0500 Subject: [PATCH 2/2] cleanups --- .cargo/config.toml | 85 ------------------------------------ Cargo.toml | 24 ++++++++++ elfcore-sample/Cargo.toml | 3 ++ elfcore/Cargo.toml | 3 ++ elfcore/src/arch/aarch64.rs | 2 - elfcore/src/coredump.rs | 46 +++++++++---------- elfcore/src/lib.rs | 2 +- elfcore/src/linux/memory.rs | 2 +- elfcore/src/linux/process.rs | 8 ++-- elfcore/src/linux/ptrace.rs | 19 ++++---- 10 files changed, 65 insertions(+), 129 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index a89f66a..6231758 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -11,91 +11,6 @@ rustflags = [ # Enable v0 symbols to get better output from `perf` and related tools. "-Csymbol-mangling-version=v0", - # ============ - # Clippy Lints - # ============ - - "-Dfuture_incompatible", - "-Dnonstandard_style", - "-Drust_2018_idioms", - - "-Wunsafe_op_in_unsafe_fn", - "-Wclippy::await_holding_lock", - "-Wclippy::dbg_macro", - "-Wclippy::debug_assert_with_mut_call", - "-Wclippy::filter_map_next", - "-Wclippy::fn_params_excessive_bools", - "-Wclippy::imprecise_flops", - "-Wclippy::inefficient_to_string", - "-Wclippy::linkedlist", - "-Wclippy::lossy_float_literal", - "-Wclippy::macro_use_imports", - "-Wclippy::match_on_vec_items", - "-Wclippy::needless_continue", - "-Wclippy::option_option", - "-Wclippy::ref_option_ref", - "-Wclippy::rest_pat_in_fully_bound_structs", - "-Wclippy::string_to_string", - "-Wclippy::suboptimal_flops", - "-Wclippy::missing_safety_doc", - "-Wclippy::undocumented_unsafe_blocks", - - # Possible future additions: - # - # useful, but _very_ tedious to fix - # "-Wclippy::doc_markdown", - # will be useful to weed-out stubbed codepaths in production - # "-Wclippy::todo", - # "-Wclippy::unimplemented", - # useful, but will require a follow-up PR to enable - # "-Wclippy::map_err_ignore", - # useful, but requires a follow-up PR to enable - # "-Wclippy::unused_self", - - # Nested if / else if statements can be easier to read than an equivalent - # flattened statements. - "-Aclippy::collapsible_else_if", - "-Aclippy::collapsible_if", - # There are types where it makes sense to define the length, but it can never - # be empty. This lint is reasonable for container-like data-structures, but - # makes less sense for hardware-backed data structures. - "-Aclippy::len_without_is_empty", - # While it's generally a good idea to derive / implement `Default` when - # appropriate, there are many types in the HvLite codebase where a type has a - # `new()` method, but no sensible "Default". - "-Aclippy::new_without_default", - # This is the #1 most commonly ignored lint for a reason (at least according - # to [this famous issue](https://github.com/rust-lang/rust-clippy/issues/5418) - # on the clippy GitHub repo)! There are plenty of perfectly reasonable - # functions that require a large number of non-optional arguments, - # particularly when working with low-level hardware APIs. - "-Aclippy::too_many_arguments", - # Pointer casts are harder to grok than an equivalent \*explicitly annotated\* - # `transmute`. Emphasis on the fact that the transmute should _not_ infer the - # underlying types, and that the turbofish operator should be used to clearly - # specify which types are being transmuted. - # - # e.g: `let callback = transmute::<*const c_void, *const fn() -> c_int>` - "-Aclippy::transmutes_expressible_as_ptr_casts", - # This is a heuristic based lint that isn't always appropriate. While it's - # often a good to decompose complex types into more digestible chunks, there - # are many cases where a one-off complex type is required, and suppressing - # this lint will simply add line-noise. - "-Aclippy::type_complexity", - # This lint attempts to simplify usages of if let usage in a loop where only - # one variant type is used. While somewhat useful, its suggestions can lead to - # throwing away potentially useful error information in non-obvious ways. - "-Aclippy::manual_flatten", - # This lint warns about comparing boolean values in an `assert_eq!` statement when `assert!` - # could be used instead. While shorter, the explicit comparison can be more obvious to read - # in certain cases than unary operators with `assert!`. - "-Aclippy::bool_assert_comparison", - # This lint suggests collapsing Box::new(Foo::default()) into Box::default(). We often - # prefer to specify types completely for local code clarity's sake. - "-Aclippy::box_default", - # This lint is purely style, and we are ok with inlined and uninlined format args. - "-Aclippy::uninlined_format_args", - ### ENABLE_IN_CI "-Dwarnings", ] \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index d7c66cb..2833787 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,27 @@ thiserror = "2.0" tracing = "0.1" tracing-subscriber = "0.3.17" zerocopy = { version = "0.8", features = ["derive"] } + +[workspace.lints.rust] +# Lint groups need a priority lower than individual lints so they get applied first. +future_incompatible = { level = "deny", priority = -2 } +rust_2018_idioms = { level = "warn", priority = -2 } + +[workspace.lints.clippy] +dbg_macro = "warn" +debug_assert_with_mut_call = "warn" +filter_map_next = "warn" +fn_params_excessive_bools = "warn" +implicit_clone = "warn" +imprecise_flops = "warn" +inefficient_to_string = "warn" +linkedlist = "warn" +lossy_float_literal = "warn" +macro_use_imports = "warn" +option_option = "warn" +ptr_cast_constness = "warn" +ref_option_ref = "warn" +rest_pat_in_fully_bound_structs = "warn" +suboptimal_flops = "warn" +undocumented_unsafe_blocks = "warn" +unnecessary_box_returns = "warn" diff --git a/elfcore-sample/Cargo.toml b/elfcore-sample/Cargo.toml index c138f2c..30803f3 100644 --- a/elfcore-sample/Cargo.toml +++ b/elfcore-sample/Cargo.toml @@ -9,3 +9,6 @@ elfcore = { path = "../elfcore" } anyhow.workspace = true tracing.workspace = true tracing-subscriber.workspace = true + +[lints] +workspace = true \ No newline at end of file diff --git a/elfcore/Cargo.toml b/elfcore/Cargo.toml index 81a8149..39b13ff 100644 --- a/elfcore/Cargo.toml +++ b/elfcore/Cargo.toml @@ -18,3 +18,6 @@ zerocopy.workspace = true [target.'cfg(unix)'.dependencies] libc.workspace = true nix.workspace = true + +[lints] +workspace = true \ No newline at end of file diff --git a/elfcore/src/arch/aarch64.rs b/elfcore/src/arch/aarch64.rs index 0059c56..4a191d3 100644 --- a/elfcore/src/arch/aarch64.rs +++ b/elfcore/src/arch/aarch64.rs @@ -3,8 +3,6 @@ //! Aarch64 specifics for ELF core dump files. -#![cfg(target_arch = "aarch64")] - #[cfg(target_os = "linux")] use super::ArchComponentState; #[cfg(target_os = "linux")] diff --git a/elfcore/src/coredump.rs b/elfcore/src/coredump.rs index bf68222..14bb8d7 100644 --- a/elfcore/src/coredump.rs +++ b/elfcore/src/coredump.rs @@ -39,7 +39,7 @@ struct ElfCoreWriter { written: usize, } -impl std::io::Write for ElfCoreWriter +impl Write for ElfCoreWriter where T: Write, { @@ -168,14 +168,13 @@ fn get_elf_notes_sizes( custom_notes: Option<&[CustomFileNote<'_>]>, ) -> Result { let header_and_name = - std::mem::size_of::() + round_up(NOTE_NAME_CORE.len() + 1, ELF_NOTE_ALIGN); - let process_info = - header_and_name + round_up(std::mem::size_of::(), ELF_NOTE_ALIGN); + size_of::() + round_up(NOTE_NAME_CORE.len() + 1, ELF_NOTE_ALIGN); + let process_info = header_and_name + round_up(size_of::(), ELF_NOTE_ALIGN); let one_thread_status = header_and_name - + round_up(std::mem::size_of::(), ELF_NOTE_ALIGN) + + round_up(size_of::(), ELF_NOTE_ALIGN) + header_and_name + round_up( - std::mem::size_of::() + { + size_of::() + { let mut arch_size = 0; for component in pv .threads() @@ -194,7 +193,7 @@ fn get_elf_notes_sizes( // Calculate auxv size - do not count if no auxv let aux_vector = pv .aux_vector() - .map(|auxv| header_and_name + std::mem::size_of_val(auxv)) + .map(|auxv| header_and_name + size_of_val(auxv)) .unwrap_or(0); // Calculate mapped files size - do not count if no mapped files @@ -206,11 +205,10 @@ fn get_elf_notes_sizes( for mapped_file in files { string_size += (mapped_file.name.len() + 1) * mapped_file.regions.len(); - addr_layout_size += - std::mem::size_of::() * mapped_file.regions.len(); + addr_layout_size += size_of::() * mapped_file.regions.len(); } - let intro_size = std::mem::size_of::(); + let intro_size = size_of::(); header_and_name + round_up(intro_size + addr_layout_size + string_size, ELF_NOTE_ALIGN) }) @@ -334,9 +332,9 @@ fn write_elf_header( e_type: ET_CORE, e_machine: arch::ArchState::EM_ELF_MACHINE, e_version: EV_CURRENT as u32, - e_phoff: std::mem::size_of::() as u64, - e_ehsize: std::mem::size_of::() as u16, - e_phentsize: std::mem::size_of::() as u16, + e_phoff: size_of::() as u64, + e_ehsize: size_of::() as u16, + e_phentsize: size_of::() as u16, e_phnum: 1 + pv.va_regions().len() as u16, // PT_NOTE and VA regions e_shentsize: 0, e_entry: 0, @@ -354,10 +352,7 @@ fn write_elf_header( // SAFETY: Elf64_Ehdr is repr(C) with no padding bytes, // so all byte patterns are valid. let slice = unsafe { - slice::from_raw_parts( - &elf_header as *const _ as *mut u8, - std::mem::size_of::(), - ) + slice::from_raw_parts(&elf_header as *const _ as *mut u8, size_of::()) }; writer.write_all(slice)?; @@ -382,8 +377,8 @@ fn write_program_headers( // as many PT_LOAD as there are VA regions. // Notes are situated right after the headers. - let phdr_size = std::mem::size_of::() * (pv.va_regions().len() + 1); - let ehdr_size = std::mem::size_of::(); + let phdr_size = size_of::() * (pv.va_regions().len() + 1); + let ehdr_size = size_of::(); let data_offset = round_up(ehdr_size, ELF_HEADER_ALIGN) + round_up(phdr_size, ELF_HEADER_ALIGN); { @@ -403,7 +398,7 @@ fn write_program_headers( let slice = unsafe { slice::from_raw_parts_mut( &mut note_header as *mut _ as *mut u8, - std::mem::size_of::(), + size_of::(), ) }; writer.write_all(slice)?; @@ -446,7 +441,7 @@ fn write_program_headers( let slice = unsafe { slice::from_raw_parts_mut( &mut seg_header as *mut _ as *mut u8, - std::mem::size_of::(), + size_of::(), ) }; writer.write_all(slice)?; @@ -484,7 +479,7 @@ fn write_elf_note_header( writer.stream_position()? ); writer.write_all(note_header.as_bytes())?; - written += std::mem::size_of::(); + written += size_of::(); tracing::debug!( "Writing note name at offset {}...", @@ -534,8 +529,7 @@ fn write_elf_note_file( ) -> Result { let mut written = 0_usize; - let header_and_name = - std::mem::size_of::() + round_up(name_bytes.len() + 1, ELF_NOTE_ALIGN); + let header_and_name = size_of::() + round_up(name_bytes.len() + 1, ELF_NOTE_ALIGN); let data_len = note_len - header_and_name; written += write_elf_note_header(writer, note_kind, name_bytes, data_len)?; @@ -545,7 +539,7 @@ fn write_elf_note_file( writer.stream_position()? ); - let max_len = data_len - std::mem::size_of::(); + let max_len = data_len - size_of::(); let total = std::io::copy(&mut file.take(max_len as u64), writer)? as usize; if file.read(&mut [0]).unwrap_or(0) != 0 { tracing::warn!(truncated_len = total, "note will be truncated"); @@ -557,7 +551,7 @@ fn write_elf_note_file( } writer.write_all((total as u32).as_bytes())?; - written += std::mem::size_of::(); + written += size_of::(); written += writer.align_position(ELF_NOTE_ALIGN)?; Ok(written) diff --git a/elfcore/src/lib.rs b/elfcore/src/lib.rs index 56168b5..32082cd 100644 --- a/elfcore/src/lib.rs +++ b/elfcore/src/lib.rs @@ -273,5 +273,5 @@ pub struct ThreadView { pub sigpend: u64, /// State of the CPU - pub arch_state: Box, + pub arch_state: Box, } diff --git a/elfcore/src/linux/memory.rs b/elfcore/src/linux/memory.rs index 9e3d7e5..d0d9925 100644 --- a/elfcore/src/linux/memory.rs +++ b/elfcore/src/linux/memory.rs @@ -80,7 +80,7 @@ fn process_vm_readv_works() -> bool { &mut [IoSliceMut::new(&mut probe_out)], &[RemoteIoVec { base: probe_in.as_ptr() as usize, - len: std::mem::size_of_val(&probe_in), + len: size_of_val(&probe_in), }], ); diff --git a/elfcore/src/linux/process.rs b/elfcore/src/linux/process.rs index 1d13209..6c7c560 100644 --- a/elfcore/src/linux/process.rs +++ b/elfcore/src/linux/process.rs @@ -184,7 +184,7 @@ fn get_thread_ids(pid: Pid) -> Result, CoreError> { if let Some(stem) = stem { if stem != "." && stem != ".." { let stem = stem.to_string_lossy(); - let tid = Pid::from_raw(stem.parse::()? as nix::libc::pid_t); + let tid = Pid::from_raw(stem.parse::()? as libc::pid_t); tracing::debug!("Found thread {}", tid); @@ -317,7 +317,7 @@ fn get_va_regions(pid: Pid) -> Result<(Vec, Vec, u64), Cor &mut [IoSliceMut::new(elf_hdr.as_mut_bytes())], &[RemoteIoVec { base: begin as usize, - len: std::mem::size_of::(), + len: size_of::(), }], ) { Ok(_) => Some(elf_hdr), @@ -331,9 +331,9 @@ fn get_va_regions(pid: Pid) -> Result<(Vec, Vec, u64), Cor && elf_hdr.e_ident[EI_MAG2] == ELFMAG2 && elf_hdr.e_ident[EI_MAG3] == ELFMAG3 && elf_hdr.e_ident[EI_VERSION] == EV_CURRENT - && elf_hdr.e_ehsize == std::mem::size_of::() as u16 + && elf_hdr.e_ehsize == size_of::() as u16 && (elf_hdr.e_type == ET_EXEC || elf_hdr.e_type == ET_DYN) - && elf_hdr.e_phentsize == std::mem::size_of::() as u16 + && elf_hdr.e_phentsize == size_of::() as u16 && elf_hdr.e_machine == arch::ArchState::EM_ELF_MACHINE { mapped_elfs.insert(mapped_file_name.clone()); diff --git a/elfcore/src/linux/ptrace.rs b/elfcore/src/linux/ptrace.rs index 93b4526..0593246 100644 --- a/elfcore/src/linux/ptrace.rs +++ b/elfcore/src/linux/ptrace.rs @@ -9,7 +9,6 @@ use std::ptr; use crate::elf::NT_PRFPREG; use crate::elf::NT_PRSTATUS; use crate::CoreError; -use nix::sys; use nix::sys::ptrace::Request; use nix::sys::ptrace::RequestType; use nix::unistd::Pid; @@ -20,23 +19,23 @@ 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 { + let mut data = Vec::with_capacity(0x1000 / size_of::()); + let vec = libc::iovec { iov_base: data.as_mut_ptr() as *mut c_void, - iov_len: data.capacity() * std::mem::size_of::(), + iov_len: data.capacity() * size_of::(), }; let err; // SAFETY: Using FFI with the process trace API to read raw bytes. unsafe { - err = nix::libc::ptrace( + err = libc::ptrace( Request::PTRACE_GETREGSET as RequestType, - nix::libc::pid_t::from(pid), + libc::pid_t::from(pid), set, &vec as *const _ as *const c_void, ); - data.set_len(vec.iov_len / std::mem::size_of::()); + data.set_len(vec.iov_len / size_of::()); data.shrink_to_fit(); }; @@ -48,9 +47,9 @@ pub fn ptrace_interrupt(pid: Pid) -> Result<(), CoreError> { // SAFETY: Using FFI with the process trace API to read raw bytes. let ret = unsafe { nix::errno::Errno::clear(); - nix::libc::ptrace( - nix::libc::PTRACE_INTERRUPT as sys::ptrace::RequestType, - nix::libc::pid_t::from(pid), + libc::ptrace( + libc::PTRACE_INTERRUPT as RequestType, + libc::pid_t::from(pid), ptr::null_mut::(), ptr::null_mut::(), )