__uc_malloc.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* vi: set sw=4 ts=4: */
  2. /* uClibc internal malloc.
  3. Copyright (C) 2007 Denys Vlasenko
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License
  6. version 2 as published by the Free Software Foundation.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this library; see the file COPYING.LIB. If
  13. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  14. Cambridge, MA 02139, USA.
  15. */
  16. #include <stdlib.h>
  17. #include <unistd.h>
  18. #include <malloc.h>
  19. libc_hidden_proto(_exit);
  20. libc_hidden_proto(__uc_malloc);
  21. libc_hidden_proto(__uc_malloc_failed);
  22. void (*__uc_malloc_failed)(size_t size) = NULL;
  23. /* Seemingly superfluous assigment of NULL above prevents gas error
  24. * ("__uc_malloc_failed can't be equated to common symbol
  25. * __GI___uc_malloc_failed") in libc_hidden_data_def: */
  26. libc_hidden_data_def(__uc_malloc_failed)
  27. void *__uc_malloc(size_t size)
  28. {
  29. void *p;
  30. while (1) {
  31. p = malloc(size);
  32. if (!size || p)
  33. return p;
  34. if (!__uc_malloc_failed)
  35. _exit(1);
  36. __uc_malloc_failed(size);
  37. }
  38. }
  39. libc_hidden_def(__uc_malloc)