1 /* table.h - definitions for tables for keeping track of allocated memory */
3 /* Copyright (C) 2001-2003 Free Software Foundation, Inc.
5 This file is part of GNU Bash, the Bourne-Again SHell.
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.
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.
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/>.
26 #ifdef MALLOC_REGISTER
28 /* values for flags byte. */
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).
48 typedef struct mr_table {
58 #define REG_TABLE_SIZE 8192
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));
67 /* NOTE: HASH_MIX taken from dmalloc (http://dmalloc.com) */
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.
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.)
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
90 #define HASH_MIX(a, b, c) \
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); \
103 #endif /* MALLOC_REGISTER */
105 #endif /* _MTABLE_H */