tunables: Simplify TUNABLE_SET interface

System Internals / glibc - Siddhesh Poyarekar [sourceware.org] - 10 February 2021 13:38 UTC

The TUNABLE_SET interface took a primitive C type argument, which resulted in inconsistent type conversions internally due to incorrect dereferencing of types, especialy on 32-bit architectures. This change simplifies the TUNABLE setting logic along with the interfaces.

Now all numeric tunable values are stored as signed numbers in tunable_num_t, which is intmax_t. All calls to set tunables cast the input value to its primitive type and then to tunable_num_t for storage. This relies on gcc-specific (although I suspect other compilers woul also do the same) unsigned to signed integer conversion semantics, i.e. the bit pattern is conserved. The reverse conversion is guaranteed by the standard.

61117bfa1b tunables: Simplify TUNABLE_SET interface
elf/dl-tunable-types.h | 4 +-
elf/dl-tunables.c | 128 ++++++++-----------------
elf/dl-tunables.h | 37 +++----
manual/README.tunables | 16 ++--
sysdeps/unix/sysv/linux/aarch64/cpu-features.c | 2 +-
sysdeps/x86/dl-cacheinfo.h | 15 ++-
6 files changed, 75 insertions(+), 127 deletions(-)

Upstream: sourceware.org


  • Share