flat assembler
Message board for the users of flat assembler.
Index
> Linux > Syscall returns file descriptor |
Author |
|
vid 07 Dec 2006, 22:49
linux kernel error codes are in range -4096 to 0. so you can do:
Code: cmp eax, -4096 ja error |
|||
07 Dec 2006, 22:49 |
|
a16b03 07 Dec 2006, 23:08
vid wrote: linux kernel error codes are in range -4096 to 0. Are you shore? |
|||
07 Dec 2006, 23:08 |
|
gunblade 08 Dec 2006, 18:53
Well, not 0, 0 is usually used to mean "all went well", but it is -4096 to -1 to indicate error as far as i know. Each one means a different error (although most syscalls probably wont implement all the error codes, just any which are relevant to what they are doing).
As for the lowest file descriptor which a syscall will return, it should technically be 0, if there is a syscall to return the stdin file descriptor. FD Description 0 Stdin 1 Stdout 2 Stderr 3+ Used for files, pipes, threads.. anything which requires a file descriptor. |
|||
08 Dec 2006, 18:53 |
|
f0dder 08 Dec 2006, 22:57
Aren't you just supposed to check for errors by "num < 0"? It'd be more work checking actual ranges then, and you could end up in trouble that way...
|
|||
08 Dec 2006, 22:57 |
|
LocoDelAssembly 09 Dec 2006, 00:28
f0dder, are you talking about vid's code? It works, I'm still not convincing myself of how it works but after a few test it worked. Thanks for post it vid
|
|||
09 Dec 2006, 00:28 |
|
gunblade 13 Dec 2006, 21:45
f0dder, checking for < 0 will check between 0x8000000 and 0xFFFFFFFF (for 32-bits), which is much too large of a range, values returned are valid from 0 up to 0xFFFFEFFF, then between 0xFFFFF000 and 0xFFFFFFFF are the possible error values.
|
|||
13 Dec 2006, 21:45 |
|
f0dder 13 Dec 2006, 23:00
gunblade wrote: f0dder, checking for < 0 will check between 0x8000000 and 0xFFFFFFFF (for 32-bits), which is much too large of a range, values returned are valid from 0 up to 0xFFFFEFFF, then between 0xFFFFF000 and 0xFFFFFFFF are the possible error values. Are they, now? If the code internally uses signed ints to represent errors, then I very much doubt this. _________________ - carpe noctem |
|||
13 Dec 2006, 23:00 |
|
vid 13 Dec 2006, 23:20
f0dder: this is following standards, not particular implementation of those standards. And standards AFAIK say that error code is -4096 to -1, which CAN be tested by one cmp
|
|||
13 Dec 2006, 23:20 |
|
f0dder 13 Dec 2006, 23:55
vid: okay - got a link to manpage, source file, or similar?
Just keep in mind that most C code probably checks for "<0", so... |
|||
13 Dec 2006, 23:55 |
|
vid 14 Dec 2006, 03:51
f0dder: got logic.
In linux you have 3GB user-mode address space. What if mmap() returns you pointer above 2GB? Also, from what i have read, even memory page xFFFFE000 to 0xFFFFEFFF is mapped. Then it seems logical to choose those values as error codes, which cannot act as pointer (those which immediately throw GPF) |
|||
14 Dec 2006, 03:51 |
|
vid 14 Dec 2006, 12:40
f0dder: after some exploring... i realized it's probably not a standard. But still it is the logical range. <0 just wouldn't work well. And keep in mind "c code" is using libc, not linux kernel.
|
|||
14 Dec 2006, 12:40 |
|
f0dder 14 Dec 2006, 15:08
I thought this was about file descriptors - but I see it has been expanded to a more generic "kernel error returns"
Well, I've never bothered doing syscalls directly on *u*x (and I can't be bothered), so I wouldn't know if there's 100% generic rules... I'd be surprised if there were. |
|||
14 Dec 2006, 15:08 |
|
arafel 14 Dec 2006, 15:38
MAX_ERRNO is 4095, hence the error values are in the range -4095 .. -1.
Simply checking the sign (since 'test eax, eax' is smaller and faster than 'cmp eax, -4096') will work fine for almost all system calls. |
|||
14 Dec 2006, 15:38 |
|
vid 14 Dec 2006, 17:27
Quote: Simply checking the sign (since 'test eax, eax' is smaller and faster than 'cmp eax, -4096') will work fine for almost all system calls. |
|||
14 Dec 2006, 17:27 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.