Blame elf/dl-tunables.h

Packit 6c4009
/* The tunable framework.  See the README to know how to use the tunable in
Packit 6c4009
   a glibc module.
Packit 6c4009
Packit 6c4009
   Copyright (C) 2016-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _TUNABLES_H_
Packit 6c4009
#define _TUNABLES_H_
Packit 6c4009
Packit 6c4009
#if !HAVE_TUNABLES
Packit 6c4009
static inline void
Packit 6c4009
__always_inline
Packit 6c4009
__tunables_init (char **unused __attribute__ ((unused)))
Packit 6c4009
{
Packit 6c4009
  /* This is optimized out if tunables are not enabled.  */
Packit 6c4009
}
Packit 6c4009
#else
Packit 6c4009
Packit 6c4009
# include <stddef.h>
Packit 6c4009
# include "dl-tunable-types.h"
Packit 6c4009
Packit 6c4009
/* A tunable.  */
Packit 6c4009
struct _tunable
Packit 6c4009
{
Packit 6c4009
  const char *name;			/* Internal name of the tunable.  */
Packit 6c4009
  tunable_type_t type;			/* Data type of the tunable.  */
Packit 6c4009
  tunable_val_t val;			/* The value.  */
Packit 6c4009
  bool initialized;			/* Flag to indicate that the tunable is
Packit 6c4009
					   initialized.  */
Packit 6c4009
  tunable_seclevel_t security_level;	/* Specify the security level for the
Packit 6c4009
					   tunable with respect to AT_SECURE
Packit 6c4009
					   programs.  See description of
Packit 6c4009
					   tunable_seclevel_t to see a
Packit 6c4009
					   description of the values.
Packit 6c4009
Packit 6c4009
					   Note that even if the tunable is
Packit 6c4009
					   read, it may not get used by the
Packit 6c4009
					   target module if the value is
Packit 6c4009
					   considered unsafe.  */
Packit 6c4009
  /* Compatibility elements.  */
Packit 6c4009
  const char *env_alias;		/* The compatibility environment
Packit 6c4009
					   variable name.  */
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
typedef struct _tunable tunable_t;
Packit 6c4009
Packit 6c4009
/* Full name for a tunable is top_ns.tunable_ns.id.  */
Packit 6c4009
# define TUNABLE_NAME_S(top,ns,id) #top "." #ns "." #id
Packit 6c4009
Packit 6c4009
# define TUNABLE_ENUM_NAME(__top,__ns,__id) TUNABLE_ENUM_NAME1 (__top,__ns,__id)
Packit 6c4009
# define TUNABLE_ENUM_NAME1(__top,__ns,__id) __top ## _ ## __ns ## _ ## __id
Packit 6c4009
Packit 6c4009
# include "dl-tunable-list.h"
Packit 6c4009
Packit 6c4009
extern void __tunables_init (char **);
Packit 6c4009
extern void __tunable_get_val (tunable_id_t, void *, tunable_callback_t);
Packit 6c4009
extern void __tunable_set_val (tunable_id_t, void *);
Packit 6c4009
rtld_hidden_proto (__tunables_init)
Packit 6c4009
rtld_hidden_proto (__tunable_get_val)
Packit 6c4009
Packit 6c4009
/* Define TUNABLE_GET and TUNABLE_SET in short form if TOP_NAMESPACE and
Packit 6c4009
   TUNABLE_NAMESPACE are defined.  This is useful shorthand to get and set
Packit 6c4009
   tunables within a module.  */
Packit 6c4009
#if defined TOP_NAMESPACE && defined TUNABLE_NAMESPACE
Packit 6c4009
# define TUNABLE_GET(__id, __type, __cb) \
Packit 6c4009
  TUNABLE_GET_FULL (TOP_NAMESPACE, TUNABLE_NAMESPACE, __id, __type, __cb)
Packit 6c4009
# define TUNABLE_SET(__id, __type, __val) \
Packit 6c4009
  TUNABLE_SET_FULL (TOP_NAMESPACE, TUNABLE_NAMESPACE, __id, __type, __val)
Packit 6c4009
#else
Packit 6c4009
# define TUNABLE_GET(__top, __ns, __id, __type, __cb) \
Packit 6c4009
  TUNABLE_GET_FULL (__top, __ns, __id, __type, __cb)
Packit 6c4009
# define TUNABLE_SET(__top, __ns, __id, __type, __val) \
Packit 6c4009
  TUNABLE_SET_FULL (__top, __ns, __id, __type, __val)
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* Get and return a tunable value.  If the tunable was set externally and __CB
Packit 6c4009
   is defined then call __CB before returning the value.  */
Packit 6c4009
# define TUNABLE_GET_FULL(__top, __ns, __id, __type, __cb) \
Packit 6c4009
({									      \
Packit 6c4009
  tunable_id_t id = TUNABLE_ENUM_NAME (__top, __ns, __id);		      \
Packit 6c4009
  __type ret;								      \
Packit 6c4009
  __tunable_get_val (id, &ret, __cb);					      \
Packit 6c4009
  ret;									      \
Packit 6c4009
})
Packit 6c4009
Packit 6c4009
/* Set a tunable value.  */
Packit 6c4009
# define TUNABLE_SET_FULL(__top, __ns, __id, __type, __val) \
Packit 6c4009
({									      \
Packit 6c4009
  __tunable_set_val (TUNABLE_ENUM_NAME (__top, __ns, __id),		      \
Packit 6c4009
			& (__type) {__val});				      \
Packit 6c4009
})
Packit 6c4009
Packit 6c4009
/* Namespace sanity for callback functions.  Use this macro to keep the
Packit 6c4009
   namespace of the modules clean.  */
Packit 6c4009
# define TUNABLE_CALLBACK(__name) _dl_tunable_ ## __name
Packit 6c4009
Packit 6c4009
# define TUNABLES_FRONTEND_valstring 1
Packit 6c4009
/* The default value for TUNABLES_FRONTEND.  */
Packit 6c4009
# define TUNABLES_FRONTEND_yes TUNABLES_FRONTEND_valstring
Packit 6c4009
Packit 6c4009
/* Compare two name strings, bounded by the name hardcoded in glibc.  */
Packit 6c4009
static inline bool
Packit 6c4009
__always_inline
Packit 6c4009
tunable_is_name (const char *orig, const char *envname)
Packit 6c4009
{
Packit 6c4009
  for (;*orig != '\0' && *envname != '\0'; envname++, orig++)
Packit 6c4009
    if (*orig != *envname)
Packit 6c4009
      break;
Packit 6c4009
Packit 6c4009
  /* The ENVNAME is immediately followed by a value.  */
Packit 6c4009
  if (*orig == '\0' && *envname == '=')
Packit 6c4009
    return true;
Packit 6c4009
  else
Packit 6c4009
    return false;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#endif
Packit 6c4009
#endif