[HAL] Reset the stack pointer to the stack frame when calling second-entry interrupt...
authorThomas Faber <thomas.faber@reactos.org>
Fri, 13 Apr 2018 06:48:57 +0000 (08:48 +0200)
committerThomas Faber <thomas.faber@reactos.org>
Fri, 13 Apr 2018 07:04:52 +0000 (09:04 +0200)
Because we can encounter pending interrupts repeatedly,
HalpEndSoftwareInterrupt and HalEndSystemInterrupt already clean up the stack
space for their arguments (done for CORE-11123/CORE-14076).
However these functions are called from C functions such as KiInterruptDispatch
and HalpDispatchInterrupt2[ndEntry]. These callers also use up stack space,
and it is unknown how much.
To fix this, we simply reset the stack pointer to the location of the trap
frame, which is where it points during a first-level dispatch. This cleans
up the stack usage of any callers higher up, and is okay because a return
will happen through the trap frame anyway.

Dedicated to Pierre.

hal/halx86/up/pic.S

index a5addcd..3f65a55 100644 (file)
@@ -39,11 +39,14 @@ PUBLIC _&WrapperName&@8
     ret 8
 
 WrapperName&_CallIntHandler:
-    /* We got a pointer to call. Since it won't return, free up our stack
-       space. Otherwise we could end up with some nasty deep recursion.
+    /* We got a pointer to call. Since it won't return, reset the stack to
+       the location of the stack frame. This frees up our own stack as well
+       as that of the functions above us, and avoids an overflow due to
+       excessive recursion.
        The next function takes the trap frame as its (fastcall) argument. */
     mov ecx, [esp+8]
-    add esp, 12
+    mov esp, ecx
+    mov ebp, esp
     jmp eax
 .ENDP
 ENDM