Skip to content

Incorrect marshalling of Bool return types in new exception handling #113574

@filipnavara

Description

@filipnavara

The managed prototypes for RhpSfiInit, RhpSfiNext and few other methods specify UnmanagedType.Bool for the return values:

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "SfiInit")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static unsafe partial bool RhpSfiInit(ref StackFrameIterator pThis, void* pStackwalkCtx, [MarshalAs(UnmanagedType.Bool)] bool instructionFault, bool* fIsExceptionIntercepted);
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "SfiNext")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static unsafe partial bool RhpSfiNext(ref StackFrameIterator pThis, uint* uExCollideClauseIdx, bool* fUnwoundReversePInvoke, bool* fIsExceptionIntercepted);

This is a four byte Win32 BOOL type. However, the native code uses 1-byte C++ bool type.

In the debug version of the runtime with MSVC compiler the contracts often trash the high bytes of the RAX/EAX register and thus an incorrect return value is marshalled.

/cc @janvorli

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions