Skip to content

Conversation

@radekdoulik
Copy link
Member

Developed with Jan Vorlicek

Make sure the return address is set in transition block when going through ExecuteInterpretedMethodWithArgs, so that SfiNextWorker gets the address.

Fill missing pieces around context.

Fix few asserts and offsets.

Developed with Jan Vorlicek

Make sure the return address is set in transition block when going
through `ExecuteInterpretedMethodWithArgs`, so that `SfiNextWorker`
gets the address.

Fill missing pieces around context.

Fix few asserts and offsets.

Co-authored-by: Jan Vorlicek <janvorli@microsoft.com>
@radekdoulik
Copy link
Member Author

Example output of throw new PlatformNotSupportedException(); with enabled EH log

TID 0001: TraceGC is not turned onInitializeExceptionHandling(): ExInfo size: 0x210 bytes
TID 0001: SetupThread  managed Thread 0x66f570 Thread Id = 1
TID 0001: in Thread::SetLastThrownObject: obj = 0x80c25c
TID 0001: ..SfiInit (pass 1): Exception stack walking starting at IP=0x439e238, SP=0x4febc8, method Program::<Main>$
TID 0001: ..Initialized EH enumeration, 0 clauses found
TID 0001: ..SfiNext: reached native frame at IP=0x59d, SP=0x4fec40, isPropagatingToNativeCode=0
TID 0001: ..SfiNext: the native frame is CallDescrWorkerInternal
TID 0001: ..SfiInit (pass 2): Exception stack walking starting at IP=0x439e238, SP=0x4febc8, method Program::<Main>$
TID 0001: ..Initialized EH enumeration, 0 clauses found
TID 0001: ..SfiNext: reached native frame at IP=0x59d, SP=0x4fec40, isPropagatingToNativeCode=0
TID 0001: ..SfiNext: the native frame is CallDescrWorkerInternal
TID 0001: Popping ExInfos below SP=0x4fec40
TID 0001: Resuming propagation of managed exception through native frames at IP=0x59d, SP=0x4fec40
TID 0001: ******* MANAGED EXCEPTION THROWN: Object thrown: 0x80c25c MT 0x44b95acT rethrow 0
TID 0001: Exception HRESULT = 0x80131539 Message String 0x0x80d0f4 (db will display) InnerException 0 MT 0T
TID 0001: in Thread::SetLastThrownObject: obj = 0x80c25c
TID 0001: ..SfiInit: No more managed frames found on stack
TID 0001: In InternalUnhandledExceptionFilter_Worker, Exception = e0434352, sp = 0x4fbfb0
TID 0001: InternalUnhandledExceptionFilter_Worker: Set unhandled exception flag at 0x4fd7e8
TID 0001: InternalUnhandledExceptionFilter_Worker: Handling
TID 0001: InternalUnhandledExceptionFilter_Worker: Notifying Debugger...
TID 0001: In NotifyAppDomainsOfUnhandledException
TID 0001: InternalUnhandledExceptionFilter_Worker: Launching Watson at sp 0x4fbf70 ...
TID 0001: D::WLC: Enter WatsonLastChance
TID 0001: WatsonLastChance: Debugger not attached at sp 0x4fbf10 ...
TID 0001: WatsonLastChance: should not notify debugger.  Returning EXCEPTION_CONTINUE_SEARCH
TID 0001: InternalUnhandledExceptionFilter_Worker: ... returned.
TID 0001: InternalUnhandledExceptionFilter_Worker: Calling DefaultCatchHandler
TID 0001: In DefaultCatchHandler
Unhandled exception. System.PlatformNotSupportedException: Operation is not supported on this platform.
   at Program.<Main>$(String[] args) in /Users/rodo/git/HelloWorld/Program.cs:line 2
Aborted(native code called abort())

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

This pull request fixes unhandled exception handling in the WebAssembly (WASM) implementation of CoreCLR. The primary goal is to ensure proper stack walking by setting return addresses in transition blocks and implementing missing context handling functionality for WASM.

Key changes:

  • Added callerIp parameter throughout the call chain to track return addresses for proper stack unwinding
  • Implemented TransitionFrame::UpdateRegDisplay_Impl to populate register display during stack walks
  • Fixed WASM context accessor functions to use interpreter fields instead of asserting/failing
  • Corrected offset constants for WASM's CONTEXT structure fields

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/coreclr/vm/wasm/helpers.cpp Implemented TransitionFrame::UpdateRegDisplay_Impl to set InterpreterIP/SP and initialized CallDescrWorkerInternalReturnAddressOffset
src/coreclr/vm/wasm/callhelpers-reverse.cpp Added callerIp parameter to ExecuteInterpretedMethodFromUnmanaged calls
src/coreclr/vm/wasm/calldescrworkerwasm.cpp Added callerIp parameter to ExecuteInterpretedMethodWithArgs call
src/coreclr/vm/prestub.cpp Updated function signatures and implementation to accept and use callerIp parameter
src/coreclr/vm/interpexec.h Updated function declaration to include callerIp parameter
src/coreclr/vm/exceptionhandling.cpp Added WASM-specific path to call PropagateExceptionThroughNativeFrames directly
src/coreclr/pal/src/include/pal/context.h Implemented CONTEXTGetPC, CONTEXTSetPC, and CONTEXTGetFP for WASM using interpreter fields
src/coreclr/pal/src/exception/seh-unwind.cpp Added conditional compilation to skip context capture for WASM
src/coreclr/pal/src/arch/wasm/stubs.cpp Fixed assert syntax and changed RtlCaptureContext to zero memory instead of asserting
src/coreclr/System.Private.CoreLib/src/System/Runtime/ExceptionServices/AsmOffsets.cs Corrected offset values for InterpreterIP and InterpreterFP and added static assertions

radekdoulik and others added 3 commits November 20, 2025 10:49
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
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.

3 participants