From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 40AEF21103DA7 for ; Thu, 23 Aug 2018 02:55:53 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Aug 2018 02:55:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,278,1531810800"; d="scan'208";a="85741617" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.8]) by orsmga002.jf.intel.com with ESMTP; 23 Aug 2018 02:55:51 -0700 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Hao Wu , Andrew Fish Date: Thu, 23 Aug 2018 17:56:19 +0800 Message-Id: <20180823095620.280996-12-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.16.1.windows.1 In-Reply-To: <20180823095620.280996-1-ruiyu.ni@intel.com> References: <20180823095620.280996-1-ruiyu.ni@intel.com> Subject: [PATCH v2 11/12] EmulatorPkg/EmuFileSystem: Fix a bug that causes Close() assertion X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Aug 2018 09:55:53 -0000 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 Cc: Hao Wu Cc: Andrew Fish --- .../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.
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
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