summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/bits
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2010-07-27 01:48:22 -0400
committerMike Frysinger <vapier@gentoo.org>2010-07-27 14:33:42 -0400
commitfd826c72f8362d054c2d0064bff2b0830d2f29d1 (patch)
treef8f866fadc5cf38cc1883c348e8bdc1cad4b0691 /libc/sysdeps/linux/common/bits
parent4e38c284bc8b3bff95543f246f3e0d3ee5a045ab (diff)
new helper funcs for alloca/malloc with mmu/nommu
The rpc rcmd code has some ugly ifdef mazes to handle mmu/nommu differences just to select alloca or malloc. Unify those with some helper macros in a new header, and then convert the rcmd code over to it. This is all geared towards fixing the getdents helper functions which only use alloca() atm. Now that we have helper functions, convert the getdents functions over too. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Reviewed-by: Steven J. Magnani <steve@digidescorp.com>
Diffstat (limited to 'libc/sysdeps/linux/common/bits')
-rw-r--r--libc/sysdeps/linux/common/bits/uClibc_alloc.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/common/bits/uClibc_alloc.h b/libc/sysdeps/linux/common/bits/uClibc_alloc.h
new file mode 100644
index 000000000..6a70d27b7
--- /dev/null
+++ b/libc/sysdeps/linux/common/bits/uClibc_alloc.h
@@ -0,0 +1,26 @@
+/*
+ * Macros to transparently switch between the stack and heap for large
+ * allocations. The former is useful on MMU systems as it results in
+ * smaller code, but the latter is required on NoMMU systems. This is
+ * due to small stacks that cannot grow and so doing large allocs will
+ * cause a stack overflow.
+ *
+ * Copyright (C) 2010 Mike Frysinger <vapier@gentoo.org>
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#ifndef _UCLIBC_ALLOC_H
+#define _UCLIBC_ALLOC_H
+
+#include <alloca.h>
+#include <stdlib.h>
+
+#ifdef __ARCH_USE_MMU__
+# define stack_heap_alloc(x) alloca(x)
+# define stack_heap_free(x) do { if (0) free(x); } while (0)
+#else
+# define stack_heap_alloc(x) malloc(x)
+# define stack_heap_free(x) free(x)
+#endif
+
+#endif