diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index fbafd6e9a844d9..d27b5e9736246c 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -9218,10 +9218,14 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX #endif // true if we should use the PINVOKE_{BEGIN,END} helpers instead of generating - // PInvoke transitions inline. + // PInvoke transitions inline. Normally used by R2R, but also used when generating a reverse pinvoke frame, as + // the current logic for frame setup initializes and pushes + // the InlinedCallFrame before performing the Reverse PInvoke transition, which is invalid (as frames cannot + // safely be pushed/popped while the thread is in a preemptive state.). bool ShouldUsePInvokeHelpers() { - return jitFlags->IsSet(JitFlags::JIT_FLAG_USE_PINVOKE_HELPERS); + return jitFlags->IsSet(JitFlags::JIT_FLAG_USE_PINVOKE_HELPERS) || + jitFlags->IsSet(JitFlags::JIT_FLAG_REVERSE_PINVOKE); } // true if we should use insert the REVERSE_PINVOKE_{ENTER,EXIT} helpers in the method