Skip to content

efi: Correct image unloading behavior

Mate Kukri requested to merge peimage-unload into master
  • In peimage.c, we're responsible for unloading images after they exit, so let's do that.

  • Reading the edk2 code confirms my suspicion that the Unload pointer of the EFI_LOADED_IMAGE_PROTOCOL is strictly a cleanup callback that drivers can register, to be called upon they are unloaded by other code. This isn't relevant for applications as they don't stay laoded after their main function has returned, so let's set it to NULL.

  • Even if we did want to support drivers, the current behavior is wrong. We shouldn't be the one setting this pointer, but instead be calling it in a system table UnloadImage hook.

  • Without driver support, we don't need to care about this pointer, nor do we need to install an UnloadImage hook as images cannot unload themselves. (this isn't specified but it is a safe assumption given EDK2's implementation doesn't even check for this and would just return into the middle of invalid memory).

Merge request reports

Loading