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)