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