summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid McCullough <davidm@snapgear.com>2002-01-17 04:12:12 +0000
committerDavid McCullough <davidm@snapgear.com>2002-01-17 04:12:12 +0000
commit36b818352e14ef19f3da291761a06bfb37e06c09 (patch)
tree9477a4c86d6060d6c30605a436d89fb1d3a336ba
parent9557844c482a3a2302df69e06677178247634d56 (diff)
Add sbrk and friends
Fix bug in setjmp (jmpbuf changed size)
-rw-r--r--libc/sysdeps/linux/sh/Makefile2
-rw-r--r--libc/sysdeps/linux/sh/__init_brk.c25
-rw-r--r--libc/sysdeps/linux/sh/brk.c22
-rw-r--r--libc/sysdeps/linux/sh/sbrk.c25
-rw-r--r--libc/sysdeps/linux/sh/setjmp.S2
5 files changed, 74 insertions, 2 deletions
diff --git a/libc/sysdeps/linux/sh/Makefile b/libc/sysdeps/linux/sh/Makefile
index 72909c989..1f7d76a70 100644
--- a/libc/sysdeps/linux/sh/Makefile
+++ b/libc/sysdeps/linux/sh/Makefile
@@ -35,7 +35,7 @@ CRT0_OBJ=$(patsubst %.S,%.o, $(CRT0))
SSRC=setjmp.S bsd-setjmp.S bsd-_setjmp.S __longjmp.S vfork.S
SOBJS=$(patsubst %.S,%.o, $(SSRC))
-CSRC=_mmap.c longjmp.c pipe.c
+CSRC=_mmap.c longjmp.c pipe.c __init_brk.c brk.c sbrk.c
COBJS=$(patsubst %.c,%.o, $(CSRC))
OBJS=$(SOBJS) $(MOBJ) $(COBJS)
diff --git a/libc/sysdeps/linux/sh/__init_brk.c b/libc/sysdeps/linux/sh/__init_brk.c
new file mode 100644
index 000000000..93aa37d8e
--- /dev/null
+++ b/libc/sysdeps/linux/sh/__init_brk.c
@@ -0,0 +1,25 @@
+/* From libc-5.3.12 */
+
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <errno.h>
+
+void * ___brk_addr = 0;
+
+#define __NR__brk __NR_brk
+_syscall1(void *, _brk, void *, ptr);
+
+int
+__init_brk ()
+{
+ if (___brk_addr == 0)
+ {
+ ___brk_addr = _brk(0);
+ if (___brk_addr == 0)
+ {
+ __set_errno(ENOMEM);
+ return -1;
+ }
+ }
+ return 0;
+}
diff --git a/libc/sysdeps/linux/sh/brk.c b/libc/sysdeps/linux/sh/brk.c
new file mode 100644
index 000000000..c7943c1fd
--- /dev/null
+++ b/libc/sysdeps/linux/sh/brk.c
@@ -0,0 +1,22 @@
+/* From libc-5.3.12 */
+
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <errno.h>
+
+extern void * ___brk_addr;
+
+extern int __init_brk ();
+extern void *_brk(void *ptr);
+
+int brk(void * end_data_seg)
+{
+ if (__init_brk () == 0)
+ {
+ ___brk_addr = _brk(end_data_seg);
+ if (___brk_addr == end_data_seg)
+ return 0;
+ __set_errno(ENOMEM);
+ }
+ return -1;
+}
diff --git a/libc/sysdeps/linux/sh/sbrk.c b/libc/sysdeps/linux/sh/sbrk.c
new file mode 100644
index 000000000..3dd5a46f0
--- /dev/null
+++ b/libc/sysdeps/linux/sh/sbrk.c
@@ -0,0 +1,25 @@
+/* From libc-5.3.12 */
+
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <errno.h>
+
+extern void * ___brk_addr;
+
+extern int __init_brk (void);
+extern void *_brk(void *ptr);
+
+void *
+sbrk(intptr_t increment)
+{
+ if (__init_brk () == 0)
+ {
+ void * tmp = ___brk_addr+increment;
+ ___brk_addr = _brk(tmp);
+ if (___brk_addr == tmp)
+ return tmp-increment;
+ __set_errno(ENOMEM);
+ return ((void *) -1);
+ }
+ return ((void *) -1);
+}
diff --git a/libc/sysdeps/linux/sh/setjmp.S b/libc/sysdeps/linux/sh/setjmp.S
index 154cef1af..c263dc918 100644
--- a/libc/sysdeps/linux/sh/setjmp.S
+++ b/libc/sysdeps/linux/sh/setjmp.S
@@ -30,7 +30,7 @@ ENTRY (__sigsetjmp)
__sigsetjmp:
*/
/* Save registers */
- add #(JB_SIZE), r4
+ add #(JB_SIZE-5*4), r4 /* this code doesn't do FP yet */
stc.l gbr, @-r4
sts.l pr, @-r4
mov.l r15, @-r4