flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > [bug]Understanding the out of memory error. Piping into fasm |
Author |
|
FlierMate11 14 Feb 2023, 09:55
Thanks to your -4095 error value, it indirectly helps to solve my hexdump to catch file open error:
Like what you reported, my hexdump evaluate rax value as -1, but it didn't catch the open error. Code: xor rsi,rsi ;O_RDONLY mov rax,2 ; sys_create syscall cmp rax,-1 je _err mov dword [fd],eax Until I saw this thread, then I changed it to: Code: ... ... cmp rax,-4095 jae _err mov dword [fd],eax ...then only it able to catch the file open error, and avoid opening a non-existent file. I tried "je _err" but it didn't work, have to use "jae _err", looks like the error code is above -4095. |
|||
14 Feb 2023, 09:55 |
|
revolution 14 Feb 2023, 10:06
The value returned is the negative value of the error (listed in "sys/errno.h"). So the returned value for an error can be anywhere from -4095 to -1.
The Linux kernel spec guarantees that all error numbers will be <=4095. So the negative will be >=-4095. As mentioned above -1 == -EPERM is a permission fault error. Looking at the current errno.h I see that highest value is EHWPOISON = 133, well within the 4095 maximum range. If you only check for -1 then you are only catching permission fault errors. |
|||
14 Feb 2023, 10:06 |
|
FlierMate11 14 Feb 2023, 10:24
I think Linux manual is misleading, for example, for "creat(2)":
Quote:
https://linux.die.net/man/2/creat Followed the wrong guide. |
|||
14 Feb 2023, 10:24 |
|
revolution 14 Feb 2023, 10:34
That is the libc wrapper document. The kernel is different.
|
|||
14 Feb 2023, 10:34 |
|
revolution 14 Feb 2023, 11:07
For reference here is the libc wrapper code of a random chosen syscall. All error values are negated and stored into the "errno" variable, and returns -1. The errno variable is a libc thing only. The kernel doesn't have it.
Code: 00000000004425d0 <__sysinfo>: 4425d0: b8 63 00 00 00 mov eax,0x63 4425d5: 0f 05 syscall 4425d7: 48 3d 01 f0 ff ff cmp rax,0xfffffffffffff001 ; -4095 4425dd: 0f 83 cd 1b 00 00 jae 4441b0 <__syscall_error> 4425e3: c3 ret ;... 00000000004441b0 <__syscall_error>: 4441b0: 48 f7 d8 neg rax 00000000004441b3 <__syscall_error_1>: 4441b3: 64 89 04 25 d0 ff ff mov DWORD PTR fs:0xffffffffffffffd0,eax ; errno variable 4441ba: ff 4441bb: 48 83 c8 ff or rax,0xffffffffffffffff ; -1 4441bf: c3 ret |
|||
14 Feb 2023, 11:07 |
|
FlierMate11 14 Feb 2023, 11:27
Thanks for the effort and informative explanation, @revolution.
I see it now. revolution wrote: That is the libc wrapper document. The kernel is different. Next time where can I refer to for the kernel one? |
|||
14 Feb 2023, 11:27 |
|
revolution 14 Feb 2023, 11:31
The page you linked is good. Just ignore the errno and -1 return value stuff. Negate the error values shown and it's all good. Everything else is the same, including the argument ordering.
|
|||
14 Feb 2023, 11:31 |
|
FlierMate11 14 Feb 2023, 11:36
revolution wrote: The page you linked is good. Just ignore the errno and -1 return value stuff. Negate the error values shown and it's all good. Everything else is the same, including the argument ordering. Thank you very much. |
|||
14 Feb 2023, 11:36 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.