|
|
@@ -1,38 +1,37 @@
|
|
|
+use alloc::borrow::ToOwned;
|
|
|
+use alloc::ffi::CString;
|
|
|
+use core::time::Duration;
|
|
|
+
|
|
|
+use bitflags::bitflags;
|
|
|
+use eonix_hal::traits::trap::RawTrapContext;
|
|
|
+use eonix_hal::trap::TrapContext;
|
|
|
+use eonix_mm::address::Addr as _;
|
|
|
+use eonix_sync::AsProof as _;
|
|
|
+use posix_types::ctypes::PtrT;
|
|
|
+use posix_types::signal::{SigAction, SigInfo, SigSet, Signal};
|
|
|
+use posix_types::stat::{TimeSpec, TimeVal};
|
|
|
+use posix_types::syscall_no::*;
|
|
|
+use posix_types::SIGNAL_NOW;
|
|
|
+
|
|
|
use super::SyscallNoReturn;
|
|
|
use crate::io::Buffer;
|
|
|
use crate::kernel::constants::{
|
|
|
- CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_REALTIME_COARSE, EINVAL, ENOENT, ENOTDIR, ERANGE, ESRCH,
|
|
|
-};
|
|
|
-use crate::kernel::constants::{
|
|
|
- ENOSYS, PR_GET_NAME, PR_SET_NAME, RLIMIT_STACK, SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK,
|
|
|
+ CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_REALTIME_COARSE, EINVAL, ENOENT, ENOSYS, ENOTDIR,
|
|
|
+ ERANGE, ESRCH, PR_GET_NAME, PR_SET_NAME, RLIMIT_STACK, SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK,
|
|
|
};
|
|
|
use crate::kernel::mem::PageBuffer;
|
|
|
use crate::kernel::syscall::{User, UserMut};
|
|
|
use crate::kernel::task::{
|
|
|
- do_clone, futex_wait, futex_wake, yield_now, FutexFlags, FutexOp, ProcessList, ProgramLoader,
|
|
|
- RobustListHead, SignalAction, Thread, WaitId, WaitType,
|
|
|
+ do_clone, futex_wait, futex_wake, parse_futexop, yield_now, CloneArgs, FutexFlags, FutexOp,
|
|
|
+ ProcessList, ProgramLoader, RobustListHead, SignalAction, Thread, WaitId, WaitType,
|
|
|
};
|
|
|
-use crate::kernel::task::{parse_futexop, CloneArgs};
|
|
|
use crate::kernel::timer::sleep;
|
|
|
-use crate::kernel::user::UserString;
|
|
|
-use crate::kernel::user::{UserPointer, UserPointerMut};
|
|
|
+use crate::kernel::user::{UserBuffer, UserPointer, UserPointerMut, UserString};
|
|
|
+use crate::kernel::vfs::dentry::Dentry;
|
|
|
use crate::kernel::vfs::types::Permission;
|
|
|
-use crate::kernel::vfs::{self, dentry::Dentry};
|
|
|
+use crate::kernel::vfs::{self};
|
|
|
use crate::path::Path;
|
|
|
-use crate::{kernel::user::UserBuffer, prelude::*};
|
|
|
-use alloc::borrow::ToOwned;
|
|
|
-use alloc::ffi::CString;
|
|
|
-use bitflags::bitflags;
|
|
|
-use core::time::Duration;
|
|
|
-use eonix_hal::processor::UserTLS;
|
|
|
-use eonix_hal::traits::trap::RawTrapContext;
|
|
|
-use eonix_hal::trap::TrapContext;
|
|
|
-use eonix_mm::address::Addr as _;
|
|
|
-use eonix_sync::AsProof as _;
|
|
|
-use posix_types::ctypes::PtrT;
|
|
|
-use posix_types::signal::{SigAction, SigInfo, SigSet, Signal};
|
|
|
-use posix_types::stat::TimeVal;
|
|
|
-use posix_types::{syscall_no::*, SIGNAL_NOW};
|
|
|
+use crate::prelude::*;
|
|
|
|
|
|
#[repr(C)]
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
@@ -366,7 +365,7 @@ async fn wait4(
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
#[eonix_macros::define_syscall(SYS_WAITPID)]
|
|
|
async fn waitpid(waitpid: i32, arg1: UserMut<u32>, options: u32) -> KResult<u32> {
|
|
|
- sys_wait4(thread, waitpid, arg1, options, core::ptr::null_mut()).await
|
|
|
+ sys_wait4(thread, waitpid, arg1, options, UserMut::null()).await
|
|
|
}
|
|
|
|
|
|
#[eonix_macros::define_syscall(SYS_SETSID)]
|
|
|
@@ -493,51 +492,15 @@ async fn gettid() -> KResult<u32> {
|
|
|
Ok(thread.tid)
|
|
|
}
|
|
|
|
|
|
-pub fn parse_user_tls(arch_tls: usize) -> KResult<UserTLS> {
|
|
|
- #[cfg(target_arch = "x86_64")]
|
|
|
- {
|
|
|
- let desc = arch_tls as *mut posix_types::x86_64::UserDescriptor;
|
|
|
- let desc_pointer = UserPointerMut::new(desc)?;
|
|
|
- let mut desc = desc_pointer.read()?;
|
|
|
-
|
|
|
- // Clear the TLS area if it is not present.
|
|
|
- if desc.flags.is_read_exec_only() && !desc.flags.is_present() {
|
|
|
- if desc.limit != 0 && desc.base != 0 {
|
|
|
- let len = if desc.flags.is_limit_in_pages() {
|
|
|
- (desc.limit as usize) << 12
|
|
|
- } else {
|
|
|
- desc.limit as usize
|
|
|
- };
|
|
|
-
|
|
|
- CheckedUserPointer::new(desc.base as _, len)?.zero()?;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- let (new_tls, entry) =
|
|
|
- UserTLS::new32(desc.base, desc.limit, desc.flags.is_limit_in_pages());
|
|
|
- desc.entry = entry;
|
|
|
- desc_pointer.write(desc)?;
|
|
|
-
|
|
|
- Ok(new_tls)
|
|
|
- }
|
|
|
-
|
|
|
- #[cfg(any(target_arch = "riscv64", target_arch = "loongarch64"))]
|
|
|
- {
|
|
|
- Ok(UserTLS::new(arch_tls as u64))
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
#[eonix_macros::define_syscall(SYS_SET_THREAD_AREA)]
|
|
|
-async fn set_thread_area(arch_tls: usize) -> KResult<()> {
|
|
|
- thread.set_user_tls(parse_user_tls(arch_tls)?)?;
|
|
|
+async fn set_thread_area(tls: PtrT) -> KResult<()> {
|
|
|
+ use crate::kernel::task::UserTLSDescriptor;
|
|
|
|
|
|
- // SAFETY: Preemption is disabled on calling `load_thread_area32()`.
|
|
|
- unsafe {
|
|
|
- eonix_preempt::disable();
|
|
|
- thread.load_thread_area32();
|
|
|
- eonix_preempt::enable();
|
|
|
- }
|
|
|
+ let tls = UserTLSDescriptor::new(tls)?.read()?;
|
|
|
+
|
|
|
+ thread.set_user_tls(tls)?;
|
|
|
+ thread.activate_tls();
|
|
|
|
|
|
Ok(())
|
|
|
}
|
|
|
@@ -651,18 +614,14 @@ async fn rt_sigprocmask(
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
-#[repr(C)]
|
|
|
-#[derive(Clone, Copy)]
|
|
|
-struct TimeSpec32 {
|
|
|
- tv_sec: i32,
|
|
|
- tv_nsec: i32,
|
|
|
-}
|
|
|
-
|
|
|
-#[eonix_macros::define_syscall(SYS_RT_SIGTIMEDWAIT_TIME32)]
|
|
|
-async fn rt_sigtimedwait_time32(
|
|
|
+#[cfg_attr(
|
|
|
+ any(target_arch = "riscv64", target_arch = "loongarch64"),
|
|
|
+ eonix_macros::define_syscall(SYS_RT_SIGTIMEDWAIT)
|
|
|
+)]
|
|
|
+async fn rt_sigtimedwait(
|
|
|
_uthese: User<SigSet>,
|
|
|
_uinfo: UserMut<SigInfo>,
|
|
|
- _uts: User<TimeSpec32>,
|
|
|
+ _uts: User<TimeSpec>,
|
|
|
) -> KResult<i32> {
|
|
|
// TODO
|
|
|
Ok(0)
|
|
|
@@ -820,7 +779,7 @@ async fn clone(
|
|
|
clone_flags: usize,
|
|
|
new_sp: usize,
|
|
|
parent_tidptr: UserMut<u32>,
|
|
|
- tls: usize,
|
|
|
+ tls: PtrT,
|
|
|
child_tidptr: UserMut<u32>,
|
|
|
) -> KResult<u32> {
|
|
|
let clone_args = CloneArgs::for_clone(clone_flags, new_sp, child_tidptr, parent_tidptr, tls)?;
|
|
|
@@ -925,8 +884,23 @@ async fn sigreturn() -> KResult<SyscallNoReturn> {
|
|
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
#[eonix_macros::define_syscall(SYS_ARCH_PRCTL)]
|
|
|
-async fn arch_prctl(option: u32, addr: u32) -> KResult<u32> {
|
|
|
- sys_arch_prctl(thread, option, addr).await
|
|
|
+async fn arch_prctl(option: u32, addr: PtrT) -> KResult<u32> {
|
|
|
+ match option {
|
|
|
+ PR_SET_NAME => {
|
|
|
+ let name = UserPointer::<[u8; 16]>::new(User::with_addr(addr.addr()))?.read()?;
|
|
|
+ let len = name.iter().position(|&c| c == 0).unwrap_or(15);
|
|
|
+ thread.set_name(name[..len].into());
|
|
|
+ Ok(0)
|
|
|
+ }
|
|
|
+ PR_GET_NAME => {
|
|
|
+ let name = thread.get_name();
|
|
|
+ let len = name.len().min(15);
|
|
|
+ let name: [u8; 16] = core::array::from_fn(|i| if i < len { name[i] } else { 0 });
|
|
|
+ UserPointerMut::<[u8; 16]>::new(UserMut::with_addr(addr.addr()))?.write(name)?;
|
|
|
+ Ok(0)
|
|
|
+ }
|
|
|
+ _ => Err(EINVAL),
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
pub fn keep_alive() {}
|