@@ -22,7 +22,10 @@ use crate::process::{
22
22
use core:: convert:: TryInto ;
23
23
use core:: mem:: MaybeUninit ;
24
24
use core:: ptr:: { null, null_mut} ;
25
- use linux_raw_sys:: general:: { __kernel_gid_t, __kernel_pid_t, __kernel_uid_t} ;
25
+ use linux_raw_sys:: general:: {
26
+ __kernel_gid_t, __kernel_pid_t, __kernel_uid_t, membarrier_cmd, membarrier_cmd_flag, rlimit,
27
+ rlimit64, PRIO_PGRP , PRIO_PROCESS , PRIO_USER , RLIM64_INFINITY , RLIM_INFINITY ,
28
+ } ;
26
29
27
30
#[ inline]
28
31
pub ( crate ) fn chdir ( filename : & CStr ) -> io:: Result < ( ) > {
@@ -45,7 +48,7 @@ pub(crate) fn membarrier_query() -> MembarrierQuery {
45
48
unsafe {
46
49
match ret_c_uint ( syscall ! (
47
50
__NR_membarrier,
48
- c_int( linux_raw_sys :: general :: membarrier_cmd:: MEMBARRIER_CMD_QUERY as _) ,
51
+ c_int( membarrier_cmd:: MEMBARRIER_CMD_QUERY as _) ,
49
52
c_uint( 0 )
50
53
) ) {
51
54
Ok ( query) => {
@@ -73,7 +76,7 @@ pub(crate) fn membarrier_cpu(cmd: MembarrierCommand, cpu: Cpuid) -> io::Result<(
73
76
ret ( syscall ! (
74
77
__NR_membarrier,
75
78
cmd,
76
- c_uint( linux_raw_sys :: general :: membarrier_cmd_flag:: MEMBARRIER_CMD_FLAG_CPU as _) ,
79
+ c_uint( membarrier_cmd_flag:: MEMBARRIER_CMD_FLAG_CPU as _) ,
77
80
cpu
78
81
) )
79
82
}
@@ -226,7 +229,7 @@ pub(crate) fn getpriority_user(uid: Uid) -> io::Result<i32> {
226
229
Ok ( 20
227
230
- ret_c_int ( syscall_readonly ! (
228
231
__NR_getpriority,
229
- c_uint( linux_raw_sys :: general :: PRIO_USER ) ,
232
+ c_uint( PRIO_USER ) ,
230
233
c_uint( uid. as_raw( ) )
231
234
) ) ?)
232
235
}
@@ -238,7 +241,7 @@ pub(crate) fn getpriority_pgrp(pgid: Option<Pid>) -> io::Result<i32> {
238
241
Ok ( 20
239
242
- ret_c_int ( syscall_readonly ! (
240
243
__NR_getpriority,
241
- c_uint( linux_raw_sys :: general :: PRIO_PGRP ) ,
244
+ c_uint( PRIO_PGRP ) ,
242
245
c_uint( Pid :: as_raw( pgid) )
243
246
) ) ?)
244
247
}
@@ -250,7 +253,7 @@ pub(crate) fn getpriority_process(pid: Option<Pid>) -> io::Result<i32> {
250
253
Ok ( 20
251
254
- ret_c_int ( syscall_readonly ! (
252
255
__NR_getpriority,
253
- c_uint( linux_raw_sys :: general :: PRIO_PROCESS ) ,
256
+ c_uint( PRIO_PROCESS ) ,
254
257
c_uint( Pid :: as_raw( pid) )
255
258
) ) ?)
256
259
}
@@ -261,7 +264,7 @@ pub(crate) fn setpriority_user(uid: Uid, priority: i32) -> io::Result<()> {
261
264
unsafe {
262
265
ret ( syscall_readonly ! (
263
266
__NR_setpriority,
264
- c_uint( linux_raw_sys :: general :: PRIO_USER ) ,
267
+ c_uint( PRIO_USER ) ,
265
268
c_uint( uid. as_raw( ) ) ,
266
269
c_int( priority)
267
270
) )
@@ -273,7 +276,7 @@ pub(crate) fn setpriority_pgrp(pgid: Option<Pid>, priority: i32) -> io::Result<(
273
276
unsafe {
274
277
ret ( syscall_readonly ! (
275
278
__NR_setpriority,
276
- c_uint( linux_raw_sys :: general :: PRIO_PGRP ) ,
279
+ c_uint( PRIO_PGRP ) ,
277
280
c_uint( Pid :: as_raw( pgid) ) ,
278
281
c_int( priority)
279
282
) )
@@ -285,7 +288,7 @@ pub(crate) fn setpriority_process(pid: Option<Pid>, priority: i32) -> io::Result
285
288
unsafe {
286
289
ret ( syscall_readonly ! (
287
290
__NR_setpriority,
288
- c_uint( linux_raw_sys :: general :: PRIO_PROCESS ) ,
291
+ c_uint( PRIO_PROCESS ) ,
289
292
c_uint( Pid :: as_raw( pid) ) ,
290
293
c_int( priority)
291
294
) )
@@ -294,7 +297,7 @@ pub(crate) fn setpriority_process(pid: Option<Pid>, priority: i32) -> io::Result
294
297
295
298
#[ inline]
296
299
pub ( crate ) fn getrlimit ( limit : Resource ) -> Rlimit {
297
- let mut result = MaybeUninit :: < linux_raw_sys :: general :: rlimit64 > :: uninit ( ) ;
300
+ let mut result = MaybeUninit :: < rlimit64 > :: uninit ( ) ;
298
301
unsafe {
299
302
match ret ( syscall ! (
300
303
__NR_prlimit64,
@@ -315,7 +318,7 @@ pub(crate) fn getrlimit(limit: Resource) -> Rlimit {
315
318
/// The old 32-bit-only `getrlimit` syscall, for when we lack the new
316
319
/// `prlimit64`.
317
320
unsafe fn getrlimit_old ( limit : Resource ) -> Rlimit {
318
- let mut result = MaybeUninit :: < linux_raw_sys :: general :: rlimit > :: uninit ( ) ;
321
+ let mut result = MaybeUninit :: < rlimit > :: uninit ( ) ;
319
322
320
323
// On these platforms, `__NR_getrlimit` is called `__NR_ugetrlimit`.
321
324
#[ cfg( any(
@@ -370,7 +373,7 @@ unsafe fn setrlimit_old(limit: Resource, new: Rlimit) -> io::Result<()> {
370
373
#[ inline]
371
374
pub ( crate ) fn prlimit ( pid : Option < Pid > , limit : Resource , new : Rlimit ) -> io:: Result < Rlimit > {
372
375
let lim = rlimit_to_linux ( new) ?;
373
- let mut result = MaybeUninit :: < linux_raw_sys :: general :: rlimit64 > :: uninit ( ) ;
376
+ let mut result = MaybeUninit :: < rlimit64 > :: uninit ( ) ;
374
377
unsafe {
375
378
match ret ( syscall ! (
376
379
__NR_prlimit64,
@@ -387,13 +390,13 @@ pub(crate) fn prlimit(pid: Option<Pid>, limit: Resource, new: Rlimit) -> io::Res
387
390
388
391
/// Convert a Rust [`Rlimit`] to a C `rlimit64`.
389
392
#[ inline]
390
- fn rlimit_from_linux ( lim : linux_raw_sys :: general :: rlimit64 ) -> Rlimit {
391
- let current = if lim. rlim_cur == linux_raw_sys :: general :: RLIM64_INFINITY as _ {
393
+ fn rlimit_from_linux ( lim : rlimit64 ) -> Rlimit {
394
+ let current = if lim. rlim_cur == RLIM64_INFINITY as _ {
392
395
None
393
396
} else {
394
397
Some ( lim. rlim_cur )
395
398
} ;
396
- let maximum = if lim. rlim_max == linux_raw_sys :: general :: RLIM64_INFINITY as _ {
399
+ let maximum = if lim. rlim_max == RLIM64_INFINITY as _ {
397
400
None
398
401
} else {
399
402
Some ( lim. rlim_max )
@@ -403,27 +406,27 @@ fn rlimit_from_linux(lim: linux_raw_sys::general::rlimit64) -> Rlimit {
403
406
404
407
/// Convert a C `rlimit64` to a Rust `Rlimit`.
405
408
#[ inline]
406
- fn rlimit_to_linux ( lim : Rlimit ) -> io:: Result < linux_raw_sys :: general :: rlimit64 > {
409
+ fn rlimit_to_linux ( lim : Rlimit ) -> io:: Result < rlimit64 > {
407
410
let rlim_cur = match lim. current {
408
411
Some ( r) => r,
409
- None => linux_raw_sys :: general :: RLIM64_INFINITY as _ ,
412
+ None => RLIM64_INFINITY as _ ,
410
413
} ;
411
414
let rlim_max = match lim. maximum {
412
415
Some ( r) => r,
413
- None => linux_raw_sys :: general :: RLIM64_INFINITY as _ ,
416
+ None => RLIM64_INFINITY as _ ,
414
417
} ;
415
- Ok ( linux_raw_sys :: general :: rlimit64 { rlim_cur, rlim_max } )
418
+ Ok ( rlimit64 { rlim_cur, rlim_max } )
416
419
}
417
420
418
421
/// Like `rlimit_from_linux` but uses Linux's old 32-bit `rlimit`.
419
422
#[ allow( clippy:: useless_conversion) ]
420
- fn rlimit_from_linux_old ( lim : linux_raw_sys :: general :: rlimit ) -> Rlimit {
421
- let current = if lim. rlim_cur == linux_raw_sys :: general :: RLIM_INFINITY as _ {
423
+ fn rlimit_from_linux_old ( lim : rlimit ) -> Rlimit {
424
+ let current = if lim. rlim_cur == RLIM_INFINITY as _ {
422
425
None
423
426
} else {
424
427
Some ( lim. rlim_cur . into ( ) )
425
428
} ;
426
- let maximum = if lim. rlim_max == linux_raw_sys :: general :: RLIM_INFINITY as _ {
429
+ let maximum = if lim. rlim_max == RLIM_INFINITY as _ {
427
430
None
428
431
} else {
429
432
Some ( lim. rlim_max . into ( ) )
@@ -433,16 +436,16 @@ fn rlimit_from_linux_old(lim: linux_raw_sys::general::rlimit) -> Rlimit {
433
436
434
437
/// Like `rlimit_to_linux` but uses Linux's old 32-bit `rlimit`.
435
438
#[ allow( clippy:: useless_conversion) ]
436
- fn rlimit_to_linux_old ( lim : Rlimit ) -> io:: Result < linux_raw_sys :: general :: rlimit > {
439
+ fn rlimit_to_linux_old ( lim : Rlimit ) -> io:: Result < rlimit > {
437
440
let rlim_cur = match lim. current {
438
441
Some ( r) => r. try_into ( ) . map_err ( |_e| io:: Errno :: INVAL ) ?,
439
- None => linux_raw_sys :: general :: RLIM_INFINITY as _ ,
442
+ None => RLIM_INFINITY as _ ,
440
443
} ;
441
444
let rlim_max = match lim. maximum {
442
445
Some ( r) => r. try_into ( ) . map_err ( |_e| io:: Errno :: INVAL ) ?,
443
- None => linux_raw_sys :: general :: RLIM_INFINITY as _ ,
446
+ None => RLIM_INFINITY as _ ,
444
447
} ;
445
- Ok ( linux_raw_sys :: general :: rlimit { rlim_cur, rlim_max } )
448
+ Ok ( rlimit { rlim_cur, rlim_max } )
446
449
}
447
450
448
451
#[ inline]
0 commit comments