aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux
diff options
context:
space:
mode:
authorPetr Malat <oss@malat.biz>2025-01-28 11:08:20 +0100
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2025-01-30 10:16:37 -0300
commit4c43173eba874039c96eca893041745c6d7be38a (patch)
tree92c4c4d375832168075395633b0a9f9ce6a95b5e /sysdeps/unix/sysv/linux
parenta6fbe36b7f31292981422692236465ab56670ea9 (diff)
downloadglibc-4c43173eba874039c96eca893041745c6d7be38a.zip
glibc-4c43173eba874039c96eca893041745c6d7be38a.tar.gz
glibc-4c43173eba874039c96eca893041745c6d7be38a.tar.bz2
ld.so: Decorate BSS mappings
Decorate BSS mappings with [anon: glibc: .bss <file>], for example [anon: glibc: .bss /lib/libc.so.6]. The string ".bss" is already used by bionic so use the same, but add the filename as well. If the name would be longer than what the kernel allows, drop the directory part of the path. Refactor glibc.mem.decorate_maps check to a separate function and use it to avoid assembling a name, which would not be used later. Signed-off-by: Petr Malat <oss@malat.biz> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps/unix/sysv/linux')
-rw-r--r--sysdeps/unix/sysv/linux/setvmaname.c45
-rw-r--r--sysdeps/unix/sysv/linux/setvmaname.h8
2 files changed, 41 insertions, 12 deletions
diff --git a/sysdeps/unix/sysv/linux/setvmaname.c b/sysdeps/unix/sysv/linux/setvmaname.c
index 749c587..ea93a5f 100644
--- a/sysdeps/unix/sysv/linux/setvmaname.c
+++ b/sysdeps/unix/sysv/linux/setvmaname.c
@@ -22,6 +22,33 @@
#include <sysdep.h>
#include <elf/dl-tunables.h>
+static enum {
+ decorate_unknown = -1,
+ decorate_off,
+ decorate_on
+} decorate_maps = decorate_unknown;
+
+bool
+__is_decorate_maps_enabled (void)
+{
+ switch (atomic_load_relaxed (&decorate_maps))
+ {
+ case decorate_unknown:
+ if (TUNABLE_GET (glibc, mem, decorate_maps, int32_t, NULL) != 0)
+ {
+ atomic_store_relaxed (&decorate_maps, decorate_on);
+ return true;
+ }
+ atomic_store_relaxed (&decorate_maps, decorate_off);
+ return false;
+ case decorate_off:
+ return false;
+ case decorate_on:
+ return true;
+ }
+ __builtin_unreachable ();
+}
+
/* If PR_SET_VMA_ANON_NAME is not supported by the kernel, prctl returns
EINVAL. However, it also returns the same error for invalid argument.
Since it is an internal-only API, it assumes well formatted input:
@@ -31,19 +58,13 @@
void
__set_vma_name (void *start, size_t len, const char *name)
{
- static int prctl_supported = 1;
- if (atomic_load_relaxed (&prctl_supported) == 0)
- return;
-
- /* Set the prctl as not supported to avoid checking the tunable on every
- call. */
- if (TUNABLE_GET (glibc, mem, decorate_maps, int32_t, NULL) != 0)
+ if (__is_decorate_maps_enabled ())
{
int r = INTERNAL_SYSCALL_CALL (prctl, PR_SET_VMA, PR_SET_VMA_ANON_NAME,
- start, len, name);
- if (r == 0 || r != -EINVAL)
- return;
+ start, len, name);
+
+ /* Disable further attempts if not supported by the kernel. */
+ if (r == -EINVAL)
+ atomic_store_relaxed (&decorate_maps, decorate_off);
}
- atomic_store_relaxed (&prctl_supported, 0);
- return;
}
diff --git a/sysdeps/unix/sysv/linux/setvmaname.h b/sysdeps/unix/sysv/linux/setvmaname.h
index 715b096..48643d0 100644
--- a/sysdeps/unix/sysv/linux/setvmaname.h
+++ b/sysdeps/unix/sysv/linux/setvmaname.h
@@ -19,9 +19,17 @@
#ifndef __SETVMANAME_H
#define __SETVMANAME_H
+/* Maximum supported name from initial kernel support, not exported
+ by user API. */
+#define ANON_VMA_NAME_MAX_LEN 80
+
/* Set the NAME to the anonymous memory map START with size of LEN.
It assumes well-formatted input. */
#if IS_IN(libc) || IS_IN(rtld)
+#include <stdbool.h>
+
+bool __is_decorate_maps_enabled (void) attribute_hidden;
+
void __set_vma_name (void *start, size_t len, const char *name)
attribute_hidden;
#else