libuv-svace-build
147 строк · 5.1 Кб
1/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2*
3* Permission is hereby granted, free of charge, to any person obtaining a copy
4* of this software and associated documentation files (the "Software"), to
5* deal in the Software without restriction, including without limitation the
6* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7* sell copies of the Software, and to permit persons to whom the Software is
8* furnished to do so, subject to the following conditions:
9*
10* The above copyright notice and this permission notice shall be included in
11* all copies or substantial portions of the Software.
12*
13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19* IN THE SOFTWARE.
20*/
21
22#include <assert.h>23
24#include "uv.h"25#include "internal.h"26
27
28/* Ntdll function pointers */
29sRtlGetVersion pRtlGetVersion;30sRtlNtStatusToDosError pRtlNtStatusToDosError;31sNtDeviceIoControlFile pNtDeviceIoControlFile;32sNtQueryInformationFile pNtQueryInformationFile;33sNtSetInformationFile pNtSetInformationFile;34sNtQueryVolumeInformationFile pNtQueryVolumeInformationFile;35sNtQueryDirectoryFile pNtQueryDirectoryFile;36sNtQuerySystemInformation pNtQuerySystemInformation;37sNtQueryInformationProcess pNtQueryInformationProcess;38
39/* Kernel32 function pointers */
40sGetQueuedCompletionStatusEx pGetQueuedCompletionStatusEx;41
42/* Powrprof.dll function pointer */
43sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;44
45/* User32.dll function pointer */
46sSetWinEventHook pSetWinEventHook;47
48/* ws2_32.dll function pointer */
49uv_sGetHostNameW pGetHostNameW;50
51void uv__winapi_init(void) {52HMODULE ntdll_module;53HMODULE powrprof_module;54HMODULE user32_module;55HMODULE kernel32_module;56HMODULE ws2_32_module;57
58ntdll_module = GetModuleHandleA("ntdll.dll");59if (ntdll_module == NULL) {60uv_fatal_error(GetLastError(), "GetModuleHandleA");61}62
63pRtlGetVersion = (sRtlGetVersion) GetProcAddress(ntdll_module,64"RtlGetVersion");65
66pRtlNtStatusToDosError = (sRtlNtStatusToDosError) GetProcAddress(67ntdll_module,68"RtlNtStatusToDosError");69if (pRtlNtStatusToDosError == NULL) {70uv_fatal_error(GetLastError(), "GetProcAddress");71}72
73pNtDeviceIoControlFile = (sNtDeviceIoControlFile) GetProcAddress(74ntdll_module,75"NtDeviceIoControlFile");76if (pNtDeviceIoControlFile == NULL) {77uv_fatal_error(GetLastError(), "GetProcAddress");78}79
80pNtQueryInformationFile = (sNtQueryInformationFile) GetProcAddress(81ntdll_module,82"NtQueryInformationFile");83if (pNtQueryInformationFile == NULL) {84uv_fatal_error(GetLastError(), "GetProcAddress");85}86
87pNtSetInformationFile = (sNtSetInformationFile) GetProcAddress(88ntdll_module,89"NtSetInformationFile");90if (pNtSetInformationFile == NULL) {91uv_fatal_error(GetLastError(), "GetProcAddress");92}93
94pNtQueryVolumeInformationFile = (sNtQueryVolumeInformationFile)95GetProcAddress(ntdll_module, "NtQueryVolumeInformationFile");96if (pNtQueryVolumeInformationFile == NULL) {97uv_fatal_error(GetLastError(), "GetProcAddress");98}99
100pNtQueryDirectoryFile = (sNtQueryDirectoryFile)101GetProcAddress(ntdll_module, "NtQueryDirectoryFile");102if (pNtQueryVolumeInformationFile == NULL) {103uv_fatal_error(GetLastError(), "GetProcAddress");104}105
106pNtQuerySystemInformation = (sNtQuerySystemInformation) GetProcAddress(107ntdll_module,108"NtQuerySystemInformation");109if (pNtQuerySystemInformation == NULL) {110uv_fatal_error(GetLastError(), "GetProcAddress");111}112
113pNtQueryInformationProcess = (sNtQueryInformationProcess) GetProcAddress(114ntdll_module,115"NtQueryInformationProcess");116if (pNtQueryInformationProcess == NULL) {117uv_fatal_error(GetLastError(), "GetProcAddress");118}119
120kernel32_module = GetModuleHandleA("kernel32.dll");121if (kernel32_module == NULL) {122uv_fatal_error(GetLastError(), "GetModuleHandleA");123}124
125pGetQueuedCompletionStatusEx = (sGetQueuedCompletionStatusEx) GetProcAddress(126kernel32_module,127"GetQueuedCompletionStatusEx");128
129powrprof_module = LoadLibraryExA("powrprof.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);130if (powrprof_module != NULL) {131pPowerRegisterSuspendResumeNotification = (sPowerRegisterSuspendResumeNotification)132GetProcAddress(powrprof_module, "PowerRegisterSuspendResumeNotification");133}134
135user32_module = GetModuleHandleA("user32.dll");136if (user32_module != NULL) {137pSetWinEventHook = (sSetWinEventHook)138GetProcAddress(user32_module, "SetWinEventHook");139}140
141ws2_32_module = GetModuleHandleA("ws2_32.dll");142if (ws2_32_module != NULL) {143pGetHostNameW = (uv_sGetHostNameW) GetProcAddress(144ws2_32_module,145"GetHostNameW");146}147}
148