stdlib: call __neatlibc_exit() in exit()
[neatlibc.git] / signal.c
blob34552ba3e0fecef26bd8a026bf93df313608c5f7
1 #ifdef __x86_64__
3 #include <signal.h>
5 #define SIG_BLOCK 0
6 #define SIG_UNBLOCK 1
7 #define SIG_SETMASK 2
9 #define SA_NOCLDSTOP 1
10 #define SA_NOCLDWAIT 2
11 #define SA_SIGINFO 4
12 #define SA_ONSTACK 0x08000000
13 #define SA_RESTART 0x10000000
14 #define SA_NODEFER 0x40000000
15 #define SA_RESETHAND 0x80000000
16 #define SA_RESTORER 0x04000000
18 struct sigset_t {
19 unsigned long __bits[128 / sizeof(long)];
21 typedef struct sigset_t sigset_t;
23 struct sigaction {
24 void (*sa_handler)(int);
25 sigset_t sa_mask;
26 int sa_flags;
27 void (*sa_restorer)(void);
30 int sigreturn(unsigned long n);
32 struct ksa {
33 void *handler;
34 unsigned long flags;
35 int (*restorer)(unsigned long n);
36 sigset_t mask;
39 int __sigaction(int sig, const struct sigaction *sa, struct sigaction *old)
41 struct ksa ksa, _ksa;
42 if (sa) {
43 ksa.handler = sa->sa_handler;
44 ksa.flags = sa->sa_flags | SA_RESTORER;
45 ksa.restorer = sigreturn;
46 ksa.mask = sa->sa_mask;
48 if (sigaction(sig, sa ? (long) &ksa : 0, old ? (long) &_ksa : 0, 8))
49 return -1;
50 if (old) {
51 old->sa_handler = _ksa.handler;
52 old->sa_flags = _ksa.flags;
53 old->sa_mask = _ksa.mask;
55 return 0;
58 int sigaction(int sig, struct sigaction *sa, struct sigaction *old_sa);
60 sighandler_t signal(int sig, sighandler_t func)
62 struct sigaction sa = {.sa_handler = func, .sa_flags = SA_RESTART};
63 if (__sigaction(sig, &sa, &sa) < 0)
64 return SIG_ERR;
65 return sa.sa_handler;
68 #endif