https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b4453242f7d7e71329b05b...
commit b4453242f7d7e71329b05b721066f11465add86e Author: Thomas Faber thomas.faber@reactos.org AuthorDate: Sun Feb 18 12:50:54 2018 +0100 Commit: Thomas Faber thomas.faber@reactos.org CommitDate: Sun Feb 18 13:06:42 2018 +0100
[HAL] Eliminate tail calls from HalpDispatchInterrupt[2]. CORE-14076 --- hal/halx86/include/halp.h | 2 +- hal/halx86/up/pic.S | 24 ++++++++++++++++++++++++ hal/halx86/up/pic.c | 8 +++++--- 3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/hal/halx86/include/halp.h b/hal/halx86/include/halp.h index 079b1adb6d..ed430910fd 100644 --- a/hal/halx86/include/halp.h +++ b/hal/halx86/include/halp.h @@ -576,7 +576,7 @@ HalpEnableInterruptHandler(IN UCHAR Flags, VOID NTAPI HalpInitializePICs(IN BOOLEAN EnableInterrupts); VOID __cdecl HalpApcInterrupt(VOID); VOID __cdecl HalpDispatchInterrupt(VOID); -VOID __cdecl HalpDispatchInterrupt2(VOID); +PHAL_SW_INTERRUPT_HANDLER __cdecl HalpDispatchInterrupt2(VOID); DECLSPEC_NORETURN VOID FASTCALL HalpApcInterrupt2ndEntry(IN PKTRAP_FRAME TrapFrame); DECLSPEC_NORETURN VOID FASTCALL HalpDispatchInterrupt2ndEntry(IN PKTRAP_FRAME TrapFrame);
diff --git a/hal/halx86/up/pic.S b/hal/halx86/up/pic.S index 8211718585..1076bc5711 100644 --- a/hal/halx86/up/pic.S +++ b/hal/halx86/up/pic.S @@ -48,8 +48,32 @@ WrapperName&_CallIntHandler: .ENDP ENDM
+MACRO(DEFINE_INTERRUPT_WRAPPER, WrapperName, HandlerName) +EXTERN _&HandlerName:PROC +PUBLIC _&WrapperName +.PROC _&WrapperName + FPO 0, 0, 0, 0, 0, FRAME_FPO + + /* Call the C function */ + call _&HandlerName + + /* Check if we got a pointer back */ + test eax, eax + jnz WrapperName&_CallIntHandler + + /* No? Just return */ + ret + +WrapperName&_CallIntHandler: + /* Optimize the tail call to avoid stack overflow */ + jmp eax +.ENDP +ENDM +
DEFINE_END_INTERRUPT_WRAPPER HalpEndSoftwareInterrupt, HalpEndSoftwareInterrupt2 DEFINE_END_INTERRUPT_WRAPPER HalEndSystemInterrupt, HalEndSystemInterrupt2
+DEFINE_INTERRUPT_WRAPPER HalpDispatchInterrupt, HalpDispatchInterrupt2 + END diff --git a/hal/halx86/up/pic.c b/hal/halx86/up/pic.c index 2d1d6d10e3..6f68f1c5d0 100644 --- a/hal/halx86/up/pic.c +++ b/hal/halx86/up/pic.c @@ -382,7 +382,7 @@ PHAL_SW_INTERRUPT_HANDLER SWInterruptHandlerTable[20] = { (PHAL_SW_INTERRUPT_HANDLER)KiUnexpectedInterrupt, HalpApcInterrupt, - HalpDispatchInterrupt2, + HalpDispatchInterrupt, (PHAL_SW_INTERRUPT_HANDLER)KiUnexpectedInterrupt, HalpHardwareInterrupt0, HalpHardwareInterrupt1, @@ -1297,7 +1297,7 @@ HalpDispatchInterrupt2ndEntry(IN PKTRAP_FRAME TrapFrame) KiEoiHelper(TrapFrame); }
-VOID +PHAL_SW_INTERRUPT_HANDLER __cdecl HalpDispatchInterrupt2(VOID) { @@ -1330,8 +1330,10 @@ HalpDispatchInterrupt2(VOID) }
/* Now handle pending interrupt */ - SWInterruptHandlerTable[PendingIrql](); + return SWInterruptHandlerTable[PendingIrql]; } + + return NULL; }
#else