Skip to content

Commit

Permalink
deps: cherry-pick e7f4e9e from upstream libuv
Browse files Browse the repository at this point in the history
Original commit message:
    tty, win: get SetWinEventHook pointer at startup

    SetWinEventHook is not available on some Windows versions.

    Fixes: #16603
    Reviewed-By: Ben Noordhuis <[email protected]>
    Reviewed-By: Colin Ihrig <[email protected]>

PR-URL: #16724
Fixes: #16603
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
  • Loading branch information
bzoz authored and MylesBorins committed Nov 4, 2017
1 parent 185229e commit ed0fbd8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
17 changes: 10 additions & 7 deletions deps/uv/src/win/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -2285,13 +2285,16 @@ static DWORD WINAPI uv__tty_console_resize_message_loop_thread(void* param) {
uv__tty_console_width = sb_info.dwSize.X;
uv__tty_console_height = sb_info.srWindow.Bottom - sb_info.srWindow.Top + 1;

if (!SetWinEventHook(EVENT_CONSOLE_LAYOUT,
EVENT_CONSOLE_LAYOUT,
NULL,
uv__tty_console_resize_event,
0,
0,
WINEVENT_OUTOFCONTEXT))
if (pSetWinEventHook == NULL)
return 0;

if (!pSetWinEventHook(EVENT_CONSOLE_LAYOUT,
EVENT_CONSOLE_LAYOUT,
NULL,
uv__tty_console_resize_event,
0,
0,
WINEVENT_OUTOFCONTEXT))
return 0;

while (GetMessage(&msg, NULL, 0, 0)) {
Expand Down
10 changes: 10 additions & 0 deletions deps/uv/src/win/winapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ sGetFinalPathNameByHandleW pGetFinalPathNameByHandleW;
/* Powrprof.dll function pointer */
sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;

/* User32.dll function pointer */
sSetWinEventHook pSetWinEventHook;


void uv_winapi_init(void) {
HMODULE ntdll_module;
HMODULE kernel32_module;
HMODULE powrprof_module;
HMODULE user32_module;

ntdll_module = GetModuleHandleA("ntdll.dll");
if (ntdll_module == NULL) {
Expand Down Expand Up @@ -156,4 +160,10 @@ void uv_winapi_init(void) {
GetProcAddress(powrprof_module, "PowerRegisterSuspendResumeNotification");
}

user32_module = LoadLibraryA("user32.dll");
if (user32_module != NULL) {
pSetWinEventHook = (sSetWinEventHook)
GetProcAddress(user32_module, "SetWinEventHook");
}

}
22 changes: 22 additions & 0 deletions deps/uv/src/win/winapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4725,6 +4725,25 @@ typedef DWORD (WINAPI *sPowerRegisterSuspendResumeNotification)
HANDLE Recipient,
_PHPOWERNOTIFY RegistrationHandle);

/* from Winuser.h */
typedef VOID (CALLBACK* WINEVENTPROC)
(HWINEVENTHOOK hWinEventHook,
DWORD event,
HWND hwnd,
LONG idObject,
LONG idChild,
DWORD idEventThread,
DWORD dwmsEventTime);

typedef HWINEVENTHOOK (WINAPI *sSetWinEventHook)
(UINT eventMin,
UINT eventMax,
HMODULE hmodWinEventProc,
WINEVENTPROC lpfnWinEventProc,
DWORD idProcess,
DWORD idThread,
UINT dwflags);


/* Ntdll function pointers */
extern sRtlNtStatusToDosError pRtlNtStatusToDosError;
Expand Down Expand Up @@ -4753,4 +4772,7 @@ extern sGetFinalPathNameByHandleW pGetFinalPathNameByHandleW;
/* Powrprof.dll function pointer */
extern sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;

/* User32.dll function pointer */
extern sSetWinEventHook pSetWinEventHook;

#endif /* UV_WIN_WINAPI_H_ */

0 comments on commit ed0fbd8

Please sign in to comment.