2023-02-16 16:01:21 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: AuProcAddresses.NT.cpp
|
|
|
|
Date: 2023-2-16
|
|
|
|
Author: Reece
|
|
|
|
***/
|
2024-04-11 20:43:56 +00:00
|
|
|
#include <AuroraEnvironment.h>
|
|
|
|
|
|
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
|
|
|
#define _WIN32_WINNT 0x0602
|
|
|
|
#endif
|
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
#include <RuntimeInternal.hpp>
|
2023-09-02 03:55:43 +00:00
|
|
|
#include "Source/Threading/Primitives/AuConditionMutex.NT.hpp"
|
2023-02-16 16:01:21 +00:00
|
|
|
|
2023-09-17 21:06:48 +00:00
|
|
|
#define AURORA_HAS_LOAD_PGKD
|
|
|
|
#define AURORA_HAS_GET_PROC_NONWIN32
|
|
|
|
|
2023-12-08 13:37:06 +00:00
|
|
|
#if !defined(AURORA_RUNITIME_NO_PROFILE_SYMBOL)
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
// As much as I despise third-party drivers matching module names and pattern matching,
|
|
|
|
// we may as well provide some hint for:
|
|
|
|
// * Windows emulators
|
|
|
|
// * Future first party win32 compatibility layers
|
|
|
|
// * Drivers checking for the vintage
|
|
|
|
// * Non-standard PE linkers (Aurora::AddBlockedDLL(...) is valid)
|
|
|
|
AUKN_SYM int NT_APPLICATION_COMPAT_AURORA_RUNTIME_ALPHA;
|
|
|
|
AUKN_SYM int NT_APPLICATION_COMPAT_AURORA_RUNTIME;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-03-19 15:47:42 +00:00
|
|
|
namespace Aurora::Memory
|
|
|
|
{
|
|
|
|
AuUInt32 RoundPageUp(AuUInt32 value);
|
|
|
|
}
|
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
namespace Aurora
|
|
|
|
{
|
2024-09-10 07:14:54 +00:00
|
|
|
static bool gShouldResPathDoNothing {}; // always
|
|
|
|
static bool gShouldResPathDoNothing2 {}; // win11 singleshot
|
|
|
|
static ULONG gLastActualResolution {};
|
2023-07-09 12:51:05 +00:00
|
|
|
|
2023-09-17 21:06:48 +00:00
|
|
|
#if !defined(AURORA_PLATFORM_WIN32)
|
2023-09-20 17:33:27 +00:00
|
|
|
HMODULE UWPLibraryW(LPCWSTR lpLibFileName);
|
2023-09-17 21:06:48 +00:00
|
|
|
|
|
|
|
FARPROC UWPProcAddress(HMODULE hModule,
|
2023-09-20 17:33:27 +00:00
|
|
|
LPCSTR lpProcName);
|
2024-04-09 22:39:00 +00:00
|
|
|
|
|
|
|
HANDLE __stdcall UWPCreateFileMappingA(HANDLE hFile,
|
|
|
|
LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
|
|
|
|
DWORD flProtect,
|
|
|
|
DWORD dwMaximumSizeHigh,
|
|
|
|
DWORD dwMaximumSizeLow,
|
|
|
|
LPCSTR lpName);
|
|
|
|
|
|
|
|
HANDLE __stdcall UWPOpenFileMappingA(DWORD dwDesiredAccess,
|
|
|
|
BOOL bInheritHandle,
|
|
|
|
LPCSTR lpName);
|
|
|
|
|
|
|
|
LPVOID __stdcall UWPMapViewOfFile(HANDLE hFileMappingObject,
|
|
|
|
DWORD dwDesiredAccess,
|
|
|
|
DWORD dwFileOffsetHigh,
|
|
|
|
DWORD dwFileOffsetLow,
|
|
|
|
SIZE_T dwNumberOfBytesToMap);
|
2023-09-17 21:06:48 +00:00
|
|
|
#endif
|
|
|
|
|
2023-10-17 04:38:08 +00:00
|
|
|
#if !defined(AURORA_DLL_BLACKLIST)
|
2024-04-15 16:22:47 +00:00
|
|
|
static AuUInt32 gBlockedDLLTable[128] {};
|
2023-10-17 04:38:08 +00:00
|
|
|
#else
|
2024-04-15 16:22:47 +00:00
|
|
|
static AuUInt32 gBlockedDLLTable[128] { AURORA_DLL_BLACKLIST };
|
2023-10-17 04:38:08 +00:00
|
|
|
#endif
|
2023-10-14 19:21:39 +00:00
|
|
|
|
|
|
|
AUKN_SYM bool AddBlockedDLL(const char *pString)
|
|
|
|
{
|
|
|
|
if (!pString)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto uHash = AuFnv1a32Runtime(pString, strlen(pString));
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(i, AuArraySize(gBlockedDLLTable)))
|
|
|
|
{
|
|
|
|
if (gBlockedDLLTable[i])
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
gBlockedDLLTable[i] = uHash;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsBlocked(const char *pString)
|
|
|
|
{
|
|
|
|
auto uHash = AuFnv1a32Runtime(pString, strlen(pString));
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(i, AuArraySize(gBlockedDLLTable)))
|
|
|
|
{
|
2023-10-18 04:06:04 +00:00
|
|
|
auto uCurrent = gBlockedDLLTable[i];
|
|
|
|
|
|
|
|
if (uCurrent == uHash)
|
2023-10-14 19:21:39 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2023-10-18 04:06:04 +00:00
|
|
|
else if (uCurrent == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2023-10-14 19:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-12-07 19:00:14 +00:00
|
|
|
void InitNTAddressesForClock()
|
|
|
|
{
|
|
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
|
|
|
// We just need a partial AuSwInfo pass to work in order to setup the clocks at TLS callback-time
|
|
|
|
// Why? rng isnt ready either. We need the fallback clock to work.
|
|
|
|
pLoadLibraryW = LoadLibraryW;
|
|
|
|
pGetProcAddress = GetProcAddress;
|
|
|
|
|
|
|
|
#define ADD_LOAD_LIB(name) \
|
|
|
|
HMODULE h ## name {}; \
|
|
|
|
h ## name = GetModuleHandleW(k## name ## DllName); \
|
|
|
|
if (!h ## name) \
|
|
|
|
{ \
|
|
|
|
h ## name = pLoadLibraryW(k## name ## DllName); \
|
|
|
|
} \
|
|
|
|
|
|
|
|
#define ADD_GET_PROC(name, proc) \
|
|
|
|
if (h ## name) \
|
|
|
|
{ \
|
|
|
|
p ## proc = AuReinterpretCast<decltype(p ## proc)>(pGetProcAddress(h ## name, #proc)); \
|
|
|
|
} \
|
|
|
|
|
|
|
|
ADD_LOAD_LIB(Kernel32);
|
|
|
|
#if 0
|
|
|
|
ADD_LOAD_LIB(AdvancedApi);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ADD_GET_PROC(Kernel32, VerifyVersionInfoW)
|
|
|
|
ADD_GET_PROC(Kernel32, VerSetConditionMask)
|
|
|
|
ADD_GET_PROC(Kernel32, QueryPerformanceCounter)
|
|
|
|
ADD_GET_PROC(Kernel32, QueryPerformanceFrequency)
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
ADD_GET_PROC(AdvancedApi, RegSetValueExW)
|
|
|
|
ADD_GET_PROC(AdvancedApi, RegCloseKey)
|
|
|
|
ADD_GET_PROC(AdvancedApi, RegOpenKeyExW)
|
|
|
|
ADD_GET_PROC(AdvancedApi, RegQueryValueExW)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef ADD_GET_PROC
|
|
|
|
#undef ADD_LOAD_LIB
|
|
|
|
#else
|
|
|
|
InitNTAddresses();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
void InitNTAddresses()
|
|
|
|
{
|
|
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
2023-09-17 21:06:48 +00:00
|
|
|
pLoadLibraryW = LoadLibraryW;
|
|
|
|
pGetProcAddress = GetProcAddress;
|
|
|
|
|
2023-07-09 09:03:29 +00:00
|
|
|
#define ADD_LOAD_LIB(name) \
|
2023-10-14 19:21:39 +00:00
|
|
|
\
|
|
|
|
HMODULE h ## name {}; \
|
|
|
|
if (!IsBlocked(#name)) \
|
2023-07-09 09:03:29 +00:00
|
|
|
{ \
|
2023-10-14 19:21:39 +00:00
|
|
|
h ## name = GetModuleHandleW(k## name ## DllName); \
|
|
|
|
if (!h ## name) \
|
|
|
|
{ \
|
|
|
|
h ## name = pLoadLibraryW(k## name ## DllName); \
|
|
|
|
} \
|
2023-07-09 09:03:29 +00:00
|
|
|
}
|
2023-02-16 16:01:21 +00:00
|
|
|
|
|
|
|
ADD_LOAD_LIB(Kernel32);
|
|
|
|
ADD_LOAD_LIB(Nt);
|
|
|
|
ADD_LOAD_LIB(KernelBase);
|
|
|
|
ADD_LOAD_LIB(Sync);
|
2023-07-09 09:03:29 +00:00
|
|
|
ADD_LOAD_LIB(WS2);
|
2023-07-09 10:26:17 +00:00
|
|
|
ADD_LOAD_LIB(AdvancedApi);
|
|
|
|
ADD_LOAD_LIB(BCrypt);
|
2023-07-24 06:17:08 +00:00
|
|
|
ADD_LOAD_LIB(Theme);
|
|
|
|
ADD_LOAD_LIB(Shell);
|
2023-07-24 11:48:42 +00:00
|
|
|
ADD_LOAD_LIB(PSAPILegacy);
|
2023-08-27 16:43:29 +00:00
|
|
|
ADD_LOAD_LIB(DbgHelper);
|
|
|
|
ADD_LOAD_LIB(WinTrust);
|
|
|
|
ADD_LOAD_LIB(IPHelper);
|
2023-09-17 20:33:14 +00:00
|
|
|
ADD_LOAD_LIB(COM);
|
2023-10-12 23:10:44 +00:00
|
|
|
ADD_LOAD_LIB(User32);
|
2023-12-05 18:44:38 +00:00
|
|
|
ADD_LOAD_LIB(SetupAPI);
|
|
|
|
ADD_LOAD_LIB(Router);
|
2023-12-28 21:00:07 +00:00
|
|
|
ADD_LOAD_LIB(CredUI);
|
2023-02-16 16:01:21 +00:00
|
|
|
|
2023-10-17 07:14:20 +00:00
|
|
|
#define ADD_GET_PROC(name, proc) \
|
|
|
|
if (!IsBlocked(#proc)) \
|
|
|
|
{ \
|
|
|
|
if (h ## name) \
|
|
|
|
{ \
|
|
|
|
p ## proc = AuReinterpretCast<decltype(p ## proc)>(pGetProcAddress(h ## name, #proc)); \
|
|
|
|
} \
|
2023-02-16 16:01:21 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 07:14:20 +00:00
|
|
|
#define ADD_GET_PROC_BI(name, name2, proc) \
|
|
|
|
if (!IsBlocked(#proc)) \
|
|
|
|
{ \
|
|
|
|
p ## proc = nullptr; \
|
|
|
|
if (h ## name) \
|
|
|
|
{ \
|
|
|
|
p ## proc = AuReinterpretCast<decltype(p ## proc)>(pGetProcAddress(h ## name, #proc)); \
|
|
|
|
} \
|
|
|
|
if (!p ## proc) \
|
|
|
|
{ \
|
|
|
|
if (h ## name2) \
|
|
|
|
{ \
|
|
|
|
p ## proc = AuReinterpretCast<decltype(p ## proc)>(pGetProcAddress(h ## name2, #proc));\
|
|
|
|
} \
|
|
|
|
} \
|
2023-02-16 16:01:21 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 07:14:20 +00:00
|
|
|
#define ADD_GET_PROC_BI2(name, name2, proc, proc2) \
|
|
|
|
if (!IsBlocked(#proc)) \
|
|
|
|
{ \
|
|
|
|
p ## proc2 = nullptr; \
|
|
|
|
if (h ## name) \
|
|
|
|
{ \
|
|
|
|
p ## proc2 = AuReinterpretCast<decltype(p ## proc2)>(pGetProcAddress(h ## name, #proc)); \
|
|
|
|
} \
|
|
|
|
if (!p ## proc2) \
|
|
|
|
{ \
|
|
|
|
if (h ## name2) \
|
|
|
|
{ \
|
|
|
|
p ## proc2 = AuReinterpretCast<decltype(p ## proc2)>(pGetProcAddress(h ## name2, #proc2)); \
|
|
|
|
} \
|
|
|
|
} \
|
2023-07-24 11:48:42 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 07:14:20 +00:00
|
|
|
#define ADD_GET_PROC_INTERNAL_MAP(name, proc, symbol) \
|
|
|
|
if (!IsBlocked(#proc)) \
|
|
|
|
{ \
|
|
|
|
if (h ## name) \
|
|
|
|
{ \
|
|
|
|
p ## proc = AuReinterpretCast<decltype(p ## proc)>(pGetProcAddress(h ## name, #symbol)); \
|
|
|
|
} \
|
2023-07-11 16:58:20 +00:00
|
|
|
}
|
|
|
|
|
2023-03-15 00:35:29 +00:00
|
|
|
if (pRtlGetVersion)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
ADD_GET_PROC(Nt, RtlGetVersion)
|
|
|
|
ADD_GET_PROC(Nt, NtDelayExecution)
|
2023-03-15 00:35:29 +00:00
|
|
|
ADD_GET_PROC(Nt, NtWaitForKeyedEvent)
|
|
|
|
ADD_GET_PROC(Nt, NtReleaseKeyedEvent)
|
|
|
|
ADD_GET_PROC(Nt, NtOpenKeyedEvent)
|
|
|
|
ADD_GET_PROC(Nt, NtCreateKeyedEvent)
|
2023-06-15 19:44:27 +00:00
|
|
|
ADD_GET_PROC(Nt, RtlWaitOnAddress)
|
2023-09-09 14:29:12 +00:00
|
|
|
ADD_GET_PROC(Nt, RtlWakeByAddressAll)
|
|
|
|
ADD_GET_PROC(Nt, RtlWakeAddressSingle)
|
2023-07-09 11:34:14 +00:00
|
|
|
ADD_GET_PROC(Nt, ZwSetTimerResolution)
|
2024-09-10 07:14:54 +00:00
|
|
|
ADD_GET_PROC(Nt, ZwQueryTimerResolution)
|
2023-07-24 06:17:08 +00:00
|
|
|
ADD_GET_PROC(Nt, NtQueryInformationProcess)
|
2023-07-28 13:09:23 +00:00
|
|
|
ADD_GET_PROC(Nt, NtNotifyChangeDirectoryFile)
|
2023-08-19 12:30:44 +00:00
|
|
|
ADD_GET_PROC(Nt, NtTerminateProcess)
|
2023-12-05 18:44:38 +00:00
|
|
|
ADD_GET_PROC(Nt, NtQuerySymbolicLinkObject)
|
|
|
|
ADD_GET_PROC(Nt, NtOpenSymbolicLinkObject)
|
2023-12-22 05:01:04 +00:00
|
|
|
ADD_GET_PROC(Nt, NtWaitForMultipleObjects)
|
2024-04-21 10:37:00 +00:00
|
|
|
ADD_GET_PROC(Nt, NtQuerySystemInformation)
|
2023-07-28 13:09:23 +00:00
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
ADD_GET_PROC_BI(Kernel32, KernelBase, VirtualAlloc2)
|
2024-04-09 22:39:00 +00:00
|
|
|
ADD_GET_PROC_BI(Kernel32, KernelBase, MapViewOfFile)
|
2023-02-16 16:01:21 +00:00
|
|
|
ADD_GET_PROC_BI(Kernel32, KernelBase, MapViewOfFile3)
|
|
|
|
ADD_GET_PROC_BI(Kernel32, KernelBase, UnmapViewOfFile2)
|
2023-09-13 01:27:18 +00:00
|
|
|
ADD_GET_PROC_BI(Kernel32, KernelBase, CreateFileW)
|
2023-09-13 13:17:45 +00:00
|
|
|
ADD_GET_PROC_BI(Kernel32, KernelBase, CreateFile2W)
|
2024-03-10 15:00:13 +00:00
|
|
|
ADD_GET_PROC_BI(Kernel32, KernelBase, GetTempPathW)
|
2024-04-09 22:39:00 +00:00
|
|
|
ADD_GET_PROC_BI(Kernel32, KernelBase, CreateFileMappingA)
|
|
|
|
ADD_GET_PROC_BI(Kernel32, KernelBase, OpenFileMappingA)
|
2023-09-13 01:27:18 +00:00
|
|
|
|
2023-07-09 09:02:21 +00:00
|
|
|
ADD_GET_PROC(Kernel32, GetSystemCpuSetInformation)
|
|
|
|
ADD_GET_PROC(Kernel32, GetLogicalProcessorInformation)
|
2023-07-09 09:03:29 +00:00
|
|
|
ADD_GET_PROC(Kernel32, SetThreadDescription)
|
|
|
|
ADD_GET_PROC(Kernel32, SetThreadInformation)
|
|
|
|
ADD_GET_PROC(Kernel32, SetThreadSelectedCpuSets)
|
|
|
|
ADD_GET_PROC(Kernel32, PrefetchVirtualMemory)
|
2023-07-14 15:31:47 +00:00
|
|
|
ADD_GET_PROC(Kernel32, SetThreadGroupAffinity)
|
2023-07-24 06:17:08 +00:00
|
|
|
ADD_GET_PROC(Kernel32, FindFirstStreamW)
|
|
|
|
ADD_GET_PROC(Kernel32, FindNextStreamW)
|
|
|
|
ADD_GET_PROC(Kernel32, FindClose)
|
2023-07-24 11:48:42 +00:00
|
|
|
ADD_GET_PROC(Kernel32, CancelIoEx)
|
|
|
|
ADD_GET_PROC(Kernel32, CancelSynchronousIo)
|
|
|
|
ADD_GET_PROC(Kernel32, SetFileInformationByHandle)
|
|
|
|
ADD_GET_PROC(Kernel32, GetLocaleInfoEx)
|
|
|
|
ADD_GET_PROC(Kernel32, LCIDToLocaleName)
|
|
|
|
ADD_GET_PROC(Kernel32, GetLocaleInfoW)
|
|
|
|
ADD_GET_PROC(Kernel32, GetThreadId)
|
2023-08-27 16:43:29 +00:00
|
|
|
ADD_GET_PROC(Kernel32, VerifyVersionInfoW)
|
2023-08-27 17:34:28 +00:00
|
|
|
ADD_GET_PROC(Kernel32, VerSetConditionMask)
|
2023-10-07 15:57:20 +00:00
|
|
|
ADD_GET_PROC(Kernel32, QueryPerformanceCounter)
|
|
|
|
ADD_GET_PROC(Kernel32, QueryPerformanceFrequency)
|
2023-10-10 23:21:32 +00:00
|
|
|
ADD_GET_PROC(Kernel32, RemoveDllDirectory)
|
|
|
|
ADD_GET_PROC(Kernel32, AddDllDirectory)
|
2024-03-12 22:50:22 +00:00
|
|
|
ADD_GET_PROC(Kernel32, SetProcessInformation)
|
2024-04-21 10:37:00 +00:00
|
|
|
ADD_GET_PROC(Kernel32, GetNamedPipeClientProcessId)
|
|
|
|
ADD_GET_PROC(Kernel32, Module32FirstW)
|
|
|
|
ADD_GET_PROC(Kernel32, Module32NextW)
|
|
|
|
ADD_GET_PROC(Kernel32, CreateJobObjectW)
|
2024-09-10 07:14:54 +00:00
|
|
|
ADD_GET_PROC(Kernel32, CreateWaitableTimerExW)
|
2024-04-14 22:11:15 +00:00
|
|
|
|
|
|
|
ADD_GET_PROC(Kernel32, GetConsoleScreenBufferInfo)
|
|
|
|
ADD_GET_PROC(Kernel32, SetConsoleScreenBufferSize)
|
|
|
|
ADD_GET_PROC(Kernel32, SetConsoleWindowInfo)
|
|
|
|
ADD_GET_PROC(Kernel32, CreateConsoleScreenBuffer)
|
|
|
|
ADD_GET_PROC(Kernel32, SetConsoleCursorPosition)
|
|
|
|
ADD_GET_PROC(Kernel32, FillConsoleOutputCharacterW)
|
|
|
|
ADD_GET_PROC(Kernel32, FillConsoleOutputAttribute)
|
|
|
|
ADD_GET_PROC(Kernel32, SetConsoleTextAttribute)
|
|
|
|
ADD_GET_PROC(Kernel32, SetConsoleActiveScreenBuffer)
|
|
|
|
ADD_GET_PROC(Kernel32, ScrollConsoleScreenBufferW)
|
|
|
|
ADD_GET_PROC(Kernel32, WriteConsoleInputW)
|
|
|
|
ADD_GET_PROC(Kernel32, WriteConsoleW)
|
|
|
|
ADD_GET_PROC(Kernel32, ReadConsoleInputW)
|
|
|
|
ADD_GET_PROC(Kernel32, GetNumberOfConsoleInputEvents)
|
|
|
|
|
2023-07-24 11:48:42 +00:00
|
|
|
ADD_GET_PROC_BI2(Kernel32, PSAPILegacy, K32GetProcessMemoryInfo, GetProcessMemoryInfo)
|
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
ADD_GET_PROC(Sync, WaitOnAddress)
|
|
|
|
ADD_GET_PROC(Sync, WakeByAddressSingle)
|
|
|
|
ADD_GET_PROC(Sync, WakeByAddressAll)
|
2023-08-27 16:43:29 +00:00
|
|
|
|
|
|
|
ADD_GET_PROC(DbgHelper, UnDecorateSymbolName)
|
|
|
|
ADD_GET_PROC(DbgHelper, MiniDumpWriteDump)
|
|
|
|
ADD_GET_PROC(DbgHelper, SymInitialize)
|
|
|
|
ADD_GET_PROC(DbgHelper, SymGetModuleBase64)
|
|
|
|
ADD_GET_PROC(DbgHelper, SymGetLineFromAddr64)
|
|
|
|
ADD_GET_PROC(DbgHelper, SymFunctionTableAccess64)
|
|
|
|
ADD_GET_PROC(DbgHelper, StackWalk64)
|
|
|
|
|
2023-07-24 06:17:08 +00:00
|
|
|
ADD_GET_PROC(WS2, GetAddrInfoExW)
|
2023-07-09 09:03:29 +00:00
|
|
|
ADD_GET_PROC(WS2, GetAddrInfoExCancel)
|
2023-07-24 06:17:08 +00:00
|
|
|
ADD_GET_PROC(WS2, FreeAddrInfoExW)
|
|
|
|
ADD_GET_PROC(WS2, getaddrinfo)
|
|
|
|
ADD_GET_PROC(WS2, freeaddrinfo)
|
2023-12-07 11:13:32 +00:00
|
|
|
ADD_GET_PROC(WS2, listen)
|
|
|
|
ADD_GET_PROC(WS2, bind)
|
|
|
|
ADD_GET_PROC(WS2, closesocket)
|
|
|
|
ADD_GET_PROC(WS2, shutdown)
|
|
|
|
ADD_GET_PROC(WS2, getpeername)
|
|
|
|
ADD_GET_PROC(WS2, getsockname)
|
|
|
|
ADD_GET_PROC(WS2, ioctlsocket)
|
|
|
|
ADD_GET_PROC(WS2, setsockopt)
|
|
|
|
ADD_GET_PROC(WS2, WSAStartup)
|
|
|
|
ADD_GET_PROC(WS2, WSAIoctl)
|
|
|
|
ADD_GET_PROC(WS2, WSAGetLastError)
|
|
|
|
ADD_GET_PROC(WS2, WSASocketW)
|
|
|
|
ADD_GET_PROC(WS2, WSARecvFrom)
|
|
|
|
ADD_GET_PROC(WS2, WSARecv)
|
|
|
|
ADD_GET_PROC(WS2, WSASendTo)
|
|
|
|
ADD_GET_PROC(WS2, WSASend)
|
|
|
|
ADD_GET_PROC(WS2, WSAStringToAddressA)
|
|
|
|
|
2023-08-27 16:43:29 +00:00
|
|
|
ADD_GET_PROC(WinTrust, WinVerifyTrust)
|
|
|
|
|
|
|
|
ADD_GET_PROC(IPHelper, GetAdaptersAddresses)
|
|
|
|
ADD_GET_PROC(IPHelper, GetAdaptersInfo)
|
|
|
|
|
2023-07-09 10:26:17 +00:00
|
|
|
ADD_GET_PROC(AdvancedApi, CryptAcquireContextW)
|
|
|
|
ADD_GET_PROC(AdvancedApi, CryptReleaseContext)
|
|
|
|
ADD_GET_PROC(AdvancedApi, CryptGenRandom)
|
2023-10-11 01:13:49 +00:00
|
|
|
|
|
|
|
ADD_GET_PROC(AdvancedApi, RegSetValueExW)
|
|
|
|
ADD_GET_PROC(AdvancedApi, RegCloseKey)
|
|
|
|
ADD_GET_PROC(AdvancedApi, RegOpenKeyExW)
|
|
|
|
ADD_GET_PROC(AdvancedApi, RegQueryValueExW)
|
|
|
|
|
|
|
|
ADD_GET_PROC(AdvancedApi, DeregisterEventSource)
|
|
|
|
ADD_GET_PROC(AdvancedApi, RegisterEventSourceW)
|
|
|
|
ADD_GET_PROC(AdvancedApi, ReportEventW)
|
|
|
|
|
|
|
|
ADD_GET_PROC(AdvancedApi, SetEntriesInAclA)
|
|
|
|
ADD_GET_PROC(AdvancedApi, AllocateAndInitializeSid)
|
|
|
|
ADD_GET_PROC(AdvancedApi, SetNamedSecurityInfoW)
|
|
|
|
ADD_GET_PROC(AdvancedApi, FreeSid)
|
|
|
|
|
2023-12-28 21:00:07 +00:00
|
|
|
// privilege escalation
|
|
|
|
ADD_GET_PROC(AdvancedApi, CreateProcessWithLogonW);
|
|
|
|
ADD_GET_PROC(AdvancedApi, CreateProcessAsUserW);
|
|
|
|
ADD_GET_PROC(AdvancedApi, AdjustTokenPrivileges);
|
|
|
|
ADD_GET_PROC(AdvancedApi, RevertToSelf);
|
|
|
|
ADD_GET_PROC(AdvancedApi, SetTokenInformation);
|
|
|
|
ADD_GET_PROC(AdvancedApi, GetSidSubAuthorityCount);
|
|
|
|
ADD_GET_PROC(AdvancedApi, GetSidSubAuthority);
|
|
|
|
ADD_GET_PROC(AdvancedApi, LogonUserW);
|
|
|
|
ADD_GET_PROC(AdvancedApi, OpenProcessToken);
|
|
|
|
ADD_GET_PROC(AdvancedApi, SetThreadToken);
|
|
|
|
ADD_GET_PROC(AdvancedApi, SetSecurityInfo);
|
|
|
|
ADD_GET_PROC(AdvancedApi, GetUserNameW);
|
|
|
|
ADD_GET_PROC(AdvancedApi, DuplicateTokenEx);
|
|
|
|
ADD_GET_PROC(AdvancedApi, LookupAccountSidW);
|
|
|
|
ADD_GET_PROC(AdvancedApi, GetTokenInformation);
|
|
|
|
ADD_GET_PROC(AdvancedApi, SetSecurityDescriptorDacl);
|
|
|
|
ADD_GET_PROC(AdvancedApi, InitializeSecurityDescriptor);
|
|
|
|
ADD_GET_PROC(AdvancedApi, LookupAccountNameW);
|
|
|
|
ADD_GET_PROC(AdvancedApi, LookupPrivilegeValueA);
|
|
|
|
ADD_GET_PROC(AdvancedApi, LsaOpenPolicy);
|
|
|
|
ADD_GET_PROC(AdvancedApi, LsaClose);
|
|
|
|
ADD_GET_PROC(AdvancedApi, LsaAddAccountRights);
|
|
|
|
|
2023-07-11 16:58:20 +00:00
|
|
|
ADD_GET_PROC_INTERNAL_MAP(AdvancedApi, RtlGenRandom, SystemFunction036)
|
2023-07-24 06:17:08 +00:00
|
|
|
|
2023-07-09 10:26:17 +00:00
|
|
|
ADD_GET_PROC(BCrypt, BCryptGenRandom)
|
|
|
|
|
2023-07-24 06:17:08 +00:00
|
|
|
ADD_GET_PROC(Theme, SetWindowTheme)
|
2023-09-17 20:33:14 +00:00
|
|
|
|
|
|
|
ADD_GET_PROC(COM, CoInitializeEx)
|
|
|
|
ADD_GET_PROC(COM, CoUninitialize)
|
|
|
|
ADD_GET_PROC(COM, CoTaskMemFree)
|
2023-07-24 06:17:08 +00:00
|
|
|
|
|
|
|
ADD_GET_PROC(Shell, SHGetKnownFolderPath)
|
2023-09-17 20:33:14 +00:00
|
|
|
ADD_GET_PROC(Shell, SHGetFolderPathA)
|
|
|
|
ADD_GET_PROC(Shell, CommandLineToArgvW)
|
|
|
|
ADD_GET_PROC(Shell, ShellExecuteW)
|
2023-09-02 03:55:43 +00:00
|
|
|
|
2023-10-12 23:10:44 +00:00
|
|
|
ADD_GET_PROC(User32, GetClipboardData);
|
|
|
|
ADD_GET_PROC(User32, MapVirtualKeyA);
|
|
|
|
ADD_GET_PROC(User32, CloseClipboard);
|
|
|
|
ADD_GET_PROC(User32, GetWindowThreadProcessId);
|
|
|
|
ADD_GET_PROC(User32, SendMessageA);
|
|
|
|
ADD_GET_PROC(User32, EnumThreadWindows);
|
|
|
|
ADD_GET_PROC(User32, DispatchMessageW);
|
|
|
|
ADD_GET_PROC(User32, TranslateMessage);
|
|
|
|
ADD_GET_PROC(User32, MsgWaitForMultipleObjectsEx);
|
|
|
|
ADD_GET_PROC(User32, MsgWaitForMultipleObjects);
|
|
|
|
ADD_GET_PROC(User32, PeekMessageW);
|
|
|
|
ADD_GET_PROC(User32, SetPropW);
|
|
|
|
ADD_GET_PROC(User32, OpenClipboard);
|
2023-09-02 03:55:43 +00:00
|
|
|
|
2023-12-05 18:44:38 +00:00
|
|
|
ADD_GET_PROC(SetupAPI, SetupDiEnumDeviceInterfaces);
|
|
|
|
ADD_GET_PROC(SetupAPI, SetupDiDestroyDeviceInfoList);
|
|
|
|
ADD_GET_PROC(SetupAPI, SetupDiGetClassDevsW);
|
|
|
|
ADD_GET_PROC(SetupAPI, SetupDiGetDeviceRegistryPropertyA);
|
|
|
|
ADD_GET_PROC(SetupAPI, SetupDiGetDeviceInterfaceDetailW);
|
|
|
|
|
|
|
|
ADD_GET_PROC(Router, WNetCloseEnum);
|
|
|
|
ADD_GET_PROC(Router, WNetEnumResourceW);
|
|
|
|
ADD_GET_PROC(Router, WNetOpenEnumW);
|
|
|
|
ADD_GET_PROC(Router, WNetGetUniversalNameW);
|
|
|
|
|
2023-12-28 21:00:07 +00:00
|
|
|
ADD_GET_PROC(CredUI, CredUIPromptForWindowsCredentialsW);
|
|
|
|
ADD_GET_PROC(CredUI, CredUnPackAuthenticationBufferW);
|
2023-12-05 18:44:38 +00:00
|
|
|
|
2023-09-02 03:55:43 +00:00
|
|
|
if (pNtCreateKeyedEvent &&
|
|
|
|
Threading::Primitives::gKeyedEventHandle == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
if (!gUseNativeWaitCondvar)
|
|
|
|
{
|
|
|
|
SysAssert(pNtCreateKeyedEvent);
|
|
|
|
pNtCreateKeyedEvent(&Threading::Primitives::gKeyedEventHandle, -1, NULL, 0);
|
|
|
|
}
|
|
|
|
}
|
2023-10-07 15:57:20 +00:00
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
#else
|
2023-09-17 21:06:48 +00:00
|
|
|
pLoadLibraryW = UWPLibraryW;
|
|
|
|
pGetProcAddress = UWPProcAddress;
|
|
|
|
|
2023-09-13 13:17:45 +00:00
|
|
|
pCreateFile2W = CreateFile2FromAppW;
|
2024-04-09 22:39:00 +00:00
|
|
|
pCreateFileMappingFromApp = CreateFileMappingFromApp;
|
|
|
|
pOpenFileMappingFromApp = OpenFileMappingFromApp;
|
|
|
|
pMapViewOfFileFromApp = MapViewOfFileFromApp;
|
|
|
|
pCreateFileMappingA = UWPCreateFileMappingA;
|
|
|
|
pOpenFileMappingA = UWPOpenFileMappingA;
|
|
|
|
pMapViewOfFile = UWPMapViewOfFile;
|
2023-09-13 01:27:18 +00:00
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
pWaitOnAddress = WaitOnAddress;
|
|
|
|
pWakeByAddressSingle = WakeByAddressSingle;
|
|
|
|
pWakeByAddressAll = WakeByAddressAll;
|
|
|
|
pVirtualAlloc2 = VirtualAlloc2FromApp;
|
|
|
|
pMapViewOfFile3 = MapViewOfFile3FromApp;
|
2023-07-09 09:03:29 +00:00
|
|
|
|
2023-07-24 11:48:42 +00:00
|
|
|
pCancelIoEx = CancelIoEx;
|
|
|
|
pCancelSynchronousIo = CancelSynchronousIo;
|
|
|
|
|
|
|
|
pGetLocaleInfoEx = GetLocaleInfoEx;
|
|
|
|
|
|
|
|
pLCIDToLocaleName = LCIDToLocaleName;
|
|
|
|
|
|
|
|
pSetFileInformationByHandle = SetFileInformationByHandle;
|
|
|
|
|
|
|
|
pFindClose = FindClose;
|
|
|
|
|
2024-03-10 15:00:13 +00:00
|
|
|
pGetTempPathW = GetTempPath2W;
|
|
|
|
|
2023-07-09 09:03:29 +00:00
|
|
|
pGetSystemCpuSetInformation = GetSystemCpuSetInformation;
|
|
|
|
pGetLogicalProcessorInformation = GetLogicalProcessorInformation;
|
|
|
|
|
|
|
|
pSetThreadInformation = SetThreadInformation;
|
|
|
|
pSetThreadDescription = SetThreadDescription;
|
|
|
|
pSetThreadSelectedCpuSets = SetThreadSelectedCpuSets;
|
|
|
|
|
|
|
|
pGetAddrInfoExCancel = GetAddrInfoExCancel;
|
|
|
|
|
|
|
|
pPrefetchVirtualMemory = PrefetchVirtualMemory;
|
|
|
|
|
2023-10-07 15:57:20 +00:00
|
|
|
pQueryPerformanceCounter = decltype(pQueryPerformanceCounter)(QueryPerformanceCounter);
|
|
|
|
pQueryPerformanceFrequency = decltype(pQueryPerformanceFrequency)(QueryPerformanceFrequency);
|
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
// https://github.com/LWJGL/lwjgl3/blob/master/modules/lwjgl/remotery/src/main/c/Remotery.c#L1188
|
|
|
|
// Xbox main SDK has a better API we should use
|
|
|
|
// So...
|
|
|
|
// TODO: Xbox One and later: https://github.com/microsoft/Xbox-ATG-Samples/blob/main/XDKSamples/Graphics/AdvancedESRAM12/PageAllocator.cpp#L193-L206
|
|
|
|
// Require AuProcess for that given target
|
|
|
|
|
|
|
|
pUnmapViewOfFile2 = UnmapViewOfFile2; // < isn't portable but
|
|
|
|
// "This topic lists the Win32 APIs that are part of the Universal Windows Platform (UWP) and that are implemented by all Windows 10 devices."
|
|
|
|
// UnmapViewOfFile2 -> Introduced into api-ms-win-core-memory-l1-1-5.dll in 10.0.17134.
|
|
|
|
|
2024-04-11 20:38:26 +00:00
|
|
|
pNtDelayExecution = nullptr /* ... (you dont need it, but it'll help a ton for SleepNs) */;
|
|
|
|
|
|
|
|
pGetAddrInfoExW = GetAddrInfoExW;
|
|
|
|
pGetAddrInfoExCancel = GetAddrInfoExCancel;
|
|
|
|
pFreeAddrInfoExW = FreeAddrInfoExW;
|
|
|
|
pgetaddrinfo = getaddrinfo;
|
|
|
|
pfreeaddrinfo = freeaddrinfo;
|
|
|
|
plisten = listen;
|
|
|
|
pbind = bind;
|
|
|
|
pclosesocket = closesocket;
|
|
|
|
pshutdown = shutdown;
|
|
|
|
pgetpeername = getpeername;
|
|
|
|
pgetsockname = getsockname;
|
|
|
|
pioctlsocket = ioctlsocket;
|
|
|
|
psetsockopt = setsockopt;
|
|
|
|
pWSAStartup = WSAStartup;
|
|
|
|
pWSAIoctl = WSAIoctl;
|
|
|
|
pWSAGetLastError = WSAGetLastError;
|
|
|
|
pWSASocketW = WSASocketW;
|
|
|
|
pWSARecvFrom = WSARecvFrom;
|
|
|
|
pWSARecv = WSARecv;
|
|
|
|
pWSASendTo = WSASendTo;
|
|
|
|
pWSASend = WSASend;
|
|
|
|
pWSAStringToAddressA = WSAStringToAddressA;
|
|
|
|
|
2023-02-16 16:01:21 +00:00
|
|
|
#endif
|
2023-06-15 19:44:27 +00:00
|
|
|
|
|
|
|
gUseNativeWaitMutex = (pWaitOnAddress &&
|
|
|
|
!gRuntimeConfig.threadingConfig.bPreferNt51XpMutexesOver8 &&
|
|
|
|
(pRtlWaitOnAddress || AuBuild::kCurrentPlatform != AuBuild::EPlatform::ePlatformWin32)) ||
|
|
|
|
!pNtWaitForKeyedEvent;
|
|
|
|
|
|
|
|
gUseNativeWaitCondvar = (pWaitOnAddress &&
|
2023-07-13 18:50:18 +00:00
|
|
|
!gRuntimeConfig.threadingConfig.bPreferNt51XpCondvarsOver8 &&
|
2023-07-09 12:51:05 +00:00
|
|
|
(pRtlWaitOnAddress || AuBuild::kCurrentPlatform != AuBuild::EPlatform::ePlatformWin32)) ||
|
|
|
|
!pNtWaitForKeyedEvent;
|
2023-06-15 23:05:46 +00:00
|
|
|
|
|
|
|
gUseNativeWaitSemapahore = bool(pWaitOnAddress);
|
2023-02-16 16:01:21 +00:00
|
|
|
}
|
2023-07-09 11:34:14 +00:00
|
|
|
|
2024-03-16 18:45:03 +00:00
|
|
|
static bool IsNetbookXpOrWin7Laptop()
|
|
|
|
{
|
|
|
|
return bool(GetEnvironmentVariableW(L"AURORA_IS_NETBOOK", nullptr, 0));
|
|
|
|
}
|
|
|
|
|
2024-09-10 07:14:54 +00:00
|
|
|
void Win32DropSchedulerResolutionNow();
|
|
|
|
|
2023-07-09 12:51:05 +00:00
|
|
|
void Win32DropInit()
|
|
|
|
{
|
|
|
|
gShouldResPathDoNothing =
|
|
|
|
(AuBuild::kCurrentPlatform != AuBuild::EPlatform::ePlatformWin32) ||
|
|
|
|
(!gRuntimeConfig.threadingConfig.bEnableAggressiveScheduling &&
|
2024-03-16 18:45:03 +00:00
|
|
|
AuSwInfo::IsWindows10OrGreater()) ||
|
|
|
|
IsNetbookXpOrWin7Laptop();
|
2023-07-11 14:21:55 +00:00
|
|
|
|
|
|
|
gUseFastFail = AuSwInfo::IsWindows8Point1OrGreater()
|
|
|
|
#if defined(PF_FASTFAIL_AVAILABLE)
|
|
|
|
&& ::IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE)
|
|
|
|
#endif
|
|
|
|
;
|
2023-07-09 11:34:14 +00:00
|
|
|
|
2024-09-10 07:14:54 +00:00
|
|
|
gShouldResPathDoNothing2 = gShouldResPathDoNothing;
|
|
|
|
|
2023-07-09 12:51:05 +00:00
|
|
|
if (gShouldResPathDoNothing)
|
2023-07-09 11:34:14 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-16 18:45:03 +00:00
|
|
|
#if defined(PROCESS_POWER_THROTTLING_CURRENT_VERSION)
|
2024-03-12 22:50:22 +00:00
|
|
|
if (pSetProcessInformation &&
|
|
|
|
AuSwInfo::IsWindows10OrGreater())
|
|
|
|
{
|
|
|
|
static AuInitOnceSmall gInitOnce;
|
|
|
|
|
|
|
|
if (AuThreading::InitOnceLocker::TryLock(&gInitOnce))
|
|
|
|
{
|
|
|
|
PROCESS_POWER_THROTTLING_STATE powerThrottling {};
|
|
|
|
|
|
|
|
powerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION;
|
|
|
|
powerThrottling.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;
|
|
|
|
powerThrottling.StateMask = 0;
|
2024-04-09 21:29:11 +00:00
|
|
|
|
2024-09-10 07:14:54 +00:00
|
|
|
gShouldResPathDoNothing2 = bool(pSetProcessInformation(GetCurrentProcess(),
|
2024-04-09 21:29:11 +00:00
|
|
|
ProcessPowerThrottling,
|
|
|
|
&powerThrottling,
|
|
|
|
sizeof(powerThrottling)));
|
2024-03-12 22:50:22 +00:00
|
|
|
|
2024-09-10 07:14:54 +00:00
|
|
|
powerThrottling.ControlMask = PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION;
|
|
|
|
powerThrottling.StateMask = 0;
|
|
|
|
gShouldResPathDoNothing2 &= bool(pSetProcessInformation(GetCurrentProcess(),
|
|
|
|
ProcessPowerThrottling,
|
|
|
|
&powerThrottling,
|
|
|
|
sizeof(powerThrottling)));
|
|
|
|
|
|
|
|
if (!gShouldResPathDoNothing2 &&
|
|
|
|
(AuSWInfo::IsWindows11OrGreater() || AuSwInfo::IsWindows10Milestone20H1OrGreater()))
|
|
|
|
{
|
|
|
|
Win32DropSchedulerResolutionNow();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gShouldResPathDoNothing2 = false;
|
|
|
|
}
|
|
|
|
|
2024-03-12 22:50:22 +00:00
|
|
|
AuThreading::InitOnceLocker::Finish(&gInitOnce);
|
|
|
|
} /* else no-wait. intentionally nop*/
|
|
|
|
}
|
2024-03-16 18:45:03 +00:00
|
|
|
#endif
|
2024-04-09 21:29:11 +00:00
|
|
|
}
|
|
|
|
|
2024-09-10 07:14:54 +00:00
|
|
|
void Win32DropSchedulerResolutionForced()
|
2024-04-09 21:29:11 +00:00
|
|
|
{
|
|
|
|
ULONG ullActualResolution {};
|
|
|
|
|
2024-09-10 07:14:54 +00:00
|
|
|
if (!gShouldResPathDoNothing)
|
2024-04-09 21:29:11 +00:00
|
|
|
{
|
2024-09-10 07:14:54 +00:00
|
|
|
Win32DropSchedulerResolution();
|
2024-04-09 21:29:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-09-10 07:14:54 +00:00
|
|
|
if (pZwQueryTimerResolution)
|
2024-04-09 21:29:11 +00:00
|
|
|
{
|
2024-09-10 07:14:54 +00:00
|
|
|
static AuInitOnce gInitOnce;
|
|
|
|
gInitOnce.Call([]()
|
2024-04-09 21:29:11 +00:00
|
|
|
{
|
2024-09-10 07:14:54 +00:00
|
|
|
ULONG IDC[2];
|
|
|
|
pZwQueryTimerResolution(&IDC[0], &IDC[1], &gLastActualResolution);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Win32DropSchedulerResolutionNow()
|
|
|
|
{
|
|
|
|
ULONG ullActualResolution {};
|
|
|
|
|
|
|
|
if (!pZwSetTimerResolution)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto uRet = pZwSetTimerResolution(1, true, &ullActualResolution);
|
|
|
|
|
|
|
|
if (uRet == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (uRet == 0xC0000245)
|
|
|
|
{
|
|
|
|
if ((uRet = pZwSetTimerResolution(5'000, true, &ullActualResolution)) == 0)
|
2024-04-09 21:29:11 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2024-09-10 07:14:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Win32DropSchedulerResolutionForcedUndo()
|
|
|
|
{
|
|
|
|
ULONG ullActualResolution {};
|
2024-03-12 22:50:22 +00:00
|
|
|
|
2024-09-10 07:14:54 +00:00
|
|
|
if (!gShouldResPathDoNothing ||
|
|
|
|
!pZwSetTimerResolution ||
|
|
|
|
!gLastActualResolution)
|
2023-07-09 11:34:14 +00:00
|
|
|
{
|
2024-09-10 07:14:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)pZwSetTimerResolution(gLastActualResolution, true, &ullActualResolution);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Win32DropSchedulerResolution()
|
|
|
|
{
|
|
|
|
ULONG ullActualResolution {};
|
2023-07-09 11:34:14 +00:00
|
|
|
|
2024-09-10 07:14:54 +00:00
|
|
|
if (gShouldResPathDoNothing2)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gRuntimeConfig.threadingConfig.bEnableAgrSchedulingRatelimit)
|
|
|
|
{
|
|
|
|
static Aurora::Utility::RateLimiter limiter;
|
|
|
|
if (!limiter.nsTimeStep)
|
2023-07-09 11:34:14 +00:00
|
|
|
{
|
2024-09-10 07:14:54 +00:00
|
|
|
limiter.SetNextStep(AuMSToNS<AuUInt64>(gRuntimeConfig.threadingConfig.bWinXpThrough7BlazeOptimizerPower));
|
2023-07-09 11:34:14 +00:00
|
|
|
}
|
2024-09-10 07:14:54 +00:00
|
|
|
else if (!limiter.CheckExchangePass())
|
2023-07-09 11:34:14 +00:00
|
|
|
{
|
2024-09-10 07:14:54 +00:00
|
|
|
return;
|
2023-07-09 11:34:14 +00:00
|
|
|
}
|
|
|
|
}
|
2024-09-10 07:14:54 +00:00
|
|
|
|
|
|
|
Win32DropSchedulerResolutionNow();
|
2023-07-09 11:34:14 +00:00
|
|
|
}
|
2024-04-09 22:39:00 +00:00
|
|
|
|
|
|
|
HANDLE UWPCreateFileMappingA(HANDLE hFile,
|
|
|
|
LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
|
|
|
|
DWORD flProtect,
|
|
|
|
DWORD dwMaximumSizeHigh,
|
|
|
|
DWORD dwMaximumSizeLow,
|
|
|
|
LPCSTR lpName)
|
|
|
|
{
|
|
|
|
auto uSize = AuUInt64(AuUInt64(dwMaximumSizeHigh) << 32ull) |
|
|
|
|
AuUInt64(dwMaximumSizeLow);
|
|
|
|
if (!uSize && SysHandleIsNonZero(AuUInt(hFile)))
|
|
|
|
{
|
|
|
|
uSize = SysGetFileLength(AuUInt(hFile));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pCreateFileMappingFromApp)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pCreateFileMappingFromApp(hFile,
|
|
|
|
lpFileMappingAttributes,
|
|
|
|
flProtect,
|
|
|
|
uSize,
|
|
|
|
lpName ? AuLocale::ConvertFromUTF8(lpName).c_str() : nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE UWPOpenFileMappingA(DWORD dwDesiredAccess,
|
|
|
|
BOOL bInheritHandle,
|
|
|
|
LPCSTR lpName)
|
|
|
|
{
|
|
|
|
if (!pOpenFileMappingFromApp)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pOpenFileMappingFromApp(dwDesiredAccess,
|
|
|
|
bInheritHandle,
|
|
|
|
lpName ? AuLocale::ConvertFromUTF8(lpName).c_str() : nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
LPVOID UWPMapViewOfFile(HANDLE hFileMappingObject,
|
|
|
|
DWORD dwDesiredAccess,
|
|
|
|
DWORD dwFileOffsetHigh,
|
|
|
|
DWORD dwFileOffsetLow,
|
|
|
|
SIZE_T dwNumberOfBytesToMap)
|
|
|
|
{
|
|
|
|
if (!pMapViewOfFileFromApp)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pMapViewOfFileFromApp(hFileMappingObject,
|
|
|
|
dwDesiredAccess,
|
|
|
|
AuUInt64(AuUInt64(dwFileOffsetHigh) << 32ull) | AuUInt64(dwFileOffsetLow),
|
|
|
|
dwNumberOfBytesToMap);
|
|
|
|
}
|
2023-07-11 14:21:55 +00:00
|
|
|
|
|
|
|
void Win32Terminate()
|
|
|
|
{
|
|
|
|
if (gUseFastFail)
|
|
|
|
{
|
|
|
|
__fastfail('fokd');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-19 12:30:44 +00:00
|
|
|
if (pNtTerminateProcess)
|
|
|
|
{
|
|
|
|
pNtTerminateProcess((HANDLE)-1, 0x0);
|
|
|
|
}
|
|
|
|
|
|
|
|
::TerminateProcess(::GetCurrentProcess(), 0);
|
2023-07-11 14:21:55 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-13 01:27:18 +00:00
|
|
|
|
|
|
|
HANDLE Win32Open(LPCWSTR lpFileName,
|
|
|
|
DWORD dwDesiredAccess,
|
|
|
|
DWORD dwShareMode,
|
|
|
|
bool bInherit,
|
|
|
|
DWORD dwCreationDisposition,
|
|
|
|
DWORD dwFlags,
|
|
|
|
DWORD dwAttributes
|
|
|
|
)
|
|
|
|
{
|
|
|
|
SECURITY_ATTRIBUTES attrs {};
|
|
|
|
attrs.nLength = sizeof(attrs);
|
|
|
|
attrs.bInheritHandle = bInherit ? TRUE : FALSE;
|
2024-10-12 15:28:18 +00:00
|
|
|
return Win32Open2(lpFileName,
|
|
|
|
dwDesiredAccess,
|
|
|
|
dwShareMode,
|
|
|
|
&attrs,
|
|
|
|
dwCreationDisposition,
|
|
|
|
dwFlags,
|
|
|
|
dwAttributes);
|
2024-04-09 22:39:00 +00:00
|
|
|
}
|
|
|
|
|
2024-10-12 15:28:18 +00:00
|
|
|
HANDLE Win32Open2(LPCWSTR lpFileName,
|
|
|
|
DWORD dwDesiredAccess,
|
|
|
|
DWORD dwShareMode,
|
2024-04-09 22:39:00 +00:00
|
|
|
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
2024-10-12 15:28:18 +00:00
|
|
|
DWORD dwCreationDisposition,
|
|
|
|
DWORD dwFlags,
|
|
|
|
DWORD dwAttributes)
|
2024-04-09 22:39:00 +00:00
|
|
|
{
|
|
|
|
bool bSpecialFlags = (dwFlags & 0x4ffff7);
|
|
|
|
bool bSpecialAttrs = (dwAttributes & 0xFFB00008);
|
|
|
|
|
|
|
|
if (!pCreateFile2W)
|
|
|
|
{
|
|
|
|
if (bSpecialFlags)
|
|
|
|
{
|
|
|
|
SysPushErrorFeatureMissing("Do not use Windows8+ attributes/flags under Win32Open");
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bSpecialAttrs)
|
|
|
|
{
|
|
|
|
SysPushErrorFeatureMissing("Do not use Windows8+ attributes/flags under Win32Open");
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dwAttributes)
|
|
|
|
{
|
|
|
|
dwAttributes = FILE_ATTRIBUTE_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pCreateFileW &&
|
|
|
|
!bSpecialFlags &&
|
|
|
|
!bSpecialAttrs)
|
|
|
|
{
|
|
|
|
return pCreateFileW(lpFileName,
|
|
|
|
dwDesiredAccess,
|
|
|
|
dwShareMode,
|
|
|
|
lpSecurityAttributes,
|
|
|
|
dwCreationDisposition,
|
|
|
|
dwFlags | dwAttributes,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pCreateFile2W)
|
|
|
|
{
|
|
|
|
_CREATEFILE2_EXTENDED_PARAMETERS params {};
|
|
|
|
bool bRead {};
|
|
|
|
HANDLE hHandle {};
|
|
|
|
|
|
|
|
params.dwSize = sizeof(_CREATEFILE2_EXTENDED_PARAMETERS);
|
|
|
|
params.dwFileFlags = dwFlags;
|
|
|
|
params.dwFileAttributes = dwAttributes;
|
|
|
|
params.lpSecurityAttributes = lpSecurityAttributes;
|
|
|
|
|
|
|
|
if ((bRead = (::wcscmp(lpFileName, L"CONIN$") == 0)) ||
|
|
|
|
(::wcscmp(lpFileName, L"CONOUT$") == 0) ||
|
|
|
|
(::wcscmp(lpFileName, L"CONERR$") == 0))
|
|
|
|
{
|
2023-09-14 02:00:35 +00:00
|
|
|
if (!bRead)
|
2023-09-13 03:01:02 +00:00
|
|
|
{
|
|
|
|
dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwDesiredAccess = GENERIC_READ;
|
|
|
|
}
|
|
|
|
|
2023-09-13 13:17:45 +00:00
|
|
|
if ((hHandle = pCreateFile2W(lpFileName,
|
|
|
|
dwDesiredAccess,
|
|
|
|
dwShareMode,
|
|
|
|
dwCreationDisposition,
|
|
|
|
¶ms)) != INVALID_HANDLE_VALUE)
|
2023-09-13 03:01:02 +00:00
|
|
|
{
|
|
|
|
return hHandle;
|
|
|
|
}
|
|
|
|
|
2023-09-13 01:27:18 +00:00
|
|
|
lpFileName = L"CON";
|
|
|
|
}
|
|
|
|
|
2023-09-13 13:17:45 +00:00
|
|
|
return pCreateFile2W(lpFileName,
|
|
|
|
dwDesiredAccess,
|
|
|
|
dwShareMode,
|
|
|
|
dwCreationDisposition,
|
|
|
|
¶ms);
|
2023-09-13 01:27:18 +00:00
|
|
|
}
|
2023-09-13 03:01:02 +00:00
|
|
|
|
|
|
|
return INVALID_HANDLE_VALUE;
|
2023-09-13 01:27:18 +00:00
|
|
|
}
|
2023-09-20 17:33:27 +00:00
|
|
|
|
|
|
|
#if !defined(AURORA_PLATFORM_WIN32)
|
|
|
|
HMODULE UWPLibraryW(LPCWSTR lpLibFileName)
|
|
|
|
{
|
|
|
|
auto pos = std::basic_string_view<wchar_t>(lpLibFileName).find_last_of('/');
|
2024-04-21 10:37:00 +00:00
|
|
|
if (pos == std::basic_string_view<wchar_t>::npos)
|
|
|
|
{
|
|
|
|
pos = std::basic_string_view<wchar_t>(lpLibFileName).find_last_of('\\');
|
|
|
|
}
|
|
|
|
|
2023-09-20 17:33:27 +00:00
|
|
|
if (pos == std::basic_string_view<wchar_t>::npos)
|
|
|
|
{
|
|
|
|
#if defined(AURORA_HAS_LOAD_PGKD)
|
|
|
|
return (HMODULE)::LoadPackagedLibrary(lpLibFileName, 0);
|
|
|
|
#else
|
|
|
|
return (HMODULE)lpLibFileName;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-04-20 06:10:09 +00:00
|
|
|
auto pString = &lpLibFileName[pos + 1];
|
2023-09-20 17:33:27 +00:00
|
|
|
#if defined(AURORA_HAS_LOAD_PGKD)
|
|
|
|
return (HMODULE)::LoadPackagedLibrary(pString, 0);
|
|
|
|
#else
|
|
|
|
return (HMODULE)pString;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FARPROC UWPProcAddress(HMODULE hModule,
|
|
|
|
LPCSTR lpProcName)
|
|
|
|
{
|
|
|
|
if (!hModule)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(AURORA_HAS_GET_PROC_NONWIN32)
|
|
|
|
return GetProcAddress(hModule, lpProcName);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2024-03-03 00:25:10 +00:00
|
|
|
|
|
|
|
bool SysNativeWaitOnAddressFutexSupported()
|
|
|
|
{
|
|
|
|
return bool(pWaitOnAddress) || bool(pRtlWaitOnAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SysWaitOnAddressTimed(const void *pTargetAddress,
|
|
|
|
const void *pCompareAddress,
|
|
|
|
AuUInt8 uWordSize,
|
|
|
|
AuUInt64 uAbsTimeSteadyClock,
|
|
|
|
AuUInt64 uRelativeNanoseconds,
|
|
|
|
AuOptional<AuUInt64> uAbsTimeAltClock,
|
|
|
|
bool bSpun)
|
|
|
|
{
|
|
|
|
// Wont move out of AuWakeOnAddress.cpp because it's so long and bloated in order to force nanosecond-scale yields on UWP.
|
|
|
|
SysUnreachable();
|
|
|
|
}
|
|
|
|
|
2024-03-27 03:12:49 +00:00
|
|
|
void NTWriteEoS(HANDLE hHandle)
|
|
|
|
{
|
|
|
|
SetEndOfFile(hHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SysWriteEoS(AuUInt uOSHandle)
|
|
|
|
{
|
|
|
|
NTWriteEoS((HANDLE)uOSHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SysCloseHandle(AuUInt uOSHandle)
|
|
|
|
{
|
|
|
|
auto pHandle = (void *)uOSHandle;
|
|
|
|
AuWin32CloseHandle(pHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SysHandleIsNonZero(AuUInt uOSHandle)
|
|
|
|
{
|
|
|
|
return uOSHandle && (void *)uOSHandle != INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SysFlushHandle(AuUInt uOSHandle)
|
|
|
|
{
|
|
|
|
auto pHandle = (void *)uOSHandle;
|
|
|
|
FlushFileBuffers(pHandle);
|
|
|
|
}
|
|
|
|
|
2024-03-07 06:49:23 +00:00
|
|
|
AuUInt64 SysGetFileLength(AuUInt uOSHandle)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER length;
|
|
|
|
|
|
|
|
if (!::GetFileSizeEx((HANDLE)uOSHandle, &length))
|
|
|
|
{
|
|
|
|
SysPushErrorIO();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return length.QuadPart;
|
|
|
|
}
|
2024-03-19 15:47:42 +00:00
|
|
|
|
|
|
|
void *SysAllocateLarge(AuUInt uLength)
|
|
|
|
{
|
|
|
|
uLength = AuMemory::RoundPageUp(uLength);
|
|
|
|
return VirtualAlloc(nullptr, uLength, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SysAllocateFree(void *pBuffer, AuUInt uLength)
|
|
|
|
{
|
|
|
|
VirtualFree(pBuffer, 0, MEM_RELEASE);
|
|
|
|
}
|
2024-04-09 21:29:11 +00:00
|
|
|
|
|
|
|
bool SysMemoryLockPages(const void *pVoid, AuUInt uLength)
|
|
|
|
{
|
|
|
|
return VirtualLock((void *)pVoid, uLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SysMemoryUnlockPages(const void *pVoid, AuUInt uLength)
|
|
|
|
{
|
|
|
|
return VirtualUnlock((void *)pVoid, uLength);
|
|
|
|
}
|
2023-02-16 16:01:21 +00:00
|
|
|
}
|