1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining a copy 4 * of this software and associated documentation files (the "Software"), to 5 * deal in the Software without restriction, including without limitation the 6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 * sell copies of the Software, and to permit persons to whom the Software is 8 * furnished to do so, subject to the following conditions: 9 * 10 * The above copyright notice and this permission notice shall be included in 11 * all copies or substantial portions of the Software. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 * IN THE SOFTWARE. 20 */ 21 22 #ifndef _WIN32_WINNT 23 # define _WIN32_WINNT 0x0A00 24 #endif 25 26 #if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED) 27 typedef intptr_t ssize_t; 28 # define SSIZE_MAX INTPTR_MAX 29 # define _SSIZE_T_ 30 # define _SSIZE_T_DEFINED 31 #endif 32 33 #include <winsock2.h> 34 35 #ifndef LOCALE_INVARIANT 36 # define LOCALE_INVARIANT 0x007f 37 #endif 38 39 #include <mswsock.h> 40 /* Disable the typedef in mstcpip.h of MinGW. */ 41 #define _TCP_INITIAL_RTO_PARAMETERS _TCP_INITIAL_RTO_PARAMETERS__AVOID 42 #define TCP_INITIAL_RTO_PARAMETERS TCP_INITIAL_RTO_PARAMETERS__AVOID 43 #define PTCP_INITIAL_RTO_PARAMETERS PTCP_INITIAL_RTO_PARAMETERS__AVOID 44 #include <ws2tcpip.h> 45 #undef _TCP_INITIAL_RTO_PARAMETERS 46 #undef TCP_INITIAL_RTO_PARAMETERS 47 #undef PTCP_INITIAL_RTO_PARAMETERS 48 #include <windows.h> 49 50 #include <process.h> 51 #include <signal.h> 52 #include <fcntl.h> 53 #include <sys/stat.h> 54 #include <stdint.h> 55 56 #include "uv/tree.h" 57 #include "uv/threadpool.h" 58 59 #define MAX_PIPENAME_LEN 256 60 61 #ifndef S_IFLNK 62 # define S_IFLNK 0xA000 63 #endif 64 65 /* Define missing in Windows Kit Include\{VERSION}\ucrt\sys\stat.h */ 66 #if defined(_CRT_INTERNAL_NONSTDC_NAMES) && _CRT_INTERNAL_NONSTDC_NAMES && !defined(S_IFIFO) 67 # define S_IFIFO _S_IFIFO 68 #endif 69 70 /* Additional signals supported by uv_signal and or uv_kill. The CRT defines 71 * the following signals already: 72 * 73 * #define SIGINT 2 74 * #define SIGILL 4 75 * #define SIGABRT_COMPAT 6 76 * #define SIGFPE 8 77 * #define SIGSEGV 11 78 * #define SIGTERM 15 79 * #define SIGBREAK 21 80 * #define SIGABRT 22 81 * 82 * The additional signals have values that are common on other Unix 83 * variants (Linux and Darwin) 84 */ 85 #define SIGHUP 1 86 #define SIGQUIT 3 87 #define SIGKILL 9 88 #define SIGWINCH 28 89 90 /* Redefine NSIG to take SIGWINCH into consideration */ 91 #if defined(NSIG) && NSIG <= SIGWINCH 92 # undef NSIG 93 #endif 94 #ifndef NSIG 95 # define NSIG SIGWINCH + 1 96 #endif 97 98 /* The CRT defines SIGABRT_COMPAT as 6, which equals SIGABRT on many unix-like 99 * platforms. However MinGW doesn't define it, so we do. */ 100 #ifndef SIGABRT_COMPAT 101 # define SIGABRT_COMPAT 6 102 #endif 103 104 /* 105 * Guids and typedefs for winsock extension functions 106 * Mingw32 doesn't have these :-( 107 */ 108 #ifndef WSAID_ACCEPTEX 109 # define WSAID_ACCEPTEX \ 110 {0xb5367df1, 0xcbac, 0x11cf, \ 111 {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}} 112 113 # define WSAID_CONNECTEX \ 114 {0x25a207b9, 0xddf3, 0x4660, \ 115 {0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e}} 116 117 # define WSAID_GETACCEPTEXSOCKADDRS \ 118 {0xb5367df2, 0xcbac, 0x11cf, \ 119 {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}} 120 121 # define WSAID_DISCONNECTEX \ 122 {0x7fda2e11, 0x8630, 0x436f, \ 123 {0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57}} 124 125 # define WSAID_TRANSMITFILE \ 126 {0xb5367df0, 0xcbac, 0x11cf, \ 127 {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}} 128 129 typedef BOOL (PASCAL *LPFN_ACCEPTEX) 130 (SOCKET sListenSocket, 131 SOCKET sAcceptSocket, 132 PVOID lpOutputBuffer, 133 DWORD dwReceiveDataLength, 134 DWORD dwLocalAddressLength, 135 DWORD dwRemoteAddressLength, 136 LPDWORD lpdwBytesReceived, 137 LPOVERLAPPED lpOverlapped); 138 139 typedef BOOL (PASCAL *LPFN_CONNECTEX) 140 (SOCKET s, 141 const struct sockaddr* name, 142 int namelen, 143 PVOID lpSendBuffer, 144 DWORD dwSendDataLength, 145 LPDWORD lpdwBytesSent, 146 LPOVERLAPPED lpOverlapped); 147 148 typedef void (PASCAL *LPFN_GETACCEPTEXSOCKADDRS) 149 (PVOID lpOutputBuffer, 150 DWORD dwReceiveDataLength, 151 DWORD dwLocalAddressLength, 152 DWORD dwRemoteAddressLength, 153 LPSOCKADDR* LocalSockaddr, 154 LPINT LocalSockaddrLength, 155 LPSOCKADDR* RemoteSockaddr, 156 LPINT RemoteSockaddrLength); 157 158 typedef BOOL (PASCAL *LPFN_DISCONNECTEX) 159 (SOCKET hSocket, 160 LPOVERLAPPED lpOverlapped, 161 DWORD dwFlags, 162 DWORD reserved); 163 164 typedef BOOL (PASCAL *LPFN_TRANSMITFILE) 165 (SOCKET hSocket, 166 HANDLE hFile, 167 DWORD nNumberOfBytesToWrite, 168 DWORD nNumberOfBytesPerSend, 169 LPOVERLAPPED lpOverlapped, 170 LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers, 171 DWORD dwFlags); 172 173 typedef PVOID RTL_SRWLOCK; 174 typedef RTL_SRWLOCK SRWLOCK, *PSRWLOCK; 175 #endif 176 177 typedef int (WSAAPI* LPFN_WSARECV) 178 (SOCKET socket, 179 LPWSABUF buffers, 180 DWORD buffer_count, 181 LPDWORD bytes, 182 LPDWORD flags, 183 LPWSAOVERLAPPED overlapped, 184 LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine); 185 186 typedef int (WSAAPI* LPFN_WSARECVFROM) 187 (SOCKET socket, 188 LPWSABUF buffers, 189 DWORD buffer_count, 190 LPDWORD bytes, 191 LPDWORD flags, 192 struct sockaddr* addr, 193 LPINT addr_len, 194 LPWSAOVERLAPPED overlapped, 195 LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine); 196 197 #ifndef _NTDEF_ 198 typedef LONG NTSTATUS; 199 typedef NTSTATUS *PNTSTATUS; 200 #endif 201 202 #ifndef RTL_CONDITION_VARIABLE_INIT 203 typedef PVOID CONDITION_VARIABLE, *PCONDITION_VARIABLE; 204 #endif 205 206 typedef struct _AFD_POLL_HANDLE_INFO { 207 HANDLE Handle; 208 ULONG Events; 209 NTSTATUS Status; 210 } AFD_POLL_HANDLE_INFO, *PAFD_POLL_HANDLE_INFO; 211 212 typedef struct _AFD_POLL_INFO { 213 LARGE_INTEGER Timeout; 214 ULONG NumberOfHandles; 215 ULONG Exclusive; 216 AFD_POLL_HANDLE_INFO Handles[1]; 217 } AFD_POLL_INFO, *PAFD_POLL_INFO; 218 219 #define UV_MSAFD_PROVIDER_COUNT 4 220 221 222 /** 223 * It should be possible to cast uv_buf_t[] to WSABUF[] 224 * see http://msdn.microsoft.com/en-us/library/ms741542(v=vs.85).aspx 225 */ 226 typedef struct uv_buf_t { 227 ULONG len; 228 char* base; 229 } uv_buf_t; 230 231 typedef int uv_file; 232 typedef SOCKET uv_os_sock_t; 233 typedef HANDLE uv_os_fd_t; 234 typedef int uv_pid_t; 235 236 typedef HANDLE uv_thread_t; 237 238 typedef HANDLE uv_sem_t; 239 240 typedef CRITICAL_SECTION uv_mutex_t; 241 242 /* This condition variable implementation is based on the SetEvent solution 243 * (section 3.2) at http://www.cs.wustl.edu/~schmidt/win32-cv-1.html 244 * We could not use the SignalObjectAndWait solution (section 3.4) because 245 * it want the 2nd argument (type uv_mutex_t) of uv_cond_wait() and 246 * uv_cond_timedwait() to be HANDLEs, but we use CRITICAL_SECTIONs. 247 */ 248 249 typedef union { 250 CONDITION_VARIABLE cond_var; 251 struct { 252 unsigned int waiters_count; 253 CRITICAL_SECTION waiters_count_lock; 254 HANDLE signal_event; 255 HANDLE broadcast_event; 256 } unused_; /* TODO: retained for ABI compatibility; remove me in v2.x. */ 257 } uv_cond_t; 258 259 typedef struct { 260 SRWLOCK read_write_lock_; 261 /* TODO: retained for ABI compatibility; remove me in v2.x */ 262 #ifdef _WIN64 263 unsigned char padding_[72]; 264 #else 265 unsigned char padding_[44]; 266 #endif 267 } uv_rwlock_t; 268 269 typedef struct { 270 unsigned threshold; 271 unsigned in; 272 uv_mutex_t mutex; 273 /* TODO: in v2 make this a uv_cond_t, without unused_ */ 274 CONDITION_VARIABLE cond; 275 unsigned out; 276 } uv_barrier_t; 277 278 typedef struct { 279 DWORD tls_index; 280 } uv_key_t; 281 282 #define UV_ONCE_INIT { 0, NULL } 283 284 typedef struct uv_once_s { 285 unsigned char unused; 286 INIT_ONCE init_once; 287 } uv_once_t; 288 289 /* Platform-specific definitions for uv_spawn support. */ 290 typedef unsigned char uv_uid_t; 291 typedef unsigned char uv_gid_t; 292 293 typedef struct uv__dirent_s { 294 int d_type; 295 char d_name[1]; 296 } uv__dirent_t; 297 298 #define UV_DIR_PRIVATE_FIELDS \ 299 HANDLE dir_handle; \ 300 WIN32_FIND_DATAW find_data; \ 301 BOOL need_find_call; 302 303 #define HAVE_DIRENT_TYPES 304 #define UV__DT_DIR UV_DIRENT_DIR 305 #define UV__DT_FILE UV_DIRENT_FILE 306 #define UV__DT_LINK UV_DIRENT_LINK 307 #define UV__DT_FIFO UV_DIRENT_FIFO 308 #define UV__DT_SOCKET UV_DIRENT_SOCKET 309 #define UV__DT_CHAR UV_DIRENT_CHAR 310 #define UV__DT_BLOCK UV_DIRENT_BLOCK 311 312 /* Platform-specific definitions for uv_dlopen support. */ 313 #define UV_DYNAMIC FAR WINAPI 314 typedef struct { 315 HMODULE handle; 316 char* errmsg; 317 } uv_lib_t; 318 319 #define UV_LOOP_PRIVATE_FIELDS \ 320 /* The loop's I/O completion port */ \ 321 HANDLE iocp; \ 322 /* The current time according to the event loop. in msecs. */ \ 323 uint64_t time; \ 324 /* Tail of a single-linked circular queue of pending reqs. If the queue */ \ 325 /* is empty, tail_ is NULL. If there is only one item, */ \ 326 /* tail_->next_req == tail_ */ \ 327 uv_req_t* pending_reqs_tail; \ 328 /* Head of a single-linked list of closed handles */ \ 329 uv_handle_t* endgame_handles; \ 330 /* TODO(bnoordhuis) Stop heap-allocating |timer_heap| in libuv v2.x. */ \ 331 void* timer_heap; \ 332 /* Lists of active loop (prepare / check / idle) watchers */ \ 333 uv_prepare_t* prepare_handles; \ 334 uv_check_t* check_handles; \ 335 uv_idle_t* idle_handles; \ 336 /* This pointer will refer to the prepare/check/idle handle whose */ \ 337 /* callback is scheduled to be called next. This is needed to allow */ \ 338 /* safe removal from one of the lists above while that list being */ \ 339 /* iterated over. */ \ 340 uv_prepare_t* next_prepare_handle; \ 341 uv_check_t* next_check_handle; \ 342 uv_idle_t* next_idle_handle; \ 343 /* This handle holds the peer sockets for the fast variant of uv_poll_t */ \ 344 SOCKET poll_peer_sockets[UV_MSAFD_PROVIDER_COUNT]; \ 345 /* No longer used. */ \ 346 unsigned int active_tcp_streams; \ 347 /* No longer used. */ \ 348 unsigned int active_udp_streams; \ 349 /* Counter to started timer */ \ 350 uint64_t timer_counter; \ 351 /* Threadpool */ \ 352 struct uv__queue wq; \ 353 uv_mutex_t wq_mutex; \ 354 uv_async_t wq_async; 355 356 #define UV_REQ_TYPE_PRIVATE \ 357 /* TODO: remove the req suffix */ \ 358 UV_ACCEPT, \ 359 UV_FS_EVENT_REQ, \ 360 UV_POLL_REQ, \ 361 UV_PROCESS_EXIT, \ 362 UV_READ, \ 363 UV_UDP_RECV, \ 364 UV_WAKEUP, \ 365 UV_SIGNAL_REQ, 366 367 #define UV_REQ_PRIVATE_FIELDS \ 368 union { \ 369 /* Used by I/O operations */ \ 370 struct { \ 371 OVERLAPPED overlapped; \ 372 size_t queued_bytes; \ 373 } io; \ 374 /* in v2, we can move these to the UV_CONNECT_PRIVATE_FIELDS */ \ 375 struct { \ 376 ULONG_PTR result; /* overlapped.Internal is reused to hold the result */\ 377 HANDLE pipeHandle; \ 378 DWORD duplex_flags; \ 379 WCHAR* name; \ 380 } connect; \ 381 } u; \ 382 struct uv_req_s* next_req; 383 384 #define UV_WRITE_PRIVATE_FIELDS \ 385 int coalesced; \ 386 uv_buf_t write_buffer; \ 387 HANDLE event_handle; \ 388 HANDLE wait_handle; 389 390 #define UV_CONNECT_PRIVATE_FIELDS \ 391 /* empty */ 392 393 #define UV_SHUTDOWN_PRIVATE_FIELDS \ 394 /* empty */ 395 396 #define UV_UDP_SEND_PRIVATE_FIELDS \ 397 /* empty */ 398 399 #define UV_PRIVATE_REQ_TYPES \ 400 typedef struct uv_pipe_accept_s { \ 401 UV_REQ_FIELDS \ 402 HANDLE pipeHandle; \ 403 struct uv_pipe_accept_s* next_pending; \ 404 } uv_pipe_accept_t; \ 405 \ 406 typedef struct uv_tcp_accept_s { \ 407 UV_REQ_FIELDS \ 408 SOCKET accept_socket; \ 409 char accept_buffer[sizeof(struct sockaddr_storage) * 2 + 32]; \ 410 HANDLE event_handle; \ 411 HANDLE wait_handle; \ 412 struct uv_tcp_accept_s* next_pending; \ 413 } uv_tcp_accept_t; \ 414 \ 415 typedef struct uv_read_s { \ 416 UV_REQ_FIELDS \ 417 HANDLE event_handle; \ 418 HANDLE wait_handle; \ 419 } uv_read_t; 420 421 #define uv_stream_connection_fields \ 422 unsigned int write_reqs_pending; \ 423 uv_shutdown_t* shutdown_req; 424 425 #define uv_stream_server_fields \ 426 uv_connection_cb connection_cb; 427 428 #define UV_STREAM_PRIVATE_FIELDS \ 429 unsigned int reqs_pending; \ 430 int activecnt; \ 431 uv_read_t read_req; \ 432 union { \ 433 struct { uv_stream_connection_fields } conn; \ 434 struct { uv_stream_server_fields } serv; \ 435 } stream; 436 437 #define uv_tcp_server_fields \ 438 uv_tcp_accept_t* accept_reqs; \ 439 unsigned int processed_accepts; \ 440 uv_tcp_accept_t* pending_accepts; \ 441 LPFN_ACCEPTEX func_acceptex; 442 443 #define uv_tcp_connection_fields \ 444 uv_buf_t read_buffer; \ 445 LPFN_CONNECTEX func_connectex; 446 447 #define UV_TCP_PRIVATE_FIELDS \ 448 SOCKET socket; \ 449 int delayed_error; \ 450 union { \ 451 struct { uv_tcp_server_fields } serv; \ 452 struct { uv_tcp_connection_fields } conn; \ 453 } tcp; 454 455 #define UV_UDP_PRIVATE_FIELDS \ 456 SOCKET socket; \ 457 unsigned int reqs_pending; \ 458 int activecnt; \ 459 uv_req_t recv_req; \ 460 uv_buf_t recv_buffer; \ 461 struct sockaddr_storage recv_from; \ 462 int recv_from_len; \ 463 uv_udp_recv_cb recv_cb; \ 464 uv_alloc_cb alloc_cb; \ 465 LPFN_WSARECV func_wsarecv; \ 466 LPFN_WSARECVFROM func_wsarecvfrom; 467 468 #define uv_pipe_server_fields \ 469 int pending_instances; \ 470 uv_pipe_accept_t* accept_reqs; \ 471 uv_pipe_accept_t* pending_accepts; 472 473 #define uv_pipe_connection_fields \ 474 uv_timer_t* eof_timer; \ 475 uv_write_t dummy; /* TODO: retained for ABI compat; remove this in v2.x. */ \ 476 DWORD ipc_remote_pid; \ 477 union { \ 478 uint32_t payload_remaining; \ 479 uint64_t dummy; /* TODO: retained for ABI compat; remove this in v2.x. */ \ 480 } ipc_data_frame; \ 481 struct uv__queue ipc_xfer_queue; \ 482 int ipc_xfer_queue_length; \ 483 uv_write_t* non_overlapped_writes_tail; \ 484 CRITICAL_SECTION readfile_thread_lock; \ 485 volatile HANDLE readfile_thread_handle; 486 487 #define UV_PIPE_PRIVATE_FIELDS \ 488 HANDLE handle; \ 489 WCHAR* name; \ 490 union { \ 491 struct { uv_pipe_server_fields } serv; \ 492 struct { uv_pipe_connection_fields } conn; \ 493 } pipe; 494 495 /* TODO: put the parser states in a union - TTY handles are always half-duplex 496 * so read-state can safely overlap write-state. */ 497 #define UV_TTY_PRIVATE_FIELDS \ 498 HANDLE handle; \ 499 union { \ 500 struct { \ 501 /* Used for readable TTY handles */ \ 502 /* TODO: remove me in v2.x. */ \ 503 HANDLE unused_; \ 504 uv_buf_t read_line_buffer; \ 505 HANDLE read_raw_wait; \ 506 /* Fields used for translating win keystrokes into vt100 characters */ \ 507 char last_key[8]; \ 508 unsigned char last_key_offset; \ 509 unsigned char last_key_len; \ 510 WCHAR last_utf16_high_surrogate; \ 511 INPUT_RECORD last_input_record; \ 512 } rd; \ 513 struct { \ 514 /* Used for writable TTY handles */ \ 515 /* utf8-to-utf16 conversion state */ \ 516 unsigned int utf8_codepoint; \ 517 unsigned char utf8_bytes_left; \ 518 /* eol conversion state */ \ 519 unsigned char previous_eol; \ 520 /* ansi parser state */ \ 521 unsigned short ansi_parser_state; \ 522 unsigned char ansi_csi_argc; \ 523 unsigned short ansi_csi_argv[4]; \ 524 COORD saved_position; \ 525 WORD saved_attributes; \ 526 } wr; \ 527 } tty; 528 529 #define UV_POLL_PRIVATE_FIELDS \ 530 SOCKET socket; \ 531 /* Used in fast mode */ \ 532 SOCKET peer_socket; \ 533 AFD_POLL_INFO afd_poll_info_1; \ 534 AFD_POLL_INFO afd_poll_info_2; \ 535 /* Used in fast and slow mode. */ \ 536 uv_req_t poll_req_1; \ 537 uv_req_t poll_req_2; \ 538 unsigned char submitted_events_1; \ 539 unsigned char submitted_events_2; \ 540 unsigned char mask_events_1; \ 541 unsigned char mask_events_2; \ 542 unsigned char events; 543 544 #define UV_TIMER_PRIVATE_FIELDS \ 545 union { \ 546 void* heap[3]; \ 547 struct uv__queue queue; \ 548 } node; \ 549 int unused; \ 550 uint64_t timeout; \ 551 uint64_t repeat; \ 552 uint64_t start_id; \ 553 uv_timer_cb timer_cb; 554 555 #define UV_ASYNC_PRIVATE_FIELDS \ 556 struct uv_req_s async_req; \ 557 uv_async_cb async_cb; \ 558 /* char to avoid alignment issues */ \ 559 char volatile async_sent; 560 561 #define UV_PREPARE_PRIVATE_FIELDS \ 562 uv_prepare_t* prepare_prev; \ 563 uv_prepare_t* prepare_next; \ 564 uv_prepare_cb prepare_cb; 565 566 #define UV_CHECK_PRIVATE_FIELDS \ 567 uv_check_t* check_prev; \ 568 uv_check_t* check_next; \ 569 uv_check_cb check_cb; 570 571 #define UV_IDLE_PRIVATE_FIELDS \ 572 uv_idle_t* idle_prev; \ 573 uv_idle_t* idle_next; \ 574 uv_idle_cb idle_cb; 575 576 #define UV_HANDLE_PRIVATE_FIELDS \ 577 uv_handle_t* endgame_next; \ 578 unsigned int flags; 579 580 #define UV_GETADDRINFO_PRIVATE_FIELDS \ 581 struct uv__work work_req; \ 582 uv_getaddrinfo_cb getaddrinfo_cb; \ 583 void* alloc; \ 584 WCHAR* node; \ 585 WCHAR* service; \ 586 /* The addrinfoW field is used to store a pointer to the hints, and */ \ 587 /* later on to store the result of GetAddrInfoW. The final result will */ \ 588 /* be converted to struct addrinfo* and stored in the addrinfo field. */ \ 589 struct addrinfoW* addrinfow; \ 590 struct addrinfo* addrinfo; \ 591 int retcode; 592 593 #define UV_GETNAMEINFO_PRIVATE_FIELDS \ 594 struct uv__work work_req; \ 595 uv_getnameinfo_cb getnameinfo_cb; \ 596 struct sockaddr_storage storage; \ 597 int flags; \ 598 char host[NI_MAXHOST]; \ 599 char service[NI_MAXSERV]; \ 600 int retcode; 601 602 #define UV_PROCESS_PRIVATE_FIELDS \ 603 struct uv_process_exit_s { \ 604 UV_REQ_FIELDS \ 605 } exit_req; \ 606 void* unused; /* TODO: retained for ABI compat; remove this in v2.x. */ \ 607 int exit_signal; \ 608 HANDLE wait_handle; \ 609 HANDLE process_handle; \ 610 volatile char exit_cb_pending; 611 612 #define UV_FS_PRIVATE_FIELDS \ 613 struct uv__work work_req; \ 614 int flags; \ 615 DWORD sys_errno_; \ 616 union { \ 617 /* TODO: remove me in 0.9. */ \ 618 WCHAR* pathw; \ 619 int fd; \ 620 } file; \ 621 union { \ 622 struct { \ 623 int mode; \ 624 WCHAR* new_pathw; \ 625 int file_flags; \ 626 int fd_out; \ 627 unsigned int nbufs; \ 628 uv_buf_t* bufs; \ 629 int64_t offset; \ 630 uv_buf_t bufsml[4]; \ 631 } info; \ 632 struct { \ 633 double atime; \ 634 double mtime; \ 635 } time; \ 636 } fs; 637 638 #define UV_WORK_PRIVATE_FIELDS \ 639 struct uv__work work_req; 640 641 #define UV_FS_EVENT_PRIVATE_FIELDS \ 642 struct uv_fs_event_req_s { \ 643 UV_REQ_FIELDS \ 644 } req; \ 645 HANDLE dir_handle; \ 646 int req_pending; \ 647 uv_fs_event_cb cb; \ 648 WCHAR* filew; \ 649 WCHAR* short_filew; \ 650 WCHAR* dirw; \ 651 char* buffer; 652 653 #define UV_SIGNAL_PRIVATE_FIELDS \ 654 RB_ENTRY(uv_signal_s) tree_entry; \ 655 struct uv_req_s signal_req; \ 656 unsigned long pending_signum; 657 658 #ifndef F_OK 659 #define F_OK 0 660 #endif 661 #ifndef R_OK 662 #define R_OK 4 663 #endif 664 #ifndef W_OK 665 #define W_OK 2 666 #endif 667 #ifndef X_OK 668 #define X_OK 1 669 #endif 670 671 /* fs open() flags supported on this platform: */ 672 #define UV_FS_O_APPEND _O_APPEND 673 #define UV_FS_O_CREAT _O_CREAT 674 #define UV_FS_O_EXCL _O_EXCL 675 #define UV_FS_O_FILEMAP 0x20000000 676 #define UV_FS_O_RANDOM _O_RANDOM 677 #define UV_FS_O_RDONLY _O_RDONLY 678 #define UV_FS_O_RDWR _O_RDWR 679 #define UV_FS_O_SEQUENTIAL _O_SEQUENTIAL 680 #define UV_FS_O_SHORT_LIVED _O_SHORT_LIVED 681 #define UV_FS_O_TEMPORARY _O_TEMPORARY 682 #define UV_FS_O_TRUNC _O_TRUNC 683 #define UV_FS_O_WRONLY _O_WRONLY 684 685 /* fs open() flags supported on other platforms (or mapped on this platform): */ 686 #define UV_FS_O_DIRECT 0x02000000 /* FILE_FLAG_NO_BUFFERING */ 687 #define UV_FS_O_DIRECTORY 0 688 #define UV_FS_O_DSYNC 0x04000000 /* FILE_FLAG_WRITE_THROUGH */ 689 #define UV_FS_O_EXLOCK 0x10000000 /* EXCLUSIVE SHARING MODE */ 690 #define UV_FS_O_NOATIME 0 691 #define UV_FS_O_NOCTTY 0 692 #define UV_FS_O_NOFOLLOW 0 693 #define UV_FS_O_NONBLOCK 0 694 #define UV_FS_O_SYMLINK 0 695 #define UV_FS_O_SYNC 0x08000000 /* FILE_FLAG_WRITE_THROUGH */ 696