Skip to content

Commit 0145c10

Browse files
committed
Fix libc-test and add more pidfd definitions
1 parent a155a28 commit 0145c10

File tree

2 files changed

+75
-7
lines changed

2 files changed

+75
-7
lines changed

libc-test/build.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,6 +4049,10 @@ fn test_linux(target: &str) {
40494049
// Might differ between kernel versions
40504050
"open_how" => true,
40514051

4052+
// Linux >= 6.13 (pidfd_info.exit_code: Linux >= 6.15)
4053+
// Might differ between kernel versions
4054+
"pidfd_info" => true,
4055+
40524056
"sctp_initmsg" | "sctp_sndrcvinfo" | "sctp_sndinfo" | "sctp_rcvinfo"
40534057
| "sctp_nxtinfo" | "sctp_prinfo" | "sctp_authinfo" => true,
40544058

@@ -4554,6 +4558,31 @@ fn test_linux(target: &str) {
45544558
// FIXME(linux): Requires >= 6.4 kernel headers.
45554559
"PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG" | "PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG" => true,
45564560

4561+
// Linux >= 6.9
4562+
"PIDFD_THREAD"
4563+
| "PIDFD_SIGNAL_THREAD"
4564+
| "PIDFD_SIGNAL_THREAD_GROUP"
4565+
| "PIDFD_SIGNAL_PROCESS_GROUP" => true,
4566+
// Linux >= 6.11
4567+
"PIDFD_GET_CGROUP_NAMESPACE"
4568+
| "PIDFD_GET_IPC_NAMESPACE"
4569+
| "PIDFD_GET_MNT_NAMESPACE"
4570+
| "PIDFD_GET_NET_NAMESPACE"
4571+
| "PIDFD_GET_PID_NAMESPACE"
4572+
| "PIDFD_GET_PID_FOR_CHILDREN_NAMESPACE"
4573+
| "PIDFD_GET_TIME_NAMESPACE"
4574+
| "PIDFD_GET_TIME_FOR_CHILDREN_NAMESPACE"
4575+
| "PIDFD_GET_USER_NAMESPACE"
4576+
| "PIDFD_GET_UTS_NAMESPACE" => true,
4577+
// Linux >= 6.13
4578+
"PIDFD_GET_INFO"
4579+
| "PIDFD_INFO_PID"
4580+
| "PIDFD_INFO_CREDS"
4581+
| "PIDFD_INFO_CGROUPID"
4582+
| "PIDFD_INFO_SIZE_VER0" => true,
4583+
// Linux >= 6.15
4584+
"PIDFD_INFO_EXIT" | "PIDFD_SELF" | "PIDFD_SELF_PROCESS" => true,
4585+
45574586
_ => false,
45584587
}
45594588
});

src/unix/linux_like/linux/gnu/mod.rs

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::off64_t;
22
use crate::prelude::*;
33

4+
use super::_IO;
5+
use super::_IOWR;
6+
47
pub type pthread_t = c_ulong;
58
pub type __priority_which_t = c_uint;
69
pub type __rlimit_resource_t = c_uint;
@@ -414,6 +417,24 @@ s! {
414417
__pos: off64_t,
415418
__state: crate::mbstate_t,
416419
}
420+
421+
pub struct pidfd_info {
422+
mask: crate::__u64,
423+
cgroupid: crate::__u64,
424+
pid: crate::__u32,
425+
tgid: crate::__u32,
426+
ppid: crate::__u32,
427+
ruid: crate::__u32,
428+
rgid: crate::__u32,
429+
euid: crate::__u32,
430+
egid: crate::__u32,
431+
suid: crate::__u32,
432+
sgid: crate::__u32,
433+
fsuid: crate::__u32,
434+
fsgid: crate::__u32,
435+
exit_code: crate::__s32,
436+
}
437+
417438
}
418439

419440
impl siginfo_t {
@@ -757,13 +778,31 @@ pub const RTLD_DI_TLS_DATA: c_int = 10;
757778
pub const SOCK_NONBLOCK: c_int = O_NONBLOCK;
758779

759780
pub const PIDFD_NONBLOCK: c_uint = O_NONBLOCK as c_uint;
760-
// libc-test failure. To new?
761-
// pub const PIDFD_THREAD: c_uint = O_EXCL as c_uint;
762-
763-
// libc-test failure. To new?
764-
// pub const PIDFD_SIGNAL_THREAD: c_uint = 1;
765-
// pub const PIDFD_SIGNAL_THREAD_GROUP: c_uint = 2;
766-
// pub const PIDFD_SIGNAL_PROCESS_GROUP: c_uint = 4;
781+
pub const PIDFD_THREAD: c_uint = O_EXCL as c_uint;
782+
783+
pub const PIDFD_SIGNAL_THREAD: c_uint = 1;
784+
pub const PIDFD_SIGNAL_THREAD_GROUP: c_uint = 2;
785+
pub const PIDFD_SIGNAL_PROCESS_GROUP: c_uint = 4;
786+
787+
pub const PIDFD_INFO_PID: c_uint = 1;
788+
pub const PIDFD_INFO_CREDS: c_uint = 2;
789+
pub const PIDFD_INFO_CGROUPID: c_uint = 4;
790+
pub const PIDFD_INFO_EXIT: c_uint = 8;
791+
792+
pub const PIDFD_INFO_SIZE_VER0: c_uint = 64;
793+
794+
const PIDFS_IOCTL_MAGIC: c_uint = 0xFF;
795+
pub const PIDFD_GET_CGROUP_NAMESPACE: c_uint = _IO(PIDFS_IOCTL_MAGIC, 1);
796+
pub const PIDFD_GET_IPC_NAMESPACE: c_uint = _IO(PIDFS_IOCTL_MAGIC, 2);
797+
pub const PIDFD_GET_MNT_NAMESPACE: c_uint = _IO(PIDFS_IOCTL_MAGIC, 3);
798+
pub const PIDFD_GET_NET_NAMESPACE: c_uint = _IO(PIDFS_IOCTL_MAGIC, 4);
799+
pub const PIDFD_GET_PID_NAMESPACE: c_uint = _IO(PIDFS_IOCTL_MAGIC, 5);
800+
pub const PIDFD_GET_PID_FOR_CHILDREN_NAMESPACE: c_uint = _IO(PIDFS_IOCTL_MAGIC, 6);
801+
pub const PIDFD_GET_TIME_NAMESPACE: c_uint = _IO(PIDFS_IOCTL_MAGIC, 7);
802+
pub const PIDFD_GET_TIME_FOR_CHILDREN_NAMESPACE: c_uint = _IO(PIDFS_IOCTL_MAGIC, 8);
803+
pub const PIDFD_GET_USER_NAMESPACE: c_uint = _IO(PIDFS_IOCTL_MAGIC, 9);
804+
pub const PIDFD_GET_UTS_NAMESPACE: c_uint = _IO(PIDFS_IOCTL_MAGIC, 10);
805+
pub const PIDFD_GET_INFO: c_uint = _IOWR::<pidfd_info>(PIDFS_IOCTL_MAGIC, 11);
767806

768807
pub const SOL_RXRPC: c_int = 272;
769808
pub const SOL_PPPOL2TP: c_int = 273;

0 commit comments

Comments
 (0)