diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-05-14 04:16:35 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-05-14 04:16:35 +0000 |
commit | 64bc6412188b141c010ac3b8e813b837dd991e80 (patch) | |
tree | ffa12b79ea4b13191754f54b872eb1a4f9e3a04b /libc/stdlib/malloc |
Initial revision
Diffstat (limited to 'libc/stdlib/malloc')
-rw-r--r-- | libc/stdlib/malloc/Makefile | 33 | ||||
-rw-r--r-- | libc/stdlib/malloc/alloc.c | 82 |
2 files changed, 115 insertions, 0 deletions
diff --git a/libc/stdlib/malloc/Makefile b/libc/stdlib/malloc/Makefile new file mode 100644 index 000000000..36872c301 --- /dev/null +++ b/libc/stdlib/malloc/Makefile @@ -0,0 +1,33 @@ +# Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk> +# This file is part of the Linux-8086 C library and is distributed +# under the GNU Library General Public License. + +LIBC=../libc.a + +CC=m68k-pic-coff-gcc +AR=m68k-pic-coff-ar +RANLIB=m68k-pic-coff-ranlib + +CCFLAGS= -O2 -m68000 -msoft-float -I../include + + +MSRC=alloc.c +MOBJ=malloc.o free.o calloc.o malloc_dbg.o free_dbg.o calloc_dbg.o + +OBJ=$(MOBJ) + +CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) + +all: $(LIBC) + @$(RM) $(OBJ) + +$(LIBC): $(LIBC)($(OBJ)) + +$(LIBC)($(MOBJ)): $(MSRC) + $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o + $(AR) $(ARFLAGS) $@ $*.o + +clean: + rm -f *.o libc.a + + diff --git a/libc/stdlib/malloc/alloc.c b/libc/stdlib/malloc/alloc.c new file mode 100644 index 000000000..b92cb7c69 --- /dev/null +++ b/libc/stdlib/malloc/alloc.c @@ -0,0 +1,82 @@ +#include <unistd.h> +#include <sys/mman.h> +#include <stdio.h> +#include <stdlib.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); + fprtinf(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); + if (result == (void*)-1) + return 0; + + return result; +} + +#endif + +#ifdef L_free + +void +free(void * ptr) +{ + munmap(ptr, 0); +} + +#endif |