unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Add syscall.c for getting correct return value
@ 2022-11-23  1:57 Xing Li
  2022-11-23  3:40 ` Xi Ruoyao via Libc-alpha
  0 siblings, 1 reply; 4+ messages in thread
From: Xing Li @ 2022-11-23  1:57 UTC (permalink / raw)
  To: adhemerval.zanella
  Cc: libc-alpha, i.swmail, xry111, caiyinyu, wanghongliang, hejinyang,
	Xing Li

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.

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;
+}
-- 
2.37.1


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

end of thread, other threads:[~2022-11-25  2:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-23  1:57 [PATCH] LoongArch: Add syscall.c for getting correct return value Xing Li
2022-11-23  3:40 ` Xi Ruoyao via Libc-alpha
2022-11-23 13:36   ` Adhemerval Zanella Netto via Libc-alpha
2022-11-25  2:37     ` XingLi

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