malloc-internal.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Internal declarations for malloc, for use within libc.
  2. Copyright (C) 2016-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public License as
  6. published by the Free Software Foundation; either version 2.1 of the
  7. License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; see the file COPYING.LIB. If
  14. not, see <http://www.gnu.org/licenses/>. */
  15. #ifndef _MALLOC_INTERNAL_H
  16. #define _MALLOC_INTERNAL_H
  17. #include <malloc-machine.h>
  18. #include <malloc-sysdep.h>
  19. /* INTERNAL_SIZE_T is the word-size used for internal bookkeeping of
  20. chunk sizes.
  21. The default version is the same as size_t.
  22. While not strictly necessary, it is best to define this as an
  23. unsigned type, even if size_t is a signed type. This may avoid some
  24. artificial size limitations on some systems.
  25. On a 64-bit machine, you may be able to reduce malloc overhead by
  26. defining INTERNAL_SIZE_T to be a 32 bit `unsigned int' at the
  27. expense of not being able to handle more than 2^32 of malloced
  28. space. If this limitation is acceptable, you are encouraged to set
  29. this unless you are on a platform requiring 16byte alignments. In
  30. this case the alignment requirements turn out to negate any
  31. potential advantages of decreasing size_t word size.
  32. Implementors: Beware of the possible combinations of:
  33. - INTERNAL_SIZE_T might be signed or unsigned, might be 32 or 64 bits,
  34. and might be the same width as int or as long
  35. - size_t might have different width and signedness as INTERNAL_SIZE_T
  36. - int and long might be 32 or 64 bits, and might be the same width
  37. To deal with this, most comparisons and difference computations
  38. among INTERNAL_SIZE_Ts should cast them to unsigned long, being
  39. aware of the fact that casting an unsigned int to a wider long does
  40. not sign-extend. (This also makes checking for negative numbers
  41. awkward.) Some of these casts result in harmless compiler warnings
  42. on some systems. */
  43. #ifndef INTERNAL_SIZE_T
  44. # define INTERNAL_SIZE_T size_t
  45. #endif
  46. /* The corresponding word size. */
  47. #define SIZE_SZ (sizeof (INTERNAL_SIZE_T))
  48. /* The corresponding bit mask value. */
  49. #define MALLOC_ALIGN_MASK (MALLOC_ALIGNMENT - 1)
  50. /* Called in the parent process before a fork. */
  51. void __malloc_fork_lock_parent (void) attribute_hidden;
  52. /* Called in the parent process after a fork. */
  53. void __malloc_fork_unlock_parent (void) attribute_hidden;
  54. /* Called in the child process after a fork. */
  55. void __malloc_fork_unlock_child (void) attribute_hidden;
  56. /* Called as part of the thread shutdown sequence. */
  57. void __malloc_arena_thread_freeres (void) attribute_hidden;
  58. #endif /* _MALLOC_INTERNAL_H */