Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 31, 2026

Added a null check for NtCurrentTeb()->ThreadLocalStoragePointer at the beginning of COMUnhandledExceptionFilter on Windows to avoid crashing inside coreclr.dll when there is an unhandled exception early during thread initialization. We have similar check in other global EH handlers.

Fixes #115476

Copilot AI changed the title [WIP] Fix access violation at COMUnhandledExceptionFilter Add exception handler to prevent crash in COMUnhandledExceptionFilter Jan 31, 2026
Copilot AI requested a review from jkotas January 31, 2026 00:43
@jkotas
Copy link
Member

jkotas commented Jan 31, 2026

@copilot Revert all changes you have made. Instead, implement the fix mentioned in #115476 (comment)

Copy link
Contributor Author

Copilot AI commented Jan 31, 2026

@copilot Revert all changes you have made. Instead, implement the fix mentioned in #115476 (comment)

Reverted the previous implementation and implemented a more minimal fix that only protects the GetThreadNULLOk() call with __try/__except. The new approach stores the thread pointer once and reuses it, avoiding multiple TLS access attempts. Changes in commit 0ef7da5.

Copilot AI changed the title Add exception handler to prevent crash in COMUnhandledExceptionFilter Protect GetThreadNULLOk() call in COMUnhandledExceptionFilter to prevent crash Jan 31, 2026
@jkotas
Copy link
Member

jkotas commented Jan 31, 2026

@copilot Please revert all changes you have made, DO NOT use any __try/__catch, and just implement the fix that it similar to the code that I have linked to. The fix should early out from COMUnhandledExceptionFilter when NtCurrentTeb()->ThreadLocalStoragePointer is null.

Copy link
Contributor Author

Copilot AI commented Jan 31, 2026

@copilot Please revert all changes you have made, DO NOT use any __try/__catch, and just implement the fix that it similar to the code that I have linked to. The fix should early out from `COMUnhandle...

Reverted all previous changes and implemented the fix using NtCurrentTeb()->ThreadLocalStoragePointer null check. The function now returns early when TLS is not available, without using any __try/__except. Changes in commit 71288f5.

Copilot AI changed the title Protect GetThreadNULLOk() call in COMUnhandledExceptionFilter to prevent crash Add null check for ThreadLocalStoragePointer in COMUnhandledExceptionFilter to prevent crash Jan 31, 2026
Copilot AI changed the title Add null check for ThreadLocalStoragePointer in COMUnhandledExceptionFilter to prevent crash Add null check for ThreadLocalStoragePointer in COMUnhandledExceptionFilter to prevent crash on Windows Jan 31, 2026
Copilot AI requested a review from jkotas January 31, 2026 04:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a defensive early-return in COMUnhandledExceptionFilter on Windows when TLS is not yet initialized, preventing a crash when the unhandled exception filter runs during very early thread startup.

Changes:

  • Add a Windows-only check for NtCurrentTeb()->ThreadLocalStoragePointer == NULL at the start of COMUnhandledExceptionFilter to avoid touching CLR TLS-backed state too early.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Access violation at COMUnhandledExceptionFilter

2 participants