10e552da7Schristos /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
20e552da7Schristos *
30e552da7Schristos * Permission is hereby granted, free of charge, to any person obtaining a copy
40e552da7Schristos * of this software and associated documentation files (the "Software"), to
50e552da7Schristos * deal in the Software without restriction, including without limitation the
60e552da7Schristos * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
70e552da7Schristos * sell copies of the Software, and to permit persons to whom the Software is
80e552da7Schristos * furnished to do so, subject to the following conditions:
90e552da7Schristos *
100e552da7Schristos * The above copyright notice and this permission notice shall be included in
110e552da7Schristos * all copies or substantial portions of the Software.
120e552da7Schristos *
130e552da7Schristos * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
140e552da7Schristos * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
150e552da7Schristos * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
160e552da7Schristos * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
170e552da7Schristos * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
180e552da7Schristos * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
190e552da7Schristos * IN THE SOFTWARE.
200e552da7Schristos */
210e552da7Schristos
220e552da7Schristos #include <assert.h>
230e552da7Schristos
240e552da7Schristos #include "uv.h"
250e552da7Schristos #include "internal.h"
260e552da7Schristos
270e552da7Schristos
280e552da7Schristos /* Ntdll function pointers */
290e552da7Schristos sRtlGetVersion pRtlGetVersion;
300e552da7Schristos sRtlNtStatusToDosError pRtlNtStatusToDosError;
310e552da7Schristos sNtDeviceIoControlFile pNtDeviceIoControlFile;
320e552da7Schristos sNtQueryInformationFile pNtQueryInformationFile;
330e552da7Schristos sNtSetInformationFile pNtSetInformationFile;
340e552da7Schristos sNtQueryVolumeInformationFile pNtQueryVolumeInformationFile;
350e552da7Schristos sNtQueryDirectoryFile pNtQueryDirectoryFile;
360e552da7Schristos sNtQuerySystemInformation pNtQuerySystemInformation;
370e552da7Schristos sNtQueryInformationProcess pNtQueryInformationProcess;
380e552da7Schristos
390e552da7Schristos /* Kernel32 function pointers */
400e552da7Schristos sGetQueuedCompletionStatusEx pGetQueuedCompletionStatusEx;
410e552da7Schristos
420e552da7Schristos /* Powrprof.dll function pointer */
430e552da7Schristos sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;
440e552da7Schristos
450e552da7Schristos /* User32.dll function pointer */
460e552da7Schristos sSetWinEventHook pSetWinEventHook;
470e552da7Schristos
48*5f2f4271Schristos /* ws2_32.dll function pointer */
49*5f2f4271Schristos uv_sGetHostNameW pGetHostNameW;
500e552da7Schristos
uv__winapi_init(void)51*5f2f4271Schristos void uv__winapi_init(void) {
520e552da7Schristos HMODULE ntdll_module;
530e552da7Schristos HMODULE powrprof_module;
540e552da7Schristos HMODULE user32_module;
550e552da7Schristos HMODULE kernel32_module;
56*5f2f4271Schristos HMODULE ws2_32_module;
570e552da7Schristos
580e552da7Schristos ntdll_module = GetModuleHandleA("ntdll.dll");
590e552da7Schristos if (ntdll_module == NULL) {
600e552da7Schristos uv_fatal_error(GetLastError(), "GetModuleHandleA");
610e552da7Schristos }
620e552da7Schristos
630e552da7Schristos pRtlGetVersion = (sRtlGetVersion) GetProcAddress(ntdll_module,
640e552da7Schristos "RtlGetVersion");
650e552da7Schristos
660e552da7Schristos pRtlNtStatusToDosError = (sRtlNtStatusToDosError) GetProcAddress(
670e552da7Schristos ntdll_module,
680e552da7Schristos "RtlNtStatusToDosError");
690e552da7Schristos if (pRtlNtStatusToDosError == NULL) {
700e552da7Schristos uv_fatal_error(GetLastError(), "GetProcAddress");
710e552da7Schristos }
720e552da7Schristos
730e552da7Schristos pNtDeviceIoControlFile = (sNtDeviceIoControlFile) GetProcAddress(
740e552da7Schristos ntdll_module,
750e552da7Schristos "NtDeviceIoControlFile");
760e552da7Schristos if (pNtDeviceIoControlFile == NULL) {
770e552da7Schristos uv_fatal_error(GetLastError(), "GetProcAddress");
780e552da7Schristos }
790e552da7Schristos
800e552da7Schristos pNtQueryInformationFile = (sNtQueryInformationFile) GetProcAddress(
810e552da7Schristos ntdll_module,
820e552da7Schristos "NtQueryInformationFile");
830e552da7Schristos if (pNtQueryInformationFile == NULL) {
840e552da7Schristos uv_fatal_error(GetLastError(), "GetProcAddress");
850e552da7Schristos }
860e552da7Schristos
870e552da7Schristos pNtSetInformationFile = (sNtSetInformationFile) GetProcAddress(
880e552da7Schristos ntdll_module,
890e552da7Schristos "NtSetInformationFile");
900e552da7Schristos if (pNtSetInformationFile == NULL) {
910e552da7Schristos uv_fatal_error(GetLastError(), "GetProcAddress");
920e552da7Schristos }
930e552da7Schristos
940e552da7Schristos pNtQueryVolumeInformationFile = (sNtQueryVolumeInformationFile)
950e552da7Schristos GetProcAddress(ntdll_module, "NtQueryVolumeInformationFile");
960e552da7Schristos if (pNtQueryVolumeInformationFile == NULL) {
970e552da7Schristos uv_fatal_error(GetLastError(), "GetProcAddress");
980e552da7Schristos }
990e552da7Schristos
1000e552da7Schristos pNtQueryDirectoryFile = (sNtQueryDirectoryFile)
1010e552da7Schristos GetProcAddress(ntdll_module, "NtQueryDirectoryFile");
1020e552da7Schristos if (pNtQueryVolumeInformationFile == NULL) {
1030e552da7Schristos uv_fatal_error(GetLastError(), "GetProcAddress");
1040e552da7Schristos }
1050e552da7Schristos
1060e552da7Schristos pNtQuerySystemInformation = (sNtQuerySystemInformation) GetProcAddress(
1070e552da7Schristos ntdll_module,
1080e552da7Schristos "NtQuerySystemInformation");
1090e552da7Schristos if (pNtQuerySystemInformation == NULL) {
1100e552da7Schristos uv_fatal_error(GetLastError(), "GetProcAddress");
1110e552da7Schristos }
1120e552da7Schristos
1130e552da7Schristos pNtQueryInformationProcess = (sNtQueryInformationProcess) GetProcAddress(
1140e552da7Schristos ntdll_module,
1150e552da7Schristos "NtQueryInformationProcess");
1160e552da7Schristos if (pNtQueryInformationProcess == NULL) {
1170e552da7Schristos uv_fatal_error(GetLastError(), "GetProcAddress");
1180e552da7Schristos }
1190e552da7Schristos
1200e552da7Schristos kernel32_module = GetModuleHandleA("kernel32.dll");
1210e552da7Schristos if (kernel32_module == NULL) {
1220e552da7Schristos uv_fatal_error(GetLastError(), "GetModuleHandleA");
1230e552da7Schristos }
1240e552da7Schristos
1250e552da7Schristos pGetQueuedCompletionStatusEx = (sGetQueuedCompletionStatusEx) GetProcAddress(
1260e552da7Schristos kernel32_module,
1270e552da7Schristos "GetQueuedCompletionStatusEx");
1280e552da7Schristos
129*5f2f4271Schristos powrprof_module = LoadLibraryExA("powrprof.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
1300e552da7Schristos if (powrprof_module != NULL) {
1310e552da7Schristos pPowerRegisterSuspendResumeNotification = (sPowerRegisterSuspendResumeNotification)
1320e552da7Schristos GetProcAddress(powrprof_module, "PowerRegisterSuspendResumeNotification");
1330e552da7Schristos }
1340e552da7Schristos
135*5f2f4271Schristos user32_module = GetModuleHandleA("user32.dll");
1360e552da7Schristos if (user32_module != NULL) {
1370e552da7Schristos pSetWinEventHook = (sSetWinEventHook)
1380e552da7Schristos GetProcAddress(user32_module, "SetWinEventHook");
1390e552da7Schristos }
140*5f2f4271Schristos
141*5f2f4271Schristos ws2_32_module = GetModuleHandleA("ws2_32.dll");
142*5f2f4271Schristos if (ws2_32_module != NULL) {
143*5f2f4271Schristos pGetHostNameW = (uv_sGetHostNameW) GetProcAddress(
144*5f2f4271Schristos ws2_32_module,
145*5f2f4271Schristos "GetHostNameW");
146*5f2f4271Schristos }
1470e552da7Schristos }
148