Pārlūkot izejas kodu

Implement getrlimit on Linux and stub on Redox

Jeremy Soller 5 gadi atpakaļ
vecāks
revīzija
ae69586f20

+ 7 - 8
src/header/sys_resource/mod.rs

@@ -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 - 0
src/platform/linux/mod.rs

@@ -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 - 0
src/platform/pal/mod.rs

@@ -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 - 0
src/platform/redox/mod.rs

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