@@ -2,7 +2,7 @@ use core::ptr;
2
2
use core:: mem;
3
3
4
4
use void:: { NotYetDef , CVoid } ;
5
- use base:: { Event , Handle , Handles , MemoryType , Status } ;
5
+ use base:: { AllocateType , Event , Handle , Handles , MemoryType , Status } ;
6
6
use event:: { EventType , EventNotify , TimerDelay } ;
7
7
use task:: TPL ;
8
8
use protocol:: { DevicePathProtocol , Protocol , get_current_image} ;
@@ -33,8 +33,8 @@ pub struct BootServices {
33
33
header : table:: TableHeader ,
34
34
raise_tpl : * const NotYetDef ,
35
35
restore_tpl : * const NotYetDef ,
36
- allocate_pages : * const NotYetDef ,
37
- free_pages : * const NotYetDef ,
36
+ allocate_pages : unsafe extern "win64" fn ( allocate_type : AllocateType , pool_type : MemoryType , pages : usize , memory : * mut * mut CVoid ) -> Status ,
37
+ free_pages : unsafe extern "win64" fn ( memory : * mut CVoid , pages : usize ) -> Status ,
38
38
get_memory_map : * const NotYetDef ,
39
39
allocate_pool : unsafe extern "win64" fn ( pool_type : MemoryType , size : usize , out : * mut * mut u8 ) -> Status ,
40
40
free_pool : unsafe extern "win64" fn ( * mut CVoid ) ,
@@ -79,6 +79,23 @@ pub struct BootServices {
79
79
}
80
80
81
81
impl BootServices {
82
+ pub fn allocate_pages ( & self , pages : usize ) -> Result < * mut CVoid , Status > {
83
+ let mut ptr: * mut CVoid = ptr:: null_mut ( ) ;
84
+
85
+ let result = unsafe { ( self . allocate_pages ) ( AllocateType :: AnyPages , get_current_image ( ) . image_data_type , pages, & mut ptr) } ;
86
+ if result != Status :: Success {
87
+ return Err ( result) ;
88
+ }
89
+
90
+ Ok ( ptr)
91
+ }
92
+
93
+ pub fn free_pages < T > ( & self , p : * const T , pages : usize ) {
94
+ unsafe {
95
+ ( self . free_pages ) ( p as * mut CVoid , pages) ;
96
+ }
97
+ }
98
+
82
99
/// Allocate `size` bytes of memory using type `T`.
83
100
pub fn allocate_pool < T > ( & self , size : usize ) -> Result < * mut T , Status > {
84
101
let mut ptr: * mut u8 = 0 as * mut u8 ;
0 commit comments