5.3.17 Exit()

The Exit() service is typically only used by UEFI applications. UEFI drivers usually have simple driver entry point implementations and typically return an EFI_STATUS code from their entry point function. This is the recommended style for UEFI driver implementations. If EFI_SUCCESS is returned by a UEFI driver, then the UEFI driver remains loaded in system memory. If an error status is returned, then the UEFI driver is unloaded from system memory.

The Exit() service allows a UEFI image to exit without having to return an EFI_STATUS value from the UEFI image's entry point. A UEFI driver with more complex logic in its entry point may discover a condition that requires the UEFI driver to exit immediately. In this rare condition, the Exit() service could be used. However, the UEFI driver implementation must take care to free any allocated resources and uninstall all protocols before returning an error code through the Exit() service. The following example shows how the Exit() service could be used by a UEFI driver to exit with a status code of EFI_UNSUPPORTED. The EDK II library UefiBootServicesTableLib provides the global gBS―a pointer to the UEFI Boot Services Table and gImageHandle―the Image Handle of the currently executing UEFI image.

Example 85-Exit from a UEFI Driver
#include <Uefi.h>
#include <Library/UefiBootServicesTableLib.h>

//
// Exit the current UEFI image with a status of EFI_UNSUPPORTED
//
gBS->Exit (gImageHandle, EFI_UNSUPPORTED, 0, NULL);