win.h 32 KB

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