Skip to content

Commit f5bd600

Browse files
authored
Merge pull request #1171 from Unity-Technologies/unity-master-stack-overflow-windows-sp-address
Update RSP with fault address for stack overflow (case 1148592)
2 parents cfa578d + 6ae9b7c commit f5bd600

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

mono/mini/exceptions-amd64.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ LONG CALLBACK seh_vectored_exception_handler(EXCEPTION_POINTERS* ep)
151151
switch (er->ExceptionCode) {
152152
case EXCEPTION_STACK_OVERFLOW:
153153
if (!mono_aot_only && restore_stack) {
154+
if (er->NumberParameters == 2) {
155+
/* Use actual stack fault address rather than relying on the
156+
* SP of the current frame. If we try to enter a method with a
157+
* large prolog (many locals) we may try to allocate more stack
158+
* than is available, however the SP has not been updated. This
159+
* means the stack overflow heuristic to free up enough space
160+
* may fail, as the used stack may be smaller than the amount
161+
* of stack that was attempted to be unwound.
162+
*/
163+
ctx->Rsp = er->ExceptionInformation[1]; /* FaultAddress */
164+
}
154165
if (mono_arch_handle_exception (ctx, domain->stack_overflow_ex)) {
155166
/* need to restore stack protection once stack is unwound
156167
* restore_stack will restore stack protection and then

0 commit comments

Comments
 (0)