Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / sys / siginfo.h @ 13

History | View | Annotate | Download (7.65 KB)

1 13 up20180614
/*        $NetBSD: siginfo.h,v 1.25 2013/11/22 21:04:11 christos Exp $         */
2
3
/*-
4
 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5
 * All rights reserved.
6
 *
7
 * This code is derived from software contributed to The NetBSD Foundation
8
 * by Christos Zoulas.
9
 *
10
 * Redistribution and use in source and binary forms, with or without
11
 * modification, are permitted provided that the following conditions
12
 * are met:
13
 * 1. Redistributions of source code must retain the above copyright
14
 *    notice, this list of conditions and the following disclaimer.
15
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in the
17
 *    documentation and/or other materials provided with the distribution.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
 * POSSIBILITY OF SUCH DAMAGE.
30
 */
31
32
#ifndef        _SYS_SIGINFO_H_
33
#define        _SYS_SIGINFO_H_
34
35
#include <machine/signal.h>
36
#include <sys/featuretest.h>
37
#ifdef _KERNEL
38
#include <sys/queue.h>
39
#endif
40
41
typedef union sigval {
42
        int        sival_int;
43
        void        *sival_ptr;
44
} sigval_t;
45
46
struct _ksiginfo {
47
        int        _signo;
48
        int        _code;
49
        int        _errno;
50
#ifdef _LP64
51
        /* In _LP64 the union starts on an 8-byte boundary. */
52
        int        _pad;
53
#endif
54
        union {
55
                struct {
56
                        pid_t        _pid;
57
                        uid_t        _uid;
58
                        sigval_t        _value;
59
                } _rt;
60
61
                struct {
62
                        pid_t        _pid;
63
                        uid_t        _uid;
64
                        int        _status;
65
                        clock_t        _utime;
66
                        clock_t        _stime;
67
                } _child;
68
69
                struct {
70
                        void   *_addr;
71
                        int        _trap;
72
                        int        _trap2;
73
                        int        _trap3;
74
                } _fault;
75
76
                struct {
77
                        long        _band;
78
                        int        _fd;
79
                } _poll;
80
        } _reason;
81
};
82
83
#ifdef _KERNEL
84
typedef struct ksiginfo {
85
        u_long                        ksi_flags;        /* 4 or 8 bytes (LP64) */
86
        TAILQ_ENTRY(ksiginfo)        ksi_list;
87
        struct _ksiginfo        ksi_info;
88
        lwpid_t                        ksi_lid;        /* 0, or directed to LWP */
89
} ksiginfo_t;
90
91
#define        KSI_TRAP        0x01        /* signal caused by trap */
92
#define        KSI_EMPTY        0x02        /* no additional information */
93
#define        KSI_QUEUED        0x04        /* on a sigpend_t queue */
94
#define        KSI_FROMPOOL        0x08        /* allocated from the ksiginfo pool */
95
96
/* Macros to initialize a ksiginfo_t. */
97
#define        KSI_INIT(ksi)                                                        \
98
do {                                                                        \
99
        memset((ksi), 0, sizeof(*(ksi)));                                \
100
} while (/*CONSTCOND*/0)
101
102
#define        KSI_INIT_EMPTY(ksi)                                                \
103
do {                                                                        \
104
        KSI_INIT((ksi));                                                \
105
        (ksi)->ksi_flags = KSI_EMPTY;                                        \
106
} while (/*CONSTCOND*/0)
107
108
#define        KSI_INIT_TRAP(ksi)                                                \
109
do {                                                                        \
110
        KSI_INIT((ksi));                                                \
111
        (ksi)->ksi_flags = KSI_TRAP;                                        \
112
} while (/*CONSTCOND*/0)
113
114
/* Copy the part of ksiginfo_t without the queue pointers */
115
#define        KSI_COPY(fksi, tksi)                                                \
116
do {                                                                        \
117
        (tksi)->ksi_info = (fksi)->ksi_info;                                \
118
        (tksi)->ksi_flags = (fksi)->ksi_flags;                                \
119
} while (/*CONSTCOND*/0)
120
121
122
/* Predicate macros to test how a ksiginfo_t was generated. */
123
#define        KSI_TRAP_P(ksi)                (((ksi)->ksi_flags & KSI_TRAP) != 0)
124
#define        KSI_EMPTY_P(ksi)        (((ksi)->ksi_flags & KSI_EMPTY) != 0)
125
126
/*
127
 * Old-style signal handler "code" arguments were only non-zero for
128
 * signals caused by traps.
129
 */
130
#define        KSI_TRAPCODE(ksi)        (KSI_TRAP_P(ksi) ? (ksi)->ksi_trap : 0)
131
#endif /* _KERNEL */
132
133
typedef union siginfo {
134
        char        si_pad[128];        /* Total size; for future expansion */
135
        struct _ksiginfo _info;
136
} siginfo_t;
137
138
/** Field access macros */
139
#define        si_signo        _info._signo
140
#define        si_code                _info._code
141
#define        si_errno        _info._errno
142
143
#define        si_value        _info._reason._rt._value
144
#define        si_pid                _info._reason._child._pid
145
#define        si_uid                _info._reason._child._uid
146
#define        si_status        _info._reason._child._status
147
#define        si_utime        _info._reason._child._utime
148
#define        si_stime        _info._reason._child._stime
149
150
#define        si_addr                _info._reason._fault._addr
151
#define        si_trap                _info._reason._fault._trap
152
#define        si_trap2        _info._reason._fault._trap2
153
#define        si_trap3        _info._reason._fault._trap3
154
155
#define        si_band                _info._reason._poll._band
156
#define        si_fd                _info._reason._poll._fd
157
158
#ifdef _KERNEL
159
/** Field access macros */
160
#define        ksi_signo        ksi_info._signo
161
#define        ksi_code        ksi_info._code
162
#define        ksi_errno        ksi_info._errno
163
164
#define        ksi_value        ksi_info._reason._rt._value
165
#define        ksi_pid                ksi_info._reason._child._pid
166
#define        ksi_uid                ksi_info._reason._child._uid
167
#define        ksi_status        ksi_info._reason._child._status
168
#define        ksi_utime        ksi_info._reason._child._utime
169
#define        ksi_stime        ksi_info._reason._child._stime
170
171
#define        ksi_addr        ksi_info._reason._fault._addr
172
#define        ksi_trap        ksi_info._reason._fault._trap
173
#define        ksi_trap2        ksi_info._reason._fault._trap2
174
#define        ksi_trap3        ksi_info._reason._fault._trap3
175
176
#define        ksi_band        ksi_info._reason._poll._band
177
#define        ksi_fd                ksi_info._reason._poll._fd
178
#endif /* _KERNEL */
179
180
/** si_code */
181
/* SIGILL */
182
#define        ILL_ILLOPC        1        /* Illegal opcode                        */
183
#define        ILL_ILLOPN        2        /* Illegal operand                        */
184
#define        ILL_ILLADR        3        /* Illegal addressing mode                */
185
#define        ILL_ILLTRP        4        /* Illegal trap                                */
186
#define        ILL_PRVOPC        5        /* Privileged opcode                        */
187
#define        ILL_PRVREG        6        /* Privileged register                        */
188
#define        ILL_COPROC        7        /* Coprocessor error                        */
189
#define        ILL_BADSTK        8        /* Internal stack error                        */
190
191
/* SIGFPE */
192
#define        FPE_INTDIV        1        /* Integer divide by zero                */
193
#define        FPE_INTOVF        2        /* Integer overflow                        */
194
#define        FPE_FLTDIV        3        /* Floating point divide by zero        */
195
#define        FPE_FLTOVF        4        /* Floating point overflow                */
196
#define        FPE_FLTUND        5        /* Floating point underflow                */
197
#define        FPE_FLTRES        6        /* Floating point inexact result        */
198
#define        FPE_FLTINV        7        /* Invalid Floating point operation        */
199
#define        FPE_FLTSUB        8        /* Subscript out of range                */
200
201
/* SIGSEGV */
202
#define        SEGV_MAPERR        1        /* Address not mapped to object                */
203
#define        SEGV_ACCERR        2        /* Invalid permissions for mapped object*/
204
205
/* SIGBUS */
206
#define        BUS_ADRALN        1        /* Invalid address alignment                */
207
#define        BUS_ADRERR        2        /* Non-existent physical address        */
208
#define        BUS_OBJERR        3        /* Object specific hardware error        */
209
210
/* SIGTRAP */
211
#define        TRAP_BRKPT        1        /* Process breakpoint                        */
212
#define        TRAP_TRACE        2        /* Process trace trap                        */
213
214
/* SIGCHLD */
215
#define        CLD_EXITED        1        /* Child has exited                        */
216
#define        CLD_KILLED        2        /* Child has terminated abnormally but        */
217
                                /* did not create a core file                */
218
#define        CLD_DUMPED        3        /* Child has terminated abnormally and        */
219
                                /* created a core file                        */
220
#define        CLD_TRAPPED        4        /* Traced child has trapped                */
221
#define        CLD_STOPPED        5        /* Child has stopped                        */
222
#define        CLD_CONTINUED        6        /* Stopped child has continued                */
223
224
/* SIGPOLL */
225
#define        POLL_IN                1        /* Data input available                        */
226
#define        POLL_OUT        2        /* Output buffers available                */
227
#define        POLL_MSG        3        /* Input message available                */
228
#define        POLL_ERR        4        /* I/O Error                                */
229
#define        POLL_PRI        5        /* High priority input available        */
230
#define        POLL_HUP        6        /* Device disconnected                        */
231
232
233
/** si_code */
234
#define        SI_USER                0        /* Sent by kill(2)                        */
235
#define        SI_QUEUE        -1        /* Sent by the sigqueue(2)                */
236
#define        SI_TIMER        -2        /* Generated by expiration of a timer        */
237
                                /* set by timer_settime(2)                */
238
#define        SI_ASYNCIO        -3        /* Generated by completion of an        */
239
                                /* asynchronous I/O signal                */
240
#define        SI_MESGQ        -4        /* Generated by arrival of a message on        */
241
                                /* an empty message queue                */
242
#if defined(_KERNEL) || defined(_NETBSD_SOURCE)
243
#define        SI_LWP                -5        /* Generated by _lwp_kill(2)                */
244
#define        SI_NOINFO        32767        /* No signal specific info available        */
245
#endif
246
247
#endif /* !_SYS_SIGINFO_H_ */