From 8b5a2c4f610a33ae1d7e68c056e127a387459a61 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 10 Feb 2019 11:55:38 -0500 Subject: [PATCH] deps: upgrade to libuv 1.26.0 Notable changes: - A bug that could result in 100% CPU utilization in Node has been fixed (https://github.com/libuv/libuv/issues/2162) - Node's report module will now include the entire Windows product name (https://github.com/libuv/libuv/pull/2170) PR-URL: https://github.com/nodejs/node/pull/26037 Fixes: https://github.com/nodejs/node/issues/26013 Fixes: https://github.com/nodejs/node/issues/25875 Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: Jeremiah Senkpiel --- deps/uv/AUTHORS | 3 + deps/uv/CMakeLists.txt | 1 + deps/uv/ChangeLog | 23 ++ deps/uv/Makefile.am | 1 + deps/uv/configure.ac | 2 +- deps/uv/docs/src/misc.rst | 9 +- deps/uv/docs/src/threading.rst | 29 +++ deps/uv/include/uv.h | 29 +++ deps/uv/include/uv/unix.h | 3 +- deps/uv/include/uv/version.h | 2 +- deps/uv/src/unix/aix.c | 1 + deps/uv/src/unix/core.c | 15 +- deps/uv/src/unix/kqueue.c | 1 + deps/uv/src/unix/linux-core.c | 1 + deps/uv/src/unix/os390.c | 1 + deps/uv/src/unix/pipe.c | 2 +- deps/uv/src/unix/posix-poll.c | 2 + deps/uv/src/unix/sunos.c | 1 + deps/uv/src/unix/tcp.c | 14 +- deps/uv/src/unix/thread.c | 25 +- deps/uv/src/win/thread.c | 27 ++- deps/uv/src/win/tty.c | 4 +- deps/uv/src/win/util.c | 80 +++++-- deps/uv/test/test-gethostname.c | 8 +- deps/uv/test/test-list.h | 8 + deps/uv/test/test-thread.c | 57 ++++- deps/uv/test/test-tty-duplicate-key.c | 321 ++++++++++++++++++++++++++ deps/uv/test/test.gyp | 1 + 28 files changed, 613 insertions(+), 58 deletions(-) create mode 100644 deps/uv/test/test-tty-duplicate-key.c diff --git a/deps/uv/AUTHORS b/deps/uv/AUTHORS index 3317efeb1ac8af..25447eb0e6e834 100644 --- a/deps/uv/AUTHORS +++ b/deps/uv/AUTHORS @@ -366,3 +366,6 @@ ptlomholt Victor Costan sid Kevin Adler +Stephen Belanger +yeyuanfeng +erw7 diff --git a/deps/uv/CMakeLists.txt b/deps/uv/CMakeLists.txt index fa268a13ed6661..5dc61eb825a2c5 100644 --- a/deps/uv/CMakeLists.txt +++ b/deps/uv/CMakeLists.txt @@ -149,6 +149,7 @@ set(uv_test_sources test/test-timer-from-check.c test/test-timer.c test/test-tmpdir.c + test/test-tty-duplicate-key.c test/test-tty.c test/test-udp-alloc-cb-fail.c test/test-udp-bind.c diff --git a/deps/uv/ChangeLog b/deps/uv/ChangeLog index 3652829ce7790b..7f02045e03ef7b 100644 --- a/deps/uv/ChangeLog +++ b/deps/uv/ChangeLog @@ -1,3 +1,26 @@ +2019.02.11, Version 1.26.0 (Stable), 8669d8d3e93cddb62611b267ef62a3ddb5ba3ca0 + +Changes since version 1.25.0: + +* doc: fix uv_get_free_memory doc (Stephen Belanger) + +* unix: fix epoll cpu 100% issue (yeyuanfeng) + +* openbsd,tcp: special handling of EINVAL on connect (ptlomholt) + +* win: simplify registry closing in uv_cpu_info() (cjihrig) + +* src,include: define UV_MAXHOSTNAMESIZE (cjihrig) + +* win: return product name in uv_os_uname() version (cjihrig) + +* thread: allow specifying stack size for new thread (Anna Henningsen) + +* win: fix duplicate tty vt100 fn key (erw7) + +* unix: don't attempt to invalidate invalid fd (Ben Noordhuis) + + 2019.01.19, Version 1.25.0 (Stable), 4a10a9d425863330af199e4b74bd688e62d945f1 Changes since version 1.24.1: diff --git a/deps/uv/Makefile.am b/deps/uv/Makefile.am index d8a01574f3cf2c..7e49d8ad0bee16 100644 --- a/deps/uv/Makefile.am +++ b/deps/uv/Makefile.am @@ -277,6 +277,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \ test/test-timer-from-check.c \ test/test-timer.c \ test/test-tmpdir.c \ + test/test-tty-duplicate-key.c \ test/test-tty.c \ test/test-udp-alloc-cb-fail.c \ test/test-udp-bind.c \ diff --git a/deps/uv/configure.ac b/deps/uv/configure.ac index ab656c83d23502..931ac3e3615e33 100644 --- a/deps/uv/configure.ac +++ b/deps/uv/configure.ac @@ -13,7 +13,7 @@ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. AC_PREREQ(2.57) -AC_INIT([libuv], [1.25.0], [https://github.com/libuv/libuv/issues]) +AC_INIT([libuv], [1.26.0], [https://github.com/libuv/libuv/issues]) AC_CONFIG_MACRO_DIR([m4]) m4_include([m4/libuv-extra-automake-flags.m4]) m4_include([m4/as_case.m4]) diff --git a/deps/uv/docs/src/misc.rst b/deps/uv/docs/src/misc.rst index 81c03a85303180..14e9acce9abb2b 100644 --- a/deps/uv/docs/src/misc.rst +++ b/deps/uv/docs/src/misc.rst @@ -431,7 +431,10 @@ API .. versionadded:: 1.9.0 -.. uint64_t uv_get_free_memory(void) +.. c:function:: uint64_t uv_get_free_memory(void) + + Gets memory information (in bytes). + .. c:function:: uint64_t uv_get_total_memory(void) Gets memory information (in bytes). @@ -531,6 +534,10 @@ API .. versionadded:: 1.12.0 + .. versionchanged:: 1.26.0 `UV_MAXHOSTNAMESIZE` is available and represents + the maximum `buffer` size required to store a + hostname and terminating `nul` character. + .. c:function:: int uv_os_getpriority(uv_pid_t pid, int* priority) Retrieves the scheduling priority of the process specified by `pid`. The diff --git a/deps/uv/docs/src/threading.rst b/deps/uv/docs/src/threading.rst index 89bb4a6f3ae14e..a5759a38a67f06 100644 --- a/deps/uv/docs/src/threading.rst +++ b/deps/uv/docs/src/threading.rst @@ -55,10 +55,39 @@ API Threads ^^^^^^^ +.. c:type:: uv_thread_options_t + + Options for spawning a new thread (passed to :c:func:`uv_thread_create_ex`). + + :: + + typedef struct uv_process_options_s { + enum { + UV_THREAD_NO_FLAGS = 0x00, + UV_THREAD_HAS_STACK_SIZE = 0x01 + } flags; + size_t stack_size; + } uv_process_options_t; + + More fields may be added to this struct at any time, so its exact + layout and size should not be relied upon. + + .. versionadded:: 1.26.0 + .. c:function:: int uv_thread_create(uv_thread_t* tid, uv_thread_cb entry, void* arg) .. versionchanged:: 1.4.1 returns a UV_E* error code on failure +.. c:function:: int uv_thread_create_ex(uv_thread_t* tid, const uv_thread_options_t* params, uv_thread_cb entry, void* arg) + + Like :c:func:`uv_thread_create`, but additionally specifies options for creating a new thread. + + If `UV_THREAD_HAS_STACK_SIZE` is set, `stack_size` specifies a stack size for the new thread. + `0` indicates that the default value should be used, i.e. behaves as if the flag was not set. + Other values will be rounded up to the nearest page boundary. + + .. versionadded:: 1.26.0 + .. c:function:: uv_thread_t uv_thread_self(void) .. c:function:: int uv_thread_join(uv_thread_t *tid) .. c:function:: int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2) diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h index a46b229dfd166e..1578bbd5682e40 100644 --- a/deps/uv/include/uv.h +++ b/deps/uv/include/uv.h @@ -1144,6 +1144,17 @@ UV_EXTERN int uv_os_getenv(const char* name, char* buffer, size_t* size); UV_EXTERN int uv_os_setenv(const char* name, const char* value); UV_EXTERN int uv_os_unsetenv(const char* name); +#ifdef MAXHOSTNAMELEN +# define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1) +#else + /* + Fallback for the maximum hostname size, including the null terminator. The + Windows gethostname() documentation states that 256 bytes will always be + large enough to hold the null-terminated hostname. + */ +# define UV_MAXHOSTNAMESIZE 256 +#endif + UV_EXTERN int uv_os_gethostname(char* buffer, size_t* size); UV_EXTERN int uv_os_uname(uv_utsname_t* buffer); @@ -1574,6 +1585,24 @@ UV_EXTERN void uv_key_set(uv_key_t* key, void* value); typedef void (*uv_thread_cb)(void* arg); UV_EXTERN int uv_thread_create(uv_thread_t* tid, uv_thread_cb entry, void* arg); + +typedef enum { + UV_THREAD_NO_FLAGS = 0x00, + UV_THREAD_HAS_STACK_SIZE = 0x01 +} uv_thread_create_flags; + +struct uv_thread_options_s { + unsigned int flags; + size_t stack_size; + /* More fields may be added at any time. */ +}; + +typedef struct uv_thread_options_s uv_thread_options_t; + +UV_EXTERN int uv_thread_create_ex(uv_thread_t* tid, + const uv_thread_options_t* params, + uv_thread_cb entry, + void* arg); UV_EXTERN uv_thread_t uv_thread_self(void); UV_EXTERN int uv_thread_join(uv_thread_t *tid); UV_EXTERN int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2); diff --git a/deps/uv/include/uv/unix.h b/deps/uv/include/uv/unix.h index d887d7211f1d1e..2363701b414728 100644 --- a/deps/uv/include/uv/unix.h +++ b/deps/uv/include/uv/unix.h @@ -31,13 +31,14 @@ #include #include #include -#include +#include /* MAXHOSTNAMELEN on Solaris */ #include #include #if !defined(__MVS__) #include +#include /* MAXHOSTNAMELEN on Linux and the BSDs */ #endif #include #include diff --git a/deps/uv/include/uv/version.h b/deps/uv/include/uv/version.h index 136772128ab35a..fa7320cf4d4a11 100644 --- a/deps/uv/include/uv/version.h +++ b/deps/uv/include/uv/version.h @@ -31,7 +31,7 @@ */ #define UV_VERSION_MAJOR 1 -#define UV_VERSION_MINOR 25 +#define UV_VERSION_MINOR 26 #define UV_VERSION_PATCH 0 #define UV_VERSION_IS_RELEASE 1 #define UV_VERSION_SUFFIX "" diff --git a/deps/uv/src/unix/aix.c b/deps/uv/src/unix/aix.c index 337e58e0adc02f..ec1fb8b01e1823 100644 --- a/deps/uv/src/unix/aix.c +++ b/deps/uv/src/unix/aix.c @@ -1041,6 +1041,7 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) { struct poll_ctl pc; assert(loop->watchers != NULL); + assert(fd >= 0); events = (struct pollfd*) loop->watchers[loop->nwatchers]; nfds = (uintptr_t) loop->watchers[loop->nwatchers + 1]; diff --git a/deps/uv/src/unix/core.c b/deps/uv/src/unix/core.c index cd57ce20ba2edb..7e42337b9aae05 100644 --- a/deps/uv/src/unix/core.c +++ b/deps/uv/src/unix/core.c @@ -43,7 +43,6 @@ #include #ifdef __sun -# include /* MAXHOSTNAMELEN on Solaris */ # include # include # include @@ -88,15 +87,6 @@ #include #endif -#if !defined(__MVS__) -#include /* MAXHOSTNAMELEN on Linux and the BSDs */ -#endif - -/* Fallback for the maximum hostname length */ -#ifndef MAXHOSTNAMELEN -# define MAXHOSTNAMELEN 256 -#endif - static int uv__run_pending(uv_loop_t* loop); /* Verify that uv_buf_t is ABI-compatible with struct iovec. */ @@ -892,7 +882,8 @@ void uv__io_close(uv_loop_t* loop, uv__io_t* w) { QUEUE_REMOVE(&w->pending_queue); /* Remove stale events for this file descriptor */ - uv__platform_invalidate_fd(loop, w->fd); + if (w->fd != -1) + uv__platform_invalidate_fd(loop, w->fd); } @@ -1291,7 +1282,7 @@ int uv_os_gethostname(char* buffer, size_t* size) { instead by creating a large enough buffer and comparing the hostname length to the size input. */ - char buf[MAXHOSTNAMELEN + 1]; + char buf[UV_MAXHOSTNAMESIZE]; size_t len; if (buffer == NULL || size == NULL || *size == 0) diff --git a/deps/uv/src/unix/kqueue.c b/deps/uv/src/unix/kqueue.c index c24f96e1399c69..38c88d7da732af 100644 --- a/deps/uv/src/unix/kqueue.c +++ b/deps/uv/src/unix/kqueue.c @@ -387,6 +387,7 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) { uintptr_t nfds; assert(loop->watchers != NULL); + assert(fd >= 0); events = (struct kevent*) loop->watchers[loop->nwatchers]; nfds = (uintptr_t) loop->watchers[loop->nwatchers + 1]; diff --git a/deps/uv/src/unix/linux-core.c b/deps/uv/src/unix/linux-core.c index 3341b94e1f26fd..7165fe2fb4dd1b 100644 --- a/deps/uv/src/unix/linux-core.c +++ b/deps/uv/src/unix/linux-core.c @@ -141,6 +141,7 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) { uintptr_t nfds; assert(loop->watchers != NULL); + assert(fd >= 0); events = (struct epoll_event*) loop->watchers[loop->nwatchers]; nfds = (uintptr_t) loop->watchers[loop->nwatchers + 1]; diff --git a/deps/uv/src/unix/os390.c b/deps/uv/src/unix/os390.c index dc146e31108108..70e389ece3bc73 100644 --- a/deps/uv/src/unix/os390.c +++ b/deps/uv/src/unix/os390.c @@ -657,6 +657,7 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) { uintptr_t nfds; assert(loop->watchers != NULL); + assert(fd >= 0); events = (struct epoll_event*) loop->watchers[loop->nwatchers]; nfds = (uintptr_t) loop->watchers[loop->nwatchers + 1]; diff --git a/deps/uv/src/unix/pipe.c b/deps/uv/src/unix/pipe.c index d3b554cfc3d896..228d158800acdc 100644 --- a/deps/uv/src/unix/pipe.c +++ b/deps/uv/src/unix/pipe.c @@ -215,7 +215,7 @@ void uv_pipe_connect(uv_connect_t* req, } if (err == 0) - uv__io_start(handle->loop, &handle->io_watcher, POLLIN | POLLOUT); + uv__io_start(handle->loop, &handle->io_watcher, POLLOUT); out: handle->delayed_error = err; diff --git a/deps/uv/src/unix/posix-poll.c b/deps/uv/src/unix/posix-poll.c index f3181f9b726278..a3b9f2196d5872 100644 --- a/deps/uv/src/unix/posix-poll.c +++ b/deps/uv/src/unix/posix-poll.c @@ -298,6 +298,8 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) { size_t i; + assert(fd >= 0); + if (loop->poll_fds_iterating) { /* uv__io_poll is currently iterating. Just invalidate fd. */ for (i = 0; i < loop->poll_fds_used; i++) diff --git a/deps/uv/src/unix/sunos.c b/deps/uv/src/unix/sunos.c index 2552a019eb474d..75501f7a0a79b6 100644 --- a/deps/uv/src/unix/sunos.c +++ b/deps/uv/src/unix/sunos.c @@ -117,6 +117,7 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) { uintptr_t nfds; assert(loop->watchers != NULL); + assert(fd >= 0); events = (struct port_event*) loop->watchers[loop->nwatchers]; nfds = (uintptr_t) loop->watchers[loop->nwatchers + 1]; diff --git a/deps/uv/src/unix/tcp.c b/deps/uv/src/unix/tcp.c index 2982851dc6eaa1..900839a99dfccc 100644 --- a/deps/uv/src/unix/tcp.c +++ b/deps/uv/src/unix/tcp.c @@ -235,12 +235,16 @@ int uv__tcp_connect(uv_connect_t* req, if (r == -1 && errno != 0) { if (errno == EINPROGRESS) ; /* not an error */ - else if (errno == ECONNREFUSED) - /* If we get a ECONNREFUSED wait until the next tick to report the - * error. Solaris wants to report immediately--other unixes want to - * wait. + else if (errno == ECONNREFUSED +#if defined(__OpenBSD__) + || errno == EINVAL +#endif + ) + /* If we get ECONNREFUSED (Solaris) or EINVAL (OpenBSD) wait until the + * next tick to report the error. Solaris and OpenBSD wants to report + * immediately -- other unixes want to wait. */ - handle->delayed_error = UV__ERR(errno); + handle->delayed_error = UV__ERR(ECONNREFUSED); else return UV__ERR(errno); } diff --git a/deps/uv/src/unix/thread.c b/deps/uv/src/unix/thread.c index 8bcb857610fa98..c17a51fed23efe 100644 --- a/deps/uv/src/unix/thread.c +++ b/deps/uv/src/unix/thread.c @@ -194,13 +194,34 @@ static size_t thread_stack_size(void) { int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) { + uv_thread_options_t params; + params.flags = UV_THREAD_NO_FLAGS; + return uv_thread_create_ex(tid, ¶ms, entry, arg); +} + +int uv_thread_create_ex(uv_thread_t* tid, + const uv_thread_options_t* params, + void (*entry)(void *arg), + void *arg) { int err; - size_t stack_size; pthread_attr_t* attr; pthread_attr_t attr_storage; + size_t pagesize; + size_t stack_size; + + stack_size = + params->flags & UV_THREAD_HAS_STACK_SIZE ? params->stack_size : 0; attr = NULL; - stack_size = thread_stack_size(); + if (stack_size == 0) { + stack_size = thread_stack_size(); + } else { + pagesize = (size_t)getpagesize(); + /* Round up to the nearest page boundary. */ + stack_size = (stack_size + pagesize - 1) &~ (pagesize - 1); + if (stack_size < PTHREAD_STACK_MIN) + stack_size = PTHREAD_STACK_MIN; + } if (stack_size > 0) { attr = &attr_storage; diff --git a/deps/uv/src/win/thread.c b/deps/uv/src/win/thread.c index fd4b7c98688f69..89c53ada755b17 100644 --- a/deps/uv/src/win/thread.c +++ b/deps/uv/src/win/thread.c @@ -112,9 +112,34 @@ static UINT __stdcall uv__thread_start(void* arg) { int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) { + uv_thread_options_t params; + params.flags = UV_THREAD_NO_FLAGS; + return uv_thread_create_ex(tid, ¶ms, entry, arg); +} + +int uv_thread_create_ex(uv_thread_t* tid, + const uv_thread_options_t* params, + void (*entry)(void *arg), + void *arg) { struct thread_ctx* ctx; int err; HANDLE thread; + SYSTEM_INFO sysinfo; + size_t stack_size; + size_t pagesize; + + stack_size = + params->flags & UV_THREAD_HAS_STACK_SIZE ? params->stack_size : 0; + + if (stack_size != 0) { + GetNativeSystemInfo(&sysinfo); + pagesize = (size_t)sysinfo.dwPageSize; + /* Round up to the nearest page boundary. */ + stack_size = (stack_size + pagesize - 1) &~ (pagesize - 1); + + if ((unsigned)stack_size != stack_size) + return UV_EINVAL; + } ctx = uv__malloc(sizeof(*ctx)); if (ctx == NULL) @@ -126,7 +151,7 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) { /* Create the thread in suspended state so we have a chance to pass * its own creation handle to it */ thread = (HANDLE) _beginthreadex(NULL, - 0, + (unsigned)stack_size, uv__thread_start, ctx, CREATE_SUSPENDED, diff --git a/deps/uv/src/win/tty.c b/deps/uv/src/win/tty.c index f38e9a88636e4b..a98fe26335e4b8 100644 --- a/deps/uv/src/win/tty.c +++ b/deps/uv/src/win/tty.c @@ -736,8 +736,8 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle, /* Ignore keyup events, unless the left alt key was held and a valid * unicode character was emitted. */ if (!KEV.bKeyDown && - KEV.wVirtualKeyCode != VK_MENU && - KEV.uChar.UnicodeChar != 0) { + (KEV.wVirtualKeyCode != VK_MENU || + KEV.uChar.UnicodeChar == 0)) { continue; } diff --git a/deps/uv/src/win/util.c b/deps/uv/src/win/util.c index 923789129e92e0..395d958c036958 100644 --- a/deps/uv/src/win/util.c +++ b/deps/uv/src/win/util.c @@ -59,13 +59,6 @@ # define UNLEN 256 #endif -/* - Max hostname length. The Windows gethostname() documentation states that 256 - bytes will always be large enough to hold the null-terminated hostname. -*/ -#ifndef MAXHOSTNAMELEN -# define MAXHOSTNAMELEN 256 -#endif /* Maximum environment variable size, including the terminating null */ #define MAX_ENV_VAR_LENGTH 32767 @@ -684,12 +677,9 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) { NULL, (BYTE*)&cpu_brand, &cpu_brand_size); - if (err != ERROR_SUCCESS) { - RegCloseKey(processor_key); - goto error; - } - RegCloseKey(processor_key); + if (err != ERROR_SUCCESS) + goto error; cpu_info = &cpu_infos[i]; cpu_info->speed = cpu_speed; @@ -1510,7 +1500,7 @@ int uv_os_unsetenv(const char* name) { int uv_os_gethostname(char* buffer, size_t* size) { - char buf[MAXHOSTNAMELEN + 1]; + char buf[UV_MAXHOSTNAMESIZE]; size_t len; if (buffer == NULL || size == NULL || *size == 0) @@ -1634,6 +1624,10 @@ int uv_os_uname(uv_utsname_t* buffer) { https://github.com/gagern/gnulib/blob/master/lib/uname.c */ OSVERSIONINFOW os_info; SYSTEM_INFO system_info; + HKEY registry_key; + WCHAR product_name_w[256]; + DWORD product_name_w_size; + int version_size; int processor_level; int r; @@ -1658,16 +1652,56 @@ int uv_os_uname(uv_utsname_t* buffer) { } /* Populate the version field. */ - if (WideCharToMultiByte(CP_UTF8, - 0, - os_info.szCSDVersion, - -1, - buffer->version, - sizeof(buffer->version), - NULL, - NULL) == 0) { - r = uv_translate_sys_error(GetLastError()); - goto error; + version_size = 0; + r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", + 0, + KEY_QUERY_VALUE, + ®istry_key); + + if (r == ERROR_SUCCESS) { + product_name_w_size = sizeof(product_name_w); + r = RegGetValueW(registry_key, + NULL, + L"ProductName", + RRF_RT_REG_SZ, + NULL, + (PVOID) product_name_w, + &product_name_w_size); + RegCloseKey(registry_key); + + if (r == ERROR_SUCCESS) { + version_size = WideCharToMultiByte(CP_UTF8, + 0, + product_name_w, + -1, + buffer->version, + sizeof(buffer->version), + NULL, + NULL); + if (version_size == 0) { + r = uv_translate_sys_error(GetLastError()); + goto error; + } + } + } + + /* Append service pack information to the version if present. */ + if (os_info.szCSDVersion[0] != L'\0') { + if (version_size > 0) + buffer->version[version_size - 1] = ' '; + + if (WideCharToMultiByte(CP_UTF8, + 0, + os_info.szCSDVersion, + -1, + buffer->version + version_size, + sizeof(buffer->version) - version_size, + NULL, + NULL) == 0) { + r = uv_translate_sys_error(GetLastError()); + goto error; + } } /* Populate the sysname field. */ diff --git a/deps/uv/test/test-gethostname.c b/deps/uv/test/test-gethostname.c index 5229804b569421..ac636f0aba638b 100644 --- a/deps/uv/test/test-gethostname.c +++ b/deps/uv/test/test-gethostname.c @@ -23,12 +23,8 @@ #include "task.h" #include -#ifndef MAXHOSTNAMELEN -# define MAXHOSTNAMELEN 256 -#endif - TEST_IMPL(gethostname) { - char buf[MAXHOSTNAMELEN + 1]; + char buf[UV_MAXHOSTNAMESIZE]; size_t size; size_t enobufs_size; int r; @@ -52,7 +48,7 @@ TEST_IMPL(gethostname) { ASSERT(enobufs_size > 1); /* Successfully get the hostname */ - size = MAXHOSTNAMELEN + 1; + size = UV_MAXHOSTNAMESIZE; r = uv_os_gethostname(buf, &size); ASSERT(r == 0); ASSERT(size > 1 && size == strlen(buf)); diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h index 53372c90f769f8..d81416fad22b54 100644 --- a/deps/uv/test/test-list.h +++ b/deps/uv/test/test-list.h @@ -53,6 +53,9 @@ TEST_DECLARE (tty_raw) TEST_DECLARE (tty_empty_write) TEST_DECLARE (tty_large_write) TEST_DECLARE (tty_raw_cancel) +TEST_DECLARE (tty_duplicate_vt100_fn_key) +TEST_DECLARE (tty_duplicate_alt_modifier_key) +TEST_DECLARE (tty_composing_character) #endif TEST_DECLARE (tty_file) TEST_DECLARE (tty_pty) @@ -365,6 +368,7 @@ TEST_DECLARE (threadpool_cancel_fs) TEST_DECLARE (threadpool_cancel_single) TEST_DECLARE (thread_local_storage) TEST_DECLARE (thread_stack_size) +TEST_DECLARE (thread_stack_size_explicit) TEST_DECLARE (thread_mutex) TEST_DECLARE (thread_mutex_recursive) TEST_DECLARE (thread_rwlock) @@ -500,6 +504,9 @@ TASK_LIST_START TEST_ENTRY (tty_empty_write) TEST_ENTRY (tty_large_write) TEST_ENTRY (tty_raw_cancel) + TEST_ENTRY (tty_duplicate_vt100_fn_key) + TEST_ENTRY (tty_duplicate_alt_modifier_key) + TEST_ENTRY (tty_composing_character) #endif TEST_ENTRY (tty_file) TEST_ENTRY (tty_pty) @@ -930,6 +937,7 @@ TASK_LIST_START TEST_ENTRY (threadpool_cancel_single) TEST_ENTRY (thread_local_storage) TEST_ENTRY (thread_stack_size) + TEST_ENTRY (thread_stack_size_explicit) TEST_ENTRY (thread_mutex) TEST_ENTRY (thread_mutex_recursive) TEST_ENTRY (thread_rwlock) diff --git a/deps/uv/test/test-thread.c b/deps/uv/test/test-thread.c index 955c9f2f1be149..be72d5e8b39979 100644 --- a/deps/uv/test/test-thread.c +++ b/deps/uv/test/test-thread.c @@ -26,6 +26,10 @@ #include #include /* memset */ +#ifdef __POSIX__ +#include +#endif + struct getaddrinfo_req { uv_thread_t thread_id; unsigned int counter; @@ -207,10 +211,15 @@ TEST_IMPL(thread_local_storage) { static void thread_check_stack(void* arg) { #if defined(__APPLE__) + size_t expected; + expected = arg == NULL ? 0 : ((uv_thread_options_t*)arg)->stack_size; /* 512 kB is the default stack size of threads other than the main thread * on MacOS. */ - ASSERT(pthread_get_stacksize_np(pthread_self()) > 512*1024); + if (expected == 0) + expected = 512 * 1024; + ASSERT(pthread_get_stacksize_np(pthread_self()) >= expected); #elif defined(__linux__) && defined(__GLIBC__) + size_t expected; struct rlimit lim; size_t stack_size; pthread_attr_t attr; @@ -219,7 +228,10 @@ static void thread_check_stack(void* arg) { lim.rlim_cur = 2 << 20; /* glibc default. */ ASSERT(0 == pthread_getattr_np(pthread_self(), &attr)); ASSERT(0 == pthread_attr_getstacksize(&attr, &stack_size)); - ASSERT(stack_size >= lim.rlim_cur); + expected = arg == NULL ? 0 : ((uv_thread_options_t*)arg)->stack_size; + if (expected == 0) + expected = (size_t)lim.rlim_cur; + ASSERT(stack_size >= expected); #endif } @@ -230,3 +242,44 @@ TEST_IMPL(thread_stack_size) { ASSERT(0 == uv_thread_join(&thread)); return 0; } + +TEST_IMPL(thread_stack_size_explicit) { + uv_thread_t thread; + uv_thread_options_t options; + + options.flags = UV_THREAD_HAS_STACK_SIZE; + options.stack_size = 1024 * 1024; + ASSERT(0 == uv_thread_create_ex(&thread, &options, + thread_check_stack, &options)); + ASSERT(0 == uv_thread_join(&thread)); + + options.stack_size = 8 * 1024 * 1024; /* larger than most default os sizes */ + ASSERT(0 == uv_thread_create_ex(&thread, &options, + thread_check_stack, &options)); + ASSERT(0 == uv_thread_join(&thread)); + + options.stack_size = 0; + ASSERT(0 == uv_thread_create_ex(&thread, &options, + thread_check_stack, &options)); + ASSERT(0 == uv_thread_join(&thread)); + +#ifdef PTHREAD_STACK_MIN + options.stack_size = PTHREAD_STACK_MIN - 42; /* unaligned size */ + ASSERT(0 == uv_thread_create_ex(&thread, &options, + thread_check_stack, &options)); + ASSERT(0 == uv_thread_join(&thread)); + + options.stack_size = PTHREAD_STACK_MIN / 2 - 42; /* unaligned size */ + ASSERT(0 == uv_thread_create_ex(&thread, &options, + thread_check_stack, &options)); + ASSERT(0 == uv_thread_join(&thread)); +#endif + + /* unaligned size, should be larger than PTHREAD_STACK_MIN */ + options.stack_size = 1234567; + ASSERT(0 == uv_thread_create_ex(&thread, &options, + thread_check_stack, &options)); + ASSERT(0 == uv_thread_join(&thread)); + + return 0; +} diff --git a/deps/uv/test/test-tty-duplicate-key.c b/deps/uv/test/test-tty-duplicate-key.c new file mode 100644 index 00000000000000..1ec2f3695d99a4 --- /dev/null +++ b/deps/uv/test/test-tty-duplicate-key.c @@ -0,0 +1,321 @@ +/* Copyright libuv project contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifdef _WIN32 + +#include "uv.h" +#include "task.h" + +#include +#include +#include +#include + +#define ESC "\x1b" +#define EUR_UTF8 "\xe2\x82\xac" +#define EUR_UNICODE 0x20AC + + +const char* expect_str = NULL; +ssize_t expect_nread = 0; + +static void dump_str(const char* str, ssize_t len) { + ssize_t i; + for (i = 0; i < len; i++) { + fprintf(stderr, "%#02x ", *(str + i)); + } +} + +static void print_err_msg(const char* expect, ssize_t expect_len, + const char* found, ssize_t found_len) { + fprintf(stderr, "expect "); + dump_str(expect, expect_len); + fprintf(stderr, ", but found "); + dump_str(found, found_len); + fprintf(stderr, "\n"); +} + +static void tty_alloc(uv_handle_t* handle, size_t size, uv_buf_t* buf) { + buf->base = malloc(size); + ASSERT(buf->base != NULL); + buf->len = size; +} + +static void tty_read(uv_stream_t* tty_in, ssize_t nread, const uv_buf_t* buf) { + if (nread > 0) { + if (nread != expect_nread) { + fprintf(stderr, "expected nread %ld, but found %ld\n", + (long)expect_nread, (long)nread); + print_err_msg(expect_str, expect_nread, buf->base, nread); + ASSERT(FALSE); + } + if (strncmp(buf->base, expect_str, nread) != 0) { + print_err_msg(expect_str, expect_nread, buf->base, nread); + ASSERT(FALSE); + } + uv_close((uv_handle_t*) tty_in, NULL); + } else { + ASSERT(nread == 0); + } +} + +static void make_key_event_records(WORD virt_key, DWORD ctr_key_state, + BOOL is_wsl, INPUT_RECORD* records) { +# define KEV(I) records[(I)].Event.KeyEvent + BYTE kb_state[256] = {0}; + WCHAR buf[2]; + int ret; + + records[0].EventType = records[1].EventType = KEY_EVENT; + KEV(0).bKeyDown = TRUE; + KEV(1).bKeyDown = FALSE; + KEV(0).wVirtualKeyCode = KEV(1).wVirtualKeyCode = virt_key; + KEV(0).wRepeatCount = KEV(1).wRepeatCount = 1; + KEV(0).wVirtualScanCode = KEV(1).wVirtualScanCode = + MapVirtualKeyW(virt_key, MAPVK_VK_TO_VSC); + KEV(0).dwControlKeyState = KEV(1).dwControlKeyState = ctr_key_state; + if (ctr_key_state & LEFT_ALT_PRESSED) { + kb_state[VK_LMENU] = 0x01; + } + if (ctr_key_state & RIGHT_ALT_PRESSED) { + kb_state[VK_RMENU] = 0x01; + } + if (ctr_key_state & LEFT_CTRL_PRESSED) { + kb_state[VK_LCONTROL] = 0x01; + } + if (ctr_key_state & RIGHT_CTRL_PRESSED) { + kb_state[VK_RCONTROL] = 0x01; + } + if (ctr_key_state & SHIFT_PRESSED) { + kb_state[VK_SHIFT] = 0x01; + } + ret = ToUnicode(virt_key, KEV(0).wVirtualScanCode, kb_state, buf, 2, 0); + if (ret == 1) { + if(!is_wsl && + ((ctr_key_state & LEFT_ALT_PRESSED) || + (ctr_key_state & RIGHT_ALT_PRESSED))) { + /* + * If ALT key is pressed, the UnicodeChar value of the keyup event is + * set to 0 on nomal console. Emulate this behavior. + * See https://github.com/Microsoft/console/issues/320 + */ + KEV(0).uChar.UnicodeChar = buf[0]; + KEV(1).uChar.UnicodeChar = 0; + } else{ + /* + * In WSL UnicodeChar is normally set. This behavior cause #2111. + */ + KEV(0).uChar.UnicodeChar = KEV(1).uChar.UnicodeChar = buf[0]; + } + } else { + KEV(0).uChar.UnicodeChar = KEV(1).uChar.UnicodeChar = 0; + } +# undef KEV +} + +TEST_IMPL(tty_duplicate_vt100_fn_key) { + int r; + int ttyin_fd; + uv_tty_t tty_in; + uv_loop_t* loop; + HANDLE handle; + INPUT_RECORD records[2]; + DWORD written; + + loop = uv_default_loop(); + + /* Make sure we have an FD that refers to a tty */ + handle = CreateFileA("conin$", + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + ASSERT(handle != INVALID_HANDLE_VALUE); + ttyin_fd = _open_osfhandle((intptr_t) handle, 0); + ASSERT(ttyin_fd >= 0); + ASSERT(UV_TTY == uv_guess_handle(ttyin_fd)); + + r = uv_tty_init(uv_default_loop(), &tty_in, ttyin_fd, 1); /* Readable. */ + ASSERT(r == 0); + ASSERT(uv_is_readable((uv_stream_t*) &tty_in)); + ASSERT(!uv_is_writable((uv_stream_t*) &tty_in)); + + r = uv_read_start((uv_stream_t*)&tty_in, tty_alloc, tty_read); + ASSERT(r == 0); + + expect_str = ESC"[[A"; + expect_nread = strlen(expect_str); + + /* Turn on raw mode. */ + r = uv_tty_set_mode(&tty_in, UV_TTY_MODE_RAW); + ASSERT(r == 0); + + /* + * Send F1 keystrokes. Test of issue cause by #2114 that vt100 fn key + * duplicate. + */ + make_key_event_records(VK_F1, 0, TRUE, records); + WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written); + ASSERT(written == ARRAY_SIZE(records)); + + uv_run(loop, UV_RUN_DEFAULT); + + MAKE_VALGRIND_HAPPY(); + return 0; +} + +TEST_IMPL(tty_duplicate_alt_modifier_key) { + int r; + int ttyin_fd; + uv_tty_t tty_in; + uv_loop_t* loop; + HANDLE handle; + INPUT_RECORD records[2]; + INPUT_RECORD alt_records[2]; + DWORD written; + + loop = uv_default_loop(); + + /* Make sure we have an FD that refers to a tty */ + handle = CreateFileA("conin$", + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + ASSERT(handle != INVALID_HANDLE_VALUE); + ttyin_fd = _open_osfhandle((intptr_t) handle, 0); + ASSERT(ttyin_fd >= 0); + ASSERT(UV_TTY == uv_guess_handle(ttyin_fd)); + + r = uv_tty_init(uv_default_loop(), &tty_in, ttyin_fd, 1); /* Readable. */ + ASSERT(r == 0); + ASSERT(uv_is_readable((uv_stream_t*) &tty_in)); + ASSERT(!uv_is_writable((uv_stream_t*) &tty_in)); + + r = uv_read_start((uv_stream_t*)&tty_in, tty_alloc, tty_read); + ASSERT(r == 0); + + expect_str = ESC"a"ESC"a"; + expect_nread = strlen(expect_str); + + /* Turn on raw mode. */ + r = uv_tty_set_mode(&tty_in, UV_TTY_MODE_RAW); + ASSERT(r == 0); + + /* Emulate transmission of M-a at normal console */ + make_key_event_records(VK_MENU, 0, TRUE, alt_records); + WriteConsoleInputW(handle, &alt_records[0], 1, &written); + ASSERT(written == 1); + make_key_event_records(L'A', LEFT_ALT_PRESSED, FALSE, records); + WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written); + ASSERT(written == 2); + WriteConsoleInputW(handle, &alt_records[1], 1, &written); + ASSERT(written == 1); + + /* Emulate transmission of M-a at WSL(#2111) */ + make_key_event_records(VK_MENU, 0, TRUE, alt_records); + WriteConsoleInputW(handle, &alt_records[0], 1, &written); + ASSERT(written == 1); + make_key_event_records(L'A', LEFT_ALT_PRESSED, TRUE, records); + WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written); + ASSERT(written == 2); + WriteConsoleInputW(handle, &alt_records[1], 1, &written); + ASSERT(written == 1); + + uv_run(loop, UV_RUN_DEFAULT); + + MAKE_VALGRIND_HAPPY(); + return 0; +} + +TEST_IMPL(tty_composing_character) { + int r; + int ttyin_fd; + uv_tty_t tty_in; + uv_loop_t* loop; + HANDLE handle; + INPUT_RECORD records[2]; + INPUT_RECORD alt_records[2]; + DWORD written; + + loop = uv_default_loop(); + + /* Make sure we have an FD that refers to a tty */ + handle = CreateFileA("conin$", + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + ASSERT(handle != INVALID_HANDLE_VALUE); + ttyin_fd = _open_osfhandle((intptr_t) handle, 0); + ASSERT(ttyin_fd >= 0); + ASSERT(UV_TTY == uv_guess_handle(ttyin_fd)); + + r = uv_tty_init(uv_default_loop(), &tty_in, ttyin_fd, 1); /* Readable. */ + ASSERT(r == 0); + ASSERT(uv_is_readable((uv_stream_t*) &tty_in)); + ASSERT(!uv_is_writable((uv_stream_t*) &tty_in)); + + r = uv_read_start((uv_stream_t*)&tty_in, tty_alloc, tty_read); + ASSERT(r == 0); + + expect_str = EUR_UTF8; + expect_nread = strlen(expect_str); + + /* Turn on raw mode. */ + r = uv_tty_set_mode(&tty_in, UV_TTY_MODE_RAW); + ASSERT(r == 0); + + /* Emulate EUR inputs by LEFT ALT+NUMPAD ASCII KeyComos */ + make_key_event_records(VK_MENU, 0, FALSE, alt_records); + alt_records[1].Event.KeyEvent.uChar.UnicodeChar = EUR_UNICODE; + WriteConsoleInputW(handle, &alt_records[0], 1, &written); + make_key_event_records(VK_NUMPAD0, LEFT_ALT_PRESSED, FALSE, records); + WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written); + ASSERT(written == ARRAY_SIZE(records)); + make_key_event_records(VK_NUMPAD1, LEFT_ALT_PRESSED, FALSE, records); + WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written); + ASSERT(written == ARRAY_SIZE(records)); + make_key_event_records(VK_NUMPAD2, LEFT_ALT_PRESSED, FALSE, records); + WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written); + ASSERT(written == ARRAY_SIZE(records)); + make_key_event_records(VK_NUMPAD8, LEFT_ALT_PRESSED, FALSE, records); + WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written); + ASSERT(written == ARRAY_SIZE(records)); + WriteConsoleInputW(handle, &alt_records[1], 1, &written); + + uv_run(loop, UV_RUN_DEFAULT); + + MAKE_VALGRIND_HAPPY(); + return 0; +} + +#else + +typedef int file_has_no_tests; /* ISO C forbids an empty translation unit. */ + +#endif /* ifndef _WIN32 */ diff --git a/deps/uv/test/test.gyp b/deps/uv/test/test.gyp index 604925861e525a..8fc6cca140dc7e 100644 --- a/deps/uv/test/test.gyp +++ b/deps/uv/test/test.gyp @@ -133,6 +133,7 @@ 'test-timer-again.c', 'test-timer-from-check.c', 'test-timer.c', + 'test-tty-duplicate-key.c', 'test-tty.c', 'test-udp-alloc-cb-fail.c', 'test-udp-bind.c',