1 /* malloc.c - dynamic memory allocation for bash. */
3 /* Copyright (C) 1985, 1987, 1997 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
19 In other words, you are welcome to use, share and improve this program.
20 You are forbidden to forbid anyone else to use, share and improve
21 what you give them. Help stamp out software-hoarding! */
24 * @(#)nmalloc.c 1 (Caltech) 2/21/82
26 * U of M Modified: 20 Jun 1983 ACT: strange hacks for Emacs
28 * Nov 1983, Mike@BRL, Added support for 4.1C/4.2 BSD.
30 * This is a very fast storage allocator. It allocates blocks of a small
31 * number of different sizes, and keeps free lists of each size. Blocks
32 * that don't exactly fit are passed up to the next larger size. In this
33 * implementation, the available sizes are (2^n)-4 (or -16) bytes long.
34 * This is designed for use in a program that uses vast quantities of
35 * memory, but bombs when it runs out. To make it a little better, it
36 * warns the user when he starts to get near the end.
38 * June 84, ACT: modified rcheck code to check the range given to malloc,
39 * rather than the range determined by the 2-power used.
41 * Jan 85, RMS: calls malloc_warning to issue warning on nearly full.
42 * No longer Emacs-specific; can serve as all-purpose malloc for GNU.
43 * You should call malloc_init to reinitialize after loading dumped Emacs.
44 * Call malloc_stats to get info on memory stats if MALLOC_STATS turned on.
45 * realloc knows how to return same block given, just changing its size,
46 * if the power of 2 is correct.
50 * nextf[i] is the pointer to the next free block of size 2^(i+3). The
51 * smallest allocatable block is 8 bytes. The overhead information will
52 * go in the first int of the block, and the returned pointer will point
56 /* Define this to have free() write 0xcf into memory as it's freed, to
57 uncover callers that refer to freed memory. */
58 /* SCO 3.2v4 getcwd and possibly other libc routines fail with MEMSCRAMBLE */
59 #if !defined (NO_MEMSCRAMBLE)
63 #if defined (HAVE_CONFIG_H)
65 #endif /* HAVE_CONFIG_H */
68 # include "bashtypes.h"
71 # include <sys/types.h>
74 # if defined (__STDC__) || defined (__GNUC__) || defined (__cplusplus)
75 # define __P(protos) protos
77 # define __P(protos) ()
83 #if defined (HAVE_UNISTD_H)
87 /* Determine which kind of system this is. */
90 #if defined (HAVE_STRING_H)
98 /* Define getpagesize () if the system does not. */
99 #ifndef HAVE_GETPAGESIZE
100 # include "getpagesize.h"
107 #ifdef MALLOC_REGISTER
111 /* System-specific omissions. */
118 #define ISALLOC ((char) 0xf7) /* magic byte that implies allocation */
119 #define ISFREE ((char) 0x54) /* magic byte that implies free block */
120 /* this is for error checking only */
121 #define ISMEMALIGN ((char) 0xd6) /* Stored before the value returned by
122 memalign, with the rest of the word
123 being the distance to the true
124 beginning of the block. */
127 /* We have a flag indicating whether memory is allocated, an index in
128 nextf[], a size field, and a sentinel value to determine whether or
129 not a caller wrote before the start of allocated memory; to realloc()
130 memory we either copy mh_nbytes or just change mh_nbytes if there is
131 enough room in the block for the new size. Range checking is always
134 bits64_t mh_align; /* 8 */
136 char mi_alloc; /* ISALLOC or ISFREE */ /* 1 */
137 char mi_index; /* index in nextf[] */ /* 1 */
138 /* Remainder are valid only when block is allocated */
139 u_bits16_t mi_magic2; /* should be == MAGIC2 */ /* 2 */
140 u_bits32_t mi_nbytes; /* # of bytes allocated */ /* 4 */
143 #define mh_alloc minfo.mi_alloc
144 #define mh_index minfo.mi_index
145 #define mh_nbytes minfo.mi_nbytes
146 #define mh_magic2 minfo.mi_magic2
148 /* Access free-list pointer of a block.
149 It is stored at block + sizeof (char *).
150 This is not a field in the minfo structure member of union mhead
151 because we want sizeof (union mhead)
152 to describe the overhead for when the block is in use,
153 and we do not want the free-list pointer to count in that. */
156 (*(union mhead **) (sizeof (char *) + (char *) (a)))
158 /* To implement range checking, we write magic values in at the beginning
159 and end of each allocated block, and make sure they are undisturbed
160 whenever a free or a realloc occurs. */
162 /* Written in each of the 4 bytes following the block's real space */
164 /* Written in the 2 bytes before the block's real space (-4 bytes) */
165 #define MAGIC2 0x5555
166 #define MSLOP 4 /* 4 bytes extra for MAGIC1s */
168 /* How many bytes are actually allocated for a request of size N --
169 rounded up to nearest multiple of 8 after accounting for malloc
171 #define ALLOCATED_BYTES(n) (((n) + sizeof (union mhead) + MSLOP + 7) & ~7)
176 if (!(p)) xbotch((PTR_T)0, ERR_ASSERT_FAILED, __STRING(p), file, line); \
180 /* Minimum and maximum bucket indices for block splitting (and to bound
181 the search for a block to split). */
183 #define SPLIT_MID 11 /* XXX - was 9 */
184 #define SPLIT_MAX 14 /* XXX - was 12 */
186 /* Minimum and maximum bucket indices for block coalescing. */
187 #define COMBINE_MIN 6
188 #define COMBINE_MAX (pagebucket - 1)
190 #define MIN_COMBINE_FREE 4
192 /* Flags for the internal functions. */
193 #define MALLOC_WRAPPER 0x01 /* wrapper function */
194 #define MALLOC_INTERNAL 0x02 /* internal function calling another */
195 #define MALLOC_NOTRACE 0x04 /* don't trace this allocation or free */
196 #define MALLOC_NOREG 0x08 /* don't register this allocation or free */
199 #define ERR_DUPFREE 0x01
200 #define ERR_UNALLOC 0x02
201 #define ERR_UNDERFLOW 0x04
202 #define ERR_ASSERT_FAILED 0x08
204 /* Evaluates to true if NB is appropriate for bucket NU. NB is adjusted
205 appropriately by the caller to account for malloc overhead. */
206 #define IN_BUCKET(nb, nu) \
207 ((nb) > (4 << (nu)) && ((nb) <= (8 << (nu))))
209 /* nextf[i] is free list of blocks of size 2**(i + 3) */
211 static union mhead *nextf[NBUCKETS];
213 /* busy[i] is nonzero while allocation of block size i is in progress. */
215 static char busy[NBUCKETS];
217 static int pagesz; /* system page size. */
218 static int pagebucket; /* bucket for requests a page in size */
219 static int maxbuck; /* highest bucket receiving allocation request. */
221 /* Declarations for internal functions */
222 static PTR_T internal_malloc __P((size_t, const char *, int, int));
223 static PTR_T internal_realloc __P((PTR_T, size_t, const char *, int, int));
224 static void internal_free __P((PTR_T, const char *, int, int));
225 static PTR_T internal_memalign __P((unsigned int, size_t, const char *, int, int));
227 static PTR_T internal_calloc __P((size_t, size_t, const char *, int, int));
228 static void internal_cfree __P((PTR_T, const char *, int, int));
231 static PTR_T internal_valloc __P((size_t, const char *, int, int));
235 extern void botch ();
237 static void botch __P((const char *, const char *, int));
239 static void xbotch __P((PTR_T, int, const char *, const char *, int));
242 extern struct _malstats _mstats;
243 #endif /* MALLOC_STATS */
246 extern char *sbrk ();
247 #endif /* !HAVE_DECL_SBRK */
250 extern int interrupt_immediately;
251 extern int signal_is_trapped __P((int));
254 /* Debugging variables available to applications. */
255 int malloc_flags = 0; /* future use */
256 int malloc_trace = 0; /* trace allocations and frees to stderr */
257 int malloc_register = 0; /* future use */
261 botch (s, file, line)
263 fprintf (stderr, "malloc: failed assertion: %s\n", s);
264 (void)fflush (stderr);
269 /* print the file and line number that caused the assertion failure and
270 call botch() to do whatever the application wants with the information */
272 xbotch (mem, e, s, file, line)
279 fprintf (stderr, "\r\nmalloc: %s:%d: assertion botched\r\n",
280 file ? file : "unknown", line);
281 #ifdef MALLOC_REGISTER
282 if (mem != NULL && malloc_register)
283 mregister_describe_mem (mem, stderr);
285 (void)fflush (stderr);
286 botch(s, file, line);
290 /* Coalesce two adjacent free blocks off the free list for size NU - 1,
291 as long as there are at least MIN_COMBINE_FREE free blocks and we
292 can find two adjacent free blocks. nextf[NU -1] is assumed to not
293 be busy; the caller (morecore()) checks for this. */
298 register union mhead *mp, *mp1, *mp2;
299 register int nfree, nbuck;
303 if (nextf[nbuck] == 0)
309 mp2 = (union mhead *)0;
316 /* We may not want to run all the way through the free list here;
317 if we do not, we need to check a threshold value here and break
318 if nfree exceeds it. */
320 if (nfree < MIN_COMBINE_FREE)
322 /* OK, now we have mp1 pointing to the block we want to add to nextf[NU].
323 CHAIN(mp2) must equal mp1. Check that mp1 and mp are adjacent. */
324 if (CHAIN(mp2) != mp1)
325 xbotch ((PTR_T)0, 0, "bcoalesce: CHAIN(mp2) != mp1", (char *)NULL, 0);
326 siz = 1 << (nbuck + 3);
327 if (CHAIN (mp1) != (union mhead *)((char *)mp1 + siz))
328 return; /* not adjacent */
331 _mstats.tbcoalesce++;
334 /* Since they are adjacent, remove them from the free list */
335 CHAIN (mp2) = CHAIN (mp);
337 /* And add the combined two blocks to nextf[NU]. */
338 mp1->mh_alloc = ISFREE;
340 CHAIN (mp1) = nextf[nu];
345 /* Split a block at index > NU (but less than SPLIT_MAX) into a set of
346 blocks of the correct size, and attach them to nextf[NU]. nextf[NU]
347 is assumed to be empty. Must be called with signals blocked (e.g.,
353 register union mhead *mp;
354 int nbuck, nblks, split_max;
357 split_max = (maxbuck > SPLIT_MAX) ? maxbuck : SPLIT_MAX;
361 for (nbuck = split_max; nbuck > nu; nbuck--)
363 if (busy[nbuck] || nextf[nbuck] == 0)
370 for (nbuck = nu + 1; nbuck <= split_max; nbuck++)
372 if (busy[nbuck] || nextf[nbuck] == 0)
378 if (nbuck > split_max || nbuck <= nu)
381 /* XXX might want to split only if nextf[nbuck] has >= 2 blocks free
382 and nbuck is below some threshold. */
386 _mstats.nsplit[nbuck]++;
389 /* Figure out how many blocks we'll get. */
390 siz = (1 << (nu + 3));
391 nblks = (1 << (nbuck + 3)) / siz;
393 /* Remove the block from the chain of larger blocks. */
395 nextf[nbuck] = CHAIN (mp);
397 /* Split the block and put it on the requested chain. */
401 mp->mh_alloc = ISFREE;
403 if (--nblks <= 0) break;
404 CHAIN (mp) = (union mhead *)((char *)mp + siz);
405 mp = (union mhead *)((char *)mp + siz);
411 block_signals (setp, osetp)
412 sigset_t *setp, *osetp;
414 #ifdef HAVE_POSIX_SIGNALS
417 sigprocmask (SIG_BLOCK, setp, osetp);
419 # if defined (HAVE_BSD_SIGNALS)
420 *osetp = sigsetmask (-1);
426 unblock_signals (setp, osetp)
427 sigset_t *setp, *osetp;
429 #ifdef HAVE_POSIX_SIGNALS
430 sigprocmask (SIG_SETMASK, osetp, (sigset_t *)NULL);
432 # if defined (HAVE_BSD_SIGNALS)
439 morecore (nu) /* ask system for more memory */
440 register int nu; /* size index to get more of */
442 register union mhead *mp;
445 long sbrk_amt; /* amount to get via sbrk() */
449 /* Block all signals in case we are executed from a signal handler. */
452 if (interrupt_immediately || signal_is_trapped (SIGINT) || signal_is_trapped (SIGCHLD))
455 block_signals (&set, &oset);
459 siz = 1 << (nu + 3); /* size of desired block for nextf[nu] */
462 goto morecore_done; /* oops */
465 _mstats.nmorecore[nu]++;
468 /* Try to split a larger block here, if we're within the range of sizes
478 /* Try to coalesce two adjacent blocks from the free list on nextf[nu - 1],
479 if we can, and we're withing the range of the block coalescing limits. */
480 if (nu >= COMBINE_MIN && nu < COMBINE_MAX && busy[nu - 1] == 0 && nextf[nu - 1])
488 /* Take at least a page, and figure out how many blocks of the requested
489 size we're getting. */
493 nblks = sbrk_amt / siz;
497 /* We always want to request an integral multiple of the page size
498 from the kernel, so let's compute whether or not `siz' is such
499 an amount. If it is, we can just request it. If not, we want
500 the smallest integral multiple of pagesize that is larger than
501 `siz' and will satisfy the request. */
502 sbrk_amt = siz % pagesz;
506 sbrk_amt = siz + pagesz - sbrk_amt;
512 _mstats.tsbrk += sbrk_amt;
515 mp = (union mhead *) sbrk (sbrk_amt);
517 /* Totally out of memory. */
521 /* shouldn't happen, but just in case -- require 8-byte alignment */
524 mp = (union mhead *) (((long)mp + 7) & ~7);
528 /* save new header and link the nblks blocks together */
532 mp->mh_alloc = ISFREE;
534 if (--nblks <= 0) break;
535 CHAIN (mp) = (union mhead *)((char *)mp + siz);
536 mp = (union mhead *)((char *)mp + siz);
542 unblock_signals (&set, &oset);
545 #if defined (MEMSCRAMBLE) || !defined (NO_CALLOC)
559 #endif /* MEMSCRAMBLE || !NO_CALLOC */
562 malloc_debug_dummy ()
564 write (1, "malloc_debug_dummy\n", 19);
568 internal_malloc (n, file, line, flags) /* get a block */
573 register union mhead *p;
574 register long nbytes;
577 /* Get the system page size and align break pointer so everything will
578 be page-aligned. The page size must be at least 1K -- anything
579 smaller is increased. */
582 register long sbrk_needed;
584 pagesz = getpagesize ();
587 /* OK, how much do we need to allocate to make things page-aligned?
588 This partial page is wasted space. Once we figure out how much
589 to advance the break pointer, go ahead and do it. */
590 sbrk_needed = pagesz - ((long)sbrk (0) & (pagesz - 1)); /* sbrk(0) % pagesz */
592 sbrk_needed += pagesz;
593 /* Now allocate the wasted space. */
598 _mstats.tsbrk += sbrk_needed;
600 if ((long)sbrk (sbrk_needed) == -1)
605 while (pagesz > nbytes)
613 /* Figure out how many bytes are required, rounding up to the nearest
614 multiple of 8, then figure out which nextf[] area to use. Try to
615 be smart about where to start searching -- if the number of bytes
616 needed is greater than the page size, we can start at pagebucket. */
617 nbytes = ALLOCATED_BYTES(n);
619 if (nbytes <= (pagesz >> 1))
621 register unsigned int shiftr;
623 shiftr = (nbytes - 1) >> 2; /* == (nbytes - 1) / 4 */
624 while (shiftr >>= 1) /* == (nbytes - 1) / {8,16,32,...} */
629 register u_bits32_t amt;
640 /* Silently reject too-large requests. */
641 if (nunits >= NBUCKETS)
642 return ((PTR_T) NULL);
644 /* In case this is reentrant use of malloc from signal handler,
645 pick a block size that no other malloc level is currently
646 trying to allocate. That's the easiest harmless way not to
647 interfere with the other level of execution. */
649 if (busy[nunits]) _mstats.nrecurse++;
651 while (busy[nunits]) nunits++;
654 if (nunits > maxbuck)
657 /* If there are no blocks of the appropriate size, go get some */
658 if (nextf[nunits] == 0)
661 /* Get one block off the list, and set the new list head */
662 if ((p = nextf[nunits]) == NULL)
667 nextf[nunits] = CHAIN (p);
670 /* Check for free block clobbered */
671 /* If not for this check, we would gobble a clobbered free chain ptr
672 and bomb out on the NEXT allocate of this size block */
673 if (p->mh_alloc != ISFREE || p->mh_index != nunits)
674 xbotch ((PTR_T)0, 0, "malloc: block on free list clobbered", file, line);
676 /* Fill in the info, and set up the magic numbers for range checking. */
677 p->mh_alloc = ISALLOC;
678 p->mh_magic2 = MAGIC2;
681 register char *m = (char *) (p + 1) + n;
683 *m++ = MAGIC1, *m++ = MAGIC1, *m++ = MAGIC1, *m = MAGIC1;
687 zmemset ((char *)(p + 1), 0xdf, n); /* scramble previous contents */
690 _mstats.nmalloc[nunits]++;
691 _mstats.tmalloc[nunits]++;
693 #endif /* MALLOC_STATS */
696 if (malloc_trace && (flags & MALLOC_NOTRACE) == 0)
697 mtrace_alloc ("malloc", p + 1, n, file, line);
700 #ifdef MALLOC_REGISTER
701 if (malloc_register && (flags & MALLOC_NOREG) == 0)
702 mregister_alloc ("malloc", p + 1, n, file, line);
705 return (char *) (p + 1); /* XXX - should be cast to PTR_T? */
709 internal_free (mem, file, line, flags)
714 register union mhead *p;
717 register unsigned int nbytes;
718 int ubytes; /* caller-requested size */
720 if ((ap = (char *)mem) == 0)
723 p = (union mhead *) ap - 1;
725 if (p->mh_alloc == ISMEMALIGN)
728 p = (union mhead *) ap - 1;
731 #if defined (MALLOC_TRACE) || defined (MALLOC_REGISTER)
732 if (malloc_trace || malloc_register)
733 ubytes = p->mh_nbytes;
736 if (p->mh_alloc != ISALLOC)
738 if (p->mh_alloc == ISFREE)
739 xbotch (mem, ERR_DUPFREE,
740 "free: called with already freed block argument", file, line);
742 xbotch (mem, ERR_UNALLOC,
743 "free: called with unallocated block argument", file, line);
746 ASSERT (p->mh_magic2 == MAGIC2);
748 nunits = p->mh_index;
749 nbytes = ALLOCATED_BYTES(p->mh_nbytes);
750 /* Since the sizeof(u_bits32_t) bytes before the memory handed to the user
751 are now used for the number of bytes allocated, a simple check of
752 mh_magic2 is no longer sufficient to catch things like p[-1] = 'x'.
753 We sanity-check the value of mh_nbytes against the size of the blocks
754 in the appropriate bucket before we use it. This can still cause problems
755 and obscure errors if mh_nbytes is wrong but still within range; the
756 checks against MAGIC1 will probably fail then. Using MALLOC_REGISTER
757 will help here, since it saves the original number of bytes requested. */
758 if (IN_BUCKET(nbytes, nunits) == 0)
759 xbotch (mem, ERR_UNDERFLOW,
760 "free: underflow detected; mh_nbytes out of range", file, line);
763 ASSERT (*ap++ == MAGIC1); ASSERT (*ap++ == MAGIC1);
764 ASSERT (*ap++ == MAGIC1); ASSERT (*ap == MAGIC1);
767 zmemset (mem, 0xcf, p->mh_nbytes);
770 ASSERT (nunits < NBUCKETS);
771 p->mh_alloc = ISFREE;
773 if (busy[nunits] == 1)
774 return; /* this is bogus, but at least it won't corrupt the chains */
776 /* Protect against signal handlers calling malloc. */
778 /* Put this block on the free list. */
779 CHAIN (p) = nextf[nunits];
784 _mstats.nmalloc[nunits]--;
786 #endif /* MALLOC_STATS */
789 if (malloc_trace && (flags & MALLOC_NOTRACE) == 0)
790 mtrace_free (mem, ubytes, file, line);
793 #ifdef MALLOC_REGISTER
794 if (malloc_register && (flags & MALLOC_NOREG) == 0)
795 mregister_free (mem, ubytes, file, line);
800 internal_realloc (mem, n, file, line, flags)
806 register union mhead *p;
807 register u_bits32_t tocopy;
808 register unsigned int nbytes;
818 internal_free (mem, file, line, MALLOC_INTERNAL);
821 if ((p = (union mhead *) mem) == 0)
822 return internal_malloc (n, file, line, MALLOC_INTERNAL);
825 nunits = p->mh_index;
826 ASSERT (nunits < NBUCKETS);
828 if (p->mh_alloc != ISALLOC)
829 xbotch (mem, ERR_UNALLOC,
830 "realloc: called with unallocated block argument", file, line);
832 ASSERT (p->mh_magic2 == MAGIC2);
833 nbytes = ALLOCATED_BYTES(p->mh_nbytes);
834 /* Since the sizeof(u_bits32_t) bytes before the memory handed to the user
835 are now used for the number of bytes allocated, a simple check of
836 mh_magic2 is no longer sufficient to catch things like p[-1] = 'x'.
837 We sanity-check the value of mh_nbytes against the size of the blocks
838 in the appropriate bucket before we use it. This can still cause problems
839 and obscure errors if mh_nbytes is wrong but still within range; the
840 checks against MAGIC1 will probably fail then. Using MALLOC_REGISTER
841 will help here, since it saves the original number of bytes requested. */
842 if (IN_BUCKET(nbytes, nunits) == 0)
843 xbotch (mem, ERR_UNDERFLOW,
844 "realloc: underflow detected; mh_nbytes out of range", file, line);
846 m = (char *)mem + (tocopy = p->mh_nbytes);
847 ASSERT (*m++ == MAGIC1); ASSERT (*m++ == MAGIC1);
848 ASSERT (*m++ == MAGIC1); ASSERT (*m == MAGIC1);
850 /* See if desired size rounds to same power of 2 as actual size. */
851 nbytes = ALLOCATED_BYTES(n);
853 /* If ok, use the same block, just marking its size as changed. */
854 if (IN_BUCKET(nbytes, nunits))
856 m = (char *)mem + tocopy;
857 *m++ = 0; *m++ = 0; *m++ = 0; *m++ = 0;
860 *m++ = MAGIC1; *m++ = MAGIC1; *m++ = MAGIC1; *m++ = MAGIC1;
871 if ((m = internal_malloc (n, file, line, MALLOC_INTERNAL|MALLOC_NOTRACE|MALLOC_NOREG)) == 0)
873 FASTCOPY (mem, m, tocopy);
874 internal_free (mem, file, line, MALLOC_INTERNAL);
877 if (malloc_trace && (flags & MALLOC_NOTRACE) == 0)
878 mtrace_alloc ("realloc", m, n, file, line);
881 #ifdef MALLOC_REGISTER
882 if (malloc_register && (flags & MALLOC_NOREG) == 0)
883 mregister_alloc ("realloc", m, n, file, line);
890 internal_memalign (alignment, size, file, line, flags)
891 unsigned int alignment;
897 register char *aligned;
898 register union mhead *p;
900 ptr = internal_malloc (size + alignment, file, line, MALLOC_INTERNAL);
904 /* If entire block has the desired alignment, just accept it. */
905 if (((long) ptr & (alignment - 1)) == 0)
907 /* Otherwise, get address of byte in the block that has that alignment. */
909 aligned = (char *) (((long) ptr + alignment - 1) & -alignment);
911 aligned = (char *) (((long) ptr + alignment - 1) & (~alignment + 1));
914 /* Store a suitable indication of how to free the block,
915 so that free can find the true beginning of it. */
916 p = (union mhead *) aligned - 1;
917 p->mh_nbytes = aligned - ptr;
918 p->mh_alloc = ISMEMALIGN;
923 #if !defined (NO_VALLOC)
924 /* This runs into trouble with getpagesize on HPUX, and Multimax machines.
925 Patching out seems cleaner than the ugly fix needed. */
927 internal_valloc (size, file, line, flags)
932 return internal_memalign (getpagesize (), size, file, line, flags|MALLOC_INTERNAL);
934 #endif /* !NO_VALLOC */
938 internal_calloc (n, s, file, line, flags)
947 result = internal_malloc (total, file, line, flags|MALLOC_INTERNAL);
949 zmemset (result, 0, total);
954 internal_cfree (p, file, line, flags)
959 internal_free (p, file, line, flags|MALLOC_INTERNAL);
961 #endif /* !NO_CALLOC */
966 malloc_free_blocks (size)
970 register union mhead *p;
973 for (p = nextf[size]; p; p = CHAIN (p))
982 sh_malloc (bytes, file, line)
987 return internal_malloc (bytes, file, line, MALLOC_WRAPPER);
991 sh_realloc (ptr, size, file, line)
997 return internal_realloc (ptr, size, file, line, MALLOC_WRAPPER);
1001 sh_free (mem, file, line)
1006 internal_free (mem, file, line, MALLOC_WRAPPER);
1010 sh_memalign (alignment, size, file, line)
1011 unsigned int alignment;
1016 return internal_memalign (alignment, size, file, line, MALLOC_WRAPPER);
1021 sh_calloc (n, s, file, line)
1026 return internal_calloc (n, s, file, line, MALLOC_WRAPPER);
1030 sh_cfree (mem, file, line)
1035 internal_cfree (mem, file, line, MALLOC_WRAPPER);
1041 sh_valloc (size, file, line)
1046 return internal_valloc (size, file, line, MALLOC_WRAPPER);
1052 /* Externally-available functions that call their internal counterparts. */
1058 return internal_malloc (size, (char *)NULL, 0, 0);
1062 realloc (mem, nbytes)
1066 return internal_realloc (mem, nbytes, (char *)NULL, 0, 0);
1073 internal_free (mem, (char *)NULL, 0, 0);
1077 memalign (alignment, size)
1078 unsigned int alignment;
1081 return internal_memalign (alignment, size, (char *)NULL, 0, 0);
1089 return internal_valloc (size, (char *)NULL, 0, 0);
1098 return internal_calloc (n, s, (char *)NULL, 0, 0);
1105 internal_cfree (mem, (char *)NULL, 0, 0);