Moved sc_sem_create to own function

This commit is contained in:
François Autin 2023-04-12 13:50:54 +02:00
parent 355071a2f1
commit 0d70751279
No known key found for this signature in database
GPG Key ID: 343F5D382E1DD77C

View File

@ -205,18 +205,7 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result<MachineOk, Mach
SC_PERROR => todo!(), SC_PERROR => todo!(),
SC_P => sc_p(machine, system), SC_P => sc_p(machine, system),
SC_V => sc_v(machine, system), SC_V => sc_v(machine, system),
SC_SEM_CREATE => { SC_SEM_CREATE => sc_sem_create(machine),
let addr_name = machine.read_int_register(10) as usize;
let initial_count = machine.read_int_register(11);
let size = get_length_param(addr_name as usize, machine);
let _name = get_string_param(addr_name, size, machine);
if initial_count <0{
}
Ok(MachineOk::Ok)
},
SC_SEM_DESTROY => todo!(), SC_SEM_DESTROY => todo!(),
SC_LOCK_CREATE => todo!(), SC_LOCK_CREATE => todo!(),
SC_LOCK_DESTROY => todo!(), SC_LOCK_DESTROY => todo!(),
@ -256,6 +245,17 @@ fn sc_v(machine: &mut Machine, system: &mut System) -> Result<(), Error> {
} }
} }
fn sc_sem_create(machine: &mut Machine) -> Result<(), Error> {
let addr_name = machine.read_int_register(10) as usize;
let initial_count = machine.read_int_register(11);
let size = get_length_param(addr_name as usize, machine);
let _name = get_string_param(addr_name, size, machine);
match initial_count < 0 {
true => Err(format!("Initial_count < 0")),
false => Ok(())
}
}
fn get_length_param(addr: usize, machine: & Machine) -> usize{ fn get_length_param(addr: usize, machine: & Machine) -> usize{
let mut i = 0; let mut i = 0;
let mut c = 1; let mut c = 1;