public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: Xing Li <lixing@loongson.cn>, adhemerval.zanella@linaro.org
Cc: libc-alpha@sourceware.org, i.swmail@xen0n.name,
	caiyinyu@loongson.cn,  wanghongliang@loongson.cn,
	hejinyang@loongson.cn
Subject: Re: [PATCH] LoongArch: Add syscall.c for getting correct return value
Date: Wed, 23 Nov 2022 11:40:28 +0800	[thread overview]
Message-ID: <bab7b718cef2801c025840de95e2150ace705da0.camel@xry111.site> (raw)
In-Reply-To: <20221123015711.707809-1-lixing@loongson.cn>

On Wed, 2022-11-23 at 09:57 +0800, Xing Li wrote:
> The __SYS_mmap syscall should return 47bits value. If we use
> the common syscall interface which defined in
> sysdeps/unix/sysv/linux/syscall.c, the syscall return value
> is 32bits with sign extend, which lead to mmap failure.

Could we just change

int r = INTERNAL_SYSCALL_NCS_CALL (number, a0, a1, a2, a3, a4, a5);

in sysdeps/unix/sysv/linux/syscall.c to "long r = ..." instead?

> 
> Testcase:
> 
>  #include <sys/syscall.h>
>  #include <sys/mman.h>
>  #include <stdio.h>
> 
> void main()
> {
>         long int ret;
>         ret = syscall(SYS_mmap, NULL, 0x801000, PROT_READ |
> PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
>         printf("map address is %lx\n",ret);
> }
> 
> Result:
> [lixing@Sunhaiyong test]$ ./mmap
> map address is fffffffff008c000
> 
>        * sysdeps/unix/sysv/linux/loongarch/syscall.c: New file
> ---
>  sysdeps/unix/sysv/linux/loongarch/syscall.c | 34
> +++++++++++++++++++++
>  1 file changed, 34 insertions(+)
>  create mode 100644 sysdeps/unix/sysv/linux/loongarch/syscall.c
> 
> diff --git a/sysdeps/unix/sysv/linux/loongarch/syscall.c
> b/sysdeps/unix/sysv/linux/loongarch/syscall.c
> new file mode 100644
> index 0000000000..fe9672a403
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/syscall.c
> @@ -0,0 +1,34 @@
> +/* system call interface.  Linux/LoongArch version.
> +   Copyright (C) 2001-2022 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be
> useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library.  If not, see
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#include <sysdep.h>
> +
> +long int
> +syscall (long int syscall_number, long int arg1, long int arg2, long
> int arg3,
> +        long int arg4, long int arg5, long int arg6, long int arg7)
> +{
> +  long int ret;
> +
> +  ret = INTERNAL_SYSCALL_NCS_CALL (syscall_number, arg1, arg2, arg3,
> arg4,
> +                                  arg5, arg6, arg7);
> +
> +  if (INTERNAL_SYSCALL_ERROR_P (ret))
> +    return __syscall_error (ret);
> +
> +  return ret;
> +}

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

  reply	other threads:[~2022-11-23  3:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23  1:57 Xing Li
2022-11-23  3:40 ` Xi Ruoyao [this message]
2022-11-23 13:36   ` Adhemerval Zanella Netto
2022-11-25  2:37     ` XingLi

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=bab7b718cef2801c025840de95e2150ace705da0.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=adhemerval.zanella@linaro.org \
    --cc=caiyinyu@loongson.cn \
    --cc=hejinyang@loongson.cn \
    --cc=i.swmail@xen0n.name \
    --cc=libc-alpha@sourceware.org \
    --cc=lixing@loongson.cn \
    --cc=wanghongliang@loongson.cn \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).