@@ -26,8 +26,13 @@ impl<T> AppliedGrant<T> {
26
26
F : FnOnce ( & mut Owned < T > , & mut Allocator ) -> R ,
27
27
R : Copy ,
28
28
{
29
+ let proc = unsafe {
30
+ process:: PROCS [ self . appid ]
31
+ . as_mut ( )
32
+ . expect ( "Request to allocate in nonexistent app" )
33
+ } ;
29
34
let mut allocator = Allocator {
30
- app : unsafe { process :: PROCS [ self . appid ] . as_mut ( ) } ,
35
+ app : proc ,
31
36
app_id : self . appid ,
32
37
} ;
33
38
let mut root = unsafe { Owned :: new ( self . grant , self . appid ) } ;
@@ -36,7 +41,7 @@ impl<T> AppliedGrant<T> {
36
41
}
37
42
38
43
pub struct Allocator < ' a > {
39
- app : Option < & ' a mut & ' a mut process:: Process < ' a > > ,
44
+ app : & ' a mut process:: Process < ' a > ,
40
45
app_id : usize ,
41
46
}
42
47
@@ -90,18 +95,13 @@ impl Allocator<'a> {
90
95
pub fn alloc < T > ( & mut self , data : T ) -> Result < Owned < T > , Error > {
91
96
unsafe {
92
97
let app_id = self . app_id ;
93
- match self . app . as_mut ( ) {
94
- Some ( app) => app
95
- . alloc ( size_of :: < T > ( ) )
96
- . map_or ( Err ( Error :: OutOfMemory ) , |arr| {
97
- let mut owned = Owned :: new ( arr. as_mut_ptr ( ) as * mut T , app_id) ;
98
- * owned = data;
99
- Ok ( owned)
100
- } ) ,
101
- None => {
102
- panic ! ( "Request to allocate in kernel grant" ) ;
103
- }
104
- }
98
+ self . app
99
+ . alloc ( size_of :: < T > ( ) )
100
+ . map_or ( Err ( Error :: OutOfMemory ) , |arr| {
101
+ let mut owned = Owned :: new ( arr. as_mut_ptr ( ) as * mut T , app_id) ;
102
+ * owned = data;
103
+ Ok ( owned)
104
+ } )
105
105
}
106
106
}
107
107
}
@@ -181,7 +181,7 @@ impl<T: Default> Grant<T> {
181
181
move |root_ptr| {
182
182
let mut root = Borrowed :: new ( & mut * root_ptr, app_id) ;
183
183
let mut allocator = Allocator {
184
- app : Some ( app) ,
184
+ app : app,
185
185
app_id : app_id,
186
186
} ;
187
187
let res = fun ( & mut root, & mut allocator) ;
0 commit comments