aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix
diff options
context:
space:
mode:
authorCupertino Miranda <cupertino.miranda@oracle.com>2025-08-22 11:37:00 +0100
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2025-08-27 10:45:45 -0300
commit3b2b88cceeb79f73a72367800d91599e2af4bb39 (patch)
treea4f7c0efe8d6c2a49ac448c977a639e609c3f45c /sysdeps/unix
parent921e251e8f364d00fc753274095007275381ae65 (diff)
downloadglibc-3b2b88cceeb79f73a72367800d91599e2af4bb39.zip
glibc-3b2b88cceeb79f73a72367800d91599e2af4bb39.tar.gz
glibc-3b2b88cceeb79f73a72367800d91599e2af4bb39.tar.bz2
elf: early conversion of elf p_flags to mprotect flags
This patch replaces _dl_stack_flags global variable by _dl_stack_prot_flags. The advantage is that any convertion from p_flags to final used mprotect flags occurs at loading of p_flags. It avoids repeated spurious convertions of _dl_stack_flags, for example in allocate_thread_stack. This modification was suggested in: https://sourceware.org/pipermail/libc-alpha/2025-March/165537.html Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps/unix')
-rw-r--r--sysdeps/unix/sysv/linux/dl-execstack.c3
-rw-r--r--sysdeps/unix/sysv/linux/machine-sp.h2
-rw-r--r--sysdeps/unix/sysv/linux/spawni.c5
3 files changed, 5 insertions, 5 deletions
diff --git a/sysdeps/unix/sysv/linux/dl-execstack.c b/sysdeps/unix/sysv/linux/dl-execstack.c
index 6db9601..a59bd56 100644
--- a/sysdeps/unix/sysv/linux/dl-execstack.c
+++ b/sysdeps/unix/sysv/linux/dl-execstack.c
@@ -17,6 +17,7 @@
<https://www.gnu.org/licenses/>. */
#include <ldsodefs.h>
+#include <stackinfo.h>
int
_dl_make_stack_executable (const void *stack_endp)
@@ -36,7 +37,7 @@ _dl_make_stack_executable (const void *stack_endp)
return errno;
/* Remember that we changed the permission. */
- GL(dl_stack_flags) |= PF_X;
+ GL(dl_stack_prot_flags) |= PROT_EXEC;
return 0;
}
diff --git a/sysdeps/unix/sysv/linux/machine-sp.h b/sysdeps/unix/sysv/linux/machine-sp.h
index 6ab3ca6..bda90fe 100644
--- a/sysdeps/unix/sysv/linux/machine-sp.h
+++ b/sysdeps/unix/sysv/linux/machine-sp.h
@@ -19,6 +19,8 @@
#ifndef _MACHINE_SP_H
#define _MACHINE_SP_H
+#include <stackinfo.h>
+
/* Return the current stack pointer. */
static inline uintptr_t
__thread_stack_pointer (void)
diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c
index eca1a84..bc8476f 100644
--- a/sysdeps/unix/sysv/linux/spawni.c
+++ b/sysdeps/unix/sysv/linux/spawni.c
@@ -348,9 +348,6 @@ __spawnix (int *pid, const char *file,
return errno;
}
- int prot = (PROT_READ | PROT_WRITE
- | ((GL (dl_stack_flags) & PF_X) ? PROT_EXEC : 0));
-
/* Add a slack area for child's stack. */
size_t argv_size = (argc * sizeof (void *)) + 512;
/* We need at least a few pages in case the compiler's stack checking is
@@ -361,7 +358,7 @@ __spawnix (int *pid, const char *file,
where it might use about 1k extra stack space). */
argv_size += (32 * 1024);
size_t stack_size = ALIGN_UP (argv_size, GLRO(dl_pagesize));
- void *stack = __mmap (NULL, stack_size, prot,
+ void *stack = __mmap (NULL, stack_size, GL (dl_stack_prot_flags),
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
if (__glibc_unlikely (stack == MAP_FAILED))
return errno;