2016-12-31 18:02:17 +00:00
|
|
|
/* The tunable framework. See the README.tunables to know how to use the
|
|
|
|
tunable in a glibc module.
|
|
|
|
|
2024-01-01 18:12:26 +00:00
|
|
|
Copyright (C) 2016-2024 Free Software Foundation, Inc.
|
2016-12-31 18:02:17 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2016-12-31 18:02:17 +00:00
|
|
|
|
2021-01-15 12:49:24 +00:00
|
|
|
/* Mark symbols hidden in static PIE for early self relocation to work. */
|
|
|
|
#if BUILD_PIE_DEFAULT
|
|
|
|
# pragma GCC visibility push(hidden)
|
|
|
|
#endif
|
i386: Add <startup.h> [BZ #21913]
On Linux/i386, there are 3 ways to make a system call:
1. call *%gs:SYSINFO_OFFSET. This requires TLS initialization.
2. call *_dl_sysinfo. This requires relocation of _dl_sysinfo.
3. int $0x80. This is slower than #2 and #3, but works everywhere.
When an object file is compiled with PIC, #1 is prefered since it is
faster than #3 and doesn't require relocation of _dl_sysinfo. For
dynamic executables, ld.so initializes TLS. However, for static
executables, before TLS is initialized by __libc_setup_tls, #3 should
be used for system calls.
This patch adds <startup.h> which defines _startup_fatal and defaults
it to __libc_fatal. It replaces __libc_fatal with _startup_fatal in
static executables where it is called before __libc_setup_tls is called.
This header file is included in all files containing functions which are
called before __libc_setup_tls is called. On Linux/i386, when PIE is
enabled by default, _startup_fatal is turned into ABORT_INSTRUCTION and
I386_USE_SYSENTER is defined to 0 so that "int $0x80" is used for system
calls before __libc_setup_tls is called.
Tested on i686 and x86-64. Without this patch, all statically-linked
tests will fail on i686 when the compiler defaults to -fPIE.
[BZ #21913]
* csu/libc-tls.c: Include <startup.h> first.
(__libc_setup_tls): Call _startup_fatal instead of __libc_fatal.
* elf/dl-tunables.c: Include <startup.h> first.
* include/libc-symbols.h (BUILD_PIE_DEFAULT): New.
* sysdeps/generic/startup.h: New file.
* sysdeps/unix/sysv/linux/i386/startup.h: Likewise.
* sysdeps/unix/sysv/linux/i386/brk.c [BUILD_PIE_DEFAULT != 0]
(I386_USE_SYSENTER): New. Defined to 0.
2017-08-08 15:41:08 +00:00
|
|
|
#include <startup.h>
|
2016-12-31 18:02:17 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sysdep.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <ldsodefs.h>
|
2020-07-12 13:04:53 +00:00
|
|
|
#include <array_length.h>
|
2021-11-03 14:20:50 +00:00
|
|
|
#include <dl-minimal-malloc.h>
|
2024-05-06 16:18:45 +00:00
|
|
|
#include <dl-symbol-redir-ifunc.h>
|
2016-12-31 18:02:17 +00:00
|
|
|
|
|
|
|
#define TUNABLES_INTERNAL 1
|
|
|
|
#include "dl-tunables.h"
|
|
|
|
|
|
|
|
static char **
|
2023-12-06 13:24:01 +00:00
|
|
|
get_next_env (char **envp, char **name, char **val, char ***prev_envp)
|
2016-12-31 18:02:17 +00:00
|
|
|
{
|
|
|
|
while (envp != NULL && *envp != NULL)
|
|
|
|
{
|
2017-02-02 10:16:01 +00:00
|
|
|
char **prev = envp;
|
2017-01-19 19:15:09 +00:00
|
|
|
char *envline = *envp++;
|
2016-12-31 18:02:17 +00:00
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
while (envline[len] != '\0' && envline[len] != '=')
|
|
|
|
len++;
|
|
|
|
|
|
|
|
/* Just the name and no value, go to the next one. */
|
|
|
|
if (envline[len] == '\0')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
*name = envline;
|
|
|
|
*val = &envline[len + 1];
|
2017-02-02 10:16:01 +00:00
|
|
|
*prev_envp = prev;
|
2016-12-31 18:02:17 +00:00
|
|
|
|
2017-01-19 19:15:09 +00:00
|
|
|
return envp;
|
2016-12-31 18:02:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-02-05 07:48:58 +00:00
|
|
|
do_tunable_update_val (tunable_t *cur, const tunable_val_t *valp,
|
|
|
|
const tunable_num_t *minp,
|
|
|
|
const tunable_num_t *maxp)
|
2016-12-31 18:02:17 +00:00
|
|
|
{
|
2021-02-05 07:48:58 +00:00
|
|
|
tunable_num_t val, min, max;
|
2017-05-17 07:41:55 +00:00
|
|
|
|
2023-12-06 13:24:02 +00:00
|
|
|
switch (cur->type.type_code)
|
2021-02-05 07:48:58 +00:00
|
|
|
{
|
2023-12-06 13:24:02 +00:00
|
|
|
case TUNABLE_TYPE_STRING:
|
2021-02-05 07:48:58 +00:00
|
|
|
cur->val.strval = valp->strval;
|
|
|
|
cur->initialized = true;
|
|
|
|
return;
|
2023-12-06 13:24:02 +00:00
|
|
|
case TUNABLE_TYPE_INT_32:
|
|
|
|
val = (int32_t) valp->numval;
|
|
|
|
break;
|
|
|
|
case TUNABLE_TYPE_UINT_64:
|
|
|
|
val = (int64_t) valp->numval;
|
|
|
|
break;
|
|
|
|
case TUNABLE_TYPE_SIZE_T:
|
|
|
|
val = (size_t) valp->numval;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
__builtin_unreachable ();
|
2021-02-05 07:48:58 +00:00
|
|
|
}
|
2017-05-17 07:41:55 +00:00
|
|
|
|
2021-03-16 13:01:02 +00:00
|
|
|
bool unsigned_cmp = unsigned_tunable_type (cur->type.type_code);
|
|
|
|
|
2021-02-05 07:48:58 +00:00
|
|
|
min = minp != NULL ? *minp : cur->type.min;
|
|
|
|
max = maxp != NULL ? *maxp : cur->type.max;
|
|
|
|
|
|
|
|
/* We allow only increasingly restrictive bounds. */
|
2021-03-16 13:01:02 +00:00
|
|
|
if (tunable_val_lt (min, cur->type.min, unsigned_cmp))
|
2021-02-05 07:48:58 +00:00
|
|
|
min = cur->type.min;
|
|
|
|
|
2021-03-16 13:01:02 +00:00
|
|
|
if (tunable_val_gt (max, cur->type.max, unsigned_cmp))
|
2021-02-05 07:48:58 +00:00
|
|
|
max = cur->type.max;
|
|
|
|
|
|
|
|
/* Skip both bounds if they're inconsistent. */
|
2021-03-16 13:01:02 +00:00
|
|
|
if (tunable_val_gt (min, max, unsigned_cmp))
|
2016-12-31 18:02:17 +00:00
|
|
|
{
|
2021-02-05 07:48:58 +00:00
|
|
|
min = cur->type.min;
|
|
|
|
max = cur->type.max;
|
|
|
|
}
|
|
|
|
|
2021-03-16 13:01:02 +00:00
|
|
|
/* Bail out if the bounds are not valid. */
|
|
|
|
if (tunable_val_lt (val, min, unsigned_cmp)
|
|
|
|
|| tunable_val_lt (max, val, unsigned_cmp))
|
|
|
|
return;
|
|
|
|
|
|
|
|
cur->val.numval = val;
|
|
|
|
cur->type.min = min;
|
|
|
|
cur->type.max = max;
|
|
|
|
cur->initialized = true;
|
2016-12-31 18:02:17 +00:00
|
|
|
}
|
|
|
|
|
2024-05-06 16:18:46 +00:00
|
|
|
static bool
|
|
|
|
tunable_parse_num (const char *strval, size_t len, tunable_num_t *val)
|
|
|
|
{
|
|
|
|
char *endptr = NULL;
|
|
|
|
uint64_t numval = _dl_strtoul (strval, &endptr);
|
|
|
|
if (endptr != strval + len)
|
|
|
|
return false;
|
|
|
|
*val = (tunable_num_t) numval;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
tunables: Clean up hooks to get and set tunables
The TUNABLE_SET_VALUE and family of macros (and my later attempt to
add a TUNABLE_GET) never quite went together very well because the
overall interface was not clearly defined. This patch is an attempt
to do just that.
This patch consolidates the API to two simple sets of macros,
TUNABLE_GET* and TUNABLE_SET*. If TUNABLE_NAMESPACE is defined,
TUNABLE_GET takes just the tunable name, type and a (optionally NULL)
callback function to get the value of the tunable. The callback
function, if non-NULL, is called if the tunable was externally set
(i.e. via GLIBC_TUNABLES or any future mechanism). For example:
val = TUNABLE_GET (check, int32_t, check_callback)
returns the value of the glibc.malloc.check tunable (assuming
TUNABLE_NAMESPACE is set to malloc) as an int32_t into VAL after
calling check_callback.
Likewise, TUNABLE_SET can be used to set the value of the tunable,
although this is currently possible only in the dynamic linker before
it relocates itself. For example:
TUNABLE_SET (check, int32_t, 2)
will set glibc.malloc.check to 2. Of course, this is not possible
since we set (or read) glibc.malloc.check long after it is relocated.
To access or set a tunable outside of TUNABLE_NAMESPACE, use the
TUNABLE_GET_FULL and TUNABLE_SET_FULL macros, which have the following
prototype:
TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL)
TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, 0xffff)
In future the tunable list may get split into mutable and immutable
tunables where mutable tunables can be modified by the library and
userspace after relocation as well and TUNABLE_SET will be more useful
than it currently is. However whenever we actually do that split, we
will have to ensure that the mutable tunables are protected with
locks.
* elf/Versions (__tunable_set_val): Rename to __tunable_get_val.
* elf/dl-tunables.c: Likewise.
(do_tunable_update_val): New function.
(__tunable_set_val): New function.
(__tunable_get_val): Call CB only if the tunable was externally
initialized.
(tunables_strtoul): Replace strval with initialized.
* elf/dl-tunables.h (strval): Replace with a bool initialized.
(TUNABLE_ENUM_NAME, TUNABLE_ENUM_NAME1): Adjust names to
prevent collision.
(__tunable_set_val): New function.
(TUNABLE_GET, TUNABLE_GET_FULL): New macros.
(TUNABLE_SET, TUNABLE_SET_FULL): Likewise.
(TUNABLE_SET_VAL): Remove.
(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
* README.tunables: Document the new macros.
* malloc/arena.c (ptmalloc_init): Adjust.
2017-06-01 14:54:46 +00:00
|
|
|
/* Validate range of the input value and initialize the tunable CUR if it looks
|
|
|
|
good. */
|
2023-12-06 13:24:02 +00:00
|
|
|
static bool
|
2023-12-06 13:24:01 +00:00
|
|
|
tunable_initialize (tunable_t *cur, const char *strval, size_t len)
|
tunables: Clean up hooks to get and set tunables
The TUNABLE_SET_VALUE and family of macros (and my later attempt to
add a TUNABLE_GET) never quite went together very well because the
overall interface was not clearly defined. This patch is an attempt
to do just that.
This patch consolidates the API to two simple sets of macros,
TUNABLE_GET* and TUNABLE_SET*. If TUNABLE_NAMESPACE is defined,
TUNABLE_GET takes just the tunable name, type and a (optionally NULL)
callback function to get the value of the tunable. The callback
function, if non-NULL, is called if the tunable was externally set
(i.e. via GLIBC_TUNABLES or any future mechanism). For example:
val = TUNABLE_GET (check, int32_t, check_callback)
returns the value of the glibc.malloc.check tunable (assuming
TUNABLE_NAMESPACE is set to malloc) as an int32_t into VAL after
calling check_callback.
Likewise, TUNABLE_SET can be used to set the value of the tunable,
although this is currently possible only in the dynamic linker before
it relocates itself. For example:
TUNABLE_SET (check, int32_t, 2)
will set glibc.malloc.check to 2. Of course, this is not possible
since we set (or read) glibc.malloc.check long after it is relocated.
To access or set a tunable outside of TUNABLE_NAMESPACE, use the
TUNABLE_GET_FULL and TUNABLE_SET_FULL macros, which have the following
prototype:
TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL)
TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, 0xffff)
In future the tunable list may get split into mutable and immutable
tunables where mutable tunables can be modified by the library and
userspace after relocation as well and TUNABLE_SET will be more useful
than it currently is. However whenever we actually do that split, we
will have to ensure that the mutable tunables are protected with
locks.
* elf/Versions (__tunable_set_val): Rename to __tunable_get_val.
* elf/dl-tunables.c: Likewise.
(do_tunable_update_val): New function.
(__tunable_set_val): New function.
(__tunable_get_val): Call CB only if the tunable was externally
initialized.
(tunables_strtoul): Replace strval with initialized.
* elf/dl-tunables.h (strval): Replace with a bool initialized.
(TUNABLE_ENUM_NAME, TUNABLE_ENUM_NAME1): Adjust names to
prevent collision.
(__tunable_set_val): New function.
(TUNABLE_GET, TUNABLE_GET_FULL): New macros.
(TUNABLE_SET, TUNABLE_SET_FULL): Likewise.
(TUNABLE_SET_VAL): Remove.
(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
* README.tunables: Document the new macros.
* malloc/arena.c (ptmalloc_init): Adjust.
2017-06-01 14:54:46 +00:00
|
|
|
{
|
2023-12-06 13:24:01 +00:00
|
|
|
tunable_val_t val = { 0 };
|
tunables: Clean up hooks to get and set tunables
The TUNABLE_SET_VALUE and family of macros (and my later attempt to
add a TUNABLE_GET) never quite went together very well because the
overall interface was not clearly defined. This patch is an attempt
to do just that.
This patch consolidates the API to two simple sets of macros,
TUNABLE_GET* and TUNABLE_SET*. If TUNABLE_NAMESPACE is defined,
TUNABLE_GET takes just the tunable name, type and a (optionally NULL)
callback function to get the value of the tunable. The callback
function, if non-NULL, is called if the tunable was externally set
(i.e. via GLIBC_TUNABLES or any future mechanism). For example:
val = TUNABLE_GET (check, int32_t, check_callback)
returns the value of the glibc.malloc.check tunable (assuming
TUNABLE_NAMESPACE is set to malloc) as an int32_t into VAL after
calling check_callback.
Likewise, TUNABLE_SET can be used to set the value of the tunable,
although this is currently possible only in the dynamic linker before
it relocates itself. For example:
TUNABLE_SET (check, int32_t, 2)
will set glibc.malloc.check to 2. Of course, this is not possible
since we set (or read) glibc.malloc.check long after it is relocated.
To access or set a tunable outside of TUNABLE_NAMESPACE, use the
TUNABLE_GET_FULL and TUNABLE_SET_FULL macros, which have the following
prototype:
TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL)
TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, 0xffff)
In future the tunable list may get split into mutable and immutable
tunables where mutable tunables can be modified by the library and
userspace after relocation as well and TUNABLE_SET will be more useful
than it currently is. However whenever we actually do that split, we
will have to ensure that the mutable tunables are protected with
locks.
* elf/Versions (__tunable_set_val): Rename to __tunable_get_val.
* elf/dl-tunables.c: Likewise.
(do_tunable_update_val): New function.
(__tunable_set_val): New function.
(__tunable_get_val): Call CB only if the tunable was externally
initialized.
(tunables_strtoul): Replace strval with initialized.
* elf/dl-tunables.h (strval): Replace with a bool initialized.
(TUNABLE_ENUM_NAME, TUNABLE_ENUM_NAME1): Adjust names to
prevent collision.
(__tunable_set_val): New function.
(TUNABLE_GET, TUNABLE_GET_FULL): New macros.
(TUNABLE_SET, TUNABLE_SET_FULL): Likewise.
(TUNABLE_SET_VAL): Remove.
(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
* README.tunables: Document the new macros.
* malloc/arena.c (ptmalloc_init): Adjust.
2017-06-01 14:54:46 +00:00
|
|
|
|
|
|
|
if (cur->type.type_code != TUNABLE_TYPE_STRING)
|
2023-12-06 13:24:02 +00:00
|
|
|
{
|
2024-05-06 16:18:46 +00:00
|
|
|
if (!tunable_parse_num (strval, len, &val.numval))
|
2023-12-06 13:24:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
tunables: Clean up hooks to get and set tunables
The TUNABLE_SET_VALUE and family of macros (and my later attempt to
add a TUNABLE_GET) never quite went together very well because the
overall interface was not clearly defined. This patch is an attempt
to do just that.
This patch consolidates the API to two simple sets of macros,
TUNABLE_GET* and TUNABLE_SET*. If TUNABLE_NAMESPACE is defined,
TUNABLE_GET takes just the tunable name, type and a (optionally NULL)
callback function to get the value of the tunable. The callback
function, if non-NULL, is called if the tunable was externally set
(i.e. via GLIBC_TUNABLES or any future mechanism). For example:
val = TUNABLE_GET (check, int32_t, check_callback)
returns the value of the glibc.malloc.check tunable (assuming
TUNABLE_NAMESPACE is set to malloc) as an int32_t into VAL after
calling check_callback.
Likewise, TUNABLE_SET can be used to set the value of the tunable,
although this is currently possible only in the dynamic linker before
it relocates itself. For example:
TUNABLE_SET (check, int32_t, 2)
will set glibc.malloc.check to 2. Of course, this is not possible
since we set (or read) glibc.malloc.check long after it is relocated.
To access or set a tunable outside of TUNABLE_NAMESPACE, use the
TUNABLE_GET_FULL and TUNABLE_SET_FULL macros, which have the following
prototype:
TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL)
TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, 0xffff)
In future the tunable list may get split into mutable and immutable
tunables where mutable tunables can be modified by the library and
userspace after relocation as well and TUNABLE_SET will be more useful
than it currently is. However whenever we actually do that split, we
will have to ensure that the mutable tunables are protected with
locks.
* elf/Versions (__tunable_set_val): Rename to __tunable_get_val.
* elf/dl-tunables.c: Likewise.
(do_tunable_update_val): New function.
(__tunable_set_val): New function.
(__tunable_get_val): Call CB only if the tunable was externally
initialized.
(tunables_strtoul): Replace strval with initialized.
* elf/dl-tunables.h (strval): Replace with a bool initialized.
(TUNABLE_ENUM_NAME, TUNABLE_ENUM_NAME1): Adjust names to
prevent collision.
(__tunable_set_val): New function.
(TUNABLE_GET, TUNABLE_GET_FULL): New macros.
(TUNABLE_SET, TUNABLE_SET_FULL): Likewise.
(TUNABLE_SET_VAL): Remove.
(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
* README.tunables: Document the new macros.
* malloc/arena.c (ptmalloc_init): Adjust.
2017-06-01 14:54:46 +00:00
|
|
|
else
|
2023-12-06 13:24:01 +00:00
|
|
|
val.strval = (struct tunable_str_t) { strval, len };
|
2021-02-05 07:48:58 +00:00
|
|
|
do_tunable_update_val (cur, &val, NULL, NULL);
|
2023-12-06 13:24:02 +00:00
|
|
|
|
|
|
|
return true;
|
tunables: Clean up hooks to get and set tunables
The TUNABLE_SET_VALUE and family of macros (and my later attempt to
add a TUNABLE_GET) never quite went together very well because the
overall interface was not clearly defined. This patch is an attempt
to do just that.
This patch consolidates the API to two simple sets of macros,
TUNABLE_GET* and TUNABLE_SET*. If TUNABLE_NAMESPACE is defined,
TUNABLE_GET takes just the tunable name, type and a (optionally NULL)
callback function to get the value of the tunable. The callback
function, if non-NULL, is called if the tunable was externally set
(i.e. via GLIBC_TUNABLES or any future mechanism). For example:
val = TUNABLE_GET (check, int32_t, check_callback)
returns the value of the glibc.malloc.check tunable (assuming
TUNABLE_NAMESPACE is set to malloc) as an int32_t into VAL after
calling check_callback.
Likewise, TUNABLE_SET can be used to set the value of the tunable,
although this is currently possible only in the dynamic linker before
it relocates itself. For example:
TUNABLE_SET (check, int32_t, 2)
will set glibc.malloc.check to 2. Of course, this is not possible
since we set (or read) glibc.malloc.check long after it is relocated.
To access or set a tunable outside of TUNABLE_NAMESPACE, use the
TUNABLE_GET_FULL and TUNABLE_SET_FULL macros, which have the following
prototype:
TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL)
TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, 0xffff)
In future the tunable list may get split into mutable and immutable
tunables where mutable tunables can be modified by the library and
userspace after relocation as well and TUNABLE_SET will be more useful
than it currently is. However whenever we actually do that split, we
will have to ensure that the mutable tunables are protected with
locks.
* elf/Versions (__tunable_set_val): Rename to __tunable_get_val.
* elf/dl-tunables.c: Likewise.
(do_tunable_update_val): New function.
(__tunable_set_val): New function.
(__tunable_get_val): Call CB only if the tunable was externally
initialized.
(tunables_strtoul): Replace strval with initialized.
* elf/dl-tunables.h (strval): Replace with a bool initialized.
(TUNABLE_ENUM_NAME, TUNABLE_ENUM_NAME1): Adjust names to
prevent collision.
(__tunable_set_val): New function.
(TUNABLE_GET, TUNABLE_GET_FULL): New macros.
(TUNABLE_SET, TUNABLE_SET_FULL): Likewise.
(TUNABLE_SET_VAL): Remove.
(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
* README.tunables: Document the new macros.
* malloc/arena.c (ptmalloc_init): Adjust.
2017-06-01 14:54:46 +00:00
|
|
|
}
|
|
|
|
|
2023-11-23 17:29:14 +00:00
|
|
|
bool
|
|
|
|
__tunable_is_initialized (tunable_id_t id)
|
|
|
|
{
|
|
|
|
return tunable_list[id].initialized;
|
|
|
|
}
|
|
|
|
rtld_hidden_def (__tunable_is_initialized)
|
|
|
|
|
tunables: Clean up hooks to get and set tunables
The TUNABLE_SET_VALUE and family of macros (and my later attempt to
add a TUNABLE_GET) never quite went together very well because the
overall interface was not clearly defined. This patch is an attempt
to do just that.
This patch consolidates the API to two simple sets of macros,
TUNABLE_GET* and TUNABLE_SET*. If TUNABLE_NAMESPACE is defined,
TUNABLE_GET takes just the tunable name, type and a (optionally NULL)
callback function to get the value of the tunable. The callback
function, if non-NULL, is called if the tunable was externally set
(i.e. via GLIBC_TUNABLES or any future mechanism). For example:
val = TUNABLE_GET (check, int32_t, check_callback)
returns the value of the glibc.malloc.check tunable (assuming
TUNABLE_NAMESPACE is set to malloc) as an int32_t into VAL after
calling check_callback.
Likewise, TUNABLE_SET can be used to set the value of the tunable,
although this is currently possible only in the dynamic linker before
it relocates itself. For example:
TUNABLE_SET (check, int32_t, 2)
will set glibc.malloc.check to 2. Of course, this is not possible
since we set (or read) glibc.malloc.check long after it is relocated.
To access or set a tunable outside of TUNABLE_NAMESPACE, use the
TUNABLE_GET_FULL and TUNABLE_SET_FULL macros, which have the following
prototype:
TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL)
TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, 0xffff)
In future the tunable list may get split into mutable and immutable
tunables where mutable tunables can be modified by the library and
userspace after relocation as well and TUNABLE_SET will be more useful
than it currently is. However whenever we actually do that split, we
will have to ensure that the mutable tunables are protected with
locks.
* elf/Versions (__tunable_set_val): Rename to __tunable_get_val.
* elf/dl-tunables.c: Likewise.
(do_tunable_update_val): New function.
(__tunable_set_val): New function.
(__tunable_get_val): Call CB only if the tunable was externally
initialized.
(tunables_strtoul): Replace strval with initialized.
* elf/dl-tunables.h (strval): Replace with a bool initialized.
(TUNABLE_ENUM_NAME, TUNABLE_ENUM_NAME1): Adjust names to
prevent collision.
(__tunable_set_val): New function.
(TUNABLE_GET, TUNABLE_GET_FULL): New macros.
(TUNABLE_SET, TUNABLE_SET_FULL): Likewise.
(TUNABLE_SET_VAL): Remove.
(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
* README.tunables: Document the new macros.
* malloc/arena.c (ptmalloc_init): Adjust.
2017-06-01 14:54:46 +00:00
|
|
|
void
|
2021-02-05 07:48:58 +00:00
|
|
|
__tunable_set_val (tunable_id_t id, tunable_val_t *valp, tunable_num_t *minp,
|
|
|
|
tunable_num_t *maxp)
|
tunables: Clean up hooks to get and set tunables
The TUNABLE_SET_VALUE and family of macros (and my later attempt to
add a TUNABLE_GET) never quite went together very well because the
overall interface was not clearly defined. This patch is an attempt
to do just that.
This patch consolidates the API to two simple sets of macros,
TUNABLE_GET* and TUNABLE_SET*. If TUNABLE_NAMESPACE is defined,
TUNABLE_GET takes just the tunable name, type and a (optionally NULL)
callback function to get the value of the tunable. The callback
function, if non-NULL, is called if the tunable was externally set
(i.e. via GLIBC_TUNABLES or any future mechanism). For example:
val = TUNABLE_GET (check, int32_t, check_callback)
returns the value of the glibc.malloc.check tunable (assuming
TUNABLE_NAMESPACE is set to malloc) as an int32_t into VAL after
calling check_callback.
Likewise, TUNABLE_SET can be used to set the value of the tunable,
although this is currently possible only in the dynamic linker before
it relocates itself. For example:
TUNABLE_SET (check, int32_t, 2)
will set glibc.malloc.check to 2. Of course, this is not possible
since we set (or read) glibc.malloc.check long after it is relocated.
To access or set a tunable outside of TUNABLE_NAMESPACE, use the
TUNABLE_GET_FULL and TUNABLE_SET_FULL macros, which have the following
prototype:
TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL)
TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, 0xffff)
In future the tunable list may get split into mutable and immutable
tunables where mutable tunables can be modified by the library and
userspace after relocation as well and TUNABLE_SET will be more useful
than it currently is. However whenever we actually do that split, we
will have to ensure that the mutable tunables are protected with
locks.
* elf/Versions (__tunable_set_val): Rename to __tunable_get_val.
* elf/dl-tunables.c: Likewise.
(do_tunable_update_val): New function.
(__tunable_set_val): New function.
(__tunable_get_val): Call CB only if the tunable was externally
initialized.
(tunables_strtoul): Replace strval with initialized.
* elf/dl-tunables.h (strval): Replace with a bool initialized.
(TUNABLE_ENUM_NAME, TUNABLE_ENUM_NAME1): Adjust names to
prevent collision.
(__tunable_set_val): New function.
(TUNABLE_GET, TUNABLE_GET_FULL): New macros.
(TUNABLE_SET, TUNABLE_SET_FULL): Likewise.
(TUNABLE_SET_VAL): Remove.
(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
* README.tunables: Document the new macros.
* malloc/arena.c (ptmalloc_init): Adjust.
2017-06-01 14:54:46 +00:00
|
|
|
{
|
|
|
|
tunable_t *cur = &tunable_list[id];
|
|
|
|
|
2020-06-01 21:11:32 +00:00
|
|
|
do_tunable_update_val (cur, valp, minp, maxp);
|
tunables: Clean up hooks to get and set tunables
The TUNABLE_SET_VALUE and family of macros (and my later attempt to
add a TUNABLE_GET) never quite went together very well because the
overall interface was not clearly defined. This patch is an attempt
to do just that.
This patch consolidates the API to two simple sets of macros,
TUNABLE_GET* and TUNABLE_SET*. If TUNABLE_NAMESPACE is defined,
TUNABLE_GET takes just the tunable name, type and a (optionally NULL)
callback function to get the value of the tunable. The callback
function, if non-NULL, is called if the tunable was externally set
(i.e. via GLIBC_TUNABLES or any future mechanism). For example:
val = TUNABLE_GET (check, int32_t, check_callback)
returns the value of the glibc.malloc.check tunable (assuming
TUNABLE_NAMESPACE is set to malloc) as an int32_t into VAL after
calling check_callback.
Likewise, TUNABLE_SET can be used to set the value of the tunable,
although this is currently possible only in the dynamic linker before
it relocates itself. For example:
TUNABLE_SET (check, int32_t, 2)
will set glibc.malloc.check to 2. Of course, this is not possible
since we set (or read) glibc.malloc.check long after it is relocated.
To access or set a tunable outside of TUNABLE_NAMESPACE, use the
TUNABLE_GET_FULL and TUNABLE_SET_FULL macros, which have the following
prototype:
TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL)
TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, 0xffff)
In future the tunable list may get split into mutable and immutable
tunables where mutable tunables can be modified by the library and
userspace after relocation as well and TUNABLE_SET will be more useful
than it currently is. However whenever we actually do that split, we
will have to ensure that the mutable tunables are protected with
locks.
* elf/Versions (__tunable_set_val): Rename to __tunable_get_val.
* elf/dl-tunables.c: Likewise.
(do_tunable_update_val): New function.
(__tunable_set_val): New function.
(__tunable_get_val): Call CB only if the tunable was externally
initialized.
(tunables_strtoul): Replace strval with initialized.
* elf/dl-tunables.h (strval): Replace with a bool initialized.
(TUNABLE_ENUM_NAME, TUNABLE_ENUM_NAME1): Adjust names to
prevent collision.
(__tunable_set_val): New function.
(TUNABLE_GET, TUNABLE_GET_FULL): New macros.
(TUNABLE_SET, TUNABLE_SET_FULL): Likewise.
(TUNABLE_SET_VAL): Remove.
(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
* README.tunables: Document the new macros.
* malloc/arena.c (ptmalloc_init): Adjust.
2017-06-01 14:54:46 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 20:25:39 +00:00
|
|
|
struct tunable_toset_t
|
|
|
|
{
|
|
|
|
tunable_t *t;
|
|
|
|
const char *value;
|
2023-12-06 13:24:01 +00:00
|
|
|
size_t len;
|
2023-11-06 20:25:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum { tunables_list_size = array_length (tunable_list) };
|
|
|
|
|
|
|
|
/* Parse the tunable string VALSTRING and set TUNABLES with the found tunables
|
2023-12-06 13:24:01 +00:00
|
|
|
and their respective values. The VALSTRING is parsed in place, with the
|
|
|
|
tunable start and size recorded in TUNABLES.
|
2023-11-06 20:25:39 +00:00
|
|
|
Return the number of tunables found (including 0 if the string is empty)
|
|
|
|
or -1 if for an ill-formatted definition. */
|
|
|
|
static int
|
2023-12-06 13:24:01 +00:00
|
|
|
parse_tunables_string (const char *valstring, struct tunable_toset_t *tunables)
|
2016-12-31 18:03:27 +00:00
|
|
|
{
|
2023-11-06 20:25:36 +00:00
|
|
|
if (valstring == NULL || *valstring == '\0')
|
2023-11-06 20:25:39 +00:00
|
|
|
return 0;
|
2016-12-31 18:03:27 +00:00
|
|
|
|
2023-12-06 13:24:01 +00:00
|
|
|
const char *p = valstring;
|
2023-11-06 20:25:36 +00:00
|
|
|
bool done = false;
|
2023-11-06 20:25:39 +00:00
|
|
|
int ntunables = 0;
|
2016-12-31 18:03:27 +00:00
|
|
|
|
2023-11-06 20:25:36 +00:00
|
|
|
while (!done)
|
2016-12-31 18:03:27 +00:00
|
|
|
{
|
2023-12-06 13:24:01 +00:00
|
|
|
const char *name = p;
|
2016-12-31 18:03:27 +00:00
|
|
|
|
|
|
|
/* First, find where the name ends. */
|
2023-11-06 20:25:36 +00:00
|
|
|
while (*p != '=' && *p != ':' && *p != '\0')
|
|
|
|
p++;
|
2016-12-31 18:03:27 +00:00
|
|
|
|
|
|
|
/* If we reach the end of the string before getting a valid name-value
|
|
|
|
pair, bail out. */
|
2023-11-06 20:25:36 +00:00
|
|
|
if (*p == '\0')
|
2023-11-06 20:25:39 +00:00
|
|
|
return -1;
|
2016-12-31 18:03:27 +00:00
|
|
|
|
|
|
|
/* We did not find a valid name-value pair before encountering the
|
|
|
|
colon. */
|
2023-11-06 20:25:36 +00:00
|
|
|
if (*p == ':')
|
2016-12-31 18:03:27 +00:00
|
|
|
{
|
2023-11-06 20:25:36 +00:00
|
|
|
p++;
|
2016-12-31 18:03:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-11-06 20:25:36 +00:00
|
|
|
/* Skip the '='. */
|
|
|
|
p++;
|
2016-12-31 18:03:27 +00:00
|
|
|
|
2023-12-06 13:24:01 +00:00
|
|
|
const char *value = p;
|
2016-12-31 18:03:27 +00:00
|
|
|
|
2023-11-06 20:25:38 +00:00
|
|
|
while (*p != '=' && *p != ':' && *p != '\0')
|
2023-11-06 20:25:36 +00:00
|
|
|
p++;
|
|
|
|
|
2023-11-06 20:25:38 +00:00
|
|
|
if (*p == '=')
|
2023-11-06 20:25:39 +00:00
|
|
|
return -1;
|
2023-11-06 20:25:38 +00:00
|
|
|
else if (*p == '\0')
|
2023-11-06 20:25:36 +00:00
|
|
|
done = true;
|
2016-12-31 18:03:27 +00:00
|
|
|
|
|
|
|
/* Add the tunable if it exists. */
|
2023-11-06 20:25:39 +00:00
|
|
|
for (size_t i = 0; i < tunables_list_size; i++)
|
2016-12-31 18:03:27 +00:00
|
|
|
{
|
|
|
|
tunable_t *cur = &tunable_list[i];
|
|
|
|
|
2017-06-30 17:28:39 +00:00
|
|
|
if (tunable_is_name (cur->name, name))
|
2016-12-31 18:03:27 +00:00
|
|
|
{
|
2024-05-06 16:18:45 +00:00
|
|
|
tunables[i] = (struct tunable_toset_t) { cur, value, p - value };
|
2016-12-31 18:03:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-06 20:25:39 +00:00
|
|
|
|
|
|
|
return ntunables;
|
|
|
|
}
|
|
|
|
|
2024-05-06 16:18:46 +00:00
|
|
|
static void
|
|
|
|
parse_tunable_print_error (const struct tunable_toset_t *toset)
|
|
|
|
{
|
|
|
|
_dl_error_printf ("WARNING: ld.so: invalid GLIBC_TUNABLES value `%.*s' "
|
|
|
|
"for option `%s': ignored.\n",
|
|
|
|
(int) toset->len,
|
|
|
|
toset->value,
|
|
|
|
toset->t->name);
|
|
|
|
}
|
|
|
|
|
2023-11-06 20:25:39 +00:00
|
|
|
static void
|
2023-12-06 13:24:01 +00:00
|
|
|
parse_tunables (const char *valstring)
|
2023-11-06 20:25:39 +00:00
|
|
|
{
|
2024-05-06 16:18:45 +00:00
|
|
|
struct tunable_toset_t tunables[tunables_list_size] = { 0 };
|
|
|
|
if (parse_tunables_string (valstring, tunables) == -1)
|
2023-11-06 20:25:41 +00:00
|
|
|
{
|
|
|
|
_dl_error_printf (
|
|
|
|
"WARNING: ld.so: invalid GLIBC_TUNABLES `%s': ignored.\n", valstring);
|
|
|
|
return;
|
|
|
|
}
|
2023-11-06 20:25:39 +00:00
|
|
|
|
2024-05-06 16:18:46 +00:00
|
|
|
/* Ignore tunables if enable_secure is set */
|
|
|
|
struct tunable_toset_t *tsec =
|
|
|
|
&tunables[TUNABLE_ENUM_NAME(glibc, rtld, enable_secure)];
|
|
|
|
if (tsec->t != NULL)
|
|
|
|
{
|
|
|
|
tunable_num_t val;
|
|
|
|
if (!tunable_parse_num (tsec->value, tsec->len, &val))
|
|
|
|
parse_tunable_print_error (tsec);
|
|
|
|
else if (val == 1)
|
|
|
|
{
|
|
|
|
__libc_enable_secure = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-06 16:18:45 +00:00
|
|
|
for (int i = 0; i < tunables_list_size; i++)
|
|
|
|
{
|
|
|
|
if (tunables[i].t == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!tunable_initialize (tunables[i].t, tunables[i].value,
|
|
|
|
tunables[i].len))
|
2024-05-06 16:18:46 +00:00
|
|
|
parse_tunable_print_error (&tunables[i]);
|
2024-05-06 16:18:45 +00:00
|
|
|
}
|
2016-12-31 18:03:27 +00:00
|
|
|
}
|
|
|
|
|
2016-12-31 18:02:17 +00:00
|
|
|
/* Initialize the tunables list from the environment. For now we only use the
|
|
|
|
ENV_ALIAS to find values. Later we will also use the tunable names to find
|
|
|
|
values. */
|
|
|
|
void
|
|
|
|
__tunables_init (char **envp)
|
|
|
|
{
|
|
|
|
char *envname = NULL;
|
|
|
|
char *envval = NULL;
|
2017-02-02 10:16:01 +00:00
|
|
|
char **prev_envp = envp;
|
2016-12-31 18:02:17 +00:00
|
|
|
|
2023-11-06 20:25:36 +00:00
|
|
|
/* Ignore tunables for AT_SECURE programs. */
|
|
|
|
if (__libc_enable_secure)
|
|
|
|
return;
|
|
|
|
|
2024-05-06 16:18:48 +00:00
|
|
|
enum { tunable_num_env_alias = array_length (tunable_env_alias_list) };
|
|
|
|
struct tunable_toset_t tunables_env_alias[tunable_num_env_alias] = { 0 };
|
|
|
|
|
2023-12-06 13:24:01 +00:00
|
|
|
while ((envp = get_next_env (envp, &envname, &envval, &prev_envp)) != NULL)
|
2016-12-31 18:02:17 +00:00
|
|
|
{
|
2023-12-06 13:24:01 +00:00
|
|
|
/* The environment variable is allocated on the stack by the kernel, so
|
|
|
|
it is safe to keep the references to the suboptions for later parsing
|
|
|
|
of string tunables. */
|
2023-03-23 13:13:51 +00:00
|
|
|
if (tunable_is_name ("GLIBC_TUNABLES", envname))
|
2016-12-31 18:03:27 +00:00
|
|
|
{
|
2023-12-06 13:24:01 +00:00
|
|
|
parse_tunables (envval);
|
2016-12-31 18:03:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-05-06 16:18:48 +00:00
|
|
|
for (int i = 0; i < tunable_num_env_alias; i++)
|
2016-12-31 18:02:17 +00:00
|
|
|
{
|
2024-05-06 16:18:48 +00:00
|
|
|
tunable_t *cur = &tunable_list[tunable_env_alias_list[i]];
|
|
|
|
const char *name = cur->env_alias;
|
2016-12-31 18:02:17 +00:00
|
|
|
|
2024-05-06 16:18:48 +00:00
|
|
|
if (name[0] == '\0')
|
2016-12-31 18:02:17 +00:00
|
|
|
continue;
|
|
|
|
|
2017-06-30 17:28:39 +00:00
|
|
|
if (tunable_is_name (name, envname))
|
2016-12-31 18:02:17 +00:00
|
|
|
{
|
2023-12-06 13:24:01 +00:00
|
|
|
size_t envvallen = 0;
|
|
|
|
/* The environment variable is always null-terminated. */
|
|
|
|
for (const char *p = envval; *p != '\0'; p++, envvallen++);
|
|
|
|
|
2024-05-06 16:18:48 +00:00
|
|
|
tunables_env_alias[i] =
|
|
|
|
(struct tunable_toset_t) { cur, envval, envvallen };
|
2016-12-31 18:02:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-05-06 16:18:48 +00:00
|
|
|
|
|
|
|
/* Check if glibc.rtld.enable_secure was set and skip over the environment
|
|
|
|
variables aliases. */
|
|
|
|
if (__libc_enable_secure)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (int i = 0; i < tunable_num_env_alias; i++)
|
|
|
|
{
|
|
|
|
/* Skip over tunables that have either been set or already initialized. */
|
|
|
|
if (tunables_env_alias[i].t == NULL
|
|
|
|
|| tunables_env_alias[i].t->initialized)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!tunable_initialize (tunables_env_alias[i].t,
|
|
|
|
tunables_env_alias[i].value,
|
|
|
|
tunables_env_alias[i].len))
|
|
|
|
parse_tunable_print_error (&tunables_env_alias[i]);
|
|
|
|
}
|
2016-12-31 18:02:17 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 13:04:53 +00:00
|
|
|
void
|
|
|
|
__tunables_print (void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < array_length (tunable_list); i++)
|
|
|
|
{
|
|
|
|
const tunable_t *cur = &tunable_list[i];
|
|
|
|
if (cur->type.type_code == TUNABLE_TYPE_STRING
|
2023-12-06 13:24:01 +00:00
|
|
|
&& cur->val.strval.str == NULL)
|
2020-07-12 13:04:53 +00:00
|
|
|
_dl_printf ("%s:\n", cur->name);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_dl_printf ("%s: ", cur->name);
|
|
|
|
switch (cur->type.type_code)
|
|
|
|
{
|
|
|
|
case TUNABLE_TYPE_INT_32:
|
|
|
|
_dl_printf ("%d (min: %d, max: %d)\n",
|
|
|
|
(int) cur->val.numval,
|
|
|
|
(int) cur->type.min,
|
|
|
|
(int) cur->type.max);
|
|
|
|
break;
|
|
|
|
case TUNABLE_TYPE_UINT_64:
|
|
|
|
_dl_printf ("0x%lx (min: 0x%lx, max: 0x%lx)\n",
|
|
|
|
(long int) cur->val.numval,
|
|
|
|
(long int) cur->type.min,
|
|
|
|
(long int) cur->type.max);
|
|
|
|
break;
|
|
|
|
case TUNABLE_TYPE_SIZE_T:
|
2022-09-01 13:02:30 +00:00
|
|
|
_dl_printf ("0x%zx (min: 0x%zx, max: 0x%zx)\n",
|
2020-07-12 13:04:53 +00:00
|
|
|
(size_t) cur->val.numval,
|
|
|
|
(size_t) cur->type.min,
|
|
|
|
(size_t) cur->type.max);
|
|
|
|
break;
|
|
|
|
case TUNABLE_TYPE_STRING:
|
2023-12-06 13:24:01 +00:00
|
|
|
_dl_printf ("%.*s\n",
|
|
|
|
(int) cur->val.strval.len,
|
|
|
|
cur->val.strval.str);
|
2020-07-12 13:04:53 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
__builtin_unreachable ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-23 17:29:14 +00:00
|
|
|
void
|
|
|
|
__tunable_get_default (tunable_id_t id, void *valp)
|
|
|
|
{
|
|
|
|
tunable_t *cur = &tunable_list[id];
|
|
|
|
|
|
|
|
switch (cur->type.type_code)
|
|
|
|
{
|
|
|
|
case TUNABLE_TYPE_UINT_64:
|
|
|
|
{
|
|
|
|
*((uint64_t *) valp) = (uint64_t) cur->def.numval;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TUNABLE_TYPE_INT_32:
|
|
|
|
{
|
|
|
|
*((int32_t *) valp) = (int32_t) cur->def.numval;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TUNABLE_TYPE_SIZE_T:
|
|
|
|
{
|
|
|
|
*((size_t *) valp) = (size_t) cur->def.numval;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TUNABLE_TYPE_STRING:
|
|
|
|
{
|
2023-12-06 13:24:01 +00:00
|
|
|
*((const struct tunable_str_t **)valp) = &cur->def.strval;
|
2023-11-23 17:29:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
__builtin_unreachable ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rtld_hidden_def (__tunable_get_default)
|
|
|
|
|
2016-12-31 18:02:17 +00:00
|
|
|
/* Set the tunable value. This is called by the module that the tunable exists
|
|
|
|
in. */
|
|
|
|
void
|
tunables: Clean up hooks to get and set tunables
The TUNABLE_SET_VALUE and family of macros (and my later attempt to
add a TUNABLE_GET) never quite went together very well because the
overall interface was not clearly defined. This patch is an attempt
to do just that.
This patch consolidates the API to two simple sets of macros,
TUNABLE_GET* and TUNABLE_SET*. If TUNABLE_NAMESPACE is defined,
TUNABLE_GET takes just the tunable name, type and a (optionally NULL)
callback function to get the value of the tunable. The callback
function, if non-NULL, is called if the tunable was externally set
(i.e. via GLIBC_TUNABLES or any future mechanism). For example:
val = TUNABLE_GET (check, int32_t, check_callback)
returns the value of the glibc.malloc.check tunable (assuming
TUNABLE_NAMESPACE is set to malloc) as an int32_t into VAL after
calling check_callback.
Likewise, TUNABLE_SET can be used to set the value of the tunable,
although this is currently possible only in the dynamic linker before
it relocates itself. For example:
TUNABLE_SET (check, int32_t, 2)
will set glibc.malloc.check to 2. Of course, this is not possible
since we set (or read) glibc.malloc.check long after it is relocated.
To access or set a tunable outside of TUNABLE_NAMESPACE, use the
TUNABLE_GET_FULL and TUNABLE_SET_FULL macros, which have the following
prototype:
TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL)
TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, 0xffff)
In future the tunable list may get split into mutable and immutable
tunables where mutable tunables can be modified by the library and
userspace after relocation as well and TUNABLE_SET will be more useful
than it currently is. However whenever we actually do that split, we
will have to ensure that the mutable tunables are protected with
locks.
* elf/Versions (__tunable_set_val): Rename to __tunable_get_val.
* elf/dl-tunables.c: Likewise.
(do_tunable_update_val): New function.
(__tunable_set_val): New function.
(__tunable_get_val): Call CB only if the tunable was externally
initialized.
(tunables_strtoul): Replace strval with initialized.
* elf/dl-tunables.h (strval): Replace with a bool initialized.
(TUNABLE_ENUM_NAME, TUNABLE_ENUM_NAME1): Adjust names to
prevent collision.
(__tunable_set_val): New function.
(TUNABLE_GET, TUNABLE_GET_FULL): New macros.
(TUNABLE_SET, TUNABLE_SET_FULL): Likewise.
(TUNABLE_SET_VAL): Remove.
(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
* README.tunables: Document the new macros.
* malloc/arena.c (ptmalloc_init): Adjust.
2017-06-01 14:54:46 +00:00
|
|
|
__tunable_get_val (tunable_id_t id, void *valp, tunable_callback_t callback)
|
2016-12-31 18:02:17 +00:00
|
|
|
{
|
|
|
|
tunable_t *cur = &tunable_list[id];
|
|
|
|
|
|
|
|
switch (cur->type.type_code)
|
|
|
|
{
|
2017-05-17 07:41:55 +00:00
|
|
|
case TUNABLE_TYPE_UINT_64:
|
|
|
|
{
|
|
|
|
*((uint64_t *) valp) = (uint64_t) cur->val.numval;
|
|
|
|
break;
|
|
|
|
}
|
2016-12-31 18:02:17 +00:00
|
|
|
case TUNABLE_TYPE_INT_32:
|
|
|
|
{
|
|
|
|
*((int32_t *) valp) = (int32_t) cur->val.numval;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TUNABLE_TYPE_SIZE_T:
|
|
|
|
{
|
|
|
|
*((size_t *) valp) = (size_t) cur->val.numval;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TUNABLE_TYPE_STRING:
|
|
|
|
{
|
2023-12-06 13:24:01 +00:00
|
|
|
*((const struct tunable_str_t **) valp) = &cur->val.strval;
|
2016-12-31 18:02:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
__builtin_unreachable ();
|
|
|
|
}
|
|
|
|
|
tunables: Clean up hooks to get and set tunables
The TUNABLE_SET_VALUE and family of macros (and my later attempt to
add a TUNABLE_GET) never quite went together very well because the
overall interface was not clearly defined. This patch is an attempt
to do just that.
This patch consolidates the API to two simple sets of macros,
TUNABLE_GET* and TUNABLE_SET*. If TUNABLE_NAMESPACE is defined,
TUNABLE_GET takes just the tunable name, type and a (optionally NULL)
callback function to get the value of the tunable. The callback
function, if non-NULL, is called if the tunable was externally set
(i.e. via GLIBC_TUNABLES or any future mechanism). For example:
val = TUNABLE_GET (check, int32_t, check_callback)
returns the value of the glibc.malloc.check tunable (assuming
TUNABLE_NAMESPACE is set to malloc) as an int32_t into VAL after
calling check_callback.
Likewise, TUNABLE_SET can be used to set the value of the tunable,
although this is currently possible only in the dynamic linker before
it relocates itself. For example:
TUNABLE_SET (check, int32_t, 2)
will set glibc.malloc.check to 2. Of course, this is not possible
since we set (or read) glibc.malloc.check long after it is relocated.
To access or set a tunable outside of TUNABLE_NAMESPACE, use the
TUNABLE_GET_FULL and TUNABLE_SET_FULL macros, which have the following
prototype:
TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL)
TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, 0xffff)
In future the tunable list may get split into mutable and immutable
tunables where mutable tunables can be modified by the library and
userspace after relocation as well and TUNABLE_SET will be more useful
than it currently is. However whenever we actually do that split, we
will have to ensure that the mutable tunables are protected with
locks.
* elf/Versions (__tunable_set_val): Rename to __tunable_get_val.
* elf/dl-tunables.c: Likewise.
(do_tunable_update_val): New function.
(__tunable_set_val): New function.
(__tunable_get_val): Call CB only if the tunable was externally
initialized.
(tunables_strtoul): Replace strval with initialized.
* elf/dl-tunables.h (strval): Replace with a bool initialized.
(TUNABLE_ENUM_NAME, TUNABLE_ENUM_NAME1): Adjust names to
prevent collision.
(__tunable_set_val): New function.
(TUNABLE_GET, TUNABLE_GET_FULL): New macros.
(TUNABLE_SET, TUNABLE_SET_FULL): Likewise.
(TUNABLE_SET_VAL): Remove.
(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
* README.tunables: Document the new macros.
* malloc/arena.c (ptmalloc_init): Adjust.
2017-06-01 14:54:46 +00:00
|
|
|
if (cur->initialized && callback != NULL)
|
2016-12-31 18:02:17 +00:00
|
|
|
callback (&cur->val);
|
|
|
|
}
|
2017-05-25 13:55:42 +00:00
|
|
|
|
tunables: Clean up hooks to get and set tunables
The TUNABLE_SET_VALUE and family of macros (and my later attempt to
add a TUNABLE_GET) never quite went together very well because the
overall interface was not clearly defined. This patch is an attempt
to do just that.
This patch consolidates the API to two simple sets of macros,
TUNABLE_GET* and TUNABLE_SET*. If TUNABLE_NAMESPACE is defined,
TUNABLE_GET takes just the tunable name, type and a (optionally NULL)
callback function to get the value of the tunable. The callback
function, if non-NULL, is called if the tunable was externally set
(i.e. via GLIBC_TUNABLES or any future mechanism). For example:
val = TUNABLE_GET (check, int32_t, check_callback)
returns the value of the glibc.malloc.check tunable (assuming
TUNABLE_NAMESPACE is set to malloc) as an int32_t into VAL after
calling check_callback.
Likewise, TUNABLE_SET can be used to set the value of the tunable,
although this is currently possible only in the dynamic linker before
it relocates itself. For example:
TUNABLE_SET (check, int32_t, 2)
will set glibc.malloc.check to 2. Of course, this is not possible
since we set (or read) glibc.malloc.check long after it is relocated.
To access or set a tunable outside of TUNABLE_NAMESPACE, use the
TUNABLE_GET_FULL and TUNABLE_SET_FULL macros, which have the following
prototype:
TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL)
TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, 0xffff)
In future the tunable list may get split into mutable and immutable
tunables where mutable tunables can be modified by the library and
userspace after relocation as well and TUNABLE_SET will be more useful
than it currently is. However whenever we actually do that split, we
will have to ensure that the mutable tunables are protected with
locks.
* elf/Versions (__tunable_set_val): Rename to __tunable_get_val.
* elf/dl-tunables.c: Likewise.
(do_tunable_update_val): New function.
(__tunable_set_val): New function.
(__tunable_get_val): Call CB only if the tunable was externally
initialized.
(tunables_strtoul): Replace strval with initialized.
* elf/dl-tunables.h (strval): Replace with a bool initialized.
(TUNABLE_ENUM_NAME, TUNABLE_ENUM_NAME1): Adjust names to
prevent collision.
(__tunable_set_val): New function.
(TUNABLE_GET, TUNABLE_GET_FULL): New macros.
(TUNABLE_SET, TUNABLE_SET_FULL): Likewise.
(TUNABLE_SET_VAL): Remove.
(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
* README.tunables: Document the new macros.
* malloc/arena.c (ptmalloc_init): Adjust.
2017-06-01 14:54:46 +00:00
|
|
|
rtld_hidden_def (__tunable_get_val)
|