Skip to content

Commit 202b80a

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

File tree

4 files changed

+164
-162
lines changed

4 files changed

+164
-162
lines changed

multiboot2/Changelog.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
# CHANGELOG for crate `multiboot2`
22

33
## 0.16.0 (xxxx-xx-xx)
4-
- Add `TagTrait` trait which enables to use DSTs as multiboot2 tags. This is
5-
mostly relevant for the command line tag, the modules tag, and the bootloader
6-
name tag. However, this might also be relevant for users of custom multiboot2
7-
tags that use DSTs as types. See the example provided in the doc of the
8-
`get_tag` method.
9-
- renamed `MULTIBOOT2_BOOTLOADER_MAGIC` to `MAGIC`
10-
- added a `builder` feature and a `builder` module with a
11-
`builder::InformationBuilder` struct
12-
- `EFIMemoryDesc` was removed and is now an alias of
4+
- **BREAKING** renamed `MULTIBOOT2_BOOTLOADER_MAGIC` to `MAGIC`
5+
- **BREAKING** `EFIMemoryDesc` was removed and is now an alias of
136
`uefi_raw::table::boot::MemoryDescriptor`
14-
- `EFIMemoryAreaType` was removed and is now an alias of
7+
- **BREAKING** `EFIMemoryAreaType` was removed and is now an alias of
158
`uefi_raw::table::boot::MemoryType`
16-
- MSRV is 1.68.0
9+
- **BREAKING** MSRV is 1.68.0
1710
- **BREAKING** Removed `MemoryAreaIter` and `MemoryMapTag::available_memory_areas`
18-
- Added `MemoryMapTag::entry_size` and `MemoryMapTag::entry_version`
1911
- **BREAKING** Renamed `BootInformation::load_base_addr` to `BootInformation::load_base_addr_tag`
2012
- **BREAKING** Renamed `BootInformation::efi_32_ih` to `BootInformation::efi_32_ih_tag`
2113
- **BREAKING** Renamed `BootInformation::efi_32_ih` to `BootInformation::efi_32_ih_tag`
@@ -25,7 +17,17 @@
2517
- **BREAKING** Renamed `EFISdt32` to `EFISdt32Tag`
2618
- **BREAKING** Renamed `EFISdt64` to `EFISdt64Tag`
2719
- **BREAKING** Renamed `EFIBootServicesNotExited` to `EFIBootServicesNotExitedTag`
20+
- **\[Might be\] BREAKING** Added `TagTrait` trait which enables to use DSTs as multiboot2 tags. This is
21+
mostly relevant for the command line tag, the modules tag, and the bootloader
22+
name tag. However, this might also be relevant for users of custom multiboot2
23+
tags that use DSTs as types. See the example provided in the doc of the
24+
`get_tag` method.
25+
- added a `builder` feature and a `builder` module with a
26+
`builder::InformationBuilder` struct
2827
- added `BootInformation::efi_bs_not_exited_tag`
28+
- deprecated `load` and `load_with_offset`
29+
- added `BootInformation::load` as new default constructor
30+
- added `MemoryMapTag::entry_size` and `MemoryMapTag::entry_version`
2931

3032
## 0.15.1 (2023-03-18)
3133
- **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)