From 6e6d3424f59f1905b07dea863696a37ccfcd3aee Mon Sep 17 00:00:00 2001 From: Samy Solhi Date: Wed, 12 Apr 2023 23:10:26 +0200 Subject: [PATCH] added lock create and destroy system calls --- src/kernel/exception.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/kernel/exception.rs b/src/kernel/exception.rs index 89f7cdb..d03668b 100644 --- a/src/kernel/exception.rs +++ b/src/kernel/exception.rs @@ -175,8 +175,8 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result sc_v(machine, system), SC_SEM_CREATE => sc_sem_create(machine, system), SC_SEM_DESTROY => sc_sem_remove(machine, system), - SC_LOCK_CREATE => todo!(), - SC_LOCK_DESTROY => todo!(), + SC_LOCK_CREATE => sc_lock_create(machine, system), + SC_LOCK_DESTROY => sc_lock_destroy(machine, system), SC_LOCK_ACQUIRE => todo!(), SC_LOCK_RELEASE => todo!(), SC_COND_CREATE => todo!(), @@ -197,6 +197,22 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result Result { + let addr_name = machine.read_int_register(10) as usize; + let size = get_length_param(addr_name, &machine); + let _name = get_string_param(addr_name, size, machine); + let lock = Lock::new(); + let id = system.get_thread_manager().get_obj_addrs().add_lock(lock); + machine.write_int_register(10, id as i64); + Ok(MachineOk::Ok) +} + +fn sc_lock_destroy(machine: &mut Machine, system: &mut System) -> Result { + let id = machine.read_int_register(10) as i32; + system.get_thread_manager().get_obj_addrs().remove_lock(id); + Ok(MachineOk::Ok) +} + fn sc_p(machine: &mut Machine, system: &mut System) -> Result { let id_sema = machine.int_reg.get_reg(10); system.get_thread_manager().sem_p(id_sema as i32, machine)