]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Core/Dxe/Image/Image.c
Change the EfiAquireLock with RaiseTPL as the call to Boot Service UnloadImage can...
[mirror_edk2.git] / EdkModulePkg / Core / Dxe / Image / Image.c
index e9541f7f9d3490ef8dc929d742f43d8ca1b1c611..3696400072e6f6be71090466699a6ef877228256 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2006, Intel Corporation\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
 All rights reserved. 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
@@ -1218,10 +1218,18 @@ Returns:
 --*/\r
 {\r
   LOADED_IMAGE_PRIVATE_DATA  *Image;\r
+  EFI_TPL                    OldTpl;\r
 \r
+  //\r
+  // Prevent possible reentrance to this function\r
+  // for the same ImageHandle\r
+  // \r
+  OldTpl = CoreRaiseTpl (EFI_TPL_NOTIFY); \r
\r
   Image = CoreLoadedImageInfo (ImageHandle);\r
   if (Image == NULL_HANDLE) {\r
-    return EFI_INVALID_PARAMETER;\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
   }\r
 \r
   if (!Image->Started) {\r
@@ -1229,7 +1237,8 @@ Returns:
     // The image has not been started so just free its resources\r
     //\r
     CoreUnloadAndCloseImage (Image, TRUE);\r
-    return EFI_SUCCESS;\r
+    Status = EFI_SUCCESS;\r
+    goto Done;\r
   }\r
 \r
   //\r
@@ -1237,7 +1246,8 @@ Returns:
   //\r
   if (Image != mCurrentImage) {\r
     DEBUG ((EFI_D_LOAD|EFI_D_ERROR, "Exit: Image is not exitable image\n"));\r
-    return EFI_INVALID_PARAMETER;\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
   }\r
 \r
   //\r
@@ -1252,11 +1262,13 @@ Returns:
     Image->ExitDataSize = ExitDataSize;\r
     Image->ExitData = CoreAllocateBootServicesPool (Image->ExitDataSize);\r
     if (Image->ExitData == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto Done;\r
     }\r
     CopyMem (Image->ExitData, ExitData, Image->ExitDataSize);\r
   }\r
 \r
+  CoreRestoreTpl (OldTpl);\r
   //\r
   // return to StartImage\r
   //\r
@@ -1266,7 +1278,10 @@ Returns:
   // If we return from LongJump, then it is an error\r
   //\r
   ASSERT (FALSE);\r
-  return EFI_ACCESS_DENIED;\r
+  Status = EFI_ACCESS_DENIED;\r
+Done:\r
+  CoreRestoreTpl (OldTpl);\r
+  return Status;\r
 }\r
 \r
 \r
@@ -1296,13 +1311,21 @@ Returns:
 {\r
   EFI_STATUS                 Status;\r
   LOADED_IMAGE_PRIVATE_DATA  *Image;\r
+  EFI_TPL                    OldTpl;\r
 \r
+  //\r
+  // Prevent possible reentrance to this function\r
+  // for the same ImageHandle\r
+  // \r
+  OldTpl = CoreRaiseTpl (EFI_TPL_NOTIFY);\r
\r
   Image = CoreLoadedImageInfo (ImageHandle);\r
   if (Image == NULL ) {\r
     //\r
     // The image handle is not valid\r
     //\r
-    return EFI_INVALID_PARAMETER;\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
   }\r
 \r
   if (Image->Started) {\r
@@ -1329,6 +1352,8 @@ Returns:
     CoreUnloadAndCloseImage (Image, TRUE);\r
   }\r
 \r
+Done:\r
+  CoreRestoreTpl (OldTpl);\r
   return Status;\r
 }\r
 \r