UefiCpuPkg: Fixed stack corruption.

This commit is contained in:
Mikhail Krichanov 2025-03-04 16:48:34 +03:00
parent b3bf2495f3
commit 2068113e8b

View File

@ -659,6 +659,7 @@ InitializeMpExceptionStackSwitchHandlers (
UINTN BufferSize; UINTN BufferSize;
EFI_STATUS Status; EFI_STATUS Status;
UINT8 *Buffer; UINT8 *Buffer;
EFI_PHYSICAL_ADDRESS BufferAddress;
SwitchStackData = AllocateZeroPool (mNumberOfProcessors * sizeof (EXCEPTION_STACK_SWITCH_CONTEXT)); SwitchStackData = AllocateZeroPool (mNumberOfProcessors * sizeof (EXCEPTION_STACK_SWITCH_CONTEXT));
if (SwitchStackData == NULL) { if (SwitchStackData == NULL) {
@ -697,12 +698,12 @@ InitializeMpExceptionStackSwitchHandlers (
// we are allocating the buffer that will hold the new GDT and IDT for the APs. These must be allocated below // we are allocating the buffer that will hold the new GDT and IDT for the APs. These must be allocated below
// 4GB as they are used by protected mode code on the APs when they are started up after this point. If they are // 4GB as they are used by protected mode code on the APs when they are started up after this point. If they are
// above 4GB, the APs will triple fault because the 32 bit code segment is invalid // above 4GB, the APs will triple fault because the 32 bit code segment is invalid
Buffer = (UINT8 *)(UINTN)(BASE_4GB - 1); BufferAddress = BASE_4GB - 1;
Status = gBS->AllocatePages ( Status = gBS->AllocatePages (
AllocateMaxAddress, AllocateMaxAddress,
EfiRuntimeServicesData, EfiRuntimeServicesData,
EFI_SIZE_TO_PAGES (BufferSize), EFI_SIZE_TO_PAGES (BufferSize),
(EFI_PHYSICAL_ADDRESS *)&Buffer &BufferAddress
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed to allocate buffer for InitializeExceptionStackSwitchHandlers Status %r\n", Status)); DEBUG ((DEBUG_ERROR, "Failed to allocate buffer for InitializeExceptionStackSwitchHandlers Status %r\n", Status));
@ -710,6 +711,8 @@ InitializeMpExceptionStackSwitchHandlers (
goto Exit; goto Exit;
} }
Buffer = (UINT8 *)(UINTN)BufferAddress;
ZeroMem (Buffer, BufferSize); ZeroMem (Buffer, BufferSize);
BufferSize = 0; BufferSize = 0;