]> git.proxmox.com Git - rustc.git/blob - vendor/rustix-0.37.22/src/thread/id.rs
New upstream version 1.73.0+dfsg1
[rustc.git] / vendor / rustix-0.37.22 / src / thread / id.rs
1 use crate::process::{Gid, Pid, Uid};
2 use crate::{backend, io};
3
4 /// `gettid()`—Returns the thread ID.
5 ///
6 /// This returns the OS thread ID, which is not necessarily the same as the
7 /// `rust::thread::Thread::id` or the pthread ID.
8 ///
9 /// # References
10 /// - [Linux]
11 ///
12 /// [Linux]: https://man7.org/linux/man-pages/man2/gettid.2.html
13 #[inline]
14 #[must_use]
15 pub fn gettid() -> Pid {
16 backend::thread::syscalls::gettid()
17 }
18
19 /// `setuid(uid)`
20 ///
21 /// # Warning
22 ///
23 /// This is not the setxid you are looking for... POSIX requires xids to be
24 /// process granular, but on Linux they are per-thread. Thus, this call only
25 /// changes the xid for the current *thread*, not the entire process even
26 /// though that is in violation of the POSIX standard.
27 ///
28 /// For details on this distinction, see the C library vs. kernel differences
29 /// in the [manual page][linux_notes]. This call implements the kernel
30 /// behavior.
31 ///
32 /// # References
33 /// - [POSIX]
34 /// - [Linux]
35 ///
36 /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setuid.html
37 /// [Linux]: https://man7.org/linux/man-pages/man2/setuid.2.html
38 /// [linux_notes]: https://man7.org/linux/man-pages/man2/setuid.2.html#NOTES
39 #[inline]
40 pub fn set_thread_uid(uid: Uid) -> io::Result<()> {
41 backend::thread::syscalls::setuid_thread(uid)
42 }
43
44 /// `setresuid(ruid, euid, suid)`
45 ///
46 /// # Warning
47 ///
48 /// This is not the setresxid you are looking for... POSIX requires xids to be
49 /// process granular, but on Linux they are per-thread. Thus, this call only
50 /// changes the xid for the current *thread*, not the entire process even
51 /// though that is in violation of the POSIX standard.
52 ///
53 /// For details on this distinction, see the C library vs. kernel differences
54 /// in the [manual page][linux_notes] and the notes in [`set_thread_uid`]. This
55 /// call implements the kernel behavior.
56 ///
57 /// # References
58 /// - [Linux]
59 ///
60 /// [Linux]: https://man7.org/linux/man-pages/man2/setresuid.2.html
61 /// [linux_notes]: https://man7.org/linux/man-pages/man2/setresuid.2.html#NOTES
62 #[inline]
63 pub fn set_thread_res_uid(ruid: Uid, euid: Uid, suid: Uid) -> io::Result<()> {
64 backend::thread::syscalls::setresuid_thread(ruid, euid, suid)
65 }
66
67 /// `setgid(gid)`
68 ///
69 /// # Warning
70 ///
71 /// This is not the setxid you are looking for... POSIX requires xids to be
72 /// process granular, but on Linux they are per-thread. Thus, this call only
73 /// changes the xid for the current *thread*, not the entire process even
74 /// though that is in violation of the POSIX standard.
75 ///
76 /// For details on this distinction, see the C library vs. kernel differences
77 /// in the [manual page][linux_notes]. This call implements the kernel
78 /// behavior.
79 ///
80 /// # References
81 /// - [POSIX]
82 /// - [Linux]
83 ///
84 /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setgid.html
85 /// [Linux]: https://man7.org/linux/man-pages/man2/setgid.2.html
86 /// [linux_notes]: https://man7.org/linux/man-pages/man2/setgid.2.html#NOTES
87 #[inline]
88 pub fn set_thread_gid(gid: Gid) -> io::Result<()> {
89 backend::thread::syscalls::setgid_thread(gid)
90 }
91
92 /// `setresgid(rgid, egid, sgid)`
93 ///
94 /// # Warning
95 ///
96 /// This is not the setresxid you are looking for... POSIX requires xids to be
97 /// process granular, but on Linux they are per-thread. Thus, this call only
98 /// changes the xid for the current *thread*, not the entire process even
99 /// though that is in violation of the POSIX standard.
100 ///
101 /// For details on this distinction, see the C library vs. kernel differences
102 /// in the [manual page][linux_notes] and the notes in [`set_thread_gid`]. This
103 /// call implements the kernel behavior.
104 ///
105 /// # References
106 /// - [Linux]
107 ///
108 /// [Linux]: https://man7.org/linux/man-pages/man2/setresgid.2.html
109 /// [linux_notes]: https://man7.org/linux/man-pages/man2/setresgid.2.html#NOTES
110 #[inline]
111 pub fn set_thread_res_gid(rgid: Gid, egid: Gid, sgid: Gid) -> io::Result<()> {
112 backend::thread::syscalls::setresgid_thread(rgid, egid, sgid)
113 }