From: qwang12 Date: Mon, 12 Mar 2007 06:26:10 +0000 (+0000) Subject: Add a lock to protect the critical region in UEFI Boot Service API: Exit() and Unload... X-Git-Tag: edk2-stable201903~23445 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=d126eaecb080a9e4d6fd697f1b6f5380a5248420 Add a lock to protect the critical region in UEFI Boot Service API: Exit() and UnloadImage from re-entrance from different TPL level. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2437 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/EdkModulePkg/Core/Dxe/Image/Image.c b/EdkModulePkg/Core/Dxe/Image/Image.c index e9541f7f9d..f1b2c7a105 100644 --- a/EdkModulePkg/Core/Dxe/Image/Image.c +++ b/EdkModulePkg/Core/Dxe/Image/Image.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2006, Intel Corporation +Copyright (c) 2006 - 2007, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -24,6 +24,9 @@ Abstract: // Module Globals // +EFI_LOCK mBsExitLock = EFI_INITIALIZE_LOCK_VARIABLE(EFI_TPL_NOTIFY); +EFI_LOCK mBsUnloadImageLock = EFI_INITIALIZE_LOCK_VARIABLE(EFI_TPL_NOTIFY); + LOADED_IMAGE_PRIVATE_DATA *mCurrentImage = NULL; LOAD_PE32_IMAGE_PRIVATE_DATA mLoadPe32PrivateData = { @@ -1219,9 +1222,12 @@ Returns: { LOADED_IMAGE_PRIVATE_DATA *Image; + EfiAcquireLock (&mBsExitLock); + Image = CoreLoadedImageInfo (ImageHandle); if (Image == NULL_HANDLE) { - return EFI_INVALID_PARAMETER; + Status = EFI_INVALID_PARAMETER; + goto Done; } if (!Image->Started) { @@ -1229,7 +1235,8 @@ Returns: // The image has not been started so just free its resources // CoreUnloadAndCloseImage (Image, TRUE); - return EFI_SUCCESS; + Status = EFI_SUCCESS; + goto Done; } // @@ -1237,7 +1244,8 @@ Returns: // if (Image != mCurrentImage) { DEBUG ((EFI_D_LOAD|EFI_D_ERROR, "Exit: Image is not exitable image\n")); - return EFI_INVALID_PARAMETER; + Status = EFI_INVALID_PARAMETER; + goto Done; } // @@ -1252,11 +1260,13 @@ Returns: Image->ExitDataSize = ExitDataSize; Image->ExitData = CoreAllocateBootServicesPool (Image->ExitDataSize); if (Image->ExitData == NULL) { - return EFI_OUT_OF_RESOURCES; + Status = EFI_OUT_OF_RESOURCES; + goto Done; } CopyMem (Image->ExitData, ExitData, Image->ExitDataSize); } + EfiReleaseLock (&mBsExitLock); // // return to StartImage // @@ -1266,7 +1276,10 @@ Returns: // If we return from LongJump, then it is an error // ASSERT (FALSE); - return EFI_ACCESS_DENIED; + Status = EFI_ACCESS_DENIED; +Done: + EfiReleaseLock (&mBsExitLock); + return Status; } @@ -1297,12 +1310,15 @@ Returns: EFI_STATUS Status; LOADED_IMAGE_PRIVATE_DATA *Image; + EfiAcquireLock (&mBsUnloadImageLock); + Image = CoreLoadedImageInfo (ImageHandle); if (Image == NULL ) { // // The image handle is not valid // - return EFI_INVALID_PARAMETER; + Status = EFI_INVALID_PARAMETER; + goto Done; } if (Image->Started) { @@ -1329,6 +1345,8 @@ Returns: CoreUnloadAndCloseImage (Image, TRUE); } +Done: + EfiReleaseLock (&mBsUnloadImageLock); return Status; }