@@ -85,6 +85,17 @@ efi_status_t efi_get_system_config_table(efi_guid_t table_guid, void **table)
return EFI_NOT_FOUND;
}
+static void efi_exit(efi_status_t code)
+{
+ exit(code);
+
+ /*
+ * Fallback to UEFI reset_system() service, in case testdev is
+ * missing and exit() does not properly exit.
+ */
+ efi_rs_call(reset_system, EFI_RESET_SHUTDOWN, code, 0, NULL);
+}
+
efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab)
{
int ret;
@@ -134,14 +145,14 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab)
ret = main(__argc, __argv, __environ);
/* Shutdown the guest VM */
- efi_rs_call(reset_system, EFI_RESET_SHUTDOWN, ret, 0, NULL);
+ efi_exit(ret);
/* Unreachable */
return EFI_UNSUPPORTED;
efi_main_error:
/* Shutdown the guest with error EFI status */
- efi_rs_call(reset_system, EFI_RESET_SHUTDOWN, status, 0, NULL);
+ efi_exit(status);
/* Unreachable */
return EFI_UNSUPPORTED;