* [PATCH] EmulatorPkg: Fix bugs about BlockIo2
@ 2019-05-23 4:59 Zhiguang Liu
0 siblings, 0 replies; only message in thread
From: Zhiguang Liu @ 2019-05-23 4:59 UTC (permalink / raw)
To: devel; +Cc: Jordan Justen, Andrew Fish, Ray Ni
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1760
Signal BlockIO2 callback event manually
Add some checks before readfile/writefile function.
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Andrew Fish <afish@apple.com>
Cc: Ray Ni <ray.ni@intel.com>
---
EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.c | 13 ++++++++++---
EmulatorPkg/Win/Host/WinBlockIo.c | 41 +++++++++++++++++++++++++++++++++++------
2 files changed, 45 insertions(+), 9 deletions(-)
diff --git a/EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.c b/EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.c
index 96424a82ae..b275d908c7 100644
--- a/EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.c
+++ b/EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.c
@@ -95,7 +95,11 @@ EmuBlockIo2ReadBlocksEx (
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Status = Private->Io->ReadBlocks (Private->Io, MediaId, LBA, Token, BufferSize, Buffer);
-
+ if (Token != NULL && Token->Event != NULL) {
+ if (!EFI_ERROR (Status)) {
+ gBS->SignalEvent (Token->Event);
+ }
+ }
gBS->RestoreTPL (OldTpl);
return Status;
}
@@ -150,9 +154,12 @@ EmuBlockIo2WriteBlocksEx (
Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
-
Status = Private->Io->WriteBlocks (Private->Io, MediaId, LBA, Token, BufferSize, Buffer);
-
+ if (Token != NULL && Token->Event != NULL) {
+ if (!EFI_ERROR (Status)) {
+ gBS->SignalEvent (Token->Event);
+ }
+ }
gBS->RestoreTPL (OldTpl);
return Status;
}
diff --git a/EmulatorPkg/Win/Host/WinBlockIo.c b/EmulatorPkg/Win/Host/WinBlockIo.c
index 5ccd17388e..8941ff1b17 100644
--- a/EmulatorPkg/Win/Host/WinBlockIo.c
+++ b/EmulatorPkg/Win/Host/WinBlockIo.c
@@ -300,9 +300,24 @@ WinNtBlockIoReadBlocks (
DWORD BytesRead;
UINT64 DistanceToMove;
UINT64 DistanceMoved;
-
+ UINT64 LastBlock;
Private = WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
-
+ if (!Private->Media->MediaPresent) {
+ return EFI_NO_MEDIA;
+ }
+ if (Private->Media->MediaId != MediaId) {
+ return EFI_MEDIA_CHANGED;
+ }
+ if ((UINTN) Buffer % Private->Media->IoAlign != 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+ if ((BufferSize % Private->BlockSize) != 0) {
+ return EFI_BAD_BUFFER_SIZE;
+ }
+ LastBlock = Lba + (BufferSize / Private->BlockSize);
+ if (LastBlock > Private->Media->LastBlock+1) {
+ return EFI_INVALID_PARAMETER;
+ }
//
// Seek to proper position
//
@@ -371,9 +386,24 @@ WinNtBlockIoWriteBlocks (
EFI_STATUS Status;
UINT64 DistanceToMove;
UINT64 DistanceMoved;
-
+ UINT64 LastBlock;
Private = WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
-
+ if (!Private->Media->MediaPresent) {
+ return EFI_NO_MEDIA;
+ }
+ if (Private->Media->MediaId != MediaId) {
+ return EFI_MEDIA_CHANGED;
+ }
+ if ((UINTN) Buffer % Private->Media->IoAlign != 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+ if ((BufferSize % Private->BlockSize) != 0) {
+ return EFI_BAD_BUFFER_SIZE;
+ }
+ LastBlock = Lba + (BufferSize / Private->BlockSize);
+ if (LastBlock > Private->Media->LastBlock+1) {
+ return EFI_INVALID_PARAMETER;
+ }
//
// Seek to proper position
//
@@ -450,14 +480,13 @@ WinNtBlockIoReset (
)
{
WIN_NT_BLOCK_IO_PRIVATE *Private;
-
Private = WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
if (Private->NtHandle != INVALID_HANDLE_VALUE) {
CloseHandle (Private->NtHandle);
Private->NtHandle = INVALID_HANDLE_VALUE;
}
-
+ WinNtBlockIoCreateMapping (This, Private->Media);
return EFI_SUCCESS;
}
--
2.21.0.windows.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-05-23 4:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-23 4:59 [PATCH] EmulatorPkg: Fix bugs about BlockIo2 Zhiguang Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox