uClibc_alloc.h 765 B

1234567891011121314151617181920212223242526
  1. /*
  2. * Macros to transparently switch between the stack and heap for large
  3. * allocations. The former is useful on MMU systems as it results in
  4. * smaller code, but the latter is required on NoMMU systems. This is
  5. * due to small stacks that cannot grow and so doing large allocs will
  6. * cause a stack overflow.
  7. *
  8. * Copyright (C) 2010 Mike Frysinger <vapier@gentoo.org>
  9. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  10. */
  11. #ifndef _UCLIBC_ALLOC_H
  12. #define _UCLIBC_ALLOC_H
  13. #include <alloca.h>
  14. #include <stdlib.h>
  15. #ifdef __ARCH_USE_MMU__
  16. # define stack_heap_alloc(x) alloca(x)
  17. # define stack_heap_free(x) do { if (0) free(x); } while (0)
  18. #else
  19. # define stack_heap_alloc(x) malloc(x)
  20. # define stack_heap_free(x) free(x)
  21. #endif
  22. #endif