Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/rawposix/src/sys_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ pub extern "C" fn fork_syscall(
// syscall implementation
threei::copy_handler_table_to_cage(
UNUSED_ARG,
child_cageid,
UNUSED_ARG,
parent_cageid,
UNUSED_ID,
child_cageid,
UNUSED_ARG,
UNUSED_ID,
UNUSED_ARG,
Expand Down
11 changes: 5 additions & 6 deletions src/threei/src/handler_table/dashmap_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@ pub fn register_handler_impl(
/// Actual implementation of copy_handler_table_to_cage.
/// See comments in threei.rs for details.
pub fn copy_handler_table_to_cage_impl(srccage: u64, targetcage: u64) -> u64 {
// Clone the source call map snapshot so we don't hold a long-lived reference
// while mutating the destination. DashMap::clone clones the structure and keys/values.
let src_snapshot: CallnumMap = if let Some(src_entry) = HANDLERTABLE.get(&srccage) {
let snap = src_entry.value().clone();
drop(src_entry);
Expand All @@ -248,10 +246,12 @@ pub fn copy_handler_table_to_cage_impl(srccage: u64, targetcage: u64) -> u64 {
return threei_const::ELINDAPIABORTED;
};

let dst_call_map_ref = HANDLERTABLE.entry(targetcage).or_insert_with(DashMap::new);
// Overwrite the entire target handler table.
HANDLERTABLE.insert(targetcage, DashMap::new());

let dst_call_map_ref = HANDLERTABLE.get(&targetcage).unwrap();
let dst_call_map: &CallnumMap = &*dst_call_map_ref;

// Copy without overwriting existing destination handlers.
for src_call_entry in src_snapshot.iter() {
let callnum = *src_call_entry.key();
let src_target_map: &TargetCageMap = src_call_entry.value();
Expand All @@ -263,8 +263,7 @@ pub fn copy_handler_table_to_cage_impl(srccage: u64, targetcage: u64) -> u64 {
let handlefunccage = *src_target_entry.key();
let addr = *src_target_entry.value();

// Insert only if absent, preserving any existing destination mapping.
dst_target_map.entry(handlefunccage).or_insert(addr);
dst_target_map.insert(handlefunccage, addr);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/threei/src/handler_table/hashmap_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ pub fn copy_handler_table_to_cage_impl(srccage: u64, targetcage: u64) -> u64 {
let mut handler_table = HANDLERTABLE.lock().unwrap();

// If srccage has a handler table, clones its contents into targetcage.
// Does not overwrite any existing handlers in the target.
// Overwrites any existing handlers in the target.
if let Some(src_entry) = handler_table.get(&srccage).cloned() {
let target_entry = handler_table.entry(targetcage).or_insert_with(HashMap::new);
handler_table.insert(targetcage, HashMap::new()); // overwrite whole target
let target_entry = handler_table.get_mut(&targetcage).unwrap();
for (callnum, callnum_map) in src_entry {
let target_callnum_map = target_entry.entry(callnum).or_insert_with(HashMap::new);
for (handlefunc, handlefunccage) in callnum_map {
Expand Down
8 changes: 4 additions & 4 deletions src/threei/src/threei.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,18 @@ pub fn register_handler(
/// interposable.
///
/// ## Arguments:
/// - targetcage: The ID of the cage receiving the copied handler mappings.
/// - srccage: The ID of the cage whose handler mappings are being copied.
/// - targetcage: The ID of the cage receiving the copied handler mappings.
///
/// ## Returns:
/// - 0 on success.
/// - `ELINDESRCH` if either source or target cage is in the EXITING state.
/// - `ELINDAPIABORTED` if srccage has no existing handler table.
pub fn copy_handler_table_to_cage(
_callnum: u64,
targetcage: u64,
_thiscage: u64,
_targetcage: u64,
srccage: u64,
_arg1cage: u64,
targetcage: u64,
_arg2: u64,
_arg2cage: u64,
_arg3: u64,
Expand Down