uv-win.h 32 KB

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