-
Notifications
You must be signed in to change notification settings - Fork 1
Update exec
to align with POSIX standard
#93
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,42 +188,59 @@ impl Cage { | |
} | ||
|
||
/* | ||
* exec() will only return if error happens | ||
* In our implementation, WASM is responsible for handling functionalities such as loading and executing the | ||
* new program, preserving process attributes, and resetting memory and the stack. | ||
* | ||
* In RawPOSIX, the focus is on memory management inheritance and resource cleanup and release. | ||
* Specifically, RawPOSIX handles tasks such as clearing memory mappings, resetting shared memory, managing file | ||
* descriptors (closing or inheriting them based on the `should_cloexec` flag in fdtable), resetting semaphores, | ||
* and managing process attributes and threads (terminating unnecessary threads). | ||
* | ||
* This allows us to fully implement the exec functionality while aligning with POSIX standards. | ||
* | ||
* Cage fields remained in exec(): | ||
* cageid, cwd, parent, interval_timer | ||
*/ | ||
pub fn exec_syscall(&self, child_cageid: u64) -> i32 { | ||
pub fn exec_syscall(&self) -> i32 { | ||
// Empty fd with flag should_cloexec | ||
fdtables::empty_fds_for_exec(self.cageid); | ||
// Add the new one to fdtable | ||
let _ = fdtables::copy_fdtable_for_cage(self.cageid, child_cageid); | ||
// Delete the original one | ||
let _newfdtable = fdtables::remove_cage_from_fdtable(self.cageid); | ||
|
||
interface::cagetable_remove(self.cageid); | ||
|
||
// Unmap shared memory mappings of the current process | ||
self.unmap_shm_mappings(); | ||
|
||
// we grab the parent cages main threads sigset and store it at 0 | ||
// this way the child can initialize the sigset properly when it establishes its own mainthreadid | ||
// In the Cage structure, some fields (e.g., cancelstatus, rev_shm, mutex_table) need to be modified | ||
// using mechanisms of interior mutability, requiring explicit locks or atomic operations. For example: | ||
// | ||
// let mut mutex_table = cage.mutex_table.write().unwrap(); | ||
// mutex_table.push(Some(interface::RustRfc::new(interface::RawMutex::new()))); | ||
// | ||
// Since our design involves a large number of field updates (thread_table, sem_table, cancelstatus, rev_shm, mutex_table, etc), | ||
// directly modifying fields would introduce additional overhead compared to simply deleting and recreating the object. | ||
// Therefore, in this context, we choose to update the Cage information in the exec process by deleting and recreating it | ||
// instead. | ||
interface::cagetable_remove(self.cageid); | ||
|
||
// Inherits the signal mask set and resets the signal handler. newsigset stores the inherited | ||
// signal mask set. Signal handlers are reset to their default state. | ||
let newsigset = interface::RustHashMap::new(); | ||
if !interface::RUSTPOSIX_TESTSUITE.load(interface::RustAtomicOrdering::Relaxed) { | ||
// we don't add these for the test suite | ||
// BUG: Signals are commented out until we add them to lind-wasm | ||
// let mainsigsetatomic = self | ||
// .sigset | ||
// .get( | ||
// &self | ||
// .main_threadid | ||
// .load(interface::RustAtomicOrdering::Relaxed), | ||
// ) | ||
// .unwrap(); | ||
// let mainsigset = interface::RustAtomicU64::new( | ||
// mainsigsetatomic.load(interface::RustAtomicOrdering::Relaxed), | ||
// ); | ||
// newsigset.insert(0, mainsigset); | ||
let mainsigsetatomic = self | ||
.sigset | ||
.get( | ||
&self | ||
.main_threadid | ||
.load(interface::RustAtomicOrdering::Relaxed), | ||
) | ||
.unwrap(); | ||
let mainsigset = interface::RustAtomicU64::new( | ||
mainsigsetatomic.load(interface::RustAtomicOrdering::Relaxed), | ||
); | ||
newsigset.insert(0, mainsigset); | ||
} | ||
|
||
// Update status | ||
let newcage = Cage { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can talk a bit more about this on Monday but I believe that we don't need to create a new cage struct here, the old one should be sufficient |
||
cageid: child_cageid, | ||
cageid: self.cageid, | ||
cwd: interface::RustLock::new(self.cwd.read().clone()), | ||
parent: self.parent, | ||
cancelstatus: interface::RustAtomicBool::new(false), | ||
|
@@ -240,11 +257,11 @@ impl Cage { | |
sigset: newsigset, | ||
pendingsigset: interface::RustHashMap::new(), | ||
main_threadid: interface::RustAtomicU64::new(0), | ||
interval_timer: self.interval_timer.clone_with_new_cageid(child_cageid), | ||
interval_timer: self.interval_timer.clone(), | ||
}; | ||
//wasteful clone of fdtable, but mutability constraints exist | ||
|
||
interface::cagetable_insert(child_cageid, newcage); | ||
interface::cagetable_insert(self.cageid, newcage); | ||
|
||
0 | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.