Blame include/rtld-malloc.h

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