File indexing completed on 2025-01-18 10:02:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #ifndef _WIN32_WINNT
0023 # define _WIN32_WINNT 0x0600
0024 #endif
0025
0026 #if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
0027 typedef intptr_t ssize_t;
0028 # define SSIZE_MAX INTPTR_MAX
0029 # define _SSIZE_T_
0030 # define _SSIZE_T_DEFINED
0031 #endif
0032
0033 #include <winsock2.h>
0034
0035 #if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
0036 typedef struct pollfd {
0037 SOCKET fd;
0038 short events;
0039 short revents;
0040 } WSAPOLLFD, *PWSAPOLLFD, *LPWSAPOLLFD;
0041 #endif
0042
0043 #ifndef LOCALE_INVARIANT
0044 # define LOCALE_INVARIANT 0x007f
0045 #endif
0046
0047 #include <mswsock.h>
0048
0049 #define _TCP_INITIAL_RTO_PARAMETERS _TCP_INITIAL_RTO_PARAMETERS__AVOID
0050 #define TCP_INITIAL_RTO_PARAMETERS TCP_INITIAL_RTO_PARAMETERS__AVOID
0051 #define PTCP_INITIAL_RTO_PARAMETERS PTCP_INITIAL_RTO_PARAMETERS__AVOID
0052 #include <ws2tcpip.h>
0053 #undef _TCP_INITIAL_RTO_PARAMETERS
0054 #undef TCP_INITIAL_RTO_PARAMETERS
0055 #undef PTCP_INITIAL_RTO_PARAMETERS
0056 #include <windows.h>
0057
0058 #include <process.h>
0059 #include <signal.h>
0060 #include <fcntl.h>
0061 #include <sys/stat.h>
0062 #include <stdint.h>
0063
0064 #include "uv/tree.h"
0065 #include "uv/threadpool.h"
0066
0067 #define MAX_PIPENAME_LEN 256
0068
0069 #ifndef S_IFLNK
0070 # define S_IFLNK 0xA000
0071 #endif
0072
0073
0074 #if defined(_CRT_INTERNAL_NONSTDC_NAMES) && _CRT_INTERNAL_NONSTDC_NAMES && !defined(S_IFIFO)
0075 # define S_IFIFO _S_IFIFO
0076 #endif
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093 #define SIGHUP 1
0094 #define SIGQUIT 3
0095 #define SIGKILL 9
0096 #define SIGWINCH 28
0097
0098
0099 #if defined(NSIG) && NSIG <= SIGWINCH
0100 # undef NSIG
0101 #endif
0102 #ifndef NSIG
0103 # define NSIG SIGWINCH + 1
0104 #endif
0105
0106
0107
0108 #ifndef SIGABRT_COMPAT
0109 # define SIGABRT_COMPAT 6
0110 #endif
0111
0112
0113
0114
0115
0116 #ifndef WSAID_ACCEPTEX
0117 # define WSAID_ACCEPTEX \
0118 {0xb5367df1, 0xcbac, 0x11cf, \
0119 {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
0120
0121 # define WSAID_CONNECTEX \
0122 {0x25a207b9, 0xddf3, 0x4660, \
0123 {0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e}}
0124
0125 # define WSAID_GETACCEPTEXSOCKADDRS \
0126 {0xb5367df2, 0xcbac, 0x11cf, \
0127 {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
0128
0129 # define WSAID_DISCONNECTEX \
0130 {0x7fda2e11, 0x8630, 0x436f, \
0131 {0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57}}
0132
0133 # define WSAID_TRANSMITFILE \
0134 {0xb5367df0, 0xcbac, 0x11cf, \
0135 {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
0136
0137 typedef BOOL (PASCAL *LPFN_ACCEPTEX)
0138 (SOCKET sListenSocket,
0139 SOCKET sAcceptSocket,
0140 PVOID lpOutputBuffer,
0141 DWORD dwReceiveDataLength,
0142 DWORD dwLocalAddressLength,
0143 DWORD dwRemoteAddressLength,
0144 LPDWORD lpdwBytesReceived,
0145 LPOVERLAPPED lpOverlapped);
0146
0147 typedef BOOL (PASCAL *LPFN_CONNECTEX)
0148 (SOCKET s,
0149 const struct sockaddr* name,
0150 int namelen,
0151 PVOID lpSendBuffer,
0152 DWORD dwSendDataLength,
0153 LPDWORD lpdwBytesSent,
0154 LPOVERLAPPED lpOverlapped);
0155
0156 typedef void (PASCAL *LPFN_GETACCEPTEXSOCKADDRS)
0157 (PVOID lpOutputBuffer,
0158 DWORD dwReceiveDataLength,
0159 DWORD dwLocalAddressLength,
0160 DWORD dwRemoteAddressLength,
0161 LPSOCKADDR* LocalSockaddr,
0162 LPINT LocalSockaddrLength,
0163 LPSOCKADDR* RemoteSockaddr,
0164 LPINT RemoteSockaddrLength);
0165
0166 typedef BOOL (PASCAL *LPFN_DISCONNECTEX)
0167 (SOCKET hSocket,
0168 LPOVERLAPPED lpOverlapped,
0169 DWORD dwFlags,
0170 DWORD reserved);
0171
0172 typedef BOOL (PASCAL *LPFN_TRANSMITFILE)
0173 (SOCKET hSocket,
0174 HANDLE hFile,
0175 DWORD nNumberOfBytesToWrite,
0176 DWORD nNumberOfBytesPerSend,
0177 LPOVERLAPPED lpOverlapped,
0178 LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers,
0179 DWORD dwFlags);
0180
0181 typedef PVOID RTL_SRWLOCK;
0182 typedef RTL_SRWLOCK SRWLOCK, *PSRWLOCK;
0183 #endif
0184
0185 typedef int (WSAAPI* LPFN_WSARECV)
0186 (SOCKET socket,
0187 LPWSABUF buffers,
0188 DWORD buffer_count,
0189 LPDWORD bytes,
0190 LPDWORD flags,
0191 LPWSAOVERLAPPED overlapped,
0192 LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine);
0193
0194 typedef int (WSAAPI* LPFN_WSARECVFROM)
0195 (SOCKET socket,
0196 LPWSABUF buffers,
0197 DWORD buffer_count,
0198 LPDWORD bytes,
0199 LPDWORD flags,
0200 struct sockaddr* addr,
0201 LPINT addr_len,
0202 LPWSAOVERLAPPED overlapped,
0203 LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine);
0204
0205 #ifndef _NTDEF_
0206 typedef LONG NTSTATUS;
0207 typedef NTSTATUS *PNTSTATUS;
0208 #endif
0209
0210 #ifndef RTL_CONDITION_VARIABLE_INIT
0211 typedef PVOID CONDITION_VARIABLE, *PCONDITION_VARIABLE;
0212 #endif
0213
0214 typedef struct _AFD_POLL_HANDLE_INFO {
0215 HANDLE Handle;
0216 ULONG Events;
0217 NTSTATUS Status;
0218 } AFD_POLL_HANDLE_INFO, *PAFD_POLL_HANDLE_INFO;
0219
0220 typedef struct _AFD_POLL_INFO {
0221 LARGE_INTEGER Timeout;
0222 ULONG NumberOfHandles;
0223 ULONG Exclusive;
0224 AFD_POLL_HANDLE_INFO Handles[1];
0225 } AFD_POLL_INFO, *PAFD_POLL_INFO;
0226
0227 #define UV_MSAFD_PROVIDER_COUNT 4
0228
0229
0230
0231
0232
0233
0234 typedef struct uv_buf_t {
0235 ULONG len;
0236 char* base;
0237 } uv_buf_t;
0238
0239 typedef int uv_file;
0240 typedef SOCKET uv_os_sock_t;
0241 typedef HANDLE uv_os_fd_t;
0242 typedef int uv_pid_t;
0243
0244 typedef HANDLE uv_thread_t;
0245
0246 typedef HANDLE uv_sem_t;
0247
0248 typedef CRITICAL_SECTION uv_mutex_t;
0249
0250
0251
0252
0253
0254
0255
0256
0257 typedef union {
0258 CONDITION_VARIABLE cond_var;
0259 struct {
0260 unsigned int waiters_count;
0261 CRITICAL_SECTION waiters_count_lock;
0262 HANDLE signal_event;
0263 HANDLE broadcast_event;
0264 } unused_;
0265 } uv_cond_t;
0266
0267 typedef struct {
0268 SRWLOCK read_write_lock_;
0269
0270 #ifdef _WIN64
0271 unsigned char padding_[72];
0272 #else
0273 unsigned char padding_[44];
0274 #endif
0275 } uv_rwlock_t;
0276
0277 typedef struct {
0278 unsigned threshold;
0279 unsigned in;
0280 uv_mutex_t mutex;
0281
0282 CONDITION_VARIABLE cond;
0283 unsigned out;
0284 } uv_barrier_t;
0285
0286 typedef struct {
0287 DWORD tls_index;
0288 } uv_key_t;
0289
0290 #define UV_ONCE_INIT { 0, NULL }
0291
0292 typedef struct uv_once_s {
0293 unsigned char ran;
0294 HANDLE event;
0295 } uv_once_t;
0296
0297
0298 typedef unsigned char uv_uid_t;
0299 typedef unsigned char uv_gid_t;
0300
0301 typedef struct uv__dirent_s {
0302 int d_type;
0303 char d_name[1];
0304 } uv__dirent_t;
0305
0306 #define UV_DIR_PRIVATE_FIELDS \
0307 HANDLE dir_handle; \
0308 WIN32_FIND_DATAW find_data; \
0309 BOOL need_find_call;
0310
0311 #define HAVE_DIRENT_TYPES
0312 #define UV__DT_DIR UV_DIRENT_DIR
0313 #define UV__DT_FILE UV_DIRENT_FILE
0314 #define UV__DT_LINK UV_DIRENT_LINK
0315 #define UV__DT_FIFO UV_DIRENT_FIFO
0316 #define UV__DT_SOCKET UV_DIRENT_SOCKET
0317 #define UV__DT_CHAR UV_DIRENT_CHAR
0318 #define UV__DT_BLOCK UV_DIRENT_BLOCK
0319
0320
0321 #define UV_DYNAMIC FAR WINAPI
0322 typedef struct {
0323 HMODULE handle;
0324 char* errmsg;
0325 } uv_lib_t;
0326
0327 #define UV_LOOP_PRIVATE_FIELDS \
0328 \
0329 HANDLE iocp; \
0330 \
0331 uint64_t time; \
0332 \
0333 \
0334 \
0335 uv_req_t* pending_reqs_tail; \
0336 \
0337 uv_handle_t* endgame_handles; \
0338 \
0339 void* timer_heap; \
0340 \
0341 uv_prepare_t* prepare_handles; \
0342 uv_check_t* check_handles; \
0343 uv_idle_t* idle_handles; \
0344 \
0345 \
0346 \
0347 \
0348 uv_prepare_t* next_prepare_handle; \
0349 uv_check_t* next_check_handle; \
0350 uv_idle_t* next_idle_handle; \
0351 \
0352 SOCKET poll_peer_sockets[UV_MSAFD_PROVIDER_COUNT]; \
0353 \
0354 unsigned int active_tcp_streams; \
0355 \
0356 unsigned int active_udp_streams; \
0357 \
0358 uint64_t timer_counter; \
0359 \
0360 struct uv__queue wq; \
0361 uv_mutex_t wq_mutex; \
0362 uv_async_t wq_async;
0363
0364 #define UV_REQ_TYPE_PRIVATE \
0365 \
0366 UV_ACCEPT, \
0367 UV_FS_EVENT_REQ, \
0368 UV_POLL_REQ, \
0369 UV_PROCESS_EXIT, \
0370 UV_READ, \
0371 UV_UDP_RECV, \
0372 UV_WAKEUP, \
0373 UV_SIGNAL_REQ,
0374
0375 #define UV_REQ_PRIVATE_FIELDS \
0376 union { \
0377 \
0378 struct { \
0379 OVERLAPPED overlapped; \
0380 size_t queued_bytes; \
0381 } io; \
0382 \
0383 struct { \
0384 ULONG_PTR result; \
0385 HANDLE pipeHandle; \
0386 DWORD duplex_flags; \
0387 WCHAR* name; \
0388 } connect; \
0389 } u; \
0390 struct uv_req_s* next_req;
0391
0392 #define UV_WRITE_PRIVATE_FIELDS \
0393 int coalesced; \
0394 uv_buf_t write_buffer; \
0395 HANDLE event_handle; \
0396 HANDLE wait_handle;
0397
0398 #define UV_CONNECT_PRIVATE_FIELDS \
0399
0400
0401 #define UV_SHUTDOWN_PRIVATE_FIELDS \
0402
0403
0404 #define UV_UDP_SEND_PRIVATE_FIELDS \
0405
0406
0407 #define UV_PRIVATE_REQ_TYPES \
0408 typedef struct uv_pipe_accept_s { \
0409 UV_REQ_FIELDS \
0410 HANDLE pipeHandle; \
0411 struct uv_pipe_accept_s* next_pending; \
0412 } uv_pipe_accept_t; \
0413 \
0414 typedef struct uv_tcp_accept_s { \
0415 UV_REQ_FIELDS \
0416 SOCKET accept_socket; \
0417 char accept_buffer[sizeof(struct sockaddr_storage) * 2 + 32]; \
0418 HANDLE event_handle; \
0419 HANDLE wait_handle; \
0420 struct uv_tcp_accept_s* next_pending; \
0421 } uv_tcp_accept_t; \
0422 \
0423 typedef struct uv_read_s { \
0424 UV_REQ_FIELDS \
0425 HANDLE event_handle; \
0426 HANDLE wait_handle; \
0427 } uv_read_t;
0428
0429 #define uv_stream_connection_fields \
0430 unsigned int write_reqs_pending; \
0431 uv_shutdown_t* shutdown_req;
0432
0433 #define uv_stream_server_fields \
0434 uv_connection_cb connection_cb;
0435
0436 #define UV_STREAM_PRIVATE_FIELDS \
0437 unsigned int reqs_pending; \
0438 int activecnt; \
0439 uv_read_t read_req; \
0440 union { \
0441 struct { uv_stream_connection_fields } conn; \
0442 struct { uv_stream_server_fields } serv; \
0443 } stream;
0444
0445 #define uv_tcp_server_fields \
0446 uv_tcp_accept_t* accept_reqs; \
0447 unsigned int processed_accepts; \
0448 uv_tcp_accept_t* pending_accepts; \
0449 LPFN_ACCEPTEX func_acceptex;
0450
0451 #define uv_tcp_connection_fields \
0452 uv_buf_t read_buffer; \
0453 LPFN_CONNECTEX func_connectex;
0454
0455 #define UV_TCP_PRIVATE_FIELDS \
0456 SOCKET socket; \
0457 int delayed_error; \
0458 union { \
0459 struct { uv_tcp_server_fields } serv; \
0460 struct { uv_tcp_connection_fields } conn; \
0461 } tcp;
0462
0463 #define UV_UDP_PRIVATE_FIELDS \
0464 SOCKET socket; \
0465 unsigned int reqs_pending; \
0466 int activecnt; \
0467 uv_req_t recv_req; \
0468 uv_buf_t recv_buffer; \
0469 struct sockaddr_storage recv_from; \
0470 int recv_from_len; \
0471 uv_udp_recv_cb recv_cb; \
0472 uv_alloc_cb alloc_cb; \
0473 LPFN_WSARECV func_wsarecv; \
0474 LPFN_WSARECVFROM func_wsarecvfrom;
0475
0476 #define uv_pipe_server_fields \
0477 int pending_instances; \
0478 uv_pipe_accept_t* accept_reqs; \
0479 uv_pipe_accept_t* pending_accepts;
0480
0481 #define uv_pipe_connection_fields \
0482 uv_timer_t* eof_timer; \
0483 uv_write_t dummy; \
0484 DWORD ipc_remote_pid; \
0485 union { \
0486 uint32_t payload_remaining; \
0487 uint64_t dummy; \
0488 } ipc_data_frame; \
0489 struct uv__queue ipc_xfer_queue; \
0490 int ipc_xfer_queue_length; \
0491 uv_write_t* non_overlapped_writes_tail; \
0492 CRITICAL_SECTION readfile_thread_lock; \
0493 volatile HANDLE readfile_thread_handle;
0494
0495 #define UV_PIPE_PRIVATE_FIELDS \
0496 HANDLE handle; \
0497 WCHAR* name; \
0498 union { \
0499 struct { uv_pipe_server_fields } serv; \
0500 struct { uv_pipe_connection_fields } conn; \
0501 } pipe;
0502
0503
0504
0505 #define UV_TTY_PRIVATE_FIELDS \
0506 HANDLE handle; \
0507 union { \
0508 struct { \
0509 \
0510 \
0511 HANDLE unused_; \
0512 uv_buf_t read_line_buffer; \
0513 HANDLE read_raw_wait; \
0514 \
0515 char last_key[8]; \
0516 unsigned char last_key_offset; \
0517 unsigned char last_key_len; \
0518 WCHAR last_utf16_high_surrogate; \
0519 INPUT_RECORD last_input_record; \
0520 } rd; \
0521 struct { \
0522 \
0523 \
0524 unsigned int utf8_codepoint; \
0525 unsigned char utf8_bytes_left; \
0526 \
0527 unsigned char previous_eol; \
0528 \
0529 unsigned short ansi_parser_state; \
0530 unsigned char ansi_csi_argc; \
0531 unsigned short ansi_csi_argv[4]; \
0532 COORD saved_position; \
0533 WORD saved_attributes; \
0534 } wr; \
0535 } tty;
0536
0537 #define UV_POLL_PRIVATE_FIELDS \
0538 SOCKET socket; \
0539 \
0540 SOCKET peer_socket; \
0541 AFD_POLL_INFO afd_poll_info_1; \
0542 AFD_POLL_INFO afd_poll_info_2; \
0543 \
0544 uv_req_t poll_req_1; \
0545 uv_req_t poll_req_2; \
0546 unsigned char submitted_events_1; \
0547 unsigned char submitted_events_2; \
0548 unsigned char mask_events_1; \
0549 unsigned char mask_events_2; \
0550 unsigned char events;
0551
0552 #define UV_TIMER_PRIVATE_FIELDS \
0553 union { \
0554 void* heap[3]; \
0555 struct uv__queue queue; \
0556 } node; \
0557 int unused; \
0558 uint64_t timeout; \
0559 uint64_t repeat; \
0560 uint64_t start_id; \
0561 uv_timer_cb timer_cb;
0562
0563 #define UV_ASYNC_PRIVATE_FIELDS \
0564 struct uv_req_s async_req; \
0565 uv_async_cb async_cb; \
0566 \
0567 char volatile async_sent;
0568
0569 #define UV_PREPARE_PRIVATE_FIELDS \
0570 uv_prepare_t* prepare_prev; \
0571 uv_prepare_t* prepare_next; \
0572 uv_prepare_cb prepare_cb;
0573
0574 #define UV_CHECK_PRIVATE_FIELDS \
0575 uv_check_t* check_prev; \
0576 uv_check_t* check_next; \
0577 uv_check_cb check_cb;
0578
0579 #define UV_IDLE_PRIVATE_FIELDS \
0580 uv_idle_t* idle_prev; \
0581 uv_idle_t* idle_next; \
0582 uv_idle_cb idle_cb;
0583
0584 #define UV_HANDLE_PRIVATE_FIELDS \
0585 uv_handle_t* endgame_next; \
0586 unsigned int flags;
0587
0588 #define UV_GETADDRINFO_PRIVATE_FIELDS \
0589 struct uv__work work_req; \
0590 uv_getaddrinfo_cb getaddrinfo_cb; \
0591 void* alloc; \
0592 WCHAR* node; \
0593 WCHAR* service; \
0594 \
0595 \
0596 \
0597 struct addrinfoW* addrinfow; \
0598 struct addrinfo* addrinfo; \
0599 int retcode;
0600
0601 #define UV_GETNAMEINFO_PRIVATE_FIELDS \
0602 struct uv__work work_req; \
0603 uv_getnameinfo_cb getnameinfo_cb; \
0604 struct sockaddr_storage storage; \
0605 int flags; \
0606 char host[NI_MAXHOST]; \
0607 char service[NI_MAXSERV]; \
0608 int retcode;
0609
0610 #define UV_PROCESS_PRIVATE_FIELDS \
0611 struct uv_process_exit_s { \
0612 UV_REQ_FIELDS \
0613 } exit_req; \
0614 void* unused; \
0615 int exit_signal; \
0616 HANDLE wait_handle; \
0617 HANDLE process_handle; \
0618 volatile char exit_cb_pending;
0619
0620 #define UV_FS_PRIVATE_FIELDS \
0621 struct uv__work work_req; \
0622 int flags; \
0623 DWORD sys_errno_; \
0624 union { \
0625 \
0626 WCHAR* pathw; \
0627 int fd; \
0628 } file; \
0629 union { \
0630 struct { \
0631 int mode; \
0632 WCHAR* new_pathw; \
0633 int file_flags; \
0634 int fd_out; \
0635 unsigned int nbufs; \
0636 uv_buf_t* bufs; \
0637 int64_t offset; \
0638 uv_buf_t bufsml[4]; \
0639 } info; \
0640 struct { \
0641 double atime; \
0642 double mtime; \
0643 } time; \
0644 } fs;
0645
0646 #define UV_WORK_PRIVATE_FIELDS \
0647 struct uv__work work_req;
0648
0649 #define UV_FS_EVENT_PRIVATE_FIELDS \
0650 struct uv_fs_event_req_s { \
0651 UV_REQ_FIELDS \
0652 } req; \
0653 HANDLE dir_handle; \
0654 int req_pending; \
0655 uv_fs_event_cb cb; \
0656 WCHAR* filew; \
0657 WCHAR* short_filew; \
0658 WCHAR* dirw; \
0659 char* buffer;
0660
0661 #define UV_SIGNAL_PRIVATE_FIELDS \
0662 RB_ENTRY(uv_signal_s) tree_entry; \
0663 struct uv_req_s signal_req; \
0664 unsigned long pending_signum;
0665
0666 #ifndef F_OK
0667 #define F_OK 0
0668 #endif
0669 #ifndef R_OK
0670 #define R_OK 4
0671 #endif
0672 #ifndef W_OK
0673 #define W_OK 2
0674 #endif
0675 #ifndef X_OK
0676 #define X_OK 1
0677 #endif
0678
0679
0680 #define UV_FS_O_APPEND _O_APPEND
0681 #define UV_FS_O_CREAT _O_CREAT
0682 #define UV_FS_O_EXCL _O_EXCL
0683 #define UV_FS_O_FILEMAP 0x20000000
0684 #define UV_FS_O_RANDOM _O_RANDOM
0685 #define UV_FS_O_RDONLY _O_RDONLY
0686 #define UV_FS_O_RDWR _O_RDWR
0687 #define UV_FS_O_SEQUENTIAL _O_SEQUENTIAL
0688 #define UV_FS_O_SHORT_LIVED _O_SHORT_LIVED
0689 #define UV_FS_O_TEMPORARY _O_TEMPORARY
0690 #define UV_FS_O_TRUNC _O_TRUNC
0691 #define UV_FS_O_WRONLY _O_WRONLY
0692
0693
0694 #define UV_FS_O_DIRECT 0x02000000
0695 #define UV_FS_O_DIRECTORY 0
0696 #define UV_FS_O_DSYNC 0x04000000
0697 #define UV_FS_O_EXLOCK 0x10000000
0698 #define UV_FS_O_NOATIME 0
0699 #define UV_FS_O_NOCTTY 0
0700 #define UV_FS_O_NOFOLLOW 0
0701 #define UV_FS_O_NONBLOCK 0
0702 #define UV_FS_O_SYMLINK 0
0703 #define UV_FS_O_SYNC 0x08000000