From c655529b074224d75ea77ce1183d879b691f37b3 Mon Sep 17 00:00:00 2001 From: Haris Okanovic Date: Wed, 28 Aug 2024 16:38:33 -0500 Subject: [PATCH] pal init: Move InitializeFlushProcessWriteBuffers() after VIRTUALInitialize() (#107100) A fixup of commit 27ee590d that's broken on platforms which don't support membarrier() syscall: GetVirtualPageSize() is called in the fallback path of InitializeFlushProcessWriteBuffers() and attempts to mmap() zero bytes. Move InitializeFlushProcessWriteBuffers() after VIRTUALInitialize() but before the first thread is created. Fixes https://github.com/dotnet/runtime/issues/106892 Fixes https://github.com/dotnet/runtime/issues/106722 Co-authored-by: Haris Okanovic --- src/coreclr/pal/src/init/pal.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/coreclr/pal/src/init/pal.cpp b/src/coreclr/pal/src/init/pal.cpp index 44c3d15e92fb1..4eeaa93b1e1e6 100644 --- a/src/coreclr/pal/src/init/pal.cpp +++ b/src/coreclr/pal/src/init/pal.cpp @@ -359,16 +359,6 @@ Initialize( goto CLEANUP0a; } - if (flags & PAL_INITIALIZE_FLUSH_PROCESS_WRITE_BUFFERS) - { - // Initialize before first thread is created for faster load on Linux - if (!InitializeFlushProcessWriteBuffers()) - { - palError = ERROR_PALINIT_INITIALIZE_FLUSH_PROCESS_WRITE_BUFFERS; - goto CLEANUP0a; - } - } - // The gSharedFilesPath is allocated dynamically so its destructor does not get // called unexpectedly during cleanup gSharedFilesPath = InternalNew(); @@ -616,6 +606,17 @@ Initialize( goto CLEANUP10; } + if (flags & PAL_INITIALIZE_FLUSH_PROCESS_WRITE_BUFFERS) + { + // Initialize before first thread is created for faster load on Linux + if (!InitializeFlushProcessWriteBuffers()) + { + ERROR("Unable to initialize flush process write buffers\n"); + palError = ERROR_PALINIT_INITIALIZE_FLUSH_PROCESS_WRITE_BUFFERS; + goto CLEANUP10; + } + } + if (flags & PAL_INITIALIZE_SYNC_THREAD) { //