IN IMAGE_FILE_HANDLE *ImageFileHandle\r
);\r
\r
-//\r
-// Image processing worker functions\r
-//\r
-\r
-/**\r
- Search a handle to a device on a specified device path that supports a specified protocol,\r
- interface of that protocol on that handle is another output.\r
-\r
- @param Protocol The protocol to search for\r
- @param FilePath The specified device path\r
- @param Interface Interface of the protocol on the handle\r
- @param Handle The handle to the device on the specified device\r
- path that supports the protocol.\r
-\r
- @return Status code.\r
-\r
-**/\r
-EFI_STATUS\r
-CoreDevicePathToInterface (\r
- IN EFI_GUID *Protocol,\r
- IN EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
- OUT VOID **Interface,\r
- OUT EFI_HANDLE *Handle\r
- );\r
-\r
-\r
-/**\r
- Loads, relocates, and invokes a PE/COFF image\r
-\r
- @param BootPolicy If TRUE, indicates that the request originates\r
- from the boot manager, and that the boot\r
- manager is attempting to load FilePath as a\r
- boot selection.\r
- @param Pe32Handle The handle of PE32 image\r
- @param Image PE image to be loaded\r
- @param DstBuffer The buffer to store the image\r
- @param EntryPoint A pointer to the entry point\r
- @param Attribute The bit mask of attributes to set for the load\r
- PE image\r
-\r
- @retval EFI_SUCCESS The file was loaded, relocated, and invoked\r
- @retval EFI_OUT_OF_RESOURCES There was not enough memory to load and\r
- relocate the PE/COFF file\r
- @retval EFI_INVALID_PARAMETER Invalid parameter\r
- @retval EFI_BUFFER_TOO_SMALL Buffer for image is too small\r
-\r
-**/\r
-EFI_STATUS\r
-CoreLoadPeImage (\r
- IN BOOLEAN BootPolicy,\r
- IN VOID *Pe32Handle,\r
- IN LOADED_IMAGE_PRIVATE_DATA *Image,\r
- IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,\r
- OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,\r
- IN UINT32 Attribute\r
- );\r
-\r
-\r
-/**\r
- Get the image's private data from its handle.\r
-\r
- @param ImageHandle The image handle\r
-\r
- @return Return the image private data associated with ImageHandle.\r
-\r
-**/\r
-LOADED_IMAGE_PRIVATE_DATA *\r
-CoreLoadedImageInfo (\r
- IN EFI_HANDLE ImageHandle\r
- );\r
-\r
-\r
-/**\r
- Unloads EFI image from memory.\r
-\r
- @param Image EFI image\r
- @param FreePage Free allocated pages\r
-\r
-**/\r
-VOID\r
-CoreUnloadAndCloseImage (\r
- IN LOADED_IMAGE_PRIVATE_DATA *Image,\r
- IN BOOLEAN FreePage\r
- );\r
\r
\r
//\r
}\r
\r
\r
+/**\r
+ Unloads EFI image from memory.\r
+\r
+ @param Image EFI image\r
+ @param FreePage Free allocated pages\r
+\r
+**/\r
+VOID\r
+CoreUnloadAndCloseImage (\r
+ IN LOADED_IMAGE_PRIVATE_DATA *Image,\r
+ IN BOOLEAN FreePage\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINTN HandleCount;\r
+ EFI_HANDLE *HandleBuffer;\r
+ UINTN HandleIndex;\r
+ EFI_GUID **ProtocolGuidArray;\r
+ UINTN ArrayCount;\r
+ UINTN ProtocolIndex;\r
+ EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;\r
+ UINTN OpenInfoCount;\r
+ UINTN OpenInfoIndex;\r
+\r
+ if (Image->Ebc != NULL) {\r
+ //\r
+ // If EBC protocol exists we must perform cleanups for this image.\r
+ //\r
+ Image->Ebc->UnloadImage (Image->Ebc, Image->Handle);\r
+ }\r
+\r
+ //\r
+ // Unload image, free Image->ImageContext->ModHandle\r
+ //\r
+ PeCoffLoaderUnloadImage (&Image->ImageContext);\r
+\r
+ //\r
+ // Free our references to the image handle\r
+ //\r
+ if (Image->Handle != NULL) {\r
+\r
+ Status = CoreLocateHandleBuffer (\r
+ AllHandles,\r
+ NULL,\r
+ NULL,\r
+ &HandleCount,\r
+ &HandleBuffer\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
+ Status = CoreProtocolsPerHandle (\r
+ HandleBuffer[HandleIndex],\r
+ &ProtocolGuidArray,\r
+ &ArrayCount\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {\r
+ Status = CoreOpenProtocolInformation (\r
+ HandleBuffer[HandleIndex],\r
+ ProtocolGuidArray[ProtocolIndex],\r
+ &OpenInfo,\r
+ &OpenInfoCount\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
+ if (OpenInfo[OpenInfoIndex].AgentHandle == Image->Handle) {\r
+ Status = CoreCloseProtocol (\r
+ HandleBuffer[HandleIndex],\r
+ ProtocolGuidArray[ProtocolIndex],\r
+ Image->Handle,\r
+ OpenInfo[OpenInfoIndex].ControllerHandle\r
+ );\r
+ }\r
+ }\r
+ if (OpenInfo != NULL) {\r
+ CoreFreePool(OpenInfo);\r
+ }\r
+ }\r
+ }\r
+ if (ProtocolGuidArray != NULL) {\r
+ CoreFreePool(ProtocolGuidArray);\r
+ }\r
+ }\r
+ }\r
+ if (HandleBuffer != NULL) {\r
+ CoreFreePool (HandleBuffer);\r
+ }\r
+ }\r
+\r
+ CoreRemoveDebugImageInfoEntry (Image->Handle);\r
+\r
+ Status = CoreUninstallProtocolInterface (\r
+ Image->Handle,\r
+ &gEfiLoadedImageDevicePathProtocolGuid,\r
+ Image->LoadedImageDevicePath\r
+ );\r
+\r
+ Status = CoreUninstallProtocolInterface (\r
+ Image->Handle,\r
+ &gEfiLoadedImageProtocolGuid,\r
+ &Image->Info\r
+ );\r
+\r
+ }\r
+\r
+ if (Image->RuntimeData != NULL) {\r
+ if (Image->RuntimeData->Link.ForwardLink != NULL) {\r
+ //\r
+ // Remove the Image from the Runtime Image list as we are about to Free it!\r
+ //\r
+ RemoveEntryList (&Image->RuntimeData->Link);\r
+ }\r
+ CoreFreePool (Image->RuntimeData);\r
+ }\r
+\r
+ //\r
+ // Free the Image from memory\r
+ //\r
+ if ((Image->ImageBasePage != 0) && FreePage) {\r
+ CoreFreePages (Image->ImageBasePage, Image->NumberOfPages);\r
+ }\r
+\r
+ //\r
+ // Done with the Image structure\r
+ //\r
+ if (Image->Info.FilePath != NULL) {\r
+ CoreFreePool (Image->Info.FilePath);\r
+ }\r
+\r
+ if (Image->LoadedImageDevicePath != NULL) {\r
+ CoreFreePool (Image->LoadedImageDevicePath);\r
+ }\r
+\r
+ if (Image->FixupData != NULL) {\r
+ CoreFreePool (Image->FixupData);\r
+ }\r
+\r
+ CoreFreePool (Image);\r
+}\r
+\r
+\r
/**\r
Loads an EFI image into memory and returns a handle to the image.\r
\r
return Status;\r
}\r
\r
-\r
-\r
-/**\r
- Unloads EFI image from memory.\r
-\r
- @param Image EFI image\r
- @param FreePage Free allocated pages\r
-\r
-**/\r
-VOID\r
-CoreUnloadAndCloseImage (\r
- IN LOADED_IMAGE_PRIVATE_DATA *Image,\r
- IN BOOLEAN FreePage\r
- )\r
-{\r
- EFI_STATUS Status;\r
- UINTN HandleCount;\r
- EFI_HANDLE *HandleBuffer;\r
- UINTN HandleIndex;\r
- EFI_GUID **ProtocolGuidArray;\r
- UINTN ArrayCount;\r
- UINTN ProtocolIndex;\r
- EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;\r
- UINTN OpenInfoCount;\r
- UINTN OpenInfoIndex;\r
-\r
- if (Image->Ebc != NULL) {\r
- //\r
- // If EBC protocol exists we must perform cleanups for this image.\r
- //\r
- Image->Ebc->UnloadImage (Image->Ebc, Image->Handle);\r
- }\r
-\r
- //\r
- // Unload image, free Image->ImageContext->ModHandle\r
- //\r
- PeCoffLoaderUnloadImage (&Image->ImageContext);\r
-\r
- //\r
- // Free our references to the image handle\r
- //\r
- if (Image->Handle != NULL) {\r
-\r
- Status = CoreLocateHandleBuffer (\r
- AllHandles,\r
- NULL,\r
- NULL,\r
- &HandleCount,\r
- &HandleBuffer\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
- Status = CoreProtocolsPerHandle (\r
- HandleBuffer[HandleIndex],\r
- &ProtocolGuidArray,\r
- &ArrayCount\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {\r
- Status = CoreOpenProtocolInformation (\r
- HandleBuffer[HandleIndex],\r
- ProtocolGuidArray[ProtocolIndex],\r
- &OpenInfo,\r
- &OpenInfoCount\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
- if (OpenInfo[OpenInfoIndex].AgentHandle == Image->Handle) {\r
- Status = CoreCloseProtocol (\r
- HandleBuffer[HandleIndex],\r
- ProtocolGuidArray[ProtocolIndex],\r
- Image->Handle,\r
- OpenInfo[OpenInfoIndex].ControllerHandle\r
- );\r
- }\r
- }\r
- if (OpenInfo != NULL) {\r
- CoreFreePool(OpenInfo);\r
- }\r
- }\r
- }\r
- if (ProtocolGuidArray != NULL) {\r
- CoreFreePool(ProtocolGuidArray);\r
- }\r
- }\r
- }\r
- if (HandleBuffer != NULL) {\r
- CoreFreePool (HandleBuffer);\r
- }\r
- }\r
-\r
- CoreRemoveDebugImageInfoEntry (Image->Handle);\r
-\r
- Status = CoreUninstallProtocolInterface (\r
- Image->Handle,\r
- &gEfiLoadedImageDevicePathProtocolGuid,\r
- Image->LoadedImageDevicePath\r
- );\r
-\r
- Status = CoreUninstallProtocolInterface (\r
- Image->Handle,\r
- &gEfiLoadedImageProtocolGuid,\r
- &Image->Info\r
- );\r
-\r
- }\r
-\r
- if (Image->RuntimeData != NULL) {\r
- if (Image->RuntimeData->Link.ForwardLink != NULL) {\r
- //\r
- // Remove the Image from the Runtime Image list as we are about to Free it!\r
- //\r
- RemoveEntryList (&Image->RuntimeData->Link);\r
- }\r
- CoreFreePool (Image->RuntimeData);\r
- }\r
-\r
- //\r
- // Free the Image from memory\r
- //\r
- if ((Image->ImageBasePage != 0) && FreePage) {\r
- CoreFreePages (Image->ImageBasePage, Image->NumberOfPages);\r
- }\r
-\r
- //\r
- // Done with the Image structure\r
- //\r
- if (Image->Info.FilePath != NULL) {\r
- CoreFreePool (Image->Info.FilePath);\r
- }\r
-\r
- if (Image->LoadedImageDevicePath != NULL) {\r
- CoreFreePool (Image->LoadedImageDevicePath);\r
- }\r
-\r
- if (Image->FixupData != NULL) {\r
- CoreFreePool (Image->FixupData);\r
- }\r
-\r
- CoreFreePool (Image);\r
-}\r
-\r
-\r
-\r
-\r
/**\r
Terminates the currently loaded EFI image and returns control to boot services.\r
\r
\r
#include "DxeMain.h"\r
\r
+/**\r
+ Search a handle to a device on a specified device path that supports a specified protocol,\r
+ interface of that protocol on that handle is another output.\r
+\r
+ @param Protocol The protocol to search for\r
+ @param FilePath The specified device path\r
+ @param Interface Interface of the protocol on the handle\r
+ @param Handle The handle to the device on the specified device\r
+ path that supports the protocol.\r
+\r
+ @return Status code.\r
+\r
+**/\r
+EFI_STATUS\r
+CoreDevicePathToInterface (\r
+ IN EFI_GUID *Protocol,\r
+ IN EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
+ OUT VOID **Interface,\r
+ OUT EFI_HANDLE *Handle\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ Status = CoreLocateDevicePath (Protocol, FilePath, Handle);\r
+ if (!EFI_ERROR (Status)) {\r
+ Status = CoreHandleProtocol (*Handle, Protocol, Interface);\r
+ }\r
+ return Status;\r
+}\r
+\r
\r
/**\r
Opens a file for (simple) reading. The simple read abstraction\r
return EFI_SUCCESS;\r
}\r
\r
-\r
-/**\r
- Search a handle to a device on a specified device path that supports a specified protocol,\r
- interface of that protocol on that handle is another output.\r
-\r
- @param Protocol The protocol to search for\r
- @param FilePath The specified device path\r
- @param Interface Interface of the protocol on the handle\r
- @param Handle The handle to the device on the specified device\r
- path that supports the protocol.\r
-\r
- @return Status code.\r
-\r
-**/\r
-EFI_STATUS\r
-CoreDevicePathToInterface (\r
- IN EFI_GUID *Protocol,\r
- IN EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
- OUT VOID **Interface,\r
- OUT EFI_HANDLE *Handle\r
- )\r
-{\r
- EFI_STATUS Status;\r
-\r
- Status = CoreLocateDevicePath (Protocol, FilePath, Handle);\r
- if (!EFI_ERROR (Status)) {\r
- Status = CoreHandleProtocol (*Handle, Protocol, Interface);\r
- }\r
- return Status;\r
-}\r
-\r
-\r
/**\r
Helper function called as part of the code needed\r
to allocate the proper sized buffer for various\r