Message ID | 20221123015711.707809-1-lixing@loongson.cn |
---|---|
State | New |
Headers | show |
Series | LoongArch: Add syscall.c for getting correct return value | expand |
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; > +}
On 23/11/22 00:40, Xi Ruoyao wrote: > 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? > Yes, afaik INTERNAL_SYSCALL_NCS on all architecture returns long int.
在 2022/11/23 下午9:36, Adhemerval Zanella Netto 写道: > > > On 23/11/22 00:40, Xi Ruoyao wrote: >> 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? >> > > Yes, afaik INTERNAL_SYSCALL_NCS on all architecture returns long int. > Yes, the __SYSCALL_DEFINEx all returns long in linux kernel.
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; +}