/* * Return the number of slots covered by this entry, i.e., the number of * addresses it covers that are suitably aligned and supply enough room * for the allocation.
*/ staticunsignedlong get_entry_num_slots(efi_memory_desc_t *md, unsignedlong size, unsignedlong align_shift,
u64 alloc_min, u64 alloc_max)
{ unsignedlong align = 1UL << align_shift;
u64 first_slot, last_slot, region_end;
if (md->type != EFI_CONVENTIONAL_MEMORY) return 0;
if (md->attribute & EFI_MEMORY_HOT_PLUGGABLE) return 0;
if (efi_soft_reserve_enabled() &&
(md->attribute & EFI_MEMORY_SP)) return 0;
/* * The UEFI memory descriptors have a virtual address field that is only used * when installing the virtual mapping using SetVirtualAddressMap(). Since it * is unused here, we can reuse it to keep track of each descriptor's slot * count.
*/ #define MD_NUM_SLOTS(md) ((md)->virt_addr)
/* consider only mirrored slots for randomization if any exist */ if (total_mirrored_slots > 0)
total_slots = total_mirrored_slots;
/* find a random number between 0 and total_slots */
target_slot = (total_slots * (u64)(random_seed & U32_MAX)) >> 32;
/* * target_slot is now a value in the range [0, total_slots), and so * it corresponds with exactly one of the suitable slots we recorded * when iterating over the memory map the first time around. * * So iterate over the memory map again, subtracting the number of * slots of each entry at each iteration, until we have found the entry * that covers our chosen slot. Use the residual value of target_slot * to calculate the randomly chosen address, and allocate it directly * using EFI_ALLOCATE_ADDRESS.
*/
status = EFI_OUT_OF_RESOURCES; for (map_offset = 0; map_offset < map->map_size; map_offset += map->desc_size) {
efi_memory_desc_t *md = (void *)map->map + map_offset;
efi_physical_addr_t target; unsignedlong pages;
if (total_mirrored_slots > 0 &&
!(md->attribute & EFI_MEMORY_MORE_RELIABLE)) continue;
if (target_slot >= MD_NUM_SLOTS(md)) {
target_slot -= MD_NUM_SLOTS(md); continue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.