1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
/*
* Copyright (C) Igor Sysoev
* Copyright (C) NGINX, Inc.
*/
#ifndef _NXT_UNIX_H_INCLUDED_
#define _NXT_UNIX_H_INCLUDED_
#if (NXT_LINUX)
#ifdef _FORTIFY_SOURCE
/*
* _FORTIFY_SOURCE
* may call sigaltstack() while _longjmp() checking;
* may cause _longjmp() to fail with message:
* "longjmp() causes uninitialized stack frame";
* does not allow to use "(void) write()";
* does surplus checks.
*/
#undef _FORTIFY_SOURCE
#endif
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* pread(), pwrite(), gethostname(). */
#endif
#define _FILE_OFFSET_BITS 64
#include <malloc.h> /* malloc_usable_size(). */
#include <sys/syscall.h> /* syscall(SYS_gettid). */
#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 4)
/*
* POSIX semaphores using NPTL atomic/futex operations
* were introduced during glibc 2.3 development time.
*/
#define NXT_HAVE_SEM_TRYWAIT_FAST 1
#endif
#endif /* NXT_LINUX */
#if (NXT_FREEBSD)
#if (NXT_HAVE_MALLOC_USABLE_SIZE)
#include <malloc_np.h> /* malloc_usable_size(). */
#endif
#if (__FreeBSD_version >= 900007)
/* POSIX semaphores using atomic/umtx. */
#define NXT_HAVE_SEM_TRYWAIT_FAST 1
#endif
#endif /* NXT_FREEBSD */
#if (NXT_SOLARIS)
#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64 /* Must be before <sys/types.h>. */
#endif
#ifndef _REENTRANT /* May be set by "-mt" options. */
#define _REENTRANT /* Thread safe errno. */
#endif
#ifndef _POSIX_PTHREAD_SEMANTICS
#define _POSIX_PTHREAD_SEMANTICS /* 2 arguments in sigwait(). */
#endif
/*
* Solaris provides two sockets API:
*
* 1) 4.3BSD sockets (int instead of socklen_t in accept(), etc.;
* struct msghdr.msg_accrights) in libsocket;
* 2) X/Open sockets (socklen_t, struct msghdr.msg_control) with __xnet_
* function name prefix in libxnet and libsocket.
*/
/* Enable X/Open sockets API. */
#define _XOPEN_SOURCE
#define _XOPEN_SOURCE_EXTENDED 1
/* Enable Solaris extensions disabled by _XOPEN_SOURCE. */
#ifndef __EXTENSIONS__
#define __EXTENSIONS__
#endif
#endif /* NXT_SOLARIS */
#if (NXT_MACOSX)
#ifndef _DARWIN_C_SOURCE
#define _DARWIN_C_SOURCE /* pthread_threadid_np(), mach_port_t. */
#endif
#include <mach/mach_time.h> /* mach_absolute_time(). */
#include <malloc/malloc.h> /* malloc_size(). */
#endif /* NXT_MACOSX */
#if (NXT_AIX)
#define _THREAD_SAFE /* Must before any include. */
#endif /* NXT_AIX */
#if (NXT_HPUX)
#define _FILE_OFFSET_BITS 64
/*
* HP-UX provides three sockets API:
*
* 1) 4.3BSD sockets (int instead of socklen_t in accept(), etc.;
* struct msghdr.msg_accrights) in libc;
* 2) X/Open sockets (socklen_t, struct msghdr.msg_control) with _xpg_
* function name prefix in libc;
* 3) and X/Open sockets (socklen_t, struct msghdr.msg_control) in libxnet.
*/
/* Enable X/Open sockets API. */
#define _XOPEN_SOURCE
#define _XOPEN_SOURCE_EXTENDED
/* Enable static function wrappers for _xpg_ X/Open sockets API in libc. */
#define _HPUX_ALT_XOPEN_SOCKET_API
#include <sys/mpctl.h>
#if (NXT_HAVE_HG_GETHRTIME)
#include <sys/mercury.h>
#endif
#endif /* NXT_HPUX */
#if (NXT_HAVE_ALLOCA_H)
#include <alloca.h>
#endif
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <limits.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <poll.h>
#include <pwd.h>
#include <semaphore.h>
#include <setjmp.h>
#include <sched.h>
#include <signal.h>
#if (NXT_HAVE_POSIX_SPAWN)
#include <spawn.h>
#endif
#include <stdarg.h>
#include <stddef.h> /* offsetof() */
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#if (NXT_HAVE_SYS_FILIO_H)
#include <sys/filio.h> /* FIONBIO */
#endif
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/param.h> /* MAXPATHLEN */
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#if (NXT_HAVE_UNIX_DOMAIN)
#include <sys/un.h>
#endif
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#if (NXT_HAVE_EPOLL)
#include <sys/epoll.h>
#ifdef EPOLLRDHUP
/*
* Epoll edge-tiggered mode is pretty much useless without EPOLLRDHUP support.
*/
#define NXT_HAVE_EPOLL_EDGE 1
#endif
#endif
#if (NXT_HAVE_SIGNALFD)
#include <sys/signalfd.h>
#endif
#if (NXT_HAVE_EVENTFD)
#include <sys/eventfd.h>
#endif
#if (NXT_HAVE_KQUEUE)
#include <sys/event.h>
#endif
#if (NXT_HAVE_EVENTPORT)
#include <port.h>
#endif
#if (NXT_HAVE_DEVPOLL)
#include <sys/devpoll.h>
#endif
#if (NXT_HAVE_POLLSET)
#include <sys/pollset.h>
#endif
#if (NXT_HAVE_LINUX_SENDFILE)
#include <sys/sendfile.h>
#endif
#if (NXT_HAVE_SOLARIS_SENDFILEV)
#include <sys/sendfile.h>
#endif
#if (NXT_HAVE_GETRANDOM)
#include <sys/random.h> /* getrandom(). */
#elif (NXT_HAVE_LINUX_SYS_GETRANDOM)
#include <linux/random.h> /* SYS_getrandom. */
#elif (NXT_HAVE_GETENTROPY_SYS_RANDOM)
#include <sys/random.h> /* getentropy(). */
#endif
#if (NXT_TEST_BUILD)
#include <nxt_test_build.h>
#endif
/*
* On Linux IOV_MAX is 1024. Linux uses kernel stack for 8 iovec's
* to avoid kernel allocation/deallocation.
*
* On FreeBSD IOV_MAX is 1024. FreeBSD used kernel stack for 8 iovec's
* to avoid kernel allocation/deallocation until FreeBSD 5.2.
* FreeBSD 5.2 and later do not use stack at all.
*
* On Solaris IOV_MAX is 16 and Solaris uses only kernel stack.
*
* On MacOSX IOV_MAX is 1024. MacOSX used kernel stack for 8 iovec's
* to avoid kernel allocation/deallocation until MacOSX 10.4 (Tiger).
* MacOSX 10.4 and later do not use stack at all.
*
* On NetBSD, OpenBSD, and DragonFlyBSD IOV_MAX is 1024. All these OSes
* uses kernel stack for 8 iovec's to avoid kernel allocation/deallocation.
*
* On AIX and HP-UX IOV_MAX is 16.
*/
#define NXT_IOBUF_MAX 8
typedef struct iovec nxt_iobuf_t;
#define \
nxt_iobuf_data(iob) \
(iob)->iov_base
#define \
nxt_iobuf_size(iob) \
(iob)->iov_len
#define \
nxt_iobuf_set(iob, p, size) \
do { \
(iob)->iov_base = (void *) p; \
(iob)->iov_len = size; \
} while (0)
#define \
nxt_iobuf_add(iob, size) \
(iob)->iov_len += size
#endif /* _NXT_UNIX_H_INCLUDED_ */
|