Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdlib The 'new malloc' (phk's malloc, from FreeBSD...



details:   https://anonhg.NetBSD.org/src/rev/83f53634b416
branches:  trunk
changeset: 474022:83f53634b416
user:      tls <tls%NetBSD.org@localhost>
date:      Sat Jun 26 04:44:36 1999 +0000

description:
The 'new malloc' (phk's malloc, from FreeBSD) is now our only malloc.

diffstat:

 lib/libc/stdlib/Makefile.inc |    11 +-
 lib/libc/stdlib/malloc-new.c |  1144 -------------------------------
 lib/libc/stdlib/malloc.c     |  1522 +++++++++++++++++++++++++++++------------
 3 files changed, 1085 insertions(+), 1592 deletions(-)

diffs (truncated from 2765 to 300 lines):

diff -r f8518d86cdaa -r 83f53634b416 lib/libc/stdlib/Makefile.inc
--- a/lib/libc/stdlib/Makefile.inc      Sat Jun 26 04:12:45 1999 +0000
+++ b/lib/libc/stdlib/Makefile.inc      Sat Jun 26 04:44:36 1999 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.42 1999/06/17 19:33:36 tls Exp $
+#      $NetBSD: Makefile.inc,v 1.43 1999/06/26 04:44:36 tls Exp $
 #      from: @(#)Makefile.inc  8.3 (Berkeley) 2/4/95
 
 # stdlib sources
@@ -7,19 +7,12 @@
 SRCS+= _rand48.c _strtoq.c _strtouq.c a64l.c abort.c atexit.c atof.c \
        atoi.c atol.c bsearch.c calloc.c drand48.c erand48.c exit.c \
        getenv.c getopt.c getsubopt.c heapsort.c jrand48.c l64a.c \
-       lcong48.c lrand48.c merge.c mrand48.c multibyte.c \
+       lcong48.c lrand48.c malloc.c merge.c mrand48.c multibyte.c \
        nrand48.c putenv.c qabs.c qdiv.c qsort.c radixsort.c rand.c \
        rand_r.c random.c seed48.c setenv.c srand48.c strtod.c \
        strtol.c strtoq.c strtoq.c strtoul.c strtouq.c system.c \
        tdelete.c tfind.c tsearch.c twalk.c
 
-.if defined (MALLOC_NEW)
-SRCS+=  malloc-new.c
-.else
-SRCS+= malloc.c
-.endif
-
-
 # machine-dependent stdlib sources
 # m-d Makefile.inc must include sources for:
 #       abs() div() labs() ldiv()
diff -r f8518d86cdaa -r 83f53634b416 lib/libc/stdlib/malloc-new.c
--- a/lib/libc/stdlib/malloc-new.c      Sat Jun 26 04:12:45 1999 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,1144 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk%FreeBSD.ORG@localhost> wrote this file.  As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- *
- * From FreeBSD: malloc.c,v 1.43 1998/09/30 06:13:59 jb
- *
- */
-
-/*
- * Defining EXTRA_SANITY will enable extra checks which are related
- * to internal conditions and consistency in malloc.c. This has a
- * noticeable runtime performance hit, and generally will not do you
- * any good unless you fiddle with the internals of malloc or want
- * to catch random pointer corruption as early as possible.
- */
-#ifndef MALLOC_EXTRA_SANITY
-#undef MALLOC_EXTRA_SANITY
-#endif
-
-/*
- * What to use for Junk.  This is the byte value we use to fill with
- * when the 'J' option is enabled.
- */
-#define SOME_JUNK      0xd0            /* as in "Duh" :-) */
-
-/*
- * The basic parameters you can tweak.
- *
- * malloc_pageshift    pagesize = 1 << malloc_pageshift
- *                     It's probably best if this is the native
- *                     page size, but it doesn't have to be.
- *
- * malloc_minsize      minimum size of an allocation in bytes.
- *                     If this is too small it's too much work
- *                     to manage them.  This is also the smallest
- *                     unit of alignment used for the storage
- *                     returned by malloc/realloc.
- *
- */
-
-#if defined(__FreeBSD__)
-#   if defined(__i386__)
-#       define malloc_pageshift                12U
-#       define malloc_minsize          16U
-#   endif
-#   if defined(__alpha__)
-#       define malloc_pageshift                13U
-#       define malloc_minsize          16U
-#   endif
-#   if !defined(__NETBSD_SYSCALLS)
-#       define HAS_UTRACE
-#   endif
-    /*
-     * Make malloc/free/realloc thread-safe in libc for use with
-     * kernel threads.
-     */
-#   include "libc_private.h"
-#   include "spinlock.h"
-    static spinlock_t thread_lock      = _SPINLOCK_INITIALIZER;
-#   define THREAD_LOCK()               if (__isthreaded) _SPINLOCK(&thread_lock);
-#   define THREAD_UNLOCK()             if (__isthreaded) _SPINUNLOCK(&thread_lock);
-#endif /* __FreeBSD__ */
-
-#if defined(__NetBSD__)
-#   include <sys/param.h>
-#   define malloc_pageshift             PGSHIFT
-#   define malloc_minsize               16U
-#   define MADV_FREE                    MADV_DONTNEED
-#endif /* __NetBSD__ */
-
-#if defined(__sparc__) && defined(sun)
-#   define malloc_pageshift            12U
-#   define malloc_minsize              16U
-#   define MAP_ANON                    (0)
-    static int fdzero;
-#   define MMAP_FD     fdzero
-#   define INIT_MMAP() \
-       { if ((fdzero=open("/dev/zero", O_RDWR, 0000)) == -1) \
-           wrterror("open of /dev/zero"); }
-#   define MADV_FREE                   MADV_DONTNEED
-#endif /* __sparc__ */
-
-/* Insert your combination here... */
-#if defined(__FOOCPU__) && defined(__BAROS__)
-#   define malloc_pageshift            12U
-#   define malloc_minsize              16U
-#endif /* __FOOCPU__ && __BAROS__ */
-
-
-/*
- * No user serviceable parts behind this point.
- */
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-/*
- * This structure describes a page worth of chunks.
- */
-
-struct pginfo {
-    struct pginfo      *next;  /* next on the free list */
-    void               *page;  /* Pointer to the page */
-    u_short            size;   /* size of this page's chunks */
-    u_short            shift;  /* How far to shift for this size chunks */
-    u_short            free;   /* How many free chunks */
-    u_short            total;  /* How many chunk */
-    u_int              bits[1]; /* Which chunks are free */
-};
-
-/*
- * This structure describes a number of free pages.
- */
-
-struct pgfree {
-    struct pgfree      *next;  /* next run of free pages */
-    struct pgfree      *prev;  /* prev run of free pages */
-    void               *page;  /* pointer to free pages */
-    void               *end;   /* pointer to end of free pages */
-    size_t             size;   /* number of bytes free */
-};
-
-/*
- * How many bits per u_int in the bitmap.
- * Change only if not 8 bits/byte
- */
-#define        MALLOC_BITS     (8*sizeof(u_int))
-
-/*
- * Magic values to put in the page_directory
- */
-#define MALLOC_NOT_MINE        ((struct pginfo*) 0)
-#define MALLOC_FREE    ((struct pginfo*) 1)
-#define MALLOC_FIRST   ((struct pginfo*) 2)
-#define MALLOC_FOLLOW  ((struct pginfo*) 3)
-#define MALLOC_MAGIC   ((struct pginfo*) 4)
-
-#ifndef malloc_pageshift
-#define malloc_pageshift               12U
-#endif
-
-#ifndef malloc_minsize
-#define malloc_minsize                 16U
-#endif
-
-#if !defined(malloc_pagesize)
-#define malloc_pagesize                        (1UL<<malloc_pageshift)
-#endif
-
-#if ((1<<malloc_pageshift) != malloc_pagesize)
-#error "(1<<malloc_pageshift) != malloc_pagesize"
-#endif
-
-#ifndef malloc_maxsize
-#define malloc_maxsize                 ((malloc_pagesize)>>1)
-#endif
-
-/* A mask for the offset inside a page.  */
-#define malloc_pagemask        ((malloc_pagesize)-1)
-
-#define pageround(foo) (((foo) + (malloc_pagemask))&(~(malloc_pagemask)))
-#define ptr2index(foo) (((u_long)(foo) >> malloc_pageshift)-malloc_origo)
-
-#ifndef THREAD_LOCK
-#define THREAD_LOCK()
-#endif
-
-#ifndef THREAD_UNLOCK
-#define THREAD_UNLOCK()
-#endif
-
-#ifndef MMAP_FD
-#define MMAP_FD (-1)
-#endif
-
-#ifndef INIT_MMAP
-#define INIT_MMAP()
-#endif
-
-/* Set when initialization has been done */
-static unsigned malloc_started;        
-
-/* Recusion flag for public interface. */
-static int malloc_active;
-
-/* Number of free pages we cache */
-static unsigned malloc_cache = 16;
-
-/* The offset from pagenumber to index into the page directory */
-static u_long malloc_origo;
-
-/* The last index in the page directory we care about */
-static u_long last_index;
-
-/* Pointer to page directory. Allocated "as if with" malloc */
-static struct  pginfo **page_dir;
-
-/* How many slots in the page directory */
-static unsigned        malloc_ninfo;
-
-/* Free pages line up here */
-static struct pgfree free_list;
-
-/* Abort(), user doesn't handle problems.  */
-static int malloc_abort;
-
-/* Are we trying to die ?  */
-static int suicide;
-
-/* always realloc ?  */
-static int malloc_realloc;
-
-/* pass the kernel a hint on free pages ?  */
-static int malloc_hint = 1;
-
-/* xmalloc behaviour ?  */
-static int malloc_xmalloc;
-
-/* sysv behaviour for malloc(0) ?  */
-static int malloc_sysv;
-
-/* zero fill ?  */
-static int malloc_zero;
-
-/* junk fill ?  */
-static int malloc_junk;
-
-#ifdef HAS_UTRACE
-
-/* utrace ?  */
-static int malloc_utrace;
-
-struct ut { void *p; size_t s; void *r; };
-
-void utrace __P((struct ut *, int));
-
-#define UTRACE(a, b, c) \
-       if (malloc_utrace) \
-               {struct ut u; u.p=a; u.s = b; u.r=c; utrace(&u, sizeof u);}
-#else /* !HAS_UTRACE */
-#define UTRACE(a,b,c)
-#endif /* HAS_UTRACE */
-
-/* my last break. */
-static void *malloc_brk;
-
-/* one location cache for free-list holders */
-static struct pgfree *px;
-
-/* compile-time options */
-char *malloc_options;
-
-/* Name of the current public function */
-static char *malloc_func;
-
-/* Macro for mmap */



Home | Main Index | Thread Index | Old Index