1 #pragma once
2 #include <unistd.h>
3 
4 #if defined(__cplusplus)
5 extern  "C"  {
6 #endif
7 
8 #define SIGHUP 1
9 #define SIGINT 2
10 #define SIGQUIT 3
11 #define SIGILL 4
12 #define SIGTRAP 5
13 #define SIGABRT 6
14 #define SIGIOT 6
15 #define SIGBUS 7
16 #define SIGFPE 8
17 #define SIGKILL 9
18 #define SIGUSR1 10
19 #define SIGSEGV 11
20 #define SIGUSR2 12
21 #define SIGPIPE 13
22 #define SIGALRM 14
23 #define SIGTERM 15
24 #define SIGSTKFLT 16
25 #define SIGCHLD 17
26 #define SIGCONT 18
27 #define SIGSTOP 19
28 #define SIGTSTP 20
29 #define SIGTTIN 21
30 #define SIGTTOU 22
31 #define SIGURG 23
32 #define SIGXCPU 24
33 #define SIGXFSZ 25
34 #define SIGVTALRM 26
35 #define SIGPROF 27
36 #define SIGWINCH 28
37 #define SIGIO 29
38 #define SIGPOLL SIGIO
39 
40 #define SIGPWR 30
41 #define SIGSYS 31
42 
43 /* These should not be considered constants from userland.  */
44 #define SIGRTMIN 32
45 #define SIGRTMAX MAX_SIG_NUM
46 
47 typedef void (*__sighandler_t)(int);
48 
49 #define SIG_DFL ((__sighandler_t)0) /* Default action.  */
50 #define SIG_IGN ((__sighandler_t)1) /* Ignore signal.  */
51 
52 // 注意,该结构体最大16字节
53 union __sifields {
54     /* kill() */
55     struct
56     {
57         pid_t _pid; /* 信号发送者的pid */
58     } _kill;
59 };
60 
61 // 注意,该结构体最大大小为32字节
62 #define __SIGINFO                                                                                                      \
63     struct                                                                                                             \
64     {                                                                                                                  \
65         int32_t si_signo; /* signal number */                                                                          \
66         int32_t si_code;                                                                                               \
67         int32_t si_errno;                                                                                              \
68         uint32_t reserved; /* 保留备用 */                                                                          \
69         union __sifields _sifields;                                                                                    \
70     }
71 
72 typedef struct
73 {
74     union {
75         __SIGINFO;
76         uint64_t padding[4]; // 让siginfo占用32字节大小
77     };
78 } siginfo_t;
79 
80 typedef struct
81 {
82     uint64_t set;
83 } sigset_t;
84 
85 struct sigaction
86 {
87     // sa_handler和sa_sigaction二选1
88     __sighandler_t sa_handler;
89     void (*sa_sigaction)(int, siginfo_t *, void *);
90     sigset_t sa_mask;
91     uint64_t sa_flags;
92     void (*sa_restorer)(void);
93 };
94 
95 int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
96 int signal(int signum, __sighandler_t handler);
97 int raise(int sig);
98 int kill(pid_t, int sig);
99 
100 #if defined(__cplusplus)
101 }  /* extern "C" */
102 #endif