commit ad6f6a63f67153a6e6ba0b7fcb794bd0ca85e53a
parent 5b55fad474216a984ba0fbefb5d478bdd4f16580
Author: Dimitris Papastamos <dimitris.papastamos@arm.com>
Date: Fri, 19 Oct 2018 16:39:43 +0100
[libc] Add _getheap() primitive
This abstracts getting the current location of the break point on
various systems.
Change-Id: Ibb7d2de7222721c286b601dcf6aa40b021c6dcd9
Signed-off-by: Dimitris Papastamos <dimitris.papastamos@arm.com>
Diffstat:
13 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/src/libc/arch/amd64/bsd/.gitignore b/src/libc/arch/amd64/bsd/.gitignore
@@ -1,5 +1,6 @@
_Exit.s
_close.s
+_brk.s
_getpid.s
_kill.s
_lseek.s
diff --git a/src/libc/arch/amd64/bsd/Makefile b/src/libc/arch/amd64/bsd/Makefile
@@ -9,6 +9,8 @@ SRC = _Exit.s \
_open.s \
_read.s \
_write.s \
+ _brk.s \
+ _getheap.s \
all: $(SRC:.s=.o)
diff --git a/src/libc/arch/amd64/bsd/_getheap.s b/src/libc/arch/amd64/bsd/_getheap.s
@@ -0,0 +1,6 @@
+ .file "_getheap.s"
+
+ .globl _getheap
+_getheap:
+ movq $end,%rax
+ retq
diff --git a/src/libc/arch/amd64/bsd/objlst.mk b/src/libc/arch/amd64/bsd/objlst.mk
@@ -1,10 +1,12 @@
SYSOBJ = $(LIBSYS)/_Exit.o \
$(LIBSYS)/_close.o \
+ $(LIBSYS)/_brk.o \
$(LIBSYS)/_getpid.o \
$(LIBSYS)/_kill.o \
$(LIBSYS)/_lseek.o \
$(LIBSYS)/_open.o \
$(LIBSYS)/_read.o \
$(LIBSYS)/_write.o \
+ $(LIBSYS)/_getheap.o \
$(LIBARCH)/setjmp.o \
$(LIBARCH)/longjmp.o \
diff --git a/src/libc/arch/amd64/bsd/syscall.lst b/src/libc/arch/amd64/bsd/syscall.lst
@@ -4,6 +4,7 @@
4 _write
5 _open
6 _close
+17 _brk
20 _getpid
37 _kill
199 _lseek
diff --git a/src/libc/arch/amd64/linux/Makefile b/src/libc/arch/amd64/linux/Makefile
@@ -10,6 +10,7 @@ SRC = _Exit.s \
_read.s \
_write.s \
_brk.s \
+ _getheap.s \
all: $(SRC:.s=.o) _cerrno.o
diff --git a/src/libc/arch/amd64/linux/_getheap.s b/src/libc/arch/amd64/linux/_getheap.s
@@ -0,0 +1,6 @@
+ .file "_getheap.s"
+
+ .globl _getheap
+_getheap:
+ movq $0,%rax
+ jmp _brk
diff --git a/src/libc/arch/amd64/linux/objlst.mk b/src/libc/arch/amd64/linux/objlst.mk
@@ -9,5 +9,6 @@ SYSOBJ = $(LIBSYS)/_Exit.o \
$(LIBSYS)/_lseek.o \
$(LIBSYS)/_cerrno.o \
$(LIBSYS)/_brk.o \
+ $(LIBSYS)/_getheap.o \
$(LIBARCH)/setjmp.o \
$(LIBARCH)/longjmp.o \
diff --git a/src/libc/arch/arm64/linux/Makefile b/src/libc/arch/arm64/linux/Makefile
@@ -9,6 +9,7 @@ SRC = _Exit.s \
_openat.s \
_read.s \
_write.s \
+ _getheap.s \
all: $(SRC:.s=.o) _open.o _cerrno.o
diff --git a/src/libc/arch/arm64/linux/_getheap.s b/src/libc/arch/arm64/linux/_getheap.s
@@ -0,0 +1,6 @@
+ .file "_getheap.s"
+
+ .globl _getheap
+_getheap:
+ mov x0,#0
+ b _brk
diff --git a/src/libc/arch/arm64/linux/objlst.mk b/src/libc/arch/arm64/linux/objlst.mk
@@ -8,5 +8,6 @@ SYSOBJ = $(LIBSYS)/_Exit.o \
$(LIBSYS)/_read.o \
$(LIBSYS)/_write.o \
$(LIBSYS)/_cerrno.o \
+ $(LIBSYS)/_getheap.o \
$(LIBARCH)/setjmp.o \
$(LIBARCH)/longjmp.o \
diff --git a/src/libc/libc.h b/src/libc/libc.h
@@ -34,4 +34,6 @@ extern struct tzone *_tzone(struct tm *tm);
extern int _daysyear(int year);
extern int _newyear(int year);
+extern void *_getheap(void);
+
extern int _daysmon[12];
diff --git a/src/libc/malloc.c b/src/libc/malloc.c
@@ -9,7 +9,6 @@
#define MAXADDR ((char *)-1)
#define ERRADDR ((char *)-1)
-extern char end[];
static Header base = { .h.next = &base };
static Header *freep = &base;
@@ -76,7 +75,7 @@ sbrk(uintptr_t inc)
static void *heap;
if (!heap)
- heap = _brk(0);
+ heap = _getheap();
old = heap;
if (old >= MAXADDR - inc)
return ERRADDR;