rustix/backend/linux_raw/ugid/
syscalls.rs1#![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
7
8use crate::backend::c;
9use crate::backend::conv::ret_usize_infallible;
10use crate::ugid::{Gid, Uid};
11
12#[inline]
13#[must_use]
14pub(crate) fn getuid() -> Uid {
15 #[cfg(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86"))]
16 unsafe {
17 let uid = ret_usize_infallible(syscall_readonly!(__NR_getuid32)) as c::uid_t;
18 Uid::from_raw(uid)
19 }
20 #[cfg(not(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86")))]
21 unsafe {
22 let uid = ret_usize_infallible(syscall_readonly!(__NR_getuid)) as c::uid_t;
23 Uid::from_raw(uid)
24 }
25}
26
27#[inline]
28#[must_use]
29pub(crate) fn geteuid() -> Uid {
30 #[cfg(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86"))]
31 unsafe {
32 let uid = ret_usize_infallible(syscall_readonly!(__NR_geteuid32)) as c::uid_t;
33 Uid::from_raw(uid)
34 }
35 #[cfg(not(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86")))]
36 unsafe {
37 let uid = ret_usize_infallible(syscall_readonly!(__NR_geteuid)) as c::uid_t;
38 Uid::from_raw(uid)
39 }
40}
41
42#[inline]
43#[must_use]
44pub(crate) fn getgid() -> Gid {
45 #[cfg(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86"))]
46 unsafe {
47 let gid = ret_usize_infallible(syscall_readonly!(__NR_getgid32)) as c::gid_t;
48 Gid::from_raw(gid)
49 }
50 #[cfg(not(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86")))]
51 unsafe {
52 let gid = ret_usize_infallible(syscall_readonly!(__NR_getgid)) as c::gid_t;
53 Gid::from_raw(gid)
54 }
55}
56
57#[inline]
58#[must_use]
59pub(crate) fn getegid() -> Gid {
60 #[cfg(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86"))]
61 unsafe {
62 let gid = ret_usize_infallible(syscall_readonly!(__NR_getegid32)) as c::gid_t;
63 Gid::from_raw(gid)
64 }
65 #[cfg(not(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86")))]
66 unsafe {
67 let gid = ret_usize_infallible(syscall_readonly!(__NR_getegid)) as c::gid_t;
68 Gid::from_raw(gid)
69 }
70}