aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-09-12 20:59:12 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-09-12 20:59:12 -0400
commitdb61b9278266ffabd9c10106e39aa9c8f5b04059 (patch)
treea4269273e51890489385d5bfc8dc53d1bd9bbc9f
parentc165c7950080ad87ed083ae15502a04527dcc7cc (diff)
downloadlibrambutan-db61b9278266ffabd9c10106e39aa9c8f5b04059.tar.gz
librambutan-db61b9278266ffabd9c10106e39aa9c8f5b04059.zip
syscalls.c: Allow environment to specify heap boundaries.
Rename HEAP_START/HEAP_END macros CONFIG_HEAP_START/CONFIG_HEAP_END, to mark them as build-time configuration options. Wrap their definitions with #ifndefs appropriately.
-rw-r--r--libmaple/syscalls.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/libmaple/syscalls.c b/libmaple/syscalls.c
index a3f12f1..9193a17 100644
--- a/libmaple/syscalls.c
+++ b/libmaple/syscalls.c
@@ -29,12 +29,17 @@
#include <sys/stat.h>
#include <errno.h>
-/* Set by the linker */
+/* If CONFIG_HEAP_START (or CONFIG_HEAP_END) isn't defined, then
+ * assume _lm_heap_start (resp. _lm_heap_end) is appropriately set by
+ * the linker */
+#ifndef CONFIG_HEAP_START
extern char _lm_heap_start;
+#define CONFIG_HEAP_START ((caddr_t)&_lm_heap_start)
+#endif
+#ifndef CONFIG_HEAP_END
extern char _lm_heap_end;
-
-#define HEAP_START ((caddr_t)&_lm_heap_start)
-#define HEAP_END ((caddr_t)&_lm_heap_end)
+#define CONFIG_HEAP_END ((caddr_t)&_lm_heap_end)
+#endif
/*
* _sbrk -- Increment the program break.
@@ -47,10 +52,11 @@ caddr_t _sbrk(int incr) {
caddr_t ret;
if (pbreak == NULL) {
- pbreak = HEAP_START;
+ pbreak = CONFIG_HEAP_START;
}
- if ((HEAP_END - pbreak < incr) || (pbreak - HEAP_START < -incr)) {
+ if ((CONFIG_HEAP_END - pbreak < incr) ||
+ (pbreak - CONFIG_HEAP_START < -incr)) {
errno = ENOMEM;
return (caddr_t)-1;
}