Blame include/rtld-malloc.h

Packit Bot ccdbaf
/* Redirection of malloc inside the dynamic linker.
Packit Bot ccdbaf
   Copyright (C) 2020 Free Software Foundation, Inc.
Packit Bot ccdbaf
   This file is part of the GNU C Library.
Packit Bot ccdbaf
Packit Bot ccdbaf
   The GNU C Library is free software; you can redistribute it and/or
Packit Bot ccdbaf
   modify it under the terms of the GNU Lesser General Public
Packit Bot ccdbaf
   License as published by the Free Software Foundation; either
Packit Bot ccdbaf
   version 2.1 of the License, or (at your option) any later version.
Packit Bot ccdbaf
Packit Bot ccdbaf
   The GNU C Library is distributed in the hope that it will be useful,
Packit Bot ccdbaf
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot ccdbaf
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Bot ccdbaf
   Lesser General Public License for more details.
Packit Bot ccdbaf
Packit Bot ccdbaf
   You should have received a copy of the GNU Lesser General Public
Packit Bot ccdbaf
   License along with the GNU C Library; if not, see
Packit Bot ccdbaf
   <https://www.gnu.org/licenses/>.  */
Packit Bot ccdbaf
Packit Bot ccdbaf
/* The dynamic linker needs to use its own minimal malloc before libc
Packit Bot ccdbaf
   has been relocated, and the libc malloc afterwards.  The active
Packit Bot ccdbaf
   malloc implementation is reached via the __rtld_* function pointers
Packit Bot ccdbaf
   declared below.  They are initialized to the minimal malloc by
Packit Bot ccdbaf
   __rtld_malloc_init_stubs, and set to the final implementation by
Packit Bot ccdbaf
   __rtld_malloc_init_real.  */
Packit Bot ccdbaf
Packit Bot ccdbaf
#ifndef _RTLD_MALLOC_H
Packit Bot ccdbaf
#define _RTLD_MALLOC_H
Packit Bot ccdbaf
Packit Bot ccdbaf
#if IS_IN (rtld)
Packit Bot ccdbaf
Packit Bot ccdbaf
extern __typeof (calloc) *__rtld_calloc attribute_hidden;
Packit Bot ccdbaf
extern __typeof (free) *__rtld_free attribute_hidden;
Packit Bot ccdbaf
extern __typeof (malloc) *__rtld_malloc attribute_hidden;
Packit Bot ccdbaf
extern __typeof (realloc) *__rtld_realloc attribute_hidden;
Packit Bot ccdbaf
Packit Bot ccdbaf
/* Wrapper functions which call through the function pointers above.
Packit Bot ccdbaf
   Note that it is not supported to take the address of those
Packit Bot ccdbaf
   functions.  Instead the function pointers must be used
Packit Bot ccdbaf
   directly.  */
Packit Bot ccdbaf
Packit Bot ccdbaf
__extern_inline void *
Packit Bot ccdbaf
calloc (size_t a, size_t b)
Packit Bot ccdbaf
{
Packit Bot ccdbaf
  return __rtld_calloc (a, b);
Packit Bot ccdbaf
}
Packit Bot ccdbaf
Packit Bot ccdbaf
__extern_inline void
Packit Bot ccdbaf
free (void *ptr)
Packit Bot ccdbaf
{
Packit Bot ccdbaf
   __rtld_free (ptr);
Packit Bot ccdbaf
}
Packit Bot ccdbaf
Packit Bot ccdbaf
__extern_inline void *
Packit Bot ccdbaf
malloc (size_t size)
Packit Bot ccdbaf
{
Packit Bot ccdbaf
  return __rtld_malloc (size);
Packit Bot ccdbaf
}
Packit Bot ccdbaf
Packit Bot ccdbaf
__extern_inline void *
Packit Bot ccdbaf
realloc (void *ptr, size_t size)
Packit Bot ccdbaf
{
Packit Bot ccdbaf
  return __rtld_realloc (ptr, size);
Packit Bot ccdbaf
}
Packit Bot ccdbaf
Packit Bot ccdbaf
/* Called after the first self-relocation to activate the minimal malloc
Packit Bot ccdbaf
   implementation.  */
Packit Bot ccdbaf
void __rtld_malloc_init_stubs (void) attribute_hidden;
Packit Bot ccdbaf
Packit Bot a8ca51
/* Return false if the active malloc is the ld.so minimal malloc, true
Packit Bot a8ca51
   if it is the full implementation from libc.so.  */
Packit Bot a8ca51
_Bool __rtld_malloc_is_complete (void) attribute_hidden;
Packit Bot a8ca51
Packit Bot ccdbaf
/* Called shortly before the final self-relocation (when RELRO
Packit Bot ccdbaf
   variables are still writable) to activate the real malloc
Packit Bot ccdbaf
   implementation.  MAIN_MAP is the link map of the executable.  */
Packit Bot ccdbaf
struct link_map;
Packit Bot ccdbaf
void __rtld_malloc_init_real (struct link_map *main_map) attribute_hidden;
Packit Bot ccdbaf
Packit Bot ccdbaf
#else /* !IS_IN (rtld) */
Packit Bot ccdbaf
Packit Bot ccdbaf
/* This allows static/non-rtld builds to get a pointer to the
Packit Bot ccdbaf
   functions, in the same way that is required inside rtld.  */
Packit Bot ccdbaf
# define __rtld_calloc (&calloc)
Packit Bot ccdbaf
# define __rtld_free (&free)
Packit Bot ccdbaf
# define __rtld_malloc (&malloc)
Packit Bot ccdbaf
# define __rtld_realloc (&realloc)
Packit Bot ccdbaf
Packit Bot ccdbaf
#endif /* !IS_IN (rtld) */
Packit Bot ccdbaf
#endif /* _RTLD_MALLOC_H */