2

My question is about the write syscall.

I know that if the write was successful, the number of bytes written is stored in rax, but what happens if an error occurs? I want to store -1 in rax in this case.

How can I detect that the the write failed, because of an invalid file descriptor for example.

Abdou Ouahib
  • 821
  • 5
  • 14
  • What operating system are you programming for? – fuz Jan 03 '20 at 13:51
  • @fuz I forgot to mention it's macos – Abdou Ouahib Jan 03 '20 at 13:52
  • 1
    I think macos sets CF on error and returns the error code in rax, but I'm not sure enough to write up an answer. – fuz Jan 03 '20 at 13:53
  • [This question](https://stackoverflow.com/questions/47834513/64-bit-syscall-documentation-for-macos-assembly) might provide you with a bit more information. – fuz Jan 03 '20 at 13:54
  • @fuz You're right, your comment was helpful. Thanks a lot – Abdou Ouahib Jan 03 '20 at 13:57
  • 1
    raw system calls (not the libc wrapper) will return the `errno` code directly, like `EBADF`. On Linux, error returns are encoded as negative, and no valid system call will ever return `-EBADF`. On MacOS with CF as sideband signalling of error / non-error, IDK if it's negated or not. – Peter Cordes Jan 03 '20 at 14:02

0 Answers0