From 52e4176168d3daa4988949c93897795ee8151cb3 Mon Sep 17 00:00:00 2001 From: Scott Blomquist Date: Fri, 15 Feb 2013 17:34:54 -0800 Subject: [PATCH 1/9] windows: pass ENOENT on to process exit callback --- src/win/process.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/win/process.c b/src/win/process.c index c5649d3ae0..f4cd7de7a9 100644 --- a/src/win/process.c +++ b/src/win/process.c @@ -956,6 +956,7 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process, /* If an error happened, queue the exit req. */ if (err.code != UV_OK) { process->exit_cb_pending = 1; + process->spawn_error = err; uv_insert_pending_req(loop, (uv_req_t*) &process->exit_req); } From e2607ec2407797b4f87fbc052a7a3dda7ceb4411 Mon Sep 17 00:00:00 2001 From: Jonathan Pickett Date: Mon, 12 Aug 2013 15:39:33 -0700 Subject: [PATCH 2/9] added import libraries that allow vcbuild to successfully compile project --- uv.gyp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uv.gyp b/uv.gyp index 301b938576..241a535405 100644 --- a/uv.gyp +++ b/uv.gyp @@ -102,7 +102,9 @@ 'libraries': [ '-lws2_32.lib', '-lpsapi.lib', - '-liphlpapi.lib' + '-liphlpapi.lib', + '-ladvapi32.lib', + '-lshell32.lib' ], }, }, { # Not Windows i.e. POSIX From 363373dba61736e59211792584e8dda6687b7e0b Mon Sep 17 00:00:00 2001 From: Jonathan Pickett Date: Mon, 12 Aug 2013 15:46:14 -0700 Subject: [PATCH 3/9] reworked ReadConsole fix to align with pull request comments --- src/win/tty.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/win/tty.c b/src/win/tty.c index 92f4604c27..e09f9754a3 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -831,6 +831,51 @@ int uv_tty_read_start(uv_tty_t* handle, uv_alloc_cb alloc_cb, } +const uint64_t UV_WINDOWS_8 = 0x0000000600000002; +const uint64_t UV_WINDOWS_7 = 0x0000000600000001; +const uint64_t UV_WINDOWS_Vista = 0x0000000600000000; +const uint64_t UV_WINDOWS_SERVER_2003 = 0x0000000500000002; +const uint64_t UV_WINDOWS_XP = 0x0000000500000001; +const uint64_t UV_WINDOWS_UNKNOWN = 0; + + +uint64_t uv_get_os_version() +{ + OSVERSIONINFOEX osvi; + uint64_t version; + + ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + if(GetVersionEx((LPOSVERSIONINFO)&osvi) == FALSE) + { + return UV_WINDOWS_UNKNOWN; + } + else + { + version = (((uint64_t)osvi.dwMajorVersion) << 32) | (uint64_t)osvi.dwMinorVersion; + return version; + } +} + + +void uv_tty_press_key(uv_tty_t* handle, char c) { + DWORD events_written; + INPUT_RECORD input; + + events_written = 0; + input.EventType = KEY_EVENT; + input.Event.KeyEvent.bKeyDown = TRUE; + input.Event.KeyEvent.dwControlKeyState = 0; + input.Event.KeyEvent.uChar.AsciiChar = c; + input.Event.KeyEvent.wRepeatCount = 1; + input.Event.KeyEvent.wVirtualKeyCode = c; + input.Event.KeyEvent.wVirtualScanCode = c; + WriteConsoleInputA(handle->handle, &input, 1, &events_written); + input.Event.KeyEvent.bKeyDown = FALSE; + WriteConsoleInputA(handle->handle, &input, 1, &events_written); +} + + int uv_tty_read_stop(uv_tty_t* handle) { uv_loop_t* loop = handle->loop; @@ -852,6 +897,10 @@ int uv_tty_read_stop(uv_tty_t* handle) { /* Cancel line-buffered read */ if (handle->read_line_handle != NULL) { + if(uv_get_os_version() >= UV_WINDOWS_8) { + /* Forces any pending ReadConsole to exit before we close the handle */ + uv_tty_press_key(handle, '\r'); + } /* Closing this handle will cancel the ReadConsole operation */ CloseHandle(handle->read_line_handle); handle->read_line_handle = NULL; From ec6411a3996087e305d15d6fc77be5ccfe9ed914 Mon Sep 17 00:00:00 2001 From: Jonathan Pickett Date: Mon, 12 Aug 2013 16:08:15 -0700 Subject: [PATCH 4/9] changed spacing to match existing source --- src/win/tty.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/win/tty.c b/src/win/tty.c index e09f9754a3..db6bf55bab 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -831,18 +831,17 @@ int uv_tty_read_start(uv_tty_t* handle, uv_alloc_cb alloc_cb, } -const uint64_t UV_WINDOWS_8 = 0x0000000600000002; -const uint64_t UV_WINDOWS_7 = 0x0000000600000001; -const uint64_t UV_WINDOWS_Vista = 0x0000000600000000; -const uint64_t UV_WINDOWS_SERVER_2003 = 0x0000000500000002; -const uint64_t UV_WINDOWS_XP = 0x0000000500000001; -const uint64_t UV_WINDOWS_UNKNOWN = 0; +const uint64_t UV_WINDOWS_8 = 0x0000000600000002; +const uint64_t UV_WINDOWS_7 = 0x0000000600000001; +const uint64_t UV_WINDOWS_Vista = 0x0000000600000000; +const uint64_t UV_WINDOWS_SERVER_2003 = 0x0000000500000002; +const uint64_t UV_WINDOWS_XP = 0x0000000500000001; +const uint64_t UV_WINDOWS_UNKNOWN = 0; uint64_t uv_get_os_version() { OSVERSIONINFOEX osvi; - uint64_t version; ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); @@ -852,8 +851,7 @@ uint64_t uv_get_os_version() } else { - version = (((uint64_t)osvi.dwMajorVersion) << 32) | (uint64_t)osvi.dwMinorVersion; - return version; + return (((uint64_t)osvi.dwMajorVersion) << 32) | (uint64_t)osvi.dwMinorVersion; } } @@ -900,7 +898,7 @@ int uv_tty_read_stop(uv_tty_t* handle) { if(uv_get_os_version() >= UV_WINDOWS_8) { /* Forces any pending ReadConsole to exit before we close the handle */ uv_tty_press_key(handle, '\r'); - } + } /* Closing this handle will cancel the ReadConsole operation */ CloseHandle(handle->read_line_handle); handle->read_line_handle = NULL; From 8100f22a94e0252f9934925426a40bbe3aab094d Mon Sep 17 00:00:00 2001 From: Jonathan Pickett Date: Mon, 12 Aug 2013 16:10:10 -0700 Subject: [PATCH 5/9] more spacing fixes --- src/win/tty.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win/tty.c b/src/win/tty.c index db6bf55bab..126261fa74 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -851,7 +851,7 @@ uint64_t uv_get_os_version() } else { - return (((uint64_t)osvi.dwMajorVersion) << 32) | (uint64_t)osvi.dwMinorVersion; + return (((uint64_t)osvi.dwMajorVersion) << 32) | (uint64_t)osvi.dwMinorVersion; } } From e77b53238240492bd40a8463a4baee88d43b25d3 Mon Sep 17 00:00:00 2001 From: Jonathan Pickett Date: Mon, 12 Aug 2013 15:46:14 -0700 Subject: [PATCH 6/9] windows: fix ReadConsole hangs on CloseHandle --- src/win/tty.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/win/tty.c b/src/win/tty.c index e6077a9901..078f030b48 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -827,6 +827,49 @@ int uv_tty_read_start(uv_tty_t* handle, uv_alloc_cb alloc_cb, } +const uint64_t UV_WINDOWS_8 = 0x0000000600000002; +const uint64_t UV_WINDOWS_7 = 0x0000000600000001; +const uint64_t UV_WINDOWS_Vista = 0x0000000600000000; +const uint64_t UV_WINDOWS_SERVER_2003 = 0x0000000500000002; +const uint64_t UV_WINDOWS_XP = 0x0000000500000001; +const uint64_t UV_WINDOWS_UNKNOWN = 0; + + +uint64_t uv_get_os_version() +{ + OSVERSIONINFOEX osvi; + + ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + if(GetVersionEx((LPOSVERSIONINFO)&osvi) == FALSE) + { + return UV_WINDOWS_UNKNOWN; + } + else + { + return (((uint64_t)osvi.dwMajorVersion) << 32) | (uint64_t)osvi.dwMinorVersion; + } +} + + +void uv_tty_press_key(uv_tty_t* handle, char c) { + DWORD events_written; + INPUT_RECORD input; + + events_written = 0; + input.EventType = KEY_EVENT; + input.Event.KeyEvent.bKeyDown = TRUE; + input.Event.KeyEvent.dwControlKeyState = 0; + input.Event.KeyEvent.uChar.AsciiChar = c; + input.Event.KeyEvent.wRepeatCount = 1; + input.Event.KeyEvent.wVirtualKeyCode = c; + input.Event.KeyEvent.wVirtualScanCode = c; + WriteConsoleInputA(handle->handle, &input, 1, &events_written); + input.Event.KeyEvent.bKeyDown = FALSE; + WriteConsoleInputA(handle->handle, &input, 1, &events_written); +} + + int uv_tty_read_stop(uv_tty_t* handle) { uv_loop_t* loop = handle->loop; @@ -847,6 +890,10 @@ int uv_tty_read_stop(uv_tty_t* handle) { /* Cancel line-buffered read */ if (handle->read_line_handle != NULL) { + if(uv_get_os_version() >= UV_WINDOWS_8) { + /* Forces any pending ReadConsole to exit before we close the handle */ + uv_tty_press_key(handle, '\r'); + } /* Closing this handle will cancel the ReadConsole operation */ CloseHandle(handle->read_line_handle); handle->read_line_handle = NULL; From 5f5d1df18b4d174ecb07b049ce5ee610cc16e2cd Mon Sep 17 00:00:00 2001 From: Jonathan Pickett Date: Thu, 15 Aug 2013 12:28:04 -0700 Subject: [PATCH 7/9] using _WIN32_WINNT_xxx constants, modified os version detection, uv_tty_press_key->uv_tty_simulate_enter_key_press, and style changes --- src/win/tty.c | 61 +++++++++++++++++++++++++++++---------------------- uv.gyp | 3 ++- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/win/tty.c b/src/win/tty.c index 126261fa74..2063c88646 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -830,47 +830,58 @@ int uv_tty_read_start(uv_tty_t* handle, uv_alloc_cb alloc_cb, return 0; } +/* definitions taken from Win8 SDK */ +#if !defined(_INC_SDKDDKVER) +#define _WIN32_WINNT_NT4 0x0400 +#define _WIN32_WINNT_WIN2K 0x0500 +#define _WIN32_WINNT_WINXP 0x0501 +#define _WIN32_WINNT_WS03 0x0502 +#define _WIN32_WINNT_WIN6 0x0600 +#define _WIN32_WINNT_VISTA 0x0600 +#define _WIN32_WINNT_WS08 0x0600 +#define _WIN32_WINNT_LONGHORN 0x0600 +#define _WIN32_WINNT_WIN7 0x0601 +#define _WIN32_WINNT_WIN8 0x0602 +#endif + -const uint64_t UV_WINDOWS_8 = 0x0000000600000002; -const uint64_t UV_WINDOWS_7 = 0x0000000600000001; -const uint64_t UV_WINDOWS_Vista = 0x0000000600000000; -const uint64_t UV_WINDOWS_SERVER_2003 = 0x0000000500000002; -const uint64_t UV_WINDOWS_XP = 0x0000000500000001; -const uint64_t UV_WINDOWS_UNKNOWN = 0; +/* SDK that comes with VS2010 does not have this */ +#if !defined(_WIN32_WINNT_WIN8) +#define _WIN32_WINNT_WIN8 0x0602 +#endif -uint64_t uv_get_os_version() +static uint16_t uv_get_os_version() { OSVERSIONINFOEX osvi; - ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); + memset(&osvi, 0, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - if(GetVersionEx((LPOSVERSIONINFO)&osvi) == FALSE) - { - return UV_WINDOWS_UNKNOWN; - } - else - { - return (((uint64_t)osvi.dwMajorVersion) << 32) | (uint64_t)osvi.dwMinorVersion; + if (GetVersionEx((OSVERSIONINFO*) &osvi) == FALSE) { + uv_fatal_error(GetLastError(), "GetVersionEx"); + } else { + return ((osvi.dwMajorVersion & 0xF) << 8) | (osvi.dwMinorVersion & 0xF); } } -void uv_tty_press_key(uv_tty_t* handle, char c) { +static void uv_tty_simulate_enter_key_press(uv_tty_t* handle) { DWORD events_written; INPUT_RECORD input; + assert(handle->handle && handle->handle != INVALID_HANDLE_VALUE); + events_written = 0; input.EventType = KEY_EVENT; input.Event.KeyEvent.bKeyDown = TRUE; input.Event.KeyEvent.dwControlKeyState = 0; - input.Event.KeyEvent.uChar.AsciiChar = c; + input.Event.KeyEvent.uChar.UnicodeChar = L'\r'; input.Event.KeyEvent.wRepeatCount = 1; - input.Event.KeyEvent.wVirtualKeyCode = c; - input.Event.KeyEvent.wVirtualScanCode = c; - WriteConsoleInputA(handle->handle, &input, 1, &events_written); + input.Event.KeyEvent.wVirtualKeyCode = VK_RETURN; + input.Event.KeyEvent.wVirtualScanCode = MapVirtualKey(VK_RETURN, MAPVK_VK_TO_VSC); + WriteConsoleInputW(handle->handle, &input, 1, &events_written); input.Event.KeyEvent.bKeyDown = FALSE; - WriteConsoleInputA(handle->handle, &input, 1, &events_written); + WriteConsoleInputW(handle->handle, &input, 1, &events_written); } @@ -888,23 +899,21 @@ int uv_tty_read_stop(uv_tty_t* handle) { DWORD written; memset(&record, 0, sizeof record); if (!WriteConsoleInputW(handle->handle, &record, 1, &written)) { - uv__set_sys_error(loop, GetLastError()); - return -1; + return GetLastError(); } } /* Cancel line-buffered read */ if (handle->read_line_handle != NULL) { - if(uv_get_os_version() >= UV_WINDOWS_8) { + if(uv_get_os_version() >= _WIN32_WINNT_WIN8) { /* Forces any pending ReadConsole to exit before we close the handle */ - uv_tty_press_key(handle, '\r'); + uv_tty_simulate_enter_key_press(handle); } /* Closing this handle will cancel the ReadConsole operation */ CloseHandle(handle->read_line_handle); handle->read_line_handle = NULL; } - return 0; } diff --git a/uv.gyp b/uv.gyp index 241a535405..6a305c8f2a 100644 --- a/uv.gyp +++ b/uv.gyp @@ -104,7 +104,8 @@ '-lpsapi.lib', '-liphlpapi.lib', '-ladvapi32.lib', - '-lshell32.lib' + '-lshell32.lib', + '-luser32.lib' ], }, }, { # Not Windows i.e. POSIX From ba24c78dd91c88f0a5fc9af6f1e998a971eab1d5 Mon Sep 17 00:00:00 2001 From: Jonathan Pickett Date: Thu, 15 Aug 2013 15:20:01 -0700 Subject: [PATCH 8/9] moved _win32_WINNT_XXX defines to winapi.h --- src/win/tty.c | 13 ------------- src/win/winapi.h | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/win/tty.c b/src/win/tty.c index 64f1f3fb48..b18992b045 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -47,19 +47,6 @@ #define ANSI_IN_STRING 0x40 #define ANSI_BACKSLASH_SEEN 0x80 -#if !defined(_INC_SDKDDKVER) -#define _WIN32_WINNT_NT4 0x0400 -#define _WIN32_WINNT_WIN2K 0x0500 -#define _WIN32_WINNT_WINXP 0x0501 -#define _WIN32_WINNT_WS03 0x0502 -#define _WIN32_WINNT_WIN6 0x0600 -#define _WIN32_WINNT_VISTA 0x0600 -#define _WIN32_WINNT_WS08 0x0600 -#define _WIN32_WINNT_LONGHORN 0x0600 -#define _WIN32_WINNT_WIN7 0x0601 -#define _WIN32_WINNT_WIN8 0x0602 -#endif - static void uv_tty_update_virtual_window(CONSOLE_SCREEN_BUFFER_INFO* info); diff --git a/src/win/winapi.h b/src/win/winapi.h index 003c14bad4..88577788a6 100644 --- a/src/win/winapi.h +++ b/src/win/winapi.h @@ -4385,6 +4385,25 @@ typedef NTSTATUS (NTAPI *sNtQuerySystemInformation) } OVERLAPPED_ENTRY, *LPOVERLAPPED_ENTRY; #endif +/* from Windows8 SDK sdkddkver.h */ +#if !defined(_INC_SDKDDKVER) +# define _WIN32_WINNT_NT4 0x0400 +# define _WIN32_WINNT_WIN2K 0x0500 +# define _WIN32_WINNT_WINXP 0x0501 +# define _WIN32_WINNT_WS03 0x0502 +# define _WIN32_WINNT_WIN6 0x0600 +# define _WIN32_WINNT_VISTA 0x0600 +# define _WIN32_WINNT_WS08 0x0600 +# define _WIN32_WINNT_LONGHORN 0x0600 +# define _WIN32_WINNT_WIN7 0x0601 +# define _WIN32_WINNT_WIN8 0x0602 +#endif + +/* for Windows7 SDK users */ +#if !defined(_WIN32_WINNT_WIN8) +# define _WIN32_WINNT_WIN8 0x0602 +#endif + /* from wincon.h */ #ifndef ENABLE_INSERT_MODE # define ENABLE_INSERT_MODE 0x20 From 11ba8e5c3abf6ba498a4fa78950b5624be166fae Mon Sep 17 00:00:00 2001 From: Jonathan Pickett Date: Thu, 15 Aug 2013 15:33:29 -0700 Subject: [PATCH 9/9] removing extra sblomb change in process.c --- src/win/process.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/win/process.c b/src/win/process.c index 774c054296..3230bb2ef5 100644 --- a/src/win/process.c +++ b/src/win/process.c @@ -1036,7 +1036,6 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process, /* If an error happened, queue the exit req. */ if (err) { process->exit_cb_pending = 1; - process->spawn_error = err; uv_insert_pending_req(loop, (uv_req_t*) &process->exit_req); }