Skip to content

Commit 1e389fa

Browse files
committed
multiboot2: load: remove weird offset thingy API
1 parent 7ba23b6 commit 1e389fa

File tree

4 files changed

+152
-151
lines changed

4 files changed

+152
-151
lines changed

multiboot2/Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
- **BREAKING** Renamed `EFISdt32` to `EFISdt32Tag`
2626
- **BREAKING** Renamed `EFISdt64` to `EFISdt64Tag`
2727
- **BREAKING** Renamed `EFIBootServicesNotExited` to `EFIBootServicesNotExitedTag`
28-
- added `BootInformation::efi_bs_not_exited_tag`
28+
- deprecated `load` and `load_with_offset`
29+
- added `BootInformation::load` as new default constructor
2930

3031
## 0.15.1 (2023-03-18)
3132
- **BREAKING** `MemoryMapTag::all_memory_areas()` was renamed to `memory_areas`

multiboot2/src/builder/information.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl InformationBuilder {
289289
#[cfg(test)]
290290
mod tests {
291291
use crate::builder::information::InformationBuilder;
292-
use crate::{load, BasicMemoryInfoTag, CommandLineTag, ModuleTag};
292+
use crate::{BasicMemoryInfoTag, BootInformation, CommandLineTag, ModuleTag};
293293

294294
#[test]
295295
fn test_size_or_up_aligned() {
@@ -327,8 +327,8 @@ mod tests {
327327
assert_eq!(builder.expected_len(), expected_len);
328328

329329
let mb2i_data = builder.build();
330-
let mb2i_addr = mb2i_data.as_ptr() as usize;
331-
let mb2i = unsafe { load(mb2i_addr) }.expect("the generated information to be readable");
330+
let mb2i = unsafe { BootInformation::load(mb2i_data.as_ptr()) }
331+
.expect("the generated information to be readable");
332332
println!("{:#?}", mb2i);
333333
assert_eq!(mb2i.basic_memory_info_tag().unwrap().memory_lower(), 640);
334334
assert_eq!(

multiboot2/src/elf_sections.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use {
1212

1313
const METADATA_SIZE: usize = size_of::<TagTypeId>() + 4 * size_of::<u32>();
1414

15-
/// This tag contains section header table from an ELF kernel.
16-
///
17-
/// The sections iterator is provided via the `sections` method.
15+
/// This tag contains the section header table from an ELF binary.
16+
// The sections iterator is provided via the [`ElfSectionsTag::sections`]
17+
// method.
1818
#[derive(ptr_meta::Pointee, PartialEq, Eq)]
1919
#[repr(C)]
2020
pub struct ElfSectionsTag {
@@ -41,7 +41,7 @@ impl ElfSectionsTag {
4141
}
4242

4343
/// Get an iterator of loaded ELF sections.
44-
pub(crate) fn sections(&self, offset: usize) -> ElfSectionIter {
44+
pub(crate) fn sections(&self) -> ElfSectionIter {
4545
let string_section_offset = (self.shndx * self.entry_size) as isize;
4646
let string_section_ptr =
4747
unsafe { self.first_section().offset(string_section_offset) as *const _ };
@@ -50,7 +50,6 @@ impl ElfSectionsTag {
5050
remaining_sections: self.number_of_sections,
5151
entry_size: self.entry_size,
5252
string_section: string_section_ptr,
53-
offset,
5453
}
5554
}
5655

@@ -81,7 +80,7 @@ impl Debug for ElfSectionsTag {
8180
.field("number_of_sections", &{ self.number_of_sections })
8281
.field("entry_size", &{ self.entry_size })
8382
.field("shndx", &{ self.shndx })
84-
.field("sections", &self.sections(0))
83+
.field("sections", &self.sections())
8584
.finish()
8685
}
8786
}
@@ -93,7 +92,6 @@ pub struct ElfSectionIter {
9392
remaining_sections: u32,
9493
entry_size: u32,
9594
string_section: *const u8,
96-
offset: usize,
9795
}
9896

9997
impl Iterator for ElfSectionIter {
@@ -105,7 +103,6 @@ impl Iterator for ElfSectionIter {
105103
inner: self.current_section,
106104
string_section: self.string_section,
107105
entry_size: self.entry_size,
108-
offset: self.offset,
109106
};
110107

111108
self.current_section = unsafe { self.current_section.offset(self.entry_size as isize) };
@@ -136,7 +133,6 @@ impl Default for ElfSectionIter {
136133
remaining_sections: 0,
137134
entry_size: 0,
138135
string_section: core::ptr::null(),
139-
offset: 0,
140136
}
141137
}
142138
}
@@ -147,7 +143,6 @@ pub struct ElfSection {
147143
inner: *const u8,
148144
string_section: *const u8,
149145
entry_size: u32,
150-
offset: usize,
151146
}
152147

153148
#[derive(Clone, Copy, Debug)]
@@ -282,7 +277,7 @@ impl ElfSection {
282277
64 => (*(self.string_section as *const ElfSectionInner64)).addr as usize,
283278
s => panic!("Unexpected entry size: {}", s),
284279
};
285-
(addr + self.offset) as *const _
280+
addr as *const _
286281
}
287282
}
288283

0 commit comments

Comments
 (0)