libuv/include/uv/unix.h
Jameson Nash 29a708a434 2024.02.07, Version 1.48.0 (Stable)
Changes since version 1.47.0:
 
 * misc: remove deprecated stalebot file (Jameson Nash)
 
 * build: disable windows asan buildbot (Ben Noordhuis)
 
 * test: don't run tcp_writealot under msan (Ben Noordhuis)
 
 * build,win: remove extraneous -lshell32 (Ben Noordhuis)
 
 * unix: ignore ifaddrs with NULL ifa_addr (Stephen Gallagher)
 
 * unix,win: utility for setting priority for thread (Hao Hu)
 
 * pipe: add back error handling to connect / bind (Jameson Nash)
 
 * test: check if ipv6 link-local traffic is routable (Ben Noordhuis)
 
 * win: remove check for UV_PIPE_NO_TRUNCATE (Jameson Nash)
 
 * linux: disable io_uring on hppa below kernel 6.1.51 (matoro)
 
 * unix,win: fix read past end of pipe name buffer (Ben Noordhuis)
 
 * unix: unbreak macOS < 10.14 (Sergey Fedorov)
 
 * aix: disable ipv6 link local (Abdirahim Musse)
 
 * doc: move cjihrig to emeriti (cjihrig)
 
 * unix: correct pwritev conditional (Bo Anderson)
 
 * test_fs.c: Fix issue on 32-bit systems using btrfs (Stephen Gallagher)
 
 * misc: ignore libuv-release-tool files (Jameson Nash)
 
 * win: honor NoDefaultCurrentDirectoryInExePath env var (Ardi Nugraha)
 
 * idna: fix compilation warning (Saúl Ibarra Corretgé)
 
 * linux: remove HAVE_IFADDRS_H macro (Ben Noordhuis)
 
 * test: skip tcp-write-in-a-row on IBM i (Abdirahim Musse)
 
 * build,win: work around missing uuid.dll on MinGW (Anton Bachin)
 
 * win: stop using deprecated names (Matheus Izvekov)
 
 * unix,win: fix busy loop with zero timeout timers (Matheus Izvekov)
 
 * aix,ibmi: use uv_interface_addresses instead of getifaddrs (Abdirahim Musse)
 
 * linux: fix bind/connect for abstract sockets (Santiago Gimeno)
 
 * win: replace c99 comments with c89 comments (Trevor Flynn)
 
 * build: add .cache clangd folder to .gitignore (Juan José Arboleda)
 
 * unix: support full TCP keep-alive on Solaris (Andy Pan)
 
 * freebsd: fix F_KINFO file path handling (David Carlier)
 
 * linux: retry fs op if unsupported by io_uring (Santiago Gimeno)
 
 * freebsd: fix build on non-intel archs (David Carlier)
 
 * unix: optimize uv__tcp_keepalive cpp directives (Andy Pan)
 
 * linux: disable io_uring on ppc64 and ppc64le (Brad King)
 
 * doc: add very basic Security Policy document (Santiago Gimeno)
 
 * build: re-enable msvc-asan job on CI (Jameson Nash)
 
 * win/spawn: optionally run executable paths with no file extension (Brad King)
 
 * win: fix ESRCH implementation (Jameson Nash)
 
 * unix,win: reset the timer queue on stop (Santiago Gimeno)
 
 * fix: always zero-terminate idna output (Ben Noordhuis)
 
 * fix: reject zero-length idna inputs (Ben Noordhuis)
 
 * test: empty strings are not valid IDNA (Santiago Gimeno)
 
 * Merge pull request from GHSA-f74f-cvh7-c6q6 (Ben Noordhuis)
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEYS8OrZQBYiN530QC8ow8jaM8A74FAmXD5fwACgkQ8ow8jaM8
 A76H+g/9F2O6hXWfm5LACvIRhcDovK1NLprTp5Ae5qA9klSDzClxi6n7/B9NtDhv
 X2EwEXhQpc/Y600dbfcmKr6P5Gt2FDhjO3iy9gCrkUN+ZHV7kRCb8dmp+eyGcOag
 uKqkkpZN6aiT0Jp4H4x66VnSotvLeilHzs16+A3/r5wUNmqzhj0cG/UVaDyZfYEH
 NCqv5MFw2N9qO5lnsu2g1sDEujnjWhXUcY9D1vVUDf63CU09n+lz1LKRB5LKEGRy
 bPF/IjuxJAJQA+gsgj1dP2nuUH8IGhNOpkQ2WG8wEuPp6hahGvND4YovP/sDY7pV
 9oo+73v1boAlYVS9IhAINVnKiPJx7tHJQvMcmgezSBCrd6v+PoWfL4A9oAWOp1qX
 ju+PC2Xk7E9Kt5gC9hjDzdMt6nw7Ab5pJ3ZcVF/2Sq27w0T4nxAOOpAt7JnJ53ug
 o26RWlO9NvBe30Uh2fwqye1UuL17Qjo7Y+ztrMQGmeV+RW693xqZ/bnVOhQupfqI
 fJNl1BBgInT9IU+A8ZtHeDuRf04hEit0rzS/yGrcHa1bHEHorG5W52nazYIsQURM
 hwWBDQ2dH2iTogHGdQ/CKdMGwuo+RwCavBXCHu03jf10hy+ImHF5ifJA7WLeH0oF
 QlCmeJl/26sOHlEa7wQnjhzh7YNg6JDuq6K22a9iR5vnduK1ByU=
 =67rH
 -----END PGP SIGNATURE-----

