Ring3: Added comments and sanity checks.

This commit is contained in:
Mikhail Krichanov 2025-02-03 12:26:31 +03:00
parent 9247588149
commit 428b43de40
4 changed files with 24 additions and 2 deletions

View File

@ -67,8 +67,6 @@ FixInterface (
LoadedImage = (EFI_LOADED_IMAGE_PROTOCOL *)*Interface; LoadedImage = (EFI_LOADED_IMAGE_PROTOCOL *)*Interface;
// TODO: Copy User changes to Core? Resembles InstallMultipleProtocolInterfaces().
LoadedImage->Unload = NULL; LoadedImage->Unload = NULL;
} else if (CompareGuid (Protocol, &gEfiBlockIoProtocolGuid)) { } else if (CompareGuid (Protocol, &gEfiBlockIoProtocolGuid)) {

View File

@ -1350,6 +1350,9 @@ CoreLoadImageCommon (
Image->IsUserImage = (FileAttributes & EFI_FV_FILE_ATTRIB_USER) != 0; Image->IsUserImage = (FileAttributes & EFI_FV_FILE_ATTRIB_USER) != 0;
if ((!PcdGetBool (PcdEnableUserSpace)) && Image->IsUserImage && mDxeRing3) { if ((!PcdGetBool (PcdEnableUserSpace)) && Image->IsUserImage && mDxeRing3) {
//
// Do not load DxeRing3 driver, if UserSpace is disabled.
//
mDxeRing3 = FALSE; mDxeRing3 = FALSE;
Status = EFI_NOT_STARTED; Status = EFI_NOT_STARTED;
goto Done; goto Done;
@ -1976,6 +1979,10 @@ CoreUnloadImage (
// //
Status = EFI_UNSUPPORTED; Status = EFI_UNSUPPORTED;
if (Image->Info.Unload != NULL) { if (Image->Info.Unload != NULL) {
//
// TODO: If Image->IsUserImage, use FindInterface() to locate UserSpace
// EFI_LOADED_IMAGE_PROTOCOL->Unload() and GoToRing3().
//
Status = Image->Info.Unload (ImageHandle); Status = Image->Info.Unload (ImageHandle);
} }
} else { } else {

View File

@ -37,11 +37,18 @@ SysCallBootService (
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN *UserArguments; UINTN *UserArguments;
UINT64 Attributes;
ArmEnableInterrupts (); ArmEnableInterrupts ();
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)Context.SystemContextAArch64->SP_EL0, &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
UserArguments = (UINTN *)(Context.SystemContextAArch64->SP_EL0 - 7 * sizeof (UINTN)); UserArguments = (UINTN *)(Context.SystemContextAArch64->SP_EL0 - 7 * sizeof (UINTN));
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)(UINTN)UserArguments, &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
AllowSupervisorAccessToUserMemory (); AllowSupervisorAccessToUserMemory ();
// //
// First 6 arguments are passed through X2-X7 and copied to Core stack, // First 6 arguments are passed through X2-X7 and copied to Core stack,

View File

@ -38,6 +38,7 @@ SysCallBootService (
UINT8 Type; UINT8 Type;
UINT8 NumberOfArguments; UINT8 NumberOfArguments;
UINTN *UserArguments; UINTN *UserArguments;
UINT64 Attributes;
ArmEnableInterrupts (); ArmEnableInterrupts ();
@ -52,6 +53,9 @@ SysCallBootService (
++NumberOfArguments; ++NumberOfArguments;
} }
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)Context.SystemContextArm->SP, &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
AllowSupervisorAccessToUserMemory (); AllowSupervisorAccessToUserMemory ();
if (Type == SysCallFreePages) { if (Type == SysCallFreePages) {
// //
@ -61,6 +65,9 @@ SysCallBootService (
// //
UserArguments = (UINTN *)(Context.SystemContextArm->SP - 2 * sizeof (UINTN)); UserArguments = (UINTN *)(Context.SystemContextArm->SP - 2 * sizeof (UINTN));
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)(UINTN)UserArguments, &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
CopyMem ( CopyMem (
(VOID *)UserArguments, (VOID *)UserArguments,
(VOID *)&(Context.SystemContextArm->R1), (VOID *)&(Context.SystemContextArm->R1),
@ -73,6 +80,9 @@ SysCallBootService (
// //
UserArguments = (UINTN *)(Context.SystemContextArm->SP - 3 * sizeof (UINTN)); UserArguments = (UINTN *)(Context.SystemContextArm->SP - 3 * sizeof (UINTN));
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)(UINTN)UserArguments, &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
CopyMem ( CopyMem (
(VOID *)UserArguments, (VOID *)UserArguments,
(VOID *)&(Context.SystemContextArm->R1), (VOID *)&(Context.SystemContextArm->R1),