summaryrefslogtreecommitdiffstats
path: root/Utilities/cmlibuv/src/win
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-02-22 00:38:46 (GMT)
committerBrad King <brad.king@kitware.com>2017-02-22 00:40:27 (GMT)
commit741b7621b3c71406359d75098f9bdf8d3567662f (patch)
tree67bdab23eb2238c175282a275ec08f2dd9431226 /Utilities/cmlibuv/src/win
parent3ccad39000281c40e2a7a5e078adc4f977e462dd (diff)
parent1f661e87a6a8304edb77bd30b546e5d113477c59 (diff)
downloadCMake-741b7621b3c71406359d75098f9bdf8d3567662f.zip
CMake-741b7621b3c71406359d75098f9bdf8d3567662f.tar.gz
CMake-741b7621b3c71406359d75098f9bdf8d3567662f.tar.bz2
Merge branch 'upstream-libuv' into update-libuv
* upstream-libuv: libuv 2017-02-21 (52ae8264)
Diffstat (limited to 'Utilities/cmlibuv/src/win')
-rw-r--r--Utilities/cmlibuv/src/win/core.c4
-rw-r--r--Utilities/cmlibuv/src/win/error.c1
-rw-r--r--Utilities/cmlibuv/src/win/fs-event.c3
-rw-r--r--Utilities/cmlibuv/src/win/fs.c4
-rw-r--r--Utilities/cmlibuv/src/win/getaddrinfo.c3
-rw-r--r--Utilities/cmlibuv/src/win/process-stdio.c1
-rw-r--r--Utilities/cmlibuv/src/win/process.c2
-rw-r--r--Utilities/cmlibuv/src/win/signal.c118
-rw-r--r--Utilities/cmlibuv/src/win/tty.c91
-rw-r--r--Utilities/cmlibuv/src/win/winapi.h4
10 files changed, 74 insertions, 157 deletions
diff --git a/Utilities/cmlibuv/src/win/core.c b/Utilities/cmlibuv/src/win/core.c
index 9d00afc..e84186d 100644
--- a/Utilities/cmlibuv/src/win/core.c
+++ b/Utilities/cmlibuv/src/win/core.c
@@ -35,10 +35,6 @@
#include "handle-inl.h"
#include "req-inl.h"
-
-static uv_loop_t default_loop_struct;
-static uv_loop_t* default_loop_ptr;
-
/* uv_once initialization guards */
static uv_once_t uv_init_guard_ = UV_ONCE_INIT;
diff --git a/Utilities/cmlibuv/src/win/error.c b/Utilities/cmlibuv/src/win/error.c
index c512f35..642d111 100644
--- a/Utilities/cmlibuv/src/win/error.c
+++ b/Utilities/cmlibuv/src/win/error.c
@@ -71,6 +71,7 @@ int uv_translate_sys_error(int sys_errno) {
switch (sys_errno) {
case ERROR_NOACCESS: return UV_EACCES;
case WSAEACCES: return UV_EACCES;
+ case ERROR_ELEVATION_REQUIRED: return UV_EACCES;
case ERROR_ADDRESS_ALREADY_ASSOCIATED: return UV_EADDRINUSE;
case WSAEADDRINUSE: return UV_EADDRINUSE;
case WSAEADDRNOTAVAIL: return UV_EADDRNOTAVAIL;
diff --git a/Utilities/cmlibuv/src/win/fs-event.c b/Utilities/cmlibuv/src/win/fs-event.c
index 03e4adc..05fc1d0 100644
--- a/Utilities/cmlibuv/src/win/fs-event.c
+++ b/Utilities/cmlibuv/src/win/fs-event.c
@@ -188,7 +188,6 @@ int uv_fs_event_start(uv_fs_event_t* handle,
if (is_path_dir) {
/* path is a directory, so that's the directory that we will watch. */
- handle->dirw = pathw;
dir_to_watch = pathw;
} else {
/*
@@ -274,6 +273,8 @@ int uv_fs_event_start(uv_fs_event_t* handle,
goto error;
}
+ assert(is_path_dir ? pathw != NULL : pathw == NULL);
+ handle->dirw = pathw;
handle->req_pending = 1;
return 0;
diff --git a/Utilities/cmlibuv/src/win/fs.c b/Utilities/cmlibuv/src/win/fs.c
index f1711ac..6902d4f 100644
--- a/Utilities/cmlibuv/src/win/fs.c
+++ b/Utilities/cmlibuv/src/win/fs.c
@@ -123,7 +123,7 @@ INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
const char* new_path, const int copy_path) {
char* buf;
char* pos;
- ssize_t buf_sz = 0, path_len, pathw_len = 0, new_pathw_len = 0;
+ ssize_t buf_sz = 0, path_len = 0, pathw_len = 0, new_pathw_len = 0;
/* new_path can only be set if path is also set. */
assert(new_path == NULL || path != NULL);
@@ -403,7 +403,6 @@ void fs__open(uv_fs_t* req) {
switch (flags & (_O_RDONLY | _O_WRONLY | _O_RDWR)) {
case _O_RDONLY:
access = FILE_GENERIC_READ;
- attributes |= FILE_FLAG_BACKUP_SEMANTICS;
break;
case _O_WRONLY:
access = FILE_GENERIC_WRITE;
@@ -418,7 +417,6 @@ void fs__open(uv_fs_t* req) {
if (flags & _O_APPEND) {
access &= ~FILE_WRITE_DATA;
access |= FILE_APPEND_DATA;
- attributes &= ~FILE_FLAG_BACKUP_SEMANTICS;
}
/*
diff --git a/Utilities/cmlibuv/src/win/getaddrinfo.c b/Utilities/cmlibuv/src/win/getaddrinfo.c
index 744f8e0..c13bfec 100644
--- a/Utilities/cmlibuv/src/win/getaddrinfo.c
+++ b/Utilities/cmlibuv/src/win/getaddrinfo.c
@@ -262,8 +262,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
int err;
if (req == NULL || (node == NULL && service == NULL)) {
- err = WSAEINVAL;
- goto error;
+ return UV_EINVAL;
}
uv_req_init(loop, (uv_req_t*)req);
diff --git a/Utilities/cmlibuv/src/win/process-stdio.c b/Utilities/cmlibuv/src/win/process-stdio.c
index e3c06f5..032e309 100644
--- a/Utilities/cmlibuv/src/win/process-stdio.c
+++ b/Utilities/cmlibuv/src/win/process-stdio.c
@@ -372,6 +372,7 @@ int uv__stdio_create(uv_loop_t* loop,
case FILE_TYPE_PIPE:
CHILD_STDIO_CRT_FLAGS(buffer, i) = FOPEN | FPIPE;
+ break;
case FILE_TYPE_CHAR:
case FILE_TYPE_REMOTE:
diff --git a/Utilities/cmlibuv/src/win/process.c b/Utilities/cmlibuv/src/win/process.c
index 855c374..bdf88d2 100644
--- a/Utilities/cmlibuv/src/win/process.c
+++ b/Utilities/cmlibuv/src/win/process.c
@@ -492,7 +492,7 @@ WCHAR* quote_cmd_arg(const WCHAR *source, WCHAR *target) {
* input : hello\\"world
* output: "hello\\\\\"world"
* input : hello world\
- * output: "hello world\"
+ * output: "hello world\\"
*/
*(target++) = L'"';
diff --git a/Utilities/cmlibuv/src/win/signal.c b/Utilities/cmlibuv/src/win/signal.c
index 2c64a55..af7974c 100644
--- a/Utilities/cmlibuv/src/win/signal.c
+++ b/Utilities/cmlibuv/src/win/signal.c
@@ -30,12 +30,14 @@
RB_HEAD(uv_signal_tree_s, uv_signal_s);
static struct uv_signal_tree_s uv__signal_tree = RB_INITIALIZER(uv__signal_tree);
-static ssize_t volatile uv__signal_control_handler_refs = 0;
static CRITICAL_SECTION uv__signal_lock;
+static BOOL WINAPI uv__signal_control_handler(DWORD type);
void uv_signals_init() {
InitializeCriticalSection(&uv__signal_lock);
+ if (!SetConsoleCtrlHandler(uv__signal_control_handler, TRUE))
+ abort();
}
@@ -125,102 +127,6 @@ static BOOL WINAPI uv__signal_control_handler(DWORD type) {
}
-static int uv__signal_register_control_handler() {
- /* When this function is called, the uv__signal_lock must be held. */
-
- /* If the console control handler has already been hooked, just add a */
- /* reference. */
- if (uv__signal_control_handler_refs > 0) {
- uv__signal_control_handler_refs++;
- return 0;
- }
-
- if (!SetConsoleCtrlHandler(uv__signal_control_handler, TRUE))
- return GetLastError();
-
- uv__signal_control_handler_refs++;
-
- return 0;
-}
-
-
-static void uv__signal_unregister_control_handler() {
- /* When this function is called, the uv__signal_lock must be held. */
- BOOL r;
-
- /* Don't unregister if the number of console control handlers exceeds one. */
- /* Just remove a reference in that case. */
- if (uv__signal_control_handler_refs > 1) {
- uv__signal_control_handler_refs--;
- return;
- }
-
- assert(uv__signal_control_handler_refs == 1);
-
- r = SetConsoleCtrlHandler(uv__signal_control_handler, FALSE);
- /* This should never fail; if it does it is probably a bug in libuv. */
- assert(r);
-
- uv__signal_control_handler_refs--;
-}
-
-
-static int uv__signal_register(int signum) {
- switch (signum) {
- case SIGINT:
- case SIGBREAK:
- case SIGHUP:
- return uv__signal_register_control_handler();
-
- case SIGWINCH:
- /* SIGWINCH is generated in tty.c. No need to register anything. */
- return 0;
-
- case SIGILL:
- case SIGABRT_COMPAT:
- case SIGFPE:
- case SIGSEGV:
- case SIGTERM:
- case SIGABRT:
- /* Signal is never raised. */
- return 0;
-
- default:
- /* Invalid signal. */
- return ERROR_INVALID_PARAMETER;
- }
-}
-
-
-static void uv__signal_unregister(int signum) {
- switch (signum) {
- case SIGINT:
- case SIGBREAK:
- case SIGHUP:
- uv__signal_unregister_control_handler();
- return;
-
- case SIGWINCH:
- /* SIGWINCH is generated in tty.c. No need to unregister anything. */
- return;
-
- case SIGILL:
- case SIGABRT_COMPAT:
- case SIGFPE:
- case SIGSEGV:
- case SIGTERM:
- case SIGABRT:
- /* Nothing is registered for this signal. */
- return;
-
- default:
- /* Libuv bug. */
- assert(0 && "Invalid signum");
- return;
- }
-}
-
-
int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle) {
uv_req_t* req;
@@ -247,8 +153,6 @@ int uv_signal_stop(uv_signal_t* handle) {
EnterCriticalSection(&uv__signal_lock);
- uv__signal_unregister(handle->signum);
-
removed_handle = RB_REMOVE(uv_signal_tree_s, &uv__signal_tree, handle);
assert(removed_handle == handle);
@@ -262,14 +166,9 @@ int uv_signal_stop(uv_signal_t* handle) {
int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) {
- int err;
-
- /* If the user supplies signum == 0, then return an error already. If the */
- /* signum is otherwise invalid then uv__signal_register will find out */
- /* eventually. */
- if (signum == 0) {
+ /* Test for invalid signal values. */
+ if (signum != SIGWINCH && (signum <= 0 || signum >= NSIG))
return UV_EINVAL;
- }
/* Short circuit: if the signal watcher is already watching {signum} don't */
/* go through the process of deregistering and registering the handler. */
@@ -289,13 +188,6 @@ int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) {
EnterCriticalSection(&uv__signal_lock);
- err = uv__signal_register(signum);
- if (err) {
- /* Uh-oh, didn't work. */
- LeaveCriticalSection(&uv__signal_lock);
- return uv_translate_sys_error(err);
- }
-
handle->signum = signum;
RB_INSERT(uv_signal_tree_s, &uv__signal_tree, handle);
diff --git a/Utilities/cmlibuv/src/win/tty.c b/Utilities/cmlibuv/src/win/tty.c
index 18d68d0..1b7adf6 100644
--- a/Utilities/cmlibuv/src/win/tty.c
+++ b/Utilities/cmlibuv/src/win/tty.c
@@ -56,6 +56,7 @@
#define ANSI_BACKSLASH_SEEN 0x80
#define MAX_INPUT_BUFFER_LENGTH 8192
+#define MAX_CONSOLE_CHAR 8192
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
@@ -1003,6 +1004,9 @@ int uv_tty_read_start(uv_tty_t* handle, uv_alloc_cb alloc_cb,
if (handle->tty.rd.last_key_len > 0) {
SET_REQ_SUCCESS(&handle->read_req);
uv_insert_pending_req(handle->loop, (uv_req_t*) &handle->read_req);
+ /* Make sure no attempt is made to insert it again until it's handled. */
+ handle->flags |= UV_HANDLE_READ_PENDING;
+ handle->reqs_pending++;
return 0;
}
@@ -1616,17 +1620,29 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
DWORD* error) {
/* We can only write 8k characters at a time. Windows can't handle */
/* much more characters in a single console write anyway. */
- WCHAR utf16_buf[8192];
+ WCHAR utf16_buf[MAX_CONSOLE_CHAR];
+ WCHAR* utf16_buffer;
DWORD utf16_buf_used = 0;
- unsigned int i;
-
-#define FLUSH_TEXT() \
- do { \
- if (utf16_buf_used > 0) { \
- uv_tty_emit_text(handle, utf16_buf, utf16_buf_used, error); \
- utf16_buf_used = 0; \
- } \
- } while (0)
+ unsigned int i, len, max_len, pos;
+ int allocate = 0;
+
+#define FLUSH_TEXT() \
+ do { \
+ pos = 0; \
+ do { \
+ len = utf16_buf_used - pos; \
+ if (len > MAX_CONSOLE_CHAR) \
+ len = MAX_CONSOLE_CHAR; \
+ uv_tty_emit_text(handle, &utf16_buffer[pos], len, error); \
+ pos += len; \
+ } while (pos < utf16_buf_used); \
+ if (allocate) { \
+ uv__free(utf16_buffer); \
+ allocate = 0; \
+ utf16_buffer = utf16_buf; \
+ } \
+ utf16_buf_used = 0; \
+ } while (0)
#define ENSURE_BUFFER_SPACE(wchars_needed) \
if (wchars_needed > ARRAY_SIZE(utf16_buf) - utf16_buf_used) { \
@@ -1644,38 +1660,47 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
/* state. */
*error = ERROR_SUCCESS;
+ utf16_buffer = utf16_buf;
+
uv_sem_wait(&uv_tty_output_lock);
for (i = 0; i < nbufs; i++) {
uv_buf_t buf = bufs[i];
unsigned int j;
- if (uv__vterm_state == UV_SUPPORTED) {
- utf16_buf_used = MultiByteToWideChar(CP_UTF8,
- 0,
- buf.base,
- buf.len,
- NULL,
- 0);
+ if (uv__vterm_state == UV_SUPPORTED && buf.len > 0) {
+ utf16_buf_used = MultiByteToWideChar(CP_UTF8,
+ 0,
+ buf.base,
+ buf.len,
+ NULL,
+ 0);
+
+ if (utf16_buf_used == 0) {
+ *error = GetLastError();
+ break;
+ }
- if (utf16_buf_used == 0) {
- *error = GetLastError();
- break;
- }
+ max_len = (utf16_buf_used + 1) * sizeof(WCHAR);
+ allocate = max_len > MAX_CONSOLE_CHAR;
+ if (allocate)
+ utf16_buffer = uv__malloc(max_len);
+ if (!MultiByteToWideChar(CP_UTF8,
+ 0,
+ buf.base,
+ buf.len,
+ utf16_buffer,
+ utf16_buf_used)) {
+ if (allocate)
+ uv__free(utf16_buffer);
+ *error = GetLastError();
+ break;
+ }
- if (!MultiByteToWideChar(CP_UTF8,
- 0,
- buf.base,
- buf.len,
- utf16_buf,
- utf16_buf_used)) {
- *error = GetLastError();
- break;
- }
+ FLUSH_TEXT();
- FLUSH_TEXT();
- continue;
- }
+ continue;
+ }
for (j = 0; j < buf.len; j++) {
unsigned char c = buf.base[j];
diff --git a/Utilities/cmlibuv/src/win/winapi.h b/Utilities/cmlibuv/src/win/winapi.h
index 597a93d..4b0eeca 100644
--- a/Utilities/cmlibuv/src/win/winapi.h
+++ b/Utilities/cmlibuv/src/win/winapi.h
@@ -4615,6 +4615,10 @@ typedef NTSTATUS (NTAPI *sNtQueryDirectoryFile)
#endif
/* from winerror.h */
+#ifndef ERROR_ELEVATION_REQUIRED
+# define ERROR_ELEVATION_REQUIRED 740
+#endif
+
#ifndef ERROR_SYMLINK_NOT_SUPPORTED
# define ERROR_SYMLINK_NOT_SUPPORTED 1464
#endif