mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
kernel: on to lifetime issues now!
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
30fef020f2
commit
8925964754
2 changed files with 45 additions and 29 deletions
|
|
@ -2,8 +2,8 @@ use crate::arch;
|
|||
use crate::arch::mem::MemoryMapping;
|
||||
pub use crate::arch::process::Process as ArchProcess;
|
||||
pub use crate::arch::process::Thread;
|
||||
use xous::MemoryRange;
|
||||
use crate::mem::MemoryManager;
|
||||
use xous::MemoryRange;
|
||||
|
||||
use core::cell::RefCell;
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ pub enum ProcessState {
|
|||
|
||||
/// This is a brand-new process that hasn't been run yet, and needs its
|
||||
/// initial context set up.
|
||||
// Setup(ThreadInit),
|
||||
Setup(ThreadInit),
|
||||
|
||||
/// This process is able to be run. The context bitmask describes contexts
|
||||
/// that are ready.
|
||||
|
|
@ -318,11 +318,12 @@ impl SystemServices {
|
|||
if pid == 1 {
|
||||
process.state = ProcessState::Running(0);
|
||||
} else {
|
||||
process.state = ProcessState::Setup(
|
||||
init.entrypoint,
|
||||
init.sp,
|
||||
crate::arch::process::DEFAULT_STACK_SIZE,
|
||||
);
|
||||
process.state = ProcessState::Setup(ThreadInit::new(
|
||||
unsafe { core::mem::transmute::<usize, _>(init.entrypoint) },
|
||||
MemoryRange::new(init.sp, crate::arch::process::DEFAULT_STACK_SIZE).unwrap(),
|
||||
None,
|
||||
[0u8; 16],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -560,27 +561,27 @@ impl SystemServices {
|
|||
process.state = match process.state {
|
||||
ProcessState::Free => return Err(xous::Error::ProcessNotFound),
|
||||
ProcessState::Sleeping => return Err(xous::Error::ProcessNotFound),
|
||||
ProcessState::Allocated => return Err(xous::Error::ProcessNotFound), /*
|
||||
ProcessState::Allocated => return Err(xous::Error::ProcessNotFound),
|
||||
ProcessState::Setup(setup) => {
|
||||
// Activate the process, which enables its memory mapping
|
||||
process.activate()?;
|
||||
// Activate the process, which enables its memory mapping
|
||||
process.activate()?;
|
||||
|
||||
// If a context is specified for a Setup task to switch to,
|
||||
// ensure it's the INITIAL_TID. Otherwise it's not valid.
|
||||
if let Some(ctx) = tid {
|
||||
if ctx != INITIAL_TID {
|
||||
return Err(xous::Error::InvalidThread);
|
||||
// If a context is specified for a Setup task to switch to,
|
||||
// ensure it's the INITIAL_TID. Otherwise it's not valid.
|
||||
if let Some(tid) = tid {
|
||||
if tid != INITIAL_TID {
|
||||
return Err(xous::Error::InvalidThread);
|
||||
}
|
||||
}
|
||||
|
||||
let mut p = crate::arch::process::Process::current();
|
||||
p.setup_thread(INITIAL_TID, setup)?;
|
||||
p.set_thread(INITIAL_TID)?;
|
||||
// process.current_thread = INITIAL_TID as u8;
|
||||
|
||||
// Mark the current proces state as "running, and no waiting contexts"
|
||||
ProcessState::Running(0)
|
||||
}
|
||||
}
|
||||
|
||||
let mut p = crate::arch::process::Process::current();
|
||||
p.setup_thread(INITIAL_TID, setup)?;
|
||||
p.set_thread(INITIAL_TID)?;
|
||||
// process.current_thread = INITIAL_TID as u8;
|
||||
|
||||
// Mark the current proces state as "running, and no waiting contexts"
|
||||
ProcessState::Running(0)
|
||||
}*/
|
||||
ProcessState::Ready(0) => {
|
||||
panic!("ProcessState was `Ready(0)`, which is invalid!");
|
||||
}
|
||||
|
|
@ -1090,7 +1091,6 @@ impl SystemServices {
|
|||
let src_mapping = self.get_process(current_pid)?.mapping;
|
||||
let dest_mapping = self.get_process(dest_pid)?.mapping;
|
||||
MemoryManager::with_mut(|mm| {
|
||||
|
||||
// Locate an address to fit the new memory.
|
||||
dest_mapping.activate();
|
||||
let dest_virt = mm
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{MemoryAddress, PID, TID};
|
||||
use crate::{MemoryAddress, MemoryRange, PID, TID};
|
||||
use core::convert::TryInto;
|
||||
|
||||
mod mem;
|
||||
|
|
@ -12,11 +12,27 @@ pub struct ProcessArgs {
|
|||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct ThreadInit {
|
||||
call: fn(data: *const usize) -> usize,
|
||||
stack: MemoryAddress,
|
||||
stack: MemoryRange,
|
||||
arg: Option<MemoryAddress>,
|
||||
name: [u8; 16],
|
||||
}
|
||||
|
||||
impl ThreadInit {
|
||||
pub fn new(
|
||||
call: fn(data: *const usize) -> usize,
|
||||
stack: MemoryRange,
|
||||
arg: Option<MemoryAddress>,
|
||||
name: [u8; 16],
|
||||
) -> Self {
|
||||
ThreadInit {
|
||||
call,
|
||||
stack,
|
||||
arg,
|
||||
name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub struct ProcessKey([u8; 16]);
|
||||
impl ProcessKey {
|
||||
|
|
@ -37,7 +53,7 @@ pub fn thread_to_args(call: usize, init: &ThreadInit) -> [usize; 8] {
|
|||
[
|
||||
call as usize,
|
||||
init.call as usize,
|
||||
init.stack.get(),
|
||||
init.stack.as_ptr() as _,
|
||||
init.arg.map(|x| x.get()).unwrap_or_default(),
|
||||
0,
|
||||
0,
|
||||
|
|
|
|||
Loading…
Reference in a new issue