[HAL] Reset the stack pointer to the stack frame when calling second-entry interrupt handlers. CORE-14449

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.
This commit is contained in:
Thomas Faber 2018-04-13 08:48:57 +02:00
parent bb03da981c
commit fc9bc9390d
No known key found for this signature in database
GPG key ID: 076E7C3D44720826

View 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