diff options
author | Ruiyu Ni <ruiyu.ni@intel.com> | 2016-03-18 15:48:49 +0800 |
---|---|---|
committer | Ruiyu Ni <ruiyu.ni@intel.com> | 2016-03-23 13:22:30 +0800 |
commit | 2d15a830172675b1685cb413de4187fb9f646695 (patch) | |
tree | 4a604f1a7535c7b926c30146e0b9666d555bcaf0 /MdeModulePkg | |
parent | b5d89de167a683eeba3e2dbb6557f402b952cdc2 (diff) | |
download | edk2-platforms-2d15a830172675b1685cb413de4187fb9f646695.tar.xz |
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>
Diffstat (limited to 'MdeModulePkg')
-rw-r--r-- | MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c | 96 |
1 files changed, 73 insertions, 23 deletions
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c index af303e8469..4cc4fb4554 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c @@ -1,7 +1,7 @@ /** @file
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
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
@@ -441,6 +441,54 @@ BmHotkeyCallback ( }
/**
+ 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.
@param Hotkey Hotkey list.
@@ -461,13 +509,7 @@ BmUnregisterHotkeyNotify ( EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;
VOID *NotifyHandle;
- gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiSimpleTextInputExProtocolGuid,
- NULL,
- &HandleCount,
- &Handles
- );
+ Handles = BmGetActiveConsoleIn (&HandleCount);
for (Index = 0; Index < HandleCount; Index++) {
Status = gBS->HandleProtocol (Handles[Index], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);
ASSERT_EFI_ERROR (Status);
@@ -485,6 +527,10 @@ BmUnregisterHotkeyNotify ( }
}
+ if (Handles != NULL) {
+ FreePool (Handles);
+ }
+
return EFI_SUCCESS;
}
@@ -636,6 +682,8 @@ BmProcessKeyOption ( EfiAcquireLock (&mBmHotkeyLock);
+ Handles = BmGetActiveConsoleIn (&HandleCount);
+
for (Index = 0; Index < KeyShiftStateCount; Index++) {
Hotkey = AllocateZeroPool (sizeof (BM_HOTKEY));
ASSERT (Hotkey != NULL);
@@ -651,13 +699,6 @@ BmProcessKeyOption ( }
InsertTailList (&mBmHotkeyList, &Hotkey->Link);
- gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiSimpleTextInputExProtocolGuid,
- NULL,
- &HandleCount,
- &Handles
- );
for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);
ASSERT_EFI_ERROR (Status);
@@ -665,6 +706,9 @@ BmProcessKeyOption ( }
}
+ if (Handles != NULL) {
+ FreePool (Handles);
+ }
EfiReleaseLock (&mBmHotkeyLock);
return EFI_SUCCESS;
@@ -875,13 +919,20 @@ EfiBootManagerStartHotkeyService ( BmProcessKeyOption (mBmContinueKeyOption);
}
- EfiCreateProtocolNotifyEvent (
- &gEfiSimpleTextInputExProtocolGuid,
- TPL_CALLBACK,
- BmTxtInExCallback,
- NULL,
- &mBmTxtInExRegistration
- );
+ //
+ // Hook hotkey on every future SimpleTextInputEx instance when
+ // SystemTable.ConsoleInHandle == NULL, which means the console
+ // manager (ConSplitter) is absent.
+ //
+ if (gST->ConsoleInHandle == NULL) {
+ EfiCreateProtocolNotifyEvent (
+ &gEfiSimpleTextInputExProtocolGuid,
+ TPL_CALLBACK,
+ BmTxtInExCallback,
+ NULL,
+ &mBmTxtInExRegistration
+ );
+ }
Status = EfiCreateEventReadyToBootEx (
TPL_CALLBACK,
@@ -891,7 +942,6 @@ EfiBootManagerStartHotkeyService ( );
ASSERT_EFI_ERROR (Status);
-
mBmHotkeyServiceStarted = TRUE;
return Status;
}
|