1 | //! linux_raw syscalls for UIDs and GIDs |
2 | //! |
3 | //! # Safety |
4 | //! |
5 | //! See the `rustix::backend` module documentation for details. |
6 | #![allow (unsafe_code, clippy::undocumented_unsafe_blocks)] |
7 | |
8 | use crate::backend::c; |
9 | use crate::backend::conv::ret_usize_infallible; |
10 | use crate::ugid::{Gid, Uid}; |
11 | |
12 | #[inline ] |
13 | #[must_use ] |
14 | pub(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: u32 = ret_usize_infallible(raw:syscall_readonly!(__NR_getuid)) as c::uid_t; |
23 | Uid::from_raw(uid) |
24 | } |
25 | } |
26 | |
27 | #[inline ] |
28 | #[must_use ] |
29 | pub(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: u32 = ret_usize_infallible(raw:syscall_readonly!(__NR_geteuid)) as c::uid_t; |
38 | Uid::from_raw(uid) |
39 | } |
40 | } |
41 | |
42 | #[inline ] |
43 | #[must_use ] |
44 | pub(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: u32 = ret_usize_infallible(raw:syscall_readonly!(__NR_getgid)) as c::gid_t; |
53 | Gid::from_raw(gid) |
54 | } |
55 | } |
56 | |
57 | #[inline ] |
58 | #[must_use ] |
59 | pub(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: u32 = ret_usize_infallible(raw:syscall_readonly!(__NR_getegid)) as c::gid_t; |
68 | Gid::from_raw(gid) |
69 | } |
70 | } |
71 | |