chiark / gitweb /
[PATCH] klibc: version 1.0.4
[elogind.git] / klibc / include / signal.h
1 /*
2  * signal.h
3  */
4
5 #ifndef _SIGNAL_H
6 #define _SIGNAL_H
7
8 #include <klibc/compiler.h>
9 #include <klibc/extern.h>
10 #include <string.h>             /* For memset() */
11 #include <limits.h>             /* For LONG_BIT */
12 #include <sys/types.h>
13 #include <asm/signal.h>
14
15 #include <klibc/archsignal.h>
16
17 /* glibc seems to use sig_atomic_t as "int" pretty much on all architectures.
18    Do the same, but allow the architecture to override. */
19 #ifndef _KLIBC_HAS_ARCH_SIG_ATOMIC_T
20 typedef int sig_atomic_t;
21 #endif
22
23 /* Some architectures don't define these */
24 #ifndef SA_RESETHAND
25 # define SA_RESETHAND SA_ONESHOT
26 #endif
27 #ifndef SA_NODEFER
28 # define SA_NODEFER SA_NOMASK
29 #endif
30 /* Some architectures define NSIG and not _NSIG or vice versa */
31 #ifndef NSIG
32 # define NSIG _NSIG
33 #endif
34 #ifndef _NSIG
35 # define _NSIG NSIG
36 #endif
37
38 /* If we don't have any real-time signals available to userspace,
39    hide them all */
40 #if SIGRTMAX <= SIGRTMIN
41 # undef SIGRTMIN
42 # undef SIGRTMAX
43 #endif
44
45 __extern const char * const sys_siglist[];
46
47 /* This assumes sigset_t is either an unsigned long or an array of such,
48    and that _NSIG_BPW in the kernel is always LONG_BIT */
49
50 static __inline__ int sigemptyset(sigset_t *__set)
51 {
52   memset(__set, 0, sizeof *__set);
53   return 0;
54 }
55 static __inline__ int sigfillset(sigset_t *__set)
56 {
57   memset(__set, ~0, sizeof *__set);
58   return 0;
59 }
60 static __inline__ int sigaddset(sigset_t *__set, int __signum)
61 {
62   unsigned long *__lset = (unsigned long *)__set;
63   __lset[__signum/LONG_BIT] |= 1UL << (__signum%LONG_BIT);
64   return 0;
65 }
66 static __inline__ int sigdelset(sigset_t *__set, int __signum)
67 {
68   unsigned long *__lset = (unsigned long *)__set;
69   __lset[__signum/LONG_BIT] &= ~(1UL << (__signum%LONG_BIT));
70   return 0;
71 }
72 static __inline__ int sigismember(sigset_t *__set, int __signum)
73 {
74   unsigned long *__lset = (unsigned long *)__set;
75   return (int)((__lset[__signum/LONG_BIT] >> (__signum%LONG_BIT)) & 1);
76 }
77
78 __extern __sighandler_t __signal(int, __sighandler_t, int);
79 __extern __sighandler_t sysv_signal(int, __sighandler_t);
80 __extern __sighandler_t bsd_signal(int, __sighandler_t);
81 __extern int sigaction(int, const struct sigaction *, struct sigaction *);
82 __extern int sigprocmask(int, const sigset_t *, sigset_t *);
83 __extern int sigpending(sigset_t *);
84 __extern int sigsuspend(const sigset_t *);
85 __extern int rt_sigaction(int, const struct sigaction *, struct sigaction *, size_t);
86 __extern int rt_sigprocmask(int, const sigset_t *, sigset_t *, size_t);
87 __extern int rt_sigpending(sigset_t *, size_t);
88 __extern int rt_sigsuspend(const sigset_t *, size_t);
89 __extern int raise(int);
90 __extern int kill(pid_t, int);
91
92 #endif /* _SIGNAL_H */