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 Attributes
); );
if (EFI_ERROR (Status)) { 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; return Status;
} }

View File

@ -1698,7 +1698,7 @@ InitializeRing3 (
// //
// Initialize MSR_IA32_STAR and MSR_IA32_LSTAR for SYSCALL and SYSRET. // 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); AsmWriteMsr64 (MSR_IA32_STAR, Msr);
Msr = (UINT64)(UINTN)CoreBootServices; Msr = (UINT64)(UINTN)CoreBootServices;
@ -1837,15 +1837,6 @@ CoreStartImage (
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)Image->EntryPoint, &Attributes); gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)Image->EntryPoint, &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0); 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 ( Image->Status = GoToRing3 (
2, 2,
(VOID *)Image->EntryPoint, (VOID *)Image->EntryPoint,

View File

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

View File

@ -44,7 +44,24 @@ GoToRing3 (
VA_END (Marker); VA_END (Marker);
EnableSMAP (); 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 EFI_STATUS

View File

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