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.

@UnityAlex
Copy link
Collaborator

@xiaoxiao921 Is there a submitted bug for this issue? Typically we try not to land changes blind without a reproduction of the bug as well as a case # for tracking.

@xiaoxiao921
Copy link
Author

@UnityAlex Hey thanks for getting back to me, I made a bug report through the Editor with the top button Help -> Report a bug

Email subject I received:

New Incident created: IN-127643 - StackOverflow Managed Exceptions are not always catched properly by the mono native handler.

@UnityAlex
Copy link
Collaborator

Excellent. Thank you @xiaoxiao921. I'll chase this down with the QA folks.

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.

2 participants