uv-win.h 30 KB

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