Initialize Tizen 2.3
[external/bash.git] / lib / malloc / table.h
1 /* table.h - definitions for tables for keeping track of allocated memory */
2
3 /*  Copyright (C) 2001-2003 Free Software Foundation, Inc.
4
5     This file is part of GNU Bash, the Bourne-Again SHell.
6
7    Bash is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11
12    Bash is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with Bash.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _MTABLE_H
22 #define _MTABLE_H
23
24 #include "imalloc.h"
25
26 #ifdef MALLOC_REGISTER
27
28 /* values for flags byte. */
29 #define MT_ALLOC        0x01
30 #define MT_FREE         0x02
31
32 /*
33  * Memory table entry.
34  *
35  * MEM is the address of the allocated pointer.
36  * SIZE is the requested allocation size.
37  * FLAGS includes either MT_ALLOC (MEM is allocated) or MT_FREE (MEM is
38  * not allocated).  Other flags later.
39  * FUNC is set to the name of the function doing the allocation (from the
40  * `tag' argument to register_alloc().
41  * FILE and LINE are the filename and line number of the last allocation
42  * and free (depending on STATUS) of MEM.
43  * NALLOC and NFREE are incremented on each allocation that returns MEM or
44  * each free of MEM, respectively (way to keep track of memory reuse
45  * and how well the free lists are working).
46  *
47  */
48 typedef struct mr_table {
49         PTR_T mem;
50         size_t size;
51         char flags;
52         const char *func;
53         const char *file;
54         int line;
55         int nalloc, nfree;
56 } mr_table_t;
57
58 #define REG_TABLE_SIZE  8192
59
60 extern mr_table_t *mr_table_entry __P((PTR_T));
61 extern void mregister_alloc __P((const char *, PTR_T, size_t, const char *, int));
62 extern void mregister_free __P((PTR_T, int, const char *, int));
63 extern void mregister_describe_mem ();
64 extern void mregister_dump_table __P((void));
65 extern void mregister_table_init __P((void));
66
67 /* NOTE:  HASH_MIX taken from dmalloc (http://dmalloc.com) */
68
69 /*
70  * void HASH_MIX
71  *
72  * DESCRIPTION:
73  *
74  * Mix 3 32-bit values reversibly.  For every delta with one or two
75  * bits set, and the deltas of all three high bits or all three low
76  * bits, whether the original value of a,b,c is almost all zero or is
77  * uniformly distributed.
78  *
79  * If HASH_MIX() is run forward or backward, at least 32 bits in a,b,c
80  * have at least 1/4 probability of changing.  If mix() is run
81  * forward, every bit of c will change between 1/3 and 2/3 of the
82  * time.  (Well, 22/100 and 78/100 for some 2-bit deltas.)
83  *
84  * HASH_MIX() takes 36 machine instructions, but only 18 cycles on a
85  * superscalar machine (like a Pentium or a Sparc).  No faster mixer
86  * seems to work, that's the result of my brute-force search.  There
87  * were about 2^68 hashes to choose from.  I only tested about a
88  * billion of those.
89  */
90 #define HASH_MIX(a, b, c) \
91  do { \
92    a -= b; a -= c; a ^= (c >> 13); \
93    b -= c; b -= a; b ^= (a << 8); \
94    c -= a; c -= b; c ^= (b >> 13); \
95    a -= b; a -= c; a ^= (c >> 12); \
96    b -= c; b -= a; b ^= (a << 16); \
97    c -= a; c -= b; c ^= (b >> 5); \
98    a -= b; a -= c; a ^= (c >> 3); \
99    b -= c; b -= a; b ^= (a << 10); \
100    c -= a; c -= b; c ^= (b >> 15); \
101  } while(0)
102
103 #endif /* MALLOC_REGISTER */
104
105 #endif /* _MTABLE_H */