I would like to know if anybody has a solution to my problem. I'm doing a project for school. This project is about creating a function (only in NASM) that uses a syscall (I have to create ft_read which reproduces the behaviour of the real read system call).
Here is the situation :
When everything is okay (FD, buff, count), my function works properly.
BUT I don't know how to check if the syscall was successful or if it failed.
For example : When I use a fake fd (-1 for example), the syscall read returns 9 in rax. I understood that 9 is the error code for the variable Errno.
The problem is that I don't know how to differentiate the error code for errno from the return value of read (red of 9 char from the file).
If anybody has an idea on how to do I would be glad to know !
Here is my code at the moment :
extern ___error
SYS_READ_MAC equ 0x2000003
SYS_READ_LINUX equ 3
section .text
global _ft_read
_ft_read:
cmp rdi, 0
jl _error
cmp rsi, 0
je _error
cmp rdx, 0
jl _error
mov rax, SYS_READ_MAC
syscall
cmp rax, 0
jl _error
ret
_error:
mov r10, rax
call ___error
mov qword [rax], r10
mov rax, -1
ret
Sorry if my english isn't perfect, i'm not a native english speaker.