public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Hao Wu <hao.a.wu@intel.com>, Andrew Fish <afish@apple.com>
Subject: [PATCH v2 11/12] EmulatorPkg/EmuFileSystem: Fix a bug that causes Close() assertion
Date: Thu, 23 Aug 2018 17:56:19 +0800	[thread overview]
Message-ID: <20180823095620.280996-12-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20180823095620.280996-1-ruiyu.ni@intel.com>

The root cause is when a file is opened through File.Open(), the
private data for the File is not allocated, so when later
when File.Close() is called, the signature check in CR() causes
the assertion.

The private data for the File is allocated properly when the file
is opened from FS.OpenVolume().

The patch also fixes a minor issue that wrongly assigns
revision number to File.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Andrew Fish <afish@apple.com>
---
 .../EmuSimpleFileSystemDxe/EmuSimpleFileSystem.c   | 33 +++++++++++++++++++---
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/EmulatorPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.c b/EmulatorPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.c
index 4709f7a46f..b5e19bb840 100644
--- a/EmulatorPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.c
+++ b/EmulatorPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.c
@@ -4,7 +4,7 @@
   environment variables. The variables must be visible to the Microsoft*
   Developer Studio for them to work.
 
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
 Portions copyright (c) 2011, Apple Inc. All rights reserved.
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
@@ -51,7 +51,10 @@ EmuSimpleFileSystemOpen (
   IN  UINT64              Attributes
   )
 {
+  EFI_STATUS                        Status;
+  EFI_TPL                           OldTpl;
   EMU_EFI_FILE_PRIVATE              *PrivateFile;
+  EMU_EFI_FILE_PRIVATE              *NewPrivateFile;
 
   //
   // Check for obvious invalid parameters.
@@ -81,9 +84,29 @@ EmuSimpleFileSystemOpen (
     return EFI_INVALID_PARAMETER;
   }
 
-  PrivateFile     = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+  PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+  NewPrivateFile = AllocateCopyPool (sizeof (EMU_EFI_FILE_PRIVATE), PrivateFile);
+  if (NewPrivateFile == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    goto Done;
+  }
+
 
-  return PrivateFile->Io->Open (PrivateFile->Io, NewHandle, FileName, OpenMode, Attributes);
+  Status = PrivateFile->Io->Open (PrivateFile->Io, &NewPrivateFile->Io, FileName, OpenMode, Attributes);
+  if (!EFI_ERROR (Status)) {
+    *NewHandle = &NewPrivateFile->EfiFile;
+  } else {
+    *NewHandle = NULL;
+    FreePool (NewPrivateFile);
+  }
+
+Done:
+  gBS->RestoreTPL (OldTpl);
+
+  return Status;
 }
 
 
@@ -508,7 +531,9 @@ EmuSimpleFileSystemOpenVolume (
   PrivateFile->Signature            = EMU_EFI_FILE_PRIVATE_SIGNATURE;
   PrivateFile->IoThunk              = Private->IoThunk;
   PrivateFile->SimpleFileSystem     = This;
-  PrivateFile->EfiFile.Revision     = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
+
+  ZeroMem (&PrivateFile->EfiFile, sizeof (PrivateFile->EfiFile));
+  PrivateFile->EfiFile.Revision     = EFI_FILE_PROTOCOL_REVISION;
   PrivateFile->EfiFile.Open         = EmuSimpleFileSystemOpen;
   PrivateFile->EfiFile.Close        = EmuSimpleFileSystemClose;
   PrivateFile->EfiFile.Delete       = EmuSimpleFileSystemDelete;
-- 
2.16.1.windows.1



  parent reply	other threads:[~2018-08-23  9:55 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-23  9:56 [PATCH v2 00/12] Add WinHost support in EmulatorPkg Ruiyu Ni
2018-08-23  9:56 ` [PATCH v2 01/12] EmulatorPkg/ThunkProtocolList: Fix VS build failure Ruiyu Ni
2018-08-23  9:56 ` [PATCH v2 02/12] EmulatorPkg/Win: Add Windows host support Ruiyu Ni
2018-08-23  9:56 ` [PATCH v2 03/12] EmulatorPkg/Win: Enable source level debugging Ruiyu Ni
2018-08-23  9:56 ` [PATCH v2 04/12] EmulatorPkg/Win: Enable native OS console as firmware console Ruiyu Ni
2018-08-23  9:56 ` [PATCH v2 05/12] EmulatorPkg/Win: Add input/output support Ruiyu Ni
2018-08-23  9:56 ` [PATCH v2 06/12] EmulatorPkg/Win: Add timer and interrupt support Ruiyu Ni
2018-08-23  9:56 ` [PATCH v2 07/12] EmulatorPkg/Win: Add RTC support Ruiyu Ni
2018-08-23  9:56 ` [PATCH v2 08/12] EmulatorPkg/Win: Add SimpleFileSystem support Ruiyu Ni
2018-08-23  9:56 ` [PATCH v2 09/12] EmulatorPkg/Win: Add BlockIo support Ruiyu Ni
2018-08-23  9:56 ` [PATCH v2 10/12] EmulatorPkg/PlatformBds: Signal EndOfDxe in platform BDS Ruiyu Ni
2018-08-23  9:56 ` Ruiyu Ni [this message]
2018-08-23  9:56 ` [PATCH v2 12/12] EmulatorPkg/DSC: Remove FS mapping to EDK Shell bin directory Ruiyu Ni
2018-08-23 15:24 ` [PATCH v2 00/12] Add WinHost support in EmulatorPkg Kinney, Michael D
2018-08-23 16:27   ` Ni, Ruiyu
2018-08-27  6:43 ` Wu, Hao A
2018-08-30  1:57 ` Shia, Cinnamon
2018-09-04  2:32   ` Ni, Ruiyu
2018-09-04  3:12     ` krishnaLee
2018-09-04 15:12       ` Kinney, Michael D
2018-09-04  6:17     ` Shia, Cinnamon

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=20180823095620.280996-12-ruiyu.ni@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