Browse Source

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>
Kagurazaka Kotori 4 years ago
parent
commit
7cc4f3a20c
3 changed files with 21 additions and 2 deletions
  1. 5 1
      inc/efilib.h
  2. 1 1
      lib/Makefile
  3. 15 0
      lib/pause.c

+ 5 - 1
inc/efilib.h

@@ -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

+ 1 - 1
lib/Makefile

@@ -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 - 0
lib/pause.c

@@ -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));
+}