]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/DxeCore: Avoid assertion in CoreLocateProtocol
authorRuiyu Ni <ruiyu.ni@intel.com>
Fri, 22 Apr 2016 09:08:49 +0000 (17:08 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Mon, 25 Apr 2016 05:36:37 +0000 (13:36 +0800)
The patch uses CoreAcquireLockOrFail() instead of
CoreAcquireProtocolLock() in CoreLocateProtocol() to avoid
assertion when CoreLocateProtocol() is called with the
protocol database locked.

The issue was found when changing PcdDebugPrintErrorLevel to
enable page/pool allocation debug message.
Nt32 platform hangs immediately after DxeCore is loaded.
Investigation shows the following calling stacks:

DxeCore entry point (Install a certain protocol)
0 DxeCore::CoreInstallProtocolInterface  // Protocol DB is locked
1 DxeCore::AllocatePool
2 PeiDxeDebugLibReportStatusCode::DebugPrint
3 DxeReportStatusCodeLib::ReportStatusCodeEx // <-------------------|
4 DxeReportStatusCodeLib::InternalGetReportStatusCode               |
5 DxeCore::LocateProtocol(StatusCodeRuntimeProtocol)                |
                     // Assertion when locking Protocol DB 2nd time |
6 DxeCore::CoreAcquireProtocolLock                                  |
7 PeiDxeDebugLibReportStatusCode::DebugAssert                       |
8 DxeReportStatusCodeLib::ReportSatusCodeEx  // loop begins ---------

In frame #6 the assertion is triggered due to the protocol database
is already locked. #8 calls #4 and the loop begins.
After changing #6 to CoreAcquireLockOrFail(), the assertion is
avoided and the loop is broken.

With the fix, NT32 can boot to Shell even setting
PcdDebugPrintErrorLevel to 0xFFFFFFFF, with all error levels turned
on.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdeModulePkg/Core/Dxe/Hand/Locate.c

index d98b55ab9363b7951dd73fd1dad9d7592867d5df..d2b6da8d6b7d14fa523b9af710cd9341b8498d51 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Locate handle functions\r
 \r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -581,7 +581,10 @@ CoreLocateProtocol (
   //\r
   // Lock the protocol database\r
   //\r
-  CoreAcquireProtocolLock ();\r
+  Status = CoreAcquireLockOrFail (&gProtocolDatabaseLock);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
 \r
   mEfiLocateHandleRequest += 1;\r
 \r