DragonOS/kernel/src/process/syscall/sys_get_rusage.rs
DoL 326cf3e0a3
refactor(process): 重构process下的系统调用 (#1184)
* refactor(process):迁移geteuid系统调用

* refactor(process):迁移getegid系统调用

* refactor(process):迁移getgid系统调用

* refactor(process):迁移getpgid系统调用

* refactor(process):迁移getpid系统调用

* refactor(process):迁移getppid系统调用

* refactor(process):迁移getsid系统调用

* refactor(process):迁移gettid系统调用

* refactor(process):迁移getuid系统调用

* refactor(process):迁移set_tid_address系统调用

* refactor(process):迁移setfsgid系统调用

* refactor(process):迁移setfsuid系统调用

* refactor(process):迁移setgid系统调用

* refactor(process):迁移setpgid系统调用

* refactor(process):迁移setresgid系统调用

* refactor(process):迁移setresuid系统调用

* refactor(process):迁移setsid系统调用

* refactor(process):迁移setuid系统调用

* refactor(process):删除部分已迁移的syscall(id相关)的原有部分

* refactor(process):make fmt

* refactor(process):迁移sys_get_rusage系统调用

* refactor(process):迁移exit exit_group 系统调用

* refactor(process):删除重构syscall下的mod中的全架构条件编译

* refactor(process):迁移sys_wait4系统调用

* refactor(process):迁移sys_getrlimit sys_prlimit64 系统调用

* make fmt

* refactor(process):迁移sys_uname系统调用

* fix(ipc):修复rebase时的错误冲突

* refactor(process):修改已迁移的系统调用的handle参数from_user-->frame

* refactor(process):迁移execve系统调用

* refactor(process):迁移clone系统调用

* refactor(process):迁移fork、vfork系统调用

* refactor(process):删除原有syscall文件,将迁移后的文件夹重命名为syscall

* refactor(process):修复条件编译错误
2025-06-04 21:29:51 +08:00

53 lines
1.6 KiB
Rust

use crate::arch::interrupt::TrapFrame;
use crate::arch::syscall::nr::SYS_GETRUSAGE;
use crate::process::resource::RUsageWho;
use crate::process::{resource::RUsage, ProcessManager};
use crate::syscall::table::FormattedSyscallParam;
use crate::syscall::table::Syscall;
use crate::syscall::user_access::UserBufferWriter;
use alloc::vec::Vec;
use core::ffi::c_int;
use system_error::SystemError;
pub struct SysGetRusage;
impl SysGetRusage {
fn who(args: &[usize]) -> c_int {
args[0] as c_int
}
fn rusage(args: &[usize]) -> *mut RUsage {
args[1] as *mut RUsage
}
}
impl Syscall for SysGetRusage {
fn num_args(&self) -> usize {
2
}
fn handle(&self, args: &[usize], _frame: &mut TrapFrame) -> Result<usize, SystemError> {
let who = Self::who(args);
let rusage = Self::rusage(args);
let who = RUsageWho::try_from(who)?;
let mut writer = UserBufferWriter::new(rusage, core::mem::size_of::<RUsage>(), true)?;
let pcb = ProcessManager::current_pcb();
let rusage = pcb.get_rusage(who).ok_or(SystemError::EINVAL)?;
let ubuf = writer.buffer::<RUsage>(0).unwrap();
ubuf.copy_from_slice(&[rusage]);
return Ok(0);
}
fn entry_format(&self, args: &[usize]) -> Vec<FormattedSyscallParam> {
vec![
FormattedSyscallParam::new("who", format!("{:#x}", Self::who(args))),
FormattedSyscallParam::new("rusage", format!("{:#x}", Self::rusage(args) as usize)),
]
}
}
syscall_table_macros::declare_syscall!(SYS_GETRUSAGE, SysGetRusage);