Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:26

0001 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
0002  *
0003  * Permission is hereby granted, free of charge, to any person obtaining a copy
0004  * of this software and associated documentation files (the "Software"), to
0005  * deal in the Software without restriction, including without limitation the
0006  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
0007  * sell copies of the Software, and to permit persons to whom the Software is
0008  * furnished to do so, subject to the following conditions:
0009  *
0010  * The above copyright notice and this permission notice shall be included in
0011  * all copies or substantial portions of the Software.
0012  *
0013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0014  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0015  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0016  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0017  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0018  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
0019  * IN THE SOFTWARE.
0020  */
0021 
0022 #ifndef UV_UNIX_H
0023 #define UV_UNIX_H
0024 
0025 #include <sys/types.h>
0026 #include <sys/stat.h>
0027 #include <fcntl.h>
0028 #include <dirent.h>
0029 
0030 #include <sys/socket.h>
0031 #include <netinet/in.h>
0032 #include <netinet/tcp.h>
0033 #include <arpa/inet.h>
0034 #include <netdb.h>  /* MAXHOSTNAMELEN on Solaris */
0035 
0036 #include <termios.h>
0037 #include <pwd.h>
0038 
0039 #if !defined(__MVS__)
0040 #include <semaphore.h>
0041 #include <sys/param.h> /* MAXHOSTNAMELEN on Linux and the BSDs */
0042 #endif
0043 #include <pthread.h>
0044 #include <signal.h>
0045 
0046 #include "uv/threadpool.h"
0047 
0048 #if defined(__linux__)
0049 # include "uv/linux.h"
0050 #elif defined (__MVS__)
0051 # include "uv/os390.h"
0052 #elif defined(__PASE__)  /* __PASE__ and _AIX are both defined on IBM i */
0053 # include "uv/posix.h"  /* IBM i needs uv/posix.h, not uv/aix.h */
0054 #elif defined(_AIX)
0055 # include "uv/aix.h"
0056 #elif defined(__sun)
0057 # include "uv/sunos.h"
0058 #elif defined(__APPLE__)
0059 # include "uv/darwin.h"
0060 #elif defined(__DragonFly__)       || \
0061       defined(__FreeBSD__)         || \
0062       defined(__OpenBSD__)         || \
0063       defined(__NetBSD__)
0064 # include "uv/bsd.h"
0065 #elif defined(__CYGWIN__) || \
0066       defined(__MSYS__)   || \
0067       defined(__HAIKU__)  || \
0068       defined(__QNX__)    || \
0069       defined(__GNU__)
0070 # include "uv/posix.h"
0071 #endif
0072 
0073 #ifndef NI_MAXHOST
0074 # define NI_MAXHOST 1025
0075 #endif
0076 
0077 #ifndef NI_MAXSERV
0078 # define NI_MAXSERV 32
0079 #endif
0080 
0081 #ifndef UV_IO_PRIVATE_PLATFORM_FIELDS
0082 # define UV_IO_PRIVATE_PLATFORM_FIELDS /* empty */
0083 #endif
0084 
0085 struct uv__io_s;
0086 struct uv_loop_s;
0087 
0088 typedef void (*uv__io_cb)(struct uv_loop_s* loop,
0089                           struct uv__io_s* w,
0090                           unsigned int events);
0091 typedef struct uv__io_s uv__io_t;
0092 
0093 struct uv__io_s {
0094   uv__io_cb cb;
0095   struct uv__queue pending_queue;
0096   struct uv__queue watcher_queue;
0097   unsigned int pevents; /* Pending event mask i.e. mask at next tick. */
0098   unsigned int events;  /* Current event mask. */
0099   int fd;
0100   UV_IO_PRIVATE_PLATFORM_FIELDS
0101 };
0102 
0103 #ifndef UV_PLATFORM_SEM_T
0104 # define UV_PLATFORM_SEM_T sem_t
0105 #endif
0106 
0107 #ifndef UV_PLATFORM_LOOP_FIELDS
0108 # define UV_PLATFORM_LOOP_FIELDS /* empty */
0109 #endif
0110 
0111 #ifndef UV_PLATFORM_FS_EVENT_FIELDS
0112 # define UV_PLATFORM_FS_EVENT_FIELDS /* empty */
0113 #endif
0114 
0115 #ifndef UV_STREAM_PRIVATE_PLATFORM_FIELDS
0116 # define UV_STREAM_PRIVATE_PLATFORM_FIELDS /* empty */
0117 #endif
0118 
0119 /* Note: May be cast to struct iovec. See writev(2). */
0120 typedef struct uv_buf_t {
0121   char* base;
0122   size_t len;
0123 } uv_buf_t;
0124 
0125 typedef int uv_file;
0126 typedef int uv_os_sock_t;
0127 typedef int uv_os_fd_t;
0128 typedef pid_t uv_pid_t;
0129 
0130 #define UV_ONCE_INIT PTHREAD_ONCE_INIT
0131 
0132 typedef pthread_once_t uv_once_t;
0133 typedef pthread_t uv_thread_t;
0134 typedef pthread_mutex_t uv_mutex_t;
0135 typedef pthread_rwlock_t uv_rwlock_t;
0136 typedef UV_PLATFORM_SEM_T uv_sem_t;
0137 typedef pthread_cond_t uv_cond_t;
0138 typedef pthread_key_t uv_key_t;
0139 
0140 /* Note: guard clauses should match uv_barrier_init's in src/unix/thread.c. */
0141 #if defined(_AIX) || \
0142     defined(__OpenBSD__) || \
0143     !defined(PTHREAD_BARRIER_SERIAL_THREAD)
0144 /* TODO(bnoordhuis) Merge into uv_barrier_t in v2. */
0145 struct _uv_barrier {
0146   uv_mutex_t mutex;
0147   uv_cond_t cond;
0148   unsigned threshold;
0149   unsigned in;
0150   unsigned out;
0151 };
0152 
0153 typedef struct {
0154   struct _uv_barrier* b;
0155 # if defined(PTHREAD_BARRIER_SERIAL_THREAD)
0156   /* TODO(bnoordhuis) Remove padding in v2. */
0157   char pad[sizeof(pthread_barrier_t) - sizeof(struct _uv_barrier*)];
0158 # endif
0159 } uv_barrier_t;
0160 #else
0161 typedef pthread_barrier_t uv_barrier_t;
0162 #endif
0163 
0164 /* Platform-specific definitions for uv_spawn support. */
0165 typedef gid_t uv_gid_t;
0166 typedef uid_t uv_uid_t;
0167 
0168 typedef struct dirent uv__dirent_t;
0169 
0170 #define UV_DIR_PRIVATE_FIELDS \
0171   DIR* dir;
0172 
0173 #if defined(DT_UNKNOWN)
0174 # define HAVE_DIRENT_TYPES
0175 # if defined(DT_REG)
0176 #  define UV__DT_FILE DT_REG
0177 # else
0178 #  define UV__DT_FILE -1
0179 # endif
0180 # if defined(DT_DIR)
0181 #  define UV__DT_DIR DT_DIR
0182 # else
0183 #  define UV__DT_DIR -2
0184 # endif
0185 # if defined(DT_LNK)
0186 #  define UV__DT_LINK DT_LNK
0187 # else
0188 #  define UV__DT_LINK -3
0189 # endif
0190 # if defined(DT_FIFO)
0191 #  define UV__DT_FIFO DT_FIFO
0192 # else
0193 #  define UV__DT_FIFO -4
0194 # endif
0195 # if defined(DT_SOCK)
0196 #  define UV__DT_SOCKET DT_SOCK
0197 # else
0198 #  define UV__DT_SOCKET -5
0199 # endif
0200 # if defined(DT_CHR)
0201 #  define UV__DT_CHAR DT_CHR
0202 # else
0203 #  define UV__DT_CHAR -6
0204 # endif
0205 # if defined(DT_BLK)
0206 #  define UV__DT_BLOCK DT_BLK
0207 # else
0208 #  define UV__DT_BLOCK -7
0209 # endif
0210 #endif
0211 
0212 /* Platform-specific definitions for uv_dlopen support. */
0213 #define UV_DYNAMIC /* empty */
0214 
0215 typedef struct {
0216   void* handle;
0217   char* errmsg;
0218 } uv_lib_t;
0219 
0220 #define UV_LOOP_PRIVATE_FIELDS                                                \
0221   unsigned long flags;                                                        \
0222   int backend_fd;                                                             \
0223   struct uv__queue pending_queue;                                             \
0224   struct uv__queue watcher_queue;                                             \
0225   uv__io_t** watchers;                                                        \
0226   unsigned int nwatchers;                                                     \
0227   unsigned int nfds;                                                          \
0228   struct uv__queue wq;                                                        \
0229   uv_mutex_t wq_mutex;                                                        \
0230   uv_async_t wq_async;                                                        \
0231   uv_rwlock_t cloexec_lock;                                                   \
0232   uv_handle_t* closing_handles;                                               \
0233   struct uv__queue process_handles;                                           \
0234   struct uv__queue prepare_handles;                                           \
0235   struct uv__queue check_handles;                                             \
0236   struct uv__queue idle_handles;                                              \
0237   struct uv__queue async_handles;                                             \
0238   void (*async_unused)(void);  /* TODO(bnoordhuis) Remove in libuv v2. */     \
0239   uv__io_t async_io_watcher;                                                  \
0240   int async_wfd;                                                              \
0241   struct {                                                                    \
0242     void* min;                                                                \
0243     unsigned int nelts;                                                       \
0244   } timer_heap;                                                               \
0245   uint64_t timer_counter;                                                     \
0246   uint64_t time;                                                              \
0247   int signal_pipefd[2];                                                       \
0248   uv__io_t signal_io_watcher;                                                 \
0249   uv_signal_t child_watcher;                                                  \
0250   int emfile_fd;                                                              \
0251   UV_PLATFORM_LOOP_FIELDS                                                     \
0252 
0253 #define UV_REQ_TYPE_PRIVATE /* empty */
0254 
0255 #define UV_REQ_PRIVATE_FIELDS  /* empty */
0256 
0257 #define UV_PRIVATE_REQ_TYPES /* empty */
0258 
0259 #define UV_WRITE_PRIVATE_FIELDS                                               \
0260   struct uv__queue queue;                                                     \
0261   unsigned int write_index;                                                   \
0262   uv_buf_t* bufs;                                                             \
0263   unsigned int nbufs;                                                         \
0264   int error;                                                                  \
0265   uv_buf_t bufsml[4];                                                         \
0266 
0267 #define UV_CONNECT_PRIVATE_FIELDS                                             \
0268   struct uv__queue queue;                                                     \
0269 
0270 #define UV_SHUTDOWN_PRIVATE_FIELDS /* empty */
0271 
0272 #define UV_UDP_SEND_PRIVATE_FIELDS                                            \
0273   struct uv__queue queue;                                                     \
0274   struct sockaddr_storage addr;                                               \
0275   unsigned int nbufs;                                                         \
0276   uv_buf_t* bufs;                                                             \
0277   ssize_t status;                                                             \
0278   uv_udp_send_cb send_cb;                                                     \
0279   uv_buf_t bufsml[4];                                                         \
0280 
0281 #define UV_HANDLE_PRIVATE_FIELDS                                              \
0282   uv_handle_t* next_closing;                                                  \
0283   unsigned int flags;                                                         \
0284 
0285 #define UV_STREAM_PRIVATE_FIELDS                                              \
0286   uv_connect_t *connect_req;                                                  \
0287   uv_shutdown_t *shutdown_req;                                                \
0288   uv__io_t io_watcher;                                                        \
0289   struct uv__queue write_queue;                                               \
0290   struct uv__queue write_completed_queue;                                     \
0291   uv_connection_cb connection_cb;                                             \
0292   int delayed_error;                                                          \
0293   int accepted_fd;                                                            \
0294   void* queued_fds;                                                           \
0295   UV_STREAM_PRIVATE_PLATFORM_FIELDS                                           \
0296 
0297 #define UV_TCP_PRIVATE_FIELDS /* empty */
0298 
0299 #define UV_UDP_PRIVATE_FIELDS                                                 \
0300   uv_alloc_cb alloc_cb;                                                       \
0301   uv_udp_recv_cb recv_cb;                                                     \
0302   uv__io_t io_watcher;                                                        \
0303   struct uv__queue write_queue;                                               \
0304   struct uv__queue write_completed_queue;                                     \
0305 
0306 #define UV_PIPE_PRIVATE_FIELDS                                                \
0307   const char* pipe_fname; /* NULL or strdup'ed */
0308 
0309 #define UV_POLL_PRIVATE_FIELDS                                                \
0310   uv__io_t io_watcher;
0311 
0312 #define UV_PREPARE_PRIVATE_FIELDS                                             \
0313   uv_prepare_cb prepare_cb;                                                   \
0314   struct uv__queue queue;                                                     \
0315 
0316 #define UV_CHECK_PRIVATE_FIELDS                                               \
0317   uv_check_cb check_cb;                                                       \
0318   struct uv__queue queue;                                                     \
0319 
0320 #define UV_IDLE_PRIVATE_FIELDS                                                \
0321   uv_idle_cb idle_cb;                                                         \
0322   struct uv__queue queue;                                                     \
0323 
0324 #define UV_ASYNC_PRIVATE_FIELDS                                               \
0325   uv_async_cb async_cb;                                                       \
0326   struct uv__queue queue;                                                     \
0327   int pending;                                                                \
0328 
0329 #define UV_TIMER_PRIVATE_FIELDS                                               \
0330   uv_timer_cb timer_cb;                                                       \
0331   union {                                                                     \
0332     void* heap[3];                                                            \
0333     struct uv__queue queue;                                                   \
0334   } node;                                                                     \
0335   uint64_t timeout;                                                           \
0336   uint64_t repeat;                                                            \
0337   uint64_t start_id;
0338 
0339 #define UV_GETADDRINFO_PRIVATE_FIELDS                                         \
0340   struct uv__work work_req;                                                   \
0341   uv_getaddrinfo_cb cb;                                                       \
0342   struct addrinfo* hints;                                                     \
0343   char* hostname;                                                             \
0344   char* service;                                                              \
0345   struct addrinfo* addrinfo;                                                  \
0346   int retcode;
0347 
0348 #define UV_GETNAMEINFO_PRIVATE_FIELDS                                         \
0349   struct uv__work work_req;                                                   \
0350   uv_getnameinfo_cb getnameinfo_cb;                                           \
0351   struct sockaddr_storage storage;                                            \
0352   int flags;                                                                  \
0353   char host[NI_MAXHOST];                                                      \
0354   char service[NI_MAXSERV];                                                   \
0355   int retcode;
0356 
0357 #define UV_PROCESS_PRIVATE_FIELDS                                             \
0358   struct uv__queue queue;                                                     \
0359   int status;                                                                 \
0360 
0361 #define UV_FS_PRIVATE_FIELDS                                                  \
0362   const char *new_path;                                                       \
0363   uv_file file;                                                               \
0364   int flags;                                                                  \
0365   mode_t mode;                                                                \
0366   unsigned int nbufs;                                                         \
0367   uv_buf_t* bufs;                                                             \
0368   off_t off;                                                                  \
0369   uv_uid_t uid;                                                               \
0370   uv_gid_t gid;                                                               \
0371   double atime;                                                               \
0372   double mtime;                                                               \
0373   struct uv__work work_req;                                                   \
0374   uv_buf_t bufsml[4];                                                         \
0375 
0376 #define UV_WORK_PRIVATE_FIELDS                                                \
0377   struct uv__work work_req;
0378 
0379 #define UV_TTY_PRIVATE_FIELDS                                                 \
0380   struct termios orig_termios;                                                \
0381   int mode;
0382 
0383 #define UV_SIGNAL_PRIVATE_FIELDS                                              \
0384   /* RB_ENTRY(uv_signal_s) tree_entry; */                                     \
0385   struct {                                                                    \
0386     struct uv_signal_s* rbe_left;                                             \
0387     struct uv_signal_s* rbe_right;                                            \
0388     struct uv_signal_s* rbe_parent;                                           \
0389     int rbe_color;                                                            \
0390   } tree_entry;                                                               \
0391   /* Use two counters here so we don have to fiddle with atomics. */          \
0392   unsigned int caught_signals;                                                \
0393   unsigned int dispatched_signals;
0394 
0395 #define UV_FS_EVENT_PRIVATE_FIELDS                                            \
0396   uv_fs_event_cb cb;                                                          \
0397   UV_PLATFORM_FS_EVENT_FIELDS                                                 \
0398 
0399 /* fs open() flags supported on this platform: */
0400 #if defined(O_APPEND)
0401 # define UV_FS_O_APPEND       O_APPEND
0402 #else
0403 # define UV_FS_O_APPEND       0
0404 #endif
0405 #if defined(O_CREAT)
0406 # define UV_FS_O_CREAT        O_CREAT
0407 #else
0408 # define UV_FS_O_CREAT        0
0409 #endif
0410 
0411 #if defined(__linux__) && defined(__arm__)
0412 # define UV_FS_O_DIRECT       0x10000
0413 #elif defined(__linux__) && defined(__m68k__)
0414 # define UV_FS_O_DIRECT       0x10000
0415 #elif defined(__linux__) && defined(__mips__)
0416 # define UV_FS_O_DIRECT       0x08000
0417 #elif defined(__linux__) && defined(__powerpc__)
0418 # define UV_FS_O_DIRECT       0x20000
0419 #elif defined(__linux__) && defined(__s390x__)
0420 # define UV_FS_O_DIRECT       0x04000
0421 #elif defined(__linux__) && defined(__x86_64__)
0422 # define UV_FS_O_DIRECT       0x04000
0423 #elif defined(__linux__) && defined(__loongarch__)
0424 # define UV_FS_O_DIRECT       0x04000
0425 #elif defined(O_DIRECT)
0426 # define UV_FS_O_DIRECT       O_DIRECT
0427 #else
0428 # define UV_FS_O_DIRECT       0
0429 #endif
0430 
0431 #if defined(O_DIRECTORY)
0432 # define UV_FS_O_DIRECTORY    O_DIRECTORY
0433 #else
0434 # define UV_FS_O_DIRECTORY    0
0435 #endif
0436 #if defined(O_DSYNC)
0437 # define UV_FS_O_DSYNC        O_DSYNC
0438 #else
0439 # define UV_FS_O_DSYNC        0
0440 #endif
0441 #if defined(O_EXCL)
0442 # define UV_FS_O_EXCL         O_EXCL
0443 #else
0444 # define UV_FS_O_EXCL         0
0445 #endif
0446 #if defined(O_EXLOCK)
0447 # define UV_FS_O_EXLOCK       O_EXLOCK
0448 #else
0449 # define UV_FS_O_EXLOCK       0
0450 #endif
0451 #if defined(O_NOATIME)
0452 # define UV_FS_O_NOATIME      O_NOATIME
0453 #else
0454 # define UV_FS_O_NOATIME      0
0455 #endif
0456 #if defined(O_NOCTTY)
0457 # define UV_FS_O_NOCTTY       O_NOCTTY
0458 #else
0459 # define UV_FS_O_NOCTTY       0
0460 #endif
0461 #if defined(O_NOFOLLOW)
0462 # define UV_FS_O_NOFOLLOW     O_NOFOLLOW
0463 #else
0464 # define UV_FS_O_NOFOLLOW     0
0465 #endif
0466 #if defined(O_NONBLOCK)
0467 # define UV_FS_O_NONBLOCK     O_NONBLOCK
0468 #else
0469 # define UV_FS_O_NONBLOCK     0
0470 #endif
0471 #if defined(O_RDONLY)
0472 # define UV_FS_O_RDONLY       O_RDONLY
0473 #else
0474 # define UV_FS_O_RDONLY       0
0475 #endif
0476 #if defined(O_RDWR)
0477 # define UV_FS_O_RDWR         O_RDWR
0478 #else
0479 # define UV_FS_O_RDWR         0
0480 #endif
0481 #if defined(O_SYMLINK)
0482 # define UV_FS_O_SYMLINK      O_SYMLINK
0483 #else
0484 # define UV_FS_O_SYMLINK      0
0485 #endif
0486 #if defined(O_SYNC)
0487 # define UV_FS_O_SYNC         O_SYNC
0488 #else
0489 # define UV_FS_O_SYNC         0
0490 #endif
0491 #if defined(O_TRUNC)
0492 # define UV_FS_O_TRUNC        O_TRUNC
0493 #else
0494 # define UV_FS_O_TRUNC        0
0495 #endif
0496 #if defined(O_WRONLY)
0497 # define UV_FS_O_WRONLY       O_WRONLY
0498 #else
0499 # define UV_FS_O_WRONLY       0
0500 #endif
0501 
0502 /* fs open() flags supported on other platforms: */
0503 #define UV_FS_O_FILEMAP       0
0504 #define UV_FS_O_RANDOM        0
0505 #define UV_FS_O_SHORT_LIVED   0
0506 #define UV_FS_O_SEQUENTIAL    0
0507 #define UV_FS_O_TEMPORARY     0
0508 
0509 #endif /* UV_UNIX_H */