1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! linux_raw syscalls for UIDs and GIDs
//!
//! # Safety
//!
//! See the `rustix::backend` module documentation for details.
#![allow(unsafe_code)]
#![allow(clippy::undocumented_unsafe_blocks)]

use crate::backend::c;
use crate::backend::conv::ret_usize_infallible;
use crate::ugid::{Gid, Uid};

#[inline]
pub(crate) fn getuid() -> Uid {
    #[cfg(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86"))]
    unsafe {
        let uid = ret_usize_infallible(syscall_readonly!(__NR_getuid32)) as c::uid_t;
        Uid::from_raw(uid)
    }
    #[cfg(not(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86")))]
    unsafe {
        let uid = ret_usize_infallible(syscall_readonly!(__NR_getuid)) as c::uid_t;
        Uid::from_raw(uid)
    }
}

#[inline]
pub(crate) fn geteuid() -> Uid {
    #[cfg(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86"))]
    unsafe {
        let uid = ret_usize_infallible(syscall_readonly!(__NR_geteuid32)) as c::uid_t;
        Uid::from_raw(uid)
    }
    #[cfg(not(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86")))]
    unsafe {
        let uid = ret_usize_infallible(syscall_readonly!(__NR_geteuid)) as c::uid_t;
        Uid::from_raw(uid)
    }
}

#[inline]
pub(crate) fn getgid() -> Gid {
    #[cfg(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86"))]
    unsafe {
        let gid = ret_usize_infallible(syscall_readonly!(__NR_getgid32)) as c::gid_t;
        Gid::from_raw(gid)
    }
    #[cfg(not(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86")))]
    unsafe {
        let gid = ret_usize_infallible(syscall_readonly!(__NR_getgid)) as c::gid_t;
        Gid::from_raw(gid)
    }
}

#[inline]
pub(crate) fn getegid() -> Gid {
    #[cfg(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86"))]
    unsafe {
        let gid = ret_usize_infallible(syscall_readonly!(__NR_getegid32)) as c::gid_t;
        Gid::from_raw(gid)
    }
    #[cfg(not(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86")))]
    unsafe {
        let gid = ret_usize_infallible(syscall_readonly!(__NR_getegid)) as c::gid_t;
        Gid::from_raw(gid)
    }
}