Skip to content

Commit 76ef429

Browse files
committed
Use fewer linux_raw_sys::general:: qualifiers in implementation code.
This is a minor code cleanup to add `use linux_raw_sys::general::` declarations to eliminate some explicit qualifiers in the code.
1 parent 8315321 commit 76ef429

File tree

6 files changed

+57
-60
lines changed

6 files changed

+57
-60
lines changed

src/imp/linux_raw/fs/dir.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use alloc::borrow::ToOwned;
88
use alloc::vec::Vec;
99
use core::fmt;
1010
use core::mem::size_of;
11-
use linux_raw_sys::general::linux_dirent64;
11+
use linux_raw_sys::general::{linux_dirent64, SEEK_SET};
1212

1313
/// `DIR*`
1414
pub struct Dir {
@@ -51,11 +51,7 @@ impl Dir {
5151
/// `readdir(self)`, where `None` means the end of the directory.
5252
pub fn read(&mut self) -> Option<io::Result<DirEntry>> {
5353
if let Some(next) = self.next.take() {
54-
match crate::imp::fs::syscalls::_seek(
55-
self.fd.as_fd(),
56-
next as i64,
57-
linux_raw_sys::general::SEEK_SET,
58-
) {
54+
match crate::imp::fs::syscalls::_seek(self.fd.as_fd(), next as i64, SEEK_SET) {
5955
Ok(_) => (),
6056
Err(err) => return Some(Err(err)),
6157
}

src/imp/linux_raw/fs/syscalls.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ use core::sync::atomic::{AtomicBool, Ordering::Relaxed};
4141
#[cfg(target_arch = "mips64")]
4242
use linux_raw_sys::general::stat as linux_stat64;
4343
use linux_raw_sys::general::{
44-
__kernel_timespec, open_how, statx, AT_FDCWD, AT_REMOVEDIR, AT_SYMLINK_NOFOLLOW, F_ADD_SEALS,
45-
F_DUPFD, F_DUPFD_CLOEXEC, F_GETFD, F_GETFL, F_GETLEASE, F_GETOWN, F_GETPIPE_SZ, F_GETSIG,
46-
F_GET_SEALS, F_SETFD, F_SETFL, F_SETPIPE_SZ,
44+
__kernel_timespec, open_how, statx, AT_EACCESS, AT_FDCWD, AT_REMOVEDIR, AT_SYMLINK_NOFOLLOW,
45+
F_ADD_SEALS, F_DUPFD, F_DUPFD_CLOEXEC, F_GETFD, F_GETFL, F_GETLEASE, F_GETOWN, F_GETPIPE_SZ,
46+
F_GETSIG, F_GET_SEALS, F_SETFD, F_SETFL, F_SETPIPE_SZ, SEEK_CUR, SEEK_END, SEEK_SET,
4747
};
4848
#[cfg(target_pointer_width = "32")]
4949
use {
@@ -219,10 +219,10 @@ pub(crate) fn seek(fd: BorrowedFd<'_>, pos: SeekFrom) -> io::Result<u64> {
219219
SeekFrom::Start(pos) => {
220220
let pos: u64 = pos;
221221
// Silently cast; we'll get `EINVAL` if the value is negative.
222-
(linux_raw_sys::general::SEEK_SET, pos as i64)
222+
(SEEK_SET, pos as i64)
223223
}
224-
SeekFrom::End(offset) => (linux_raw_sys::general::SEEK_END, offset),
225-
SeekFrom::Current(offset) => (linux_raw_sys::general::SEEK_CUR, offset),
224+
SeekFrom::End(offset) => (SEEK_END, offset),
225+
SeekFrom::Current(offset) => (SEEK_CUR, offset),
226226
};
227227
_seek(fd, offset, whence)
228228
}
@@ -257,7 +257,7 @@ pub(crate) fn _seek(fd: BorrowedFd<'_>, offset: i64, whence: c::c_uint) -> io::R
257257

258258
#[inline]
259259
pub(crate) fn tell(fd: BorrowedFd<'_>) -> io::Result<u64> {
260-
_seek(fd, 0, linux_raw_sys::general::SEEK_CUR).map(|x| x as u64)
260+
_seek(fd, 0, SEEK_CUR).map(|x| x as u64)
261261
}
262262

263263
#[inline]
@@ -1314,14 +1314,14 @@ pub(crate) fn accessat(
13141314
// Linux's `faccessat` doesn't have a flags parameter. If we have
13151315
// `AT_EACCESS` and we're not setuid or setgid, we can emulate it.
13161316
if flags.is_empty()
1317-
|| (flags.bits() == linux_raw_sys::general::AT_EACCESS
1317+
|| (flags.bits() == AT_EACCESS
13181318
&& crate::process::getuid() == crate::process::geteuid()
13191319
&& crate::process::getgid() == crate::process::getegid())
13201320
{
13211321
return unsafe { ret(syscall_readonly!(__NR_faccessat, dirfd, path, access)) };
13221322
}
13231323

1324-
if flags.bits() != linux_raw_sys::general::AT_EACCESS {
1324+
if flags.bits() != AT_EACCESS {
13251325
return Err(io::Errno::INVAL);
13261326
}
13271327

src/imp/linux_raw/io/syscalls.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use crate::io::{
2424
use crate::net::{RecvFlags, SendFlags};
2525
use core::cmp;
2626
use core::mem::MaybeUninit;
27-
use linux_raw_sys::general::{epoll_event, EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD};
27+
use linux_raw_sys::general::{
28+
epoll_event, EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD, UIO_MAXIOV,
29+
};
2830
use linux_raw_sys::ioctl::{BLKPBSZGET, BLKSSZGET, FIONBIO, FIONREAD, TIOCEXCL, TIOCNXCL};
2931
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
3032
use {
@@ -281,7 +283,7 @@ pub(crate) fn pwritev2(
281283
/// The maximum number of buffers that can be passed into a vectored I/O system
282284
/// call on the current platform.
283285
const fn max_iov() -> usize {
284-
linux_raw_sys::general::UIO_MAXIOV as usize
286+
UIO_MAXIOV as usize
285287
}
286288

287289
#[inline]

src/imp/linux_raw/mm/syscalls.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::fd::BorrowedFd;
1818
use crate::io::{self, OwnedFd};
1919
#[cfg(target_pointer_width = "32")]
2020
use core::convert::TryInto;
21+
use linux_raw_sys::general::MAP_ANONYMOUS;
2122

2223
#[inline]
2324
pub(crate) fn madvise(addr: *mut c::c_void, len: usize, advice: Advice) -> io::Result<()> {
@@ -96,7 +97,7 @@ pub(crate) unsafe fn mmap_anonymous(
9697
addr,
9798
pass_usize(length),
9899
prot,
99-
c_uint(flags.bits() | linux_raw_sys::general::MAP_ANONYMOUS),
100+
c_uint(flags.bits() | MAP_ANONYMOUS),
100101
no_fd(),
101102
pass_usize(0)
102103
))
@@ -108,7 +109,7 @@ pub(crate) unsafe fn mmap_anonymous(
108109
addr,
109110
pass_usize(length),
110111
prot,
111-
c_uint(flags.bits() | linux_raw_sys::general::MAP_ANONYMOUS),
112+
c_uint(flags.bits() | MAP_ANONYMOUS),
112113
no_fd(),
113114
loff_t_from_u64(0)
114115
))

src/imp/linux_raw/process/syscalls.rs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ use crate::process::{
2222
use core::convert::TryInto;
2323
use core::mem::MaybeUninit;
2424
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+
};
2629

2730
#[inline]
2831
pub(crate) fn chdir(filename: &CStr) -> io::Result<()> {
@@ -45,7 +48,7 @@ pub(crate) fn membarrier_query() -> MembarrierQuery {
4548
unsafe {
4649
match ret_c_uint(syscall!(
4750
__NR_membarrier,
48-
c_int(linux_raw_sys::general::membarrier_cmd::MEMBARRIER_CMD_QUERY as _),
51+
c_int(membarrier_cmd::MEMBARRIER_CMD_QUERY as _),
4952
c_uint(0)
5053
)) {
5154
Ok(query) => {
@@ -73,7 +76,7 @@ pub(crate) fn membarrier_cpu(cmd: MembarrierCommand, cpu: Cpuid) -> io::Result<(
7376
ret(syscall!(
7477
__NR_membarrier,
7578
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 _),
7780
cpu
7881
))
7982
}
@@ -226,7 +229,7 @@ pub(crate) fn getpriority_user(uid: Uid) -> io::Result<i32> {
226229
Ok(20
227230
- ret_c_int(syscall_readonly!(
228231
__NR_getpriority,
229-
c_uint(linux_raw_sys::general::PRIO_USER),
232+
c_uint(PRIO_USER),
230233
c_uint(uid.as_raw())
231234
))?)
232235
}
@@ -238,7 +241,7 @@ pub(crate) fn getpriority_pgrp(pgid: Option<Pid>) -> io::Result<i32> {
238241
Ok(20
239242
- ret_c_int(syscall_readonly!(
240243
__NR_getpriority,
241-
c_uint(linux_raw_sys::general::PRIO_PGRP),
244+
c_uint(PRIO_PGRP),
242245
c_uint(Pid::as_raw(pgid))
243246
))?)
244247
}
@@ -250,7 +253,7 @@ pub(crate) fn getpriority_process(pid: Option<Pid>) -> io::Result<i32> {
250253
Ok(20
251254
- ret_c_int(syscall_readonly!(
252255
__NR_getpriority,
253-
c_uint(linux_raw_sys::general::PRIO_PROCESS),
256+
c_uint(PRIO_PROCESS),
254257
c_uint(Pid::as_raw(pid))
255258
))?)
256259
}
@@ -261,7 +264,7 @@ pub(crate) fn setpriority_user(uid: Uid, priority: i32) -> io::Result<()> {
261264
unsafe {
262265
ret(syscall_readonly!(
263266
__NR_setpriority,
264-
c_uint(linux_raw_sys::general::PRIO_USER),
267+
c_uint(PRIO_USER),
265268
c_uint(uid.as_raw()),
266269
c_int(priority)
267270
))
@@ -273,7 +276,7 @@ pub(crate) fn setpriority_pgrp(pgid: Option<Pid>, priority: i32) -> io::Result<(
273276
unsafe {
274277
ret(syscall_readonly!(
275278
__NR_setpriority,
276-
c_uint(linux_raw_sys::general::PRIO_PGRP),
279+
c_uint(PRIO_PGRP),
277280
c_uint(Pid::as_raw(pgid)),
278281
c_int(priority)
279282
))
@@ -285,7 +288,7 @@ pub(crate) fn setpriority_process(pid: Option<Pid>, priority: i32) -> io::Result
285288
unsafe {
286289
ret(syscall_readonly!(
287290
__NR_setpriority,
288-
c_uint(linux_raw_sys::general::PRIO_PROCESS),
291+
c_uint(PRIO_PROCESS),
289292
c_uint(Pid::as_raw(pid)),
290293
c_int(priority)
291294
))
@@ -294,7 +297,7 @@ pub(crate) fn setpriority_process(pid: Option<Pid>, priority: i32) -> io::Result
294297

295298
#[inline]
296299
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();
298301
unsafe {
299302
match ret(syscall!(
300303
__NR_prlimit64,
@@ -315,7 +318,7 @@ pub(crate) fn getrlimit(limit: Resource) -> Rlimit {
315318
/// The old 32-bit-only `getrlimit` syscall, for when we lack the new
316319
/// `prlimit64`.
317320
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();
319322

320323
// On these platforms, `__NR_getrlimit` is called `__NR_ugetrlimit`.
321324
#[cfg(any(
@@ -370,7 +373,7 @@ unsafe fn setrlimit_old(limit: Resource, new: Rlimit) -> io::Result<()> {
370373
#[inline]
371374
pub(crate) fn prlimit(pid: Option<Pid>, limit: Resource, new: Rlimit) -> io::Result<Rlimit> {
372375
let lim = rlimit_to_linux(new)?;
373-
let mut result = MaybeUninit::<linux_raw_sys::general::rlimit64>::uninit();
376+
let mut result = MaybeUninit::<rlimit64>::uninit();
374377
unsafe {
375378
match ret(syscall!(
376379
__NR_prlimit64,
@@ -387,13 +390,13 @@ pub(crate) fn prlimit(pid: Option<Pid>, limit: Resource, new: Rlimit) -> io::Res
387390

388391
/// Convert a Rust [`Rlimit`] to a C `rlimit64`.
389392
#[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 _ {
392395
None
393396
} else {
394397
Some(lim.rlim_cur)
395398
};
396-
let maximum = if lim.rlim_max == linux_raw_sys::general::RLIM64_INFINITY as _ {
399+
let maximum = if lim.rlim_max == RLIM64_INFINITY as _ {
397400
None
398401
} else {
399402
Some(lim.rlim_max)
@@ -403,27 +406,27 @@ fn rlimit_from_linux(lim: linux_raw_sys::general::rlimit64) -> Rlimit {
403406

404407
/// Convert a C `rlimit64` to a Rust `Rlimit`.
405408
#[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> {
407410
let rlim_cur = match lim.current {
408411
Some(r) => r,
409-
None => linux_raw_sys::general::RLIM64_INFINITY as _,
412+
None => RLIM64_INFINITY as _,
410413
};
411414
let rlim_max = match lim.maximum {
412415
Some(r) => r,
413-
None => linux_raw_sys::general::RLIM64_INFINITY as _,
416+
None => RLIM64_INFINITY as _,
414417
};
415-
Ok(linux_raw_sys::general::rlimit64 { rlim_cur, rlim_max })
418+
Ok(rlimit64 { rlim_cur, rlim_max })
416419
}
417420

418421
/// Like `rlimit_from_linux` but uses Linux's old 32-bit `rlimit`.
419422
#[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 _ {
422425
None
423426
} else {
424427
Some(lim.rlim_cur.into())
425428
};
426-
let maximum = if lim.rlim_max == linux_raw_sys::general::RLIM_INFINITY as _ {
429+
let maximum = if lim.rlim_max == RLIM_INFINITY as _ {
427430
None
428431
} else {
429432
Some(lim.rlim_max.into())
@@ -433,16 +436,16 @@ fn rlimit_from_linux_old(lim: linux_raw_sys::general::rlimit) -> Rlimit {
433436

434437
/// Like `rlimit_to_linux` but uses Linux's old 32-bit `rlimit`.
435438
#[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> {
437440
let rlim_cur = match lim.current {
438441
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 _,
440443
};
441444
let rlim_max = match lim.maximum {
442445
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 _,
444447
};
445-
Ok(linux_raw_sys::general::rlimit { rlim_cur, rlim_max })
448+
Ok(rlimit { rlim_cur, rlim_max })
446449
}
447450

448451
#[inline]

src/imp/linux_raw/process/types.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::super::c;
2+
use linux_raw_sys::general::membarrier_cmd;
23

34
/// A command for use with [`membarrier`] and [`membarrier_cpu`].
45
///
@@ -13,31 +14,25 @@ pub enum MembarrierCommand {
1314
/// `MEMBARRIER_CMD_GLOBAL`
1415
#[doc(alias = "Shared")]
1516
#[doc(alias = "MEMBARRIER_CMD_SHARED")]
16-
Global = linux_raw_sys::general::membarrier_cmd::MEMBARRIER_CMD_GLOBAL as _,
17+
Global = membarrier_cmd::MEMBARRIER_CMD_GLOBAL as _,
1718
/// `MEMBARRIER_CMD_GLOBAL_EXPEDITED`
18-
GlobalExpedited = linux_raw_sys::general::membarrier_cmd::MEMBARRIER_CMD_GLOBAL_EXPEDITED as _,
19+
GlobalExpedited = membarrier_cmd::MEMBARRIER_CMD_GLOBAL_EXPEDITED as _,
1920
/// `MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED`
20-
RegisterGlobalExpedited =
21-
linux_raw_sys::general::membarrier_cmd::MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED as _,
21+
RegisterGlobalExpedited = membarrier_cmd::MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED as _,
2222
/// `MEMBARRIER_CMD_PRIVATE_EXPEDITED`
23-
PrivateExpedited =
24-
linux_raw_sys::general::membarrier_cmd::MEMBARRIER_CMD_PRIVATE_EXPEDITED as _,
23+
PrivateExpedited = membarrier_cmd::MEMBARRIER_CMD_PRIVATE_EXPEDITED as _,
2524
/// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED`
26-
RegisterPrivateExpedited =
27-
linux_raw_sys::general::membarrier_cmd::MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED as _,
25+
RegisterPrivateExpedited = membarrier_cmd::MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED as _,
2826
/// `MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE`
29-
PrivateExpeditedSyncCore =
30-
linux_raw_sys::general::membarrier_cmd::MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE as _,
27+
PrivateExpeditedSyncCore = membarrier_cmd::MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE as _,
3128
/// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE`
3229
RegisterPrivateExpeditedSyncCore =
33-
linux_raw_sys::general::membarrier_cmd::MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE
34-
as _,
30+
membarrier_cmd::MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE as _,
3531
/// `MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ` (since Linux 5.10)
36-
PrivateExpeditedRseq =
37-
linux_raw_sys::general::membarrier_cmd::MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ as _,
32+
PrivateExpeditedRseq = membarrier_cmd::MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ as _,
3833
/// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ` (since Linux 5.10)
3934
RegisterPrivateExpeditedRseq =
40-
linux_raw_sys::general::membarrier_cmd::MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ as _,
35+
membarrier_cmd::MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ as _,
4136
}
4237

4338
/// A resource value for use with [`getrlimit`], [`setrlimit`], and

0 commit comments

Comments
 (0)