public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-7605] libgcc: use syscall rather than __mmap/__munmap
@ 2020-04-07 18:31 Ian Lance Taylor
0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2020-04-07 18:31 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:50c7853216e8511971c55b51d7fe29173db4749b
commit r10-7605-g50c7853216e8511971c55b51d7fe29173db4749b
Author: Ian Lance Taylor <iant@golang.org>
Date: Tue Apr 7 11:29:41 2020 -0700
libgcc: use syscall rather than __mmap/__munmap
PR libgcc/94513
* generic-morestack.c: Give up trying to use __mmap/__munmap, use
syscall instead.
Diff:
---
libgcc/ChangeLog | 6 +++++
libgcc/generic-morestack.c | 55 +++++++++++++++++++++++++++++++++++++++-------
2 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog
index ec225d1cb5a..6340cfbbf59 100644
--- a/libgcc/ChangeLog
+++ b/libgcc/ChangeLog
@@ -1,3 +1,9 @@
+2020-04-07 Ian Lance Taylor <iant@golang.org>
+
+ PR libgcc/94513
+ * generic-morestack.c: Give up trying to use __mmap/__munmap, use
+ syscall instead.
+
2020-04-04 Ian Lance Taylor <iant@golang.org>
* generic-morestack.c: Only use __mmap on glibc >= 2.26.
diff --git a/libgcc/generic-morestack.c b/libgcc/generic-morestack.c
index fa2062e2bb3..35764a848f6 100644
--- a/libgcc/generic-morestack.c
+++ b/libgcc/generic-morestack.c
@@ -56,17 +56,56 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
/* Some systems use LD_PRELOAD or similar tricks to add hooks to
mmap/munmap. That breaks this code, because when we call mmap
there is enough stack space for the system call but there is not,
- in general, enough stack space to run a hook. At least when using
- glibc on GNU/Linux we can avoid the problem by calling __mmap and
- __munmap. */
+ in general, enough stack space to run a hook. Try to avoid the
+ problem by calling syscall directly. We only do this on GNU/Linux
+ for now, but it should be easy to add support for more systems with
+ testing. */
-#if defined(__gnu_linux__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 26))
+#if defined(__gnu_linux__)
-extern void *__mmap (void *, size_t, int, int, int, off_t);
-extern int __munmap (void *, size_t);
+#include <sys/syscall.h>
-#define mmap __mmap
-#define munmap __munmap
+#if defined(SYS_mmap) || defined(SYS_mmap2)
+
+#ifdef SYS_mmap2
+#define MORESTACK_MMAP SYS_mmap2
+#define MORESTACK_ADJUST_OFFSET(x) ((x) / 4096ULL)
+#else
+#define MORESTACK_MMAP SYS_mmap
+#define MORESTACK_ADJUST_OFFSET(x) (x)
+#endif
+
+static void *
+morestack_mmap (void *addr, size_t length, int prot, int flags, int fd,
+ off_t offset)
+{
+ offset = MORESTACK_ADJUST_OFFSET (offset);
+
+#ifdef __s390__
+ long args[6] = { (long) addr, (long) length, (long) prot, (long) flags,
+ (long) fd, (long) offset };
+ return (void *) syscall (MORESTACK_MMAP, args);
+#else
+ return (void *) syscall (MORESTACK_MMAP, addr, length, prot, flags, fd,
+ offset);
+#endif
+}
+
+#define mmap morestack_mmap
+
+#endif /* defined(SYS_MMAP) || defined(SYS_mmap2) */
+
+#if defined(SYS_munmap)
+
+static int
+morestack_munmap (void * addr, size_t length)
+{
+ return (int) syscall (SYS_munmap, addr, length);
+}
+
+#define munmap morestack_munmap
+
+#endif /* defined(SYS_munmap) */
#endif /* defined(__gnu_linux__) */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-04-07 18:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-07 18:31 [gcc r10-7605] libgcc: use syscall rather than __mmap/__munmap Ian Lance Taylor
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).