From e28a3923884274e2c541f1ac8ee8d70ac58bfbaa Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 28 Jan 2021 00:24:46 -0800 Subject: [PATCH] Update Environment.ProcessorCount - port dotnet/runtime#45943 (#598) Port of https://github.com/dotnet/runtime/pull/45943 Delete some dead code --- src/coreclr/gc/gcload.cpp | 2 + src/coreclr/nativeaot/Runtime/PalRedhawk.h | 26 +--- .../nativeaot/Runtime/PalRedhawkFunctions.h | 12 -- src/coreclr/nativeaot/Runtime/RWLock.cpp | 4 +- .../nativeaot/Runtime/arm/StubDispatch.S | 13 -- src/coreclr/nativeaot/Runtime/gcrhenv.cpp | 6 - src/coreclr/nativeaot/Runtime/rhassert.cpp | 15 +-- src/coreclr/nativeaot/Runtime/rhassert.h | 6 - src/coreclr/nativeaot/Runtime/threadstore.cpp | 2 +- .../nativeaot/Runtime/unix/PalRedhawkUnix.cpp | 115 ++---------------- .../nativeaot/Runtime/unix/config.h.in | 5 - .../nativeaot/Runtime/unix/configure.cmake | 5 - .../Runtime/unix/unixasmmacrosarm.inc | 9 -- .../Runtime/windows/PalRedhawkCommon.cpp | 17 +-- .../Runtime/windows/PalRedhawkMinWin.cpp | 26 ++-- 15 files changed, 33 insertions(+), 230 deletions(-) diff --git a/src/coreclr/gc/gcload.cpp b/src/coreclr/gc/gcload.cpp index 0549ca856a9b60..12cc857a049c93 100644 --- a/src/coreclr/gc/gcload.cpp +++ b/src/coreclr/gc/gcload.cpp @@ -78,10 +78,12 @@ GC_Initialize( // various components may want to query the current configuration. GCConfig::Initialize(); +#ifndef FEATURE_REDHAWK // GCToOSInterface is initialized directly if (!GCToOSInterface::Initialize()) { return E_FAIL; } +#endif IGCHandleManager* handleManager = CreateGCHandleManager(); if (handleManager == nullptr) diff --git a/src/coreclr/nativeaot/Runtime/PalRedhawk.h b/src/coreclr/nativeaot/Runtime/PalRedhawk.h index 1d9cc27633ace6..74937f9da8f76c 100644 --- a/src/coreclr/nativeaot/Runtime/PalRedhawk.h +++ b/src/coreclr/nativeaot/Runtime/PalRedhawk.h @@ -82,27 +82,6 @@ typedef struct _GUID { #define DECLARE_HANDLE(_name) typedef HANDLE _name -struct SYSTEM_INFO -{ - union - { - uint32_t dwOemId; - struct { - uint16_t wProcessorArchitecture; - uint16_t wReserved; - } DUMMYSTRUCTNAME; - } DUMMYUNIONNAME; - uint32_t dwPageSize; - void * lpMinimumApplicationAddress; - void * lpMaximumApplicationAddress; - uintptr_t dwActiveProcessorMask; - uint32_t dwNumberOfProcessors; - uint32_t dwProcessorType; - uint32_t dwAllocationGranularity; - uint16_t wProcessorLevel; - uint16_t wProcessorRevision; -}; - // defined in gcrhenv.cpp bool __SwitchToThread(uint32_t dwSleepMSec, uint32_t dwSwitchCount); @@ -559,7 +538,7 @@ EventDataDescCreate(_Out_ EVENT_DATA_DESCRIPTOR * EventDataDescriptor, _In_opt_ } #endif // _EVNTPROV_H_ -extern GCSystemInfo g_RhSystemInfo; +extern uint32_t g_RhNumberOfProcessors; #ifdef TARGET_UNIX #define REDHAWK_PALIMPORT extern "C" @@ -570,8 +549,6 @@ extern GCSystemInfo g_RhSystemInfo; #define REDHAWK_PALAPI __stdcall #endif // TARGET_UNIX -bool InitializeSystemInfo(); - #ifndef DACCESS_COMPILE #ifdef _DEBUG @@ -679,7 +656,6 @@ REDHAWK_PALIMPORT void REDHAWK_PALAPI PalSleep(uint32_t milliseconds); REDHAWK_PALIMPORT UInt32_BOOL REDHAWK_PALAPI PalSwitchToThread(); REDHAWK_PALIMPORT HANDLE REDHAWK_PALAPI PalCreateEventW(_In_opt_ LPSECURITY_ATTRIBUTES pEventAttributes, UInt32_BOOL manualReset, UInt32_BOOL initialState, _In_opt_z_ LPCWSTR pName); REDHAWK_PALIMPORT uint64_t REDHAWK_PALAPI PalGetTickCount64(); -REDHAWK_PALIMPORT HANDLE REDHAWK_PALAPI PalCreateLowMemoryNotification(); REDHAWK_PALIMPORT void REDHAWK_PALAPI PalTerminateCurrentProcess(uint32_t exitCode); REDHAWK_PALIMPORT HANDLE REDHAWK_PALAPI PalGetModuleHandleFromPointer(_In_ void* pointer); diff --git a/src/coreclr/nativeaot/Runtime/PalRedhawkFunctions.h b/src/coreclr/nativeaot/Runtime/PalRedhawkFunctions.h index 0de11d986c306e..ff58a8ea0dc08d 100644 --- a/src/coreclr/nativeaot/Runtime/PalRedhawkFunctions.h +++ b/src/coreclr/nativeaot/Runtime/PalRedhawkFunctions.h @@ -141,12 +141,6 @@ inline void PalRaiseException(uint32_t arg1, uint32_t arg2, uint32_t arg3, const RaiseException(arg1, arg2, arg3, arg4); } -extern "C" UInt32_BOOL __stdcall ReleaseMutex(HANDLE); -inline UInt32_BOOL PalReleaseMutex(HANDLE arg1) -{ - return ReleaseMutex(arg1); -} - extern "C" UInt32_BOOL __stdcall ResetEvent(HANDLE); inline UInt32_BOOL PalResetEvent(HANDLE arg1) { @@ -159,12 +153,6 @@ inline UInt32_BOOL PalSetEvent(HANDLE arg1) return SetEvent(arg1); } -extern "C" void __stdcall TerminateProcess(HANDLE, uint32_t); -inline void PalTerminateProcess(HANDLE arg1, uint32_t arg2) -{ - TerminateProcess(arg1, arg2); -} - extern "C" uint32_t __stdcall WaitForSingleObjectEx(HANDLE, uint32_t, UInt32_BOOL); inline uint32_t PalWaitForSingleObjectEx(HANDLE arg1, uint32_t arg2, UInt32_BOOL arg3) { diff --git a/src/coreclr/nativeaot/Runtime/RWLock.cpp b/src/coreclr/nativeaot/Runtime/RWLock.cpp index 9a8c45edfdb938..0ae19e96ebd276 100644 --- a/src/coreclr/nativeaot/Runtime/RWLock.cpp +++ b/src/coreclr/nativeaot/Runtime/RWLock.cpp @@ -175,7 +175,7 @@ void ReaderWriterLock::AcquireReadLockWorker() if (TryAcquireReadLock()) return; - if (g_RhSystemInfo.dwNumberOfProcessors <= 1) + if (g_RhNumberOfProcessors <= 1) break; // Delay by approximately 2*i clock cycles (Pentium III). @@ -241,7 +241,7 @@ void ReaderWriterLock::AcquireWriteLock() RedhawkGCInterface::WaitForGCCompletion(); } - if (g_RhSystemInfo.dwNumberOfProcessors <= 1) + if (g_RhNumberOfProcessors <= 1) { break; } diff --git a/src/coreclr/nativeaot/Runtime/arm/StubDispatch.S b/src/coreclr/nativeaot/Runtime/arm/StubDispatch.S index 6b7cf11a4a58aa..6c030e7de854e6 100644 --- a/src/coreclr/nativeaot/Runtime/arm/StubDispatch.S +++ b/src/coreclr/nativeaot/Runtime/arm/StubDispatch.S @@ -9,19 +9,6 @@ #ifdef FEATURE_CACHED_INTERFACE_DISPATCH -// TODO: Implement Arm support -#ifdef _DEBUG -.rodata -AssertMsg: .asciz "__FILE__:%s: %s is not implemented\n" -FileName: .asciz "StubDispatch.S" -RhpVTableOffsetDispatchName: .asciz "RhpVTableOffsetDispatch" -.text -.macro GEN_ASSERT_FUNC func - GEN_ASSERT AssertMsg, FileName, \func -.endm -#endif - - // Macro that generates a stub consuming a cache with the given number of entries. .macro DEFINE_INTERFACE_DISPATCH_STUB entries diff --git a/src/coreclr/nativeaot/Runtime/gcrhenv.cpp b/src/coreclr/nativeaot/Runtime/gcrhenv.cpp index 6441cdbf5d33a5..133c4297bf9da6 100644 --- a/src/coreclr/nativeaot/Runtime/gcrhenv.cpp +++ b/src/coreclr/nativeaot/Runtime/gcrhenv.cpp @@ -175,11 +175,6 @@ bool RedhawkGCInterface::InitializeSubsystems() MICROSOFT_WINDOWS_REDHAWK_GC_PUBLIC_PROVIDER_Context.RegistrationHandle = Microsoft_Windows_Redhawk_GC_PublicHandle; #endif // FEATURE_ETW - if (!InitializeSystemInfo()) - { - return false; - } - // Initialize the special EEType used to mark free list entries in the GC heap. g_FreeObjectEEType.InitializeAsGcFreeType(); g_pFreeObjectEEType = &g_FreeObjectEEType; @@ -188,7 +183,6 @@ bool RedhawkGCInterface::InitializeSubsystems() return false; #ifdef FEATURE_SVR_GC - // TODO: This should use the logical CPU count adjusted for process affinity and cgroup limits g_heap_type = (g_pRhConfig->GetUseServerGC() && PalGetProcessCpuCount() > 1) ? GC_HEAP_SVR : GC_HEAP_WKS; #else g_heap_type = GC_HEAP_WKS; diff --git a/src/coreclr/nativeaot/Runtime/rhassert.cpp b/src/coreclr/nativeaot/Runtime/rhassert.cpp index 07c8115d2916ab..f69a919450b390 100644 --- a/src/coreclr/nativeaot/Runtime/rhassert.cpp +++ b/src/coreclr/nativeaot/Runtime/rhassert.cpp @@ -77,7 +77,7 @@ void Assert(const char * expr, const char * file, uint32_t line_num, const char switch (result) { case IDABORT: - PalTerminateProcess(PalGetCurrentProcess(), 666); + PalTerminateCurrentProcess(42); break; case IDRETRY: PalDebugBreak(); @@ -94,17 +94,4 @@ void Assert(const char * expr, const char * file, uint32_t line_num, const char #endif //!DACCESS_COMPILE } -extern "C" void NYI_Assert(const char *message, ...) -{ -#if !defined(DACCESS_COMPILE) - va_list args; - va_start(args, message); - vprintf(message, args); - va_end(args); - ASSERT_UNCONDITIONALLY("NYI"); -#else - UNREFERENCED_PARAMETER(message); -#endif -} - #endif // _DEBUG diff --git a/src/coreclr/nativeaot/Runtime/rhassert.h b/src/coreclr/nativeaot/Runtime/rhassert.h index d931649c31022a..ef9ce47b841c93 100644 --- a/src/coreclr/nativeaot/Runtime/rhassert.h +++ b/src/coreclr/nativeaot/Runtime/rhassert.h @@ -44,12 +44,6 @@ void Assert(const char * expr, const char * file, unsigned int line_num, const c #define _ASSERTE(_expr) ASSERT(_expr) #endif -#if defined(_DEBUG) - -void NYI_ASSERT(); - -#endif - #define PORTABILITY_ASSERT(message) \ ASSERT_UNCONDITIONALLY(message); \ ASSUME(0); \ diff --git a/src/coreclr/nativeaot/Runtime/threadstore.cpp b/src/coreclr/nativeaot/Runtime/threadstore.cpp index 49acb7d97765f6..4d31c955a1cdf7 100644 --- a/src/coreclr/nativeaot/Runtime/threadstore.cpp +++ b/src/coreclr/nativeaot/Runtime/threadstore.cpp @@ -275,7 +275,7 @@ void ThreadStore::SuspendAllThreads(bool waitForGCEvent, bool fireDebugEvent) if (keepWaiting) { - if (PalSwitchToThread() == 0 && g_RhSystemInfo.dwNumberOfProcessors > 1) + if (PalSwitchToThread() == 0 && g_RhNumberOfProcessors > 1) { // No threads are scheduled on this processor. Perhaps we're waiting for a thread // that's scheduled on another processor. If so, let's give it a little time diff --git a/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp b/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp index bf1bfa05cf08e4..385e5b23615427 100644 --- a/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp +++ b/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp @@ -39,14 +39,6 @@ #include #endif -#if HAVE_SYSCONF -// already included above -#elif HAVE_SYSCTL -#include -#else -#error Either sysctl or sysconf is required for GetSystemInfo. -#endif - #if HAVE_SYS_VMPARAM_H #include #endif // HAVE_SYS_VMPARAM_H @@ -73,24 +65,6 @@ using std::nullptr_t; -#ifndef __APPLE__ -#if HAVE_SYSCONF && HAVE__SC_AVPHYS_PAGES -#define SYSCONF_PAGES _SC_AVPHYS_PAGES -#elif HAVE_SYSCONF && HAVE__SC_PHYS_PAGES -#define SYSCONF_PAGES _SC_PHYS_PAGES -#else -#error Dont know how to get page-size on this architecture! -#endif -#endif // __APPLE__ - -#if defined(HOST_ARM) || defined(HOST_ARM64) -#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_CONF -#define SYSCONF_GET_NUMPROCS_NAME "_SC_NPROCESSORS_CONF" -#else -#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_ONLN -#define SYSCONF_GET_NUMPROCS_NAME "_SC_NPROCESSORS_ONLN" -#endif - #define PalRaiseFailFastException RaiseFailFastException #define FATAL_ASSERT(e, msg) \ @@ -126,10 +100,6 @@ static const int tccMilliSecondsToMicroSeconds = 1000; static const int tccMilliSecondsToNanoSeconds = 1000000; static const int tccMicroSecondsToNanoSeconds = 1000; -static uint32_t g_cNumProcs = 0; - -bool QueryLogicalProcessorCount(); - extern "C" void RaiseFailFastException(PEXCEPTION_RECORD arg1, PCONTEXT arg2, uint32_t arg3) { // Abort aborts the process and causes creation of a crash dump @@ -401,9 +371,6 @@ void ConfigureSignals() // initialization and false on failure. REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalInit() { - if (!QueryLogicalProcessorCount()) - return false; - #ifndef USE_PORTABLE_HELPERS if (!InitializeHardwareExceptionHandling()) { @@ -413,6 +380,14 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalInit() ConfigureSignals(); + if (!GCToOSInterface::Initialize()) + { + return false; + } + + // Use the same adjustment for current processor count as GC + g_RhNumberOfProcessors = GCToOSInterface::GetCurrentProcessCpuCount(); + return true; } @@ -705,30 +680,6 @@ REDHAWK_PALEXPORT void PalPrintFatalError(const char* message) write(STDERR_FILENO, message, sizeof(message)); } -bool QueryLogicalProcessorCount() -{ -#if HAVE_SYSCONF - g_cNumProcs = sysconf(SYSCONF_GET_NUMPROCS); - if (g_cNumProcs < 1) - { - ASSERT_UNCONDITIONALLY("sysconf failed for " SYSCONF_GET_NUMPROCS_NAME "\n"); - return false; - } -#elif HAVE_SYSCTL - size_t sz = sizeof(g_cNumProcs); - - int st = 0; - if (sysctlbyname("hw.logicalcpu_max", &g_cNumProcs, &sz, NULL, 0) != 0) - { - ASSERT_UNCONDITIONALLY("sysctl failed for hw.logicalcpu_max\n"); - return false; - } - -#endif // HAVE_SYSCONF - - return true; -} - static int W32toUnixAccessControl(uint32_t flProtect) { int prot = 0; @@ -904,14 +855,6 @@ extern "C" UInt32_BOOL IsDebuggerPresent() #endif } -extern "C" void TerminateProcess(HANDLE arg1, uint32_t arg2) -{ - // TODO: change it to TerminateCurrentProcess - // Then if we modified the signature of the DuplicateHandle too, we can - // get rid of the PalGetCurrentProcess. - PORTABILITY_ASSERT("UNIXTODO: Implement this function"); -} - extern "C" UInt32_BOOL SetEvent(HANDLE event) { EventUnixHandle* unixHandle = (EventUnixHandle*)event; @@ -1002,9 +945,12 @@ extern "C" int32_t _stricmp(const char *string1, const char *string2) return strcasecmp(string1, string2); } +uint32_t g_RhNumberOfProcessors; + REDHAWK_PALEXPORT int32_t PalGetProcessCpuCount() { - return g_cNumProcs; + ASSERT(g_RhNumberOfProcessors > 0); + return g_RhNumberOfProcessors; } __thread void* pStackHighOut = NULL; @@ -1081,43 +1027,6 @@ REDHAWK_PALEXPORT int32_t PalGetModuleFileName(_Out_ const TCHAR** pModuleNameOu #endif // defined(HOST_WASM) } -GCSystemInfo g_RhSystemInfo; - -// Initialize the g_SystemInfo -bool InitializeSystemInfo() -{ - long pagesize = getpagesize(); - g_RhSystemInfo.dwPageSize = pagesize; - g_RhSystemInfo.dwAllocationGranularity = pagesize; - - int nrcpus = 0; - -#if HAVE_SYSCONF - nrcpus = sysconf(SYSCONF_GET_NUMPROCS); - if (nrcpus < 1) - { - ASSERT_UNCONDITIONALLY("sysconf failed for " SYSCONF_GET_NUMPROCS_NAME "\n"); - return false; - } -#elif HAVE_SYSCTL - int mib[2]; - - size_t sz = sizeof(nrcpus); - mib[0] = CTL_HW; - mib[1] = HW_NCPU; - int rc = sysctl(mib, 2, &nrcpus, &sz, NULL, 0); - if (rc != 0) - { - ASSERT_UNCONDITIONALLY("sysctl failed for HW_NCPU\n"); - return false; - } -#endif // HAVE_SYSCONF - - g_RhSystemInfo.dwNumberOfProcessors = nrcpus; - - return true; -} - extern "C" void FlushProcessWriteBuffers() { GCToOSInterface::FlushProcessWriteBuffers(); diff --git a/src/coreclr/nativeaot/Runtime/unix/config.h.in b/src/coreclr/nativeaot/Runtime/unix/config.h.in index aa63aed6c04ee5..3182e1709d70dd 100644 --- a/src/coreclr/nativeaot/Runtime/unix/config.h.in +++ b/src/coreclr/nativeaot/Runtime/unix/config.h.in @@ -11,8 +11,6 @@ #cmakedefine01 HAVE_PTHREAD_GETTHREADID_NP #cmakedefine01 HAVE_CLOCK_NANOSLEEP -#cmakedefine01 HAVE_SYSCTL -#cmakedefine01 HAVE_SYSCONF #cmakedefine01 HAVE_GREGSET_T #cmakedefine01 HAVE___GREGSET_T @@ -20,9 +18,6 @@ #cmakedefine01 HAVE_SIGINFO_T #cmakedefine01 HAVE_UCONTEXT_T -#cmakedefine01 HAVE__SC_PHYS_PAGES -#cmakedefine01 HAVE__SC_AVPHYS_PAGES - #cmakedefine01 HAVE_LWP_SELF #cmakedefine01 HAVE_SCHED_GETCPU #cmakedefine01 HAVE_CLOCK_MONOTONIC diff --git a/src/coreclr/nativeaot/Runtime/unix/configure.cmake b/src/coreclr/nativeaot/Runtime/unix/configure.cmake index e8a1e159c3e681..f10b73cdcc44f8 100644 --- a/src/coreclr/nativeaot/Runtime/unix/configure.cmake +++ b/src/coreclr/nativeaot/Runtime/unix/configure.cmake @@ -25,8 +25,6 @@ check_library_exists(pthread pthread_condattr_setclock "" HAVE_PTHREAD_CONDATTR_ check_library_exists(pthread pthread_getthreadid_np "" HAVE_PTHREAD_GETTHREADID_NP) check_function_exists(clock_nanosleep HAVE_CLOCK_NANOSLEEP) -check_function_exists(sysctl HAVE_SYSCTL) -check_function_exists(sysconf HAVE_SYSCONF) check_struct_has_member ("ucontext_t" uc_mcontext.gregs[0] ucontext.h HAVE_GREGSET_T) check_struct_has_member ("ucontext_t" uc_mcontext.__gregs[0] ucontext.h HAVE___GREGSET_T) @@ -38,9 +36,6 @@ set(CMAKE_EXTRA_INCLUDE_FILES) set(CMAKE_EXTRA_INCLUDE_FILES ucontext.h) check_type_size(ucontext_t UCONTEXT_T) -check_cxx_symbol_exists(_SC_PHYS_PAGES unistd.h HAVE__SC_PHYS_PAGES) -check_cxx_symbol_exists(_SC_AVPHYS_PAGES unistd.h HAVE__SC_AVPHYS_PAGES) - check_cxx_source_compiles(" #include diff --git a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm.inc b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm.inc index 73a9968f3b8d6b..95b0cad1681b5b 100644 --- a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm.inc +++ b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm.inc @@ -255,15 +255,6 @@ C_FUNC(\Name): EPILOG_STACK_FREE 4 // Discard caller's SP .endm -#ifdef _DEBUG -.macro GEN_ASSERT message, fileName, funcName - ldr r0, =\message - ldr r1, =\fileName - ldr r2, =\funcName - bl C_FUNC(NYI_Assert) -.endm -#endif - // thumb with PIC version .macro INLINE_GET_TLS_VAR Var ldr r0, 2f diff --git a/src/coreclr/nativeaot/Runtime/windows/PalRedhawkCommon.cpp b/src/coreclr/nativeaot/Runtime/windows/PalRedhawkCommon.cpp index a641797bfcfd6e..0850da0d520edc 100644 --- a/src/coreclr/nativeaot/Runtime/windows/PalRedhawkCommon.cpp +++ b/src/coreclr/nativeaot/Runtime/windows/PalRedhawkCommon.cpp @@ -221,21 +221,12 @@ REDHAWK_PALEXPORT void REDHAWK_PALAPI PalGetPDBInfo(HANDLE hOsHandle, _Out_ GUID } } +uint32_t g_RhNumberOfProcessors; + REDHAWK_PALEXPORT int32_t REDHAWK_PALAPI PalGetProcessCpuCount() { - static int CpuCount = 0; - - if (CpuCount != 0) - return CpuCount; - else - { - // The concept of process CPU affinity is going away and so CoreSystem obsoletes the APIs used to - // fetch this information. Instead we'll just return total cpu count. - SYSTEM_INFO sysInfo; - ::GetSystemInfo(&sysInfo); - CpuCount = sysInfo.dwNumberOfProcessors; - return sysInfo.dwNumberOfProcessors; - } + ASSERT(g_RhNumberOfProcessors > 0); + return g_RhNumberOfProcessors; } // Retrieves the entire range of memory dedicated to the calling thread's stack. This does diff --git a/src/coreclr/nativeaot/Runtime/windows/PalRedhawkMinWin.cpp b/src/coreclr/nativeaot/Runtime/windows/PalRedhawkMinWin.cpp index 1c3a74fa20c22c..ebfc0ebb078494 100644 --- a/src/coreclr/nativeaot/Runtime/windows/PalRedhawkMinWin.cpp +++ b/src/coreclr/nativeaot/Runtime/windows/PalRedhawkMinWin.cpp @@ -35,20 +35,6 @@ uint32_t PalEventWrite(REGHANDLE arg1, const EVENT_DESCRIPTOR * arg2, uint32_t a // Index for the fiber local storage of the attached thread pointer static uint32_t g_flsIndex = FLS_OUT_OF_INDEXES; -GCSystemInfo g_RhSystemInfo; - -bool InitializeSystemInfo() -{ - SYSTEM_INFO systemInfo; - GetSystemInfo(&systemInfo); - - g_RhSystemInfo.dwNumberOfProcessors = systemInfo.dwNumberOfProcessors; - g_RhSystemInfo.dwPageSize = systemInfo.dwPageSize; - g_RhSystemInfo.dwAllocationGranularity = systemInfo.dwAllocationGranularity; - - return true; -} - // This is called when each *fiber* is destroyed. When the home fiber of a thread is destroyed, // it means that the thread itself is destroyed. // Since we receive that notification outside of the Loader Lock, it allows us to safely acquire @@ -77,6 +63,14 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalInit() return false; } + if (!GCToOSInterface::Initialize()) + { + return false; + } + + // Use the same adjustment for current processor count as GC + g_RhNumberOfProcessors = GCToOSInterface::GetCurrentProcessCpuCount(); + return true; } @@ -380,9 +374,9 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalEventEnabled(REGHANDLE regHandle, _In_ return !!EventEnabled(regHandle, eventDescriptor); } -REDHAWK_PALEXPORT HANDLE REDHAWK_PALAPI PalCreateLowMemoryNotification() +REDHAWK_PALEXPORT void REDHAWK_PALAPI PalTerminateCurrentProcess(uint32_t arg2) { - return CreateMemoryResourceNotification(LowMemoryResourceNotification); + TerminateProcess(GetCurrentProcess(), arg2); } REDHAWK_PALEXPORT HANDLE REDHAWK_PALAPI PalGetModuleHandleFromPointer(_In_ void* pointer)