]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Image/Image.c
e7ad450db5d68f90d25a9fa1aff1f2416419ecdc
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Image / Image.c
1 /** @file
2 Core image handling services to load and unload PeImage.
3
4 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "DxeMain.h"
16 #include "Image.h"
17
18 //
19 // Module Globals
20 //
21 LOADED_IMAGE_PRIVATE_DATA *mCurrentImage = NULL;
22
23 LOAD_PE32_IMAGE_PRIVATE_DATA mLoadPe32PrivateData = {
24 LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE,
25 NULL,
26 {
27 CoreLoadImageEx,
28 CoreUnloadImageEx
29 }
30 };
31
32
33 //
34 // This code is needed to build the Image handle for the DXE Core
35 //
36 LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = {
37 LOADED_IMAGE_PRIVATE_DATA_SIGNATURE, // Signature
38 NULL, // Image handle
39 EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER, // Image type
40 TRUE, // If entrypoint has been called
41 NULL, // EntryPoint
42 {
43 EFI_LOADED_IMAGE_INFORMATION_REVISION, // Revision
44 NULL, // Parent handle
45 NULL, // System handle
46
47 NULL, // Device handle
48 NULL, // File path
49 NULL, // Reserved
50
51 0, // LoadOptionsSize
52 NULL, // LoadOptions
53
54 NULL, // ImageBase
55 0, // ImageSize
56 EfiBootServicesCode, // ImageCodeType
57 EfiBootServicesData // ImageDataType
58 },
59 (EFI_PHYSICAL_ADDRESS)0, // ImageBasePage
60 0, // NumberOfPages
61 NULL, // FixupData
62 0, // Tpl
63 EFI_SUCCESS, // Status
64 0, // ExitDataSize
65 NULL, // ExitData
66 NULL, // JumpBuffer
67 NULL, // JumpContext
68 0, // Machine
69 NULL, // Ebc
70 NULL, // RuntimeData
71 NULL // LoadedImageDevicePath
72 };
73 //
74 // The field is define for Loading modules at fixed address feature to tracker the PEI code
75 // memory range usage. It is a bit mapped array in which every bit indicates the correspoding memory page
76 // available or not.
77 //
78 GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mDxeCodeMemoryRangeUsageBitMap=NULL;
79
80 typedef struct {
81 UINT16 MachineType;
82 CHAR16 *MachineTypeName;
83 } MACHINE_TYPE_INFO;
84
85 //
86 // EBC machine is not listed in this table, because EBC is in the default supported scopes of other machine type.
87 //
88 GLOBAL_REMOVE_IF_UNREFERENCED MACHINE_TYPE_INFO mMachineTypeInfo[] = {
89 {EFI_IMAGE_MACHINE_IA32, L"IA32"},
90 {EFI_IMAGE_MACHINE_IA64, L"IA64"},
91 {EFI_IMAGE_MACHINE_X64, L"X64"},
92 {EFI_IMAGE_MACHINE_ARMTHUMB_MIXED, L"ARM"}
93 };
94
95 UINT16 mDxeCoreImageMachineType = 0;
96
97 /**
98 Return machine type name.
99
100 @param MachineType The machine type
101
102 @return machine type name
103 **/
104 CHAR16 *
105 GetMachineTypeName (
106 UINT16 MachineType
107 )
108 {
109 UINTN Index;
110
111 for (Index = 0; Index < sizeof(mMachineTypeInfo)/sizeof(mMachineTypeInfo[0]); Index++) {
112 if (mMachineTypeInfo[Index].MachineType == MachineType) {
113 return mMachineTypeInfo[Index].MachineTypeName;
114 }
115 }
116
117 return L"<Unknown>";
118 }
119
120 /**
121 Add the Image Services to EFI Boot Services Table and install the protocol
122 interfaces for this image.
123
124 @param HobStart The HOB to initialize
125
126 @return Status code.
127
128 **/
129 EFI_STATUS
130 CoreInitializeImageServices (
131 IN VOID *HobStart
132 )
133 {
134 EFI_STATUS Status;
135 LOADED_IMAGE_PRIVATE_DATA *Image;
136 EFI_PHYSICAL_ADDRESS DxeCoreImageBaseAddress;
137 UINT64 DxeCoreImageLength;
138 VOID *DxeCoreEntryPoint;
139 EFI_PEI_HOB_POINTERS DxeCoreHob;
140
141 //
142 // Searching for image hob
143 //
144 DxeCoreHob.Raw = HobStart;
145 while ((DxeCoreHob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, DxeCoreHob.Raw)) != NULL) {
146 if (CompareGuid (&DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.Name, &gEfiHobMemoryAllocModuleGuid)) {
147 //
148 // Find Dxe Core HOB
149 //
150 break;
151 }
152 DxeCoreHob.Raw = GET_NEXT_HOB (DxeCoreHob);
153 }
154 ASSERT (DxeCoreHob.Raw != NULL);
155
156 DxeCoreImageBaseAddress = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryBaseAddress;
157 DxeCoreImageLength = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryLength;
158 DxeCoreEntryPoint = (VOID *) (UINTN) DxeCoreHob.MemoryAllocationModule->EntryPoint;
159 gDxeCoreFileName = &DxeCoreHob.MemoryAllocationModule->ModuleName;
160
161 //
162 // Initialize the fields for an internal driver
163 //
164 Image = &mCorePrivateImage;
165
166 Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)DxeCoreEntryPoint;
167 Image->ImageBasePage = DxeCoreImageBaseAddress;
168 Image->NumberOfPages = (UINTN)(EFI_SIZE_TO_PAGES((UINTN)(DxeCoreImageLength)));
169 Image->Tpl = gEfiCurrentTpl;
170 Image->Info.SystemTable = gDxeCoreST;
171 Image->Info.ImageBase = (VOID *)(UINTN)DxeCoreImageBaseAddress;
172 Image->Info.ImageSize = DxeCoreImageLength;
173
174 //
175 // Install the protocol interfaces for this image
176 //
177 Status = CoreInstallProtocolInterface (
178 &Image->Handle,
179 &gEfiLoadedImageProtocolGuid,
180 EFI_NATIVE_INTERFACE,
181 &Image->Info
182 );
183 ASSERT_EFI_ERROR (Status);
184
185 mCurrentImage = Image;
186
187 //
188 // Fill in DXE globals
189 //
190 mDxeCoreImageMachineType = PeCoffLoaderGetMachineType (Image->Info.ImageBase);
191 gDxeCoreImageHandle = Image->Handle;
192 gDxeCoreLoadedImage = &Image->Info;
193
194 if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {
195 //
196 // Export DXE Core PE Loader functionality for backward compatibility.
197 //
198 Status = CoreInstallProtocolInterface (
199 &mLoadPe32PrivateData.Handle,
200 &gEfiLoadPeImageProtocolGuid,
201 EFI_NATIVE_INTERFACE,
202 &mLoadPe32PrivateData.Pe32Image
203 );
204 }
205
206 return Status;
207 }
208
209 /**
210 Read image file (specified by UserHandle) into user specified buffer with specified offset
211 and length.
212
213 @param UserHandle Image file handle
214 @param Offset Offset to the source file
215 @param ReadSize For input, pointer of size to read; For output,
216 pointer of size actually read.
217 @param Buffer Buffer to write into
218
219 @retval EFI_SUCCESS Successfully read the specified part of file
220 into buffer.
221
222 **/
223 EFI_STATUS
224 EFIAPI
225 CoreReadImageFile (
226 IN VOID *UserHandle,
227 IN UINTN Offset,
228 IN OUT UINTN *ReadSize,
229 OUT VOID *Buffer
230 )
231 {
232 UINTN EndPosition;
233 IMAGE_FILE_HANDLE *FHand;
234
235 if (UserHandle == NULL || ReadSize == NULL || Buffer == NULL) {
236 return EFI_INVALID_PARAMETER;
237 }
238
239 if (MAX_ADDRESS - Offset < *ReadSize) {
240 return EFI_INVALID_PARAMETER;
241 }
242
243 FHand = (IMAGE_FILE_HANDLE *)UserHandle;
244 ASSERT (FHand->Signature == IMAGE_FILE_HANDLE_SIGNATURE);
245
246 //
247 // Move data from our local copy of the file
248 //
249 EndPosition = Offset + *ReadSize;
250 if (EndPosition > FHand->SourceSize) {
251 *ReadSize = (UINT32)(FHand->SourceSize - Offset);
252 }
253 if (Offset >= FHand->SourceSize) {
254 *ReadSize = 0;
255 }
256
257 CopyMem (Buffer, (CHAR8 *)FHand->Source + Offset, *ReadSize);
258 return EFI_SUCCESS;
259 }
260 /**
261 To check memory usage bit map arry to figure out if the memory range the image will be loaded in is available or not. If
262 memory range is avaliable, the function will mark the correponding bits to 1 which indicates the memory range is used.
263 The function is only invoked when load modules at fixed address feature is enabled.
264
265 @param ImageBase The base addres the image will be loaded at.
266 @param ImageSize The size of the image
267
268 @retval EFI_SUCCESS The memory range the image will be loaded in is available
269 @retval EFI_NOT_FOUND The memory range the image will be loaded in is not available
270 **/
271 EFI_STATUS
272 CheckAndMarkFixLoadingMemoryUsageBitMap (
273 IN EFI_PHYSICAL_ADDRESS ImageBase,
274 IN UINTN ImageSize
275 )
276 {
277 UINT32 DxeCodePageNumber;
278 UINT64 DxeCodeSize;
279 EFI_PHYSICAL_ADDRESS DxeCodeBase;
280 UINTN BaseOffsetPageNumber;
281 UINTN TopOffsetPageNumber;
282 UINTN Index;
283 //
284 // The DXE code range includes RuntimeCodePage range and Boot time code range.
285 //
286 DxeCodePageNumber = PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber);
287 DxeCodePageNumber += PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber);
288 DxeCodeSize = EFI_PAGES_TO_SIZE(DxeCodePageNumber);
289 DxeCodeBase = gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress - DxeCodeSize;
290
291 //
292 // If the memory usage bit map is not initialized, do it. Every bit in the array
293 // indicate the status of the corresponding memory page, available or not
294 //
295 if (mDxeCodeMemoryRangeUsageBitMap == NULL) {
296 mDxeCodeMemoryRangeUsageBitMap = AllocateZeroPool(((DxeCodePageNumber/64) + 1)*sizeof(UINT64));
297 }
298 //
299 // If the Dxe code memory range is not allocated or the bit map array allocation failed, return EFI_NOT_FOUND
300 //
301 if (!gLoadFixedAddressCodeMemoryReady || mDxeCodeMemoryRangeUsageBitMap == NULL) {
302 return EFI_NOT_FOUND;
303 }
304 //
305 // Test the memory range for loading the image in the DXE code range.
306 //
307 if (gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress < ImageBase + ImageSize ||
308 DxeCodeBase > ImageBase) {
309 return EFI_NOT_FOUND;
310 }
311 //
312 // Test if the memory is avalaible or not.
313 //
314 BaseOffsetPageNumber = (UINTN)EFI_SIZE_TO_PAGES((UINT32)(ImageBase - DxeCodeBase));
315 TopOffsetPageNumber = (UINTN)EFI_SIZE_TO_PAGES((UINT32)(ImageBase + ImageSize - DxeCodeBase));
316 for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) {
317 if ((mDxeCodeMemoryRangeUsageBitMap[Index / 64] & LShiftU64(1, (Index % 64))) != 0) {
318 //
319 // This page is already used.
320 //
321 return EFI_NOT_FOUND;
322 }
323 }
324
325 //
326 // Being here means the memory range is available. So mark the bits for the memory range
327 //
328 for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) {
329 mDxeCodeMemoryRangeUsageBitMap[Index / 64] |= LShiftU64(1, (Index % 64));
330 }
331 return EFI_SUCCESS;
332 }
333 /**
334
335 Get the fixed loadding address from image header assigned by build tool. This function only be called
336 when Loading module at Fixed address feature enabled.
337
338 @param ImageContext Pointer to the image context structure that describes the PE/COFF
339 image that needs to be examined by this function.
340 @retval EFI_SUCCESS An fixed loading address is assigned to this image by build tools .
341 @retval EFI_NOT_FOUND The image has no assigned fixed loadding address.
342
343 **/
344 EFI_STATUS
345 GetPeCoffImageFixLoadingAssignedAddress(
346 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
347 )
348 {
349 UINTN SectionHeaderOffset;
350 EFI_STATUS Status;
351 EFI_IMAGE_SECTION_HEADER SectionHeader;
352 EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
353 UINT16 Index;
354 UINTN Size;
355 UINT16 NumberOfSections;
356 IMAGE_FILE_HANDLE *Handle;
357 UINT64 ValueInSectionHeader;
358
359
360 Status = EFI_NOT_FOUND;
361
362 //
363 // Get PeHeader pointer
364 //
365 Handle = (IMAGE_FILE_HANDLE*)ImageContext->Handle;
366 ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )Handle->Source + ImageContext->PeCoffHeaderOffset);
367 SectionHeaderOffset = (UINTN)(
368 ImageContext->PeCoffHeaderOffset +
369 sizeof (UINT32) +
370 sizeof (EFI_IMAGE_FILE_HEADER) +
371 ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
372 );
373 NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
374
375 //
376 // Get base address from the first section header that doesn't point to code section.
377 //
378 for (Index = 0; Index < NumberOfSections; Index++) {
379 //
380 // Read section header from file
381 //
382 Size = sizeof (EFI_IMAGE_SECTION_HEADER);
383 Status = ImageContext->ImageRead (
384 ImageContext->Handle,
385 SectionHeaderOffset,
386 &Size,
387 &SectionHeader
388 );
389 if (EFI_ERROR (Status)) {
390 return Status;
391 }
392 if (Size != sizeof (EFI_IMAGE_SECTION_HEADER)) {
393 return EFI_NOT_FOUND;
394 }
395
396 Status = EFI_NOT_FOUND;
397
398 if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
399 //
400 // Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields in the first section header
401 // that doesn't point to code section in image header, as well as ImageBase field of image header. And there is an
402 // assumption that when the feature is enabled, if a module is assigned a loading address by tools, PointerToRelocations
403 // & PointerToLineNumbers fields should NOT be Zero, or else, these 2 fileds should be set to Zero
404 //
405 ValueInSectionHeader = ReadUnaligned64((UINT64*)&SectionHeader.PointerToRelocations);
406 if (ValueInSectionHeader != 0) {
407 //
408 // When the feature is configured as load module at fixed absolute address, the ImageAddress field of ImageContext
409 // hold the spcified address. If the feature is configured as load module at fixed offset, ImageAddress hold an offset
410 // relative to top address
411 //
412 if ((INT64)PcdGet64(PcdLoadModuleAtFixAddressEnable) < 0) {
413 ImageContext->ImageAddress = gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress + (INT64)(INTN)ImageContext->ImageAddress;
414 }
415 //
416 // Check if the memory range is avaliable.
417 //
418 Status = CheckAndMarkFixLoadingMemoryUsageBitMap (ImageContext->ImageAddress, (UINTN)(ImageContext->ImageSize + ImageContext->SectionAlignment));
419 }
420 break;
421 }
422 SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
423 }
424 DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address 0x%11p. Status = %r \n", (VOID *)(UINTN)(ImageContext->ImageAddress), Status));
425 return Status;
426 }
427 /**
428 Loads, relocates, and invokes a PE/COFF image
429
430 @param BootPolicy If TRUE, indicates that the request originates
431 from the boot manager, and that the boot
432 manager is attempting to load FilePath as a
433 boot selection.
434 @param Pe32Handle The handle of PE32 image
435 @param Image PE image to be loaded
436 @param DstBuffer The buffer to store the image
437 @param EntryPoint A pointer to the entry point
438 @param Attribute The bit mask of attributes to set for the load
439 PE image
440
441 @retval EFI_SUCCESS The file was loaded, relocated, and invoked
442 @retval EFI_OUT_OF_RESOURCES There was not enough memory to load and
443 relocate the PE/COFF file
444 @retval EFI_INVALID_PARAMETER Invalid parameter
445 @retval EFI_BUFFER_TOO_SMALL Buffer for image is too small
446
447 **/
448 EFI_STATUS
449 CoreLoadPeImage (
450 IN BOOLEAN BootPolicy,
451 IN VOID *Pe32Handle,
452 IN LOADED_IMAGE_PRIVATE_DATA *Image,
453 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
454 OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
455 IN UINT32 Attribute
456 )
457 {
458 EFI_STATUS Status;
459 BOOLEAN DstBufAlocated;
460 UINTN Size;
461
462 ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext));
463
464 Image->ImageContext.Handle = Pe32Handle;
465 Image->ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE)CoreReadImageFile;
466
467 //
468 // Get information about the image being loaded
469 //
470 Status = PeCoffLoaderGetImageInfo (&Image->ImageContext);
471 if (EFI_ERROR (Status)) {
472 return Status;
473 }
474
475 if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->ImageContext.Machine)) {
476 if (!EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED (Image->ImageContext.Machine)) {
477 //
478 // The PE/COFF loader can support loading image types that can be executed.
479 // If we loaded an image type that we can not execute return EFI_UNSUPORTED.
480 //
481 DEBUG ((EFI_D_ERROR, "Image type %s can't be loaded ", GetMachineTypeName(Image->ImageContext.Machine)));
482 DEBUG ((EFI_D_ERROR, "on %s UEFI system.\n", GetMachineTypeName(mDxeCoreImageMachineType)));
483 return EFI_UNSUPPORTED;
484 }
485 }
486
487 //
488 // Set EFI memory type based on ImageType
489 //
490 switch (Image->ImageContext.ImageType) {
491 case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:
492 Image->ImageContext.ImageCodeMemoryType = EfiLoaderCode;
493 Image->ImageContext.ImageDataMemoryType = EfiLoaderData;
494 break;
495 case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
496 Image->ImageContext.ImageCodeMemoryType = EfiBootServicesCode;
497 Image->ImageContext.ImageDataMemoryType = EfiBootServicesData;
498 break;
499 case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
500 case EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER:
501 Image->ImageContext.ImageCodeMemoryType = EfiRuntimeServicesCode;
502 Image->ImageContext.ImageDataMemoryType = EfiRuntimeServicesData;
503 break;
504 default:
505 Image->ImageContext.ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM;
506 return EFI_UNSUPPORTED;
507 }
508
509 //
510 // Allocate memory of the correct memory type aligned on the required image boundry
511 //
512 DstBufAlocated = FALSE;
513 if (DstBuffer == 0) {
514 //
515 // Allocate Destination Buffer as caller did not pass it in
516 //
517
518 if (Image->ImageContext.SectionAlignment > EFI_PAGE_SIZE) {
519 Size = (UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment;
520 } else {
521 Size = (UINTN)Image->ImageContext.ImageSize;
522 }
523
524 Image->NumberOfPages = EFI_SIZE_TO_PAGES (Size);
525
526 //
527 // If the image relocations have not been stripped, then load at any address.
528 // Otherwise load at the address at which it was linked.
529 //
530 // Memory below 1MB should be treated reserved for CSM and there should be
531 // no modules whose preferred load addresses are below 1MB.
532 //
533 Status = EFI_OUT_OF_RESOURCES;
534 //
535 // If Loading Module At Fixed Address feature is enabled, the module should be loaded to
536 // a specified address.
537 //
538 if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 ) {
539 Status = GetPeCoffImageFixLoadingAssignedAddress (&(Image->ImageContext));
540
541 if (EFI_ERROR (Status)) {
542 //
543 // If the code memory is not ready, invoke CoreAllocatePage with AllocateAnyPages to load the driver.
544 //
545 DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED ERROR: Loading module at fixed address failed since specified memory is not available.\n"));
546
547 Status = CoreAllocatePages (
548 AllocateAnyPages,
549 (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType),
550 Image->NumberOfPages,
551 &Image->ImageContext.ImageAddress
552 );
553 }
554 } else {
555 if (Image->ImageContext.ImageAddress >= 0x100000 || Image->ImageContext.RelocationsStripped) {
556 Status = CoreAllocatePages (
557 AllocateAddress,
558 (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType),
559 Image->NumberOfPages,
560 &Image->ImageContext.ImageAddress
561 );
562 }
563 if (EFI_ERROR (Status) && !Image->ImageContext.RelocationsStripped) {
564 Status = CoreAllocatePages (
565 AllocateAnyPages,
566 (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType),
567 Image->NumberOfPages,
568 &Image->ImageContext.ImageAddress
569 );
570 }
571 }
572 if (EFI_ERROR (Status)) {
573 return Status;
574 }
575 DstBufAlocated = TRUE;
576 } else {
577 //
578 // Caller provided the destination buffer
579 //
580
581 if (Image->ImageContext.RelocationsStripped && (Image->ImageContext.ImageAddress != DstBuffer)) {
582 //
583 // If the image relocations were stripped, and the caller provided a
584 // destination buffer address that does not match the address that the
585 // image is linked at, then the image cannot be loaded.
586 //
587 return EFI_INVALID_PARAMETER;
588 }
589
590 if (Image->NumberOfPages != 0 &&
591 Image->NumberOfPages <
592 (EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment))) {
593 Image->NumberOfPages = EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment);
594 return EFI_BUFFER_TOO_SMALL;
595 }
596
597 Image->NumberOfPages = EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment);
598 Image->ImageContext.ImageAddress = DstBuffer;
599 }
600
601 Image->ImageBasePage = Image->ImageContext.ImageAddress;
602 if (!Image->ImageContext.IsTeImage) {
603 Image->ImageContext.ImageAddress =
604 (Image->ImageContext.ImageAddress + Image->ImageContext.SectionAlignment - 1) &
605 ~((UINTN)Image->ImageContext.SectionAlignment - 1);
606 }
607
608 //
609 // Load the image from the file into the allocated memory
610 //
611 Status = PeCoffLoaderLoadImage (&Image->ImageContext);
612 if (EFI_ERROR (Status)) {
613 goto Done;
614 }
615
616 //
617 // If this is a Runtime Driver, then allocate memory for the FixupData that
618 // is used to relocate the image when SetVirtualAddressMap() is called. The
619 // relocation is done by the Runtime AP.
620 //
621 if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) != 0) {
622 if (Image->ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) {
623 Image->ImageContext.FixupData = AllocateRuntimePool ((UINTN)(Image->ImageContext.FixupDataSize));
624 if (Image->ImageContext.FixupData == NULL) {
625 Status = EFI_OUT_OF_RESOURCES;
626 goto Done;
627 }
628 }
629 }
630
631 //
632 // Relocate the image in memory
633 //
634 Status = PeCoffLoaderRelocateImage (&Image->ImageContext);
635 if (EFI_ERROR (Status)) {
636 goto Done;
637 }
638
639 //
640 // Flush the Instruction Cache
641 //
642 InvalidateInstructionCacheRange ((VOID *)(UINTN)Image->ImageContext.ImageAddress, (UINTN)Image->ImageContext.ImageSize);
643
644 //
645 // Copy the machine type from the context to the image private data. This
646 // is needed during image unload to know if we should call an EBC protocol
647 // to unload the image.
648 //
649 Image->Machine = Image->ImageContext.Machine;
650
651 //
652 // Get the image entry point. If it's an EBC image, then call into the
653 // interpreter to create a thunk for the entry point and use the returned
654 // value for the entry point.
655 //
656 Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)Image->ImageContext.EntryPoint;
657 if (Image->ImageContext.Machine == EFI_IMAGE_MACHINE_EBC) {
658 //
659 // Locate the EBC interpreter protocol
660 //
661 Status = CoreLocateProtocol (&gEfiEbcProtocolGuid, NULL, (VOID **)&Image->Ebc);
662 if (EFI_ERROR(Status) || Image->Ebc == NULL) {
663 DEBUG ((DEBUG_LOAD | DEBUG_ERROR, "CoreLoadPeImage: There is no EBC interpreter for an EBC image.\n"));
664 goto Done;
665 }
666
667 //
668 // Register a callback for flushing the instruction cache so that created
669 // thunks can be flushed.
670 //
671 Status = Image->Ebc->RegisterICacheFlush (Image->Ebc, (EBC_ICACHE_FLUSH)InvalidateInstructionCacheRange);
672 if (EFI_ERROR(Status)) {
673 goto Done;
674 }
675
676 //
677 // Create a thunk for the image's entry point. This will be the new
678 // entry point for the image.
679 //
680 Status = Image->Ebc->CreateThunk (
681 Image->Ebc,
682 Image->Handle,
683 (VOID *)(UINTN) Image->ImageContext.EntryPoint,
684 (VOID **) &Image->EntryPoint
685 );
686 if (EFI_ERROR(Status)) {
687 goto Done;
688 }
689 }
690
691 //
692 // Fill in the image information for the Loaded Image Protocol
693 //
694 Image->Type = Image->ImageContext.ImageType;
695 Image->Info.ImageBase = (VOID *)(UINTN)Image->ImageContext.ImageAddress;
696 Image->Info.ImageSize = Image->ImageContext.ImageSize;
697 Image->Info.ImageCodeType = (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType);
698 Image->Info.ImageDataType = (EFI_MEMORY_TYPE) (Image->ImageContext.ImageDataMemoryType);
699 if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) != 0) {
700 if (Image->ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) {
701 //
702 // Make a list off all the RT images so we can let the RT AP know about them.
703 //
704 Image->RuntimeData = AllocateRuntimePool (sizeof(EFI_RUNTIME_IMAGE_ENTRY));
705 if (Image->RuntimeData == NULL) {
706 goto Done;
707 }
708 Image->RuntimeData->ImageBase = Image->Info.ImageBase;
709 Image->RuntimeData->ImageSize = (UINT64) (Image->Info.ImageSize);
710 Image->RuntimeData->RelocationData = Image->ImageContext.FixupData;
711 Image->RuntimeData->Handle = Image->Handle;
712 InsertTailList (&gRuntime->ImageHead, &Image->RuntimeData->Link);
713 }
714 }
715
716 //
717 // Fill in the entry point of the image if it is available
718 //
719 if (EntryPoint != NULL) {
720 *EntryPoint = Image->ImageContext.EntryPoint;
721 }
722
723 //
724 // Print the load address and the PDB file name if it is available
725 //
726
727 DEBUG_CODE_BEGIN ();
728
729 UINTN Index;
730 UINTN StartIndex;
731 CHAR8 EfiFileName[256];
732
733
734 DEBUG ((DEBUG_INFO | DEBUG_LOAD,
735 "Loading driver at 0x%11p EntryPoint=0x%11p ",
736 (VOID *)(UINTN) Image->ImageContext.ImageAddress,
737 FUNCTION_ENTRY_POINT (Image->ImageContext.EntryPoint)));
738
739
740 //
741 // Print Module Name by Pdb file path.
742 // Windows and Unix style file path are all trimmed correctly.
743 //
744 if (Image->ImageContext.PdbPointer != NULL) {
745 StartIndex = 0;
746 for (Index = 0; Image->ImageContext.PdbPointer[Index] != 0; Index++) {
747 if ((Image->ImageContext.PdbPointer[Index] == '\\') || (Image->ImageContext.PdbPointer[Index] == '/')) {
748 StartIndex = Index + 1;
749 }
750 }
751 //
752 // Copy the PDB file name to our temporary string, and replace .pdb with .efi
753 // The PDB file name is limited in the range of 0~255.
754 // If the length is bigger than 255, trim the redudant characters to avoid overflow in array boundary.
755 //
756 for (Index = 0; Index < sizeof (EfiFileName) - 4; Index++) {
757 EfiFileName[Index] = Image->ImageContext.PdbPointer[Index + StartIndex];
758 if (EfiFileName[Index] == 0) {
759 EfiFileName[Index] = '.';
760 }
761 if (EfiFileName[Index] == '.') {
762 EfiFileName[Index + 1] = 'e';
763 EfiFileName[Index + 2] = 'f';
764 EfiFileName[Index + 3] = 'i';
765 EfiFileName[Index + 4] = 0;
766 break;
767 }
768 }
769
770 if (Index == sizeof (EfiFileName) - 4) {
771 EfiFileName[Index] = 0;
772 }
773 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex]));
774 }
775 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
776
777 DEBUG_CODE_END ();
778
779 return EFI_SUCCESS;
780
781 Done:
782
783 //
784 // Free memory.
785 //
786
787 if (DstBufAlocated) {
788 CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages);
789 }
790
791 if (Image->ImageContext.FixupData != NULL) {
792 CoreFreePool (Image->ImageContext.FixupData);
793 }
794
795 return Status;
796 }
797
798
799
800 /**
801 Get the image's private data from its handle.
802
803 @param ImageHandle The image handle
804
805 @return Return the image private data associated with ImageHandle.
806
807 **/
808 LOADED_IMAGE_PRIVATE_DATA *
809 CoreLoadedImageInfo (
810 IN EFI_HANDLE ImageHandle
811 )
812 {
813 EFI_STATUS Status;
814 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
815 LOADED_IMAGE_PRIVATE_DATA *Image;
816
817 Status = CoreHandleProtocol (
818 ImageHandle,
819 &gEfiLoadedImageProtocolGuid,
820 (VOID **)&LoadedImage
821 );
822 if (!EFI_ERROR (Status)) {
823 Image = LOADED_IMAGE_PRIVATE_DATA_FROM_THIS (LoadedImage);
824 } else {
825 DEBUG ((DEBUG_LOAD, "CoreLoadedImageInfo: Not an ImageHandle %p\n", ImageHandle));
826 Image = NULL;
827 }
828
829 return Image;
830 }
831
832
833 /**
834 Unloads EFI image from memory.
835
836 @param Image EFI image
837 @param FreePage Free allocated pages
838
839 **/
840 VOID
841 CoreUnloadAndCloseImage (
842 IN LOADED_IMAGE_PRIVATE_DATA *Image,
843 IN BOOLEAN FreePage
844 )
845 {
846 EFI_STATUS Status;
847 UINTN HandleCount;
848 EFI_HANDLE *HandleBuffer;
849 UINTN HandleIndex;
850 EFI_GUID **ProtocolGuidArray;
851 UINTN ArrayCount;
852 UINTN ProtocolIndex;
853 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
854 UINTN OpenInfoCount;
855 UINTN OpenInfoIndex;
856
857 HandleBuffer = NULL;
858 ProtocolGuidArray = NULL;
859
860 if (Image->Ebc != NULL) {
861 //
862 // If EBC protocol exists we must perform cleanups for this image.
863 //
864 Image->Ebc->UnloadImage (Image->Ebc, Image->Handle);
865 }
866
867 //
868 // Unload image, free Image->ImageContext->ModHandle
869 //
870 PeCoffLoaderUnloadImage (&Image->ImageContext);
871
872 //
873 // Free our references to the image handle
874 //
875 if (Image->Handle != NULL) {
876
877 Status = CoreLocateHandleBuffer (
878 AllHandles,
879 NULL,
880 NULL,
881 &HandleCount,
882 &HandleBuffer
883 );
884 if (!EFI_ERROR (Status)) {
885 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
886 Status = CoreProtocolsPerHandle (
887 HandleBuffer[HandleIndex],
888 &ProtocolGuidArray,
889 &ArrayCount
890 );
891 if (!EFI_ERROR (Status)) {
892 for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
893 Status = CoreOpenProtocolInformation (
894 HandleBuffer[HandleIndex],
895 ProtocolGuidArray[ProtocolIndex],
896 &OpenInfo,
897 &OpenInfoCount
898 );
899 if (!EFI_ERROR (Status)) {
900 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
901 if (OpenInfo[OpenInfoIndex].AgentHandle == Image->Handle) {
902 Status = CoreCloseProtocol (
903 HandleBuffer[HandleIndex],
904 ProtocolGuidArray[ProtocolIndex],
905 Image->Handle,
906 OpenInfo[OpenInfoIndex].ControllerHandle
907 );
908 }
909 }
910 if (OpenInfo != NULL) {
911 CoreFreePool(OpenInfo);
912 }
913 }
914 }
915 if (ProtocolGuidArray != NULL) {
916 CoreFreePool(ProtocolGuidArray);
917 }
918 }
919 }
920 if (HandleBuffer != NULL) {
921 CoreFreePool (HandleBuffer);
922 }
923 }
924
925 CoreRemoveDebugImageInfoEntry (Image->Handle);
926
927 Status = CoreUninstallProtocolInterface (
928 Image->Handle,
929 &gEfiLoadedImageDevicePathProtocolGuid,
930 Image->LoadedImageDevicePath
931 );
932
933 Status = CoreUninstallProtocolInterface (
934 Image->Handle,
935 &gEfiLoadedImageProtocolGuid,
936 &Image->Info
937 );
938
939 if (Image->ImageContext.HiiResourceData != 0) {
940 Status = CoreUninstallProtocolInterface (
941 Image->Handle,
942 &gEfiHiiPackageListProtocolGuid,
943 (VOID *) (UINTN) Image->ImageContext.HiiResourceData
944 );
945 }
946
947 }
948
949 if (Image->RuntimeData != NULL) {
950 if (Image->RuntimeData->Link.ForwardLink != NULL) {
951 //
952 // Remove the Image from the Runtime Image list as we are about to Free it!
953 //
954 RemoveEntryList (&Image->RuntimeData->Link);
955 }
956 CoreFreePool (Image->RuntimeData);
957 }
958
959 //
960 // Free the Image from memory
961 //
962 if ((Image->ImageBasePage != 0) && FreePage) {
963 CoreFreePages (Image->ImageBasePage, Image->NumberOfPages);
964 }
965
966 //
967 // Done with the Image structure
968 //
969 if (Image->Info.FilePath != NULL) {
970 CoreFreePool (Image->Info.FilePath);
971 }
972
973 if (Image->LoadedImageDevicePath != NULL) {
974 CoreFreePool (Image->LoadedImageDevicePath);
975 }
976
977 if (Image->FixupData != NULL) {
978 CoreFreePool (Image->FixupData);
979 }
980
981 CoreFreePool (Image);
982 }
983
984
985 /**
986 Loads an EFI image into memory and returns a handle to the image.
987
988 @param BootPolicy If TRUE, indicates that the request originates
989 from the boot manager, and that the boot
990 manager is attempting to load FilePath as a
991 boot selection.
992 @param ParentImageHandle The caller's image handle.
993 @param FilePath The specific file path from which the image is
994 loaded.
995 @param SourceBuffer If not NULL, a pointer to the memory location
996 containing a copy of the image to be loaded.
997 @param SourceSize The size in bytes of SourceBuffer.
998 @param DstBuffer The buffer to store the image
999 @param NumberOfPages If not NULL, it inputs a pointer to the page
1000 number of DstBuffer and outputs a pointer to
1001 the page number of the image. If this number is
1002 not enough, return EFI_BUFFER_TOO_SMALL and
1003 this parameter contains the required number.
1004 @param ImageHandle Pointer to the returned image handle that is
1005 created when the image is successfully loaded.
1006 @param EntryPoint A pointer to the entry point
1007 @param Attribute The bit mask of attributes to set for the load
1008 PE image
1009
1010 @retval EFI_SUCCESS The image was loaded into memory.
1011 @retval EFI_NOT_FOUND The FilePath was not found.
1012 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
1013 @retval EFI_BUFFER_TOO_SMALL The buffer is too small
1014 @retval EFI_UNSUPPORTED The image type is not supported, or the device
1015 path cannot be parsed to locate the proper
1016 protocol for loading the file.
1017 @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient
1018 resources.
1019 @retval EFI_LOAD_ERROR Image was not loaded because the image format was corrupt or not
1020 understood.
1021 @retval EFI_DEVICE_ERROR Image was not loaded because the device returned a read error.
1022 @retval EFI_ACCESS_DENIED Image was not loaded because the platform policy prohibits the
1023 image from being loaded. NULL is returned in *ImageHandle.
1024 @retval EFI_SECURITY_VIOLATION Image was loaded and an ImageHandle was created with a
1025 valid EFI_LOADED_IMAGE_PROTOCOL. However, the current
1026 platform policy specifies that the image should not be started.
1027
1028 **/
1029 EFI_STATUS
1030 CoreLoadImageCommon (
1031 IN BOOLEAN BootPolicy,
1032 IN EFI_HANDLE ParentImageHandle,
1033 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
1034 IN VOID *SourceBuffer OPTIONAL,
1035 IN UINTN SourceSize,
1036 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
1037 IN OUT UINTN *NumberOfPages OPTIONAL,
1038 OUT EFI_HANDLE *ImageHandle,
1039 OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
1040 IN UINT32 Attribute
1041 )
1042 {
1043 LOADED_IMAGE_PRIVATE_DATA *Image;
1044 LOADED_IMAGE_PRIVATE_DATA *ParentImage;
1045 IMAGE_FILE_HANDLE FHand;
1046 EFI_STATUS Status;
1047 EFI_STATUS SecurityStatus;
1048 EFI_HANDLE DeviceHandle;
1049 UINT32 AuthenticationStatus;
1050 EFI_DEVICE_PATH_PROTOCOL *OriginalFilePath;
1051 EFI_DEVICE_PATH_PROTOCOL *HandleFilePath;
1052 UINTN FilePathSize;
1053 BOOLEAN ImageIsFromFv;
1054
1055 SecurityStatus = EFI_SUCCESS;
1056
1057 ASSERT (gEfiCurrentTpl < TPL_NOTIFY);
1058 ParentImage = NULL;
1059
1060 //
1061 // The caller must pass in a valid ParentImageHandle
1062 //
1063 if (ImageHandle == NULL || ParentImageHandle == NULL) {
1064 return EFI_INVALID_PARAMETER;
1065 }
1066
1067 ParentImage = CoreLoadedImageInfo (ParentImageHandle);
1068 if (ParentImage == NULL) {
1069 DEBUG((DEBUG_LOAD|DEBUG_ERROR, "LoadImageEx: Parent handle not an image handle\n"));
1070 return EFI_INVALID_PARAMETER;
1071 }
1072
1073 ZeroMem (&FHand, sizeof (IMAGE_FILE_HANDLE));
1074 FHand.Signature = IMAGE_FILE_HANDLE_SIGNATURE;
1075 OriginalFilePath = FilePath;
1076 HandleFilePath = FilePath;
1077 DeviceHandle = NULL;
1078 Status = EFI_SUCCESS;
1079 AuthenticationStatus = 0;
1080 ImageIsFromFv = FALSE;
1081
1082 //
1083 // If the caller passed a copy of the file, then just use it
1084 //
1085 if (SourceBuffer != NULL) {
1086 FHand.Source = SourceBuffer;
1087 FHand.SourceSize = SourceSize;
1088 Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &HandleFilePath, &DeviceHandle);
1089 if (EFI_ERROR (Status)) {
1090 DeviceHandle = NULL;
1091 }
1092 if (SourceSize > 0) {
1093 Status = EFI_SUCCESS;
1094 } else {
1095 Status = EFI_LOAD_ERROR;
1096 }
1097 } else {
1098 if (FilePath == NULL) {
1099 return EFI_INVALID_PARAMETER;
1100 }
1101 //
1102 // Get the source file buffer by its device path.
1103 //
1104 FHand.Source = GetFileBufferByFilePath (
1105 BootPolicy,
1106 FilePath,
1107 &FHand.SourceSize,
1108 &AuthenticationStatus
1109 );
1110 if (FHand.Source == NULL) {
1111 Status = EFI_NOT_FOUND;
1112 } else {
1113 //
1114 // Try to get the image device handle by checking the match protocol.
1115 //
1116 FHand.FreeBuffer = TRUE;
1117 Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &HandleFilePath, &DeviceHandle);
1118 if (!EFI_ERROR (Status)) {
1119 ImageIsFromFv = TRUE;
1120 } else {
1121 HandleFilePath = FilePath;
1122 Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle);
1123 if (EFI_ERROR (Status)) {
1124 if (!BootPolicy) {
1125 HandleFilePath = FilePath;
1126 Status = CoreLocateDevicePath (&gEfiLoadFile2ProtocolGuid, &HandleFilePath, &DeviceHandle);
1127 }
1128 if (EFI_ERROR (Status)) {
1129 HandleFilePath = FilePath;
1130 Status = CoreLocateDevicePath (&gEfiLoadFileProtocolGuid, &HandleFilePath, &DeviceHandle);
1131 }
1132 }
1133 }
1134 }
1135 }
1136
1137 if (EFI_ERROR (Status)) {
1138 Image = NULL;
1139 goto Done;
1140 }
1141
1142 if (gSecurity2 != NULL) {
1143 //
1144 // Verify File Authentication through the Security2 Architectural Protocol
1145 //
1146 SecurityStatus = gSecurity2->FileAuthentication (
1147 gSecurity2,
1148 OriginalFilePath,
1149 FHand.Source,
1150 FHand.SourceSize,
1151 BootPolicy
1152 );
1153 if (!EFI_ERROR (SecurityStatus) && ImageIsFromFv) {
1154 //
1155 // When Security2 is installed, Security Architectural Protocol must be published.
1156 //
1157 ASSERT (gSecurity != NULL);
1158
1159 //
1160 // Verify the Authentication Status through the Security Architectural Protocol
1161 // Only on images that have been read using Firmware Volume protocol.
1162 //
1163 SecurityStatus = gSecurity->FileAuthenticationState (
1164 gSecurity,
1165 AuthenticationStatus,
1166 OriginalFilePath
1167 );
1168 }
1169 } else if ((gSecurity != NULL) && (OriginalFilePath != NULL)) {
1170 //
1171 // Verify the Authentication Status through the Security Architectural Protocol
1172 //
1173 SecurityStatus = gSecurity->FileAuthenticationState (
1174 gSecurity,
1175 AuthenticationStatus,
1176 OriginalFilePath
1177 );
1178 }
1179
1180 //
1181 // Check Security Status.
1182 //
1183 if (EFI_ERROR (SecurityStatus) && SecurityStatus != EFI_SECURITY_VIOLATION) {
1184 if (SecurityStatus == EFI_ACCESS_DENIED) {
1185 //
1186 // Image was not loaded because the platform policy prohibits the image from being loaded.
1187 // It's the only place we could meet EFI_ACCESS_DENIED.
1188 //
1189 *ImageHandle = NULL;
1190 }
1191 Status = SecurityStatus;
1192 Image = NULL;
1193 goto Done;
1194 }
1195
1196 //
1197 // Allocate a new image structure
1198 //
1199 Image = AllocateZeroPool (sizeof(LOADED_IMAGE_PRIVATE_DATA));
1200 if (Image == NULL) {
1201 Status = EFI_OUT_OF_RESOURCES;
1202 goto Done;
1203 }
1204
1205 //
1206 // Pull out just the file portion of the DevicePath for the LoadedImage FilePath
1207 //
1208 FilePath = OriginalFilePath;
1209 if (DeviceHandle != NULL) {
1210 Status = CoreHandleProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath);
1211 if (!EFI_ERROR (Status)) {
1212 FilePathSize = GetDevicePathSize (HandleFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
1213 FilePath = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *)FilePath) + FilePathSize );
1214 }
1215 }
1216 //
1217 // Initialize the fields for an internal driver
1218 //
1219 Image->Signature = LOADED_IMAGE_PRIVATE_DATA_SIGNATURE;
1220 Image->Info.SystemTable = gDxeCoreST;
1221 Image->Info.DeviceHandle = DeviceHandle;
1222 Image->Info.Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
1223 Image->Info.FilePath = DuplicateDevicePath (FilePath);
1224 Image->Info.ParentHandle = ParentImageHandle;
1225
1226
1227 if (NumberOfPages != NULL) {
1228 Image->NumberOfPages = *NumberOfPages ;
1229 } else {
1230 Image->NumberOfPages = 0 ;
1231 }
1232
1233 //
1234 // Install the protocol interfaces for this image
1235 // don't fire notifications yet
1236 //
1237 Status = CoreInstallProtocolInterfaceNotify (
1238 &Image->Handle,
1239 &gEfiLoadedImageProtocolGuid,
1240 EFI_NATIVE_INTERFACE,
1241 &Image->Info,
1242 FALSE
1243 );
1244 if (EFI_ERROR (Status)) {
1245 goto Done;
1246 }
1247
1248 //
1249 // Load the image. If EntryPoint is Null, it will not be set.
1250 //
1251 Status = CoreLoadPeImage (BootPolicy, &FHand, Image, DstBuffer, EntryPoint, Attribute);
1252 if (EFI_ERROR (Status)) {
1253 if ((Status == EFI_BUFFER_TOO_SMALL) || (Status == EFI_OUT_OF_RESOURCES)) {
1254 if (NumberOfPages != NULL) {
1255 *NumberOfPages = Image->NumberOfPages;
1256 }
1257 }
1258 goto Done;
1259 }
1260
1261 if (NumberOfPages != NULL) {
1262 *NumberOfPages = Image->NumberOfPages;
1263 }
1264
1265 //
1266 // Register the image in the Debug Image Info Table if the attribute is set
1267 //
1268 if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION) != 0) {
1269 CoreNewDebugImageInfoEntry (EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL, &Image->Info, Image->Handle);
1270 }
1271
1272 //
1273 //Reinstall loaded image protocol to fire any notifications
1274 //
1275 Status = CoreReinstallProtocolInterface (
1276 Image->Handle,
1277 &gEfiLoadedImageProtocolGuid,
1278 &Image->Info,
1279 &Image->Info
1280 );
1281 if (EFI_ERROR (Status)) {
1282 goto Done;
1283 }
1284
1285 //
1286 // If DevicePath parameter to the LoadImage() is not NULL, then make a copy of DevicePath,
1287 // otherwise Loaded Image Device Path Protocol is installed with a NULL interface pointer.
1288 //
1289 if (OriginalFilePath != NULL) {
1290 Image->LoadedImageDevicePath = DuplicateDevicePath (OriginalFilePath);
1291 }
1292
1293 //
1294 // Install Loaded Image Device Path Protocol onto the image handle of a PE/COFE image
1295 //
1296 Status = CoreInstallProtocolInterface (
1297 &Image->Handle,
1298 &gEfiLoadedImageDevicePathProtocolGuid,
1299 EFI_NATIVE_INTERFACE,
1300 Image->LoadedImageDevicePath
1301 );
1302 if (EFI_ERROR (Status)) {
1303 goto Done;
1304 }
1305
1306 //
1307 // Install HII Package List Protocol onto the image handle
1308 //
1309 if (Image->ImageContext.HiiResourceData != 0) {
1310 Status = CoreInstallProtocolInterface (
1311 &Image->Handle,
1312 &gEfiHiiPackageListProtocolGuid,
1313 EFI_NATIVE_INTERFACE,
1314 (VOID *) (UINTN) Image->ImageContext.HiiResourceData
1315 );
1316 if (EFI_ERROR (Status)) {
1317 goto Done;
1318 }
1319 }
1320
1321 //
1322 // Success. Return the image handle
1323 //
1324 *ImageHandle = Image->Handle;
1325
1326 Done:
1327 //
1328 // All done accessing the source file
1329 // If we allocated the Source buffer, free it
1330 //
1331 if (FHand.FreeBuffer) {
1332 CoreFreePool (FHand.Source);
1333 }
1334
1335 //
1336 // There was an error. If there's an Image structure, free it
1337 //
1338 if (EFI_ERROR (Status)) {
1339 if (Image != NULL) {
1340 CoreUnloadAndCloseImage (Image, (BOOLEAN)(DstBuffer == 0));
1341 Image = NULL;
1342 }
1343 } else if (EFI_ERROR (SecurityStatus)) {
1344 Status = SecurityStatus;
1345 }
1346
1347 //
1348 // Track the return status from LoadImage.
1349 //
1350 if (Image != NULL) {
1351 Image->LoadImageStatus = Status;
1352 }
1353
1354 return Status;
1355 }
1356
1357
1358
1359
1360 /**
1361 Loads an EFI image into memory and returns a handle to the image.
1362
1363 @param BootPolicy If TRUE, indicates that the request originates
1364 from the boot manager, and that the boot
1365 manager is attempting to load FilePath as a
1366 boot selection.
1367 @param ParentImageHandle The caller's image handle.
1368 @param FilePath The specific file path from which the image is
1369 loaded.
1370 @param SourceBuffer If not NULL, a pointer to the memory location
1371 containing a copy of the image to be loaded.
1372 @param SourceSize The size in bytes of SourceBuffer.
1373 @param ImageHandle Pointer to the returned image handle that is
1374 created when the image is successfully loaded.
1375
1376 @retval EFI_SUCCESS The image was loaded into memory.
1377 @retval EFI_NOT_FOUND The FilePath was not found.
1378 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
1379 @retval EFI_UNSUPPORTED The image type is not supported, or the device
1380 path cannot be parsed to locate the proper
1381 protocol for loading the file.
1382 @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient
1383 resources.
1384 @retval EFI_LOAD_ERROR Image was not loaded because the image format was corrupt or not
1385 understood.
1386 @retval EFI_DEVICE_ERROR Image was not loaded because the device returned a read error.
1387 @retval EFI_ACCESS_DENIED Image was not loaded because the platform policy prohibits the
1388 image from being loaded. NULL is returned in *ImageHandle.
1389 @retval EFI_SECURITY_VIOLATION Image was loaded and an ImageHandle was created with a
1390 valid EFI_LOADED_IMAGE_PROTOCOL. However, the current
1391 platform policy specifies that the image should not be started.
1392
1393 **/
1394 EFI_STATUS
1395 EFIAPI
1396 CoreLoadImage (
1397 IN BOOLEAN BootPolicy,
1398 IN EFI_HANDLE ParentImageHandle,
1399 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
1400 IN VOID *SourceBuffer OPTIONAL,
1401 IN UINTN SourceSize,
1402 OUT EFI_HANDLE *ImageHandle
1403 )
1404 {
1405 EFI_STATUS Status;
1406 UINT64 Tick;
1407 EFI_HANDLE Handle;
1408
1409 Tick = 0;
1410 PERF_CODE (
1411 Tick = GetPerformanceCounter ();
1412 );
1413
1414 Status = CoreLoadImageCommon (
1415 BootPolicy,
1416 ParentImageHandle,
1417 FilePath,
1418 SourceBuffer,
1419 SourceSize,
1420 (EFI_PHYSICAL_ADDRESS) (UINTN) NULL,
1421 NULL,
1422 ImageHandle,
1423 NULL,
1424 EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION | EFI_LOAD_PE_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION
1425 );
1426
1427 Handle = NULL;
1428 if (!EFI_ERROR (Status)) {
1429 //
1430 // ImageHandle will be valid only Status is success.
1431 //
1432 Handle = *ImageHandle;
1433 }
1434
1435 PERF_START (Handle, "LoadImage:", NULL, Tick);
1436 PERF_END (Handle, "LoadImage:", NULL, 0);
1437
1438 return Status;
1439 }
1440
1441
1442
1443 /**
1444 Loads an EFI image into memory and returns a handle to the image with extended parameters.
1445
1446 @param This Calling context
1447 @param ParentImageHandle The caller's image handle.
1448 @param FilePath The specific file path from which the image is
1449 loaded.
1450 @param SourceBuffer If not NULL, a pointer to the memory location
1451 containing a copy of the image to be loaded.
1452 @param SourceSize The size in bytes of SourceBuffer.
1453 @param DstBuffer The buffer to store the image.
1454 @param NumberOfPages For input, specifies the space size of the
1455 image by caller if not NULL. For output,
1456 specifies the actual space size needed.
1457 @param ImageHandle Image handle for output.
1458 @param EntryPoint Image entry point for output.
1459 @param Attribute The bit mask of attributes to set for the load
1460 PE image.
1461
1462 @retval EFI_SUCCESS The image was loaded into memory.
1463 @retval EFI_NOT_FOUND The FilePath was not found.
1464 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
1465 @retval EFI_UNSUPPORTED The image type is not supported, or the device
1466 path cannot be parsed to locate the proper
1467 protocol for loading the file.
1468 @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient
1469 resources.
1470 @retval EFI_LOAD_ERROR Image was not loaded because the image format was corrupt or not
1471 understood.
1472 @retval EFI_DEVICE_ERROR Image was not loaded because the device returned a read error.
1473 @retval EFI_ACCESS_DENIED Image was not loaded because the platform policy prohibits the
1474 image from being loaded. NULL is returned in *ImageHandle.
1475 @retval EFI_SECURITY_VIOLATION Image was loaded and an ImageHandle was created with a
1476 valid EFI_LOADED_IMAGE_PROTOCOL. However, the current
1477 platform policy specifies that the image should not be started.
1478
1479 **/
1480 EFI_STATUS
1481 EFIAPI
1482 CoreLoadImageEx (
1483 IN EFI_PE32_IMAGE_PROTOCOL *This,
1484 IN EFI_HANDLE ParentImageHandle,
1485 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
1486 IN VOID *SourceBuffer OPTIONAL,
1487 IN UINTN SourceSize,
1488 IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
1489 OUT UINTN *NumberOfPages OPTIONAL,
1490 OUT EFI_HANDLE *ImageHandle,
1491 OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
1492 IN UINT32 Attribute
1493 )
1494 {
1495 EFI_STATUS Status;
1496 UINT64 Tick;
1497 EFI_HANDLE Handle;
1498
1499 Tick = 0;
1500 PERF_CODE (
1501 Tick = GetPerformanceCounter ();
1502 );
1503
1504 Status = CoreLoadImageCommon (
1505 TRUE,
1506 ParentImageHandle,
1507 FilePath,
1508 SourceBuffer,
1509 SourceSize,
1510 DstBuffer,
1511 NumberOfPages,
1512 ImageHandle,
1513 EntryPoint,
1514 Attribute
1515 );
1516
1517 Handle = NULL;
1518 if (!EFI_ERROR (Status)) {
1519 //
1520 // ImageHandle will be valid only Status is success.
1521 //
1522 Handle = *ImageHandle;
1523 }
1524
1525 PERF_START (Handle, "LoadImage:", NULL, Tick);
1526 PERF_END (Handle, "LoadImage:", NULL, 0);
1527
1528 return Status;
1529 }
1530
1531
1532 /**
1533 Transfer control to a loaded image's entry point.
1534
1535 @param ImageHandle Handle of image to be started.
1536 @param ExitDataSize Pointer of the size to ExitData
1537 @param ExitData Pointer to a pointer to a data buffer that
1538 includes a Null-terminated string,
1539 optionally followed by additional binary data.
1540 The string is a description that the caller may
1541 use to further indicate the reason for the
1542 image's exit.
1543
1544 @retval EFI_INVALID_PARAMETER Invalid parameter
1545 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
1546 @retval EFI_SECURITY_VIOLATION The current platform policy specifies that the image should not be started.
1547 @retval EFI_SUCCESS Successfully transfer control to the image's
1548 entry point.
1549
1550 **/
1551 EFI_STATUS
1552 EFIAPI
1553 CoreStartImage (
1554 IN EFI_HANDLE ImageHandle,
1555 OUT UINTN *ExitDataSize,
1556 OUT CHAR16 **ExitData OPTIONAL
1557 )
1558 {
1559 EFI_STATUS Status;
1560 LOADED_IMAGE_PRIVATE_DATA *Image;
1561 LOADED_IMAGE_PRIVATE_DATA *LastImage;
1562 UINT64 HandleDatabaseKey;
1563 UINTN SetJumpFlag;
1564 UINT64 Tick;
1565 EFI_HANDLE Handle;
1566
1567 Tick = 0;
1568 Handle = ImageHandle;
1569
1570 Image = CoreLoadedImageInfo (ImageHandle);
1571 if (Image == NULL || Image->Started) {
1572 return EFI_INVALID_PARAMETER;
1573 }
1574 if (EFI_ERROR (Image->LoadImageStatus)) {
1575 return Image->LoadImageStatus;
1576 }
1577
1578 //
1579 // The image to be started must have the machine type supported by DxeCore.
1580 //
1581 if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->Machine)) {
1582 //
1583 // Do not ASSERT here, because image might be loaded via EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED
1584 // But it can not be started.
1585 //
1586 DEBUG ((EFI_D_ERROR, "Image type %s can't be started ", GetMachineTypeName(Image->Machine)));
1587 DEBUG ((EFI_D_ERROR, "on %s UEFI system.\n", GetMachineTypeName(mDxeCoreImageMachineType)));
1588 return EFI_UNSUPPORTED;
1589 }
1590
1591 PERF_CODE (
1592 Tick = GetPerformanceCounter ();
1593 );
1594
1595
1596 //
1597 // Push the current start image context, and
1598 // link the current image to the head. This is the
1599 // only image that can call Exit()
1600 //
1601 HandleDatabaseKey = CoreGetHandleDatabaseKey ();
1602 LastImage = mCurrentImage;
1603 mCurrentImage = Image;
1604 Image->Tpl = gEfiCurrentTpl;
1605
1606 //
1607 // Set long jump for Exit() support
1608 // JumpContext must be aligned on a CPU specific boundary.
1609 // Overallocate the buffer and force the required alignment
1610 //
1611 Image->JumpBuffer = AllocatePool (sizeof (BASE_LIBRARY_JUMP_BUFFER) + BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT);
1612 if (Image->JumpBuffer == NULL) {
1613 //
1614 // Image may be unloaded after return with failure,
1615 // then ImageHandle may be invalid, so use NULL handle to record perf log.
1616 //
1617 PERF_START (NULL, "StartImage:", NULL, Tick);
1618 PERF_END (NULL, "StartImage:", NULL, 0);
1619 return EFI_OUT_OF_RESOURCES;
1620 }
1621 Image->JumpContext = ALIGN_POINTER (Image->JumpBuffer, BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT);
1622
1623 SetJumpFlag = SetJump (Image->JumpContext);
1624 //
1625 // The initial call to SetJump() must always return 0.
1626 // Subsequent calls to LongJump() cause a non-zero value to be returned by SetJump().
1627 //
1628 if (SetJumpFlag == 0) {
1629 //
1630 // Call the image's entry point
1631 //
1632 Image->Started = TRUE;
1633 Image->Status = Image->EntryPoint (ImageHandle, Image->Info.SystemTable);
1634
1635 //
1636 // Add some debug information if the image returned with error.
1637 // This make the user aware and check if the driver image have already released
1638 // all the resource in this situation.
1639 //
1640 DEBUG_CODE_BEGIN ();
1641 if (EFI_ERROR (Image->Status)) {
1642 DEBUG ((DEBUG_ERROR, "Error: Image at %11p start failed: %r\n", Image->Info.ImageBase, Image->Status));
1643 }
1644 DEBUG_CODE_END ();
1645
1646 //
1647 // If the image returns, exit it through Exit()
1648 //
1649 CoreExit (ImageHandle, Image->Status, 0, NULL);
1650 }
1651
1652 //
1653 // Image has completed. Verify the tpl is the same
1654 //
1655 ASSERT (Image->Tpl == gEfiCurrentTpl);
1656 CoreRestoreTpl (Image->Tpl);
1657
1658 CoreFreePool (Image->JumpBuffer);
1659
1660 //
1661 // Pop the current start image context
1662 //
1663 mCurrentImage = LastImage;
1664
1665 //
1666 // Go connect any handles that were created or modified while the image executed.
1667 //
1668 CoreConnectHandlesByKey (HandleDatabaseKey);
1669
1670 //
1671 // Handle the image's returned ExitData
1672 //
1673 DEBUG_CODE_BEGIN ();
1674 if (Image->ExitDataSize != 0 || Image->ExitData != NULL) {
1675
1676 DEBUG ((DEBUG_LOAD, "StartImage: ExitDataSize %d, ExitData %p", (UINT32)Image->ExitDataSize, Image->ExitData));
1677 if (Image->ExitData != NULL) {
1678 DEBUG ((DEBUG_LOAD, " (%hs)", Image->ExitData));
1679 }
1680 DEBUG ((DEBUG_LOAD, "\n"));
1681 }
1682 DEBUG_CODE_END ();
1683
1684 //
1685 // Return the exit data to the caller
1686 //
1687 if (ExitData != NULL && ExitDataSize != NULL) {
1688 *ExitDataSize = Image->ExitDataSize;
1689 *ExitData = Image->ExitData;
1690 } else {
1691 //
1692 // Caller doesn't want the exit data, free it
1693 //
1694 CoreFreePool (Image->ExitData);
1695 Image->ExitData = NULL;
1696 }
1697
1698 //
1699 // Save the Status because Image will get destroyed if it is unloaded.
1700 //
1701 Status = Image->Status;
1702
1703 //
1704 // If the image returned an error, or if the image is an application
1705 // unload it
1706 //
1707 if (EFI_ERROR (Image->Status) || Image->Type == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
1708 CoreUnloadAndCloseImage (Image, TRUE);
1709 //
1710 // ImageHandle may be invalid after the image is unloaded, so use NULL handle to record perf log.
1711 //
1712 Handle = NULL;
1713 }
1714
1715 //
1716 // Done
1717 //
1718 PERF_START (Handle, "StartImage:", NULL, Tick);
1719 PERF_END (Handle, "StartImage:", NULL, 0);
1720 return Status;
1721 }
1722
1723 /**
1724 Terminates the currently loaded EFI image and returns control to boot services.
1725
1726 @param ImageHandle Handle that identifies the image. This
1727 parameter is passed to the image on entry.
1728 @param Status The image's exit code.
1729 @param ExitDataSize The size, in bytes, of ExitData. Ignored if
1730 ExitStatus is EFI_SUCCESS.
1731 @param ExitData Pointer to a data buffer that includes a
1732 Null-terminated Unicode string, optionally
1733 followed by additional binary data. The string
1734 is a description that the caller may use to
1735 further indicate the reason for the image's
1736 exit.
1737
1738 @retval EFI_INVALID_PARAMETER Image handle is NULL or it is not current
1739 image.
1740 @retval EFI_SUCCESS Successfully terminates the currently loaded
1741 EFI image.
1742 @retval EFI_ACCESS_DENIED Should never reach there.
1743 @retval EFI_OUT_OF_RESOURCES Could not allocate pool
1744
1745 **/
1746 EFI_STATUS
1747 EFIAPI
1748 CoreExit (
1749 IN EFI_HANDLE ImageHandle,
1750 IN EFI_STATUS Status,
1751 IN UINTN ExitDataSize,
1752 IN CHAR16 *ExitData OPTIONAL
1753 )
1754 {
1755 LOADED_IMAGE_PRIVATE_DATA *Image;
1756 EFI_TPL OldTpl;
1757
1758 //
1759 // Prevent possible reentrance to this function
1760 // for the same ImageHandle
1761 //
1762 OldTpl = CoreRaiseTpl (TPL_NOTIFY);
1763
1764 Image = CoreLoadedImageInfo (ImageHandle);
1765 if (Image == NULL) {
1766 Status = EFI_INVALID_PARAMETER;
1767 goto Done;
1768 }
1769
1770 if (!Image->Started) {
1771 //
1772 // The image has not been started so just free its resources
1773 //
1774 CoreUnloadAndCloseImage (Image, TRUE);
1775 Status = EFI_SUCCESS;
1776 goto Done;
1777 }
1778
1779 //
1780 // Image has been started, verify this image can exit
1781 //
1782 if (Image != mCurrentImage) {
1783 DEBUG ((DEBUG_LOAD|DEBUG_ERROR, "Exit: Image is not exitable image\n"));
1784 Status = EFI_INVALID_PARAMETER;
1785 goto Done;
1786 }
1787
1788 //
1789 // Set status
1790 //
1791 Image->Status = Status;
1792
1793 //
1794 // If there's ExitData info, move it
1795 //
1796 if (ExitData != NULL) {
1797 Image->ExitDataSize = ExitDataSize;
1798 Image->ExitData = AllocatePool (Image->ExitDataSize);
1799 if (Image->ExitData == NULL) {
1800 Status = EFI_OUT_OF_RESOURCES;
1801 goto Done;
1802 }
1803 CopyMem (Image->ExitData, ExitData, Image->ExitDataSize);
1804 }
1805
1806 CoreRestoreTpl (OldTpl);
1807 //
1808 // return to StartImage
1809 //
1810 LongJump (Image->JumpContext, (UINTN)-1);
1811
1812 //
1813 // If we return from LongJump, then it is an error
1814 //
1815 ASSERT (FALSE);
1816 Status = EFI_ACCESS_DENIED;
1817 Done:
1818 CoreRestoreTpl (OldTpl);
1819 return Status;
1820 }
1821
1822
1823
1824
1825 /**
1826 Unloads an image.
1827
1828 @param ImageHandle Handle that identifies the image to be
1829 unloaded.
1830
1831 @retval EFI_SUCCESS The image has been unloaded.
1832 @retval EFI_UNSUPPORTED The image has been sarted, and does not support
1833 unload.
1834 @retval EFI_INVALID_PARAMPETER ImageHandle is not a valid image handle.
1835
1836 **/
1837 EFI_STATUS
1838 EFIAPI
1839 CoreUnloadImage (
1840 IN EFI_HANDLE ImageHandle
1841 )
1842 {
1843 EFI_STATUS Status;
1844 LOADED_IMAGE_PRIVATE_DATA *Image;
1845
1846 Image = CoreLoadedImageInfo (ImageHandle);
1847 if (Image == NULL ) {
1848 //
1849 // The image handle is not valid
1850 //
1851 Status = EFI_INVALID_PARAMETER;
1852 goto Done;
1853 }
1854
1855 if (Image->Started) {
1856 //
1857 // The image has been started, request it to unload.
1858 //
1859 Status = EFI_UNSUPPORTED;
1860 if (Image->Info.Unload != NULL) {
1861 Status = Image->Info.Unload (ImageHandle);
1862 }
1863
1864 } else {
1865 //
1866 // This Image hasn't been started, thus it can be unloaded
1867 //
1868 Status = EFI_SUCCESS;
1869 }
1870
1871
1872 if (!EFI_ERROR (Status)) {
1873 //
1874 // if the Image was not started or Unloaded O.K. then clean up
1875 //
1876 CoreUnloadAndCloseImage (Image, TRUE);
1877 }
1878
1879 Done:
1880 return Status;
1881 }
1882
1883
1884
1885 /**
1886 Unload the specified image.
1887
1888 @param This Indicates the calling context.
1889 @param ImageHandle The specified image handle.
1890
1891 @retval EFI_INVALID_PARAMETER Image handle is NULL.
1892 @retval EFI_UNSUPPORTED Attempt to unload an unsupported image.
1893 @retval EFI_SUCCESS Image successfully unloaded.
1894
1895 **/
1896 EFI_STATUS
1897 EFIAPI
1898 CoreUnloadImageEx (
1899 IN EFI_PE32_IMAGE_PROTOCOL *This,
1900 IN EFI_HANDLE ImageHandle
1901 )
1902 {
1903 return CoreUnloadImage (ImageHandle);
1904 }