Skip to content

Conversation

@xiaoxiao921
Copy link

Why

The stack overflow handler fails to execute properly in some cases, it can happen both in game release builds and inside some user editor code / c# scripts.

How

The thunk pushed RBP (−8) and then reserved only 32 bytes of shadow space, leaving RSP misaligned by 8 bytes. This violated the Win64 ABI requirement that RSP be 16-byte aligned at every call instruction. As a result, the calls to _resetstkoflw, mono_tls_get_jit_tls, and mono_restore_context were executed with an unaligned stack.

Increase the reservation to 40 bytes (32 shadow + 8 alignment fixup) to restore correct 16-byte alignment after the initial push and ensure all call sites are ABI-compliant.


  • Should this pull request have release notes?
    • Yeah? Probably?
  • Do these changes need to be back ported?
    • Yes.
      I don't know how far back, probably forever since that line of code is probably decade old at this point, I did test this personally on 2019.4.26 and 2021.3.33 but that's it.
  • Do these changes need to be upstreamed to mono/mono repository?

The thunk pushed RBP (−8) and then reserved only 32 bytes of shadow space, leaving RSP misaligned by 8 bytes. This violated the Win64 ABI requirement that RSP be 16-byte aligned at every call instruction. As a result, the calls to _resetstkoflw, mono_tls_get_jit_tls, and mono_restore_context were executed with an unaligned stack.

Increase the reservation to 40 bytes (32 shadow + 8 alignment fixup) to restore correct 16-byte alignment after the initial push and ensure all call sites are ABI-compliant.
@cla-assistant-unity
Copy link

cla-assistant-unity bot commented Dec 7, 2025

CLA assistant check
All committers have signed the CLA.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant