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