Skip to content

Commit

Permalink
Require that Pod: Clone
Browse files Browse the repository at this point in the history
With upcoming changes we are going to support either working with memory
mapped ELF data or with data retrieved using regular file I/O APIs.
Obviously, from a memory management perspective the two behave
differently: where one just requires some massaging of byte slices, the
other necessitates heap allocated buffers.
In order for our ELF types to play nice with the latter, guarantee that
everything implementing Pod also is cloneable.

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o authored and danielocfb committed Dec 23, 2024
1 parent a2e6c8a commit 6ee4daa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/elf/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub(crate) trait Has32BitTy {
}


#[derive(Debug, Default)]
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub(crate) struct Elf32_Ehdr {
pub e_ident: [u8; EI_NIDENT],
Expand All @@ -131,7 +131,7 @@ pub(crate) struct Elf32_Ehdr {
unsafe impl Pod for Elf32_Ehdr {}


#[derive(Debug, Default)]
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub(crate) struct Elf64_Ehdr {
pub e_ident: [u8; EI_NIDENT], /* ELF "magic number" */
Expand Down Expand Up @@ -572,7 +572,7 @@ impl ElfN_Sym<'_> {
pub(crate) const NT_GNU_BUILD_ID: Elf64_Word = 3;


#[derive(Debug, Default)]
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub(crate) struct Elf32_Nhdr {
pub n_namesz: Elf32_Word, /* Length of the note's name. */
Expand All @@ -584,7 +584,7 @@ pub(crate) struct Elf32_Nhdr {
unsafe impl Pod for Elf32_Nhdr {}


#[derive(Debug, Default)]
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub(crate) struct Elf64_Nhdr {
pub n_namesz: Elf64_Word,
Expand All @@ -600,7 +600,7 @@ impl Has32BitTy for Elf64_Nhdr {
}


#[derive(Debug)]
#[derive(Clone, Debug)]
#[repr(C)]
pub(crate) struct Elf32_Chdr {
pub ch_type: Elf32_Word, /* Compression format. */
Expand All @@ -612,7 +612,7 @@ pub(crate) struct Elf32_Chdr {
unsafe impl Pod for Elf32_Chdr {}


#[derive(Debug)]
#[derive(Clone, Debug)]
#[repr(C)]
pub(crate) struct Elf64_Chdr {
/// Compression format.
Expand Down
1 change: 1 addition & 0 deletions src/gsym/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Header {
pub _uuid: [u8; 20],
}

#[derive(Clone, Debug)]
#[repr(C)]
pub struct FileInfo {
pub directory: u32,
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ where
///
/// # Safety
/// Only safe to implement for types that are valid for any bit pattern.
pub unsafe trait Pod {}
pub unsafe trait Pod: Clone {}

unsafe impl Pod for i8 {}
unsafe impl Pod for u8 {}
Expand Down
3 changes: 3 additions & 0 deletions src/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const FLAG_HAS_DATA_DESCRIPTOR: u16 = 1 << 3;


/// See section 4.3.16 of the spec.
#[derive(Clone, Debug)]
#[repr(C, packed)]
struct EndOfCdRecord {
/// Magic value equal to END_OF_CD_RECORD_MAGIC.
Expand Down Expand Up @@ -62,6 +63,7 @@ unsafe impl Pod for EndOfCdRecord {}


/// See section 4.3.12 of the spec.
#[derive(Clone, Debug)]
#[repr(C, packed)]
struct CdFileHeader {
/// Magic value equal to CD_FILE_HEADER_MAGIC.
Expand Down Expand Up @@ -93,6 +95,7 @@ unsafe impl Pod for CdFileHeader {}


/// See section 4.3.7 of the spec.
#[derive(Clone, Debug)]
#[repr(C, packed)]
struct LocalFileHeader {
/// Magic value equal to LOCAL_FILE_HEADER_MAGIC.
Expand Down

0 comments on commit 6ee4daa

Please sign in to comment.