MdeModulePkg/Bds: BDS hotkey shouldn't work on inactive consoles
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Feng Tian <feng.tian@intel.com> Reviewed-by: Sunny Wang <sunnywang@intel.com>
This commit is contained in:
parent
b5d89de167
commit
2d15a83017
|
@ -1,7 +1,7 @@
|
||||||
/** @file
|
/** @file
|
||||||
Hotkey library functions.
|
Hotkey library functions.
|
||||||
|
|
||||||
Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -440,6 +440,54 @@ BmHotkeyCallback (
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return the active Simple Text Input Ex handle array.
|
||||||
|
If the SystemTable.ConsoleInHandle is NULL, the function returns all
|
||||||
|
founded Simple Text Input Ex handles.
|
||||||
|
Otherwise, it just returns the ConsoleInHandle.
|
||||||
|
|
||||||
|
@param Count Return the handle count.
|
||||||
|
|
||||||
|
@retval The active console handles.
|
||||||
|
**/
|
||||||
|
EFI_HANDLE *
|
||||||
|
BmGetActiveConsoleIn (
|
||||||
|
OUT UINTN *Count
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
EFI_HANDLE *Handles;
|
||||||
|
|
||||||
|
if (gST->ConsoleInHandle != NULL) {
|
||||||
|
Status = gBS->OpenProtocol (
|
||||||
|
gST->ConsoleInHandle,
|
||||||
|
&gEfiSimpleTextInputExProtocolGuid,
|
||||||
|
NULL,
|
||||||
|
gImageHandle,
|
||||||
|
NULL,
|
||||||
|
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
Handles = AllocateCopyPool (sizeof (EFI_HANDLE *), &gST->ConsoleInHandle);
|
||||||
|
*Count = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Status = gBS->LocateHandleBuffer (
|
||||||
|
ByProtocol,
|
||||||
|
&gEfiSimpleTextInputExProtocolGuid,
|
||||||
|
NULL,
|
||||||
|
Count,
|
||||||
|
&Handles
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
Handles = NULL;
|
||||||
|
*Count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Handles;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Unregister hotkey notify list.
|
Unregister hotkey notify list.
|
||||||
|
|
||||||
|
@ -461,13 +509,7 @@ BmUnregisterHotkeyNotify (
|
||||||
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;
|
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;
|
||||||
VOID *NotifyHandle;
|
VOID *NotifyHandle;
|
||||||
|
|
||||||
gBS->LocateHandleBuffer (
|
Handles = BmGetActiveConsoleIn (&HandleCount);
|
||||||
ByProtocol,
|
|
||||||
&gEfiSimpleTextInputExProtocolGuid,
|
|
||||||
NULL,
|
|
||||||
&HandleCount,
|
|
||||||
&Handles
|
|
||||||
);
|
|
||||||
for (Index = 0; Index < HandleCount; Index++) {
|
for (Index = 0; Index < HandleCount; Index++) {
|
||||||
Status = gBS->HandleProtocol (Handles[Index], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);
|
Status = gBS->HandleProtocol (Handles[Index], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
@ -485,6 +527,10 @@ BmUnregisterHotkeyNotify (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Handles != NULL) {
|
||||||
|
FreePool (Handles);
|
||||||
|
}
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -636,6 +682,8 @@ BmProcessKeyOption (
|
||||||
|
|
||||||
EfiAcquireLock (&mBmHotkeyLock);
|
EfiAcquireLock (&mBmHotkeyLock);
|
||||||
|
|
||||||
|
Handles = BmGetActiveConsoleIn (&HandleCount);
|
||||||
|
|
||||||
for (Index = 0; Index < KeyShiftStateCount; Index++) {
|
for (Index = 0; Index < KeyShiftStateCount; Index++) {
|
||||||
Hotkey = AllocateZeroPool (sizeof (BM_HOTKEY));
|
Hotkey = AllocateZeroPool (sizeof (BM_HOTKEY));
|
||||||
ASSERT (Hotkey != NULL);
|
ASSERT (Hotkey != NULL);
|
||||||
|
@ -651,13 +699,6 @@ BmProcessKeyOption (
|
||||||
}
|
}
|
||||||
InsertTailList (&mBmHotkeyList, &Hotkey->Link);
|
InsertTailList (&mBmHotkeyList, &Hotkey->Link);
|
||||||
|
|
||||||
gBS->LocateHandleBuffer (
|
|
||||||
ByProtocol,
|
|
||||||
&gEfiSimpleTextInputExProtocolGuid,
|
|
||||||
NULL,
|
|
||||||
&HandleCount,
|
|
||||||
&Handles
|
|
||||||
);
|
|
||||||
for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
|
for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
|
||||||
Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);
|
Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
@ -665,6 +706,9 @@ BmProcessKeyOption (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Handles != NULL) {
|
||||||
|
FreePool (Handles);
|
||||||
|
}
|
||||||
EfiReleaseLock (&mBmHotkeyLock);
|
EfiReleaseLock (&mBmHotkeyLock);
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
|
@ -875,13 +919,20 @@ EfiBootManagerStartHotkeyService (
|
||||||
BmProcessKeyOption (mBmContinueKeyOption);
|
BmProcessKeyOption (mBmContinueKeyOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
EfiCreateProtocolNotifyEvent (
|
//
|
||||||
&gEfiSimpleTextInputExProtocolGuid,
|
// Hook hotkey on every future SimpleTextInputEx instance when
|
||||||
TPL_CALLBACK,
|
// SystemTable.ConsoleInHandle == NULL, which means the console
|
||||||
BmTxtInExCallback,
|
// manager (ConSplitter) is absent.
|
||||||
NULL,
|
//
|
||||||
&mBmTxtInExRegistration
|
if (gST->ConsoleInHandle == NULL) {
|
||||||
);
|
EfiCreateProtocolNotifyEvent (
|
||||||
|
&gEfiSimpleTextInputExProtocolGuid,
|
||||||
|
TPL_CALLBACK,
|
||||||
|
BmTxtInExCallback,
|
||||||
|
NULL,
|
||||||
|
&mBmTxtInExRegistration
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Status = EfiCreateEventReadyToBootEx (
|
Status = EfiCreateEventReadyToBootEx (
|
||||||
TPL_CALLBACK,
|
TPL_CALLBACK,
|
||||||
|
@ -891,7 +942,6 @@ EfiBootManagerStartHotkeyService (
|
||||||
);
|
);
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
|
||||||
mBmHotkeyServiceStarted = TRUE;
|
mBmHotkeyServiceStarted = TRUE;
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue