Linux-man Archive on lore.kernel.org
 help / color / Atom feed
* Re: [BUG] [man syscall] x86_64 error code / return value must be placed in rdi
       [not found]   ` <20190623171706.GA23943@altlinux.org>
@ 2019-09-01 21:43     ` Naveen Iyer
  2019-09-01 22:25       ` Dmitry V. Levin
  0 siblings, 1 reply; 2+ messages in thread
From: Naveen Iyer @ 2019-09-01 21:43 UTC (permalink / raw)
  To: Dmitry V. Levin; +Cc: mtk.manpages, linux-man

On Sun, Jun 23, 2019 at 10:17 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
>
> Hi,
>
> 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?

> > }
> >
> > 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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [BUG] [man syscall] x86_64 error code / return value must be placed in rdi
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry V. Levin @ 2019-09-01 22:25 UTC (permalink / raw)
  To: Naveen Iyer; +Cc: mtk.manpages, linux-man

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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

Linux-man Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-man/0 linux-man/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-man linux-man/ https://lore.kernel.org/linux-man \
		linux-man@vger.kernel.org linux-man@archiver.kernel.org
	public-inbox-index linux-man


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-man


AGPL code for this site: git clone https://public-inbox.org/ public-inbox