On Sun, Sep 01, 2019 at 02:43:22PM -0700, Naveen Iyer wrote: > On Sun, Jun 23, 2019 at 10:17 AM Dmitry V. Levin wrote: > > On Sun, Jun 23, 2019 at 09:03:31AM -0700, Naveen Iyer wrote: > > > Hi, > > > > > > As suggested by > > > https://www.kernel.org/doc/man-pages/reporting_bugs.html , I looked up > > > the online man page as well: > > > http://man7.org/linux/man-pages/man2/syscall.2.html > > > > > > In the table in "Architecture calling conventions" section: > > > arch/ABI instruction syscall # retval error Notes > > > ──────────────────────────────────── > > > x86-64 syscall rax rax - [5] > > > > > > Retval must be placed in rdi > > > > Why? > > > > > as per the following link: > > > https://w3challs.com/syscalls/?arch=x86_64 > > > > This link doesn't claim that. > > > The link states that rdi contains the int error_code. I am able to > return whatever int I want to return by placing the int value of my > choice in rdi. > Why do you say that this link doesn't claim that when it clearly does? > Am I misreading it? The link properly states that %rdi contains the 1st argument of syscall and %rax contains its return value. If you are reading something else, you must be misreading it. > > > } > > > > > > Step 2) Compile and execute: > > > $ gcc -nostdlib -c startup.c > > > $ ld startup.o -o startup > > > $ ./startup > > > $ echo $? > > > 97 > > > > So your test invokes "exit" syscall with 97 as its first argument. > > The return value of this syscall has no meaning because it does not return. > > Most of syscalls do return and their return value is in %rax on x86_64. > I am checking for the program's return status and not the return of > syscall itself. Yes, that's exactly the problem: you are talking about syscalls but at the same time you are checking the process's exit status instead of the syscall's return value. Most of syscalls do not cause an immediate process termination, and those syscalls that do cause immediate process termination do not have a return value. -- ldv