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 | pub(crate) fn getuid() -> Uid { |
14 | #[cfg (any(target_arch = "arm" , target_arch = "sparc" , target_arch = "x86" ))] |
15 | unsafe { |
16 | let uid = ret_usize_infallible(syscall_readonly!(__NR_getuid32)) as c::uid_t; |
17 | Uid::from_raw(uid) |
18 | } |
19 | #[cfg (not(any(target_arch = "arm" , target_arch = "sparc" , target_arch = "x86" )))] |
20 | unsafe { |
21 | let uid: u32 = ret_usize_infallible(raw:syscall_readonly!(__NR_getuid)) as c::uid_t; |
22 | Uid::from_raw(uid) |
23 | } |
24 | } |
25 | |
26 | #[inline ] |
27 | pub(crate) fn geteuid() -> Uid { |
28 | #[cfg (any(target_arch = "arm" , target_arch = "sparc" , target_arch = "x86" ))] |
29 | unsafe { |
30 | let uid = ret_usize_infallible(syscall_readonly!(__NR_geteuid32)) as c::uid_t; |
31 | Uid::from_raw(uid) |
32 | } |
33 | #[cfg (not(any(target_arch = "arm" , target_arch = "sparc" , target_arch = "x86" )))] |
34 | unsafe { |
35 | let uid: u32 = ret_usize_infallible(raw:syscall_readonly!(__NR_geteuid)) as c::uid_t; |
36 | Uid::from_raw(uid) |
37 | } |
38 | } |
39 | |
40 | #[inline ] |
41 | pub(crate) fn getgid() -> Gid { |
42 | #[cfg (any(target_arch = "arm" , target_arch = "sparc" , target_arch = "x86" ))] |
43 | unsafe { |
44 | let gid = ret_usize_infallible(syscall_readonly!(__NR_getgid32)) as c::gid_t; |
45 | Gid::from_raw(gid) |
46 | } |
47 | #[cfg (not(any(target_arch = "arm" , target_arch = "sparc" , target_arch = "x86" )))] |
48 | unsafe { |
49 | let gid: u32 = ret_usize_infallible(raw:syscall_readonly!(__NR_getgid)) as c::gid_t; |
50 | Gid::from_raw(gid) |
51 | } |
52 | } |
53 | |
54 | #[inline ] |
55 | pub(crate) fn getegid() -> Gid { |
56 | #[cfg (any(target_arch = "arm" , target_arch = "sparc" , target_arch = "x86" ))] |
57 | unsafe { |
58 | let gid = ret_usize_infallible(syscall_readonly!(__NR_getegid32)) as c::gid_t; |
59 | Gid::from_raw(gid) |
60 | } |
61 | #[cfg (not(any(target_arch = "arm" , target_arch = "sparc" , target_arch = "x86" )))] |
62 | unsafe { |
63 | let gid: u32 = ret_usize_infallible(raw:syscall_readonly!(__NR_getegid)) as c::gid_t; |
64 | Gid::from_raw(gid) |
65 | } |
66 | } |
67 | |