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.
|
|
|
|
|
2017-01-01 00:14:16 +00:00
|
|
|
Copyright (C) 2016-2017 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
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sysdep.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <ldsodefs.h>
|
|
|
|
|
|
|
|
#define TUNABLES_INTERNAL 1
|
|
|
|
#include "dl-tunables.h"
|
|
|
|
|
2017-07-17 21:11:12 +00:00
|
|
|
#include <not-errno.h>
|
|
|
|
|
2016-12-31 18:04:04 +00:00
|
|
|
#if TUNABLES_FRONTEND == TUNABLES_FRONTEND_valstring
|
|
|
|
# define GLIBC_TUNABLES "GLIBC_TUNABLES"
|
|
|
|
#endif
|
2016-12-31 18:03:27 +00:00
|
|
|
|
2016-12-31 18:04:04 +00:00
|
|
|
#if TUNABLES_FRONTEND == TUNABLES_FRONTEND_valstring
|
2016-12-31 18:03:27 +00:00
|
|
|
static char *
|
|
|
|
tunables_strdup (const char *in)
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
while (in[i++] != '\0');
|
|
|
|
char *out = __sbrk (i);
|
|
|
|
|
|
|
|
/* FIXME: In reality if the allocation fails, __sbrk will crash attempting to
|
|
|
|
set the thread-local errno since the TCB has not yet been set up. This
|
|
|
|
needs to be fixed with an __sbrk implementation that does not set
|
|
|
|
errno. */
|
|
|
|
if (out == (void *)-1)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
i--;
|
|
|
|
|
|
|
|
while (i-- > 0)
|
|
|
|
out[i] = in[i];
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
2016-12-31 18:04:04 +00:00
|
|
|
#endif
|
2016-12-31 18:03:27 +00:00
|
|
|
|
2016-12-31 18:02:17 +00:00
|
|
|
static char **
|
2017-02-02 10:16:01 +00:00
|
|
|
get_next_env (char **envp, char **name, size_t *namelen, 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;
|
|
|
|
*namelen = len;
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
Fix range check in do_tunable_update_val
Current implementation of tunables does not set arena_max and arena_test
values. Any value provided by glibc.malloc.arena_max and
glibc.malloc.arena_test parameters is ignored.
These tunables have minval value set to 1 (see elf/dl-tunables.list file)
and undefined maxval value. In that case default value (which is 0. see
scripts/gen-tunables.awk) is being used to set maxval.
For instance, generated tunable_list[] entry for arena_max is:
(gdb) p *cur
$1 = {name = 0x7ffff7df6217 "glibc.malloc.arena_max",
type = {type_code = TUNABLE_TYPE_SIZE_T, min = 1, max = 0},
val = {numval = 0, strval = 0x0}, initialized = false,
security_level = TUNABLE_SECLEVEL_SXID_IGNORE,
env_alias = 0x7ffff7df622e "MALLOC_ARENA_MAX"}
As a result, any value of glibc.malloc.arena_max is ignored by
TUNABLE_SET_VAL_IF_VALID_RANGE macro
__type min = (__cur)->type.min; <- initialized to 1
__type max = (__cur)->type.max; <- initialized to 0!
if (min == max) <- false
{
min = __default_min;
max = __default_max;
}
if ((__type) (__val) >= min && (__type) (val) <= max) <- false
{
(__cur)->val.numval = val;
(__cur)->initialized = true;
}
Assigning correct min/max values at a build time fixes a problem.
Plus, a bit of optimization: Setting of default min/max values for the
given type at a run time might be eliminated.
* elf/dl-tunables.c (do_tunable_update_val): Range checking fix.
* scripts/gen-tunables.awk: Set unspecified minval and/or maxval
values to correct default value for given type.
2017-09-26 21:14:09 +00:00
|
|
|
#define TUNABLE_SET_VAL_IF_VALID_RANGE(__cur, __val, __type) \
|
2017-05-17 07:41:55 +00:00
|
|
|
({ \
|
|
|
|
__type min = (__cur)->type.min; \
|
|
|
|
__type max = (__cur)->type.max; \
|
|
|
|
\
|
|
|
|
if ((__type) (__val) >= min && (__type) (val) <= max) \
|
|
|
|
{ \
|
|
|
|
(__cur)->val.numval = val; \
|
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
|
|
|
(__cur)->initialized = true; \
|
2017-05-17 07:41:55 +00:00
|
|
|
} \
|
|
|
|
})
|
2017-01-21 00:52:52 +00:00
|
|
|
|
2016-12-31 18:02:17 +00:00
|
|
|
static 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
|
|
|
do_tunable_update_val (tunable_t *cur, const void *valp)
|
2016-12-31 18:02:17 +00:00
|
|
|
{
|
2017-05-17 07:41:55 +00:00
|
|
|
uint64_t val;
|
|
|
|
|
|
|
|
if (cur->type.type_code != TUNABLE_TYPE_STRING)
|
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
|
|
|
val = *((int64_t *) valp);
|
2017-05-17 07:41:55 +00:00
|
|
|
|
2016-12-31 18:02:17 +00:00
|
|
|
switch (cur->type.type_code)
|
|
|
|
{
|
|
|
|
case TUNABLE_TYPE_INT_32:
|
|
|
|
{
|
Fix range check in do_tunable_update_val
Current implementation of tunables does not set arena_max and arena_test
values. Any value provided by glibc.malloc.arena_max and
glibc.malloc.arena_test parameters is ignored.
These tunables have minval value set to 1 (see elf/dl-tunables.list file)
and undefined maxval value. In that case default value (which is 0. see
scripts/gen-tunables.awk) is being used to set maxval.
For instance, generated tunable_list[] entry for arena_max is:
(gdb) p *cur
$1 = {name = 0x7ffff7df6217 "glibc.malloc.arena_max",
type = {type_code = TUNABLE_TYPE_SIZE_T, min = 1, max = 0},
val = {numval = 0, strval = 0x0}, initialized = false,
security_level = TUNABLE_SECLEVEL_SXID_IGNORE,
env_alias = 0x7ffff7df622e "MALLOC_ARENA_MAX"}
As a result, any value of glibc.malloc.arena_max is ignored by
TUNABLE_SET_VAL_IF_VALID_RANGE macro
__type min = (__cur)->type.min; <- initialized to 1
__type max = (__cur)->type.max; <- initialized to 0!
if (min == max) <- false
{
min = __default_min;
max = __default_max;
}
if ((__type) (__val) >= min && (__type) (val) <= max) <- false
{
(__cur)->val.numval = val;
(__cur)->initialized = true;
}
Assigning correct min/max values at a build time fixes a problem.
Plus, a bit of optimization: Setting of default min/max values for the
given type at a run time might be eliminated.
* elf/dl-tunables.c (do_tunable_update_val): Range checking fix.
* scripts/gen-tunables.awk: Set unspecified minval and/or maxval
values to correct default value for given type.
2017-09-26 21:14:09 +00:00
|
|
|
TUNABLE_SET_VAL_IF_VALID_RANGE (cur, val, int64_t);
|
2017-05-17 07:41:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TUNABLE_TYPE_UINT_64:
|
|
|
|
{
|
Fix range check in do_tunable_update_val
Current implementation of tunables does not set arena_max and arena_test
values. Any value provided by glibc.malloc.arena_max and
glibc.malloc.arena_test parameters is ignored.
These tunables have minval value set to 1 (see elf/dl-tunables.list file)
and undefined maxval value. In that case default value (which is 0. see
scripts/gen-tunables.awk) is being used to set maxval.
For instance, generated tunable_list[] entry for arena_max is:
(gdb) p *cur
$1 = {name = 0x7ffff7df6217 "glibc.malloc.arena_max",
type = {type_code = TUNABLE_TYPE_SIZE_T, min = 1, max = 0},
val = {numval = 0, strval = 0x0}, initialized = false,
security_level = TUNABLE_SECLEVEL_SXID_IGNORE,
env_alias = 0x7ffff7df622e "MALLOC_ARENA_MAX"}
As a result, any value of glibc.malloc.arena_max is ignored by
TUNABLE_SET_VAL_IF_VALID_RANGE macro
__type min = (__cur)->type.min; <- initialized to 1
__type max = (__cur)->type.max; <- initialized to 0!
if (min == max) <- false
{
min = __default_min;
max = __default_max;
}
if ((__type) (__val) >= min && (__type) (val) <= max) <- false
{
(__cur)->val.numval = val;
(__cur)->initialized = true;
}
Assigning correct min/max values at a build time fixes a problem.
Plus, a bit of optimization: Setting of default min/max values for the
given type at a run time might be eliminated.
* elf/dl-tunables.c (do_tunable_update_val): Range checking fix.
* scripts/gen-tunables.awk: Set unspecified minval and/or maxval
values to correct default value for given type.
2017-09-26 21:14:09 +00:00
|
|
|
TUNABLE_SET_VAL_IF_VALID_RANGE (cur, val, uint64_t);
|
2016-12-31 18:02:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TUNABLE_TYPE_SIZE_T:
|
|
|
|
{
|
Fix range check in do_tunable_update_val
Current implementation of tunables does not set arena_max and arena_test
values. Any value provided by glibc.malloc.arena_max and
glibc.malloc.arena_test parameters is ignored.
These tunables have minval value set to 1 (see elf/dl-tunables.list file)
and undefined maxval value. In that case default value (which is 0. see
scripts/gen-tunables.awk) is being used to set maxval.
For instance, generated tunable_list[] entry for arena_max is:
(gdb) p *cur
$1 = {name = 0x7ffff7df6217 "glibc.malloc.arena_max",
type = {type_code = TUNABLE_TYPE_SIZE_T, min = 1, max = 0},
val = {numval = 0, strval = 0x0}, initialized = false,
security_level = TUNABLE_SECLEVEL_SXID_IGNORE,
env_alias = 0x7ffff7df622e "MALLOC_ARENA_MAX"}
As a result, any value of glibc.malloc.arena_max is ignored by
TUNABLE_SET_VAL_IF_VALID_RANGE macro
__type min = (__cur)->type.min; <- initialized to 1
__type max = (__cur)->type.max; <- initialized to 0!
if (min == max) <- false
{
min = __default_min;
max = __default_max;
}
if ((__type) (__val) >= min && (__type) (val) <= max) <- false
{
(__cur)->val.numval = val;
(__cur)->initialized = true;
}
Assigning correct min/max values at a build time fixes a problem.
Plus, a bit of optimization: Setting of default min/max values for the
given type at a run time might be eliminated.
* elf/dl-tunables.c (do_tunable_update_val): Range checking fix.
* scripts/gen-tunables.awk: Set unspecified minval and/or maxval
values to correct default value for given type.
2017-09-26 21:14:09 +00:00
|
|
|
TUNABLE_SET_VAL_IF_VALID_RANGE (cur, val, uint64_t);
|
2016-12-31 18:02:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TUNABLE_TYPE_STRING:
|
|
|
|
{
|
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
|
|
|
cur->val.strval = valp;
|
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
|
|
|
/* Validate range of the input value and initialize the tunable CUR if it looks
|
|
|
|
good. */
|
|
|
|
static void
|
|
|
|
tunable_initialize (tunable_t *cur, const char *strval)
|
|
|
|
{
|
|
|
|
uint64_t val;
|
|
|
|
const void *valp;
|
|
|
|
|
|
|
|
if (cur->type.type_code != TUNABLE_TYPE_STRING)
|
|
|
|
{
|
2017-06-08 19:52:42 +00:00
|
|
|
val = _dl_strtoul (strval, NULL);
|
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
|
|
|
valp = &val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cur->initialized = true;
|
|
|
|
valp = strval;
|
|
|
|
}
|
|
|
|
do_tunable_update_val (cur, valp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
__tunable_set_val (tunable_id_t id, void *valp)
|
|
|
|
{
|
|
|
|
tunable_t *cur = &tunable_list[id];
|
|
|
|
|
|
|
|
do_tunable_update_val (cur, valp);
|
|
|
|
}
|
|
|
|
|
2016-12-31 18:04:04 +00:00
|
|
|
#if TUNABLES_FRONTEND == TUNABLES_FRONTEND_valstring
|
2017-02-02 10:16:01 +00:00
|
|
|
/* Parse the tunable string TUNESTR and adjust it to drop any tunables that may
|
|
|
|
be unsafe for AT_SECURE processes so that it can be used as the new
|
|
|
|
environment variable value for GLIBC_TUNABLES. VALSTRING is the original
|
|
|
|
environment variable string which we use to make NULL terminated values so
|
|
|
|
that we don't have to allocate memory again for it. */
|
2016-12-31 18:03:27 +00:00
|
|
|
static void
|
2017-02-02 10:16:01 +00:00
|
|
|
parse_tunables (char *tunestr, char *valstring)
|
2016-12-31 18:03:27 +00:00
|
|
|
{
|
|
|
|
if (tunestr == NULL || *tunestr == '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
char *p = tunestr;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
char *name = p;
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
/* First, find where the name ends. */
|
|
|
|
while (p[len] != '=' && p[len] != ':' && p[len] != '\0')
|
|
|
|
len++;
|
|
|
|
|
|
|
|
/* If we reach the end of the string before getting a valid name-value
|
|
|
|
pair, bail out. */
|
|
|
|
if (p[len] == '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We did not find a valid name-value pair before encountering the
|
|
|
|
colon. */
|
|
|
|
if (p[len]== ':')
|
|
|
|
{
|
|
|
|
p += len + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
p += len + 1;
|
|
|
|
|
2017-02-02 10:16:01 +00:00
|
|
|
/* Take the value from the valstring since we need to NULL terminate it. */
|
|
|
|
char *value = &valstring[p - tunestr];
|
2016-12-31 18:03:27 +00:00
|
|
|
len = 0;
|
|
|
|
|
|
|
|
while (p[len] != ':' && p[len] != '\0')
|
|
|
|
len++;
|
|
|
|
|
|
|
|
/* Add the tunable if it exists. */
|
|
|
|
for (size_t i = 0; i < sizeof (tunable_list) / sizeof (tunable_t); i++)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2017-02-02 10:16:01 +00:00
|
|
|
/* If we are in a secure context (AT_SECURE) then ignore the tunable
|
|
|
|
unless it is explicitly marked as secure. Tunable values take
|
|
|
|
precendence over their envvar aliases. */
|
|
|
|
if (__libc_enable_secure)
|
|
|
|
{
|
|
|
|
if (cur->security_level == TUNABLE_SECLEVEL_SXID_ERASE)
|
|
|
|
{
|
|
|
|
if (p[len] == '\0')
|
|
|
|
{
|
|
|
|
/* Last tunable in the valstring. Null-terminate and
|
|
|
|
return. */
|
|
|
|
*name = '\0';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Remove the current tunable from the string. We do
|
|
|
|
this by overwriting the string starting from NAME
|
|
|
|
(which is where the current tunable begins) with
|
|
|
|
the remainder of the string. We then have P point
|
|
|
|
to NAME so that we continue in the correct
|
|
|
|
position in the valstring. */
|
|
|
|
char *q = &p[len + 1];
|
|
|
|
p = name;
|
|
|
|
while (*q != '\0')
|
|
|
|
*name++ = *q++;
|
|
|
|
name[0] = '\0';
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur->security_level != TUNABLE_SECLEVEL_NONE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
value[len] = '\0';
|
2016-12-31 18:03:27 +00:00
|
|
|
tunable_initialize (cur, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-02 10:16:01 +00:00
|
|
|
if (p[len] == '\0')
|
2016-12-31 18:03:27 +00:00
|
|
|
return;
|
2017-02-02 10:16:01 +00:00
|
|
|
else
|
|
|
|
p += len + 1;
|
2016-12-31 18:03:27 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-31 18:04:04 +00:00
|
|
|
#endif
|
2016-12-31 18:03:27 +00:00
|
|
|
|
2017-01-10 11:05:58 +00:00
|
|
|
/* Enable the glibc.malloc.check tunable in SETUID/SETGID programs only when
|
|
|
|
the system administrator has created the /etc/suid-debug file. This is a
|
|
|
|
special case where we want to conditionally enable/disable a tunable even
|
|
|
|
for setuid binaries. We use the special version of access() to avoid
|
|
|
|
setting ERRNO, which is a TLS variable since TLS has not yet been set
|
|
|
|
up. */
|
2016-12-31 18:02:17 +00:00
|
|
|
static inline void
|
|
|
|
__always_inline
|
2017-01-10 11:05:58 +00:00
|
|
|
maybe_enable_malloc_check (void)
|
2016-12-31 18:02:17 +00:00
|
|
|
{
|
2017-02-02 10:16:01 +00:00
|
|
|
tunable_id_t id = TUNABLE_ENUM_NAME (glibc, malloc, check);
|
|
|
|
if (__libc_enable_secure && __access_noerrno ("/etc/suid-debug", F_OK) == 0)
|
|
|
|
tunable_list[id].security_level = TUNABLE_SECLEVEL_NONE;
|
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;
|
|
|
|
size_t len = 0;
|
2017-02-02 10:16:01 +00:00
|
|
|
char **prev_envp = envp;
|
2016-12-31 18:02:17 +00:00
|
|
|
|
2017-01-10 11:05:58 +00:00
|
|
|
maybe_enable_malloc_check ();
|
2016-12-31 18:02:17 +00:00
|
|
|
|
2017-02-02 10:16:01 +00:00
|
|
|
while ((envp = get_next_env (envp, &envname, &len, &envval,
|
|
|
|
&prev_envp)) != NULL)
|
2016-12-31 18:02:17 +00:00
|
|
|
{
|
2016-12-31 18:04:04 +00:00
|
|
|
#if TUNABLES_FRONTEND == TUNABLES_FRONTEND_valstring
|
2017-06-30 17:28:39 +00:00
|
|
|
if (tunable_is_name (GLIBC_TUNABLES, envname))
|
2016-12-31 18:03:27 +00:00
|
|
|
{
|
2017-02-02 10:16:01 +00:00
|
|
|
char *new_env = tunables_strdup (envname);
|
|
|
|
if (new_env != NULL)
|
|
|
|
parse_tunables (new_env + len + 1, envval);
|
|
|
|
/* Put in the updated envval. */
|
|
|
|
*prev_envp = new_env;
|
2016-12-31 18:03:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-12-31 18:04:04 +00:00
|
|
|
#endif
|
2016-12-31 18:03:27 +00:00
|
|
|
|
2016-12-31 18:02:17 +00:00
|
|
|
for (int i = 0; i < sizeof (tunable_list) / sizeof (tunable_t); i++)
|
|
|
|
{
|
|
|
|
tunable_t *cur = &tunable_list[i];
|
|
|
|
|
|
|
|
/* Skip over tunables that have either been set already or should be
|
|
|
|
skipped. */
|
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 || cur->env_alias == NULL)
|
2016-12-31 18:02:17 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
const char *name = cur->env_alias;
|
|
|
|
|
|
|
|
/* We have a match. Initialize and move on to the next line. */
|
2017-06-30 17:28:39 +00:00
|
|
|
if (tunable_is_name (name, envname))
|
2016-12-31 18:02:17 +00:00
|
|
|
{
|
2017-02-02 10:16:01 +00:00
|
|
|
/* For AT_SECURE binaries, we need to check the security settings of
|
|
|
|
the tunable and decide whether we read the value and also whether
|
|
|
|
we erase the value so that child processes don't inherit them in
|
|
|
|
the environment. */
|
|
|
|
if (__libc_enable_secure)
|
|
|
|
{
|
|
|
|
if (cur->security_level == TUNABLE_SECLEVEL_SXID_ERASE)
|
|
|
|
{
|
|
|
|
/* Erase the environment variable. */
|
|
|
|
char **ep = prev_envp;
|
|
|
|
|
|
|
|
while (*ep != NULL)
|
|
|
|
{
|
2017-06-30 17:28:39 +00:00
|
|
|
if (tunable_is_name (name, *ep))
|
2017-02-02 10:16:01 +00:00
|
|
|
{
|
|
|
|
char **dp = ep;
|
|
|
|
|
|
|
|
do
|
|
|
|
dp[0] = dp[1];
|
|
|
|
while (*dp++);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++ep;
|
|
|
|
}
|
|
|
|
/* Reset the iterator so that we read the environment again
|
|
|
|
from the point we erased. */
|
|
|
|
envp = prev_envp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur->security_level != TUNABLE_SECLEVEL_NONE)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-31 18:02:17 +00:00
|
|
|
tunable_initialize (cur, envval);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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:
|
|
|
|
{
|
|
|
|
*((const char **)valp) = cur->val.strval;
|
|
|
|
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)
|