8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libbc / libc / gen / common / mallint.h
blobd516393191d3c2d8250f186a5eba74f2b44c9c32
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
22 #pragma ident "%Z%%M% %I% %E% SMI"
25 * Copyright (c) 1986 by Sun Microsystems, Inc.
29 * file: mallint.h
30 * description:
32 * Definitions for malloc.c and friends (realloc.c, memalign.c)
34 * The node header structure. Header info never overlaps with user
35 * data space, in order to accommodate the following atrocity:
36 * free(p);
37 * realloc(p, newsize);
38 * ... which was historically used to obtain storage compaction as
39 * a side effect of the realloc() call, when the block referenced
40 * by p was coalesced with another free block by the call to free().
42 * To reduce storage consumption, a header block is associated with
43 * free blocks only, not allocated blocks.
44 * When a free block is allocated, its header block is put on
45 * a free header block list.
47 * This creates a header space and a free block space.
48 * The left pointer of a header blocks is used to chain free header
49 * blocks together. New header blocks are allocated in chunks of
50 * NFREE_HDRS.
52 #include <malloc.h>
54 typedef enum {false,true} bool;
55 typedef struct freehdr *Freehdr;
56 typedef struct dblk *Dblk;
57 typedef unsigned int uint;
60 * Description of a header for a free block
61 * Only free blocks have such headers.
63 struct freehdr {
64 Freehdr left; /* Left tree pointer */
65 Freehdr right; /* Right tree pointer */
66 Dblk block; /* Ptr to the data block */
67 uint size;
70 #define NIL ((Freehdr) 0)
71 #define NFREE_HDRS 512 /* Get this many headers at a time */
72 #define SMALLEST_BLK sizeof(struct dblk) /* Size of smallest block */
73 #define NULL 0
76 * Description of a data block.
77 * A data block consists of a length word, possibly followed by
78 * a filler word for alignment, followed by the user's data.
79 * To back up from the user's data to the length word, use
80 * (address of data) - ALIGNSIZ;
83 #ifdef sparc
84 #define ALIGNSIZ sizeof(double)
85 struct dblk {
86 uint size; /* Size of the block */
87 uint filler; /* filler, for double alignment */
88 char data[ALIGNSIZ]; /* Addr returned to the caller */
90 #endif
92 #ifdef mc68000
93 #define ALIGNSIZ sizeof(uint)
94 struct dblk {
95 uint size; /* Size of the block */
96 char data[ALIGNSIZ]; /* Addr returned to the caller */
98 #endif
102 * weight(x) is the size of a block, in bytes; or 0 if and only if x
103 * is a null pointer. Note that malloc() and free() should be
104 * prepared to deal with things like zero-length blocks, which
105 * can be introduced by errant programs.
108 #define weight(x) ((x) == NIL? 0: (x->size))
109 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
110 #define nextblk(p, size) ((Dblk) ((char *) (p) + (size)))
111 #define max(a, b) ((a) < (b)? (b): (a))
112 #define min(a, b) ((a) < (b)? (a): (b))
113 #define heapsize() (_ubound - _lbound)
114 #define misaligned(p) ((unsigned)(p)&3)
116 extern Freehdr _root;
117 extern char *_lbound, *_ubound;
118 extern int malloc_debug();
120 extern struct mallinfo __mallinfo;