master
1/* Wrapper for file descriptors that refers to a process functions.
2 Copyright (C) 2022-2025 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _PIDFD_H
20
21#include <fcntl.h>
22#include <bits/types/siginfo_t.h>
23#include <sys/ioctl.h>
24
25// zig patch: check target glibc version
26#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 36) || __GLIBC__ > 2
27
28#define PIDFD_NONBLOCK O_NONBLOCK
29#define PIDFD_THREAD O_EXCL
30
31#define PIDFD_SIGNAL_THREAD (1UL << 0)
32#define PIDFD_SIGNAL_THREAD_GROUP (1UL << 1)
33#define PIDFD_SIGNAL_PROCESS_GROUP (1UL << 2)
34
35#define PIDFS_IOCTL_MAGIC 0xFF
36
37#define PIDFD_GET_CGROUP_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 1)
38#define PIDFD_GET_IPC_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 2)
39#define PIDFD_GET_MNT_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 3)
40#define PIDFD_GET_NET_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 4)
41#define PIDFD_GET_PID_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 5)
42#define PIDFD_GET_PID_FOR_CHILDREN_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 6)
43#define PIDFD_GET_TIME_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 7)
44#define PIDFD_GET_TIME_FOR_CHILDREN_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 8)
45#define PIDFD_GET_USER_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 9)
46#define PIDFD_GET_UTS_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 10)
47
48/* Returns a file descriptor that refers to the process PID. The
49 close-on-exec is set on the file descriptor. */
50extern int pidfd_open (__pid_t __pid, unsigned int __flags) __THROW;
51
52/* Duplicates an existing file descriptor TARGETFD in the process referred
53 by the PIDFD file descriptor PIDFD.
54
55 The FLAGS argument is reserved for future use, it must be specified
56 as 0. */
57extern int pidfd_getfd (int __pidfd, int __targetfd,
58 unsigned int __flags) __THROW;
59
60/* Sends the signal SIG to the target process referred by the PIDFD. If
61 INFO points to a siginfo_t buffer, it will be populated. */
62extern int pidfd_send_signal (int __pidfd, int __sig, siginfo_t *__info,
63 unsigned int __flags) __THROW;
64
65#endif /* (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 36) || __GLIBC__ > 2 */
66
67// zig patch: check target glibc version
68#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 39) || __GLIBC__ > 2
69
70/* Query the process ID (PID) from process descriptor FD. Return the PID
71 or -1 in case of an error. */
72extern pid_t pidfd_getpid (int __fd) __THROW;
73
74#endif /* (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 36) || __GLIBC__ > 2 */
75
76#endif /* _PIDFD_H */