summaryrefslogtreecommitdiff
path: root/libc/stdlib/malloc-930716/malloc.h
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-06-18 09:19:10 +0000
committerEric Andersen <andersen@codepoet.org>2002-06-18 09:19:10 +0000
commitf1952f0996f0586abe1d987e35e594c2b9cce31e (patch)
tree282fd2361db44db9e96b56c6c21972daa81c3f9f /libc/stdlib/malloc-930716/malloc.h
parent3bc8ac7796cf6f3ab67316e6df5aa8915a6bb03e (diff)
Rework, reduce the size, add proper locking
-Erik
Diffstat (limited to 'libc/stdlib/malloc-930716/malloc.h')
-rw-r--r--libc/stdlib/malloc-930716/malloc.h63
1 files changed, 9 insertions, 54 deletions
diff --git a/libc/stdlib/malloc-930716/malloc.h b/libc/stdlib/malloc-930716/malloc.h
index 34458c062..fc21a13cc 100644
--- a/libc/stdlib/malloc-930716/malloc.h
+++ b/libc/stdlib/malloc-930716/malloc.h
@@ -10,23 +10,13 @@
#include <sys/cdefs.h>
-/* Underlying allocation function; successive calls should return
- contiguous pieces of memory. */
-extern void *(*__morecore)(long);
-
-/* Default value of previous. */
-extern void *__default_morecore_init(long);
-extern void *__default_morecore(long);
-
/* The allocator divides the heap into blocks of fixed size; large
requests receive one or more whole blocks, and small requests
receive a fragment of a block. Fragment sizes are powers of two,
and all fragments of a block are the same size. When all the
fragments in a block have been freed, the block itself is freed.
- WARNING: BLOCKSIZE must be set greater than or equal to the
- machine's page size for valloc() to work correctly. The default
- definition here is 4096 bytes. */
-#define INT_BIT (CHAR_BIT * sizeof (int))
+ */
+#define INT_BIT (CHAR_BIT * sizeof (size_t))
#define BLOCKLOG (INT_BIT > 16 ? 12 : 9)
#define BLOCKSIZE (1 << BLOCKLOG)
#define BLOCKIFY(SIZE) (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE)
@@ -42,66 +32,31 @@ extern void *__default_morecore(long);
/* Data structure giving per-block information. */
union info {
struct {
- int type; /* Zero for a large block, or positive
+ size_t type; /* Zero for a large block, or positive
giving the logarithm to the base two
of the fragment size. */
union {
struct {
- int nfree; /* Free fragments in a fragmented block. */
- int first; /* First free fragment of the block. */
+ size_t nfree; /* Free fragments in a fragmented block. */
+ size_t first; /* First free fragment of the block. */
} frag;
- int size; /* Size (in blocks) of a large cluster. */
+ size_t size; /* Size (in blocks) of a large cluster. */
} info;
} busy;
struct {
- int size; /* Size (in blocks) of a free cluster. */
- int next; /* Index of next free cluster. */
- int prev; /* Index of previous free cluster. */
+ size_t size; /* Size (in blocks) of a free cluster. */
+ size_t next; /* Index of next free cluster. */
+ size_t prev; /* Index of previous free cluster. */
} free;
};
-/* Pointer to first block of the heap. */
-extern char *_heapbase;
-
-/* Table indexed by block number giving per-block information. */
-extern union info *_heapinfo;
-
/* Address to block number and vice versa. */
#define BLOCK(A) (((char *) (A) - _heapbase) / BLOCKSIZE + 1)
#define ADDRESS(B) ((void *) (((B) - 1) * BLOCKSIZE + _heapbase))
-/* Current search index for the heap table. */
-extern int _heapindex;
-
-/* Limit of valid info table indices. */
-extern int _heaplimit;
-
/* Doubly linked lists of free fragments. */
struct list {
struct list *next;
struct list *prev;
};
-/* Count of blocks for each fragment size. */
-extern int _fragblocks[];
-
-/* Free list headers for each fragment size. */
-extern struct list _fraghead[];
-
-/* List of blocks allocated with `memalign' (or `valloc'). */
-struct alignlist
-{
- struct alignlist *next;
- __ptr_t aligned; /* The address that memaligned returned. */
- __ptr_t exact; /* The address that malloc returned. */
-};
-extern struct alignlist *_aligned_blocks;
-
-extern void _free_internal __P ((__ptr_t __ptr));
-
-extern void free (void *);
-extern void * malloc (size_t);
-extern void * calloc (size_t, size_t);
-extern void * valloc (size_t);
-extern void * memalign (size_t, size_t);
-extern void * realloc (void *, size_t);