Implement getrlimit on Linux and stub on Redox

This commit is contained in:
Jeremy Soller
2019-09-18 20:29:25 -06:00
parent 46a330ec9e
commit ae69586f20
4 changed files with 25 additions and 8 deletions
+7 -8
View File
@@ -2,7 +2,6 @@
//! http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysresource.h.html
use crate::header::sys_time::timeval;
use crate::platform;
use crate::platform::types::*;
use crate::platform::{Pal, Sys};
@@ -33,7 +32,7 @@ pub const RLIMIT_NICE: u64 = 13;
pub const RLIMIT_RTPRIO: u64 = 14;
pub const RLIMIT_NLIMITS: u64 = 15;
type rlim_t = u64;
pub type rlim_t = u64;
#[repr(C)]
pub struct rlimit {
@@ -65,12 +64,12 @@ pub struct rusage {
// pub unsafe extern "C" fn getpriority(which: c_int, who: id_t) -> c_int {
// unimplemented!();
// }
//
// #[no_mangle]
// pub unsafe extern "C" fn getrlimit(resource: c_int, rlp: *mut rlimit) -> c_int {
// Sys::getrlimit(resource, rlp)
// }
//
#[no_mangle]
pub unsafe extern "C" fn getrlimit(resource: c_int, rlp: *mut rlimit) -> c_int {
Sys::getrlimit(resource, rlp)
}
// #[no_mangle]
// pub unsafe extern "C" fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int {
// // Sys::getrusage(who, r_usage)
+5
View File
@@ -8,6 +8,7 @@ use crate::{
};
// use header::sys_resource::rusage;
use crate::header::{
sys_resource::rlimit,
sys_stat::stat,
sys_statvfs::statvfs,
sys_time::{timeval, timezone},
@@ -253,6 +254,10 @@ impl Pal for Sys {
e(unsafe { syscall!(GETPPID) }) as pid_t
}
unsafe fn getrlimit(resource: c_int, rlim: *mut rlimit) -> c_int {
e(syscall!(GETRLIMIT, resource, rlim)) as c_int
}
fn gettid() -> pid_t {
e(unsafe { syscall!(GETTID) }) as pid_t
}
+3
View File
@@ -3,6 +3,7 @@ use crate::{
c_str::CStr,
header::{
dirent::dirent,
sys_resource::rlimit,
sys_stat::stat,
sys_statvfs::statvfs,
sys_time::{timeval, timezone},
@@ -90,6 +91,8 @@ pub trait Pal {
fn getppid() -> pid_t;
unsafe fn getrlimit(resource: c_int, rlim: *mut rlimit) -> c_int;
fn gettid() -> pid_t;
fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int;
+10
View File
@@ -13,6 +13,7 @@ use crate::{
errno::{EINVAL, EIO, EPERM, ERANGE},
fcntl,
sys_mman::MAP_ANON,
sys_resource::{rlimit, RLIM_INFINITY},
sys_stat::stat,
sys_statvfs::statvfs,
sys_time::{timeval, timezone},
@@ -556,6 +557,15 @@ impl Pal for Sys {
e(syscall::getppid()) as pid_t
}
unsafe fn getrlimit(resource: c_int, rlim: *mut rlimit) -> c_int {
//TODO
if ! rlim.is_null() {
(*rlim).rlim_cur = RLIM_INFINITY;
(*rlim).rlim_max = RLIM_INFINITY;
}
0
}
fn gettid() -> pid_t {
//TODO
Self::getpid()