Skip to content

Conversation

@AsakuraMizu
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings December 24, 2025 12:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors user space memory access in the sys_clone implementation by replacing the custom UserPtr wrapper with the starry-vm library's VmMutPtr trait. This change modernizes the codebase to use a more standardized approach for user memory operations.

Key changes:

  • Replaced UserPtr wrapper and access_user_memory with direct raw pointer usage and starry-vm's VmMutPtr trait
  • Changed new_user_task parameter from Option<&'static mut Pid> to usize for better consistency with other syscall parameters
  • Updated sys_clone to use vm_write() method instead of UserPtr::get_as_mut()

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/entry.rs Updated new_user_task call to pass 0 instead of None for the set_child_tid parameter
api/src/task.rs Refactored new_user_task to use VmMutPtr trait methods (nullable() and vm_write()) instead of UserPtr and access_user_memory; removed import of access_user_memory
api/src/syscall/task/clone.rs Replaced UserPtr usage with raw pointer casts and vm_write() calls for parent_tid and child_tid parameters; updated imports to use VmMutPtr instead of UserPtr

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
});
if let Some(tid) = (set_child_tid as *mut Pid).nullable() {
tid.vm_write(curr.id().as_u64() as Pid).ok();
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silently discarding vm_write errors with .ok() may lead to unexpected behavior. If set_child_tid points to an invalid address, the old code (which used direct pointer dereference within access_user_memory) would trigger a page fault that could terminate the task. The new code silently ignores write failures, allowing the task to continue. Consider handling errors by at least logging them, or by raising a signal similar to how line 162 in do_exit checks is_ok() but takes conditional action based on the result.

Suggested change
tid.vm_write(curr.id().as_u64() as Pid).ok();
if let Err(err) = tid.vm_write(curr.id().as_u64() as Pid) {
warn!(
"Failed to write child TID to user memory at {:p}: {:?}",
tid.as_ptr(),
err
);
// Mirror the behavior for serious memory faults by raising SIGSEGV.
raise_signal_fatal(SignalInfo::new_kernel(Signo::SIGSEGV))
.expect("Failed to send SIGSEGV");
}

Copilot uses AI. Check for mistakes.
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.

2 participants