From 8a28a25a5866e184a26c872e6ed1cf3b6dee2f52 Mon Sep 17 00:00:00 2001 From: Ahmed Charles Date: Wed, 6 Dec 2017 05:20:05 +0000 Subject: [PATCH] Various cleanups. Add debug implementations. Mark everything as repr(C) and repr(packed), just to be sure. --- src/elf_sections.rs | 7 ++++--- src/header.rs | 4 +++- src/lib.rs | 4 +++- src/module.rs | 3 ++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/elf_sections.rs b/src/elf_sections.rs index 25b12104..ce0c74f0 100644 --- a/src/elf_sections.rs +++ b/src/elf_sections.rs @@ -45,7 +45,7 @@ impl ElfSectionsTag { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ElfSectionIter { current_section: *const u8, remaining_sections: u32, @@ -78,6 +78,7 @@ impl Iterator for ElfSectionIter { } } +#[derive(Debug)] pub struct ElfSection { inner: *const u8, string_section: *const u8, @@ -85,7 +86,7 @@ pub struct ElfSection { } #[derive(Debug)] -#[repr(C)] +#[repr(C, packed)] struct ElfSectionInner32 { name_index: u32, typ: u32, @@ -100,7 +101,7 @@ struct ElfSectionInner32 { } #[derive(Debug)] -#[repr(C)] +#[repr(C, packed)] struct ElfSectionInner64 { name_index: u32, typ: u32, diff --git a/src/header.rs b/src/header.rs index 2257deb8..2a1722f1 100644 --- a/src/header.rs +++ b/src/header.rs @@ -1,10 +1,12 @@ -#[repr(C)] +#[derive(Debug)] +#[repr(C, packed)] pub struct Tag { pub typ: u32, pub size: u32, // tag specific fields } +#[derive(Debug)] pub struct TagIter { pub current: *const Tag, } diff --git a/src/lib.rs b/src/lib.rs index 99f5cc6f..3e7daa0b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ #![no_std] +#![deny(missing_debug_implementations)] + use core::fmt; use header::{Tag, TagIter}; @@ -33,7 +35,7 @@ pub struct BootInformation { inner: *const BootInformationInner, } -#[repr(C)] +#[repr(C, packed)] struct BootInformationInner { total_size: u32, _reserved: u32, diff --git a/src/module.rs b/src/module.rs index a68a3aec..74bf36f4 100644 --- a/src/module.rs +++ b/src/module.rs @@ -1,7 +1,7 @@ use header::{Tag, TagIter}; -#[repr(packed)] #[derive(Debug)] +#[repr(C, packed)] pub struct ModuleTag { typ: u32, size: u32, @@ -36,6 +36,7 @@ pub fn module_iter(iter: TagIter) -> ModuleIter { ModuleIter { iter: iter } } +#[derive(Debug)] pub struct ModuleIter { iter: TagIter, }