Restoring stdin fcntl flags before exit
This commit is contained in:
parent
3c459352c6
commit
58ea0f523d
1 changed files with 24 additions and 3 deletions
27
wtfstopw.asm
27
wtfstopw.asm
|
|
@ -95,6 +95,8 @@ section .data
|
||||||
lapcountlen: equ $ - lapcount
|
lapcountlen: equ $ - lapcount
|
||||||
laplen: dq 2
|
laplen: dq 2
|
||||||
|
|
||||||
|
fcntl_flag: dq 0
|
||||||
|
|
||||||
section .text
|
section .text
|
||||||
global _start
|
global _start
|
||||||
_start:
|
_start:
|
||||||
|
|
@ -105,6 +107,7 @@ xor rdi, rdi
|
||||||
mov rax, 72 ; fcntl
|
mov rax, 72 ; fcntl
|
||||||
mov rsi, 3 ; F_GETFL
|
mov rsi, 3 ; F_GETFL
|
||||||
syscall
|
syscall
|
||||||
|
mov [fcntl_flag], rax
|
||||||
mov rdx, rax
|
mov rdx, rax
|
||||||
or rdx, 0x800 ; O_NONBLOCK
|
or rdx, 0x800 ; O_NONBLOCK
|
||||||
mov rax, 72 ; fcntl
|
mov rax, 72 ; fcntl
|
||||||
|
|
@ -175,9 +178,26 @@ flush_stdin:
|
||||||
je newline_exit
|
je newline_exit
|
||||||
jg flush_stdin
|
jg flush_stdin
|
||||||
|
|
||||||
|
mov rdi, 0 ; EXIT OK
|
||||||
|
;
|
||||||
|
; Expect rdi to be the return code
|
||||||
|
;
|
||||||
exit:
|
exit:
|
||||||
|
push rdi
|
||||||
|
; restoring stdin state
|
||||||
|
mov rax, 72 ; fcntl
|
||||||
|
xor rdi, rdi
|
||||||
|
mov rsi, 4 ; F_SETFL
|
||||||
|
mov rdx, [fcntl_flag]
|
||||||
|
syscall
|
||||||
|
cmp rax, 0
|
||||||
|
je exit_end
|
||||||
|
pop rdi ; failed to restore
|
||||||
|
push 1 ; exit FAIL
|
||||||
|
|
||||||
|
exit_end:
|
||||||
mov rax, 60 ; sys_exit
|
mov rax, 60 ; sys_exit
|
||||||
mov rdi, 0 ; OK
|
pop rdi ; return code
|
||||||
syscall
|
syscall
|
||||||
fault:
|
fault:
|
||||||
mov rax, 1 ; write
|
mov rax, 1 ; write
|
||||||
|
|
@ -190,9 +210,8 @@ fault:
|
||||||
mov rdx, faultmsglen
|
mov rdx, faultmsglen
|
||||||
syscall
|
syscall
|
||||||
|
|
||||||
mov rax, 60 ; sys_exit
|
|
||||||
mov rdi, 1 ; failure
|
mov rdi, 1 ; failure
|
||||||
syscall
|
jmp exit
|
||||||
|
|
||||||
newline_exit:
|
newline_exit:
|
||||||
mov rax, 1
|
mov rax, 1
|
||||||
|
|
@ -200,6 +219,8 @@ newline_exit:
|
||||||
mov rsi, nl
|
mov rsi, nl
|
||||||
mov rdx, 1
|
mov rdx, 1
|
||||||
syscall
|
syscall
|
||||||
|
|
||||||
|
mov rdi, 0 ; exit OK
|
||||||
jmp exit
|
jmp exit
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue