aboutsummaryrefslogtreecommitdiff
path: root/libgcc/generic-morestack.c
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2020-06-17 07:50:57 -0400
committerAldy Hernandez <aldyh@redhat.com>2020-06-17 07:50:57 -0400
commitb9e67f2840ce0d8859d96e7f8df8fe9584af5eba (patch)
treeed3b7284ff15c802583f6409b9c71b3739642d15 /libgcc/generic-morestack.c
parent1957047ed1c94bf17cf993a2b1866965f493ba87 (diff)
parent56638b9b1853666f575928f8baf17f70e4ed3517 (diff)
downloadgcc-b9e67f2840ce0d8859d96e7f8df8fe9584af5eba.zip
gcc-b9e67f2840ce0d8859d96e7f8df8fe9584af5eba.tar.gz
gcc-b9e67f2840ce0d8859d96e7f8df8fe9584af5eba.tar.bz2
Merge from trunk at:
commit 56638b9b1853666f575928f8baf17f70e4ed3517 Author: GCC Administrator <gccadmin@gcc.gnu.org> Date: Wed Jun 17 00:16:36 2020 +0000 Daily bump.
Diffstat (limited to 'libgcc/generic-morestack.c')
-rw-r--r--libgcc/generic-morestack.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/libgcc/generic-morestack.c b/libgcc/generic-morestack.c
index c26dba1..35764a8 100644
--- a/libgcc/generic-morestack.c
+++ b/libgcc/generic-morestack.c
@@ -53,6 +53,62 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include "generic-morestack.h"
+/* 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. 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__)
+
+#include <sys/syscall.h>
+
+#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__) */
+
typedef unsigned uintptr_type __attribute__ ((mode (pointer)));
/* This file contains subroutines that are used by code compiled with