Skip to content

[interpreter] Add a Windows SEH handler around managed calli - #135336

Draft
BrzVlad wants to merge 1 commit into
dotnet:mainfrom
BrzVlad:fix-interp-win
Draft

BrzVlad wants to merge 1 commit into
dotnet:mainfrom
BrzVlad:fix-interp-win

Conversation

@BrzVlad

@BrzVlad BrzVlad commented Oct 7, 2026

Copy link
Copy Markdown
Member

#133662 changed the first reflection invocation from:

MethodInfo.Invoke
-> RuntimeMethodHandle_InvokeMethod (QCall)
-> CallDescrWorkerWithHandler
-> target method

to this path when the CoreLib thunk is interpreted:

MethodInfo.Invoke
-> InvokeWithSharedThunk
-> IntrinsicInvokeHelper.Invoke
-> shared thunk
-> InvokeCalliStub
-> pHeader->Invoke
-> target method

The old path had exception handling around the target call. The new pHeader->Invoke call was not wrapped in a Windows SEH handler. Loading a type or assembly while preparing the target can raise a CLR exception as SEH before the target body runs. That exception could miss the interpreted caller's catch block.

Wrap pHeader->Invoke with CallWithSEHWrapper on Windows. The handler passes the CLR's existing exception object to DispatchManagedException so the interpreter can find the caller's catch block. Also allow the wrapper to call void functions and extend GitHub_76531 to cover MethodInfo.Invoke and MethodInvoker.Invoke.

The handler uses LastThrownObject; it does not turn raw native SEH codes into managed exceptions. The calli_excep test remains skipped.

dotnet#133662 changed the first reflection invocation from:

  MethodInfo.Invoke
    -> RuntimeMethodHandle_InvokeMethod (QCall)
    -> CallDescrWorkerWithHandler
    -> target method

to this path when the CoreLib thunk is interpreted:

  MethodInfo.Invoke
    -> InvokeWithSharedThunk
    -> IntrinsicInvokeHelper.Invoke
    -> shared thunk
    -> InvokeCalliStub
    -> pHeader->Invoke
    -> target method

The old path had exception handling around the target call. The new
pHeader->Invoke call was not wrapped in a Windows SEH handler. Loading a
type or assembly while preparing the target can raise a CLR exception as
SEH before the target body runs. That exception could miss the interpreted
caller's catch block.

Wrap pHeader->Invoke with CallWithSEHWrapper on Windows. The handler passes
the CLR's existing exception object to DispatchManagedException so the
interpreter can find the caller's catch block. Also allow the wrapper to
call void functions and extend GitHub_76531 to cover MethodInfo.Invoke and
MethodInvoker.Invoke.

The handler uses LastThrownObject; it does not turn raw native SEH codes
into managed exceptions. The calli_excep test remains skipped.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 752296b7-8fe1-428c-9643-012fd69699ee
@BrzVlad

BrzVlad commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

/azp run runtime-interpreter

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli
See info in area-owners.md if you want to be subscribed.

@BrzVlad

BrzVlad commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

/azp run runtime-interpreter

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

This branch has not been deployed

No deployments
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.

1 participant