]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
MdeModulePkg: Change OPTIONAL keyword usage style
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / BmLoadOption.c
index ff0c65a2efc6cba4f77eaff354f3a7541bed6210..de9dde2d3d27e774bb340eb8469e1c1e97f3cbff 100644 (file)
@@ -1,15 +1,9 @@
 /** @file\r
   Load option library functions which relate with creating and processing load options.\r
 \r
-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
-(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2015-2018 Hewlett Packard Enterprise Development LP<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -250,13 +244,16 @@ structure.
     VariableAttributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;\r
   }\r
 \r
-  return gRT->SetVariable (\r
-                OptionName,\r
-                &gEfiGlobalVariableGuid,\r
-                VariableAttributes,\r
-                VariableSize,\r
-                Variable\r
-                );\r
+  Status = gRT->SetVariable (\r
+                  OptionName,\r
+                  &gEfiGlobalVariableGuid,\r
+                  VariableAttributes,\r
+                  VariableSize,\r
+                  Variable\r
+                  );\r
+  FreePool (Variable);\r
+\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -479,7 +476,7 @@ EfiBootManagerInitializeLoadOption (
   IN  UINT32                            Attributes,\r
   IN  CHAR16                            *Description,\r
   IN  EFI_DEVICE_PATH_PROTOCOL          *FilePath,\r
-  IN  UINT8                             *OptionalData,   OPTIONAL\r
+  IN  UINT8                             *OptionalData    OPTIONAL,\r
   IN  UINT32                            OptionalDataSize\r
   )\r
 {\r
@@ -1084,7 +1081,7 @@ EfiBootManagerGetLoadOptions (
 \r
       Status = EfiBootManagerVariableToLoadOption (OptionName, &Options[OptionIndex]);\r
       if (EFI_ERROR (Status)) {\r
-        DEBUG ((EFI_D_INFO, "[Bds] %s doesn't exist - Update ****Order variable to remove the reference!!", OptionName));\r
+        DEBUG ((DEBUG_INFO, "[Bds] %s doesn't exist - Update ****Order variable to remove the reference!!", OptionName));\r
         EfiBootManagerDeleteLoadOptionVariable (OptionNumber, LoadOptionType);\r
       } else {\r
         ASSERT (Options[OptionIndex].OptionNumber == OptionNumber);\r
@@ -1230,10 +1227,8 @@ BmIsLoadOptionPeHeaderValid (
       // Check PE32 or PE32+ magic, and machine type\r
       //\r
       OptionalHeader = (EFI_IMAGE_OPTIONAL_HEADER32 *) &PeHeader->Pe32.OptionalHeader;\r
-      if ((OptionalHeader->Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC ||\r
-           OptionalHeader->Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) &&\r
-          EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeHeader->Pe32.FileHeader.Machine)\r
-          ) {\r
+      if (OptionalHeader->Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC ||\r
+          OptionalHeader->Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
         //\r
         // Check the Subsystem:\r
         //   Driver#### must be of type BootServiceDriver or RuntimeDriver\r
@@ -1416,7 +1411,17 @@ EfiBootManagerProcessLoadOption (
                     );\r
     FreePool (FileBuffer);\r
 \r
-    if (!EFI_ERROR (Status)) {\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an ImageHandle was created\r
+      // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be started right now.\r
+      // If the caller doesn't have the option to defer the execution of an image, we should\r
+      // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak.\r
+      //\r
+      if (Status == EFI_SECURITY_VIOLATION) {\r
+        gBS->UnloadImage (ImageHandle);\r
+      }\r
+    } else {\r
       Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&ImageInfo);\r
       ASSERT_EFI_ERROR (Status);\r
 \r