Skip to content

Commit

Permalink
Windows: Remove exception handler for pagemap on unloading (#746)
Browse files Browse the repository at this point in the history
Co-authored-by: Neil Monday <[email protected]>
  • Loading branch information
NeilMonday and Neil Monday authored Feb 12, 2025
1 parent a3fe420 commit ef47482
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/snmalloc/pal/pal_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,22 @@ namespace snmalloc

static void initialise_for_singleton(size_t*) noexcept
{
AddVectoredExceptionHandler(1, HandleReadonlyLazyCommit);
// Keep a handle for the exception handler, so we can remove it later
// when needed.
static PVOID g_Handler{};
// Destructor for removing exception handler.
static OnDestruct tidy([]() {
if (g_Handler)
{
RemoveVectoredExceptionHandler(g_Handler);
g_Handler = NULL; // Prevent dangling pointer
}
});
// Add exception handler for lazy commit.
if (!g_Handler)
{
g_Handler = AddVectoredExceptionHandler(1, HandleReadonlyLazyCommit);
}
}

// Ensure the exception handler is registered.
Expand Down

0 comments on commit ef47482

Please sign in to comment.