/* * 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_usable_size(). */ #include /* syscall(SYS_gettid). */ #if (NXT_GETRANDOM) #include /* getrandom(). */ #endif #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_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 . */ #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) #define _XOPEN_SOURCE /* ucontext(3). */ #ifndef _DARWIN_C_SOURCE #define _DARWIN_C_SOURCE /* pthread_threadid_np(), mach_port_t. */ #endif #include /* mach_absolute_time(). */ #include /* 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 #if (NXT_HAVE_HG_GETHRTIME) #include #endif #endif /* NXT_HPUX */ #if (NXT_HAVE_ALLOCA_H) #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if (NXT_HAVE_POSIX_SPAWN) #include #endif #include #include /* offsetof() */ #include #include #include #include #include #if (NXT_HAVE_SYS_FILIO_H) #include /* FIONBIO */ #endif #include #include #include /* MAXPATHLEN */ #include #include #include #include #include #include #if (NXT_HAVE_UNIX_DOMAIN) #include #endif #include #include #include #include #include #if (NXT_HAVE_EPOLL) #include #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 #endif #if (NXT_HAVE_EVENTFD) #include #endif #if (NXT_HAVE_KQUEUE) #include #endif #if (NXT_HAVE_EVENTPORT) #include #endif #if (NXT_HAVE_DEVPOLL) #include #endif #if (NXT_HAVE_POLLSET) #include #endif #if (NXT_HAVE_LINUX_SENDFILE) #include #endif #if (NXT_HAVE_SOLARIS_SENDFILEV) #include #endif #if (NXT_TEST_BUILD) #include #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_ */