Merge tag 'v1.48.0' into merge_1.48.0
2024-02-09 19:52:08 +00:00

501 lines
19 KiB
C

/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef UV_UNIX_H
#define UV_UNIX_H
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h> /* MAXHOSTNAMELEN on Solaris */
#include <termios.h>
#include <pwd.h>
#if !defined(__MVS__)
#include <semaphore.h>
#include <sys/param.h> /* MAXHOSTNAMELEN on Linux and the BSDs */
#endif
#include <pthread.h>
#include <signal.h>
#include "uv/threadpool.h"
#if defined(__linux__)
# include "uv/linux.h"
#elif defined (__MVS__)
# include "uv/os390.h"
#elif defined(__PASE__) /* __PASE__ and _AIX are both defined on IBM i */
# include "uv/posix.h" /* IBM i needs uv/posix.h, not uv/aix.h */
#elif defined(_AIX)
# include "uv/aix.h"
#elif defined(__sun)
# include "uv/sunos.h"
#elif defined(__APPLE__)
# include "uv/darwin.h"
#elif defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__OpenBSD__) || \
defined(__NetBSD__)
# include "uv/bsd.h"
#elif defined(__CYGWIN__) || \
defined(__MSYS__) || \
defined(__HAIKU__) || \
defined(__QNX__) || \
defined(__GNU__)
# include "uv/posix.h"
#endif
#ifndef NI_MAXHOST
# define NI_MAXHOST 1025
#endif
#ifndef NI_MAXSERV
# define NI_MAXSERV 32
#endif
#ifndef UV_IO_PRIVATE_PLATFORM_FIELDS
# define UV_IO_PRIVATE_PLATFORM_FIELDS /* empty */
#endif
struct uv__io_s;
struct uv_loop_s;
typedef void (*uv__io_cb)(struct uv_loop_s* loop,
struct uv__io_s* w,
unsigned int events);
typedef struct uv__io_s uv__io_t;
struct uv__io_s {
uv__io_cb cb;
struct uv__queue pending_queue;
struct uv__queue watcher_queue;
unsigned int pevents; /* Pending event mask i.e. mask at next tick. */
unsigned int events; /* Current event mask. */
int fd;
UV_IO_PRIVATE_PLATFORM_FIELDS
};
#ifndef UV_PLATFORM_SEM_T
# define UV_PLATFORM_SEM_T sem_t
#endif
#ifndef UV_PLATFORM_LOOP_FIELDS
# define UV_PLATFORM_LOOP_FIELDS /* empty */
#endif
#ifndef UV_PLATFORM_FS_EVENT_FIELDS
# define UV_PLATFORM_FS_EVENT_FIELDS /* empty */
#endif
#ifndef UV_STREAM_PRIVATE_PLATFORM_FIELDS
# define UV_STREAM_PRIVATE_PLATFORM_FIELDS /* empty */
#endif
/* Note: May be cast to struct iovec. See writev(2). */
typedef struct uv_buf_t {
char* base;
size_t len;
} uv_buf_t;
typedef int uv_os_sock_t;
typedef int uv_os_fd_t;
typedef pid_t uv_pid_t;
#define UV_ONCE_INIT PTHREAD_ONCE_INIT
typedef pthread_once_t uv_once_t;
typedef pthread_t uv_thread_t;
typedef pthread_mutex_t uv_mutex_t;
typedef pthread_rwlock_t uv_rwlock_t;
typedef UV_PLATFORM_SEM_T uv_sem_t;
typedef pthread_cond_t uv_cond_t;
typedef pthread_key_t uv_key_t;
/* Note: guard clauses should match uv_barrier_init's in src/unix/thread.c. */
#if defined(_AIX) || \
defined(__OpenBSD__) || \
!defined(PTHREAD_BARRIER_SERIAL_THREAD)
typedef struct {
uv_mutex_t mutex;
uv_cond_t cond;
unsigned threshold;
unsigned in;
unsigned out;
} uv_barrier_t;
#else
typedef pthread_barrier_t uv_barrier_t;
#endif
/* Platform-specific definitions for uv_spawn support. */
typedef gid_t uv_gid_t;
typedef uid_t uv_uid_t;
typedef struct dirent uv__dirent_t;
#define UV_DIR_PRIVATE_FIELDS \
DIR* dir;
#if defined(DT_UNKNOWN)
# define HAVE_DIRENT_TYPES
# if defined(DT_REG)
# define UV__DT_FILE DT_REG
# else
# define UV__DT_FILE -1
# endif
# if defined(DT_DIR)
# define UV__DT_DIR DT_DIR
# else
# define UV__DT_DIR -2
# endif
# if defined(DT_LNK)
# define UV__DT_LINK DT_LNK
# else
# define UV__DT_LINK -3
# endif
# if defined(DT_FIFO)
# define UV__DT_FIFO DT_FIFO
# else
# define UV__DT_FIFO -4
# endif
# if defined(DT_SOCK)
# define UV__DT_SOCKET DT_SOCK
# else
# define UV__DT_SOCKET -5
# endif
# if defined(DT_CHR)
# define UV__DT_CHAR DT_CHR
# else
# define UV__DT_CHAR -6
# endif
# if defined(DT_BLK)
# define UV__DT_BLOCK DT_BLK
# else
# define UV__DT_BLOCK -7
# endif
#endif
/* Platform-specific definitions for uv_dlopen support. */
#define UV_DYNAMIC /* empty */
typedef struct {
void* handle;
char* errmsg;
} uv_lib_t;
#define UV_LOOP_PRIVATE_FIELDS \
unsigned long flags; \
int backend_fd; \
struct uv__queue pending_queue; \
struct uv__queue watcher_queue; \
uv__io_t** watchers; \
unsigned int nwatchers; \
unsigned int nfds; \
struct uv__queue wq; \
uv_mutex_t wq_mutex; \
uv_async_t wq_async; \
uv_rwlock_t cloexec_lock; \
uv_handle_t* closing_handles; \
struct uv__queue process_handles; \
struct uv__queue prepare_handles; \
struct uv__queue check_handles; \
struct uv__queue idle_handles; \
struct uv__queue async_handles; \
uv__io_t async_io_watcher; \
int async_wfd; \
struct { \
void* min; \
unsigned int nelts; \
} timer_heap; \
uint64_t timer_counter; \
uint64_t time; \
int signal_pipefd[2]; \
uv__io_t signal_io_watcher; \
uv_signal_t child_watcher; \
int emfile_fd; \
UV_PLATFORM_LOOP_FIELDS \
#define UV_REQ_TYPE_PRIVATE /* empty */
#define UV_REQ_PRIVATE_FIELDS /* empty */
#define UV_PRIVATE_REQ_TYPES /* empty */
#define UV_WRITE_PRIVATE_FIELDS \
struct uv__queue queue; \
unsigned int write_index; \
uv_buf_t* bufs; \
unsigned int nbufs; \
int error; \
uv_buf_t bufsml[4]; \
#define UV_CONNECT_PRIVATE_FIELDS \
struct uv__queue queue; \
#define UV_SHUTDOWN_PRIVATE_FIELDS /* empty */
#define UV_UDP_SEND_PRIVATE_FIELDS \
struct uv__queue queue; \
struct sockaddr_storage addr; \
unsigned int nbufs; \
uv_buf_t* bufs; \
ssize_t status; \
uv_udp_send_cb send_cb; \
uv_buf_t bufsml[4]; \
#define UV_HANDLE_PRIVATE_FIELDS \
uv_handle_t* next_closing; \
unsigned int flags; \
#define UV_STREAM_PRIVATE_FIELDS \
uv_connect_t *connect_req; \
uv_shutdown_t *shutdown_req; \
uv__io_t io_watcher; \
struct uv__queue write_queue; \
struct uv__queue write_completed_queue; \
uv_connection_cb connection_cb; \
int delayed_error; \
int accepted_fd; \
void* queued_fds; \
UV_STREAM_PRIVATE_PLATFORM_FIELDS \
#define UV_TCP_PRIVATE_FIELDS /* empty */
#define UV_UDP_PRIVATE_FIELDS \
uv_alloc_cb alloc_cb; \
uv_udp_recv_cb recv_cb; \
uv__io_t io_watcher; \
struct uv__queue write_queue; \
struct uv__queue write_completed_queue; \
#define UV_PIPE_PRIVATE_FIELDS \
const char* pipe_fname; /* NULL or strdup'ed */
#define UV_POLL_PRIVATE_FIELDS \
uv__io_t io_watcher;
#define UV_PREPARE_PRIVATE_FIELDS \
uv_prepare_cb prepare_cb; \
struct uv__queue queue; \
#define UV_CHECK_PRIVATE_FIELDS \
uv_check_cb check_cb; \
struct uv__queue queue; \
#define UV_IDLE_PRIVATE_FIELDS \
uv_idle_cb idle_cb; \
struct uv__queue queue; \
#define UV_ASYNC_PRIVATE_FIELDS \
uv_async_cb async_cb; \
struct uv__queue queue; \
int busy; \
int pending; \
#define UV_TIMER_PRIVATE_FIELDS \
uv_timer_cb timer_cb; \
union { \
void* heap[3]; \
struct uv__queue queue; \
} node; \
uint64_t timeout; \
uint64_t repeat; \
uint64_t start_id;
#define UV_GETADDRINFO_PRIVATE_FIELDS \
struct uv__work work_req; \
uv_getaddrinfo_cb cb; \
struct addrinfo* hints; \
char* hostname; \
char* service; \
struct addrinfo* addrinfo; \
int retcode;
#define UV_GETNAMEINFO_PRIVATE_FIELDS \
struct uv__work work_req; \
uv_getnameinfo_cb getnameinfo_cb; \
struct sockaddr_storage storage; \
int flags; \
char host[NI_MAXHOST]; \
char service[NI_MAXSERV]; \
int retcode;
#define UV_PROCESS_PRIVATE_FIELDS \
struct uv__queue queue; \
int status; \
#define UV_FS_PRIVATE_FIELDS \
const char *new_path; \
uv_os_fd_t file; \
int flags; \
mode_t mode; \
unsigned int nbufs; \
uv_buf_t* bufs; \
off_t off; \
uv_uid_t uid; \
uv_gid_t gid; \
double btime; \
double atime; \
double mtime; \
struct uv__work work_req; \
uv_buf_t bufsml[4]; \
#define UV_WORK_PRIVATE_FIELDS \
struct uv__work work_req;
#define UV_TTY_PRIVATE_FIELDS \
struct termios orig_termios; \
int mode;
#define UV_SIGNAL_PRIVATE_FIELDS \
/* RB_ENTRY(uv_signal_s) tree_entry; */ \
struct { \
struct uv_signal_s* rbe_left; \
struct uv_signal_s* rbe_right; \
struct uv_signal_s* rbe_parent; \
int rbe_color; \
} tree_entry; \
/* Use two counters here so we don have to fiddle with atomics. */ \
unsigned int caught_signals; \
unsigned int dispatched_signals;
#define UV_FS_EVENT_PRIVATE_FIELDS \
uv_fs_event_cb cb; \
UV_PLATFORM_FS_EVENT_FIELDS \
/* fs open() flags supported on this platform: */
#if defined(O_APPEND)
# define UV_FS_O_APPEND O_APPEND
#else
# define UV_FS_O_APPEND 0
#endif
#if defined(O_CREAT)
# define UV_FS_O_CREAT O_CREAT
#else
# define UV_FS_O_CREAT 0
#endif
#if defined(__linux__) && defined(__arm__)
# define UV_FS_O_DIRECT 0x10000
#elif defined(__linux__) && defined(__m68k__)
# define UV_FS_O_DIRECT 0x10000
#elif defined(__linux__) && defined(__mips__)
# define UV_FS_O_DIRECT 0x08000
#elif defined(__linux__) && defined(__powerpc__)
# define UV_FS_O_DIRECT 0x20000
#elif defined(__linux__) && defined(__s390x__)
# define UV_FS_O_DIRECT 0x04000
#elif defined(__linux__) && defined(__x86_64__)
# define UV_FS_O_DIRECT 0x04000
#elif defined(__linux__) && defined(__loongarch__)
# define UV_FS_O_DIRECT 0x04000
#elif defined(O_DIRECT)
# define UV_FS_O_DIRECT O_DIRECT
#else
# define UV_FS_O_DIRECT 0
#endif
#if defined(O_DIRECTORY)
# define UV_FS_O_DIRECTORY O_DIRECTORY
#else
# define UV_FS_O_DIRECTORY 0
#endif
#if defined(O_DSYNC)
# define UV_FS_O_DSYNC O_DSYNC
#else
# define UV_FS_O_DSYNC 0
#endif
#if defined(O_EXCL)
# define UV_FS_O_EXCL O_EXCL
#else
# define UV_FS_O_EXCL 0
#endif
#if defined(O_EXLOCK)
# define UV_FS_O_EXLOCK O_EXLOCK
#else
# define UV_FS_O_EXLOCK 0
#endif
#if defined(O_NOATIME)
# define UV_FS_O_NOATIME O_NOATIME
#else
# define UV_FS_O_NOATIME 0
#endif
#if defined(O_NOCTTY)
# define UV_FS_O_NOCTTY O_NOCTTY
#else
# define UV_FS_O_NOCTTY 0
#endif
#if defined(O_NOFOLLOW)
# define UV_FS_O_NOFOLLOW O_NOFOLLOW
#else
# define UV_FS_O_NOFOLLOW 0
#endif
#if defined(O_NONBLOCK)
# define UV_FS_O_NONBLOCK O_NONBLOCK
#else
# define UV_FS_O_NONBLOCK 0
#endif
#if defined(O_RDONLY)
# define UV_FS_O_RDONLY O_RDONLY
#else
# define UV_FS_O_RDONLY 0
#endif
#if defined(O_RDWR)
# define UV_FS_O_RDWR O_RDWR
#else
# define UV_FS_O_RDWR 0
#endif
#if defined(O_SYMLINK)
# define UV_FS_O_SYMLINK O_SYMLINK
#else
# define UV_FS_O_SYMLINK 0
#endif
#if defined(O_SYNC)
# define UV_FS_O_SYNC O_SYNC
#else
# define UV_FS_O_SYNC 0
#endif
#if defined(O_TRUNC)
# define UV_FS_O_TRUNC O_TRUNC
#else
# define UV_FS_O_TRUNC 0
#endif
#if defined(O_WRONLY)
# define UV_FS_O_WRONLY O_WRONLY
#else
# define UV_FS_O_WRONLY 0
#endif
/* fs open() flags supported on other platforms: */
#define UV_FS_O_FILEMAP 0
#define UV_FS_O_RANDOM 0
#define UV_FS_O_SHORT_LIVED 0
#define UV_FS_O_SEQUENTIAL 0
#define UV_FS_O_TEMPORARY 0
#endif /* UV_UNIX_H */