diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c index 4aef9b70a1..dbb89932e7 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c @@ -157,6 +157,7 @@ SmmLegacyBootHandler ( { EFI_STATUS Status; EFI_HANDLE SmmHandle; + UINTN Index; // // Install SMM Legacy Boot protocol. @@ -173,6 +174,16 @@ SmmLegacyBootHandler ( SmiHandlerUnRegister (DispatchHandle); + // + // It is legacy boot, unregister ExitBootService SMI handler. + // + for (Index = 0; mSmmCoreSmiHandlers[Index].HandlerType != NULL; Index++) { + if (CompareGuid (mSmmCoreSmiHandlers[Index].HandlerType, &gEfiEventExitBootServicesGuid)) { + SmiHandlerUnRegister (mSmmCoreSmiHandlers[Index].DispatchHandle); + break; + } + } + return Status; } @@ -201,6 +212,7 @@ SmmExitBootServicesHandler ( { EFI_STATUS Status; EFI_HANDLE SmmHandle; + UINTN Index; // // Install SMM Exit Boot Services protocol. @@ -215,6 +227,16 @@ SmmExitBootServicesHandler ( SmiHandlerUnRegister (DispatchHandle); + // + // It is UEFI boot, unregister LegacyBoot SMI handler. + // + for (Index = 0; mSmmCoreSmiHandlers[Index].HandlerType != NULL; Index++) { + if (CompareGuid (mSmmCoreSmiHandlers[Index].HandlerType, &gEfiEventLegacyBootGuid)) { + SmiHandlerUnRegister (mSmmCoreSmiHandlers[Index].DispatchHandle); + break; + } + } + return Status; }