mirror of
https://github.com/memtest86plus/memtest86plus.git
synced 2026-11-24 23:18:39 -06:00
Before calling ExitBootServices(), Memtest86+ obtains the memory map and resizes its buffer if it is too small or lacks the required headroom. If ExitBootServices() returns EFI_INVALID_PARAMETER, Memtest86+ calls GetMemoryMap() again using the same buffer, then retries ExitBootServices(). This retry path does not resize the buffer. If GetMemoryMap() returns EFI_BUFFER_TOO_SMALL, Memtest86+ stops in efi_setup() without making a second call to ExitBootServices(). This failure was observed on a TD622E0 system with two Loongson 3C6000/D processors and multiple peripherals, running EDK2 202602-based firmware. Device-related event callbacks or other firmware operations may change the memory map during the exit sequence and invalidate the MapKey. The initial GetMemoryMap() call reports a required buffer size of 0x2f40 bytes and a descriptor size of 0x30 bytes. With eight spare descriptors, Memtest86+ allocates 0x30c0 bytes. After the first exit attempt fails, the map query reports a required size of 0x3180 bytes. This exceeds the buffer capacity by four descriptor slots. Increase the reserve to sixteen descriptors, providing 0x3240 bytes for this sequence. This adds 384 bytes of headroom with 48-byte descriptors and keeps all buffer allocations before the first ExitBootServices() call. UEFI 2.8 Errata A and modern EDK2 allow memory allocation after a failed exit, but retaining the existing retry policy avoids relying on that behavior for compatibility with older firmware. REF: https://uefi.org/specs/UEFI/2.10/Frontmatter/Revision_History.html > Memory allocations between ExitBootServices calls Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn>