Ring3: Moved UINT64 arguments to the end of argument list to fix IA32 stack.

This commit is contained in:
Mikhail Krichanov 2024-03-25 11:56:13 +03:00
parent c1fc70dc07
commit 3055d657eb
3 changed files with 59 additions and 63 deletions

View File

@ -35,9 +35,9 @@ Ring3BlockIoRead (
SysCallBlockIoRead, SysCallBlockIoRead,
This, This,
MediaId, MediaId,
Lba,
BufferSize, BufferSize,
Buffer Buffer,
Lba
); );
} }
@ -55,9 +55,9 @@ Ring3BlockIoWrite (
SysCallBlockIoWrite, SysCallBlockIoWrite,
This, This,
MediaId, MediaId,
Lba,
BufferSize, BufferSize,
Buffer Buffer,
Lba
); );
} }
@ -87,9 +87,9 @@ Ring3DiskIoRead (
SysCallDiskIoRead, SysCallDiskIoRead,
This, This,
MediaId, MediaId,
Offset,
BufferSize, BufferSize,
Buffer Buffer,
Offset
); );
} }
@ -107,9 +107,9 @@ Ring3DiskIoWrite (
SysCallDiskIoWrite, SysCallDiskIoWrite,
This, This,
MediaId, MediaId,
Offset,
BufferSize, BufferSize,
Buffer Buffer,
Offset
); );
} }

View File

@ -150,8 +150,8 @@ Ring3FreePages (
Status = SysCall ( Status = SysCall (
SysCallFreePages, SysCallFreePages,
Memory, NumberOfPages,
NumberOfPages Memory
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Ring3: Failed to free %d pages.\n", NumberOfPages)); DEBUG ((DEBUG_ERROR, "Ring3: Failed to free %d pages.\n", NumberOfPages));
@ -594,7 +594,7 @@ Ring3LocateHandleBuffer (
Buffer Buffer
); );
if ((NumberHandles != NULL) && (Buffer != NULL) && (*Buffer != NULL)) { if ((NumberHandles != NULL) && (*NumberHandles != 0) && (Buffer != NULL) && (*Buffer != NULL)) {
PoolSize = *NumberHandles * sizeof (EFI_HANDLE *); PoolSize = *NumberHandles * sizeof (EFI_HANDLE *);
Status = CoreAllocatePool (EfiRing3MemoryType, PoolSize, &Pool); Status = CoreAllocatePool (EfiRing3MemoryType, PoolSize, &Pool);

View File

@ -565,17 +565,17 @@ CallBootService (
case SysCallFreePages: case SysCallFreePages:
// //
// Argument 1: EFI_PHYSICAL_ADDRESS Memory // Argument 1: UINTN NumberOfPages
// Argument 2: UINTN NumberOfPages // Argument 2: EFI_PHYSICAL_ADDRESS Memory
// //
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)CoreRbp->Argument1, &Attributes); gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)CoreRbp->Argument2, &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)(CoreRbp->Argument1 + CoreRbp->Argument2 * EFI_PAGE_SIZE - 1), &Attributes); gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)(CoreRbp->Argument2 + CoreRbp->Argument1 * EFI_PAGE_SIZE - 1), &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
return gBS->FreePages ( return gBS->FreePages (
(EFI_PHYSICAL_ADDRESS)CoreRbp->Argument1, *(EFI_PHYSICAL_ADDRESS *)&CoreRbp->Argument2,
CoreRbp->Argument2 CoreRbp->Argument1
); );
case SysCallRaiseTpl: case SysCallRaiseTpl:
@ -811,9 +811,9 @@ CallBootService (
// //
// Argument 1: EFI_BLOCK_IO_PROTOCOL *This // Argument 1: EFI_BLOCK_IO_PROTOCOL *This
// Argument 2: UINT32 MediaId // Argument 2: UINT32 MediaId
// Argument 3: EFI_LBA Lba // Argument 3: UINTN BufferSize
// Argument 4: UINTN BufferSize // Argument 4: VOID *Buffer
// Argument 5: VOID *Buffer // Argument 5: EFI_LBA Lba
// //
BlockIo = FindInterface (FALSE, (VOID *)CoreRbp->Argument1); BlockIo = FindInterface (FALSE, (VOID *)CoreRbp->Argument1);
@ -825,10 +825,10 @@ CallBootService (
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
DisableSMAP (); DisableSMAP ();
Argument4 = UserRsp->Arguments[4]; Attributes = *(UINT64 *)&UserRsp->Arguments[5];
EnableSMAP (); EnableSMAP ();
Argument5 = (UINTN)AllocatePool (Argument4); Argument5 = (UINTN)AllocatePool (CoreRbp->Argument3);
if ((VOID *)Argument5 == NULL) { if ((VOID *)Argument5 == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -836,17 +836,17 @@ CallBootService (
Status = BlockIo->ReadBlocks ( Status = BlockIo->ReadBlocks (
BlockIo, BlockIo,
(UINT32)CoreRbp->Argument2, (UINT32)CoreRbp->Argument2,
(EFI_LBA)CoreRbp->Argument3, (EFI_LBA)Attributes,
Argument4, CoreRbp->Argument3,
(VOID *)Argument5 (VOID *)Argument5
); );
DisableSMAP (); DisableSMAP ();
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)UserRsp->Arguments[5], &Attributes); gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)UserRsp->Arguments[4], &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)((UINTN)UserRsp->Arguments[5] + Argument4 - 1), &Attributes); gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)((UINTN)UserRsp->Arguments[4] + CoreRbp->Argument3 - 1), &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
CopyMem ((VOID *)UserRsp->Arguments[5], (VOID *)Argument5, Argument4); CopyMem ((VOID *)UserRsp->Arguments[4], (VOID *)Argument5, CoreRbp->Argument3);
EnableSMAP (); EnableSMAP ();
FreePool ((VOID *)Argument5); FreePool ((VOID *)Argument5);
@ -857,9 +857,9 @@ CallBootService (
// //
// Argument 1: EFI_BLOCK_IO_PROTOCOL *This // Argument 1: EFI_BLOCK_IO_PROTOCOL *This
// Argument 2: UINT32 MediaId // Argument 2: UINT32 MediaId
// Argument 3: EFI_LBA Lba // Argument 3: UINTN BufferSize
// Argument 4: UINTN BufferSize // Argument 4: VOID *Buffer
// Argument 5: VOID *Buffer // Argument 5: EFI_LBA Lba
// //
BlockIo = FindInterface (FALSE, (VOID *)CoreRbp->Argument1); BlockIo = FindInterface (FALSE, (VOID *)CoreRbp->Argument1);
@ -870,29 +870,27 @@ CallBootService (
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)((UINTN)UserRsp + 7 * sizeof (UINTN) - 1), &Attributes); gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)((UINTN)UserRsp + 7 * sizeof (UINTN) - 1), &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
DisableSMAP (); Argument5 = (UINTN)AllocatePool (CoreRbp->Argument3);
Argument4 = UserRsp->Arguments[4];
EnableSMAP ();
Argument5 = (UINTN)AllocatePool (Argument4);
if ((VOID *)Argument5 == NULL) { if ((VOID *)Argument5 == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
DisableSMAP (); DisableSMAP ();
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)UserRsp->Arguments[5], &Attributes); gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)UserRsp->Arguments[4], &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)((UINTN)UserRsp->Arguments[5] + Argument4 - 1), &Attributes); gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)((UINTN)UserRsp->Arguments[4] + CoreRbp->Argument3 - 1), &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
CopyMem ((VOID *)Argument5,(VOID *)UserRsp->Arguments[5], Argument4); CopyMem ((VOID *)Argument5,(VOID *)UserRsp->Arguments[4], CoreRbp->Argument3);
Attributes = *(UINT64 *)&UserRsp->Arguments[5];
EnableSMAP (); EnableSMAP ();
Status = BlockIo->WriteBlocks ( Status = BlockIo->WriteBlocks (
BlockIo, BlockIo,
(UINT32)CoreRbp->Argument2, (UINT32)CoreRbp->Argument2,
(EFI_LBA)CoreRbp->Argument3, (EFI_LBA)Attributes,
Argument4, CoreRbp->Argument3,
(VOID *)Argument5 (VOID *)Argument5
); );
@ -916,9 +914,9 @@ CallBootService (
// //
// Argument 1: EFI_DISK_IO_PROTOCOL *This // Argument 1: EFI_DISK_IO_PROTOCOL *This
// Argument 2: UINT32 MediaId // Argument 2: UINT32 MediaId
// Argument 3: UINT64 Offset // Argument 3: UINTN BufferSize
// Argument 4: UINTN BufferSize // Argument 4: VOID *Buffer
// Argument 5: VOID *Buffer // Argument 5: UINT64 Offset
// //
DiskIo = FindInterface (FALSE, (VOID *)CoreRbp->Argument1); DiskIo = FindInterface (FALSE, (VOID *)CoreRbp->Argument1);
@ -930,10 +928,10 @@ CallBootService (
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
DisableSMAP (); DisableSMAP ();
Argument4 = UserRsp->Arguments[4]; Attributes = *(UINT64 *)&UserRsp->Arguments[5];
EnableSMAP (); EnableSMAP ();
Argument5 = (UINTN)AllocatePool (Argument4); Argument5 = (UINTN)AllocatePool (CoreRbp->Argument3);
if ((VOID *)Argument5 == NULL) { if ((VOID *)Argument5 == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -941,17 +939,17 @@ CallBootService (
Status = DiskIo->ReadDisk ( Status = DiskIo->ReadDisk (
DiskIo, DiskIo,
(UINT32)CoreRbp->Argument2, (UINT32)CoreRbp->Argument2,
(UINT64)CoreRbp->Argument3, Attributes,
Argument4, CoreRbp->Argument3,
(VOID *)Argument5 (VOID *)Argument5
); );
DisableSMAP (); DisableSMAP ();
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)UserRsp->Arguments[5], &Attributes); gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)UserRsp->Arguments[4], &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)((UINTN)UserRsp->Arguments[5] + Argument4 - 1), &Attributes); gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)((UINTN)UserRsp->Arguments[4] + CoreRbp->Argument3 - 1), &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
CopyMem ((VOID *)UserRsp->Arguments[5], (VOID *)Argument5, Argument4); CopyMem ((VOID *)UserRsp->Arguments[4], (VOID *)Argument5, CoreRbp->Argument3);
EnableSMAP (); EnableSMAP ();
FreePool ((VOID *)Argument5); FreePool ((VOID *)Argument5);
@ -962,9 +960,9 @@ CallBootService (
// //
// Argument 1: EFI_DISK_IO_PROTOCOL *This // Argument 1: EFI_DISK_IO_PROTOCOL *This
// Argument 2: UINT32 MediaId // Argument 2: UINT32 MediaId
// Argument 3: UINT64 Offset // Argument 3: UINTN BufferSize
// Argument 4: UINTN BufferSize // Argument 4: VOID *Buffer
// Argument 5: VOID *Buffer // Argument 5: UINT64 Offset
// //
DiskIo = FindInterface (FALSE, (VOID *)CoreRbp->Argument1); DiskIo = FindInterface (FALSE, (VOID *)CoreRbp->Argument1);
@ -975,29 +973,27 @@ CallBootService (
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)((UINTN)UserRsp + 7 * sizeof (UINTN) - 1), &Attributes); gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)((UINTN)UserRsp + 7 * sizeof (UINTN) - 1), &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
DisableSMAP (); Argument5 = (UINTN)AllocatePool (CoreRbp->Argument3);
Argument4 = UserRsp->Arguments[4];
EnableSMAP ();
Argument5 = (UINTN)AllocatePool (Argument4);
if ((VOID *)Argument5 == NULL) { if ((VOID *)Argument5 == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
DisableSMAP (); DisableSMAP ();
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)UserRsp->Arguments[5], &Attributes); gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)UserRsp->Arguments[4], &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)((UINTN)UserRsp->Arguments[5] + Argument4 - 1), &Attributes); gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)((UINTN)UserRsp->Arguments[4] + CoreRbp->Argument3 - 1), &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
CopyMem ((VOID *)Argument5, (VOID *)UserRsp->Arguments[5], Argument4); CopyMem ((VOID *)Argument5, (VOID *)UserRsp->Arguments[4], CoreRbp->Argument3);
Attributes = *(UINT64 *)&UserRsp->Arguments[5];
EnableSMAP (); EnableSMAP ();
Status = DiskIo->WriteDisk ( Status = DiskIo->WriteDisk (
DiskIo, DiskIo,
(UINT32)CoreRbp->Argument2, (UINT32)CoreRbp->Argument2,
(UINT64)CoreRbp->Argument3, Attributes,
Argument4, CoreRbp->Argument3,
(VOID *)Argument5 (VOID *)Argument5
); );