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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
use crate::{backend, io};
pub use crate::pid::{Pid, RawPid};
pub use crate::ugid::{Gid, RawGid, RawUid, Uid};
/// `gettid()`—Returns the thread ID.
///
/// This returns the OS thread ID, which is not necessarily the same as the
/// `rust::thread::Thread::id` or the pthread ID.
///
/// # References
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/gettid.2.html
#[inline]
#[must_use]
pub fn gettid() -> Pid {
backend::thread::syscalls::gettid()
}
/// `setuid(uid)`
///
/// # Warning
///
/// This is not the setxid you are looking for… POSIX requires xids to be
/// process granular, but on Linux they are per-thread. Thus, this call only
/// changes the xid for the current *thread*, not the entire process even
/// though that is in violation of the POSIX standard.
///
/// For details on this distinction, see the C library vs. kernel differences
/// in the [manual page][linux_notes]. This call implements the kernel
/// behavior.
///
/// # References
/// - [POSIX]
/// - [Linux]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setuid.html
/// [Linux]: https://man7.org/linux/man-pages/man2/setuid.2.html
/// [linux_notes]: https://man7.org/linux/man-pages/man2/setuid.2.html#NOTES
#[inline]
pub fn set_thread_uid(uid: Uid) -> io::Result<()> {
backend::thread::syscalls::setuid_thread(uid)
}
/// `setresuid(ruid, euid, suid)`
///
/// # Warning
///
/// This is not the setresxid you are looking for… POSIX requires xids to be
/// process granular, but on Linux they are per-thread. Thus, this call only
/// changes the xid for the current *thread*, not the entire process even
/// though that is in violation of the POSIX standard.
///
/// For details on this distinction, see the C library vs. kernel differences
/// in the [manual page][linux_notes] and the notes in [`set_thread_uid`]. This
/// call implements the kernel behavior.
///
/// # References
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/setresuid.2.html
/// [linux_notes]: https://man7.org/linux/man-pages/man2/setresuid.2.html#NOTES
#[inline]
pub fn set_thread_res_uid(ruid: Uid, euid: Uid, suid: Uid) -> io::Result<()> {
backend::thread::syscalls::setresuid_thread(ruid, euid, suid)
}
/// `setgid(gid)`
///
/// # Warning
///
/// This is not the setxid you are looking for… POSIX requires xids to be
/// process granular, but on Linux they are per-thread. Thus, this call only
/// changes the xid for the current *thread*, not the entire process even
/// though that is in violation of the POSIX standard.
///
/// For details on this distinction, see the C library vs. kernel differences
/// in the [manual page][linux_notes]. This call implements the kernel
/// behavior.
///
/// # References
/// - [POSIX]
/// - [Linux]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setgid.html
/// [Linux]: https://man7.org/linux/man-pages/man2/setgid.2.html
/// [linux_notes]: https://man7.org/linux/man-pages/man2/setgid.2.html#NOTES
#[inline]
pub fn set_thread_gid(gid: Gid) -> io::Result<()> {
backend::thread::syscalls::setgid_thread(gid)
}
/// `setresgid(rgid, egid, sgid)`
///
/// # Warning
///
/// This is not the setresxid you are looking for… POSIX requires xids to be
/// process granular, but on Linux they are per-thread. Thus, this call only
/// changes the xid for the current *thread*, not the entire process even
/// though that is in violation of the POSIX standard.
///
/// For details on this distinction, see the C library vs. kernel differences
/// in the [manual page][linux_notes] and the notes in [`set_thread_gid`]. This
/// call implements the kernel behavior.
///
/// # References
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/setresgid.2.html
/// [linux_notes]: https://man7.org/linux/man-pages/man2/setresgid.2.html#NOTES
#[inline]
pub fn set_thread_res_gid(rgid: Gid, egid: Gid, sgid: Gid) -> io::Result<()> {
backend::thread::syscalls::setresgid_thread(rgid, egid, sgid)
}