Skip to content

Update dependencies and fix a clippy warning #33

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
2 changes: 1 addition & 1 deletion elfcore-sample/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions elfcore/src/arch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions elfcore/src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -31,6 +32,7 @@ pub trait Arch {
const EM_ELF_MACHINE: u16;

fn new(pid: Pid) -> Result<Box<Self>, CoreError>;
#[allow(unused)]
fn name() -> &'static str;
fn greg_set(&self) -> elf_gregset_t;
fn components(&self) -> &Vec<ArchComponentState>;
Expand Down
7 changes: 3 additions & 4 deletions elfcore/src/arch/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
13 changes: 7 additions & 6 deletions elfcore/src/coredump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -437,7 +438,7 @@ fn get_aux_vector(pid: Pid) -> Result<Vec<Elf64_Auxv>, 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,
}
Expand Down Expand Up @@ -541,7 +542,7 @@ fn get_va_regions(pid: Pid) -> Result<(Vec<VaRegion>, Vec<MappedFile>, 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::<Elf64_Ehdr>(),
Expand Down
18 changes: 9 additions & 9 deletions elfcore/src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -96,15 +96,15 @@ pub struct siginfo_t {
}

/// Kernel time value
#[derive(AsBytes)]
#[derive(IntoBytes, Immutable)]
#[repr(C)]
pub struct pr_timeval_t {
pub tv_sec: u64,
pub tv_usec: u64,
}

/// Program status
#[derive(AsBytes)]
#[derive(IntoBytes, Immutable)]
#[repr(C)]
pub struct prstatus_t {
// total size (bytes): 336 (x86_64)
Expand All @@ -129,15 +129,15 @@ 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
pub a_val: u64,
}

/// ELF note header
#[derive(AsBytes)]
#[derive(IntoBytes, Immutable)]
#[repr(C)]
pub struct Elf64_Nhdr {
pub namesz: u32,
Expand All @@ -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],
Expand Down
7 changes: 5 additions & 2 deletions elfcore/src/ptrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: AsBytes + FromBytes>(pid: Pid, set: u32) -> Result<Vec<T>, CoreError> {
pub fn ptrace_get_reg_set<T: IntoBytes + FromBytes>(
pid: Pid,
set: u32,
) -> Result<Vec<T>, CoreError> {
let mut data = Vec::with_capacity(0x1000 / std::mem::size_of::<T>());
let vec = nix::libc::iovec {
iov_base: data.as_mut_ptr() as *mut c_void,
Expand Down