diff --git a/kernel/src/arch/hosted/mem.rs b/kernel/src/arch/hosted/mem.rs index c2d5a26fc..f13ac3ace 100644 --- a/kernel/src/arch/hosted/mem.rs +++ b/kernel/src/arch/hosted/mem.rs @@ -40,6 +40,11 @@ impl MemoryMapping { Ok(()) } + /// Does nothing in hosted mode. + pub unsafe fn allocate(&mut self, _pid: PID) -> Result<(), xous_kernel::Error> { + Ok(()) + } + pub fn reserve_address( &mut self, _mm: &mut MemoryManager, diff --git a/kernel/src/arch/hosted/process.rs b/kernel/src/arch/hosted/process.rs index 8c2052475..57c7dbdd4 100644 --- a/kernel/src/arch/hosted/process.rs +++ b/kernel/src/arch/hosted/process.rs @@ -337,7 +337,11 @@ impl Process { /// Initialize this process with the given memory space. THIS DOES NOT /// INITIALIZE A MAIN THREAD. You must call `setup_thread()` in order to /// select a main thread. - pub fn create(pid: PID, init_data: ProcessInit) -> ProcessStartup { + pub fn create( + pid: PID, + init_data: ProcessInit, + _services: &mut crate::SystemServices, + ) -> Result { PROCESS_TABLE.with(|process_table| { let mut process_table = process_table.borrow_mut(); let pid_idx = (pid.get() - 1) as usize; @@ -359,7 +363,7 @@ impl Process { } else { panic!("pid already allocated!"); } - ProcessStartup::new(pid) + Ok(ProcessStartup::new(pid)) }) } diff --git a/kernel/src/services.rs b/kernel/src/services.rs index 62b006fae..2d099d462 100644 --- a/kernel/src/services.rs +++ b/kernel/src/services.rs @@ -421,12 +421,15 @@ impl SystemServices { let new_pid = new_pid.unwrap(); let startup = arch::process::Process::create(new_pid, init_process, self).unwrap(); - let mut entry = &mut self.processes[entry_idx.unwrap()]; - // The `Process::create()` call above set up the process so that it will - // be ready to run right away, meaning we will not need to first set - // the state to `ProcessState::Allocated` and we can go straight to running - // this process. - entry.state = ProcessState::Ready(1 << INITIAL_TID); + #[cfg(baremetal)] + { + let mut entry = &mut self.processes[entry_idx.unwrap()]; + // The `Process::create()` call above set up the process so that it will + // be ready to run right away, meaning we will not need to first set + // the state to `ProcessState::Allocated` and we can go straight to running + // this process. + entry.state = ProcessState::Ready(1 << INITIAL_TID); + } // entry.ppid = _ppid; klog!("created new process for PID {} with PPID {}", new_pid, ppid); return Ok(startup); @@ -1210,6 +1213,9 @@ impl SystemServices { if dest_virt as usize & 0xfff != 0 { return Err(xous_kernel::Error::BadAddress); } + if (dest_virt as usize) + len > crate::arch::mem::USER_AREA_END { + return Err(xous_kernel::Error::BadAddress); + } let current_pid = self.current_pid();