Skip to content

Commit 6c614fe

Browse files
committed
Upgrade libuv to 65f71a2
1 parent 89bed19 commit 6c614fe

File tree

12 files changed

+267
-16
lines changed

12 files changed

+267
-16
lines changed

deps/uv/.gitignore

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
/build/gyp
1212

1313
/test/run-tests
14+
/test/run-tests.exe
1415
/test/run-tests.dSYM
1516
/test/run-benchmarks
17+
/test/run-benchmarks.exe
1618
/test/run-benchmarks.dSYM
1719

1820
*.sln
@@ -22,6 +24,6 @@
2224
*.vcxproj.user
2325
_UpgradeReport_Files/
2426
UpgradeLog*.XML
25-
build/Debug
26-
build/Release
27-
build/ipch
27+
Debug
28+
Release
29+
ipch

deps/uv/BSDmakefile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
all:
2+
@echo "I need GNU make. Please run \`gmake\` instead."

deps/uv/all.gyp

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
'src/win/handle.c',
143143
'src/win/internal.h',
144144
'src/win/loop-watcher.c',
145+
'src/win/ntdll.h',
145146
'src/win/pipe.c',
146147
'src/win/process.c',
147148
'src/win/req.c',
@@ -150,6 +151,7 @@
150151
'src/win/tcp.c',
151152
'src/win/timer.c',
152153
'src/win/util.c',
154+
'src/win/winapi.c',
153155
]
154156
}, { # Not Windows i.e. POSIX
155157
'cflags': [

deps/uv/config-unix.mk

+7-1
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,14 @@ endif
7474

7575
# Need _GNU_SOURCE for strdup?
7676
RUNNER_CFLAGS=$(CFLAGS) -D_GNU_SOURCE
77+
RUNNER_LINKFLAGS=$(LINKFLAGS)
78+
79+
ifeq (SunOS,$(uname_S))
80+
RUNNER_LINKFLAGS += -pthreads
81+
else
82+
RUNNER_LINKFLAGS += -pthread
83+
endif
7784

78-
RUNNER_LINKFLAGS=$(LINKFLAGS) -pthreads
7985
RUNNER_LIBS=
8086
RUNNER_SRC=test/runner-unix.c
8187

deps/uv/src/eio/config_freebsd.h

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
/* fdatasync(2) is available */
88
/* #undef HAVE_FDATASYNC */
99

10+
/* utimes(2) is available */
11+
#define HAVE_UTIMES 1
12+
1013
/* futimes(2) is available */
1114
#define HAVE_FUTIMES 1
1215

deps/uv/src/uv-unix.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@
4848
#include <linux/version.h>
4949
/* pipe2() requires linux >= 2.6.27 and glibc >= 2.9 */
5050
#define HAVE_PIPE2 \
51-
defined(LINUX_VERSION_CODE) && defined(__GLIBC_PREREQ) && LINUX_VERSION_CODE >= 0x2061B && __GLIBC_PREREQ(2, 9))
51+
defined(LINUX_VERSION_CODE) && defined(__GLIBC_PREREQ) && \
52+
LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) && __GLIBC_PREREQ(2, 9))
5253
#endif
5354

55+
/* XXX disabling HAVE_PIPE2 for now can't compile on 2.6.18 */
56+
#undef HAVE_PIPE2
57+
5458
#ifdef __sun
5559
# include <sys/types.h>
5660
# include <sys/wait.h>

deps/uv/src/win/core.c

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ void uv_init() {
7070
/* Initialize winsock */
7171
uv_winsock_startup();
7272

73+
/* Fetch winapi function pointers */
74+
uv_winapi_init();
75+
7376
/* Intialize event loop */
7477
uv_loop_init();
7578
}

deps/uv/src/win/internal.h

+11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525
#include "uv.h"
2626
#include "../uv-common.h"
27+
2728
#include "tree.h"
29+
#include "ntdll.h"
2830

2931

3032
/*
@@ -234,4 +236,13 @@ void uv_set_sys_error(int sys_errno);
234236
void uv_set_error(uv_err_code code, int sys_errno);
235237

236238

239+
/*
240+
* Windows api functions that we need to retrieve dynamically
241+
*/
242+
void uv_winapi_init();
243+
244+
extern sRtlNtStatusToDosError pRtlNtStatusToDosError;
245+
extern sNtQueryInformationFile pNtQueryInformationFile;
246+
247+
237248
#endif /* UV_WIN_INTERNAL_H_ */

