about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-10-27 00:07:10 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-10-27 09:23:31 -0300
commit51da90c20d54c5098d9e1b01950a43bd2197813d (patch)
tree1e034bd07d5cc765b370577af03944c5119fb793
parent2869a2eb9669e8cc1cd019805c419d11e5f3a1d3 (diff)
downloadglibc-51da90c20d54c5098d9e1b01950a43bd2197813d.tar.gz
glibc-51da90c20d54c5098d9e1b01950a43bd2197813d.tar.xz
glibc-51da90c20d54c5098d9e1b01950a43bd2197813d.zip
elf: Add a way to check if tunable is set (BZ 27069)
The tunable already keep a field whether it is initialized.  Add
the TUNABLE_IS_INITIALIZED to query it.

Checked on x86_64-linux-gnu.
-rw-r--r--elf/dl-tunables.c7
-rw-r--r--elf/dl-tunables.h12
2 files changed, 19 insertions, 0 deletions
diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
index cae67efa0a..fb40d3138a 100644
--- a/elf/dl-tunables.c
+++ b/elf/dl-tunables.c
@@ -145,6 +145,13 @@ tunable_initialize (tunable_t *cur, const char *strval)
   do_tunable_update_val (cur, &val, NULL, NULL);
 }
 
+bool
+__tunable_is_initialized (tunable_id_t id)
+{
+  return tunable_list[id].initialized;
+}
+rtld_hidden_def (__tunable_is_initialized)
+
 void
 __tunable_set_val (tunable_id_t id, tunable_val_t *valp, tunable_num_t *minp,
 		   tunable_num_t *maxp)
diff --git a/elf/dl-tunables.h b/elf/dl-tunables.h
index 45c191e021..4187ffc525 100644
--- a/elf/dl-tunables.h
+++ b/elf/dl-tunables.h
@@ -45,11 +45,13 @@ typedef void (*tunable_callback_t) (tunable_val_t *);
 
 extern void __tunables_init (char **);
 extern void __tunables_print (void);
+extern bool __tunable_is_initialized (tunable_id_t);
 extern void __tunable_get_val (tunable_id_t, void *, tunable_callback_t);
 extern void __tunable_set_val (tunable_id_t, tunable_val_t *, tunable_num_t *,
 			       tunable_num_t *);
 rtld_hidden_proto (__tunables_init)
 rtld_hidden_proto (__tunables_print)
+rtld_hidden_proto (__tunable_is_initialized)
 rtld_hidden_proto (__tunable_get_val)
 rtld_hidden_proto (__tunable_set_val)
 
@@ -57,6 +59,8 @@ rtld_hidden_proto (__tunable_set_val)
    TUNABLE_NAMESPACE are defined.  This is useful shorthand to get and set
    tunables within a module.  */
 #if defined TOP_NAMESPACE && defined TUNABLE_NAMESPACE
+# define TUNABLE_IS_INITIALIZED(__id) \
+  TUNABLE_IS_INITIALIZED_FULL(TOP_NAMESPACE, TUNABLE_NAMESPACE, __id)
 # define TUNABLE_GET(__id, __type, __cb) \
   TUNABLE_GET_FULL (TOP_NAMESPACE, TUNABLE_NAMESPACE, __id, __type, __cb)
 # define TUNABLE_SET(__id, __val) \
@@ -65,6 +69,8 @@ rtld_hidden_proto (__tunable_set_val)
   TUNABLE_SET_WITH_BOUNDS_FULL (TOP_NAMESPACE, TUNABLE_NAMESPACE, __id, \
 				__val, __min, __max)
 #else
+# define TUNABLE_IS_INITIALIZED(__top, __ns, __id) \
+  TUNABLE_IS_INITIALIZED_FULL(__top, __ns, __id)
 # define TUNABLE_GET(__top, __ns, __id, __type, __cb) \
   TUNABLE_GET_FULL (__top, __ns, __id, __type, __cb)
 # define TUNABLE_SET(__top, __ns, __id, __val) \
@@ -73,6 +79,12 @@ rtld_hidden_proto (__tunable_set_val)
   TUNABLE_SET_WITH_BOUNDS_FULL (__top, __ns, __id, __val, __min, __max)
 #endif
 
+#define TUNABLE_IS_INITIALIZED_FULL(__top, __ns, __id) \
+({									      \
+  tunable_id_t id = TUNABLE_ENUM_NAME (__top, __ns, __id);		      \
+  __tunable_is_initialized (id);					      \
+})
+
 /* Get and return a tunable value.  If the tunable was set externally and __CB
    is defined then call __CB before returning the value.  */
 #define TUNABLE_GET_FULL(__top, __ns, __id, __type, __cb) \