Replace Pause() macro with new library function

Key input should be consumed to prevent WaitForKey event from being
always triggered and potential buffer overflow.
This fixes issue #26.

Signed-off-by: Kagurazaka Kotori <kagurazakakotori@gmail.com>
This commit is contained in:
Kagurazaka Kotori 2020-07-22 17:49:07 +08:00
parent b82e6b6f5b
commit 7cc4f3a20c
No known key found for this signature in database
GPG Key ID: 816F0D4481B7E7DD
3 changed files with 21 additions and 2 deletions

View File

@ -1017,6 +1017,11 @@ WritePciConfig (
IN UINTN Data
);
VOID
Pause (
VOID
);
extern EFI_DEVICE_IO_INTERFACE *GlobalIoFncs;
#define outp(_Port, _DataByte) (UINT8)WritePort(GlobalIoFncs, IO_UINT8, (UINTN)_Port, (UINTN)_DataByte)
@ -1033,7 +1038,6 @@ extern EFI_DEVICE_IO_INTERFACE *GlobalIoFncs;
#define writepci32(_Addr, _DataByte) (UINT32)WritePciConfig(GlobalIoFncs, IO_UINT32, (UINTN)_Addr, (UINTN)_DataByte)
#define readpci32(_Addr) (UINT32)ReadPciConfig(GlobalIoFncs, IO_UINT32, (UINTN)_Addr)
#define Pause() WaitForSingleEvent (ST->ConIn->WaitForKey, 0)
#define Port80(_PostCode) GlobalIoFncs->Io.Write (GlobalIoFncs, IO_UINT16, (UINT64)0x80, 1, &(_PostCode))
#endif

View File

@ -45,7 +45,7 @@ TOPDIR = $(SRCDIR)/..
CDIR = $(TOPDIR)/..
FILES = boxdraw smbios console crc data debug dpath \
error event exit guid hand hw init lock \
misc print sread str cmdline \
misc pause print sread str cmdline\
runtime/rtlock runtime/efirtlib runtime/rtstr runtime/vm runtime/rtdata \
$(ARCH)/initplat $(ARCH)/math $(ARCH)/setjmp

15
lib/pause.c Normal file
View File

@ -0,0 +1,15 @@
#include "lib.h"
VOID
Pause(
VOID
)
// Pause until any key is pressed
{
EFI_INPUT_KEY Key;
EFI_STATUS Status EFI_UNUSED;
WaitForSingleEvent(ST->ConIn->WaitForKey, 0);
Status = uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, &Key);
ASSERT(!EFI_ERROR(Status));
}