From nobody Sun Apr 28 18:36:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+41265+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+41265+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1558587561; cv=none; d=zoho.com; s=zohoarc; b=bIqHIisVygQz7IrLbeba421JD+N443VF0bPOljOf/q1EQvQaFNu+ypwgNu4ipWB66Wn2sQ+P/2GFGceluQ4AqtU4iBhYTn4i4YJC4NNfL/JefiLAUEM89sG3U5G7pAJ7T1Nf8tP5ubsgzIlAPEAbqkAGSEmGEUK3yWoz+Q6Ennw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558587561; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=35ann8b90P+lUlH2DXYcqkTrjDIhYWpFE2k6zjZgUVQ=; b=e18lsUjFr+m9OpdisIYYxDheXmNM4bZG1LQT3ctwqOIbGsCOjf/Wlc1nQ42ZV745tvY9rK16K3DfTInKEgwG4Ihiiqp5pnpDt7sbG7yD+7m995QGqQBWVXYP2D9oD2B1Xd8yPUlM0Ar8gIUANxMRiZU7NfAazRqeL1zzU0YgjqM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+41265+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1558587561292191.99889534760518; Wed, 22 May 2019 21:59:21 -0700 (PDT) Return-Path: X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by groups.io with SMTP; Wed, 22 May 2019 21:59:20 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 May 2019 21:59:19 -0700 X-ExtLoop1: 1 X-Received: from fieedk002.ccr.corp.intel.com ([10.239.157.133]) by fmsmga008.fm.intel.com with ESMTP; 22 May 2019 21:59:18 -0700 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Jordan Justen , Andrew Fish , Ray Ni Subject: [edk2-devel] [PATCH] EmulatorPkg: Fix bugs about BlockIo2 Date: Thu, 23 May 2019 12:59:04 +0800 Message-Id: <20190523045905.17208-1-zhiguang.liu@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,zhiguang.liu@intel.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1558587560; bh=/68xMeMW50DrQd2oqgAI0Hdle+6+uwd3HTEYC5/C4W4=; h=Cc:Date:From:Reply-To:Subject:To; b=rOP14YUCc+ybwuQZUBvwXxbGAXU4egZspEdmz1xvgxCf0WhYuJRJPplK+g4AuYRvTH1 raPhCPtkmQziJ2zZ+L+Hta1ixNJ2viC3R9LkDNJVXH77CiqG2RpYuI6jsf+kdvZUD9SOM anU3my1Bh3iQ+Donh0Zn4u79xJvQjp/3si4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D1760 Signal BlockIO2 callback event manually Add some checks before readfile/writefile function. Signed-off-by: Zhiguang Liu Cc: Jordan Justen Cc: Andrew Fish Cc: Ray Ni --- 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/EmuBlockI= oDxe/EmuBlockIo.c index 96424a82ae..b275d908c7 100644 --- a/EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.c +++ b/EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.c @@ -95,7 +95,11 @@ EmuBlockIo2ReadBlocksEx ( OldTpl =3D gBS->RaiseTPL (TPL_CALLBACK); =20 Status =3D Private->Io->ReadBlocks (Private->Io, MediaId, LBA, Token, Bu= fferSize, Buffer); - + if (Token !=3D NULL && Token->Event !=3D NULL) { + if (!EFI_ERROR (Status)) { + gBS->SignalEvent (Token->Event); + } + } gBS->RestoreTPL (OldTpl); return Status; } @@ -150,9 +154,12 @@ EmuBlockIo2WriteBlocksEx ( Private =3D EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This); =20 OldTpl =3D gBS->RaiseTPL (TPL_CALLBACK); - Status =3D Private->Io->WriteBlocks (Private->Io, MediaId, LBA, Token, B= ufferSize, Buffer); - + if (Token !=3D NULL && Token->Event !=3D 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/WinBl= ockIo.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 =3D WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This); - + if (!Private->Media->MediaPresent) { + return EFI_NO_MEDIA; + } + if (Private->Media->MediaId !=3D MediaId) { + return EFI_MEDIA_CHANGED; + } + if ((UINTN) Buffer % Private->Media->IoAlign !=3D 0) { + return EFI_INVALID_PARAMETER; + } + if ((BufferSize % Private->BlockSize) !=3D 0) { + return EFI_BAD_BUFFER_SIZE; + } + LastBlock =3D 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 =3D WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This); - + if (!Private->Media->MediaPresent) { + return EFI_NO_MEDIA; + } + if (Private->Media->MediaId !=3D MediaId) { + return EFI_MEDIA_CHANGED; + } + if ((UINTN) Buffer % Private->Media->IoAlign !=3D 0) { + return EFI_INVALID_PARAMETER; + } + if ((BufferSize % Private->BlockSize) !=3D 0) { + return EFI_BAD_BUFFER_SIZE; + } + LastBlock =3D 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 =3D WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This); =20 if (Private->NtHandle !=3D INVALID_HANDLE_VALUE) { CloseHandle (Private->NtHandle); Private->NtHandle =3D INVALID_HANDLE_VALUE; } - + WinNtBlockIoCreateMapping (This, Private->Media); return EFI_SUCCESS; } =20 --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#41265): https://edk2.groups.io/g/devel/message/41265 Mute This Topic: https://groups.io/mt/31728072/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-