summaryrefslogtreecommitdiffstats
path: root/EmulatorPkg
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2018-08-23 17:38:42 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2018-08-27 15:21:02 +0800
commit3da7b0639f618a3809c2e20e072d97b30aeb0d4b (patch)
treee2e522f9f88982e26054059797531c599cff5d1b /EmulatorPkg
parent41fd56be34cdec9a6ed729cbadb25a9097c675c1 (diff)
downloadedk2-3da7b0639f618a3809c2e20e072d97b30aeb0d4b.tar.gz
edk2-3da7b0639f618a3809c2e20e072d97b30aeb0d4b.tar.bz2
edk2-3da7b0639f618a3809c2e20e072d97b30aeb0d4b.zip
EmulatorPkg/EmuFileSystem: Fix a bug that causes Close() assertion
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1117 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> Reviewed-by: Hao Wu <hao.a.wu@intel.com> Cc: Andrew Fish <afish@apple.com>
Diffstat (limited to 'EmulatorPkg')
-rw-r--r--EmulatorPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.c33
1 files 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;