Error codes and logging
| Error returns | |
| errno values | |
| Writing a log |
Error returns
Raw syscalls return errors as a negative number in RAX, between -4095 and -1. Check the sign of RAX after every call that can fail, and negate it to get the positive errno:
syscall
cmp rax, 0
jl .error
neg rax ; rax = errno
errno values
Common errnos: 2 ENOENT (no such file), 5 EIO, 9 EBADF (bad descriptor), 13 EACCES, 17 EEXIST, 22 EINVAL. The list is in errno.h. Your program maps them to a message table and prints the text.
Writing a log
A log is a file opened with O_APPEND (0x400), written with sys_write, and closed with sys_close. Write one line per event: timestamp, severity, message, newline. Opening and closing per line is slow but simple; keeping the descriptor open is the production version.
Next: Parsing CSV
Article author: Arthur Isaev