mirror of
https://github.com/ipxe/ipxe
synced 2025-12-27 10:02:42 +03:00
[efi] Separate GetMemoryMap() wrapper from shim unlocker
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -90,23 +90,13 @@ struct image_tag efi_shim __image_tag = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** Original GetMemoryMap() function */
|
/** Original GetMemoryMap() function */
|
||||||
static EFI_GET_MEMORY_MAP efi_shim_orig_map;
|
static EFI_GET_MEMORY_MAP efi_shim_orig_get_memory_map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlock UEFI shim
|
* Unlock UEFI shim
|
||||||
*
|
*
|
||||||
* @v len Memory map size
|
|
||||||
* @v map Memory map
|
|
||||||
* @v key Memory map key
|
|
||||||
* @v desclen Descriptor size
|
|
||||||
* @v descver Descriptor version
|
|
||||||
* @ret efirc EFI status code
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
static EFIAPI EFI_STATUS efi_shim_unlock ( UINTN *len,
|
static void efi_shim_unlock ( void ) {
|
||||||
EFI_MEMORY_DESCRIPTOR *map,
|
|
||||||
UINTN *key, UINTN *desclen,
|
|
||||||
UINT32 *descver ) {
|
|
||||||
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
||||||
uint8_t empty[0];
|
uint8_t empty[0];
|
||||||
union {
|
union {
|
||||||
@@ -121,9 +111,30 @@ static EFIAPI EFI_STATUS efi_shim_unlock ( UINTN *len,
|
|||||||
u.lock->Verify ( empty, sizeof ( empty ) );
|
u.lock->Verify ( empty, sizeof ( empty ) );
|
||||||
DBGC ( &efi_shim, "SHIM unlocked via %p\n", u.lock );
|
DBGC ( &efi_shim, "SHIM unlocked via %p\n", u.lock );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap GetMemoryMap()
|
||||||
|
*
|
||||||
|
* @v len Memory map size
|
||||||
|
* @v map Memory map
|
||||||
|
* @v key Memory map key
|
||||||
|
* @v desclen Descriptor size
|
||||||
|
* @v descver Descriptor version
|
||||||
|
* @ret efirc EFI status code
|
||||||
|
*/
|
||||||
|
static EFIAPI EFI_STATUS efi_shim_get_memory_map ( UINTN *len,
|
||||||
|
EFI_MEMORY_DESCRIPTOR *map,
|
||||||
|
UINTN *key, UINTN *desclen,
|
||||||
|
UINT32 *descver ) {
|
||||||
|
|
||||||
|
/* Unlock shim */
|
||||||
|
if ( ! efi_shim_require_loader )
|
||||||
|
efi_shim_unlock();
|
||||||
|
|
||||||
/* Hand off to original GetMemoryMap() */
|
/* Hand off to original GetMemoryMap() */
|
||||||
return efi_shim_orig_map ( len, map, key, desclen, descver );
|
return efi_shim_orig_get_memory_map ( len, map, key, desclen,
|
||||||
|
descver );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -216,27 +227,23 @@ int efi_shim_install ( struct image *shim, EFI_HANDLE handle,
|
|||||||
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Intercept GetMemoryMap() via boot services table */
|
|
||||||
efi_shim_orig_map = bs->GetMemoryMap;
|
|
||||||
if ( ! efi_shim_require_loader )
|
|
||||||
bs->GetMemoryMap = efi_shim_unlock;
|
|
||||||
|
|
||||||
/* Stop PXE base code */
|
/* Stop PXE base code */
|
||||||
if ( ( ! efi_shim_allow_pxe ) &&
|
if ( ( ! efi_shim_allow_pxe ) &&
|
||||||
( ( rc = efi_shim_inhibit_pxe ( handle ) ) != 0 ) ) {
|
( ( rc = efi_shim_inhibit_pxe ( handle ) ) != 0 ) ) {
|
||||||
goto err_inhibit_pxe;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update command line */
|
/* Update command line */
|
||||||
if ( ( rc = efi_shim_cmdline ( shim, cmdline ) ) != 0 )
|
if ( ( rc = efi_shim_cmdline ( shim, cmdline ) ) != 0 )
|
||||||
goto err_cmdline;
|
return rc;
|
||||||
|
|
||||||
|
/* Record original boot services functions */
|
||||||
|
efi_shim_orig_get_memory_map = bs->GetMemoryMap;
|
||||||
|
|
||||||
|
/* Wrap relevant boot services functions */
|
||||||
|
bs->GetMemoryMap = efi_shim_get_memory_map;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_cmdline:
|
|
||||||
err_inhibit_pxe:
|
|
||||||
bs->GetMemoryMap = efi_shim_orig_map;
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,6 +253,6 @@ int efi_shim_install ( struct image *shim, EFI_HANDLE handle,
|
|||||||
void efi_shim_uninstall ( void ) {
|
void efi_shim_uninstall ( void ) {
|
||||||
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
||||||
|
|
||||||
/* Restore original GetMemoryMap() */
|
/* Restore original boot services functions */
|
||||||
bs->GetMemoryMap = efi_shim_orig_map;
|
bs->GetMemoryMap = efi_shim_orig_get_memory_map;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user