mirror of
https://github.com/sgmarz/osblog.git
synced 2024-11-24 02:16:19 +04:00
Resolved
This commit is contained in:
parent
6cd64c84bf
commit
21f16b4754
@ -9,8 +9,6 @@ use crate::{block::block_op,
|
||||
page::{virt_to_phys, Table},
|
||||
process::{delete_process, get_by_pid, set_sleeping, set_waiting}};
|
||||
|
||||
use crate::process::{PROCESS_LIST_MUTEX, PROCESS_LIST, Process};
|
||||
|
||||
/// do_syscall is called from trap.rs to invoke a system call. No discernment is
|
||||
/// made here whether this is a U-mode, S-mode, or M-mode system call.
|
||||
/// Since we can't do anything unless we dereference the passed pointer,
|
||||
@ -43,6 +41,7 @@ pub unsafe fn do_syscall(mepc: usize, frame: *mut TrapFrame) -> usize {
|
||||
set_sleeping((*frame).pid as u16, (*frame).regs[10]);
|
||||
0
|
||||
},
|
||||
<<<<<<< HEAD
|
||||
11 => {
|
||||
// Add process to the scheduler. This is obviously insecure and
|
||||
// we wouldn't do this realistically.
|
||||
@ -62,6 +61,8 @@ pub unsafe fn do_syscall(mepc: usize, frame: *mut TrapFrame) -> usize {
|
||||
}
|
||||
mepc + 4
|
||||
},
|
||||
=======
|
||||
>>>>>>> parent of fe5a909... Create a system call to add a process to prevent data race with the process list.
|
||||
63 => {
|
||||
// Read system call
|
||||
// This is an asynchronous call. This will get the
|
||||
@ -207,6 +208,7 @@ pub fn syscall_sleep(duration: usize)
|
||||
}
|
||||
|
||||
pub fn syscall_add_process(process: Process) -> bool {
|
||||
// Thid doesn't quite work since we move process which causes it to drop :(
|
||||
1 == do_make_syscall(11, &process as *const Process as usize, 0, 0, 0, 0, 0)
|
||||
}
|
||||
// These system call numbers come from libgloss so that we can use newlib
|
||||
|
@ -13,9 +13,11 @@ use crate::{cpu::{build_satp,
|
||||
ProcessData,
|
||||
ProcessState,
|
||||
NEXT_PID,
|
||||
PROCESS_LIST,
|
||||
PROCESS_LIST_MUTEX,
|
||||
STACK_ADDR,
|
||||
STACK_PAGES},
|
||||
syscall::{syscall_add_process, syscall_fs_read}};
|
||||
syscall::syscall_fs_read};
|
||||
|
||||
/// Test block will load raw binaries into memory to execute them. This function
|
||||
/// will load ELF files and try to execute them.
|
||||
@ -185,14 +187,32 @@ pub fn test_elf() {
|
||||
// now. Since we don't reuse PIDs, this means that we can only spawn
|
||||
// 65534 processes.
|
||||
satp_fence_asid(my_pid as usize);
|
||||
|
||||
// We will get a data race if we don't use the add process system call. This
|
||||
// test process is being ran as a kernel process, which then competes with
|
||||
// the scheduler due to the context switch timer. When we use a system call,
|
||||
// it goes into an interrupt context so that the scheduler can safely
|
||||
// receive our new process without preemption.
|
||||
if !syscall_add_process(my_proc) {
|
||||
println!("Could not add process to the process list.");
|
||||
// I took a different tact here than in process.rs. In there I created
|
||||
// the process while holding onto the process list. It might
|
||||
// matter since this is asynchronous--it is being ran as a kernel process.
|
||||
unsafe {
|
||||
PROCESS_LIST_MUTEX.spin_lock();
|
||||
}
|
||||
if let Some(mut pl) = unsafe { PROCESS_LIST.take() } {
|
||||
// As soon as we push this process on the list, it'll be
|
||||
// schedule-able.
|
||||
println!(
|
||||
"Added user process to the scheduler...get ready \
|
||||
for take-off!"
|
||||
);
|
||||
pl.push_back(my_proc);
|
||||
unsafe {
|
||||
PROCESS_LIST.replace(pl);
|
||||
}
|
||||
}
|
||||
else {
|
||||
println!("Unable to spawn process.");
|
||||
// Since my_proc couldn't enter the process list, it
|
||||
// will be dropped and all of the associated allocations
|
||||
// will be deallocated through the process' Drop trait.
|
||||
}
|
||||
unsafe {
|
||||
PROCESS_LIST_MUTEX.unlock();
|
||||
}
|
||||
println!();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user