diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-07-18 15:00:07 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-07-18 15:00:07 +0000 |
commit | 35d29fcb08fadaf006561a058746b0fce76a6a74 (patch) | |
tree | b42a59394f8ee7dc7c11f71ae2d45b1e1beb834b | |
parent | 3b1e82407a02aed6319c6686c5b06c2051a20cca (diff) |
Miles Bader implemented a new mmap based malloc which is much
smarter than the old "malloc-simple", and actually works, unlike
the old "malloc". So kill the old "malloc-simple" and the old
"malloc" and replace them with Miles' new malloc implementation.
Update Config files to match. Thanks Miles!
30 files changed, 844 insertions, 1524 deletions
diff --git a/extra/Configs/Config.alpha b/extra/Configs/Config.alpha index f8cc9ddbc..d5160c1fa 100644 --- a/extra/Configs/Config.alpha +++ b/extra/Configs/Config.alpha @@ -86,19 +86,17 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -MALLOC = malloc-simple +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. #MALLOC = malloc -#MALLOC = malloc-930716 +MALLOC = malloc-930716 # If you want to collect common syscall code into one function, set to this to # `true'. Set it to false otherwise. diff --git a/extra/Configs/Config.arm b/extra/Configs/Config.arm index 4d552624f..7c91b5fc6 100644 --- a/extra/Configs/Config.arm +++ b/extra/Configs/Config.arm @@ -90,17 +90,15 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -#MALLOC = malloc-simple +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. #MALLOC = malloc MALLOC = malloc-930716 diff --git a/extra/Configs/Config.cross.arm.uclinux b/extra/Configs/Config.cross.arm.uclinux index a86931f0b..30a915f26 100644 --- a/extra/Configs/Config.cross.arm.uclinux +++ b/extra/Configs/Config.cross.arm.uclinux @@ -86,18 +86,16 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -MALLOC = malloc-simple -#MALLOC = malloc +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. +MALLOC = malloc #MALLOC = malloc-930716 # Having brk allows one to use malloc-930716, which is an order diff --git a/extra/Configs/Config.h8300 b/extra/Configs/Config.h8300 index 8f29b8bd8..716c19d57 100644 --- a/extra/Configs/Config.h8300 +++ b/extra/Configs/Config.h8300 @@ -89,18 +89,16 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -MALLOC = malloc-simple -#MALLOC = malloc +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. +MALLOC = malloc #MALLOC = malloc-930716 # If you want to collect common syscall code into one function, set to this to diff --git a/extra/Configs/Config.i386 b/extra/Configs/Config.i386 index 706a34223..0125417e7 100644 --- a/extra/Configs/Config.i386 +++ b/extra/Configs/Config.i386 @@ -86,17 +86,15 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -#MALLOC = malloc-simple +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. #MALLOC = malloc MALLOC = malloc-930716 diff --git a/extra/Configs/Config.i960 b/extra/Configs/Config.i960 index 65d563b7f..0c073e9e8 100644 --- a/extra/Configs/Config.i960 +++ b/extra/Configs/Config.i960 @@ -86,17 +86,15 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -#MALLOC = malloc-simple +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. MALLOC = malloc #MALLOC = malloc-930716 diff --git a/extra/Configs/Config.m68k b/extra/Configs/Config.m68k index 90e1d4783..6a68fe786 100644 --- a/extra/Configs/Config.m68k +++ b/extra/Configs/Config.m68k @@ -86,18 +86,16 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -MALLOC = malloc-simple -#MALLOC = malloc +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. +MALLOC = malloc #MALLOC = malloc-930716 # Having brk allows one to use malloc-930716, which is an order diff --git a/extra/Configs/Config.m68k.coff b/extra/Configs/Config.m68k.coff index 0ca204a7c..73cc40d23 100644 --- a/extra/Configs/Config.m68k.coff +++ b/extra/Configs/Config.m68k.coff @@ -86,18 +86,16 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -MALLOC = malloc-simple -#MALLOC = malloc +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. +MALLOC = malloc #MALLOC = malloc-930716 # Having brk allows one to use malloc-930716, which is an order diff --git a/extra/Configs/Config.mips b/extra/Configs/Config.mips index eac4dd6ad..75ad13b43 100644 --- a/extra/Configs/Config.mips +++ b/extra/Configs/Config.mips @@ -89,17 +89,15 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -#MALLOC = malloc-simple +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. #MALLOC = malloc MALLOC = malloc-930716 diff --git a/extra/Configs/Config.mipsel b/extra/Configs/Config.mipsel index acb00142b..c302199f7 100644 --- a/extra/Configs/Config.mipsel +++ b/extra/Configs/Config.mipsel @@ -89,17 +89,15 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -#MALLOC = malloc-simple +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. #MALLOC = malloc MALLOC = malloc-930716 diff --git a/extra/Configs/Config.powerpc b/extra/Configs/Config.powerpc index 4cd446979..1d1cacf68 100644 --- a/extra/Configs/Config.powerpc +++ b/extra/Configs/Config.powerpc @@ -86,17 +86,15 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -#MALLOC = malloc-simple +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. #MALLOC = malloc MALLOC = malloc-930716 diff --git a/extra/Configs/Config.sh b/extra/Configs/Config.sh index 399d6bcc5..0b6fccc25 100644 --- a/extra/Configs/Config.sh +++ b/extra/Configs/Config.sh @@ -110,18 +110,16 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -MALLOC = malloc-simple -#MALLOC = malloc +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. +MALLOC = malloc #MALLOC = malloc-930716 # If you want to collect common syscall code into one function, set to this to diff --git a/extra/Configs/Config.sparc b/extra/Configs/Config.sparc index 761262365..f96e83020 100644 --- a/extra/Configs/Config.sparc +++ b/extra/Configs/Config.sparc @@ -86,17 +86,15 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -#MALLOC = malloc-simple +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. #MALLOC = malloc MALLOC = malloc-930716 diff --git a/extra/Configs/Config.v850e b/extra/Configs/Config.v850e index f1e618a0c..bd0a62c9b 100644 --- a/extra/Configs/Config.v850e +++ b/extra/Configs/Config.v850e @@ -88,17 +88,15 @@ HAS_LOCALE = false HAS_WCHAR = false # This specifies which malloc implementation is used. -# "malloc-simple" is very, very small, but is also very, very dumb -# and does not try to make good use of memory or clean up after itself. # -# "malloc" on the other hand is a bit bigger, but is pretty smart thereby -# minimizing memory wastage and reusing already allocated memory. This -# can be lots faster and safer IMHO. +# "malloc" use mmap for all allocations and so works very well on MMU-less +# systems that do not support the brk() system call. It is pretty smart +# about reusing already allocated memory, and minimizing memory wastage. # -# "malloc-930716" is from libc-5.3.12 and was/is the standard gnu malloc. -# It is actually smaller than "malloc", but because it is based on brk/sbrk -# it will only work on systems with an MMU. -#MALLOC = malloc-simple +# "malloc-930716" is derived from libc-5.3.12 and uses the brk() system call +# for all memory allocations. This makes it very fast. It is also pretty +# smart about reusing already allocated memory, and minimizing memory wastage. +# Because this uses brk() it will not work on uClinux MMU-less systems. MALLOC = malloc #MALLOC = malloc-930716 diff --git a/libc/stdlib/malloc-simple/.indent.pro b/libc/stdlib/malloc-simple/.indent.pro deleted file mode 100644 index 492ecf1c7..000000000 --- a/libc/stdlib/malloc-simple/.indent.pro +++ /dev/null @@ -1,33 +0,0 @@ ---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 deleted file mode 100644 index f8fe3520d..000000000 --- a/libc/stdlib/malloc-simple/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# Makefile for uClibc -# -# Copyright (C) 2000 by Lineo, inc. -# Copyright (C) 2000,2001 Erik Andersen <andersen@uclibc.org> -# -# 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 Library General Public License for more -# details. -# -# You should have received a copy of the GNU Library 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.mak - -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 - $(STRIPTOOL) -x -R .note -R .comment $*.o - -$(COBJS): %.o : %.c - $(CC) $(CFLAGS) -c $< -o $@ - $(STRIPTOOL) -x -R .note -R .comment $*.o - -clean: - rm -f *.[oa] *~ core - diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c deleted file mode 100644 index 1824507eb..000000000 --- a/libc/stdlib/malloc-simple/alloc.c +++ /dev/null @@ -1,141 +0,0 @@ - -/* - * For MMU hosts we need to track the size of the allocations otherwise - * munmap will fail to free the memory (EINVAL). - */ - -#include <features.h> -#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 = ", (int) (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 size, char *function, char *file, int line) -{ - void *result; - - fprintf(stderr, "malloc of %d bytes at %s @%s:%d = ", (int) size, function, - file, line); - result = malloc(size); - 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 size) -{ - void *result; - - /* Some programs will call malloc (0). Lets be strict and return NULL */ - if (size == 0) - return NULL; - -#ifdef __UCLIBC_HAS_MMU__ - result = mmap((void *) 0, size + sizeof(size_t), PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); -#else - result = mmap((void *) 0, size, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); -#endif - - if (result == MAP_FAILED) - return 0; - -#ifdef __UCLIBC_HAS_MMU__ - * (size_t *) result = size; - return(result + sizeof(size_t)); -#else - return(result); -#endif -} - -#endif - -#ifdef L_free - -void free(void *ptr) -{ -#ifdef __UCLIBC_HAS_MMU__ - if (ptr) { - ptr -= sizeof(size_t); - munmap(ptr, * (size_t *) ptr + sizeof(size_t)); - } -#else - munmap(ptr, 0); -#endif -} - -#endif - -#ifdef L_realloc - -void *realloc(void *ptr, size_t size) -{ - void *newptr = NULL; - - if (size > 0) { - newptr = malloc(size); - if (newptr && ptr) { -#ifdef __UCLIBC_HAS_MMU__ - memcpy(newptr, ptr, * ((size_t *) (ptr - sizeof(size_t)))); -#else - memcpy(newptr, ptr, size); -#endif - free(ptr); - } - } - else - free(ptr); - return newptr; -} - -#endif diff --git a/libc/stdlib/malloc/Makefile b/libc/stdlib/malloc/Makefile index 64aad319a..710f70297 100644 --- a/libc/stdlib/malloc/Makefile +++ b/libc/stdlib/malloc/Makefile @@ -1,7 +1,7 @@ # Makefile for uClibc # -# Copyright (C) 2000 by Lineo, inc. -# Copyright (C) 2000,2001 Erik Andersen <andersen@uclibc.org> +# Copyright (C) 2002 NEC Corporation +# Copyright (C) 2002 Miles Bader <miles@gnu.org> # # 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 @@ -24,14 +24,10 @@ TOPDIR=../../../ include $(TOPDIR)Rules.mak -#MSRC=alloc.c -#MOBJ=malloc_dbg.o free_dbg.o calloc_dbg.o realloc_dbg.o - -MSRC1=malloc.c -MOBJ1=_avl_support.o _free_support.o _malloc_init.o _realloc_no_move.o calloc.o \ - free.o malloc.o realloc.o - -OBJS=$(MOBJ) $(MOBJ1) +CSRC = malloc.o free.o realloc.o calloc.o heap_alloc.o \ + heap_alloc_at.o heap_free.o heap_append_free.o +COBJS=$(patsubst %.c,%.o, $(CSRC)) +OBJS=$(COBJS) all: $(OBJS) $(LIBC) @@ -40,12 +36,8 @@ $(LIBC): ar-target ar-target: $(OBJS) $(AR) $(ARFLAGS) $(LIBC) $(OBJS) -$(MOBJ): $(MSRC) - $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o - $(STRIPTOOL) -x -R .note -R .comment $*.o - -$(MOBJ1): $(MSRC1) - $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o +$(COBJS): %.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ $(STRIPTOOL) -x -R .note -R .comment $*.o clean: diff --git a/libc/stdlib/malloc/alloc.c b/libc/stdlib/malloc/alloc.c deleted file mode 100644 index 99537a35d..000000000 --- a/libc/stdlib/malloc/alloc.c +++ /dev/null @@ -1,60 +0,0 @@ -#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 %ld |