|
Packit |
b5b901 |
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|
Packit |
b5b901 |
*
|
|
Packit |
b5b901 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
Packit |
b5b901 |
* of this software and associated documentation files (the "Software"), to
|
|
Packit |
b5b901 |
* deal in the Software without restriction, including without limitation the
|
|
Packit |
b5b901 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
Packit |
b5b901 |
* sell copies of the Software, and to permit persons to whom the Software is
|
|
Packit |
b5b901 |
* furnished to do so, subject to the following conditions:
|
|
Packit |
b5b901 |
*
|
|
Packit |
b5b901 |
* The above copyright notice and this permission notice shall be included in
|
|
Packit |
b5b901 |
* all copies or substantial portions of the Software.
|
|
Packit |
b5b901 |
*
|
|
Packit |
b5b901 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
Packit |
b5b901 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
Packit |
b5b901 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
Packit |
b5b901 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
Packit |
b5b901 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
Packit |
b5b901 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
Packit |
b5b901 |
* IN THE SOFTWARE.
|
|
Packit |
b5b901 |
*/
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
#include <assert.h>
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
#include "uv.h"
|
|
Packit |
b5b901 |
#include "internal.h"
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
/* Ntdll function pointers */
|
|
Packit Service |
e08953 |
sRtlGetVersion pRtlGetVersion;
|
|
Packit |
b5b901 |
sRtlNtStatusToDosError pRtlNtStatusToDosError;
|
|
Packit |
b5b901 |
sNtDeviceIoControlFile pNtDeviceIoControlFile;
|
|
Packit |
b5b901 |
sNtQueryInformationFile pNtQueryInformationFile;
|
|
Packit |
b5b901 |
sNtSetInformationFile pNtSetInformationFile;
|
|
Packit |
b5b901 |
sNtQueryVolumeInformationFile pNtQueryVolumeInformationFile;
|
|
Packit |
b5b901 |
sNtQueryDirectoryFile pNtQueryDirectoryFile;
|
|
Packit |
b5b901 |
sNtQuerySystemInformation pNtQuerySystemInformation;
|
|
Packit Service |
e08953 |
sNtQueryInformationProcess pNtQueryInformationProcess;
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
/* Kernel32 function pointers */
|
|
Packit |
b5b901 |
sGetQueuedCompletionStatusEx pGetQueuedCompletionStatusEx;
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
/* Powrprof.dll function pointer */
|
|
Packit |
b5b901 |
sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
/* User32.dll function pointer */
|
|
Packit |
b5b901 |
sSetWinEventHook pSetWinEventHook;
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
void uv_winapi_init(void) {
|
|
Packit |
b5b901 |
HMODULE ntdll_module;
|
|
Packit |
b5b901 |
HMODULE powrprof_module;
|
|
Packit |
b5b901 |
HMODULE user32_module;
|
|
Packit |
b5b901 |
HMODULE kernel32_module;
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
ntdll_module = GetModuleHandleA("ntdll.dll");
|
|
Packit |
b5b901 |
if (ntdll_module == NULL) {
|
|
Packit |
b5b901 |
uv_fatal_error(GetLastError(), "GetModuleHandleA");
|
|
Packit |
b5b901 |
}
|
|
Packit |
b5b901 |
|
|
Packit Service |
e08953 |
pRtlGetVersion = (sRtlGetVersion) GetProcAddress(ntdll_module,
|
|
Packit Service |
e08953 |
"RtlGetVersion");
|
|
Packit Service |
e08953 |
|
|
Packit |
b5b901 |
pRtlNtStatusToDosError = (sRtlNtStatusToDosError) GetProcAddress(
|
|
Packit |
b5b901 |
ntdll_module,
|
|
Packit |
b5b901 |
"RtlNtStatusToDosError");
|
|
Packit |
b5b901 |
if (pRtlNtStatusToDosError == NULL) {
|
|
Packit |
b5b901 |
uv_fatal_error(GetLastError(), "GetProcAddress");
|
|
Packit |
b5b901 |
}
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
pNtDeviceIoControlFile = (sNtDeviceIoControlFile) GetProcAddress(
|
|
Packit |
b5b901 |
ntdll_module,
|
|
Packit |
b5b901 |
"NtDeviceIoControlFile");
|
|
Packit |
b5b901 |
if (pNtDeviceIoControlFile == NULL) {
|
|
Packit |
b5b901 |
uv_fatal_error(GetLastError(), "GetProcAddress");
|
|
Packit |
b5b901 |
}
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
pNtQueryInformationFile = (sNtQueryInformationFile) GetProcAddress(
|
|
Packit |
b5b901 |
ntdll_module,
|
|
Packit |
b5b901 |
"NtQueryInformationFile");
|
|
Packit |
b5b901 |
if (pNtQueryInformationFile == NULL) {
|
|
Packit |
b5b901 |
uv_fatal_error(GetLastError(), "GetProcAddress");
|
|
Packit |
b5b901 |
}
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
pNtSetInformationFile = (sNtSetInformationFile) GetProcAddress(
|
|
Packit |
b5b901 |
ntdll_module,
|
|
Packit |
b5b901 |
"NtSetInformationFile");
|
|
Packit |
b5b901 |
if (pNtSetInformationFile == NULL) {
|
|
Packit |
b5b901 |
uv_fatal_error(GetLastError(), "GetProcAddress");
|
|
Packit |
b5b901 |
}
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
pNtQueryVolumeInformationFile = (sNtQueryVolumeInformationFile)
|
|
Packit |
b5b901 |
GetProcAddress(ntdll_module, "NtQueryVolumeInformationFile");
|
|
Packit |
b5b901 |
if (pNtQueryVolumeInformationFile == NULL) {
|
|
Packit |
b5b901 |
uv_fatal_error(GetLastError(), "GetProcAddress");
|
|
Packit |
b5b901 |
}
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
pNtQueryDirectoryFile = (sNtQueryDirectoryFile)
|
|
Packit |
b5b901 |
GetProcAddress(ntdll_module, "NtQueryDirectoryFile");
|
|
Packit |
b5b901 |
if (pNtQueryVolumeInformationFile == NULL) {
|
|
Packit |
b5b901 |
uv_fatal_error(GetLastError(), "GetProcAddress");
|
|
Packit |
b5b901 |
}
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
pNtQuerySystemInformation = (sNtQuerySystemInformation) GetProcAddress(
|
|
Packit |
b5b901 |
ntdll_module,
|
|
Packit |
b5b901 |
"NtQuerySystemInformation");
|
|
Packit |
b5b901 |
if (pNtQuerySystemInformation == NULL) {
|
|
Packit |
b5b901 |
uv_fatal_error(GetLastError(), "GetProcAddress");
|
|
Packit |
b5b901 |
}
|
|
Packit |
b5b901 |
|
|
Packit Service |
e08953 |
pNtQueryInformationProcess = (sNtQueryInformationProcess) GetProcAddress(
|
|
Packit Service |
e08953 |
ntdll_module,
|
|
Packit Service |
e08953 |
"NtQueryInformationProcess");
|
|
Packit Service |
e08953 |
if (pNtQueryInformationProcess == NULL) {
|
|
Packit Service |
e08953 |
uv_fatal_error(GetLastError(), "GetProcAddress");
|
|
Packit Service |
e08953 |
}
|
|
Packit Service |
e08953 |
|
|
Packit |
b5b901 |
kernel32_module = GetModuleHandleA("kernel32.dll");
|
|
Packit |
b5b901 |
if (kernel32_module == NULL) {
|
|
Packit |
b5b901 |
uv_fatal_error(GetLastError(), "GetModuleHandleA");
|
|
Packit |
b5b901 |
}
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
pGetQueuedCompletionStatusEx = (sGetQueuedCompletionStatusEx) GetProcAddress(
|
|
Packit |
b5b901 |
kernel32_module,
|
|
Packit |
b5b901 |
"GetQueuedCompletionStatusEx");
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
powrprof_module = LoadLibraryA("powrprof.dll");
|
|
Packit |
b5b901 |
if (powrprof_module != NULL) {
|
|
Packit |
b5b901 |
pPowerRegisterSuspendResumeNotification = (sPowerRegisterSuspendResumeNotification)
|
|
Packit |
b5b901 |
GetProcAddress(powrprof_module, "PowerRegisterSuspendResumeNotification");
|
|
Packit |
b5b901 |
}
|
|
Packit |
b5b901 |
|
|
Packit |
b5b901 |
user32_module = LoadLibraryA("user32.dll");
|
|
Packit |
b5b901 |
if (user32_module != NULL) {
|
|
Packit |
b5b901 |
pSetWinEventHook = (sSetWinEventHook)
|
|
Packit |
b5b901 |
GetProcAddress(user32_module, "SetWinEventHook");
|
|
Packit |
b5b901 |
}
|
|
Packit |
b5b901 |
}
|