-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wait/waitpid implementation #94
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhere in the comments you should also explain this part of your PR: "When a cage exits, it will decrement the parent's num_child, and put itself into parent's zombie list. Then when parent calls wait syscall, it can simply check the zombie list and retrieve the zombie from it." You're always getting the first child (first in, first out), right? Please mention that in comments too.
if self.parent != self.cageid { | ||
let parent_cage = interface::cagetable_getref_opt(self.parent); | ||
// if parent hasn't exited yet | ||
if let Some(parent) = parent_cage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not some we implemented in lind-nacl either but worth adding a BUG tag here since we dont handle the situation where a parent has exited already. I'm not sure if we want to implement zombies being reclaimed by another process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work! Only minor suggestions. Everything else looks good to me
src/safeposix/dispatcher.rs
Outdated
@@ -1005,6 +1007,22 @@ pub fn lind_syscall_api( | |||
.nanosleep_time64_syscall(clockid, flags, req, rem) | |||
} | |||
|
|||
WAIT_SYSCALL => { | |||
let mut status = unsafe { &mut *((start_address + arg1) as *mut i32) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better to wrap this into a function in src/interface/types.rs
?
src/safeposix/dispatcher.rs
Outdated
|
||
WAITPID_SYSCALL => { | ||
let pid = arg1 as i32; | ||
let mut status = unsafe { &mut *((start_address + arg2) as *mut i32) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same with before
@@ -271,6 +298,104 @@ impl Cage { | |||
status | |||
} | |||
|
|||
pub fn waitpid_syscall(&self, cageid: i32, status: &mut i32, options: i32) -> i32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with what Justin said. Might be good to add a comment to explain high-level implementation logic here
Co-authored-by: Justin Cappos <[email protected]>
Comments are resolved. Could you guys review again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Let's squash and merge when we do merge this in.
Are there accompanying PRs for libc and wasmtime with this? |
There is no change in wasmtime. But there are like 2 lines of change in glibc that basically replaces "MAKE_SYSCALL" at correspond place. Should I raise a PR for the 2 lines in glibc, or I can just put them together into the upcoming bash fix PR? |
Cool. Yash is currently porting the mono repo so it may make sense to wait to do these PRS there. Let's check in with him on Monday and see where that stands. |
@qianxichen233 we now have a monorepo at in lind-wasm, can you port this PR over to there? |
Description
This PR adds wait and waitpid syscall to rawposix. This is achieved by adding two new fields to cage struct: num_child and zombies. When a cage is created via fork, its parent's num_child is incremented. When a cage exits, it will decrement the parent's num_child, and put itself into the end of the parent's zombie list. Then when parent calls wait syscall, it can simply check the zombie list and retrieve the first zombie from it (first in, first out).
Fixes # (issue)
Lind-Project/lind-wasm#23
Type of change
How Has This Been Tested?
tests/sys_tests.rs/ut_lind_waitpid
Checklist: