@@ -25,11 +25,11 @@ use goblin::{
25
25
use oak_restricted_kernel_interface:: syscalls:: { MmapFlags , MmapProtection } ;
26
26
use self_cell:: self_cell;
27
27
use x86_64:: {
28
- structures:: paging:: { PageSize , Size2MiB } ,
28
+ structures:: paging:: { PageSize , PhysFrame , Size2MiB } ,
29
29
VirtAddr ,
30
30
} ;
31
31
32
- use crate :: syscall:: mmap:: mmap;
32
+ use crate :: { syscall:: mmap:: mmap, PROCCESSES } ;
33
33
34
34
// Set up the userspace stack at the end of the lower half of the virtual
35
35
// address space. Well... almost. It's one page lower than the very end, as
@@ -160,19 +160,21 @@ pub fn identify_pml4_frame(
160
160
}
161
161
162
162
pub struct Process {
163
- pml4 : x86_64 :: structures :: paging :: PageTable ,
163
+ pml4_frame : PhysFrame ,
164
164
entry : VirtAddr ,
165
165
}
166
166
167
167
impl Process {
168
- /// Creates a process from the application, without executing it.
168
+ /// Creates a process from the application, without executing it. Returns
169
+ /// the PID of the new process.
169
170
///
170
171
/// # Safety
171
172
///
172
173
/// The application must be built from a valid ELF file representing an Oak
173
174
/// Restricted Application.
174
- pub unsafe fn from_application ( application : & Application ) -> Result < Self , anyhow:: Error > {
175
+ pub unsafe fn from_application ( application : & Application ) -> Result < usize , anyhow:: Error > {
175
176
let pml4 = crate :: BASE_L4_PAGE_TABLE . get ( ) . context ( "base l4 table should be set" ) ?. clone ( ) ;
177
+ let pml4_frame: PhysFrame = identify_pml4_frame ( & pml4) ?;
176
178
// Load the process's page table, so the application can be loaded into its
177
179
// memory. Hold onto the previous PT, so we can revert to it once the
178
180
// application has been mapped into the process pt.
@@ -198,17 +200,15 @@ impl Process {
198
200
// Safety: the new page table maintains the same mappings for kernel space.
199
201
unsafe { crate :: PAGE_TABLES . lock ( ) . replace ( pml4_frame) } ;
200
202
}
201
-
202
- Ok ( Self { pml4 , entry } )
203
+ let pid = PROCCESSES . add ( Self { pml4_frame , entry } ) ;
204
+ Ok ( pid )
203
205
}
204
206
/// Executes the process.
205
207
pub fn execute ( & self ) -> ! {
206
- let pml4_frame = identify_pml4_frame ( & self . pml4 ) . expect ( "could not get pml4 frame" ) ;
207
208
// Safety: the new page table maintains the same mappings for kernel space.
208
- unsafe { crate :: PAGE_TABLES . lock ( ) . replace ( pml4_frame) } ;
209
+ unsafe { crate :: PAGE_TABLES . lock ( ) . replace ( self . pml4_frame ) } ;
209
210
210
211
let entry = self . entry ;
211
- log:: info!( "Running application" ) ;
212
212
// Enter Ring 3 and jump to user code.
213
213
// Safety: by now, if we're here, we've loaded a valid ELF file. It's up to the
214
214
// user to guarantee that the file made sense.
0 commit comments