commit fad240875a1562d7d667270f490fb3a1816e561a
parent b79109d022fb39d885e7134ad5db12d7a6ca21f1
Author: leitner <leitner>
Date: Fri, 8 Apr 2005 17:18:40 +0000
added small special-purpose malloc using a static buffer before
calling the real malloc (Nikola Vladov)
Diffstat:
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/CHANGES b/CHANGES
@@ -28,6 +28,8 @@
add usage for serdo (Nikola Vladov)
fix msvc -d followed by msvc -h (would send SIGHUP to pid 1, i.e. kill
minit; found by Paul Fox)
+ added small special-purpose malloc using a static buffer before
+ calling the real malloc (Nikola Vladov)
0.9.1:
fix embarassing typo in msvc (Gelu G. Lupas)
diff --git a/Makefile b/Makefile
@@ -56,7 +56,7 @@ shutdown: shutdown.o split.o openreadclose.o opendevconsole.o
clean:
rm -f *.o minit msvc pidfilehack hard-reboot write_proc killall5 \
- shutdown
+ shutdown minit-update serdo
test: test.c
gcc -nostdlib -o $@ $^ -I../dietlibc/include ../dietlibc/start.o ../dietlibc/dietlibc.a
diff --git a/minit.c b/minit.c
@@ -21,6 +21,45 @@
#include "minit.h"
+#define MALLOC_TEST
+#if !defined(__dietlibc__) && !defined(__GLIBC__)
+#undef MALLOC_TEST
+#endif
+
+#ifdef MALLOC_TEST
+extern void* __libc_malloc(size_t size);
+extern void* __libc_realloc(void* x,size_t size);
+extern void __libc_free(void* x);
+static char malloc_buf[2048];
+static unsigned long n;
+static struct process procbuf[100];
+void *malloc(size_t size) {
+ if (n+size<sizeof(malloc_buf)) {
+ char* tmp=malloc_buf+n;
+ n+=size;
+ n=(n+3)&~3;
+ return tmp;
+ }
+ return __libc_malloc(size);
+}
+void free(void* x) {
+ if ((char*)x>=malloc_buf && (char*)x<malloc_buf+sizeof(malloc_buf)) return;
+ __libc_free(x);
+}
+void* realloc(void* x,size_t size) {
+ if (x==0 || x==procbuf) {
+ void* y;
+ if (size<=sizeof(procbuf))
+ return procbuf;
+ y=__libc_malloc(size);
+ if (!y) return 0;
+ memcpy(y,x,size);
+ return y;
+ }
+ return __libc_realloc(x,size);
+}
+#endif
+
char** Argv;
#undef printf