Skip to content
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

Closed
wants to merge 5 commits into from
Closed

wait/waitpid implementation #94

wants to merge 5 commits into from

Conversation

qianxichen233
Copy link
Contributor

@qianxichen233 qianxichen233 commented Nov 16, 2024

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

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Test A - tests/sys_tests.rs/ut_lind_waitpid

Checklist:

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been added to a pull request and/or merged in other modules (native-client, lind-glibc, lind-project)

Copy link
Member

@JustinCappos JustinCappos left a 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.

src/safeposix/cage.rs Show resolved Hide resolved
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 {
Copy link
Contributor

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.

Copy link
Member

@Yaxuan-w Yaxuan-w left a 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

@@ -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) };
Copy link
Member

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?


WAITPID_SYSCALL => {
let pid = arg1 as i32;
let mut status = unsafe { &mut *((start_address + arg2) as *mut i32) };
Copy link
Member

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 {
Copy link
Member

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

@qianxichen233
Copy link
Contributor Author

Comments are resolved. Could you guys review again?

Copy link
Member

@JustinCappos JustinCappos left a 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.

@rennergade
Copy link
Contributor

Are there accompanying PRs for libc and wasmtime with this?

@qianxichen233
Copy link
Contributor Author

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?

@rennergade
Copy link
Contributor

rennergade commented Nov 16, 2024

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.

@rennergade
Copy link
Contributor

@qianxichen233 we now have a monorepo at in lind-wasm, can you port this PR over to there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants