address review

This commit is contained in:
Ashwin Naren
2025-12-22 01:49:14 -08:00
parent 8bf0a72bce
commit 2cb93c0891
3 changed files with 19 additions and 20 deletions

View File

@@ -169,7 +169,7 @@ pub async fn handle_syscall() {
}
0x50 => sys_fstat(arg1.into(), TUA::from_value(arg2 as _)).await,
0x51 => sys_sync().await,
0x5d => sys_exit(arg1 as _),
0x5d => sys_exit(arg1 as _).await,
0x5e => sys_exit_group(arg1 as _),
0x60 => sys_set_tid_address(VA::from_value(arg1 as _)).await,
0x62 => {
@@ -255,8 +255,8 @@ pub async fn handle_syscall() {
sys_clone(
arg1 as _,
UA::from_value(arg2 as _),
UA::from_value(arg3 as _),
UA::from_value(arg5 as _),
TUA::from_value(arg3 as _),
TUA::from_value(arg5 as _),
arg4 as _,
)
.await

View File

@@ -1,3 +1,4 @@
use super::{ctx::Context, thread_group::signal::SigSet};
use crate::memory::uaccess::copy_to_user;
use crate::{
process::{TASK_LIST, Task, TaskState},
@@ -5,14 +6,13 @@ use crate::{
sync::SpinLock,
};
use bitflags::bitflags;
use libkernel::memory::address::TUA;
use libkernel::{
error::{KernelError, Result},
memory::address::UA,
};
use ringbuf::Arc;
use super::{ctx::Context, thread_group::signal::SigSet};
bitflags! {
#[derive(Debug)]
pub struct CloneFlags: u32 {
@@ -45,8 +45,8 @@ bitflags! {
pub async fn sys_clone(
flags: u32,
newsp: UA,
parent_tidptr: UA,
child_tidptr: UA,
parent_tidptr: TUA<u32>,
child_tidptr: TUA<u32>,
tls: usize,
) -> Result<usize> {
let flags = CloneFlags::from_bits_truncate(flags);
@@ -148,7 +148,7 @@ pub async fn sys_clone(
last_run: SpinLock::new(None),
robust_list: SpinLock::new(None),
child_tid_ptr: SpinLock::new(if !child_tidptr.is_null() {
Some(child_tidptr.cast::<u32>())
Some(child_tidptr)
} else {
None
}),
@@ -165,10 +165,10 @@ pub async fn sys_clone(
// Honour CLONE_*SETTID semantics for the parent and (shared-VM) child.
if flags.contains(CloneFlags::CLONE_PARENT_SETTID) && !parent_tidptr.is_null() {
copy_to_user(parent_tidptr.cast::<u32>(), tid.value() as u32).await?;
copy_to_user(parent_tidptr, tid.value()).await?;
}
if flags.contains(CloneFlags::CLONE_CHILD_SETTID) && !child_tidptr.is_null() {
copy_to_user(child_tidptr.cast::<u32>(), tid.value() as u32).await?;
copy_to_user(child_tidptr, tid.value()).await?;
}
Ok(tid.value() as _)

View File

@@ -1,14 +1,14 @@
use super::{
TaskState,
thread_group::{ProcessState, Tgid, ThreadGroup, signal::SigId, wait::ChildState},
};
use crate::memory::uaccess::copy_to_user;
use crate::process::threading::futex_wake_addr;
use crate::sched::current_task;
use alloc::vec::Vec;
use libkernel::error::Result;
use ringbuf::Arc;
use super::{
TaskState,
thread_group::{ProcessState, Tgid, ThreadGroup, signal::SigId, wait::ChildState},
};
pub fn do_exit_group(exit_code: ChildState) {
let task = current_task();
let process = Arc::clone(&task.process);
@@ -100,14 +100,13 @@ pub fn sys_exit_group(exit_code: usize) -> Result<usize> {
Ok(0)
}
pub fn sys_exit(exit_code: usize) -> Result<usize> {
pub async fn sys_exit(exit_code: usize) -> Result<usize> {
let task = current_task();
// Honour CLONE_CHILD_CLEARTID: clear the user TID word and futex-wake any waiters.
if let Some(ptr) = task.child_tid_ptr.lock_save_irq().take() {
unsafe {
(ptr.value() as *mut u32).write_volatile(0);
}
let ptr = task.child_tid_ptr.lock_save_irq().take();
if let Some(ptr) = ptr {
copy_to_user(ptr, 0u32).await?;
// Wake any thread waiting on this futex.
futex_wake_addr(ptr, 1);