deps/uv/src/win/ntdll.h

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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 UV_WIN_NTDLL_H_
23+
#define UV_WIN_NTDLL_H_
24+
25+
#include <windows.h>
26+
27+
28+
#ifndef _NTDEF_
29+
typedef LONG NTSTATUS;
30+
typedef NTSTATUS *PNTSTATUS;
31+
#endif
32+
33+
34+
#define STATUS_SUCCESS ((NTSTATUS)0x0)
35+
36+
37+
typedef struct _IO_STATUS_BLOCK {
38+
union {
39+
NTSTATUS Status;
40+
PVOID Pointer;
41+
} DUMMYUNIONNAME;
42+
ULONG_PTR Information;
43+
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
44+
45+
46+
typedef struct _FILE_PIPE_LOCAL_INFORMATION {
47+
ULONG NamedPipeType;
48+
ULONG NamedPipeConfiguration;
49+
ULONG MaximumInstances;
50+
ULONG CurrentInstances;
51+
ULONG InboundQuota;
52+
ULONG ReadDataAvailable;
53+
ULONG OutboundQuota;
54+
ULONG WriteQuotaAvailable;
55+
ULONG NamedPipeState;
56+
ULONG NamedPipeEnd;
57+
} FILE_PIPE_LOCAL_INFORMATION, *PFILE_PIPE_LOCAL_INFORMATION;
58+
59+
60+
typedef enum _FILE_INFORMATION_CLASS {
61+
FileDirectoryInformation = 1,
62+
FileFullDirectoryInformation,
63+
FileBothDirectoryInformation,
64+
FileBasicInformation,
65+
FileStandardInformation,
66+
FileInternalInformation,
67+
FileEaInformation,
68+
FileAccessInformation,
69+
FileNameInformation,
70+
FileRenameInformation,
71+
FileLinkInformation,
72+
FileNamesInformation,
73+
FileDispositionInformation,
74+
FilePositionInformation,
75+
FileFullEaInformation,
76+
FileModeInformation,
77+
FileAlignmentInformation,
78+
FileAllInformation,
79+
FileAllocationInformation,
80+
FileEndOfFileInformation,
81+
FileAlternateNameInformation,
82+
FileStreamInformation,
83+
FilePipeInformation,
84+
FilePipeLocalInformation,
85+
FilePipeRemoteInformation,
86+
FileMailslotQueryInformation,
87+
FileMailslotSetInformation,
88+
FileCompressionInformation,
89+
FileObjectIdInformation,
90+
FileCompletionInformation,
91+
FileMoveClusterInformation,
92+
FileQuotaInformation,
93+
FileReparsePointInformation,
94+
FileNetworkOpenInformation,
95+
FileAttributeTagInformation,
96+
FileTrackingInformation,
97+
FileIdBothDirectoryInformation,
98+
FileIdFullDirectoryInformation,
99+
FileValidDataLengthInformation,
100+
FileShortNameInformation,
101+
FileIoCompletionNotificationInformation,
102+
FileIoStatusBlockRangeInformation,
103+
FileIoPriorityHintInformation,
104+
FileSfioReserveInformation,
105+
FileSfioVolumeInformation,
106+
FileHardLinkInformation,
107+
FileProcessIdsUsingFileInformation,
108+
FileNormalizedNameInformation,
109+
FileNetworkPhysicalNameInformation,
110+
FileIdGlobalTxDirectoryInformation,
111+
FileIsRemoteDeviceInformation,
112+
FileAttributeCacheInformation,
113+
FileNumaNodeInformation,
114+
FileStandardLinkInformation,
115+
FileRemoteProtocolInformation,
116+
FileMaximumInformation
117+
} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
118+
119+
120+
typedef ULONG (NTAPI *sRtlNtStatusToDosError)
121+
(NTSTATUS Status);
122+
123+
typedef NTSTATUS (NTAPI *sNtQueryInformationFile)
124+
(HANDLE FileHandle,
125+
PIO_STATUS_BLOCK IoStatusBlock,
126+
PVOID FileInformation,
127+
ULONG Length,
128+
FILE_INFORMATION_CLASS FileInformationClass);
129+
130+
#endif /* UV_WIN_NTDLL_H_ */

deps/uv/src/win/pipe.c

+45-9
Original file line numberDiff line numberDiff line change
@@ -173,29 +173,63 @@ void uv_pipe_endgame(uv_pipe_t* handle) {
173173
int status;
174174
unsigned int uv_alloced;
175175
DWORD result;
176+
uv_shutdown_t* req;
177+
NTSTATUS nt_status;
178+
IO_STATUS_BLOCK io_status;
179+
FILE_PIPE_LOCAL_INFORMATION pipe_info;
180+
176181

177182
if (handle->flags & UV_HANDLE_SHUTTING &&
178183
!(handle->flags & UV_HANDLE_SHUT) &&
179184
handle->write_reqs_pending == 0) {
185+
req = handle->shutdown_req;
186+
187+
/* Try to avoid flushing the pipe buffer in the thread pool. */
188+
nt_status = pNtQueryInformationFile(handle->handle,
189+
&io_status,
190+
&pipe_info,
191+
sizeof pipe_info,
192+
FilePipeLocalInformation);
193+
194+
if (nt_status != STATUS_SUCCESS) {
195+
/* Failure */
196+
handle->flags &= ~UV_HANDLE_SHUTTING;
197+
if (req->cb) {
198+
uv_set_sys_error(pRtlNtStatusToDosError(nt_status));
199+
req->cb(req, -1);
200+
}
201+
DECREASE_PENDING_REQ_COUNT(handle);
202+
return;
203+
}
204+
205+
if (pipe_info.OutboundQuota == pipe_info.WriteQuotaAvailable) {
206+
/* Short-circuit, no need to call FlushFileBuffers. */
207+
handle->flags |= UV_HANDLE_SHUT;
208+
if (req->cb) {
209+
req->cb(req, 0);
210+
}
211+
DECREASE_PENDING_REQ_COUNT(handle);
212+
return;
213+
}
180214

181-
/* TODO: Try to avoid using the thread pool. Maybe we can somehow figure */
182-
/* out how much data is left in the kernel buffer? */
215+
/* Run FlushFileBuffers in the thhead pool. */
183216
result = QueueUserWorkItem(pipe_shutdown_thread_proc,
184-
handle->shutdown_req,
217+
req,
185218
WT_EXECUTELONGFUNCTION);
186219
if (result) {
187220
/* Mark the handle as shut now to avoid going through this again. */
188221
handle->flags |= UV_HANDLE_SHUT;
189222

190223
} else {
191224
/* Failure. */
192-
uv_set_sys_error(GetLastError());
193-
handle->shutdown_req->cb(handle->shutdown_req, -1);
194225
handle->flags &= ~UV_HANDLE_SHUTTING;
226+
if (req->cb) {
227+
uv_set_sys_error(GetLastError());
228+
req->cb(req, -1);
229+
}
195230
DECREASE_PENDING_REQ_COUNT(handle);
231+
return;
196232
}
197-
198-
return;
199233
}
200234

201235
if (handle->flags & UV_HANDLE_CLOSING &&
@@ -333,6 +367,8 @@ static DWORD WINAPI pipe_connect_thread_proc(void* parameter) {
333367
if (pipeHandle != INVALID_HANDLE_VALUE) {
334368
break;
335369
}
370+
371+
SwitchToThread();
336372
}
337373

338374
if (pipeHandle != INVALID_HANDLE_VALUE && !uv_set_pipe_handle(handle, pipeHandle)) {
@@ -754,7 +790,7 @@ void uv_process_pipe_read_req(uv_pipe_t* handle, uv_req_t* req) {
754790
}
755791

756792
if (avail == 0) {
757-
// Nothing to read after all
793+
/* There is nothing to read after all. */
758794
break;
759795
}
760796

@@ -863,7 +899,7 @@ void uv_process_pipe_shutdown_req(uv_pipe_t* handle, uv_shutdown_t* req) {
863899
handle->handle = INVALID_HANDLE_VALUE;
864900

865901
if (req->cb) {
866-
((uv_shutdown_cb) req->cb)(req, 0);
902+
req->cb(req, 0);
867903
}
868904

869905
DECREASE_PENDING_REQ_COUNT(handle);

deps/uv/src/win/winapi.c

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
#include <assert.h>
23+
24+
#include "uv.h"
25+
#include "../uv-common.h"
26+
#include "internal.h"
27+
28+
29+
sRtlNtStatusToDosError pRtlNtStatusToDosError;
30+
sNtQueryInformationFile pNtQueryInformationFile;
31+
32+
33+
void uv_winapi_init() {
34+
HMODULE module;
35+
36+
module = GetModuleHandleA("ntdll.dll");
37+
if (module == NULL) {
38+
uv_fatal_error(GetLastError(), "GetModuleHandleA");
39+
}
40+
41+
pRtlNtStatusToDosError = (sRtlNtStatusToDosError) GetProcAddress(module,
42+
"RtlNtStatusToDosError");
43+
if (pRtlNtStatusToDosError == NULL) {
44+
uv_fatal_error(GetLastError(), "GetProcAddress");
45+
}
46+
47+
pNtQueryInformationFile = (sNtQueryInformationFile) GetProcAddress(module,
48+
"NtQueryInformationFile");
49+
if (pNtQueryInformationFile == NULL) {
50+
uv_fatal_error(GetLastError(), "GetProcAddress");
51+
}
52+
}

0 commit comments

Comments
 (0)