Add user_stack_size to Machine and use it for threads sp

This commit is contained in:
Quentin Legot
2023-05-09 17:01:52 +02:00
parent 7d29b92eba
commit 7be0c0accc
6 changed files with 34 additions and 16 deletions

View File

@ -3,7 +3,7 @@ use std::{cell::RefCell, rc::Rc};
use crate::{simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}}};
use crate::kernel::synch::{Lock, Semaphore};
use super::{system::{System, self}, thread::Thread};
use super::{system::System, thread::Thread};
/// The halt system call. Stops Burritos.
pub const SC_SHUTDOWN: u8 = 0;
@ -282,7 +282,9 @@ fn sc_new_thread(machine: &mut Machine, system: &mut System) -> Result<MachineOk
};
let current_thread = current_thread.borrow_mut();
if let Some(process) = current_thread.get_process_owner() {
system.get_thread_manager().start_thread(n_thread, Rc::clone(&process), func as u64, current_thread.thread_context.int_registers[2] as u64 + machine.page_size, args);
let sp_max = system.get_thread_manager().get_sp_max() + machine.user_stack_size;
system.get_thread_manager().set_sp_max(sp_max);
system.get_thread_manager().start_thread(n_thread, Rc::clone(&process), func as u64, sp_max, args);
// TODO changé la valeur de sp quand on supportera les addresses virtuels
machine.write_int_register(10, tid as i64);
Ok(MachineOk::Ok)

View File

@ -118,7 +118,8 @@ pub struct ThreadManager {
/// List of objects created by the thread manager (such as Locks and Semaphores)
obj_addrs: ObjAddr,
/// If true, enables debug mode
debug: bool
debug: bool,
sp_max: u64,
}
impl ThreadManager {
@ -130,7 +131,8 @@ impl ThreadManager {
g_alive: List::default(),
ready_list: List::default(),
obj_addrs: ObjAddr::init(),
debug
debug,
sp_max: 0
}
}
@ -423,6 +425,14 @@ impl ThreadManager {
}
}
pub fn get_sp_max(&self) -> u64 {
self.sp_max
}
pub fn set_sp_max(&mut self, sp_max: u64) {
self.sp_max = sp_max;
}
}
#[cfg(test)]