Add getrusage

This commit is contained in:
Jeremy Soller
2024-09-19 16:08:54 -06:00
parent 8a0b2dcbd0
commit 1b7d059707
4 changed files with 23 additions and 19 deletions
+5 -11
View File
@@ -88,14 +88,8 @@ pub unsafe extern "C" fn getrlimit(resource: c_int, rlp: *mut rlimit) -> c_int {
pub unsafe extern "C" fn setrlimit(resource: c_int, rlp: *const rlimit) -> c_int {
Sys::setrlimit(resource, rlp)
}
// #[no_mangle]
// pub unsafe extern "C" fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int {
// // Sys::getrusage(who, r_usage)
// unimplemented!();
// }
//
// #[no_mangle]
// pub unsafe extern "C" fn setpriority(which: c_int, who: id_t, nice: c_int) -> c_int {
// unimplemented!();
// }
//
#[no_mangle]
pub unsafe extern "C" fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int {
Sys::getrusage(who, &mut *r_usage)
}
+5 -6
View File
@@ -6,9 +6,8 @@ use crate::{
c_str::CStr,
header::{dirent::dirent, errno::EINVAL, signal::SIGCHLD, sys_stat::S_IFIFO},
};
// use header::sys_resource::rusage;
use crate::header::{
sys_resource::rlimit,
sys_resource::{rlimit, rusage},
sys_stat::stat,
sys_statvfs::statvfs,
sys_time::{timeval, timezone},
@@ -76,10 +75,6 @@ pub fn e(sys: usize) -> usize {
pub struct Sys;
impl Sys {
// fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int {
// e(unsafe { syscall!(GETRUSAGE, who, r_usage) }) as c_int
// }
pub unsafe fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> c_int {
// TODO: Somehow support varargs to syscall??
e(syscall!(IOCTL, fd, request, out)) as c_int
@@ -342,6 +337,10 @@ impl Pal for Sys {
e(syscall!(SETRLIMIT, resource, rlimit)) as c_int
}
fn getrusage(who: c_int, r_usage: &mut rusage) -> c_int {
e(unsafe { syscall!(GETRUSAGE, who, r_usage) }) as c_int
}
fn getsid(pid: pid_t) -> pid_t {
e(unsafe { syscall!(GETSID, pid) }) as pid_t
}
+3 -1
View File
@@ -4,7 +4,7 @@ use crate::{
error::Errno,
header::{
dirent::dirent,
sys_resource::rlimit,
sys_resource::{rlimit, rusage},
sys_stat::stat,
sys_statvfs::statvfs,
sys_time::{timeval, timezone},
@@ -128,6 +128,8 @@ pub trait Pal {
unsafe fn setrlimit(resource: c_int, rlim: *const rlimit) -> c_int;
fn getrusage(who: c_int, r_usage: &mut rusage) -> c_int;
fn getsid(pid: pid_t) -> pid_t;
fn gettid() -> pid_t;
+10 -1
View File
@@ -24,7 +24,7 @@ use crate::{
fcntl, limits,
sys_mman::{MAP_ANONYMOUS, MAP_FAILED, PROT_READ, PROT_WRITE},
sys_random,
sys_resource::{rlimit, RLIM_INFINITY},
sys_resource::{rlimit, rusage, RLIM_INFINITY},
sys_stat::{stat, S_ISGID, S_ISUID},
sys_statvfs::statvfs,
sys_time::{timeval, timezone},
@@ -529,6 +529,15 @@ impl Pal for Sys {
-1
}
fn getrusage(who: c_int, r_usage: &mut rusage) -> c_int {
//TODO
eprintln!(
"relibc getrusage({}, {:p}): not implemented",
who, r_usage
);
0
}
fn getsid(pid: pid_t) -> pid_t {
let mut buf = [0; mem::size_of::<usize>()];
let path = if pid == 0 {