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,

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 as per the following link:
https://w3challs.com/syscalls/?arch=x86_64

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"
        );

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

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

Step 2) Compile and execute:
$ gcc -nostdlib -c startup.c
$ ld startup.o -o startup
$ ./startup
$ echo $?
97

My system details:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic

$ uname -a
Linux user 4.15.0-51-generic #55-Ubuntu SMP Wed May 15 14:27:21 UTC
2019 x86_64 x86_64 x86_64 GNU/Linux

Please let me know if there's anything else you need to rectify this issue.

Thanks
Naveen


On Sun, Jun 23, 2019 at 8:57 AM Naveen Iyer <iyernaveenr@xxxxxxxxx> wrote:
>
> Hi,
>
> As sugegsted 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 as per the following link:
> https://w3challs.com/syscalls/?arch=x86_64
>
> I personally ran the test to verify that the retval is indeed supposed to be placed in rdi, not rax.
> 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"
>         );
>
>         // Specify the type of system call (1 is the exit syscall) in eax register.
>         asm volatile (
>                 "movq $0x3c, %rax"
>         );
>
>         // Transition to kernel mode.
>         asm volatile (
>                 "syscall"
>         );
> }
>
> Step 2) Compile and execute:
> $ gcc -nostdlib -c startup.c
> $ ld startup.o -o startup
> $ ./startup
> $ echo $?
> 97
>
> My system details:
> $ lsb_release -a
> No LSB modules are available.
> Distributor ID: Ubuntu
> Description: Ubuntu 18.04.1 LTS
> Release: 18.04
> Codename: bionic
>
> $ uname -a
> Linux user 4.15.0-51-generic #55-Ubuntu SMP Wed May 15 14:27:21 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
>
> Please let me know if there's anything else you need to rectify this issue.
>
> Thanks
> Naveen




[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