feat: add SavedContext::with_entry_and_stack, wire SpawnThread to preserve entry point and stack
This commit is contained in:
@@ -7,16 +7,18 @@ impl<P: Platform> Kernel<P> {
|
||||
pub(crate) fn handle_spawn_thread(
|
||||
&mut self,
|
||||
pid: types::id::ProcessId,
|
||||
_entry: types::address::EntryPoint,
|
||||
_stack: types::address::StackPointer,
|
||||
entry: types::address::EntryPoint,
|
||||
stack: types::address::StackPointer,
|
||||
) -> SyscallOutcome {
|
||||
use domain::scheduler::Scheduler;
|
||||
use domain::thread::SavedContext;
|
||||
|
||||
let priority = types::bounded::Priority::new(16)
|
||||
.unwrap_or_else(|| unreachable!());
|
||||
let time_slice = types::time::TimeSlice::new(100);
|
||||
let context = SavedContext::with_entry_and_stack(entry, stack);
|
||||
|
||||
let tid = match self.threads.spawn(pid, priority, time_slice, None) {
|
||||
let tid = match self.threads.spawn_with_context(pid, priority, time_slice, None, context) {
|
||||
Ok(t) => t,
|
||||
Err(e) => return SyscallOutcome::Complete(SyscallResult::Error(e)),
|
||||
};
|
||||
|
||||
@@ -97,4 +97,8 @@ impl Kernel<MockPlatform> {
|
||||
) -> CapSlot {
|
||||
self.grant_cap(pid, resource, permissions).expect("grant cap")
|
||||
}
|
||||
|
||||
pub fn thread_context(&self, tid: ThreadId) -> &domain::thread::SavedContext {
|
||||
self.threads.get(tid).expect("thread").saved_context()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::{SyscallOutcome, SyscallResult};
|
||||
use domain::syscall::Syscall;
|
||||
use types::address::{DataRef, EntryPoint, StackPointer};
|
||||
use types::bounded::CapSlot;
|
||||
use types::id::ThreadId;
|
||||
|
||||
#[test]
|
||||
fn spawn_thread_creates_ready_thread() {
|
||||
@@ -17,6 +18,21 @@ fn spawn_thread_creates_ready_thread() {
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawn_thread_preserves_entry_and_stack() {
|
||||
let (mut k, _) = kernel_with_process();
|
||||
let tid = match k.handle_syscall(Syscall::SpawnThread {
|
||||
entry: EntryPoint::from_raw(0xDEAD),
|
||||
stack: StackPointer::from_raw(0xBEEF),
|
||||
}) {
|
||||
SyscallOutcome::Complete(SyscallResult::Value(v)) => ThreadId::from_raw(v as u16),
|
||||
_ => panic!("expected Value"),
|
||||
};
|
||||
let ctx = k.thread_context(tid);
|
||||
assert_eq!(ctx.program_counter(), 0xDEAD);
|
||||
assert_eq!(ctx.stack_pointer(), 0xBEEF);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_process_with_cap_succeeds() {
|
||||
let (mut k, _) = kernel_with_process();
|
||||
|
||||
Reference in New Issue
Block a user