Ring3: Added SysCallGetVariable wrapper.

This commit is contained in:
Mikhail Krichanov 2024-03-11 13:07:10 +03:00
parent 81e1df054f
commit e3f3d64eb5
7 changed files with 123 additions and 16 deletions

View File

@ -133,6 +133,7 @@
gEfiEndOfDxeEventGroupGuid ## SOMETIMES_CONSUMES ## Event gEfiEndOfDxeEventGroupGuid ## SOMETIMES_CONSUMES ## Event
gEfiHobMemoryAllocStackGuid ## SOMETIMES_CONSUMES ## SystemTable gEfiHobMemoryAllocStackGuid ## SOMETIMES_CONSUMES ## SystemTable
gUefiImageLoaderImageContextGuid ## CONSUMES ## HOB gUefiImageLoaderImageContextGuid ## CONSUMES ## HOB
gEfiGlobalVariableGuid ## SOMETIMES_CONSUMES ## SysCall
[Ppis] [Ppis]
gEfiVectorHandoffInfoPpiGuid ## UNDEFINED # HOB gEfiVectorHandoffInfoPpiGuid ## UNDEFINED # HOB

View File

@ -9,6 +9,7 @@
#include <Library/BaseMemoryLib.h> #include <Library/BaseMemoryLib.h>
#include <Library/MemoryPoolLib.h> #include <Library/MemoryPoolLib.h>
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include "Ring3.h" #include "Ring3.h"
@ -200,10 +201,12 @@ Ring3Initialization (
Ring3Data = (RING3_DATA *)SystemTable; Ring3Data = (RING3_DATA *)SystemTable;
Ring3Data->EntryPoint = (VOID *)Ring3EntryPoint; Ring3Data->EntryPoint = (VOID *)Ring3EntryPoint;
Ring3Data->BootServices = &mBootServices; Ring3Data->BootServices = &mBootServices;
Ring3Data->RuntimeServices = &mRuntimeServices;
gBS = &mBootServices; gBS = &mBootServices;
gRT = &mRuntimeServices;
CoreInitializePool (); CoreInitializePool ();

View File

@ -42,6 +42,7 @@
MemoryPoolLib MemoryPoolLib
UefiBootServicesTableLib UefiBootServicesTableLib
UefiDriverEntryPoint UefiDriverEntryPoint
UefiRuntimeServicesTableLib
[Protocols] [Protocols]
gEfiDevicePathUtilitiesProtocolGuid ## SOMETIMES_CONSUMES gEfiDevicePathUtilitiesProtocolGuid ## SOMETIMES_CONSUMES

View File

@ -89,9 +89,14 @@ Ring3GetVariable (
OUT VOID *Data OPTIONAL OUT VOID *Data OPTIONAL
) )
{ {
DEBUG ((DEBUG_ERROR, "Ring3: GetVariable is not supported\n")); return SysCall (
SysCallGetVariable,
return EFI_UNSUPPORTED; VariableName,
VendorGuid,
Attributes,
DataSize,
Data
);
} }
EFI_STATUS EFI_STATUS

View File

