SysCall: Refactored out CORE_STACK and RING3_STACK.

This commit is contained in:
Mikhail Krichanov 2025-01-13 20:00:34 +03:00
parent ea41000bcf
commit 8587830d67
6 changed files with 421 additions and 367 deletions

View File

@ -235,17 +235,6 @@ typedef struct {
UINTN UserStackTop; UINTN UserStackTop;
} LOADED_IMAGE_PRIVATE_DATA; } LOADED_IMAGE_PRIVATE_DATA;
typedef struct {
UINTN Argument1;
UINTN Argument2;
UINTN Argument3;
} CORE_STACK;
typedef struct {
UINTN Rip;
UINTN Arguments[];
} RING3_STACK;
#define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \ #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \
CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE) CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)
@ -2749,9 +2738,8 @@ CoreBootServices (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
CallBootService ( CallBootService (
IN UINT8 Type, IN UINT8 Type,
IN CORE_STACK *CoreRbp, IN UINTN *UserArguments
IN RING3_STACK *UserRsp
); );
VOID VOID

View File

@ -74,8 +74,7 @@ SysCallBootService (
Status = CallBootService ( Status = CallBootService (
Type, Type,
(CORE_STACK *)CoreRbp, (UINTN *)((UINTN)Physical + sizeof (UINTN))
(RING3_STACK *)(UINTN)Physical
); );
CoreFreePages (Physical, EFI_SIZE_TO_PAGES (9 * sizeof (UINTN))); CoreFreePages (Physical, EFI_SIZE_TO_PAGES (9 * sizeof (UINTN)));

View File

@ -80,8 +80,7 @@ SysCallBootService (
Status = CallBootService ( Status = CallBootService (
Type, Type,
(CORE_STACK *)CoreRbp, (UINTN *)((UINTN)Physical + sizeof (UINTN))
(RING3_STACK *)(UINTN)Physical
); );
// //
// TODO: Fix memory leak for ReturnToCore(). // TODO: Fix memory leak for ReturnToCore().

File diff suppressed because it is too large Load Diff

View File

@ -132,18 +132,10 @@ ASM_PFX(CoreBootServices):
mov gs, ax mov gs, ax
; Prepare CallBootService arguments. ; Prepare CallBootService arguments.
call ASM_PFX(AllowSupervisorAccessToUserMemory)
mov eax, [edx + 4 * 4] ; User Argument 3
push eax
mov eax, [edx + 3 * 4] ; User Argument 2
push eax
mov eax, [edx + 2 * 4] ; User Argument 1
push eax
call ASM_PFX(ForbidSupervisorAccessToUserMemory)
mov ebp, esp mov ebp, esp
add edx, 4 ; User Arguments[]
push edx push edx
push ebp push ecx ; Type
push ecx
sti sti
call ASM_PFX(CallBootService) call ASM_PFX(CallBootService)
@ -157,8 +149,8 @@ ASM_PFX(CoreBootServices):
pop eax pop eax
; Step over User Arguments [1..3] and CallBootService input. ; Step over CallBootService input.
add esp, 4*6 add esp, 4*2
; Prepare SYSEXIT arguments. ; Prepare SYSEXIT arguments.
pop edx ; User return address. pop edx ; User return address.

View File

@ -23,9 +23,9 @@ SECTION .text
global ASM_PFX(AllowSupervisorAccessToUserMemory) global ASM_PFX(AllowSupervisorAccessToUserMemory)
ASM_PFX(AllowSupervisorAccessToUserMemory): ASM_PFX(AllowSupervisorAccessToUserMemory):
pushfq pushfq
pop r10 pop rax
or r10, 0x40000 ; Set AC (bit 18) or rax, 0x40000 ; Set AC (bit 18)
push r10 push rax
popfq popfq
ret ret
@ -39,9 +39,9 @@ ASM_PFX(AllowSupervisorAccessToUserMemory):
global ASM_PFX(ForbidSupervisorAccessToUserMemory) global ASM_PFX(ForbidSupervisorAccessToUserMemory)
ASM_PFX(ForbidSupervisorAccessToUserMemory): ASM_PFX(ForbidSupervisorAccessToUserMemory):
pushfq pushfq
pop r10 pop rax
and r10, ~0x40000 ; Clear AC (bit 18) and rax, ~0x40000 ; Clear AC (bit 18)
push r10 push rax
popfq popfq
ret ret
@ -147,18 +147,21 @@ ASM_PFX(CoreBootServices):
push rcx push rcx
; Save User RFLAGS for SYSRET. ; Save User RFLAGS for SYSRET.
push r11 push r11
; Save User Arguments [1..3]. ; Save User Arguments [1..3] on User stack.
push r9 call ASM_PFX(AllowSupervisorAccessToUserMemory)
push r8 mov rax, [rsp + 8*3]
push rdx mov [rax + 8*2], rdx
mov [rax + 8*3], r8
mov [rax + 8*4], r9
call ASM_PFX(ForbidSupervisorAccessToUserMemory)
mov rbp, rsp mov rbp, rsp
; Reserve space on stack for 4 CallBootService arguments (NOOPT prerequisite). ; Reserve space on stack for 4 CallBootService arguments (NOOPT prerequisite).
sub rsp, 8*4 sub rsp, 8*4
; Prepare CallBootService arguments. ; Prepare CallBootService arguments.
mov rcx, r10 mov rcx, r10 ; Type
mov rdx, rbp mov rdx, [rbp + 8*3]
mov r8, [rbp + 8*6] add rdx, 8 ; User Arguments[]
sti sti
call ASM_PFX(CallBootService) call ASM_PFX(CallBootService)
@ -169,8 +172,8 @@ ASM_PFX(CoreBootServices):
pop rax pop rax
; Step over Arguments [1..3] and NOOPT buffer. ; Step over NOOPT buffer.
add rsp, 8*7 add rsp, 8*4
; Prepare SYSRET arguments. ; Prepare SYSRET arguments.
pop r11 pop r11