1
0

win.h 32 KB

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