Skip to content

Commit fc9bc93

Browse files
committed
[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.
1 parent bb03da9 commit fc9bc93

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

hal/halx86/up/pic.S

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ PUBLIC _&WrapperName&@8
3939
ret 8
4040

4141
WrapperName&_CallIntHandler:
42-
/* We got a pointer to call. Since it won't return, free up our stack
43-
space. Otherwise we could end up with some nasty deep recursion.
42+
/* We got a pointer to call. Since it won't return, reset the stack to
43+
the location of the stack frame. This frees up our own stack as well
44+
as that of the functions above us, and avoids an overflow due to
45+
excessive recursion.
4446
The next function takes the trap frame as its (fastcall) argument. */
4547
mov ecx, [esp+8]
46-
add esp, 12
48+
mov esp, ecx
49+
mov ebp, esp
4750
jmp eax
4851
.ENDP
4952
ENDM

0 commit comments

Comments
 (0)