@@ -28,8 +28,8 @@ use crate::utils::as_mut_ptr;
2828use core:: mem:: MaybeUninit ;
2929use core:: ptr:: { null, null_mut} ;
3030use linux_raw_sys:: general:: {
31- membarrier_cmd, membarrier_cmd_flag, rlimit , rlimit64, PRIO_PGRP , PRIO_PROCESS , PRIO_USER ,
32- RLIM64_INFINITY , RLIM_INFINITY ,
31+ membarrier_cmd, membarrier_cmd_flag, rlimit64, PRIO_PGRP , PRIO_PROCESS , PRIO_USER ,
32+ RLIM64_INFINITY ,
3333} ;
3434#[ cfg( feature = "fs" ) ]
3535use { crate :: backend:: conv:: ret_c_uint_infallible, crate :: fs:: Mode } ;
@@ -299,52 +299,17 @@ pub(crate) fn setpriority_process(pid: Option<Pid>, priority: i32) -> io::Result
299299pub ( crate ) fn getrlimit ( limit : Resource ) -> Rlimit {
300300 let mut result = MaybeUninit :: < rlimit64 > :: uninit ( ) ;
301301 unsafe {
302- match ret ( syscall ! (
302+ ret_infallible ( syscall ! (
303303 __NR_prlimit64,
304304 c_uint( 0 ) ,
305305 limit,
306306 null:: <c:: c_void>( ) ,
307307 & mut result
308- ) ) {
309- Ok ( ( ) ) => rlimit_from_linux ( result. assume_init ( ) ) ,
310- Err ( err) => {
311- debug_assert_eq ! ( err, io:: Errno :: NOSYS ) ;
312- getrlimit_old ( limit)
313- }
314- }
308+ ) ) ;
309+ rlimit_from_linux ( result. assume_init ( ) )
315310 }
316311}
317312
318- /// The old 32-bit-only `getrlimit` syscall, for when we lack the new
319- /// `prlimit64`.
320- unsafe fn getrlimit_old ( limit : Resource ) -> Rlimit {
321- let mut result = MaybeUninit :: < rlimit > :: uninit ( ) ;
322-
323- // On these platforms, `__NR_getrlimit` is called `__NR_ugetrlimit`.
324- #[ cfg( any(
325- target_arch = "arm" ,
326- target_arch = "powerpc" ,
327- target_arch = "powerpc64" ,
328- target_arch = "x86" ,
329- ) ) ]
330- {
331- ret_infallible ( syscall ! ( __NR_ugetrlimit, limit, & mut result) ) ;
332- }
333-
334- // On these platforms, it's just `__NR_getrlimit`.
335- #[ cfg( not( any(
336- target_arch = "arm" ,
337- target_arch = "powerpc" ,
338- target_arch = "powerpc64" ,
339- target_arch = "x86" ,
340- ) ) ) ]
341- {
342- ret_infallible ( syscall ! ( __NR_getrlimit, limit, & mut result) ) ;
343- }
344-
345- rlimit_from_linux_old ( result. assume_init ( ) )
346- }
347-
348313#[ inline]
349314pub ( crate ) fn setrlimit ( limit : Resource , new : Rlimit ) -> io:: Result < ( ) > {
350315 unsafe {
@@ -357,19 +322,11 @@ pub(crate) fn setrlimit(limit: Resource, new: Rlimit) -> io::Result<()> {
357322 null_mut:: <c:: c_void>( )
358323 ) ) {
359324 Ok ( ( ) ) => Ok ( ( ) ) ,
360- Err ( io:: Errno :: NOSYS ) => setrlimit_old ( limit, new) ,
361325 Err ( err) => Err ( err) ,
362326 }
363327 }
364328}
365329
366- /// The old 32-bit-only `setrlimit` syscall, for when we lack the new
367- /// `prlimit64`.
368- unsafe fn setrlimit_old ( limit : Resource , new : Rlimit ) -> io:: Result < ( ) > {
369- let lim = rlimit_to_linux_old ( new) ?;
370- ret ( syscall_readonly ! ( __NR_setrlimit, limit, by_ref( & lim) ) )
371- }
372-
373330#[ inline]
374331pub ( crate ) fn prlimit ( pid : Option < Pid > , limit : Resource , new : Rlimit ) -> io:: Result < Rlimit > {
375332 let lim = rlimit_to_linux ( new) ;
@@ -391,12 +348,12 @@ pub(crate) fn prlimit(pid: Option<Pid>, limit: Resource, new: Rlimit) -> io::Res
391348/// Convert a Rust [`Rlimit`] to a C `rlimit64`.
392349#[ inline]
393350fn rlimit_from_linux ( lim : rlimit64 ) -> Rlimit {
394- let current = if lim. rlim_cur as u64 == RLIM64_INFINITY as u64 {
351+ let current = if lim. rlim_cur == RLIM64_INFINITY as _ {
395352 None
396353 } else {
397354 Some ( lim. rlim_cur )
398355 } ;
399- let maximum = if lim. rlim_max as u64 == RLIM64_INFINITY as u64 {
356+ let maximum = if lim. rlim_max == RLIM64_INFINITY as _ {
400357 None
401358 } else {
402359 Some ( lim. rlim_max )
@@ -418,36 +375,6 @@ fn rlimit_to_linux(lim: Rlimit) -> rlimit64 {
418375 rlimit64 { rlim_cur, rlim_max }
419376}
420377
421- /// Like `rlimit_from_linux` but uses Linux's old 32-bit `rlimit`.
422- #[ allow( clippy:: useless_conversion) ]
423- fn rlimit_from_linux_old ( lim : rlimit ) -> Rlimit {
424- let current = if lim. rlim_cur as u32 == RLIM_INFINITY as u32 {
425- None
426- } else {
427- Some ( lim. rlim_cur . into ( ) )
428- } ;
429- let maximum = if lim. rlim_max as u32 == RLIM_INFINITY as u32 {
430- None
431- } else {
432- Some ( lim. rlim_max . into ( ) )
433- } ;
434- Rlimit { current, maximum }
435- }
436-
437- /// Like `rlimit_to_linux` but uses Linux's old 32-bit `rlimit`.
438- #[ allow( clippy:: useless_conversion) ]
439- fn rlimit_to_linux_old ( lim : Rlimit ) -> io:: Result < rlimit > {
440- let rlim_cur = match lim. current {
441- Some ( r) => r. try_into ( ) . map_err ( |_e| io:: Errno :: INVAL ) ?,
442- None => RLIM_INFINITY as _ ,
443- } ;
444- let rlim_max = match lim. maximum {
445- Some ( r) => r. try_into ( ) . map_err ( |_e| io:: Errno :: INVAL ) ?,
446- None => RLIM_INFINITY as _ ,
447- } ;
448- Ok ( rlimit { rlim_cur, rlim_max } )
449- }
450-
451378#[ inline]
452379pub ( crate ) fn wait ( waitopts : WaitOptions ) -> io:: Result < Option < ( Pid , WaitStatus ) > > {
453380 _waitpid ( !0 , waitopts)
0 commit comments