public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Sergey Bugaev <bugaevc@gmail.com>
To: libc-alpha@sourceware.org
Cc: bug-hurd@gnu.org, Samuel Thibault <samuel.thibault@gnu.org>,
	"H . J . Lu" <hjl.tools@gmail.com>
Subject: [RFC PATCH 4/4] hurd: Implement prefer_map_32bit_exec tunable
Date: Mon, 24 Apr 2023 00:55:26 +0300	[thread overview]
Message-ID: <20230423215526.346009-4-bugaevc@gmail.com> (raw)
In-Reply-To: <20230423215526.346009-1-bugaevc@gmail.com>

This makes the prefer_map_32bit_exec tunable no longer Linux-specific.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
 sysdeps/mach/hurd/dl-sysdep.c                 |  5 ++++
 sysdeps/mach/hurd/mmap.c                      |  6 +++++
 sysdeps/unix/sysv/linux/x86_64/64/Makefile    | 23 -------------------
 sysdeps/x86_64/64/Makefile                    | 22 ++++++++++++++++++
 .../linux => }/x86_64/64/dl-tunables.list     |  0
 .../linux => }/x86_64/64/tst-map-32bit-1a.c   |  0
 .../linux => }/x86_64/64/tst-map-32bit-1b.c   |  0
 .../linux => }/x86_64/64/tst-map-32bit-mod.c  |  0
 8 files changed, 33 insertions(+), 23 deletions(-)
 create mode 100644 sysdeps/x86_64/64/Makefile
 rename sysdeps/{unix/sysv/linux => }/x86_64/64/dl-tunables.list (100%)
 rename sysdeps/{unix/sysv/linux => }/x86_64/64/tst-map-32bit-1a.c (100%)
 rename sysdeps/{unix/sysv/linux => }/x86_64/64/tst-map-32bit-1b.c (100%)
 rename sysdeps/{unix/sysv/linux => }/x86_64/64/tst-map-32bit-mod.c (100%)

diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index 25a12774..79ebb0ce 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 d570be24..c4ffbba3 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>
 
@@ -56,6 +57,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 1bf7d528..a7b6dc5a 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 00000000..73fcfe0b
--- /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
similarity index 100%
rename from sysdeps/unix/sysv/linux/x86_64/64/dl-tunables.list
rename to 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
similarity index 100%
rename from sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-1a.c
rename to 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
similarity index 100%
rename from sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-1b.c
rename to 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
similarity index 100%
rename from sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-mod.c
rename to sysdeps/x86_64/64/tst-map-32bit-mod.c
-- 
2.40.0


  parent reply	other threads:[~2023-04-23 21:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-23 21:55 [PATCH 1/4] hurd: Implement MAP_32BIT Sergey Bugaev
2023-04-23 21:55 ` [PATCH 2/4] hurd: Don't attempt to deallocate MACH_PORT_DEAD Sergey Bugaev
2023-04-24 20:44   ` Samuel Thibault
2023-04-23 21:55 ` [PATCH 3/4] hurd: Microoptimize mmap () Sergey Bugaev
2023-04-24 20:46   ` Samuel Thibault
2023-04-24 21:09     ` Sergey Bugaev
2023-04-24 21:25       ` Samuel Thibault
2023-04-23 21:55 ` Sergey Bugaev [this message]
2023-04-24 20:48   ` [RFC PATCH 4/4] hurd: Implement prefer_map_32bit_exec tunable Samuel Thibault
2023-04-24 20:42 ` [PATCH 1/4] hurd: Implement MAP_32BIT Samuel Thibault

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230423215526.346009-4-bugaevc@gmail.com \
    --to=bugaevc@gmail.com \
    --cc=bug-hurd@gnu.org \
    --cc=hjl.tools@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=samuel.thibault@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).