Re: [BUG] [man syscall] x86_64 error code / return value must be placed in rdi

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

> I ran the test to verify that the retval is indeed supposed to be
> placed in rdi, and not rax as the man page incorrectly suggests.
> My man page version:
> $ man --version
> man 2.8.3
> 
> Steps to replicate this issue:
> Step 1)
> Write test code 'startup.c':
> void _start()
> {
>         /*
>            Source: $: man syscall
>            arch/ABI    instruction           syscall #  retval  error    Notes
>            ────────────────────────────────────────────────────────────────────
>            i386        int $0x80             eax        eax     -
>            ia64        break 0x100000        r15        r8      r10      [1]
>            x86-64      syscall               rax        rax     -        [5]
>         */
> 
>         // Specify the return value/error code in ebx for x86 and rdi for x86_64
>         asm volatile (
>                 "movq $97, %rdi"
>         );

%rdi contains the first argument of syscall on x86_64.

>         // Specify the type of system call (1 is the exit syscall) in
> eax register.
>         asm volatile (
>                 "movq $0x3c, %rax"
>         );

syscall number 0x3c is exit on x86_64.

> 
>         // Transition to kernel mode.
>         asm volatile (
>                 "syscall"
>         );

This syscall does not return.

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


-- 
ldv



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux