Update OpenExecutable logic to properly check BSD/Linux error conditions

This commit is contained in:
Paul Kulchenko 2022-03-07 20:23:39 -08:00
parent 13ff8745c9
commit efa12a67f9

View file

@ -121,19 +121,20 @@ OpenExecutable:
mov -0x08(%rbp),%eax # __NR_open
mov %r14,%rdi
mov -0x20(%rbp),%esi # O_RDWR
clc # clear carry flag
syscall
mov %eax,%r15d
mov $-1,%eax # check if successful
cmp %eax,%r15d
jne 0f
jc .Lohno # bsd error
cmp $-4095,%eax
jae .Lohno # linux error
jmp .Lok
// Open executable in read-only mode.
mov -0x08(%rbp),%eax # __NR_open
.Lohno: mov -0x08(%rbp),%eax # __NR_open
mov %r14,%rdi
mov -0x48(%rbp),%esi # O_RDONLY
syscall
mov %eax,%r15d
0:
.Lok: mov %eax,%r15d
// Map code segment.
mov -0x10(%rbp),%eax # __NR_mmap