File tree Expand file tree Collapse file tree 3 files changed +47
-48
lines changed Expand file tree Collapse file tree 3 files changed +47
-48
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,51 @@ pub unsafe fn free_pool(ptr: NonNull<u8>) -> Result {
178
178
unsafe { ( bt. free_pool ) ( ptr. as_ptr ( ) ) } . to_result ( )
179
179
}
180
180
181
+ /// Queries the `get_memory_map` function of UEFI to retrieve the current
182
+ /// size of the map. Returns a [`MemoryMapMeta`].
183
+ ///
184
+ /// It is recommended to add a few more bytes for a subsequent allocation
185
+ /// for the memory map, as the memory map itself also needs heap memory,
186
+ /// and other allocations might occur before that call.
187
+ #[ must_use]
188
+ pub ( crate ) fn memory_map_size ( ) -> MemoryMapMeta {
189
+ let bt = boot_services_raw_panicking ( ) ;
190
+ let bt = unsafe { bt. as_ref ( ) } ;
191
+
192
+ let mut map_size = 0 ;
193
+ let mut map_key = MemoryMapKey ( 0 ) ;
194
+ let mut desc_size = 0 ;
195
+ let mut desc_version = 0 ;
196
+
197
+ let status = unsafe {
198
+ ( bt. get_memory_map ) (
199
+ & mut map_size,
200
+ ptr:: null_mut ( ) ,
201
+ & mut map_key. 0 ,
202
+ & mut desc_size,
203
+ & mut desc_version,
204
+ )
205
+ } ;
206
+ assert_eq ! ( status, Status :: BUFFER_TOO_SMALL ) ;
207
+
208
+ assert_eq ! (
209
+ map_size % desc_size,
210
+ 0 ,
211
+ "Memory map must be a multiple of the reported descriptor size."
212
+ ) ;
213
+
214
+ let mmm = MemoryMapMeta {
215
+ desc_size,
216
+ map_size,
217
+ map_key,
218
+ desc_version,
219
+ } ;
220
+
221
+ mmm. assert_sanity_checks ( ) ;
222
+
223
+ mmm
224
+ }
225
+
181
226
/// Stores the current UEFI memory map in an UEFI-heap allocated buffer
182
227
/// and returns a [`MemoryMapOwned`].
183
228
///
Original file line number Diff line number Diff line change 3
3
4
4
use super :: * ;
5
5
use crate :: boot;
6
- use crate :: table:: system_table_boot;
7
6
use core:: fmt:: { Debug , Display , Formatter } ;
8
7
use core:: ops:: { Index , IndexMut } ;
9
8
use core:: ptr:: NonNull ;
@@ -275,12 +274,9 @@ impl MemoryMapBackingMemory {
275
274
/// - `memory_type`: The memory type for the memory map allocation.
276
275
/// Typically, [`MemoryType::LOADER_DATA`] for regular UEFI applications.
277
276
pub ( crate ) fn new ( memory_type : MemoryType ) -> crate :: Result < Self > {
278
- let st = system_table_boot ( ) . expect ( "Should have boot services activated" ) ;
279
- let bs = st. boot_services ( ) ;
280
-
281
- let memory_map_meta = bs. memory_map_size ( ) ;
277
+ let memory_map_meta = boot:: memory_map_size ( ) ;
282
278
let len = Self :: safe_allocation_size_hint ( memory_map_meta) ;
283
- let ptr = bs . allocate_pool ( memory_type, len) ?. as_ptr ( ) ;
279
+ let ptr = boot :: allocate_pool ( memory_type, len) ?. as_ptr ( ) ;
284
280
285
281
// Should be fine as UEFI always has allocations with a guaranteed
286
282
// alignment of 8 bytes.
Original file line number Diff line number Diff line change @@ -168,48 +168,6 @@ impl BootServices {
168
168
unsafe { ( self . 0 . free_pages ) ( addr, count) } . to_result ( )
169
169
}
170
170
171
- /// Queries the `get_memory_map` function of UEFI to retrieve the current
172
- /// size of the map. Returns a [`MemoryMapMeta`].
173
- ///
174
- /// It is recommended to add a few more bytes for a subsequent allocation
175
- /// for the memory map, as the memory map itself also needs heap memory,
176
- /// and other allocations might occur before that call.
177
- #[ must_use]
178
- pub ( crate ) fn memory_map_size ( & self ) -> MemoryMapMeta {
179
- let mut map_size = 0 ;
180
- let mut map_key = MemoryMapKey ( 0 ) ;
181
- let mut desc_size = 0 ;
182
- let mut desc_version = 0 ;
183
-
184
- let status = unsafe {
185
- ( self . 0 . get_memory_map ) (
186
- & mut map_size,
187
- ptr:: null_mut ( ) ,
188
- & mut map_key. 0 ,
189
- & mut desc_size,
190
- & mut desc_version,
191
- )
192
- } ;
193
- assert_eq ! ( status, Status :: BUFFER_TOO_SMALL ) ;
194
-
195
- assert_eq ! (
196
- map_size % desc_size,
197
- 0 ,
198
- "Memory map must be a multiple of the reported descriptor size."
199
- ) ;
200
-
201
- let mmm = MemoryMapMeta {
202
- desc_size,
203
- map_size,
204
- map_key,
205
- desc_version,
206
- } ;
207
-
208
- mmm. assert_sanity_checks ( ) ;
209
-
210
- mmm
211
- }
212
-
213
171
/// Stores the current UEFI memory map in an UEFI-heap allocated buffer
214
172
/// and returns a [`MemoryMapOwned`].
215
173
///
You can’t perform that action at this time.
0 commit comments