Skip to content

Commit

Permalink
wait: fix negative pid
Browse files Browse the repository at this point in the history
  • Loading branch information
qianxichen233 committed Nov 16, 2024
1 parent 075d9ad commit c89e593
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/safeposix/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ pub fn lind_syscall_api(
}

WAITPID_SYSCALL => {
let pid = arg1 as u64;
let pid = arg1 as i32;
let mut status = unsafe { &mut *((start_address + arg2) as *mut i32) };
let options = arg3 as i32;

Expand Down
8 changes: 4 additions & 4 deletions src/safeposix/syscalls/sys_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl Cage {
status
}

pub fn waitpid_syscall(&self, cageid: u64, status: &mut i32, options: i32) -> i32 {
pub fn waitpid_syscall(&self, cageid: i32, status: &mut i32, options: i32) -> i32 {
let mut zombies = self.zombies.write();
let child_num = self.child_num.load(interface::RustAtomicOrdering::Relaxed);

Expand Down Expand Up @@ -339,7 +339,7 @@ impl Cage {
// if cageid is specified, then we need to look up the zombie list for the id
else {
// first let's check if the cageid is in the zombie list
if let Some(index) = zombies.iter().position(|zombie| zombie.cageid == cageid) {
if let Some(index) = zombies.iter().position(|zombie| zombie.cageid == cageid as u64) {
// find the cage in zombie list, remove it from the list and break
zombie_opt = Some(zombies.remove(index));
} else {
Expand All @@ -348,7 +348,7 @@ impl Cage {
// 2. the cage has exited, but it is not the child of this cage, or
// 3. the cage does not exist
// we need to make sure the child is still running, and it is the child of this cage
let child = interface::cagetable_getref_opt(cageid);
let child = interface::cagetable_getref_opt(cageid as u64);
if let Some(child_cage) = child {
// make sure the child's parent is correct
if child_cage.parent != self.cageid {
Expand All @@ -372,7 +372,7 @@ impl Cage {
zombies = self.zombies.write();

// let's check if the zombie list contains the cage
if let Some(index) = zombies.iter().position(|zombie| zombie.cageid == cageid) {
if let Some(index) = zombies.iter().position(|zombie| zombie.cageid == cageid as u64) {
// find the cage in zombie list, remove it from the list and break
zombie_opt = Some(zombies.remove(index));
break;
Expand Down

0 comments on commit c89e593

Please sign in to comment.