Exit()service is typically only used by UEFI applications. UEFI drivers usually have simple driver entry point implementations and typically return an
EFI_STATUScode from their entry point function. This is the recommended style for UEFI driver implementations. If
EFI_SUCCESSis 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.
Exit()service allows a UEFI image to exit without having to return an
EFI_STATUSvalue 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
UefiBootServicesTableLibprovides the global
gBS―a pointer to the UEFI Boot Services Table and
gImageHandle―the Image Handle of the currently executing UEFI image.
// Exit the current UEFI image with a status of EFI_UNSUPPORTED
gBS->Exit (gImageHandle, EFI_UNSUPPORTED, 0, NULL);