about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2023-04-24 00:55:26 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-04-24 22:48:35 +0200
commitc02b26455b3c9d33c8a94e56eed1958d7f751b72 (patch)
treecef6d7d11c961ab5ff7e300009b23501c23d818a /sysdeps
parent35b7bf2fe003d6dbd5726cdf69f3c5d8179590e5 (diff)
downloadglibc-c02b26455b3c9d33c8a94e56eed1958d7f751b72.tar.gz
glibc-c02b26455b3c9d33c8a94e56eed1958d7f751b72.tar.xz
glibc-c02b26455b3c9d33c8a94e56eed1958d7f751b72.zip
hurd: Implement prefer_map_32bit_exec tunable
This makes the prefer_map_32bit_exec tunable no longer Linux-specific.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20230423215526.346009-4-bugaevc@gmail.com>
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/mach/hurd/dl-sysdep.c5
-rw-r--r--sysdeps/mach/hurd/mmap.c6
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/64/Makefile23
-rw-r--r--sysdeps/x86_64/64/Makefile22
-rw-r--r--sysdeps/x86_64/64/dl-tunables.list (renamed from sysdeps/unix/sysv/linux/x86_64/64/dl-tunables.list)0
-rw-r--r--sysdeps/x86_64/64/tst-map-32bit-1a.c (renamed from sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-1a.c)0
-rw-r--r--sysdeps/x86_64/64/tst-map-32bit-1b.c (renamed from sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-1b.c)0
-rw-r--r--sysdeps/x86_64/64/tst-map-32bit-mod.c (renamed from sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-mod.c)0
8 files changed, 33 insertions, 23 deletions
diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index 25a1277461..79ebb0ceb1 100644
--- a/sysdeps/mach/hurd/dl-sysdep.c
+++ b/sysdeps/mach/hurd/dl-sysdep.c
@@ -462,6 +462,11 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
   if (prot & PROT_EXEC)
     vmprot |= VM_PROT_EXECUTE;
 
+#ifdef __LP64__
+  if ((addr == NULL) && (prot & PROT_EXEC)
+      && HAS_ARCH_FEATURE (Prefer_MAP_32BIT_EXEC))
+    flags |= MAP_32BIT;
+#endif
   mask = (flags & MAP_32BIT) ? ~(vm_address_t) 0x7FFFFFFF : 0;
 
   if (flags & MAP_ANON)
diff --git a/sysdeps/mach/hurd/mmap.c b/sysdeps/mach/hurd/mmap.c
index 790eb23886..5aa7008393 100644
--- a/sysdeps/mach/hurd/mmap.c
+++ b/sysdeps/mach/hurd/mmap.c
@@ -18,6 +18,7 @@
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <errno.h>
+#include <ldsodefs.h>
 #include <hurd.h>
 #include <hurd/fd.h>
 
@@ -55,6 +56,11 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
 
   copy = ! (flags & MAP_SHARED);
 
+#ifdef __LP64__
+  if ((addr == NULL) && (prot & PROT_EXEC)
+      && HAS_ARCH_FEATURE (Prefer_MAP_32BIT_EXEC))
+    flags |= MAP_32BIT;
+#endif
   mask = (flags & MAP_32BIT) ? ~(vm_address_t) 0x7FFFFFFF : 0;
 
   switch (flags & MAP_TYPE)
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/Makefile b/sysdeps/unix/sysv/linux/x86_64/64/Makefile
index 1bf7d528b2..a7b6dc5a53 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/Makefile
+++ b/sysdeps/unix/sysv/linux/x86_64/64/Makefile
@@ -1,25 +1,2 @@
 # The default ABI is 64.
 default-abi := 64
-
-ifeq ($(subdir),elf)
-
-tests-map-32bit = \
-  tst-map-32bit-1a \
-  tst-map-32bit-1b \
-# tests-map-32bit
-tst-map-32bit-1a-no-pie = yes
-tst-map-32bit-1b-no-pie = yes
-tests += $(tests-map-32bit)
-
-modules-map-32bit = \
-  tst-map-32bit-mod \
-# modules-map-32bit
-modules-names += $(modules-map-32bit)
-
-$(objpfx)tst-map-32bit-mod.so: $(libsupport)
-tst-map-32bit-1a-ENV = LD_PREFER_MAP_32BIT_EXEC=1
-$(objpfx)tst-map-32bit-1a: $(objpfx)tst-map-32bit-mod.so
-tst-map-32bit-1b-ENV = GLIBC_TUNABLES=glibc.cpu.prefer_map_32bit_exec=1
-$(objpfx)tst-map-32bit-1b: $(objpfx)tst-map-32bit-mod.so
-
-endif
diff --git a/sysdeps/x86_64/64/Makefile b/sysdeps/x86_64/64/Makefile
new file mode 100644
index 0000000000..73fcfe0bb0
--- /dev/null
+++ b/sysdeps/x86_64/64/Makefile
@@ -0,0 +1,22 @@
+ifeq ($(subdir),elf)
+
+tests-map-32bit = \
+  tst-map-32bit-1a \
+  tst-map-32bit-1b \
+# tests-map-32bit
+tst-map-32bit-1a-no-pie = yes
+tst-map-32bit-1b-no-pie = yes
+tests += $(tests-map-32bit)
+
+modules-map-32bit = \
+  tst-map-32bit-mod \
+# modules-map-32bit
+modules-names += $(modules-map-32bit)
+
+$(objpfx)tst-map-32bit-mod.so: $(libsupport)
+tst-map-32bit-1a-ENV = LD_PREFER_MAP_32BIT_EXEC=1
+$(objpfx)tst-map-32bit-1a: $(objpfx)tst-map-32bit-mod.so
+tst-map-32bit-1b-ENV = GLIBC_TUNABLES=glibc.cpu.prefer_map_32bit_exec=1
+$(objpfx)tst-map-32bit-1b: $(objpfx)tst-map-32bit-mod.so
+
+endif
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/dl-tunables.list b/sysdeps/x86_64/64/dl-tunables.list
index 0aab52e662..0aab52e662 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/dl-tunables.list
+++ b/sysdeps/x86_64/64/dl-tunables.list
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-1a.c b/sysdeps/x86_64/64/tst-map-32bit-1a.c
index abc396589e..abc396589e 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-1a.c
+++ b/sysdeps/x86_64/64/tst-map-32bit-1a.c
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-1b.c b/sysdeps/x86_64/64/tst-map-32bit-1b.c
index 34ab01c773..34ab01c773 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-1b.c
+++ b/sysdeps/x86_64/64/tst-map-32bit-1b.c
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-mod.c b/sysdeps/x86_64/64/tst-map-32bit-mod.c
index 78d4b6133c..78d4b6133c 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-mod.c
+++ b/sysdeps/x86_64/64/tst-map-32bit-mod.c