All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dmitry V. Levin" <ldv@altlinux.org>
To: Naveen Iyer <iyernaveenr@gmail.com>
Cc: mtk.manpages@gmail.com, linux-man@vger.kernel.org
Subject: Re: [BUG] [man syscall] x86_64 error code / return value must be placed in rdi
Date: Mon, 2 Sep 2019 01:25:07 +0300	[thread overview]
Message-ID: <20190901222507.GA31828@altlinux.org> (raw)
In-Reply-To: <CAAAu3Xt6S5ODyn_d1Yu-H8q89zTYfSicMfhKsGAgVzhLo2XGbg@mail.gmail.com>

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

      reply	other threads:[~2019-09-01 22:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAAAu3XtbB=Y0s2emVJoj5Vt4UXSjvk_3EBw_f=gRKssVxbK0=A@mail.gmail.com>
     [not found] ` <CAAAu3XtsLqvVEnMO5A_LMEF5qP64pJFB2+aey4yhCnhvY_F79Q@mail.gmail.com>
     [not found]   ` <20190623171706.GA23943@altlinux.org>
2019-09-01 21:43     ` [BUG] [man syscall] x86_64 error code / return value must be placed in rdi Naveen Iyer
2019-09-01 22:25       ` Dmitry V. Levin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190901222507.GA31828@altlinux.org \
    --to=ldv@altlinux.org \
    --cc=iyernaveenr@gmail.com \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.