xref: /netbsd-src/include/signal.h (revision 16b64fc3a6275026aa14750a215c499b4885c03e)
1*16b64fc3Srillig /*	$NetBSD: signal.h,v 1.60 2024/09/09 21:19:54 rillig Exp $	*/
24d2cbfceScgd 
37e4a306fScgd /*-
47e4a306fScgd  * Copyright (c) 1991, 1993
57e4a306fScgd  *	The Regents of the University of California.  All rights reserved.
67e4a306fScgd  *
77e4a306fScgd  * Redistribution and use in source and binary forms, with or without
87e4a306fScgd  * modification, are permitted provided that the following conditions
97e4a306fScgd  * are met:
107e4a306fScgd  * 1. Redistributions of source code must retain the above copyright
117e4a306fScgd  *    notice, this list of conditions and the following disclaimer.
127e4a306fScgd  * 2. Redistributions in binary form must reproduce the above copyright
137e4a306fScgd  *    notice, this list of conditions and the following disclaimer in the
147e4a306fScgd  *    documentation and/or other materials provided with the distribution.
15039cc956Sagc  * 3. Neither the name of the University nor the names of its contributors
167e4a306fScgd  *    may be used to endorse or promote products derived from this software
177e4a306fScgd  *    without specific prior written permission.
187e4a306fScgd  *
197e4a306fScgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
207e4a306fScgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
217e4a306fScgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
227e4a306fScgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
237e4a306fScgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
247e4a306fScgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
257e4a306fScgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
267e4a306fScgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
277e4a306fScgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
287e4a306fScgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
297e4a306fScgd  * SUCH DAMAGE.
307e4a306fScgd  *
317e4a306fScgd  *	@(#)signal.h	8.3 (Berkeley) 3/30/94
327e4a306fScgd  */
337e4a306fScgd 
34c97ee76bSkleink #ifndef _SIGNAL_H_
35c97ee76bSkleink #define _SIGNAL_H_
367e4a306fScgd 
377e4a306fScgd #include <sys/cdefs.h>
38c97ee76bSkleink #include <sys/featuretest.h>
397e4a306fScgd 
404be7a2dcSbjh21 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
414be7a2dcSbjh21     defined(_NETBSD_SOURCE)
4237133e94Sjtc #include <sys/types.h>
4337133e94Sjtc #endif
4437133e94Sjtc 
45bb8dae36Skleink #include <sys/signal.h>
46bb8dae36Skleink 
474cbe3e34Sjoerg __BEGIN_DECLS
484be7a2dcSbjh21 #if defined(_NETBSD_SOURCE)
49a2cd7322Sperry extern const char *const *sys_signame __RENAME(__sys_signame14);
50d1969826Schristos #ifndef __SYS_SIGLIST_DECLARED
51d1969826Schristos #define __SYS_SIGLIST_DECLARED
52d1969826Schristos /* also in unistd.h */
53a2cd7322Sperry extern const char *const *sys_siglist __RENAME(__sys_siglist14);
54d1969826Schristos #endif /* __SYS_SIGLIST_DECLARED */
55a2cd7322Sperry extern const int sys_nsig __RENAME(__sys_nsig14);
567e4a306fScgd #endif
577e4a306fScgd 
5819b7469aSperry int	raise(int);
5948669190Skre 
6048669190Skre #if defined(_NETBSD_SOURCE)
6148669190Skre const char *signalname(int);
6248669190Skre int signalnext(int);
6348669190Skre int signalnumber(const char *);
6448669190Skre #endif
6548669190Skre 
66e3167f6cSbjh21 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
67e3167f6cSbjh21     defined(_NETBSD_SOURCE)
6819b7469aSperry int	kill(pid_t, int);
6902edde8aSthorpej int	__sigaction_siginfo(int, const struct sigaction * __restrict,
70b9a719aeSkleink 	    struct sigaction * __restrict);
7143a24c44Smycroft 
721c5f5912Snathanw #if (_POSIX_C_SOURCE - 0L) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
731c5f5912Snathanw     defined(_NETBSD_SOURCE)
745af00b0bSkleink int	pthread_sigmask(int, const sigset_t * __restrict,
755af00b0bSkleink 	    sigset_t * __restrict);
7619b7469aSperry int	pthread_kill(pthread_t, int);
775af00b0bSkleink int	__libc_thr_sigsetmask(int, const sigset_t * __restrict,
785af00b0bSkleink 	    sigset_t * __restrict);
790eaa8971Snathanw #ifndef __LIBPTHREAD_SOURCE__
800eaa8971Snathanw #define	pthread_sigmask		__libc_thr_sigsetmask
810eaa8971Snathanw #endif /* __LIBPTHREAD_SOURCE__ */
821c5f5912Snathanw #endif
83c62a74e6Sthorpej 
8466412e72Schristos #ifndef __LIBC12_SOURCE__
85b9a719aeSkleink int	sigaction(int, const struct sigaction * __restrict,
8602edde8aSthorpej 	    struct sigaction * __restrict) __RENAME(__sigaction_siginfo);
8719b7469aSperry int	sigaddset(sigset_t *, int) __RENAME(__sigaddset14);
8819b7469aSperry int	sigdelset(sigset_t *, int) __RENAME(__sigdelset14);
8919b7469aSperry int	sigemptyset(sigset_t *) __RENAME(__sigemptyset14);
9019b7469aSperry int	sigfillset(sigset_t *) __RENAME(__sigfillset14);
9119b7469aSperry int	sigismember(const sigset_t *, int) __RENAME(__sigismember14);
9219b7469aSperry int	sigpending(sigset_t *) __RENAME(__sigpending14);
93b9a719aeSkleink int	sigprocmask(int, const sigset_t * __restrict, sigset_t * __restrict)
94b9a719aeSkleink 	    __RENAME(__sigprocmask14);
9519b7469aSperry int	sigsuspend(const sigset_t *) __RENAME(__sigsuspend14);
96ff34f690Sjtc 
9744b30937Sjoerg #if defined(__c99inline) || defined(__SIGSETOPS_BODY)
9844b30937Sjoerg 
9944b30937Sjoerg #if defined(__SIGSETOPS_BODY)
10044b30937Sjoerg #undef	__c99inline
10144b30937Sjoerg #define	__c99inline
10244b30937Sjoerg #endif
103933ac468Sdholland 
10465900038Sdholland /* note: this appears in both errno.h and signal.h */
105933ac468Sdholland #ifndef __errno
10619b7469aSperry int *__errno(void);
107933ac468Sdholland #define __errno __errno
108d1969826Schristos #endif
109933ac468Sdholland 
110933ac468Sdholland /* the same as "errno" - but signal.h is not allowed to define that */
111933ac468Sdholland #ifndef ___errno
112933ac468Sdholland #define ___errno (*__errno())
113933ac468Sdholland #endif
114933ac468Sdholland 
11544b30937Sjoerg __c99inline int
11657387ec1Smycroft sigaddset(sigset_t *set, int signo)
11757387ec1Smycroft {
11884b76af5Sjtc 	if (signo <= 0 || signo >= _NSIG) {
119933ac468Sdholland 		___errno = 22;			/* EINVAL */
12057387ec1Smycroft 		return (-1);
121ff34f690Sjtc 	}
12243a24c44Smycroft 	__sigaddset(set, signo);
123ff34f690Sjtc 	return (0);
124ff34f690Sjtc }
125ff34f690Sjtc 
12644b30937Sjoerg __c99inline int
12757387ec1Smycroft sigdelset(sigset_t *set, int signo)
12857387ec1Smycroft {
12984b76af5Sjtc 	if (signo <= 0 || signo >= _NSIG) {
130933ac468Sdholland 		___errno = 22;			/* EINVAL */
13157387ec1Smycroft 		return (-1);
132ff34f690Sjtc 	}
13343a24c44Smycroft 	__sigdelset(set, signo);
134ff34f690Sjtc 	return (0);
135ff34f690Sjtc }
136ff34f690Sjtc 
13744b30937Sjoerg __c99inline int
13857387ec1Smycroft sigismember(const sigset_t *set, int signo)
13957387ec1Smycroft {
14084b76af5Sjtc 	if (signo <= 0 || signo >= _NSIG) {
141933ac468Sdholland 		___errno = 22;			/* EINVAL */
14257387ec1Smycroft 		return (-1);
143ff34f690Sjtc 	}
14443a24c44Smycroft 	return (__sigismember(set, signo));
145ff34f690Sjtc }
146ff34f690Sjtc 
14744b30937Sjoerg __c99inline int
148c3d77c55Skleink sigemptyset(sigset_t *set)
149c3d77c55Skleink {
150c3d77c55Skleink 	__sigemptyset(set);
151c3d77c55Skleink 	return (0);
152c3d77c55Skleink }
153c3d77c55Skleink 
15444b30937Sjoerg __c99inline int
155c3d77c55Skleink sigfillset(sigset_t *set)
156c3d77c55Skleink {
157c3d77c55Skleink 	__sigfillset(set);
158c3d77c55Skleink 	return (0);
159c3d77c55Skleink }
16044b30937Sjoerg #endif /* __c99inline */
1617dcac1e4Sthorpej #endif /* !__LIBC12_SOURCE__ */
16237133e94Sjtc 
16330a90a73Skleink /*
1647e47c9f6Skleink  * X/Open CAE Specification Issue 4 Version 2
16530a90a73Skleink  */
1664be7a2dcSbjh21 #if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
167686d7357Schristos     (_XOPEN_SOURCE - 0) >= 500 || (_POSIX_C_SOURCE - 0) >= 200809L || \
168686d7357Schristos     defined(_NETBSD_SOURCE)
16919b7469aSperry int	killpg(pid_t, int);
17019b7469aSperry int	siginterrupt(int, int);
17119b7469aSperry int	sigstack(const struct sigstack *, struct sigstack *);
17266412e72Schristos #ifndef __LIBC12_SOURCE__
173b9a719aeSkleink int	sigaltstack(const stack_t * __restrict, stack_t * __restrict)
174b9a719aeSkleink     __RENAME(__sigaltstack14);
1755d7a8f4aSkleink #endif
17619b7469aSperry int	sighold(int);
17719b7469aSperry int	sigignore(int);
17819b7469aSperry int	sigpause(int);
17919b7469aSperry int	sigrelse(int);
18019b7469aSperry void	(*sigset (int, void (*)(int)))(int);
181686d7357Schristos #endif /* _XOPEN_SOURCE_EXTENDED || _XOPEN_SOURCE >= 500
182686d7357Schristos 	* || _POSIX_C_SOURCE >= 200809L || _NETBSD_SOURCE
183686d7357Schristos 	*/
1847e47c9f6Skleink 
1857e47c9f6Skleink 
1867e47c9f6Skleink /*
1877e47c9f6Skleink  * X/Open CAE Specification Issue 5; IEEE Std 1003.1b-1993 (POSIX)
1887e47c9f6Skleink  */
1897e47c9f6Skleink #if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \
1907e47c9f6Skleink     defined(_NETBSD_SOURCE)
19119b7469aSperry int	sigwait	(const sigset_t * __restrict, int * __restrict);
19219b7469aSperry int	sigwaitinfo(const sigset_t * __restrict, siginfo_t * __restrict);
1936a480416Schristos void	psiginfo(const siginfo_t *, const char *);
194af3d346aSjdolecek 
19550728e78Schristos #ifndef __LIBC12_SOURCE__
1960c4bdb74Skamil #include <sys/timespec.h>
19719b7469aSperry int	sigtimedwait(const sigset_t * __restrict,
19850728e78Schristos     siginfo_t * __restrict, const struct timespec * __restrict)
19950728e78Schristos     __RENAME(__sigtimedwait50);
20019b7469aSperry int	__sigtimedwait(const sigset_t * __restrict,
20150728e78Schristos     siginfo_t * __restrict, struct timespec * __restrict)
20250728e78Schristos     __RENAME(____sigtimedwait50);
20350728e78Schristos #endif
204*16b64fc3Srillig #endif /* _POSIX_C_SOURCE >= 199309L || _XOPEN_SOURCE_EXTENDED || ... */
20530a90a73Skleink 
20630a90a73Skleink 
2074be7a2dcSbjh21 #if defined(_NETBSD_SOURCE)
208d1969826Schristos #ifndef __PSIGNAL_DECLARED
209d1969826Schristos #define __PSIGNAL_DECLARED
210d1969826Schristos /* also in unistd.h */
2116a480416Schristos void	psignal(int, const char *);
212d1969826Schristos #endif /* __PSIGNAL_DECLARED */
21319b7469aSperry int	sigblock(int);
21419b7469aSperry int	sigsetmask(int);
2154be7a2dcSbjh21 #endif /* _NETBSD_SOURCE */
216c97ee76bSkleink 
21702edde8aSthorpej int	__sigtramp_check_np(void *);
21802edde8aSthorpej 
219e3167f6cSbjh21 #endif	/* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE */
2207e4a306fScgd __END_DECLS
2217e4a306fScgd 
222c97ee76bSkleink #endif	/* !_SIGNAL_H_ */
223