Skip to content

Commit ef47482

Browse files
NeilMondayNeil Monday
andauthored
Windows: Remove exception handler for pagemap on unloading (#746)
Co-authored-by: Neil Monday <[email protected]>
1 parent a3fe420 commit ef47482

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/snmalloc/pal/pal_windows.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,22 @@ namespace snmalloc
103103

104104
static void initialise_for_singleton(size_t*) noexcept
105105
{
106-
AddVectoredExceptionHandler(1, HandleReadonlyLazyCommit);
106+
// Keep a handle for the exception handler, so we can remove it later
107+
// when needed.
108+
static PVOID g_Handler{};
109+
// Destructor for removing exception handler.
110+
static OnDestruct tidy([]() {
111+
if (g_Handler)
112+
{
113+
RemoveVectoredExceptionHandler(g_Handler);
114+
g_Handler = NULL; // Prevent dangling pointer
115+
}
116+
});
117+
// Add exception handler for lazy commit.
118+
if (!g_Handler)
119+
{
120+
g_Handler = AddVectoredExceptionHandler(1, HandleReadonlyLazyCommit);
121+
}
107122
}
108123

109124
// Ensure the exception handler is registered.

0 commit comments

Comments
 (0)