Blame elf/dl-tunables.h

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