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