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