From: "Zhiguang Liu" <zhiguang.liu@intel.com>
To: devel@edk2.groups.io
Cc: Jordan Justen <jordan.l.justen@intel.com>,
Andrew Fish <afish@apple.com>, Ray Ni <ray.ni@intel.com>
Subject: [PATCH] EmulatorPkg: Fix bugs about BlockIo2
Date: Thu, 23 May 2019 12:59:04 +0800 [thread overview]
Message-ID: <20190523045905.17208-1-zhiguang.liu@intel.com> (raw)
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
reply other threads:[~2019-05-23 4:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190523045905.17208-1-zhiguang.liu@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox