xref: /aosp_15_r20/external/ltp/include/lapi/pidfd.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
4*49cdfc7eSAndroid Build Coastguard Worker  * Author: Yang Xu <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker  */
6*49cdfc7eSAndroid Build Coastguard Worker 
7*49cdfc7eSAndroid Build Coastguard Worker #ifndef LAPI_PIDFD_H__
8*49cdfc7eSAndroid Build Coastguard Worker #define LAPI_PIDFD_H__
9*49cdfc7eSAndroid Build Coastguard Worker 
10*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
11*49cdfc7eSAndroid Build Coastguard Worker #ifdef HAVE_SYS_PIDFD_H
12*49cdfc7eSAndroid Build Coastguard Worker # include <sys/pidfd.h>
13*49cdfc7eSAndroid Build Coastguard Worker #endif
14*49cdfc7eSAndroid Build Coastguard Worker #include "config.h"
15*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/syscalls.h"
16*49cdfc7eSAndroid Build Coastguard Worker 
17*49cdfc7eSAndroid Build Coastguard Worker #ifndef PIDFD_NONBLOCK
18*49cdfc7eSAndroid Build Coastguard Worker #define PIDFD_NONBLOCK O_NONBLOCK
19*49cdfc7eSAndroid Build Coastguard Worker #endif
20*49cdfc7eSAndroid Build Coastguard Worker 
pidfd_send_signal_supported(void)21*49cdfc7eSAndroid Build Coastguard Worker static inline void pidfd_send_signal_supported(void)
22*49cdfc7eSAndroid Build Coastguard Worker {
23*49cdfc7eSAndroid Build Coastguard Worker 	/* allow the tests to fail early */
24*49cdfc7eSAndroid Build Coastguard Worker 	tst_syscall(__NR_pidfd_send_signal);
25*49cdfc7eSAndroid Build Coastguard Worker }
26*49cdfc7eSAndroid Build Coastguard Worker 
27*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_PIDFD_SEND_SIGNAL
pidfd_send_signal(int pidfd,int sig,siginfo_t * info,unsigned int flags)28*49cdfc7eSAndroid Build Coastguard Worker static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
29*49cdfc7eSAndroid Build Coastguard Worker 				    unsigned int flags)
30*49cdfc7eSAndroid Build Coastguard Worker {
31*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
32*49cdfc7eSAndroid Build Coastguard Worker }
33*49cdfc7eSAndroid Build Coastguard Worker #endif
34*49cdfc7eSAndroid Build Coastguard Worker 
pidfd_open_supported(void)35*49cdfc7eSAndroid Build Coastguard Worker static inline void pidfd_open_supported(void)
36*49cdfc7eSAndroid Build Coastguard Worker {
37*49cdfc7eSAndroid Build Coastguard Worker 	/* allow the tests to fail early */
38*49cdfc7eSAndroid Build Coastguard Worker 	tst_syscall(__NR_pidfd_open);
39*49cdfc7eSAndroid Build Coastguard Worker }
40*49cdfc7eSAndroid Build Coastguard Worker 
41*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_PIDFD_OPEN
pidfd_open(pid_t pid,unsigned int flags)42*49cdfc7eSAndroid Build Coastguard Worker static inline int pidfd_open(pid_t pid, unsigned int flags)
43*49cdfc7eSAndroid Build Coastguard Worker {
44*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_pidfd_open, pid, flags);
45*49cdfc7eSAndroid Build Coastguard Worker }
46*49cdfc7eSAndroid Build Coastguard Worker #endif
47*49cdfc7eSAndroid Build Coastguard Worker 
pidfd_getfd_supported(void)48*49cdfc7eSAndroid Build Coastguard Worker static inline void pidfd_getfd_supported(void)
49*49cdfc7eSAndroid Build Coastguard Worker {
50*49cdfc7eSAndroid Build Coastguard Worker 	/* allow the tests to fail early */
51*49cdfc7eSAndroid Build Coastguard Worker 	tst_syscall(__NR_pidfd_getfd);
52*49cdfc7eSAndroid Build Coastguard Worker }
53*49cdfc7eSAndroid Build Coastguard Worker 
54*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_PIDFD_GETFD
pidfd_getfd(int pidfd,int targetfd,unsigned int flags)55*49cdfc7eSAndroid Build Coastguard Worker static inline int pidfd_getfd(int pidfd, int targetfd, unsigned int flags)
56*49cdfc7eSAndroid Build Coastguard Worker {
57*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_pidfd_getfd, pidfd, targetfd, flags);
58*49cdfc7eSAndroid Build Coastguard Worker }
59*49cdfc7eSAndroid Build Coastguard Worker #endif
60*49cdfc7eSAndroid Build Coastguard Worker 
61*49cdfc7eSAndroid Build Coastguard Worker #endif /* LAPI_PIDFD_H__ */
62