I write assembly for a school project and I'm stuck on a point, i need re rewrite Read in asm, so i got it, but i need to set the errno variable, then my read can return -1 in case of an error and set value of errno to 9 for example. And i don't found how to change this famous errno :( this is my actual code :
global my_write
section .text
my_write:
mov rax, 1 ; sys_write
syscall ; call write
cmp rax, 0
jl error
ret
error:
mov rax, -1
ret
ps : i found somewhere i need to use __error but i don't find any docs on this :(
thanks a lot :D
edit :
Thanks for you help guys ! __errno_location work i make this :
extern __ernno_location
global my_write
section .text
my_write:
mov rax, 1 ; sys_write
syscall ; call write
cmp rax, 0
jl error
ret
error:
neg rax ; get absolute value of syscall return
mov rdi, rax
call __ernno_location
mov [rax], rdi ; set the value of errno
mov rax, -1
ret