1e66f31c5Sopenharmony_ci/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2e66f31c5Sopenharmony_ci * 3e66f31c5Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 4e66f31c5Sopenharmony_ci * of this software and associated documentation files (the "Software"), to 5e66f31c5Sopenharmony_ci * deal in the Software without restriction, including without limitation the 6e66f31c5Sopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7e66f31c5Sopenharmony_ci * sell copies of the Software, and to permit persons to whom the Software is 8e66f31c5Sopenharmony_ci * furnished to do so, subject to the following conditions: 9e66f31c5Sopenharmony_ci * 10e66f31c5Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 11e66f31c5Sopenharmony_ci * all copies or substantial portions of the Software. 12e66f31c5Sopenharmony_ci * 13e66f31c5Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14e66f31c5Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15e66f31c5Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16e66f31c5Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17e66f31c5Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18e66f31c5Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19e66f31c5Sopenharmony_ci * IN THE SOFTWARE. 20e66f31c5Sopenharmony_ci */ 21e66f31c5Sopenharmony_ci 22e66f31c5Sopenharmony_ci#ifndef UV_UNIX_INTERNAL_H_ 23e66f31c5Sopenharmony_ci#define UV_UNIX_INTERNAL_H_ 24e66f31c5Sopenharmony_ci 25e66f31c5Sopenharmony_ci#include "uv-common.h" 26e66f31c5Sopenharmony_ci 27e66f31c5Sopenharmony_ci#include <assert.h> 28e66f31c5Sopenharmony_ci#include <limits.h> /* _POSIX_PATH_MAX, PATH_MAX */ 29e66f31c5Sopenharmony_ci#include <stdint.h> 30e66f31c5Sopenharmony_ci#include <stdlib.h> /* abort */ 31e66f31c5Sopenharmony_ci#include <string.h> /* strrchr */ 32e66f31c5Sopenharmony_ci#include <fcntl.h> /* O_CLOEXEC and O_NONBLOCK, if supported. */ 33e66f31c5Sopenharmony_ci#include <stdio.h> 34e66f31c5Sopenharmony_ci#include <errno.h> 35e66f31c5Sopenharmony_ci#include <sys/socket.h> 36e66f31c5Sopenharmony_ci#include <sys/stat.h> 37e66f31c5Sopenharmony_ci#include <sys/types.h> 38e66f31c5Sopenharmony_ci 39e66f31c5Sopenharmony_ci#ifdef USE_FFRT 40e66f31c5Sopenharmony_ci#include <sys/epoll.h> 41e66f31c5Sopenharmony_ci#endif 42e66f31c5Sopenharmony_ci 43e66f31c5Sopenharmony_ci#define UV_LOOP_MAGIC 0x100B100BU 44e66f31c5Sopenharmony_ci#define uv__msan_unpoison(p, n) \ 45e66f31c5Sopenharmony_ci do { \ 46e66f31c5Sopenharmony_ci (void) (p); \ 47e66f31c5Sopenharmony_ci (void) (n); \ 48e66f31c5Sopenharmony_ci } while (0) 49e66f31c5Sopenharmony_ci 50e66f31c5Sopenharmony_ci#if defined(__has_feature) 51e66f31c5Sopenharmony_ci# if __has_feature(memory_sanitizer) 52e66f31c5Sopenharmony_ci# include <sanitizer/msan_interface.h> 53e66f31c5Sopenharmony_ci# undef uv__msan_unpoison 54e66f31c5Sopenharmony_ci# define uv__msan_unpoison __msan_unpoison 55e66f31c5Sopenharmony_ci# endif 56e66f31c5Sopenharmony_ci#endif 57e66f31c5Sopenharmony_ci 58e66f31c5Sopenharmony_ci#if defined(__STRICT_ANSI__) 59e66f31c5Sopenharmony_ci# define inline __inline 60e66f31c5Sopenharmony_ci#endif 61e66f31c5Sopenharmony_ci 62e66f31c5Sopenharmony_ci#if defined(__MVS__) 63e66f31c5Sopenharmony_ci# include "os390-syscalls.h" 64e66f31c5Sopenharmony_ci#endif /* __MVS__ */ 65e66f31c5Sopenharmony_ci 66e66f31c5Sopenharmony_ci#if defined(__sun) 67e66f31c5Sopenharmony_ci# include <sys/port.h> 68e66f31c5Sopenharmony_ci# include <port.h> 69e66f31c5Sopenharmony_ci#endif /* __sun */ 70e66f31c5Sopenharmony_ci 71e66f31c5Sopenharmony_ci#if defined(_AIX) 72e66f31c5Sopenharmony_ci# define reqevents events 73e66f31c5Sopenharmony_ci# define rtnevents revents 74e66f31c5Sopenharmony_ci# include <sys/poll.h> 75e66f31c5Sopenharmony_ci#else 76e66f31c5Sopenharmony_ci# include <poll.h> 77e66f31c5Sopenharmony_ci#endif /* _AIX */ 78e66f31c5Sopenharmony_ci 79e66f31c5Sopenharmony_ci#if defined(__APPLE__) && !TARGET_OS_IPHONE 80e66f31c5Sopenharmony_ci# include <AvailabilityMacros.h> 81e66f31c5Sopenharmony_ci#endif 82e66f31c5Sopenharmony_ci 83e66f31c5Sopenharmony_ci/* 84e66f31c5Sopenharmony_ci * Define common detection for active Thread Sanitizer 85e66f31c5Sopenharmony_ci * - clang uses __has_feature(thread_sanitizer) 86e66f31c5Sopenharmony_ci * - gcc-7+ uses __SANITIZE_THREAD__ 87e66f31c5Sopenharmony_ci */ 88e66f31c5Sopenharmony_ci#if defined(__has_feature) 89e66f31c5Sopenharmony_ci# if __has_feature(thread_sanitizer) 90e66f31c5Sopenharmony_ci# define __SANITIZE_THREAD__ 1 91e66f31c5Sopenharmony_ci# endif 92e66f31c5Sopenharmony_ci#endif 93e66f31c5Sopenharmony_ci 94e66f31c5Sopenharmony_ci#if defined(PATH_MAX) 95e66f31c5Sopenharmony_ci# define UV__PATH_MAX PATH_MAX 96e66f31c5Sopenharmony_ci#else 97e66f31c5Sopenharmony_ci# define UV__PATH_MAX 8192 98e66f31c5Sopenharmony_ci#endif 99e66f31c5Sopenharmony_ci 100e66f31c5Sopenharmony_ciunion uv__sockaddr { 101e66f31c5Sopenharmony_ci struct sockaddr_in6 in6; 102e66f31c5Sopenharmony_ci struct sockaddr_in in; 103e66f31c5Sopenharmony_ci struct sockaddr addr; 104e66f31c5Sopenharmony_ci}; 105e66f31c5Sopenharmony_ci 106e66f31c5Sopenharmony_ci#define ACCESS_ONCE(type, var) \ 107e66f31c5Sopenharmony_ci (*(volatile type*) &(var)) 108e66f31c5Sopenharmony_ci 109e66f31c5Sopenharmony_ci#define ROUND_UP(a, b) \ 110e66f31c5Sopenharmony_ci ((a) % (b) ? ((a) + (b)) - ((a) % (b)) : (a)) 111e66f31c5Sopenharmony_ci 112e66f31c5Sopenharmony_ci#define UNREACHABLE() \ 113e66f31c5Sopenharmony_ci do { \ 114e66f31c5Sopenharmony_ci assert(0 && "unreachable code"); \ 115e66f31c5Sopenharmony_ci abort(); \ 116e66f31c5Sopenharmony_ci } \ 117e66f31c5Sopenharmony_ci while (0) 118e66f31c5Sopenharmony_ci 119e66f31c5Sopenharmony_ci#define SAVE_ERRNO(block) \ 120e66f31c5Sopenharmony_ci do { \ 121e66f31c5Sopenharmony_ci int _saved_errno = errno; \ 122e66f31c5Sopenharmony_ci do { block; } while (0); \ 123e66f31c5Sopenharmony_ci errno = _saved_errno; \ 124e66f31c5Sopenharmony_ci } \ 125e66f31c5Sopenharmony_ci while (0) 126e66f31c5Sopenharmony_ci 127e66f31c5Sopenharmony_ci/* The __clang__ and __INTEL_COMPILER checks are superfluous because they 128e66f31c5Sopenharmony_ci * define __GNUC__. They are here to convey to you, dear reader, that these 129e66f31c5Sopenharmony_ci * macros are enabled when compiling with clang or icc. 130e66f31c5Sopenharmony_ci */ 131e66f31c5Sopenharmony_ci#if defined(__clang__) || \ 132e66f31c5Sopenharmony_ci defined(__GNUC__) || \ 133e66f31c5Sopenharmony_ci defined(__INTEL_COMPILER) 134e66f31c5Sopenharmony_ci# define UV_UNUSED(declaration) __attribute__((unused)) declaration 135e66f31c5Sopenharmony_ci#else 136e66f31c5Sopenharmony_ci# define UV_UNUSED(declaration) declaration 137e66f31c5Sopenharmony_ci#endif 138e66f31c5Sopenharmony_ci 139e66f31c5Sopenharmony_ci/* Leans on the fact that, on Linux, POLLRDHUP == EPOLLRDHUP. */ 140e66f31c5Sopenharmony_ci#ifdef POLLRDHUP 141e66f31c5Sopenharmony_ci# define UV__POLLRDHUP POLLRDHUP 142e66f31c5Sopenharmony_ci#else 143e66f31c5Sopenharmony_ci# define UV__POLLRDHUP 0x2000 144e66f31c5Sopenharmony_ci#endif 145e66f31c5Sopenharmony_ci 146e66f31c5Sopenharmony_ci#ifdef POLLPRI 147e66f31c5Sopenharmony_ci# define UV__POLLPRI POLLPRI 148e66f31c5Sopenharmony_ci#else 149e66f31c5Sopenharmony_ci# define UV__POLLPRI 0 150e66f31c5Sopenharmony_ci#endif 151e66f31c5Sopenharmony_ci 152e66f31c5Sopenharmony_ci#if !defined(O_CLOEXEC) && defined(__FreeBSD__) 153e66f31c5Sopenharmony_ci/* 154e66f31c5Sopenharmony_ci * It may be that we are just missing `__POSIX_VISIBLE >= 200809`. 155e66f31c5Sopenharmony_ci * Try using fixed value const and give up, if it doesn't work 156e66f31c5Sopenharmony_ci */ 157e66f31c5Sopenharmony_ci# define O_CLOEXEC 0x00100000 158e66f31c5Sopenharmony_ci#endif 159e66f31c5Sopenharmony_ci 160e66f31c5Sopenharmony_citypedef struct uv__stream_queued_fds_s uv__stream_queued_fds_t; 161e66f31c5Sopenharmony_ci 162e66f31c5Sopenharmony_ci/* loop flags */ 163e66f31c5Sopenharmony_cienum { 164e66f31c5Sopenharmony_ci UV_LOOP_BLOCK_SIGPROF = 0x1, 165e66f31c5Sopenharmony_ci UV_LOOP_REAP_CHILDREN = 0x2 166e66f31c5Sopenharmony_ci}; 167e66f31c5Sopenharmony_ci 168e66f31c5Sopenharmony_ci/* flags of excluding ifaddr */ 169e66f31c5Sopenharmony_cienum { 170e66f31c5Sopenharmony_ci UV__EXCLUDE_IFPHYS, 171e66f31c5Sopenharmony_ci UV__EXCLUDE_IFADDR 172e66f31c5Sopenharmony_ci}; 173e66f31c5Sopenharmony_ci 174e66f31c5Sopenharmony_citypedef enum { 175e66f31c5Sopenharmony_ci UV_CLOCK_PRECISE = 0, /* Use the highest resolution clock available. */ 176e66f31c5Sopenharmony_ci UV_CLOCK_FAST = 1 /* Use the fastest clock with <= 1ms granularity. */ 177e66f31c5Sopenharmony_ci} uv_clocktype_t; 178e66f31c5Sopenharmony_ci 179e66f31c5Sopenharmony_cistruct uv__stream_queued_fds_s { 180e66f31c5Sopenharmony_ci unsigned int size; 181e66f31c5Sopenharmony_ci unsigned int offset; 182e66f31c5Sopenharmony_ci int fds[1]; 183e66f31c5Sopenharmony_ci}; 184e66f31c5Sopenharmony_ci 185e66f31c5Sopenharmony_ci#ifdef __linux__ 186e66f31c5Sopenharmony_cistruct uv__statx_timestamp { 187e66f31c5Sopenharmony_ci int64_t tv_sec; 188e66f31c5Sopenharmony_ci uint32_t tv_nsec; 189e66f31c5Sopenharmony_ci int32_t unused0; 190e66f31c5Sopenharmony_ci}; 191e66f31c5Sopenharmony_ci 192e66f31c5Sopenharmony_cistruct uv__statx { 193e66f31c5Sopenharmony_ci uint32_t stx_mask; 194e66f31c5Sopenharmony_ci uint32_t stx_blksize; 195e66f31c5Sopenharmony_ci uint64_t stx_attributes; 196e66f31c5Sopenharmony_ci uint32_t stx_nlink; 197e66f31c5Sopenharmony_ci uint32_t stx_uid; 198e66f31c5Sopenharmony_ci uint32_t stx_gid; 199e66f31c5Sopenharmony_ci uint16_t stx_mode; 200e66f31c5Sopenharmony_ci uint16_t unused0; 201e66f31c5Sopenharmony_ci uint64_t stx_ino; 202e66f31c5Sopenharmony_ci uint64_t stx_size; 203e66f31c5Sopenharmony_ci uint64_t stx_blocks; 204e66f31c5Sopenharmony_ci uint64_t stx_attributes_mask; 205e66f31c5Sopenharmony_ci struct uv__statx_timestamp stx_atime; 206e66f31c5Sopenharmony_ci struct uv__statx_timestamp stx_btime; 207e66f31c5Sopenharmony_ci struct uv__statx_timestamp stx_ctime; 208e66f31c5Sopenharmony_ci struct uv__statx_timestamp stx_mtime; 209e66f31c5Sopenharmony_ci uint32_t stx_rdev_major; 210e66f31c5Sopenharmony_ci uint32_t stx_rdev_minor; 211e66f31c5Sopenharmony_ci uint32_t stx_dev_major; 212e66f31c5Sopenharmony_ci uint32_t stx_dev_minor; 213e66f31c5Sopenharmony_ci uint64_t unused1[14]; 214e66f31c5Sopenharmony_ci}; 215e66f31c5Sopenharmony_ci#endif /* __linux__ */ 216e66f31c5Sopenharmony_ci 217e66f31c5Sopenharmony_ci#if defined(_AIX) || \ 218e66f31c5Sopenharmony_ci defined(__APPLE__) || \ 219e66f31c5Sopenharmony_ci defined(__DragonFly__) || \ 220e66f31c5Sopenharmony_ci defined(__FreeBSD__) || \ 221e66f31c5Sopenharmony_ci defined(__linux__) || \ 222e66f31c5Sopenharmony_ci defined(__OpenBSD__) || \ 223e66f31c5Sopenharmony_ci defined(__NetBSD__) 224e66f31c5Sopenharmony_ci#define uv__nonblock uv__nonblock_ioctl 225e66f31c5Sopenharmony_ci#define UV__NONBLOCK_IS_IOCTL 1 226e66f31c5Sopenharmony_ci#else 227e66f31c5Sopenharmony_ci#define uv__nonblock uv__nonblock_fcntl 228e66f31c5Sopenharmony_ci#define UV__NONBLOCK_IS_IOCTL 0 229e66f31c5Sopenharmony_ci#endif 230e66f31c5Sopenharmony_ci 231e66f31c5Sopenharmony_ci/* On Linux, uv__nonblock_fcntl() and uv__nonblock_ioctl() do not commute 232e66f31c5Sopenharmony_ci * when O_NDELAY is not equal to O_NONBLOCK. Case in point: linux/sparc32 233e66f31c5Sopenharmony_ci * and linux/sparc64, where O_NDELAY is O_NONBLOCK + another bit. 234e66f31c5Sopenharmony_ci * 235e66f31c5Sopenharmony_ci * Libuv uses uv__nonblock_fcntl() directly sometimes so ensure that it 236e66f31c5Sopenharmony_ci * commutes with uv__nonblock(). 237e66f31c5Sopenharmony_ci */ 238e66f31c5Sopenharmony_ci#if defined(__linux__) && O_NDELAY != O_NONBLOCK 239e66f31c5Sopenharmony_ci#undef uv__nonblock 240e66f31c5Sopenharmony_ci#define uv__nonblock uv__nonblock_fcntl 241e66f31c5Sopenharmony_ci#endif 242e66f31c5Sopenharmony_ci 243e66f31c5Sopenharmony_ci/* core */ 244e66f31c5Sopenharmony_ciint uv__cloexec(int fd, int set); 245e66f31c5Sopenharmony_ciint uv__nonblock_ioctl(int fd, int set); 246e66f31c5Sopenharmony_ciint uv__nonblock_fcntl(int fd, int set); 247e66f31c5Sopenharmony_ciint uv__close(int fd); /* preserves errno */ 248e66f31c5Sopenharmony_ciint uv__close_nocheckstdio(int fd); 249e66f31c5Sopenharmony_ciint uv__close_nocancel(int fd); 250e66f31c5Sopenharmony_ciint uv__socket(int domain, int type, int protocol); 251e66f31c5Sopenharmony_cissize_t uv__recvmsg(int fd, struct msghdr *msg, int flags); 252e66f31c5Sopenharmony_civoid uv__make_close_pending(uv_handle_t* handle); 253e66f31c5Sopenharmony_ciint uv__getiovmax(void); 254e66f31c5Sopenharmony_ci 255e66f31c5Sopenharmony_civoid uv__io_init(uv__io_t* w, uv__io_cb cb, int fd); 256e66f31c5Sopenharmony_civoid uv__io_start(uv_loop_t* loop, uv__io_t* w, unsigned int events); 257e66f31c5Sopenharmony_civoid uv__io_stop(uv_loop_t* loop, uv__io_t* w, unsigned int events); 258e66f31c5Sopenharmony_civoid uv__io_close(uv_loop_t* loop, uv__io_t* w); 259e66f31c5Sopenharmony_civoid uv__io_feed(uv_loop_t* loop, uv__io_t* w); 260e66f31c5Sopenharmony_ciint uv__io_active(const uv__io_t* w, unsigned int events); 261e66f31c5Sopenharmony_ciint uv__io_check_fd(uv_loop_t* loop, int fd); 262e66f31c5Sopenharmony_civoid uv__io_poll(uv_loop_t* loop, int timeout); /* in milliseconds or -1 */ 263e66f31c5Sopenharmony_ciint uv__io_fork(uv_loop_t* loop); 264e66f31c5Sopenharmony_ciint uv__fd_exists(uv_loop_t* loop, int fd); 265e66f31c5Sopenharmony_ci 266e66f31c5Sopenharmony_ci/* async */ 267e66f31c5Sopenharmony_civoid uv__async_stop(uv_loop_t* loop); 268e66f31c5Sopenharmony_ciint uv__async_fork(uv_loop_t* loop); 269e66f31c5Sopenharmony_ci 270e66f31c5Sopenharmony_ci#ifdef USE_FFRT 271e66f31c5Sopenharmony_ci/* epoll */ 272e66f31c5Sopenharmony_ciint uv__epoll_ctl(int epoll_fd, int op, int fd, struct epoll_event* event); 273e66f31c5Sopenharmony_ci#endif 274e66f31c5Sopenharmony_ci 275e66f31c5Sopenharmony_ci/* loop */ 276e66f31c5Sopenharmony_civoid uv__run_idle(uv_loop_t* loop); 277e66f31c5Sopenharmony_civoid uv__run_check(uv_loop_t* loop); 278e66f31c5Sopenharmony_civoid uv__run_prepare(uv_loop_t* loop); 279e66f31c5Sopenharmony_ci 280e66f31c5Sopenharmony_ci/* stream */ 281e66f31c5Sopenharmony_civoid uv__stream_init(uv_loop_t* loop, uv_stream_t* stream, 282e66f31c5Sopenharmony_ci uv_handle_type type); 283e66f31c5Sopenharmony_ciint uv__stream_open(uv_stream_t*, int fd, int flags); 284e66f31c5Sopenharmony_civoid uv__stream_destroy(uv_stream_t* stream); 285e66f31c5Sopenharmony_ci#if defined(__APPLE__) 286e66f31c5Sopenharmony_ciint uv__stream_try_select(uv_stream_t* stream, int* fd); 287e66f31c5Sopenharmony_ci#endif /* defined(__APPLE__) */ 288e66f31c5Sopenharmony_civoid uv__server_io(uv_loop_t* loop, uv__io_t* w, unsigned int events); 289e66f31c5Sopenharmony_ciint uv__accept(int sockfd); 290e66f31c5Sopenharmony_ciint uv__dup2_cloexec(int oldfd, int newfd); 291e66f31c5Sopenharmony_ciint uv__open_cloexec(const char* path, int flags); 292e66f31c5Sopenharmony_ciint uv__slurp(const char* filename, char* buf, size_t len); 293e66f31c5Sopenharmony_ci 294e66f31c5Sopenharmony_ci/* tcp */ 295e66f31c5Sopenharmony_ciint uv__tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb); 296e66f31c5Sopenharmony_ciint uv__tcp_nodelay(int fd, int on); 297e66f31c5Sopenharmony_ciint uv__tcp_keepalive(int fd, int on, unsigned int delay); 298e66f31c5Sopenharmony_ci 299e66f31c5Sopenharmony_ci/* pipe */ 300e66f31c5Sopenharmony_ciint uv__pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb); 301e66f31c5Sopenharmony_ci 302e66f31c5Sopenharmony_ci/* signal */ 303e66f31c5Sopenharmony_civoid uv__signal_close(uv_signal_t* handle); 304e66f31c5Sopenharmony_civoid uv__signal_global_once_init(void); 305e66f31c5Sopenharmony_civoid uv__signal_loop_cleanup(uv_loop_t* loop); 306e66f31c5Sopenharmony_ciint uv__signal_loop_fork(uv_loop_t* loop); 307e66f31c5Sopenharmony_ci 308e66f31c5Sopenharmony_ci/* platform specific */ 309e66f31c5Sopenharmony_ciuint64_t uv__hrtime(uv_clocktype_t type); 310e66f31c5Sopenharmony_ciint uv__kqueue_init(uv_loop_t* loop); 311e66f31c5Sopenharmony_ciint uv__platform_loop_init(uv_loop_t* loop); 312e66f31c5Sopenharmony_civoid uv__platform_loop_delete(uv_loop_t* loop); 313e66f31c5Sopenharmony_civoid uv__platform_invalidate_fd(uv_loop_t* loop, int fd); 314e66f31c5Sopenharmony_ciint uv__process_init(uv_loop_t* loop); 315e66f31c5Sopenharmony_ci 316e66f31c5Sopenharmony_ci/* various */ 317e66f31c5Sopenharmony_civoid uv__async_close(uv_async_t* handle); 318e66f31c5Sopenharmony_civoid uv__check_close(uv_check_t* handle); 319e66f31c5Sopenharmony_civoid uv__fs_event_close(uv_fs_event_t* handle); 320e66f31c5Sopenharmony_civoid uv__idle_close(uv_idle_t* handle); 321e66f31c5Sopenharmony_civoid uv__pipe_close(uv_pipe_t* handle); 322e66f31c5Sopenharmony_civoid uv__poll_close(uv_poll_t* handle); 323e66f31c5Sopenharmony_civoid uv__prepare_close(uv_prepare_t* handle); 324e66f31c5Sopenharmony_civoid uv__process_close(uv_process_t* handle); 325e66f31c5Sopenharmony_civoid uv__stream_close(uv_stream_t* handle); 326e66f31c5Sopenharmony_civoid uv__tcp_close(uv_tcp_t* handle); 327e66f31c5Sopenharmony_cisize_t uv__thread_stack_size(void); 328e66f31c5Sopenharmony_civoid uv__udp_close(uv_udp_t* handle); 329e66f31c5Sopenharmony_civoid uv__udp_finish_close(uv_udp_t* handle); 330e66f31c5Sopenharmony_ciFILE* uv__open_file(const char* path); 331e66f31c5Sopenharmony_ciint uv__search_path(const char* prog, char* buf, size_t* buflen); 332e66f31c5Sopenharmony_civoid uv__wait_children(uv_loop_t* loop); 333e66f31c5Sopenharmony_ci 334e66f31c5Sopenharmony_ci/* random */ 335e66f31c5Sopenharmony_ciint uv__random_devurandom(void* buf, size_t buflen); 336e66f31c5Sopenharmony_ciint uv__random_getrandom(void* buf, size_t buflen); 337e66f31c5Sopenharmony_ciint uv__random_getentropy(void* buf, size_t buflen); 338e66f31c5Sopenharmony_ciint uv__random_readpath(const char* path, void* buf, size_t buflen); 339e66f31c5Sopenharmony_ciint uv__random_sysctl(void* buf, size_t buflen); 340e66f31c5Sopenharmony_ci 341e66f31c5Sopenharmony_ci/* io_uring */ 342e66f31c5Sopenharmony_ci#ifdef __linux__ 343e66f31c5Sopenharmony_ciint uv__iou_fs_close(uv_loop_t* loop, uv_fs_t* req); 344e66f31c5Sopenharmony_ciint uv__iou_fs_fsync_or_fdatasync(uv_loop_t* loop, 345e66f31c5Sopenharmony_ci uv_fs_t* req, 346e66f31c5Sopenharmony_ci uint32_t fsync_flags); 347e66f31c5Sopenharmony_ciint uv__iou_fs_link(uv_loop_t* loop, uv_fs_t* req); 348e66f31c5Sopenharmony_ciint uv__iou_fs_mkdir(uv_loop_t* loop, uv_fs_t* req); 349e66f31c5Sopenharmony_ciint uv__iou_fs_open(uv_loop_t* loop, uv_fs_t* req); 350e66f31c5Sopenharmony_ciint uv__iou_fs_read_or_write(uv_loop_t* loop, 351e66f31c5Sopenharmony_ci uv_fs_t* req, 352e66f31c5Sopenharmony_ci int is_read); 353e66f31c5Sopenharmony_ciint uv__iou_fs_rename(uv_loop_t* loop, uv_fs_t* req); 354e66f31c5Sopenharmony_ciint uv__iou_fs_statx(uv_loop_t* loop, 355e66f31c5Sopenharmony_ci uv_fs_t* req, 356e66f31c5Sopenharmony_ci int is_fstat, 357e66f31c5Sopenharmony_ci int is_lstat); 358e66f31c5Sopenharmony_ciint uv__iou_fs_symlink(uv_loop_t* loop, uv_fs_t* req); 359e66f31c5Sopenharmony_ciint uv__iou_fs_unlink(uv_loop_t* loop, uv_fs_t* req); 360e66f31c5Sopenharmony_ci#else 361e66f31c5Sopenharmony_ci#define uv__iou_fs_close(loop, req) 0 362e66f31c5Sopenharmony_ci#define uv__iou_fs_fsync_or_fdatasync(loop, req, fsync_flags) 0 363e66f31c5Sopenharmony_ci#define uv__iou_fs_link(loop, req) 0 364e66f31c5Sopenharmony_ci#define uv__iou_fs_mkdir(loop, req) 0 365e66f31c5Sopenharmony_ci#define uv__iou_fs_open(loop, req) 0 366e66f31c5Sopenharmony_ci#define uv__iou_fs_read_or_write(loop, req, is_read) 0 367e66f31c5Sopenharmony_ci#define uv__iou_fs_rename(loop, req) 0 368e66f31c5Sopenharmony_ci#define uv__iou_fs_statx(loop, req, is_fstat, is_lstat) 0 369e66f31c5Sopenharmony_ci#define uv__iou_fs_symlink(loop, req) 0 370e66f31c5Sopenharmony_ci#define uv__iou_fs_unlink(loop, req) 0 371e66f31c5Sopenharmony_ci#endif 372e66f31c5Sopenharmony_ci 373e66f31c5Sopenharmony_ci#if defined(__APPLE__) 374e66f31c5Sopenharmony_ciint uv___stream_fd(const uv_stream_t* handle); 375e66f31c5Sopenharmony_ci#define uv__stream_fd(handle) (uv___stream_fd((const uv_stream_t*) (handle))) 376e66f31c5Sopenharmony_ci#else 377e66f31c5Sopenharmony_ci#define uv__stream_fd(handle) ((handle)->io_watcher.fd) 378e66f31c5Sopenharmony_ci#endif /* defined(__APPLE__) */ 379e66f31c5Sopenharmony_ci 380e66f31c5Sopenharmony_ciint uv__make_pipe(int fds[2], int flags); 381e66f31c5Sopenharmony_ci 382e66f31c5Sopenharmony_ci#if defined(__APPLE__) 383e66f31c5Sopenharmony_ci 384e66f31c5Sopenharmony_ciint uv__fsevents_init(uv_fs_event_t* handle); 385e66f31c5Sopenharmony_ciint uv__fsevents_close(uv_fs_event_t* handle); 386e66f31c5Sopenharmony_civoid uv__fsevents_loop_delete(uv_loop_t* loop); 387e66f31c5Sopenharmony_ci 388e66f31c5Sopenharmony_ci#endif /* defined(__APPLE__) */ 389e66f31c5Sopenharmony_ci 390e66f31c5Sopenharmony_ciUV_UNUSED(static void uv__update_time(uv_loop_t* loop)) { 391e66f31c5Sopenharmony_ci /* Use a fast time source if available. We only need millisecond precision. 392e66f31c5Sopenharmony_ci */ 393e66f31c5Sopenharmony_ci loop->time = uv__hrtime(UV_CLOCK_FAST) / 1000000; 394e66f31c5Sopenharmony_ci} 395e66f31c5Sopenharmony_ci 396e66f31c5Sopenharmony_ciUV_UNUSED(static char* uv__basename_r(const char* path)) { 397e66f31c5Sopenharmony_ci char* s; 398e66f31c5Sopenharmony_ci 399e66f31c5Sopenharmony_ci s = strrchr(path, '/'); 400e66f31c5Sopenharmony_ci if (s == NULL) 401e66f31c5Sopenharmony_ci return (char*) path; 402e66f31c5Sopenharmony_ci 403e66f31c5Sopenharmony_ci return s + 1; 404e66f31c5Sopenharmony_ci} 405e66f31c5Sopenharmony_ci 406e66f31c5Sopenharmony_ciUV_UNUSED(static int uv__fstat(int fd, struct stat* s)) { 407e66f31c5Sopenharmony_ci int rc; 408e66f31c5Sopenharmony_ci 409e66f31c5Sopenharmony_ci rc = fstat(fd, s); 410e66f31c5Sopenharmony_ci if (rc >= 0) 411e66f31c5Sopenharmony_ci uv__msan_unpoison(s, sizeof(*s)); 412e66f31c5Sopenharmony_ci 413e66f31c5Sopenharmony_ci return rc; 414e66f31c5Sopenharmony_ci} 415e66f31c5Sopenharmony_ci 416e66f31c5Sopenharmony_ciUV_UNUSED(static int uv__lstat(const char* path, struct stat* s)) { 417e66f31c5Sopenharmony_ci int rc; 418e66f31c5Sopenharmony_ci 419e66f31c5Sopenharmony_ci rc = lstat(path, s); 420e66f31c5Sopenharmony_ci if (rc >= 0) 421e66f31c5Sopenharmony_ci uv__msan_unpoison(s, sizeof(*s)); 422e66f31c5Sopenharmony_ci 423e66f31c5Sopenharmony_ci return rc; 424e66f31c5Sopenharmony_ci} 425e66f31c5Sopenharmony_ci 426e66f31c5Sopenharmony_ciUV_UNUSED(static int uv__stat(const char* path, struct stat* s)) { 427e66f31c5Sopenharmony_ci int rc; 428e66f31c5Sopenharmony_ci 429e66f31c5Sopenharmony_ci rc = stat(path, s); 430e66f31c5Sopenharmony_ci if (rc >= 0) 431e66f31c5Sopenharmony_ci uv__msan_unpoison(s, sizeof(*s)); 432e66f31c5Sopenharmony_ci 433e66f31c5Sopenharmony_ci return rc; 434e66f31c5Sopenharmony_ci} 435e66f31c5Sopenharmony_ci 436e66f31c5Sopenharmony_ci#if defined(__linux__) 437e66f31c5Sopenharmony_civoid uv__fs_post(uv_loop_t* loop, uv_fs_t* req); 438e66f31c5Sopenharmony_cissize_t 439e66f31c5Sopenharmony_ciuv__fs_copy_file_range(int fd_in, 440e66f31c5Sopenharmony_ci off_t* off_in, 441e66f31c5Sopenharmony_ci int fd_out, 442e66f31c5Sopenharmony_ci off_t* off_out, 443e66f31c5Sopenharmony_ci size_t len, 444e66f31c5Sopenharmony_ci unsigned int flags); 445e66f31c5Sopenharmony_ciint uv__statx(int dirfd, 446e66f31c5Sopenharmony_ci const char* path, 447e66f31c5Sopenharmony_ci int flags, 448e66f31c5Sopenharmony_ci unsigned int mask, 449e66f31c5Sopenharmony_ci struct uv__statx* statxbuf); 450e66f31c5Sopenharmony_civoid uv__statx_to_stat(const struct uv__statx* statxbuf, uv_stat_t* buf); 451e66f31c5Sopenharmony_cissize_t uv__getrandom(void* buf, size_t buflen, unsigned flags); 452e66f31c5Sopenharmony_ciunsigned uv__kernel_version(void); 453e66f31c5Sopenharmony_ci#endif 454e66f31c5Sopenharmony_ci 455e66f31c5Sopenharmony_citypedef int (*uv__peersockfunc)(int, struct sockaddr*, socklen_t*); 456e66f31c5Sopenharmony_ci 457e66f31c5Sopenharmony_ciint uv__getsockpeername(const uv_handle_t* handle, 458e66f31c5Sopenharmony_ci uv__peersockfunc func, 459e66f31c5Sopenharmony_ci struct sockaddr* name, 460e66f31c5Sopenharmony_ci int* namelen); 461e66f31c5Sopenharmony_ci 462e66f31c5Sopenharmony_ci#if defined(__sun) 463e66f31c5Sopenharmony_ci#if !defined(_POSIX_VERSION) || _POSIX_VERSION < 200809L 464e66f31c5Sopenharmony_cisize_t strnlen(const char* s, size_t maxlen); 465e66f31c5Sopenharmony_ci#endif 466e66f31c5Sopenharmony_ci#endif 467e66f31c5Sopenharmony_ci 468e66f31c5Sopenharmony_ci#if defined(__FreeBSD__) 469e66f31c5Sopenharmony_cissize_t 470e66f31c5Sopenharmony_ciuv__fs_copy_file_range(int fd_in, 471e66f31c5Sopenharmony_ci off_t* off_in, 472e66f31c5Sopenharmony_ci int fd_out, 473e66f31c5Sopenharmony_ci off_t* off_out, 474e66f31c5Sopenharmony_ci size_t len, 475e66f31c5Sopenharmony_ci unsigned int flags); 476e66f31c5Sopenharmony_ci#endif 477e66f31c5Sopenharmony_ci 478e66f31c5Sopenharmony_ci#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 1301000) 479e66f31c5Sopenharmony_ci#define UV__CPU_AFFINITY_SUPPORTED 1 480e66f31c5Sopenharmony_ci#else 481e66f31c5Sopenharmony_ci#define UV__CPU_AFFINITY_SUPPORTED 0 482e66f31c5Sopenharmony_ci#endif 483e66f31c5Sopenharmony_ci 484e66f31c5Sopenharmony_ciUV_UNUSED(static unsigned int self_increase(unsigned int* ptr)) { 485e66f31c5Sopenharmony_ci return __sync_fetch_and_add(ptr, 1); 486e66f31c5Sopenharmony_ci} 487e66f31c5Sopenharmony_ci 488e66f31c5Sopenharmony_ciUV_UNUSED(static unsigned int self_decrease(unsigned int* ptr)) { 489e66f31c5Sopenharmony_ci return __sync_fetch_and_sub(ptr, 1); 490e66f31c5Sopenharmony_ci} 491e66f31c5Sopenharmony_ci#endif /* UV_UNIX_INTERNAL_H_ */ 492