SysCall: Refactored out CORE_STACK and RING3_STACK.

This commit is contained in:
Mikhail Krichanov 2025-01-13 20:00:34 +03:00
parent 0f9e888860
commit 08df5ddf53
6 changed files with 421 additions and 367 deletions

View File

@ -234,17 +234,6 @@ typedef struct {
UINTN UserStackTop;
} 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) \
CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)
@ -2737,9 +2726,8 @@ CoreBootServices (
EFI_STATUS
EFIAPI
CallBootService (
IN UINT8 Type,
IN CORE_STACK *CoreRbp,
IN RING3_STACK *UserRsp
IN UINT8 Type,
IN UINTN *UserArguments
);
VOID

View File

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

View File

@ -80,8 +80,7 @@ SysCallBootService (
Status = CallBootService (
Type,
(CORE_STACK *)CoreRbp,
(RING3_STACK *)(UINTN)Physical
(UINTN *)((UINTN)Physical + sizeof (UINTN))
);
//
// 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
; 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
add edx, 4 ; User Arguments[]
push edx
push ebp
push ecx
push ecx ; Type
sti
call ASM_PFX(CallBootService)
@ -157,8 +149,8 @@ ASM_PFX(CoreBootServices):
pop eax
; Step over User Arguments [1..3] and CallBootService input.
add esp, 4*6
; Step over CallBootService input.
add esp, 4*2
; Prepare SYSEXIT arguments.
pop edx ; User return address.

View File

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