Ring3: Some refactoring.

This commit is contained in:
Mikhail Krichanov 2024-02-19 15:00:10 +03:00
parent f82b04a2dc
commit d19bee4d2d
5 changed files with 35 additions and 23 deletions

View File

@ -397,7 +397,7 @@ Ring3OpenProtocol (
Attributes
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Ring3: Failed to open protocol %g - %r\n", Protocol, Status));
// DEBUG ((DEBUG_ERROR, "Ring3: Failed to open protocol %g - %r\n", Protocol, Status));
return Status;
}

View File

@ -1698,7 +1698,7 @@ InitializeRing3 (
//
// Initialize MSR_IA32_STAR and MSR_IA32_LSTAR for SYSCALL and SYSRET.
//
Msr = ((((UINT64)RING3_CODE64_SEL - 16) << 16) | (UINT64)RING0_CODE64_SEL) << 32;
Msr = (((((UINT64)RING3_CODE64_SEL - 16) | 3) << 16) | (UINT64)RING0_CODE64_SEL) << 32;
AsmWriteMsr64 (MSR_IA32_STAR, Msr);
Msr = (UINT64)(UINTN)CoreBootServices;
@ -1837,15 +1837,6 @@ CoreStartImage (
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)Image->EntryPoint, &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
//
// Necessary fix for ProcessLibraryConstructorList() -> DxeCcProbeLibConstructor()
//
SetUefiImageMemoryAttributes (
FixedPcdGet32 (PcdOvmfWorkAreaBase),
FixedPcdGet32 (PcdOvmfWorkAreaSize),
EFI_MEMORY_XP | EFI_MEMORY_USER
);
Image->Status = GoToRing3 (
2,
(VOID *)Image->EntryPoint,

View File

@ -155,10 +155,12 @@ CallBootService (
);
DisableSMAP ();
Interface = AllocateRing3Copy (Interface, MemoryCoreSize, MemoryCoreSize);
if (Interface == NULL) {
EnableSMAP ();
return EFI_OUT_OF_RESOURCES;
if (Interface != NULL) {
Interface = AllocateRing3Copy (Interface, MemoryCoreSize, MemoryCoreSize);
if (Interface == NULL) {
EnableSMAP ();
return EFI_OUT_OF_RESOURCES;
}
}
*(VOID **)CoreRbp->Argument3 = Interface;
@ -197,13 +199,15 @@ CallBootService (
);
DisableSMAP ();
Interface = AllocateRing3Copy (Interface, MemoryCoreSize, MemoryCoreSize);
if (Interface == NULL) {
EnableSMAP ();
return EFI_OUT_OF_RESOURCES;
}
if (Interface != NULL) {
Interface = AllocateRing3Copy (Interface, MemoryCoreSize, MemoryCoreSize);
if (Interface == NULL) {
EnableSMAP ();
return EFI_OUT_OF_RESOURCES;
}
FixInterface (CoreProtocol, Interface);
FixInterface (CoreProtocol, Interface);
}
*(VOID **)CoreRbp->Argument3 = Interface;
EnableSMAP ();
@ -285,6 +289,7 @@ CallBootService (
return Status;
default:
DEBUG ((DEBUG_ERROR, "Ring0: Unknown syscall type.\n"));
break;
}

View File

@ -44,7 +44,24 @@ GoToRing3 (
VA_END (Marker);
EnableSMAP ();
return CallRing3 (Input);
//
// Necessary fix for ProcessLibraryConstructorList() -> DxeCcProbeLibConstructor()
//
SetUefiImageMemoryAttributes (
FixedPcdGet32 (PcdOvmfWorkAreaBase),
FixedPcdGet32 (PcdOvmfWorkAreaSize),
EFI_MEMORY_XP | EFI_MEMORY_USER
);
Status = CallRing3 (Input);
SetUefiImageMemoryAttributes (
FixedPcdGet32 (PcdOvmfWorkAreaBase),
FixedPcdGet32 (PcdOvmfWorkAreaSize),
EFI_MEMORY_XP
);
return Status;
}
EFI_STATUS

View File

@ -197,7 +197,6 @@ ASM_PFX(CallRing3):
add rax, 8
; Set Data selectors
or rax, 3H ; RPL = 3
mov ds, ax
mov es, ax
mov fs, ax