diff --git a/etc/syscalls_linux_aarch64.md b/etc/syscalls_linux_aarch64.md index 532e6f16..1fc3a153 100644 --- a/etc/syscalls_linux_aarch64.md +++ b/etc/syscalls_linux_aarch64.md @@ -168,7 +168,7 @@ | 0xa5 (165) | getrusage | (int who, struct rusage *ru) | __arm64_sys_getrusage | false | | 0xa6 (166) | umask | (int mask) | __arm64_sys_umask | true | | 0xa7 (167) | prctl | (int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) | __arm64_sys_prctl | stub | -| 0xa8 (168) | getcpu | (unsigned *cpup, unsigned *nodep, struct getcpu_cache *unused) | __arm64_sys_getcpu | false | +| 0xa8 (168) | getcpu | (unsigned *cpup, unsigned *nodep, struct getcpu_cache *unused) | __arm64_sys_getcpu | true | | 0xa9 (169) | gettimeofday | (struct __kernel_old_timeval *tv, struct timezone *tz) | __arm64_sys_gettimeofday | partial | | 0xaa (170) | settimeofday | (struct __kernel_old_timeval *tv, struct timezone *tz) | __arm64_sys_settimeofday | partial | | 0xab (171) | adjtimex | (struct __kernel_timex *txc_p) | __arm64_sys_adjtimex | false | diff --git a/src/arch/arm64/exceptions/syscall.rs b/src/arch/arm64/exceptions/syscall.rs index b6b1cdaf..ea0ea040 100644 --- a/src/arch/arm64/exceptions/syscall.rs +++ b/src/arch/arm64/exceptions/syscall.rs @@ -47,8 +47,8 @@ use crate::{ }, }, kernel::{ - hostname::sys_sethostname, power::sys_reboot, rand::sys_getrandom, sysinfo::sys_sysinfo, - uname::sys_uname, + getcpu::sys_getcpu, hostname::sys_sethostname, power::sys_reboot, rand::sys_getrandom, + sysinfo::sys_sysinfo, uname::sys_uname, }, memory::{ brk::sys_brk, @@ -561,6 +561,7 @@ pub async fn handle_syscall(mut ctx: ProcessCtx) { 0xa3 => Err(KernelError::InvalidValue), 0xa6 => sys_umask(&ctx, arg1 as _).map_err(|e| match e {}), 0xa7 => sys_prctl(&ctx, arg1 as _, arg2, arg3).await, + 0xa8 => sys_getcpu(TUA::from_value(arg1 as _), TUA::from_value(arg2 as _)).await, 0xa9 => sys_gettimeofday(TUA::from_value(arg1 as _), TUA::from_value(arg2 as _)).await, 0xaa => sys_settimeofday(TUA::from_value(arg1 as _), TUA::from_value(arg2 as _)).await, 0xac => sys_getpid(&ctx).map_err(|e| match e {}), diff --git a/src/kernel/getcpu.rs b/src/kernel/getcpu.rs new file mode 100644 index 00000000..df8a9bd0 --- /dev/null +++ b/src/kernel/getcpu.rs @@ -0,0 +1,10 @@ +use crate::kernel::cpu_id::CpuId; +use crate::memory::uaccess::copy_to_user; +use libkernel::memory::address::TUA; + +pub async fn sys_getcpu(cpu_ptr: TUA, _node_ptr: TUA) -> libkernel::error::Result { + let cpu_id = CpuId::this().value() as u32; + copy_to_user(cpu_ptr, cpu_id).await?; + // TODO: implement NUMA and write the node ID to node_ptr + Ok(0) +} diff --git a/src/kernel/mod.rs b/src/kernel/mod.rs index 8e3471ca..698cf22b 100644 --- a/src/kernel/mod.rs +++ b/src/kernel/mod.rs @@ -1,4 +1,5 @@ pub mod cpu_id; +pub mod getcpu; pub mod hostname; pub mod kpipe; pub mod power;