implement getcpu(2)

This commit is contained in:
Ashwin Naren
2026-03-19 14:22:19 -07:00
parent 9ec0447c40
commit f49a3f9b65
4 changed files with 15 additions and 3 deletions

View File

@@ -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 |

View File

@@ -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 {}),

10
src/kernel/getcpu.rs Normal file
View File

@@ -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<u32>, _node_ptr: TUA<u32>) -> libkernel::error::Result<usize> {
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)
}

View File

@@ -1,4 +1,5 @@
pub mod cpu_id;
pub mod getcpu;
pub mod hostname;
pub mod kpipe;
pub mod power;