[*] Ensure AuProcAddresses.NT.* is used for all dynamically linked symbols
This commit is contained in:
parent
d192e2529f
commit
627bdddfdc
@ -13,12 +13,17 @@ namespace Aurora
|
||||
{
|
||||
#if defined(AURORA_PLATFORM_WIN32)
|
||||
#define ADD_LOAD_LIB(name) \
|
||||
auto h ## name = LoadLibraryW(k## name ## DllName);
|
||||
auto h ## name = GetModuleHandleW(k## name ## DllName); \
|
||||
if (!h ## name) \
|
||||
{ \
|
||||
auto h ## name = LoadLibraryW(k## name ## DllName); \
|
||||
}
|
||||
|
||||
ADD_LOAD_LIB(Kernel32);
|
||||
ADD_LOAD_LIB(Nt);
|
||||
ADD_LOAD_LIB(KernelBase);
|
||||
ADD_LOAD_LIB(Sync);
|
||||
ADD_LOAD_LIB(WS2);
|
||||
|
||||
#define ADD_GET_PROC(name, proc) \
|
||||
if (h ## name) \
|
||||
@ -59,11 +64,17 @@ namespace Aurora
|
||||
|
||||
ADD_GET_PROC(Kernel32, GetSystemCpuSetInformation)
|
||||
ADD_GET_PROC(Kernel32, GetLogicalProcessorInformation)
|
||||
ADD_GET_PROC(Kernel32, SetThreadDescription)
|
||||
ADD_GET_PROC(Kernel32, SetThreadInformation)
|
||||
ADD_GET_PROC(Kernel32, SetThreadSelectedCpuSets)
|
||||
ADD_GET_PROC(Kernel32, PrefetchVirtualMemory)
|
||||
|
||||
ADD_GET_PROC(Sync, WaitOnAddress)
|
||||
ADD_GET_PROC(Sync, WakeByAddressSingle)
|
||||
ADD_GET_PROC(Sync, WakeByAddressAll)
|
||||
|
||||
ADD_GET_PROC(WS2, GetAddrInfoExCancel)
|
||||
|
||||
#else
|
||||
pWaitOnAddress = WaitOnAddress;
|
||||
pWakeByAddressSingle = WakeByAddressSingle;
|
||||
@ -71,6 +82,17 @@ namespace Aurora
|
||||
pVirtualAlloc2 = VirtualAlloc2FromApp;
|
||||
pMapViewOfFile3 = MapViewOfFile3FromApp;
|
||||
|
||||
pGetSystemCpuSetInformation = GetSystemCpuSetInformation;
|
||||
pGetLogicalProcessorInformation = GetLogicalProcessorInformation;
|
||||
|
||||
pSetThreadInformation = SetThreadInformation;
|
||||
pSetThreadDescription = SetThreadDescription;
|
||||
pSetThreadSelectedCpuSets = SetThreadSelectedCpuSets;
|
||||
|
||||
pGetAddrInfoExCancel = GetAddrInfoExCancel;
|
||||
|
||||
pPrefetchVirtualMemory = PrefetchVirtualMemory;
|
||||
|
||||
// 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...
|
||||
|
@ -15,6 +15,22 @@ namespace Aurora
|
||||
static const wchar_t *kNtDllName { L"NTDLL.dll" };
|
||||
static const wchar_t *kKernel32DllName { L"Kernel32.dll" };
|
||||
static const wchar_t *kKernelBaseDllName { L"KernelBase.dll" };
|
||||
static const wchar_t *kWS2DllName { L"Ws2_32.dll" };
|
||||
|
||||
struct WIN32_MEMORY_RANGE_ENTRY2
|
||||
{
|
||||
PVOID VirtualAddress;
|
||||
SIZE_T NumberOfBytes;
|
||||
};
|
||||
|
||||
enum class THREAD_INFORMATION_CLASS
|
||||
{
|
||||
ThreadMemoryPriority,
|
||||
ThreadAbsoluteCpuPriority,
|
||||
ThreadDynamicCodePolicy,
|
||||
ThreadPowerThrottling,
|
||||
ThreadInformationClassMax
|
||||
};
|
||||
|
||||
inline BOOL(_stdcall *pWaitOnAddress)(
|
||||
volatile VOID * Address,
|
||||
@ -42,7 +58,7 @@ namespace Aurora
|
||||
SIZE_T Size,
|
||||
ULONG AllocationType,
|
||||
ULONG PageProtection,
|
||||
MEM_EXTENDED_PARAMETER *ExtendedParameters,
|
||||
MEM_EXTENDED_PARAMETER * ExtendedParameters,
|
||||
ULONG ParameterCount
|
||||
);
|
||||
|
||||
@ -54,7 +70,7 @@ namespace Aurora
|
||||
SIZE_T ViewSize,
|
||||
ULONG AllocationType,
|
||||
ULONG PageProtection,
|
||||
MEM_EXTENDED_PARAMETER *ExtendedParameters,
|
||||
MEM_EXTENDED_PARAMETER * ExtendedParameters,
|
||||
ULONG ParameterCount
|
||||
);
|
||||
|
||||
@ -112,11 +128,40 @@ namespace Aurora
|
||||
ULONG Flags
|
||||
);
|
||||
|
||||
inline BOOL(__stdcall * pGetLogicalProcessorInformation)(
|
||||
inline BOOL(__stdcall *pGetLogicalProcessorInformation)(
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer,
|
||||
PDWORD ReturnedLength
|
||||
);
|
||||
|
||||
inline HRESULT(__stdcall *pSetThreadDescription)(
|
||||
HANDLE hThread,
|
||||
PCWSTR lpThreadDescription
|
||||
);
|
||||
|
||||
inline BOOL(__stdcall *pSetThreadInformation)(
|
||||
HANDLE hThread,
|
||||
THREAD_INFORMATION_CLASS ThreadInformationClass,
|
||||
LPVOID ThreadInformation,
|
||||
DWORD ThreadInformationSize
|
||||
);
|
||||
|
||||
inline BOOL(__stdcall *pSetThreadSelectedCpuSets)(
|
||||
HANDLE Thread,
|
||||
const ULONG * CpuSetIds,
|
||||
ULONG CpuSetIdCount
|
||||
);
|
||||
|
||||
inline INT(__stdcall *pGetAddrInfoExCancel)(
|
||||
LPHANDLE lpHandle
|
||||
);
|
||||
|
||||
inline BOOL(__stdcall *pPrefetchVirtualMemory)(
|
||||
HANDLE hProcess,
|
||||
ULONG_PTR NumberOfEntries,
|
||||
WIN32_MEMORY_RANGE_ENTRY2 * VirtualAddresses,
|
||||
ULONG Flags
|
||||
);
|
||||
|
||||
inline bool gUseNativeWaitMutex {};
|
||||
inline bool gUseNativeWaitCondvar {};
|
||||
inline bool gUseNativeWaitSemapahore {};
|
||||
|
@ -56,7 +56,7 @@ namespace Aurora::IO::Net
|
||||
int iRet {};
|
||||
HANDLE hHandle = NULL;
|
||||
|
||||
if (GetAddrInfoExCancel_f)
|
||||
if (pGetAddrInfoExCancel)
|
||||
{
|
||||
iRet = GetAddrInfoExW(AuLocale::ConvertFromUTF8(this->hostname).data(),
|
||||
nullptr,
|
||||
@ -160,9 +160,9 @@ namespace Aurora::IO::Net
|
||||
auto hHandle = AuExchange(this->hName_, (HANDLE)NULL);
|
||||
if (hHandle != NULL)
|
||||
{
|
||||
if (GetAddrInfoExCancel_f)
|
||||
if (pGetAddrInfoExCancel)
|
||||
{
|
||||
GetAddrInfoExCancel_f(&hHandle);
|
||||
pGetAddrInfoExCancel(&hHandle);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,6 @@ namespace Aurora::IO::Net
|
||||
wVersionRequested = MAKEWORD(2, 2);
|
||||
gWin32NetReady = !WSAStartup(wVersionRequested, &wsaData);
|
||||
|
||||
GetAddrInfoExCancel_f = AuReinterpretCast<decltype(GetAddrInfoExCancel_f)>(GetProcAddress(GetModuleHandleW(L"Ws2_32.dll"), "GetAddrInfoExCancel"));
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(AURORA_IS_LINUX_DERIVED)
|
||||
|
@ -43,11 +43,5 @@ namespace Aurora::IO::Net
|
||||
{
|
||||
static const auto kDefaultStreamSize = 32 * 1024; // ~960 clients for 30MB of 2x 32KiB streams. Seems... reasonable.
|
||||
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
inline INT(__stdcall *GetAddrInfoExCancel_f)(
|
||||
LPHANDLE lpHandle
|
||||
);
|
||||
#endif
|
||||
|
||||
bool IsNetReady();
|
||||
}
|
@ -25,26 +25,12 @@
|
||||
|
||||
namespace Aurora::Memory::Cache
|
||||
{
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
struct WIN32_MEMORY_RANGE_ENTRY2 {
|
||||
PVOID VirtualAddress;
|
||||
SIZE_T NumberOfBytes;
|
||||
};
|
||||
|
||||
BOOL (__stdcall *PrefetchVirtualMemory_f)(
|
||||
HANDLE hProcess,
|
||||
ULONG_PTR NumberOfEntries,
|
||||
WIN32_MEMORY_RANGE_ENTRY2* VirtualAddresses,
|
||||
ULONG Flags
|
||||
);
|
||||
#endif
|
||||
|
||||
AUKN_SYM void OptimizeAddressRangeOnCore(const AuList<AuPair<AuUInt, AuUInt>> &addressRanges)
|
||||
{
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
AuList<WIN32_MEMORY_RANGE_ENTRY2> arry;
|
||||
|
||||
if (!PrefetchVirtualMemory_f)
|
||||
if (!pPrefetchVirtualMemory)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -82,7 +68,7 @@ namespace Aurora::Memory::Cache
|
||||
}
|
||||
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
if (!PrefetchVirtualMemory_f(GetCurrentProcess(), arry.size(), arry.data(), 0))
|
||||
if (!pPrefetchVirtualMemory(GetCurrentProcess(), arry.size(), arry.data(), 0))
|
||||
{
|
||||
SysPushErrorHAL("Couldn't poke memory physical memory into virtual address space (array)");
|
||||
}
|
||||
@ -134,8 +120,6 @@ namespace Aurora::Memory::Cache
|
||||
|
||||
void InitCache()
|
||||
{
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
PrefetchVirtualMemory_f = AuReinterpretCast<decltype(PrefetchVirtualMemory_f)>(GetProcAddress(GetModuleHandleW(L"Kernel32.dll"), "PrefetchVirtualMemory"));
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
@ -96,10 +96,7 @@ namespace Aurora::SWInfo
|
||||
RTL_OSVERSIONINFOEXW ovi {};
|
||||
ovi.dwOSVersionInfoSize = sizeof(ovi);
|
||||
|
||||
NTSTATUS(CALLBACK *pRtlGetVersion) (PRTL_OSVERSIONINFOW lpVersionInformation);
|
||||
pRtlGetVersion = reinterpret_cast<decltype(pRtlGetVersion)>(GetProcAddress(LoadLibraryW(L"Ntdll.dll"), "RtlGetVersion"));
|
||||
|
||||
if (pRtlGetVersion && pRtlGetVersion(reinterpret_cast<PRTL_OSVERSIONINFOW>(&ovi)) == 0)
|
||||
if (pRtlGetVersion(reinterpret_cast<PRTL_OSVERSIONINFOW>(&ovi)) == 0)
|
||||
{
|
||||
osInfo.uKernelPatch = ovi.dwBuildNumber;
|
||||
osInfo.uKernelMinor = ovi.dwMinorVersion;
|
||||
|
@ -26,14 +26,7 @@
|
||||
#endif
|
||||
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
BOOL (*SetThreadInformation_f)(
|
||||
HANDLE hThread,
|
||||
DWORD ThreadInformationClass,
|
||||
LPVOID ThreadInformation,
|
||||
DWORD ThreadInformationSize
|
||||
);
|
||||
|
||||
static auto const kThreadPowerThrottling = 3;
|
||||
static auto const kThreadPowerThrottling = Aurora::THREAD_INFORMATION_CLASS::ThreadPowerThrottling;
|
||||
|
||||
struct THREAD_POWER_THROTTLING_STATE2
|
||||
{
|
||||
@ -671,19 +664,9 @@ namespace Aurora::Threading::Threads
|
||||
}
|
||||
else
|
||||
{
|
||||
static HRESULT(WINAPI * SetThreadDescription_f)(HANDLE, PCWSTR);
|
||||
if (!SetThreadDescription_f)
|
||||
if (pSetThreadDescription)
|
||||
{
|
||||
#if !defined(AURORA_PLATFORM_WIN32)
|
||||
SetThreadDescription_f = SetThreadDescription;
|
||||
#else
|
||||
SetThreadDescription_f = AuReinterpretCast<decltype(SetThreadDescription_f)>(GetProcAddress(GetModuleHandleW(L"Kernel32.dll"), "SetThreadDescription"));
|
||||
#endif
|
||||
}
|
||||
|
||||
if (SetThreadDescription_f)
|
||||
{
|
||||
SetThreadDescription_f(this->handle_, AuLocale::ConvertFromUTF8(this->name_).c_str());
|
||||
pSetThreadDescription(this->handle_, AuLocale::ConvertFromUTF8(this->name_).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@ -891,9 +874,9 @@ namespace Aurora::Threading::Threads
|
||||
break;
|
||||
}
|
||||
|
||||
if (SetThreadInformation_f)
|
||||
if (pSetThreadInformation)
|
||||
{
|
||||
SetThreadInformation_f(this->handle_,
|
||||
pSetThreadInformation(this->handle_,
|
||||
kThreadPowerThrottling,
|
||||
&throttlingState,
|
||||
sizeof(throttlingState));
|
||||
@ -981,23 +964,13 @@ namespace Aurora::Threading::Threads
|
||||
if ((AuBuild::kCurrentPlatform != AuBuild::EPlatform::ePlatformWin32) ||
|
||||
(AuSwInfo::IsWindows10OrGreater()))
|
||||
{
|
||||
static BOOL(WINAPI * SetThreadSelectedCpuSets_f)(HANDLE, const ULONG *, ULONG);
|
||||
if (!SetThreadSelectedCpuSets_f)
|
||||
{
|
||||
#if !defined(AURORA_PLATFORM_WIN32)
|
||||
SetThreadSelectedCpuSets_f = SetThreadSelectedCpuSets;
|
||||
#else
|
||||
SetThreadSelectedCpuSets_f = AuReinterpretCast<decltype(SetThreadSelectedCpuSets_f)>(GetProcAddress(GetModuleHandleW(L"Kernel32.dll"), "SetThreadSelectedCpuSets"));
|
||||
#endif
|
||||
}
|
||||
|
||||
auto sets = mask.CpuBitCount() ?
|
||||
mask.ToCpuSets() :
|
||||
AuHwInfo::GetCPUInfo().maskAllCores.ToCpuSets();
|
||||
|
||||
if (SetThreadSelectedCpuSets_f)
|
||||
if (pSetThreadSelectedCpuSets)
|
||||
{
|
||||
if (SetThreadSelectedCpuSets_f(this->handle_, sets.data(), sets.size()))
|
||||
if (pSetThreadSelectedCpuSets(this->handle_, sets.data(), sets.size()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -1244,10 +1217,6 @@ namespace Aurora::Threading::Threads
|
||||
AuxUlibInitialize();
|
||||
#endif
|
||||
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
SetThreadInformation_f = AuReinterpretCast<decltype(SetThreadInformation_f)>(GetProcAddress(GetModuleHandleW(L"Kernel32.dll"), "SetThreadInformation"));
|
||||
#endif
|
||||
|
||||
AttachSignalKiller();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user