@ -1611,7 +1611,8 @@ InitializeRing3 (
gRing3EntryPoint = gRing3Data->EntryPoint; gRing3EntryPoint = gRing3Data->EntryPoint;
gRing3Data->SystemTable.BootServices = gRing3Data->BootServices; gRing3Data->SystemTable.BootServices = gRing3Data->BootServices;
gRing3Data->SystemTable.RuntimeServices = gRing3Data->RuntimeServices;
Status = CoreAllocatePages ( Status = CoreAllocatePages (
AllocateAnyPages, AllocateAnyPages,

View File

@ -85,6 +85,10 @@ FindGuid (
*Core = &gEfiUnicodeCollationProtocolGuid; *Core = &gEfiUnicodeCollationProtocolGuid;
*CoreSize = sizeof (EFI_UNICODE_COLLATION_PROTOCOL); *CoreSize = sizeof (EFI_UNICODE_COLLATION_PROTOCOL);
} else if (CompareGuid (Ring3, &gEfiGlobalVariableGuid)) {
*Core = &gEfiGlobalVariableGuid;
} else { } else {
DEBUG ((DEBUG_ERROR, "Ring0: Unknown protocol - %g.\n", Ring3)); DEBUG ((DEBUG_ERROR, "Ring0: Unknown protocol - %g.\n", Ring3));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
@ -533,8 +537,8 @@ CallBootService (
// //
// Argument 1: EFI_LOCATE_SEARCH_TYPE SearchType // Argument 1: EFI_LOCATE_SEARCH_TYPE SearchType
// Argument 2: EFI_GUID *Protocol OPTIONAL // Argument 2: EFI_GUID *Protocol OPTIONAL
// Argument 3: VOID *SearchKey OPTIONAL, // Argument 3: VOID *SearchKey OPTIONAL
// Argument 4: UINTN *NumberHandles, // Argument 4: UINTN *NumberHandles
// Argument 5: EFI_HANDLE **Buffer // Argument 5: EFI_HANDLE **Buffer
// //
if ((EFI_GUID *)CoreRbp->Argument2 != NULL) { if ((EFI_GUID *)CoreRbp->Argument2 != NULL) {
@ -581,11 +585,11 @@ CallBootService (
PagesNumber = EFI_SIZE_TO_PAGES (Argument4 * sizeof (EFI_HANDLE *)); PagesNumber = EFI_SIZE_TO_PAGES (Argument4 * sizeof (EFI_HANDLE *));
Status = CoreAllocatePages ( Status = CoreAllocatePages (
AllocateAnyPages, AllocateAnyPages,
EfiRing3MemoryType, EfiRing3MemoryType,
PagesNumber, PagesNumber,
(EFI_PHYSICAL_ADDRESS *)&Ring3Pages (EFI_PHYSICAL_ADDRESS *)&Ring3Pages
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
@ -600,6 +604,96 @@ CallBootService (
return StatusBS; return StatusBS;
case SysCallGetVariable:
//
// Argument 1: CHAR16 *VariableName
// Argument 2: EFI_GUID *VendorGuid
// Argument 3: UINT32 *Attributes OPTIONAL
// Argument 4: UINTN *DataSize
// Argument 5: VOID *Data OPTIONAL
//
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)CoreRbp->Argument1, &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)CoreRbp->Argument2, &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)(CoreRbp->Argument2 + sizeof (EFI_GUID) - 1), &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
if ((UINT32 *)CoreRbp->Argument3 != NULL) {
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)CoreRbp->Argument3, &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)(CoreRbp->Argument3 + sizeof (UINT32) - 1), &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
}
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)((UINTN)UserRsp + 7 * sizeof (UINTN) - 1), &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
DisableSMAP ();
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)(CoreRbp->Argument1 + StrSize ((CHAR16 *)CoreRbp->Argument1) - 1), &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
Argument6 = (UINTN)AllocateCopyPool (StrSize ((CHAR16 *)CoreRbp->Argument1), (CHAR16 *)CoreRbp->Argument1);
if ((VOID *)Argument6 == NULL) {
EnableSMAP ();
return EFI_OUT_OF_RESOURCES;
}
Status = FindGuid ((EFI_GUID *)CoreRbp->Argument2, &CoreProtocol, &MemoryCoreSize);
if (EFI_ERROR (Status)) {
EnableSMAP ();
FreePool ((VOID *)Argument6);
return Status;
}
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)UserRsp->Arguments[4], &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)(UserRsp->Arguments[4] + sizeof (UINTN) - 1), &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
Argument4 = *(UINTN *)UserRsp->Arguments[4];
if ((VOID *)UserRsp->Arguments[5] != NULL) {
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)UserRsp->Arguments[5], &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)(UserRsp->Arguments[5] + Argument4 - 1), &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
Argument5 = (UINTN)AllocatePool (Argument4);
if ((VOID *)Argument5 == NULL) {
EnableSMAP ();
FreePool ((VOID *)Argument6);
return EFI_OUT_OF_RESOURCES;
}
}
EnableSMAP ();
Status = gRT->GetVariable (
(CHAR16 *)Argument6,
CoreProtocol,
(UINT32 *)&Attributes,
&Argument4,
(VOID *)Argument5
);
DisableSMAP ();
if ((VOID *)UserRsp->Arguments[5] != NULL) {
CopyMem ((VOID *)UserRsp->Arguments[5], (VOID *)Argument5, Argument4);
}
*(UINTN *)UserRsp->Arguments[4] = Argument4;
if ((UINT32 *)CoreRbp->Argument3 != NULL) {
*(UINT32 *)CoreRbp->Argument3 = (UINT32)Attributes;
}
EnableSMAP ();
FreePool ((VOID *)Argument6);
if ((VOID *)Argument5 != NULL) {
FreePool ((VOID *)Argument5);
}
return Status;
case SysCallBlockIoReset: case SysCallBlockIoReset:
// //
// Argument 1: EFI_BLOCK_IO_PROTOCOL *This // Argument 1: EFI_BLOCK_IO_PROTOCOL *This

View File

@ -2043,6 +2043,7 @@ typedef enum {
// //
// RuntimeServices // RuntimeServices
// //
SysCallGetVariable,
// //
// Protocols // Protocols
// //
@ -2149,9 +2150,10 @@ typedef struct {
} EFI_SYSTEM_TABLE; } EFI_SYSTEM_TABLE;
typedef struct { typedef struct {
EFI_SYSTEM_TABLE SystemTable; EFI_SYSTEM_TABLE SystemTable;
VOID *EntryPoint; VOID *EntryPoint;
EFI_BOOT_SERVICES *BootServices; EFI_BOOT_SERVICES *BootServices;
EFI_RUNTIME_SERVICES *RuntimeServices;
} RING3_DATA; } RING3_DATA;
typedef struct { typedef struct {