/// Create a process from a module
Create a process from a module
Create a process from a module
fn load(
        &mut self,
        pid: Pid,
        module: &Module,
        writeable_sections: Vec<Frame>,
    ) -> Result<(), KError> {
        self.pid = pid;
        // TODO(error-handling): properly unwind on error
        self.writeable_sections.clear();
        for sec in writeable_sections {
            self.writeable_sections.try_push(sec)?;
        }
        // Load the Module into the process address-space
        // This needs mostly sanitation work on elfloader and
        // ElfLoad trait impl for process to be safe
        unsafe {
            let e = elfloader::ElfBinary::new(module.as_slice())?;
            if !e.is_pie() {
                // We don't have an offset for non-pie applications (rump apps)
                self.offset = VAddr::zero();
            }
            self.entry_point = VAddr::from(e.entry_point());
            e.load(self)?;
        }
        // Install the kernel mappings
        // TODO(efficiency): These should probably be global mappings
        // TODO(broken): Big (>= 2 MiB) allocations should be inserted here too
        // TODO(ugly): Find a better way to express this mess
        super::kcb::try_get_kcb().map(|kcb: &mut Kcb<Arch86Kcb>| {
            for i in 128..=135 {
                let kernel_pml_entry = kcb.arch.init_vspace().pml4[i];
                trace!("Patched in kernel mappings at {:?}", kernel_pml_entry);
                self.vspace.page_table.pml4[i] = kernel_pml_entry;
            }
        });
        Ok(())
    }
fn load ( & mut self , pid : Pid , module : & Module , writeable_sections : Vec < Frame > , ) -> Result < ( ) , KError > { self . pid = pid ; // TODO(error-handling): properly unwind on error self . writeable_sections . clear ( ) ; for sec in writeable_sections { self . writeable_sections . try_push ( sec ) ? ; } // Load the Module into the process address-space // This needs mostly sanitation work on elfloader and // ElfLoad trait impl for process to be safe unsafe { let e = elfloader :: ElfBinary :: new ( module . as_slice ( ) ) ? ; if ! e . is_pie ( ) { // We don't have an offset for non-pie applications (rump apps) self . offset = VAddr :: zero ( ) ; } self . entry_point = VAddr :: from ( e . entry_point ( ) ) ; e . load ( self ) ? ; } // Install the kernel mappings // TODO(efficiency): These should probably be global mappings // TODO(broken): Big (>= 2 MiB) allocations should be inserted here too // TODO(ugly): Find a better way to express this mess super :: kcb :: try_get_kcb ( ) . map ( | kcb : & mut Kcb < Arch86Kcb > | { for i in 128 ..= 135 { let kernel_pml_entry = kcb . arch . init_vspace ( ) . pml4 [ i ] ; trace ! ( " " kernel_pml_entry ) ; self . vspace . page_table . pml4 [ i ] = kernel_pml_entry ; } } ) ; Ok ( ( ) ) }
Create a process from a module
Create a process from a module
&mut self
pid
Pid
module
&Module
writeable_sections
Vec<Frame>