VOID EFIAPI ExitDriver ( IN EFI_STATUS Status ) { if (EFI_ERROR (Status)) { ProcessLibraryDestructorList (gImageHandle, gST); } gBS->Exit (gImageHandle, Status, 0, NULL); }
/** Invokes the library destructors for all dependent libraries and terminates the UEFI Application. This function calls ProcessLibraryDestructorList() and the EFI Boot Service Exit() with a status specified by Status. @param Status Status returned by the application that is exiting. **/ VOID EFIAPI Exit ( IN EFI_STATUS Status ) { ProcessLibraryDestructorList (gImageHandle, gST); gBS->Exit (gImageHandle, Status, 0, NULL); }
/** Unload function that is registered in the LoadImage protocol. It un-installs protocols produced and deallocates pool used by the driver. Called by the core when unloading the driver. @param ImageHandle @retval EFI_SUCCESS **/ EFI_STATUS EFIAPI _DriverUnloadHandler ( EFI_HANDLE ImageHandle ) { EFI_STATUS Status; // // If an UnloadImage() handler is specified, then call it // Status = ProcessModuleUnloadList (ImageHandle); // // If the driver specific unload handler does not return an error, then call all of the // library destructors. If the unload handler returned an error, then the driver can not be // unloaded, and the library destructors should not be called // if (!EFI_ERROR (Status)) { // // Close our ExitBootServices () notify function // #if __EDKII_GLUE_HAVE_DRIVER_EXIT_BOOT_SERVICES_EVENT__ if (_gDriverExitBootServicesEvent[0] != NULL) { ASSERT (gBS != NULL); Status = gBS->CloseEvent (_mDriverExitBootServicesNotifyEvent); ASSERT_EFI_ERROR (Status); } #endif ProcessLibraryDestructorList (ImageHandle, gST); } // // Return the status from the driver specific unload handler // return Status; }
/** Entry point to UEFI Application. This function is the entry point for a UEFI Application. This function must call ProcessLibraryConstructorList(), ProcessModuleEntryPointList(), and ProcessLibraryDestructorList(). The return value from ProcessModuleEntryPointList() is returned. If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than _gUefiDriverRevison, then return EFI_INCOMPATIBLE_VERSION. @param ImageHandle The image handle of the UEFI Application. @param SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS The UEFI Application exited normally. @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than SystemTable->Hdr.Revision. @retval Other Return value from ProcessModuleEntryPointList(). **/ EFI_STATUS EFIAPI _ModuleEntryPoint ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; if (_gUefiDriverRevision != 0) { // // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the application. // if (SystemTable->Hdr.Revision < _gUefiDriverRevision) { return EFI_INCOMPATIBLE_VERSION; } } // // Call constructor for all libraries. // ProcessLibraryConstructorList (ImageHandle, SystemTable); // // Call the module's entry point // Status = ProcessModuleEntryPointList (ImageHandle, SystemTable); // // Process destructor for all libraries. // ProcessLibraryDestructorList (ImageHandle, SystemTable); // // Return the return status code from the driver entry point // return Status; }
/** Enrty point to DXE SMM Driver. @param ImageHandle ImageHandle of the loaded driver. @param SystemTable Pointer to the EFI System Table. @retval EFI_SUCCESS One or more of the drivers returned a success code. @retval !EFI_SUCESS The return status from the last driver entry point in the list. **/ EFI_STATUS EFIAPI _ModuleEntryPoint ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; EFI_SMM_BASE_PROTOCOL *SmmBase; BOOLEAN InSmm; EFI_DEVICE_PATH_PROTOCOL *CompleteFilePath; EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath; EFI_HANDLE Handle; // // Cache a pointer to the Boot Services Table // gBS = SystemTable->BootServices; // // Retrieve SMM Base Protocol // Status = gBS->LocateProtocol ( &gEfiSmmBaseProtocolGuid, NULL, (VOID **) &SmmBase ); ASSERT_EFI_ERROR (Status); // // Check to see if we are already in SMM // SmmBase->InSmm (SmmBase, &InSmm); // // // if (!InSmm) { // // Retrieve the Loaded Image Protocol // Status = gBS->HandleProtocol ( ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID*)&LoadedImage ); ASSERT_EFI_ERROR (Status); // // Retrieve the Device Path Protocol from the DeviceHandle from which this driver was loaded // Status = gBS->HandleProtocol ( LoadedImage->DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID*)&ImageDevicePath ); ASSERT_EFI_ERROR (Status); // // Build the full device path to the currently execuing image // CompleteFilePath = SmmAppendDevicePath (ImageDevicePath, LoadedImage->FilePath); // // Load the image in memory to SMRAM; it will automatically generate the // SMI. // Status = SmmBase->Register (SmmBase, CompleteFilePath, LoadedImage->ImageBase, 0, &Handle, FALSE); ASSERT_EFI_ERROR (Status); // // Optionally install the unload handler // if (_gDriverUnloadImageCount > 0) { Status = gBS->HandleProtocol ( ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&LoadedImage ); ASSERT_EFI_ERROR (Status); LoadedImage->Unload = _DriverUnloadHandler; } return Status; } // // Call constructor for all libraries // ProcessLibraryConstructorList (ImageHandle, SystemTable); // // Call the list of driver entry points // Status = ProcessModuleEntryPointList (ImageHandle, SystemTable); if (EFI_ERROR (Status)) { ProcessLibraryDestructorList (ImageHandle, SystemTable); } return Status; }
/** Enrty point to DXE Driver. @param ImageHandle ImageHandle of the loaded driver. @param SystemTable Pointer to the EFI System Table. @retval EFI_SUCCESS One or more of the drivers returned a success code. @retval !EFI_SUCESS The return status from the last driver entry point in the list. **/ EFI_STATUS EFIAPI _ModuleEntryPoint ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; // if (_gUefiDriverRevision != 0) { // // // // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver // // // if (SystemTable->Hdr.Revision < _gUefiDriverRevision) { // return EFI_INCOMPATIBLE_VERSION; // } // } // DEBUG ((EFI_D_ERROR, "EdkII Glue Driver Entry - 0\n")); // // Call constructor for all libraries // ProcessLibraryConstructorList (ImageHandle, SystemTable); // // Register our ExitBootServices () notify function // #if __EDKII_GLUE_HAVE_DRIVER_EXIT_BOOT_SERVICES_EVENT__ if (_gDriverExitBootServicesEvent[0] != NULL) { Status = SystemTable->BootServices->CreateEvent ( EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES, EFI_TPL_NOTIFY, _DriverExitBootServices, NULL, &_mDriverExitBootServicesNotifyEvent ); ASSERT_EFI_ERROR (Status); } #endif // // Install unload handler... // // // Add conditional macro to save size. The 4 macros check against // potential functions which may be invoked, if there is no function // to be called, we don't register Unload callback. // #if ( defined(__EDKII_GLUE_MODULE_UNLOAD_HANDLER__) \ || defined(__EDKII_GLUE_UEFI_DRIVER_MODEL_LIB__) \ || defined(__EDKII_GLUE_EDK_DXE_RUNTIME_DRIVER_LIB__) ) \ || __EDKII_GLUE_HAVE_DRIVER_EXIT_BOOT_SERVICES_EVENT__ do { EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; Status = SystemTable->BootServices->HandleProtocol ( ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&LoadedImage ); ASSERT_EFI_ERROR (Status); LoadedImage->Unload = _DriverUnloadHandler; } while(0); #endif // // Call the driver entry point // #ifdef __EDKII_GLUE_MODULE_ENTRY_POINT__ Status = (__EDKII_GLUE_MODULE_ENTRY_POINT__ (ImageHandle, SystemTable)); #else Status = EFI_SUCCESS; #endif // // If all of the drivers returned errors, then invoke all of the library destructors // if (EFI_ERROR (Status)) { // // Close our ExitBootServices () notify function // #if __EDKII_GLUE_HAVE_DRIVER_EXIT_BOOT_SERVICES_EVENT__ if (_gDriverExitBootServicesEvent[0] != NULL) { EFI_STATUS CloseEventStatus; CloseEventStatus = SystemTable->BootServices->CloseEvent (_mDriverExitBootServicesNotifyEvent); ASSERT_EFI_ERROR (CloseEventStatus); } #endif ProcessLibraryDestructorList (ImageHandle, SystemTable); } // // Return the cummalative return status code from all of the driver entry points // return Status; }