summaryrefslogtreecommitdiffstats
path: root/libc/stdlib/malloc-simple
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdlib/malloc-simple')
-rw-r--r--libc/stdlib/malloc-simple/.indent.pro33
-rw-r--r--libc/stdlib/malloc-simple/Makefile46
-rw-r--r--libc/stdlib/malloc-simple/alloc.c106
3 files changed, 185 insertions, 0 deletions
diff --git a/libc/stdlib/malloc-simple/.indent.pro b/libc/stdlib/malloc-simple/.indent.pro
new file mode 100644
index 000000000..492ecf1c7
--- /dev/null
+++ b/libc/stdlib/malloc-simple/.indent.pro
@@ -0,0 +1,33 @@
+--blank-lines-after-declarations
+--blank-lines-after-procedures
+--break-before-boolean-operator
+--no-blank-lines-after-commas
+--braces-on-if-line
+--braces-on-struct-decl-line
+--comment-indentation25
+--declaration-comment-column25
+--no-comment-delimiters-on-blank-lines
+--cuddle-else
+--continuation-indentation4
+--case-indentation0
+--else-endif-column33
+--space-after-cast
+--line-comments-indentation0
+--declaration-indentation1
+--dont-format-first-column-comments
+--dont-format-comments
+--honour-newlines
+--indent-level4
+/* changed from 0 to 4 */
+--parameter-indentation4
+--line-length78 /* changed from 75 */
+--continue-at-parentheses
+--no-space-after-function-call-names
+--dont-break-procedure-type
+--dont-star-comments
+--leave-optional-blank-lines
+--dont-space-special-semicolon
+--tab-size4
+/* additions by Mark */
+--case-brace-indentation0
+--leave-preprocessor-space
diff --git a/libc/stdlib/malloc-simple/Makefile b/libc/stdlib/malloc-simple/Makefile
new file mode 100644
index 000000000..c2f8827b5
--- /dev/null
+++ b/libc/stdlib/malloc-simple/Makefile
@@ -0,0 +1,46 @@
+# Makefile for uCLibc
+#
+# Copyright (C) 2000 by Lineo, inc.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Library General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Derived in part from the Linux-8086 C library, the GNU C Library, and several
+# other sundry sources. Files within this library are copyright by their
+# respective copyright holders.
+
+TOPDIR=../
+include $(TOPDIR)Rules.make
+LIBC=$(TOPDIR)libc.a
+
+MSRC=alloc.c
+MOBJ=malloc.o realloc.o free.o calloc.o malloc_dbg.o free_dbg.o calloc_dbg.o
+OBJS=$(MOBJ)
+
+
+all: $(OBJS) $(LIBC)
+
+$(LIBC): ar-target
+
+ar-target: $(OBJS)
+ $(AR) $(ARFLAGS) $(LIBC) $(OBJS)
+
+$(MOBJ): $(MSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+
+$(OBJ): Makefile
+
+clean:
+ rm -f *.[oa] *~ core
+
diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c
new file mode 100644
index 000000000..cf4835c97
--- /dev/null
+++ b/libc/stdlib/malloc-simple/alloc.c
@@ -0,0 +1,106 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+
+#ifdef L_calloc_dbg
+
+void *calloc_dbg(size_t num, size_t size, char *function, char *file,
+ int line)
+{
+ void *ptr;
+
+ fprintf(stderr, "calloc of %d bytes at %s @%s:%d = ", num * size,
+ function, file, line);
+ ptr = calloc(num, size);
+ fprintf(stderr, "%p\n", ptr);
+ return ptr;
+}
+
+#endif
+
+#ifdef L_malloc_dbg
+
+void *malloc_dbg(size_t len, char *function, char *file, int line)
+{
+ void *result;
+
+ fprintf(stderr, "malloc of %d bytes at %s @%s:%d = ", len, function,
+ file, line);
+ result = malloc(len);
+ fprintf(stderr, "%p\n", result);
+ return result;
+}
+
+#endif
+
+#ifdef L_free_dbg
+
+void free_dbg(void *ptr, char *function, char *file, int line)
+{
+ fprintf(stderr, "free of %p at %s @%s:%d\n", ptr, function, file,
+ line);
+ free(ptr);
+}
+
+#endif
+
+
+#ifdef L_calloc
+
+void *calloc(size_t num, size_t size)
+{
+ void *ptr = malloc(num * size);
+
+ if (ptr)
+ memset(ptr, 0, num * size);
+ return ptr;
+}
+
+#endif
+
+#ifdef L_malloc
+
+void *malloc(size_t len)
+{
+ void *result = mmap((void *) 0, len, PROT_READ | PROT_WRITE,
+ //MAP_SHARED | MAP_ANONYMOUS, 0, 0);
+ MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+
+ if (result == (void *) -1)
+ return 0;
+
+ return result;
+}
+
+#endif
+
+#ifdef L_free
+
+void free(void *ptr)
+{
+ munmap(ptr, 0);
+}
+
+#endif
+
+#ifdef L_realloc
+
+void *realloc(void *ptr, size_t size)
+{
+ void *newptr = NULL;
+
+ if (size > 0) {
+ newptr = malloc(size);
+ if (newptr && ptr)
+ memcpy(newptr, ptr, size);
+ }
+ if (ptr)
+ free(ptr);
+ return newptr;
+}
+
+#endif