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
//! The [`pidfd_getfd`] function and supporting types.
use crateOwnedFd;
use crate::;
use ;
/// Raw file descriptor in another process.
///
/// A distinct type alias is used here to inform the user that normal file
/// descriptors from the calling process should not be used. The provided file
/// descriptor is used by the kernel as the index into the file descriptor
/// table of an entirely different process.
pub type ForeignRawFd = RawFd;
bitflags!
/// `syscall(SYS_pidfd_getfd, pidfd, flags)`—Obtain a duplicate of another
/// process' file descriptor.
///
/// # References
/// - [Linux]
///
/// # Warning
///
/// This function is generally safe for the calling process, but it can impact
/// the target process in unexpected ways. If you want to ensure that Rust I/O
/// safety assumptions continue to hold in the target process, then the target
/// process must have communicated the file description number to the calling
/// process from a value of a type that implements `AsRawFd`, and the target
/// process must not drop that value until after the calling process has
/// returned from `pidfd_getfd`.
///
/// When `pidfd_getfd` is used to debug the target, or the target is not a Rust
/// application, or `pidfd_getfd` is used in any other way, then extra care
/// should be taken to avoid unexpected behaviour or crashes.
///
/// For further details, see the references above.
///
/// [Linux]: https://man7.org/linux/man-pages/man2/pidfd_getfd.2.html