[*] 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)
|
#if defined(AURORA_PLATFORM_WIN32)
|
||||||
#define ADD_LOAD_LIB(name) \
|
#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(Kernel32);
|
||||||
ADD_LOAD_LIB(Nt);
|
ADD_LOAD_LIB(Nt);
|
||||||
ADD_LOAD_LIB(KernelBase);
|
ADD_LOAD_LIB(KernelBase);
|
||||||
ADD_LOAD_LIB(Sync);
|
ADD_LOAD_LIB(Sync);
|
||||||
|
ADD_LOAD_LIB(WS2);
|
||||||
|
|
||||||
#define ADD_GET_PROC(name, proc) \
|
#define ADD_GET_PROC(name, proc) \
|
||||||
if (h ## name) \
|
if (h ## name) \
|
||||||
@ -59,11 +64,17 @@ namespace Aurora
|
|||||||
|
|
||||||
ADD_GET_PROC(Kernel32, GetSystemCpuSetInformation)
|
ADD_GET_PROC(Kernel32, GetSystemCpuSetInformation)
|
||||||
ADD_GET_PROC(Kernel32, GetLogicalProcessorInformation)
|
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, WaitOnAddress)
|
||||||
ADD_GET_PROC(Sync, WakeByAddressSingle)
|
ADD_GET_PROC(Sync, WakeByAddressSingle)
|
||||||
ADD_GET_PROC(Sync, WakeByAddressAll)
|
ADD_GET_PROC(Sync, WakeByAddressAll)
|
||||||
|
|
||||||
|
ADD_GET_PROC(WS2, GetAddrInfoExCancel)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
pWaitOnAddress = WaitOnAddress;
|
pWaitOnAddress = WaitOnAddress;
|
||||||
pWakeByAddressSingle = WakeByAddressSingle;
|
pWakeByAddressSingle = WakeByAddressSingle;
|
||||||
@ -71,6 +82,17 @@ namespace Aurora
|
|||||||
pVirtualAlloc2 = VirtualAlloc2FromApp;
|
pVirtualAlloc2 = VirtualAlloc2FromApp;
|
||||||
pMapViewOfFile3 = MapViewOfFile3FromApp;
|
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
|
// 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
|
// Xbox main SDK has a better API we should use
|
||||||
// So...
|
// So...
|
||||||
|
@ -15,6 +15,22 @@ namespace Aurora
|
|||||||
static const wchar_t *kNtDllName { L"NTDLL.dll" };
|
static const wchar_t *kNtDllName { L"NTDLL.dll" };
|
||||||
static const wchar_t *kKernel32DllName { L"Kernel32.dll" };
|
static const wchar_t *kKernel32DllName { L"Kernel32.dll" };
|
||||||
static const wchar_t *kKernelBaseDllName { L"KernelBase.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)(
|
inline BOOL(_stdcall *pWaitOnAddress)(
|
||||||
volatile VOID * Address,
|
volatile VOID * Address,
|
||||||
@ -117,6 +133,35 @@ namespace Aurora
|
|||||||
PDWORD ReturnedLength
|
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 gUseNativeWaitMutex {};
|
||||||
inline bool gUseNativeWaitCondvar {};
|
inline bool gUseNativeWaitCondvar {};
|
||||||
inline bool gUseNativeWaitSemapahore {};
|
inline bool gUseNativeWaitSemapahore {};
|
||||||
|
@ -56,7 +56,7 @@ namespace Aurora::IO::Net
|
|||||||
int iRet {};
|
int iRet {};
|
||||||
HANDLE hHandle = NULL;
|
HANDLE hHandle = NULL;
|
||||||
|
|
||||||
if (GetAddrInfoExCancel_f)
|
if (pGetAddrInfoExCancel)
|
||||||
{
|
{
|
||||||
iRet = GetAddrInfoExW(AuLocale::ConvertFromUTF8(this->hostname).data(),
|
iRet = GetAddrInfoExW(AuLocale::ConvertFromUTF8(this->hostname).data(),
|
||||||
nullptr,
|
nullptr,
|
||||||
@ -160,9 +160,9 @@ namespace Aurora::IO::Net
|
|||||||
auto hHandle = AuExchange(this->hName_, (HANDLE)NULL);
|
auto hHandle = AuExchange(this->hName_, (HANDLE)NULL);
|
||||||
if (hHandle != 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);
|
wVersionRequested = MAKEWORD(2, 2);
|
||||||
gWin32NetReady = !WSAStartup(wVersionRequested, &wsaData);
|
gWin32NetReady = !WSAStartup(wVersionRequested, &wsaData);
|
||||||
|
|
||||||
GetAddrInfoExCancel_f = AuReinterpretCast<decltype(GetAddrInfoExCancel_f)>(GetProcAddress(GetModuleHandleW(L"Ws2_32.dll"), "GetAddrInfoExCancel"));
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(AURORA_IS_LINUX_DERIVED)
|
#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.
|
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();
|
bool IsNetReady();
|
||||||
}
|
}
|
@ -25,26 +25,12 @@
|
|||||||
|
|
||||||
namespace Aurora::Memory::Cache
|
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)
|
AUKN_SYM void OptimizeAddressRangeOnCore(const AuList<AuPair<AuUInt, AuUInt>> &addressRanges)
|
||||||
{
|
{
|
||||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||||
AuList<WIN32_MEMORY_RANGE_ENTRY2> arry;
|
AuList<WIN32_MEMORY_RANGE_ENTRY2> arry;
|
||||||
|
|
||||||
if (!PrefetchVirtualMemory_f)
|
if (!pPrefetchVirtualMemory)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -82,7 +68,7 @@ namespace Aurora::Memory::Cache
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
#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)");
|
SysPushErrorHAL("Couldn't poke memory physical memory into virtual address space (array)");
|
||||||
}
|
}
|
||||||
@ -134,8 +120,6 @@ namespace Aurora::Memory::Cache
|
|||||||
|
|
||||||
void InitCache()
|
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 {};
|
RTL_OSVERSIONINFOEXW ovi {};
|
||||||
ovi.dwOSVersionInfoSize = sizeof(ovi);
|
ovi.dwOSVersionInfoSize = sizeof(ovi);
|
||||||
|
|
||||||
NTSTATUS(CALLBACK *pRtlGetVersion) (PRTL_OSVERSIONINFOW lpVersionInformation);
|
if (pRtlGetVersion(reinterpret_cast<PRTL_OSVERSIONINFOW>(&ovi)) == 0)
|
||||||
pRtlGetVersion = reinterpret_cast<decltype(pRtlGetVersion)>(GetProcAddress(LoadLibraryW(L"Ntdll.dll"), "RtlGetVersion"));
|
|
||||||
|
|
||||||
if (pRtlGetVersion && pRtlGetVersion(reinterpret_cast<PRTL_OSVERSIONINFOW>(&ovi)) == 0)
|
|
||||||
{
|
{
|
||||||
osInfo.uKernelPatch = ovi.dwBuildNumber;
|
osInfo.uKernelPatch = ovi.dwBuildNumber;
|
||||||
osInfo.uKernelMinor = ovi.dwMinorVersion;
|
osInfo.uKernelMinor = ovi.dwMinorVersion;
|
||||||
|
@ -26,14 +26,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||||
BOOL (*SetThreadInformation_f)(
|
static auto const kThreadPowerThrottling = Aurora::THREAD_INFORMATION_CLASS::ThreadPowerThrottling;
|
||||||
HANDLE hThread,
|
|
||||||
DWORD ThreadInformationClass,
|
|
||||||
LPVOID ThreadInformation,
|
|
||||||
DWORD ThreadInformationSize
|
|
||||||
);
|
|
||||||
|
|
||||||
static auto const kThreadPowerThrottling = 3;
|
|
||||||
|
|
||||||
struct THREAD_POWER_THROTTLING_STATE2
|
struct THREAD_POWER_THROTTLING_STATE2
|
||||||
{
|
{
|
||||||
@ -671,19 +664,9 @@ namespace Aurora::Threading::Threads
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
static HRESULT(WINAPI * SetThreadDescription_f)(HANDLE, PCWSTR);
|
if (pSetThreadDescription)
|
||||||
if (!SetThreadDescription_f)
|
|
||||||
{
|
{
|
||||||
#if !defined(AURORA_PLATFORM_WIN32)
|
pSetThreadDescription(this->handle_, AuLocale::ConvertFromUTF8(this->name_).c_str());
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -891,9 +874,9 @@ namespace Aurora::Threading::Threads
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SetThreadInformation_f)
|
if (pSetThreadInformation)
|
||||||
{
|
{
|
||||||
SetThreadInformation_f(this->handle_,
|
pSetThreadInformation(this->handle_,
|
||||||
kThreadPowerThrottling,
|
kThreadPowerThrottling,
|
||||||
&throttlingState,
|
&throttlingState,
|
||||||
sizeof(throttlingState));
|
sizeof(throttlingState));
|
||||||
@ -981,23 +964,13 @@ namespace Aurora::Threading::Threads
|
|||||||
if ((AuBuild::kCurrentPlatform != AuBuild::EPlatform::ePlatformWin32) ||
|
if ((AuBuild::kCurrentPlatform != AuBuild::EPlatform::ePlatformWin32) ||
|
||||||
(AuSwInfo::IsWindows10OrGreater()))
|
(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() ?
|
auto sets = mask.CpuBitCount() ?
|
||||||
mask.ToCpuSets() :
|
mask.ToCpuSets() :
|
||||||
AuHwInfo::GetCPUInfo().maskAllCores.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;
|
return;
|
||||||
}
|
}
|
||||||
@ -1244,10 +1217,6 @@ namespace Aurora::Threading::Threads
|
|||||||
AuxUlibInitialize();
|
AuxUlibInitialize();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
|
||||||
SetThreadInformation_f = AuReinterpretCast<decltype(SetThreadInformation_f)>(GetProcAddress(GetModuleHandleW(L"Kernel32.dll"), "SetThreadInformation"));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
AttachSignalKiller();
|
AttachSignalKiller();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user