hex2: also close rootdir on exit.
This commit is contained in:
parent
e3ccc9b046
commit
dcaba36d05
|
@ -105,6 +105,7 @@ DEFINE STORE32_R11_into_Address_RAX 4C8918
|
||||||
DEFINE STORE32_R12_into_Address_R11_Immediate8 4D8963
|
DEFINE STORE32_R12_into_Address_R11_Immediate8 4D8963
|
||||||
DEFINE STORE32_R13_into_Address_RAX_Immediate8 4C8968
|
DEFINE STORE32_R13_into_Address_RAX_Immediate8 4C8968
|
||||||
DEFINE STORE64_rel_RAX 488905
|
DEFINE STORE64_rel_RAX 488905
|
||||||
|
DEFINE STORE64_rel_RBX 48891D
|
||||||
DEFINE STORE64_rel_R14 4C8935
|
DEFINE STORE64_rel_R14 4C8935
|
||||||
DEFINE SUBI8_RAX 83E8
|
DEFINE SUBI8_RAX 83E8
|
||||||
DEFINE SUBI8_RSP 4883EC
|
DEFINE SUBI8_RSP 4883EC
|
||||||
|
@ -199,7 +200,8 @@ DEFINE ZERO_EXTEND_BL 480FB6DB
|
||||||
CALL_RCX_Immediate8 !8 # rootfs->open_volume(rootfs, &rootdir)
|
CALL_RCX_Immediate8 !8 # rootfs->open_volume(rootfs, &rootdir)
|
||||||
POP_RAX # deallocate stack
|
POP_RAX # deallocate stack
|
||||||
POP_RAX # deallocate stack
|
POP_RAX # deallocate stack
|
||||||
POP_RBX # save rootdir
|
POP_RBX # get rootdir
|
||||||
|
STORE64_rel_RBX %rootdir # save rootdir
|
||||||
|
|
||||||
# Open file for reading
|
# Open file for reading
|
||||||
PUSH_RDX # allocate stack for fin
|
PUSH_RDX # allocate stack for fin
|
||||||
|
@ -720,23 +722,34 @@ DEFINE ZERO_EXTEND_BL 480FB6DB
|
||||||
:terminate
|
:terminate
|
||||||
PUSH_RAX # save exit code
|
PUSH_RAX # save exit code
|
||||||
PUSH_R10 # protect fout
|
PUSH_R10 # protect fout
|
||||||
|
|
||||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
PUSH_RAX # allocate shadow stack space for UEFI function
|
||||||
LOAD64_rel_R14 %SystemBoot # get system->boot
|
LOAD64_rel_R14 %SystemBoot # get system->boot
|
||||||
LOAD64_rel_RCX %scratch # arg1 = scratch
|
LOAD64_rel_RCX %scratch # arg1 = scratch
|
||||||
CALL_R14_Immediate8 !72 # system->boot->free_pool(scratch)
|
CALL_R14_Immediate8 !72 # system->boot->free_pool(scratch)
|
||||||
|
POP_RAX # deallocate stack
|
||||||
|
|
||||||
LOAD64_rel_RCX %fin # arg1 = fin
|
LOAD64_rel_RCX %fin # arg1 = fin
|
||||||
CALL_RCX_Immediate8 !16 # fin->close(fin)
|
CALLI32 %close_file # close fin
|
||||||
POP_RAX # deallocate stack
|
|
||||||
POP_RCX # restore fout
|
POP_RCX # restore fout
|
||||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
CALLI32 %close_file # close fout
|
||||||
CALL_RCX_Immediate8 !16 # fout->close(fout)
|
|
||||||
POP_RAX # deallocate stack
|
LOAD64_rel_RCX %rootdir # get rootdir
|
||||||
|
CALLI32 %close_file # close rootdir
|
||||||
|
|
||||||
POP_RAX # restore exit code
|
POP_RAX # restore exit code
|
||||||
|
|
||||||
COPY_RBP_to_RSP # restore stack
|
COPY_RBP_to_RSP # restore stack
|
||||||
RET # return to UEFI
|
RET # return to UEFI
|
||||||
|
|
||||||
|
# rcx: file handle
|
||||||
|
:close_file
|
||||||
|
PUSH_RAX # allocate shadow stack space for UEFI function
|
||||||
|
CALL_RCX_Immediate8 !16 # file_handle->close(file_handle)
|
||||||
|
POP_RAX # deallocate stack
|
||||||
|
RET
|
||||||
|
|
||||||
# rdx: number of bytes to allocate
|
# rdx: number of bytes to allocate
|
||||||
# r14: system->boot
|
# r14: system->boot
|
||||||
# returns pointer in rax
|
# returns pointer in rax
|
||||||
|
@ -776,4 +789,7 @@ DEFINE ZERO_EXTEND_BL 480FB6DB
|
||||||
:SystemBoot
|
:SystemBoot
|
||||||
%0 %0
|
%0 %0
|
||||||
|
|
||||||
|
:rootdir
|
||||||
|
%0 %0
|
||||||
|
|
||||||
:PE32_end
|
:PE32_end
|
||||||
|
|
|
@ -88,7 +88,8 @@ loop_options2: # Skip argv[1]
|
||||||
call [rcx+8] # rootfs->open_volume(rootfs, &rootdir)
|
call [rcx+8] # rootfs->open_volume(rootfs, &rootdir)
|
||||||
pop rax # deallocate stack
|
pop rax # deallocate stack
|
||||||
pop rax # deallocate stack
|
pop rax # deallocate stack
|
||||||
pop rbx # save rootdir
|
pop rbx # get rootdir
|
||||||
|
mov [rip+rootdir], rbx # save rootdir
|
||||||
|
|
||||||
# Open file for reading
|
# Open file for reading
|
||||||
push rdx # allocate stack for fin
|
push rdx # allocate stack for fin
|
||||||
|
@ -609,24 +610,35 @@ terminate:
|
||||||
# Free pool
|
# Free pool
|
||||||
push rax # save exit code
|
push rax # save exit code
|
||||||
push r10 # protect fout
|
push r10 # protect fout
|
||||||
|
|
||||||
push rax # allocate shadow stack space for UEFI function
|
push rax # allocate shadow stack space for UEFI function
|
||||||
mov r14, [rip+SystemBoot] # get system->boot
|
mov r14, [rip+SystemBoot] # get system->boot
|
||||||
mov rcx, [rip+scratch] # arg1 = scratch
|
mov rcx, [rip+scratch] # arg1 = scratch
|
||||||
call [r14+72] # system->boot->free_pool(scratch)
|
call [r14+72] # system->boot->free_pool(scratch)
|
||||||
|
pop rax # deallocate stack
|
||||||
|
|
||||||
mov rcx, [rip+fin] # arg1 = fin
|
mov rcx, [rip+fin] # arg1 = fin
|
||||||
call [rcx+16] # fin->close(fin)
|
call close_file # close fin
|
||||||
pop rax # deallocate stack
|
|
||||||
pop rcx # restore fout
|
pop rcx # restore fout
|
||||||
push rax # allocate shadow stack space for UEFI function
|
call close_file # close fout
|
||||||
call [rcx+16] # fout->close(fout)
|
|
||||||
pop rax # deallocate stack
|
mov rcx, [rip+rootdir] # get rootdir
|
||||||
|
call close_file # close rootdir
|
||||||
|
|
||||||
pop rax # restore exit code
|
pop rax # restore exit code
|
||||||
|
|
||||||
abort: # used for debugging only
|
abort: # used for debugging only
|
||||||
mov rsp, rbp # restore stack
|
mov rsp, rbp # restore stack
|
||||||
ret # return to UEFI
|
ret # return to UEFI
|
||||||
|
|
||||||
|
# rcx: file handle
|
||||||
|
close_file:
|
||||||
|
push rax # allocate shadow stack space for UEFI function
|
||||||
|
call [rcx+16] # file_handle->close(file_handle)
|
||||||
|
pop rax # deallocate stack
|
||||||
|
ret
|
||||||
|
|
||||||
# rdx: number of bytes to allocate
|
# rdx: number of bytes to allocate
|
||||||
# r14: system->boot
|
# r14: system->boot
|
||||||
# returns pointer in rax
|
# returns pointer in rax
|
||||||
|
@ -662,5 +674,8 @@ fin:
|
||||||
scratch:
|
scratch:
|
||||||
.long 0, 0
|
.long 0, 0
|
||||||
|
|
||||||
|
rootdir:
|
||||||
|
.long 0, 0
|
||||||
|
|
||||||
SystemBoot:
|
SystemBoot:
|
||||||
.long 0, 0
|
.long 0, 0
|
||||||
|
|
|
@ -132,9 +132,9 @@ F0 00 # SizeOfOptionalHeader
|
||||||
# [0x148]
|
# [0x148]
|
||||||
# Start of section headers
|
# Start of section headers
|
||||||
00 00 00 00 00 00 00 00 ; Name of the section (empty) but could set to ".text"
|
00 00 00 00 00 00 00 00 ; Name of the section (empty) but could set to ".text"
|
||||||
52 06 00 00 ; VirtualSize
|
75 06 00 00 ; VirtualSize
|
||||||
00 10 00 00 ; VirtualAddress
|
00 10 00 00 ; VirtualAddress
|
||||||
52 06 00 00 ; SizeOfRawData
|
75 06 00 00 ; SizeOfRawData
|
||||||
70 01 00 00 ; PointerToRawData
|
70 01 00 00 ; PointerToRawData
|
||||||
00 00 00 00 ; PointerToRelocations
|
00 00 00 00 ; PointerToRelocations
|
||||||
00 00 00 00 ; PointerToLinenumbers
|
00 00 00 00 ; PointerToLinenumbers
|
||||||
|
@ -216,7 +216,8 @@ F0 00 # SizeOfOptionalHeader
|
||||||
FF51 08 ; CALL_RCX_Immediate8 !8 # rootfs->open_volume(rootfs, &rootdir)
|
FF51 08 ; CALL_RCX_Immediate8 !8 # rootfs->open_volume(rootfs, &rootdir)
|
||||||
58 ; POP_RAX # deallocate stack
|
58 ; POP_RAX # deallocate stack
|
||||||
58 ; POP_RAX # deallocate stack
|
58 ; POP_RAX # deallocate stack
|
||||||
5B ; POP_RBX # save rootdir
|
5B ; POP_RBX # get rootdir
|
||||||
|
48891D %2 ; STORE64_rel_RBX %rootdir # save rootdir
|
||||||
|
|
||||||
# Open file for reading
|
# Open file for reading
|
||||||
52 ; PUSH_RDX # allocate stack for fin
|
52 ; PUSH_RDX # allocate stack for fin
|
||||||
|
@ -737,23 +738,34 @@ F0 00 # SizeOfOptionalHeader
|
||||||
:T #:terminate
|
:T #:terminate
|
||||||
50 ; PUSH_RAX # save exit code
|
50 ; PUSH_RAX # save exit code
|
||||||
4152 ; PUSH_R10 # protect fout
|
4152 ; PUSH_R10 # protect fout
|
||||||
|
|
||||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
||||||
4C8B35 %1 ; LOAD64_rel_R14 %SystemBoot # get system->boot
|
4C8B35 %1 ; LOAD64_rel_R14 %SystemBoot # get system->boot
|
||||||
488B0D %0 ; LOAD64_rel_RCX %scratch # arg1 = scratch
|
488B0D %0 ; LOAD64_rel_RCX %scratch # arg1 = scratch
|
||||||
41FF56 48 ; CALL_R14_Immediate8 !72 # system->boot->free_pool(scratch)
|
41FF56 48 ; CALL_R14_Immediate8 !72 # system->boot->free_pool(scratch)
|
||||||
|
58 ; POP_RAX # deallocate stack
|
||||||
|
|
||||||
488B0D %Z ; LOAD64_rel_RCX %fin # arg1 = fin
|
488B0D %Z ; LOAD64_rel_RCX %fin # arg1 = fin
|
||||||
FF51 10 ; CALL_RCX_Immediate8 !16 # fin->close(fin)
|
E8 %3 ; CALLI32 %close_file # close fin
|
||||||
58 ; POP_RAX # deallocate stack
|
|
||||||
59 ; POP_RCX # restore fout
|
59 ; POP_RCX # restore fout
|
||||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
E8 %3 ; CALLI32 %close_file # close fout
|
||||||
FF51 10 ; CALL_RCX_Immediate8 !16 # fout->close(fout)
|
|
||||||
58 ; POP_RAX # deallocate stack
|
488B0D %2 ; LOAD64_rel_RCX %rootdir # get rootdir
|
||||||
|
E8 %3 ; CALLI32 %close_file # close rootdir
|
||||||
|
|
||||||
58 ; POP_RAX # restore exit code
|
58 ; POP_RAX # restore exit code
|
||||||
|
|
||||||
4889EC ; COPY_RBP_to_RSP # restore stack
|
4889EC ; COPY_RBP_to_RSP # restore stack
|
||||||
C3 ; RET # return to UEFI
|
C3 ; RET # return to UEFI
|
||||||
|
|
||||||
|
# rcx: file handle
|
||||||
|
:3 #:close_file
|
||||||
|
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
||||||
|
FF51 10 ; CALL_RCX_Immediate8 !16 # file_handle->close(file_handle)
|
||||||
|
58 ; POP_RAX # deallocate stack
|
||||||
|
C3 ; RET
|
||||||
|
|
||||||
# rdx: number of bytes to allocate
|
# rdx: number of bytes to allocate
|
||||||
# r14: system->boot
|
# r14: system->boot
|
||||||
# returns pointer in rax
|
# returns pointer in rax
|
||||||
|
@ -793,4 +805,7 @@ F0 00 # SizeOfOptionalHeader
|
||||||
:1 #:SystemBoot
|
:1 #:SystemBoot
|
||||||
00000000 00000000
|
00000000 00000000
|
||||||
|
|
||||||
|
:2 #:rootdir
|
||||||
|
00000000 00000000
|
||||||
|
|
||||||
# :PE32_end
|
# :PE32_end
|
||||||
|
|
Loading…
Reference in New Issue