Remove dup inftarg.o from NATDEPFILES.
[deliverable/binutils-gdb.git] / mmalloc / fsf.shar.orig
1 #--------CUT---------CUT---------CUT---------CUT--------#
2 #########################################################
3 # #
4 # This is a shell archive file. To extract files: #
5 # #
6 # 1) Make a directory for the files. #
7 # 2) Write a file, such as "file.shar", containing #
8 # this archive file into the directory. #
9 # 3) Type "sh file.shar". Do not use csh. #
10 # #
11 #########################################################
12 #
13 #
14 echo Extracting ChangeLog:
15 sed 's/^Z//' >ChangeLog <<\STUNKYFLUFF
16 ZThu Jul 11 18:15:04 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu)
17 Z
18 Z * Merged with C library version, which now has its own subdir.
19 Z * malloc.h, *.c: Use ansideclisms and #ifdefs for portability both
20 Z in and out of the C library.
21 Z * Makefile: New makefile for malloc subdir in libc.
22 Z Has targets to create malloc.tar{,.Z} by ansidecl processing on srcs.
23 Z * malloc/Makefile: New file; Makefile for standalone distribution.
24 Z * malloc/README: New file; info for same.
25 Z
26 ZFri Apr 6 00:18:36 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu)
27 Z
28 Z * Makefile: Add comments.
29 Z
30 ZThu Apr 5 23:08:14 1990 Mike Haertel (mike at albert.ai.mit.edu)
31 Z
32 Z * mcheck.c (mcheck, checkhdr): Support user-supplied abort()
33 Z function.
34 Z * malloc.h: Declare __free().
35 Z * Makefile: New target libmalloc.a.
36 Z
37 ZThu Apr 5 21:56:03 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu)
38 Z
39 Z * free.c (free): Split into free and __free.
40 Z * malloc.c (morecore): Call __free on oldinfo.
41 Z\f
42 ZLocal Variables:
43 Zmode: indented-text
44 Zleft-margin: 8
45 Zfill-column: 76
46 Zversion-control: never
47 ZEnd:
48 STUNKYFLUFF
49 set `sum ChangeLog`
50 if test 21008 != $1
51 then
52 echo ChangeLog: Checksum error. Is: $1, should be: 21008.
53 fi
54 #
55 #
56 echo Extracting Makefile:
57 sed 's/^Z//' >Makefile <<\STUNKYFLUFF
58 Z# Copyright (C) 1991, 1992 Free Software Foundation, Inc.
59 Z# This file is part of the GNU C Library.
60 Z
61 Z# The GNU C Library is free software; you can redistribute it and/or
62 Z# modify it under the terms of the GNU Library General Public License as
63 Z# published by the Free Software Foundation; either version 2 of the
64 Z# License, or (at your option) any later version.
65 Z
66 Z# The GNU C Library is distributed in the hope that it will be useful,
67 Z# but WITHOUT ANY WARRANTY; without even the implied warranty of
68 Z# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
69 Z# Library General Public License for more details.
70 Z
71 Z# You should have received a copy of the GNU Library General Public
72 Z# License along with the GNU C Library; see the file COPYING.LIB. If
73 Z# not, write to the Free Software Foundation, Inc., 675 Mass Ave,
74 Z# Cambridge, MA 02139, USA.
75 Z
76 Z#
77 Z# Makefile for malloc routines
78 Z#
79 Zsubdir := malloc
80 Z
81 Zall:
82 Z
83 Zheaders := malloc.h
84 Z
85 Zroutines := malloc free cfree realloc calloc morecore \
86 Z valloc memalign mcheck mtrace mstats
87 Znodist := cfree
88 Z
89 Zinstall-lib := libmcheck.a
90 Z
91 Zdistribute := mcheck-init.c ChangeLog TODO \
92 Z malloc/gmalloc-head.c dist-README dist-Makefile \
93 Z mtrace.awk
94 Z
95 Z
96 Zinclude ../Rules
97 Z
98 Z$(objpfx)libmcheck.a: $(objpfx)mcheck-init.o
99 Z ln $< $@
100 Z
101 Z# Make the standalone malloc distribution.
102 Zdist-routines := $(filter-out $(nodist),$(routines))
103 Zmalloc-dist := README COPYING.LIB Makefile ChangeLog \
104 Z $(addsuffix .c,$(dist-routines)) $(headers) gmalloc.c \
105 Z gmalloc-head.c mtrace.awk
106 Z%.uu: %
107 Z uuencode $< < $< > $@-tmp
108 Z mv $@-tmp $@
109 Z%.Z: %
110 Z compress -c $< > $@-tmp
111 Z mv $@-tmp $@
112 Zmalloc.tar: $(addprefix malloc/,$(malloc-dist))
113 Z tar ch$(verbose)f $@ $^
114 Zmalloc/%.c: %.c malloc/
115 Z $(..)ansidecl -trad $< | indent -stdin -gnu > $@-tmp
116 Z mv $@-tmp $@
117 Zmalloc/%.h: %.h malloc/
118 Z $(..)ansidecl -trad $< | indent -stdin -gnu > $@-tmp
119 Z mv $@-tmp $@
120 Zmalloc/Makefile: dist-Makefile
121 Z sed -e 's,<DIST-SOURCES>,$(addsuffix .c,$(dist-routines)),' \
122 Z -e 's,<DIST-OBJECTS>,$(addsuffix .o,$(dist-routines)),' \
123 Z -e 's,<DIST-HEADERS>,$(headers),' < $< > $@-tmp
124 Z mv $@-tmp $@
125 Zmalloc/gmalloc.c: malloc/Makefile
126 Z $(MAKE) -C malloc gmalloc.c
127 Zmalloc/README: dist-README
128 Z @rm -f $@
129 Z cp $< $@
130 Zmalloc/%: %
131 Z @rm -f $@
132 Z cp $< $@
133 STUNKYFLUFF
134 set `sum Makefile`
135 if test 48180 != $1
136 then
137 echo Makefile: Checksum error. Is: $1, should be: 48180.
138 fi
139 #
140 #
141 echo Extracting TODO:
142 sed 's/^Z//' >TODO <<\STUNKYFLUFF
143 Z0. Access data structures with accessor macros, then turn the heapinfo
144 Zinto several arrays for faster access on machines with addressing modes.
145 ZAlso, this eventually raises the possibility of maintaining multiple
146 Zheaps.
147 Z1. Possible heuristic to catch multiple frees. Introduce an extra word
148 Zof heapinfo that says whether the remaining info is for something
149 Zbusy or something free. Then we can catch attempts to free already-free
150 Zlarge blocks, as well as things not belonging to malloc at all. In the
151 Zcase of a fragment, we can check if the fragment looks like it *already*
152 Zbelongs to the fragment list, by comparing it with the "first" fragment
153 Zof the block, or checking its "prev" pointer to see if it points into
154 Zthe block. Then if it looks like it might we can exhaustively search
155 Zthe block's free list to see if the fragment is there or not. Extending
156 Zthe heapinfo structure would have the benefit of making it a power of
157 Ztwo and thus making array indexing faster, perhaps. Suitably adapted,
158 Zthis heuristic could also catch invalid pointers passed to realloc.
159 Z
160 ZAll of these additional features require the inclusion of <malloc.h>.
161 Z3. indirect reference allocator: ialloc(), ifree(), irealloc().
162 Z4. garbage collecting allocator: galloc(), garbage(), gfree(), grealloc().
163 STUNKYFLUFF
164 set `sum TODO`
165 if test 51437 != $1
166 then
167 echo TODO: Checksum error. Is: $1, should be: 51437.
168 fi
169 #
170 #
171 echo Extracting calloc.c:
172 sed 's/^Z//' >calloc.c <<\STUNKYFLUFF
173 Z/* Copyright (C) 1991 Free Software Foundation, Inc.
174 ZThis file is part of the GNU C Library.
175 Z
176 ZThe GNU C Library is free software; you can redistribute it and/or
177 Zmodify it under the terms of the GNU Library General Public License as
178 Zpublished by the Free Software Foundation; either version 2 of the
179 ZLicense, or (at your option) any later version.
180 Z
181 ZThe GNU C Library is distributed in the hope that it will be useful,
182 Zbut WITHOUT ANY WARRANTY; without even the implied warranty of
183 ZMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
184 ZLibrary General Public License for more details.
185 Z
186 ZYou should have received a copy of the GNU Library General Public
187 ZLicense along with the GNU C Library; see the file COPYING.LIB. If
188 Znot, write to the Free Software Foundation, Inc., 675 Mass Ave,
189 ZCambridge, MA 02139, USA. */
190 Z
191 Z/* IGNORE(@ */
192 Z#include <ansidecl.h>
193 Z/* @) */
194 Z#include <malloc.h>
195 Z
196 Z#if defined(__GNU_LIBRARY__) || defined(STDC_HEADERS) || defined(USG)
197 Z#include <string.h>
198 Z#else
199 Z#define memset(s, zero, n) bzero ((s), (n))
200 Z#endif
201 Z
202 Z/* Allocate an array of NMEMB elements each SIZE bytes long.
203 Z The entire array is initialized to zeros. */
204 ZPTR
205 ZDEFUN(calloc, (nmemb, size), register size_t nmemb AND register size_t size)
206 Z{
207 Z register PTR result = malloc (nmemb * size);
208 Z
209 Z if (result != NULL)
210 Z (void) memset (result, 0, nmemb * size);
211 Z
212 Z return result;
213 Z}
214 STUNKYFLUFF
215 set `sum calloc.c`
216 if test 48371 != $1
217 then
218 echo calloc.c: Checksum error. Is: $1, should be: 48371.
219 fi
220 #
221 #
222 echo Extracting cfree.c:
223 sed 's/^Z//' >cfree.c <<\STUNKYFLUFF
224 Z/* Copyright (C) 1991 Free Software Foundation, Inc.
225 ZThis file is part of the GNU C Library.
226 Z
227 ZThe GNU C Library is free software; you can redistribute it and/or
228 Zmodify it under the terms of the GNU Library General Public License as
229 Zpublished by the Free Software Foundation; either version 2 of the
230 ZLicense, or (at your option) any later version.
231 Z
232 ZThe GNU C Library is distributed in the hope that it will be useful,
233 Zbut WITHOUT ANY WARRANTY; without even the implied warranty of
234 ZMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
235 ZLibrary General Public License for more details.
236 Z
237 ZYou should have received a copy of the GNU Library General Public
238 ZLicense along with the GNU C Library; see the file COPYING.LIB. If
239 Znot, write to the Free Software Foundation, Inc., 675 Mass Ave,
240 ZCambridge, MA 02139, USA. */
241 Z
242 Z#include <ansidecl.h>
243 Z#include <stdlib.h>
244 Z
245 Z#undef cfree
246 Z
247 Z#include <gnu-stabs.h>
248 Z
249 Zfunction_alias(cfree, free, void, (ptr),
250 Z DEFUN(cfree, (ptr), PTR ptr))
251 STUNKYFLUFF
252 set `sum cfree.c`
253 if test 17488 != $1
254 then
255 echo cfree.c: Checksum error. Is: $1, should be: 17488.
256 fi
257 #
258 #
259 echo Extracting dist-Makefile:
260 sed 's/^Z//' >dist-Makefile <<\STUNKYFLUFF
261 Z# Copyright (C) 1991 Free Software Foundation, Inc.
262 Z# This file is part of the GNU C Library.
263 Z
264 Z# The GNU C Library is free software; you can redistribute it and/or
265 Z# modify it under the terms of the GNU Library General Public License
266 Z# as published by the Free Software Foundation; either version 2 of
267 Z# the License, or (at your option) any later version.
268 Z
269 Z# The GNU C Library is distributed in the hope that it will be useful,
270 Z# but WITHOUT ANY WARRANTY; without even the implied warranty of
271 Z# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
272 Z# Library General Public License for more details.
273 Z
274 Z# You should have received a copy of the GNU Library General Public
275 Z# License along with the GNU C Library; see the file COPYING.LIB. If
276 Z# not, write to the Free Software Foundation, Inc., 675 Mass Ave,
277 Z# Cambridge, MA 02139, USA.
278 Z
279 Z# Makefile for standalone distribution of malloc.
280 Z
281 Z# Use this on System V.
282 Z#CPPFLAGS = -DUSG
283 Z
284 Z.PHONY: all
285 Zall: libmalloc.a gmalloc.o
286 Z
287 Zsources = <DIST-SOURCES>
288 Zobjects = <DIST-OBJECTS>
289 Zheaders = <DIST-HEADERS>
290 Z
291 Zlibmalloc.a: $(objects)
292 Z ar crv $@ $(objects)
293 Z ranlib $@
294 Z
295 Z$(objects): $(headers)
296 Z
297 Zgmalloc.c: gmalloc-head.c $(headers) $(sources)
298 Z cat gmalloc-head.c $(headers) $(sources) > $@
299 Z
300 Z.c.o:
301 Z $(CC) $(CFLAGS) $(CPPFLAGS) -I. -c $< $(OUTPUT_OPTION)
302 Z
303 Z.PHONY: clean realclean malloc-clean malloc-realclean
304 Zclean malloc-clean:
305 Z -rm -f libmalloc.a *.o core
306 Zrealclean malloc-realclean: clean
307 Z -rm -f TAGS tags *~
308 Z
309 Z# For inside the C library.
310 Zmalloc.tar malloc.tar.Z:
311 Z $(MAKE) -C .. $@
312 STUNKYFLUFF
313 set `sum dist-Makefile`
314 if test 58822 != $1
315 then
316 echo dist-Makefile: Checksum error. Is: $1, should be: 58822.
317 fi
318 #
319 #
320 echo Extracting dist-README:
321 sed 's/^Z//' >dist-README <<\STUNKYFLUFF
322 ZThis is the standalone distribution of GNU malloc.
323 ZGNU malloc is part of the GNU C Library, but is also distributed separately.
324 Z
325 ZIf you find bugs in GNU malloc, send reports to bug-glibc@prep.ai.mit.edu.
326 Z
327 ZGNU malloc is free software. See the file COPYING.LIB for copying conditions.
328 Z
329 ZThe makefile builds libmalloc.a and gmalloc.o. If you are using GNU malloc
330 Zto replace your system's existing malloc package, it is important to make
331 Zsure you get all GNU functions, not some of the GNU functions and some from
332 Zthe system library. gmalloc.o has all the functions in one file, so using
333 Zthat will make sure you don't accidentally mix the two malloc packages.
334 STUNKYFLUFF
335 set `sum dist-README`
336 if test 59167 != $1
337 then
338 echo dist-README: Checksum error. Is: $1, should be: 59167.
339 fi
340 #
341 #
342 echo Extracting free.c:
343 sed 's/^Z//' >free.c <<\STUNKYFLUFF
344 Z/* Free a block of memory allocated by `malloc'.
345 Z Copyright 1990, 1991 Free Software Foundation
346 Z Written May 1989 by Mike Haertel.
347 Z
348 ZThe GNU C Library is free software; you can redistribute it and/or
349 Zmodify it under the terms of the GNU Library General Public License as
350 Zpublished by the Free Software Foundation; either version 2 of the
351 ZLicense, or (at your option) any later version.
352 Z
353 ZThe GNU C Library is distributed in the hope that it will be useful,
354 Zbut WITHOUT ANY WARRANTY; without even the implied warranty of
355 ZMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
356 ZLibrary General Public License for more details.
357 Z
358 ZYou should have received a copy of the GNU Library General Public
359 ZLicense along with the GNU C Library; see the file COPYING.LIB. If
360 Znot, write to the Free Software Foundation, Inc., 675 Mass Ave,
361 ZCambridge, MA 02139, USA.
362 Z
363 Z The author may be reached (Email) at the address mike@ai.mit.edu,
364 Z or (US mail) as Mike Haertel c/o Free Software Foundation. */
365 Z
366 Z/* IGNORE(@ */
367 Z#include <ansidecl.h>
368 Z#include <stddef.h>
369 Z#include <stdlib.h>
370 Z/* @) */
371 Z
372 Z#define _MALLOC_INTERNAL
373 Z#include <malloc.h>
374 Z
375 Z/* Debugging hook for free. */
376 Zvoid EXFUN((*__free_hook), (PTR __ptr));
377 Z
378 Z/* List of blocks allocated by memalign. */
379 Zstruct alignlist *_aligned_blocks = NULL;
380 Z
381 Z/* Return memory to the heap.
382 Z Like `free' but don't call a __free_hook if there is one. */
383 Zvoid
384 ZDEFUN(__free, (ptr), PTR ptr)
385 Z{
386 Z int type;
387 Z size_t block, blocks;
388 Z register size_t i;
389 Z struct list *prev, *next;
390 Z
391 Z block = BLOCK(ptr);
392 Z
393 Z type = _heapinfo[block].busy.type;
394 Z switch (type)
395 Z {
396 Z case 0:
397 Z /* Get as many statistics as early as we can. */
398 Z --_chunks_used;
399 Z _bytes_used -= _heapinfo[block].busy.info.size * BLOCKSIZE;
400 Z _bytes_free += _heapinfo[block].busy.info.size * BLOCKSIZE;
401 Z
402 Z /* Find the free cluster previous to this one in the free list.
403 Z Start searching at the last block referenced; this may benefit
404 Z programs with locality of allocation. */
405 Z i = _heapindex;
406 Z if (i > block)
407 Z while (i > block)
408 Z i = _heapinfo[i].free.prev;
409 Z else
410 Z {
411 Z do
412 Z i = _heapinfo[i].free.next;
413 Z while (i > 0 && i < block);
414 Z i = _heapinfo[i].free.prev;
415 Z }
416 Z
417 Z /* Determine how to link this block into the free list. */
418 Z if (block == i + _heapinfo[i].free.size)
419 Z {
420 Z /* Coalesce this block with its predecessor. */
421 Z _heapinfo[i].free.size += _heapinfo[block].busy.info.size;
422 Z block = i;
423 Z }
424 Z else
425 Z {
426 Z /* Really link this block back into the free list. */
427 Z _heapinfo[block].free.size = _heapinfo[block].busy.info.size;
428 Z _heapinfo[block].free.next = _heapinfo[i].free.next;
429 Z _heapinfo[block].free.prev = i;
430 Z _heapinfo[i].free.next = block;
431 Z _heapinfo[_heapinfo[block].free.next].free.prev = block;
432 Z ++_chunks_free;
433 Z }
434 Z
435 Z /* Now that the block is linked in, see if we can coalesce it
436 Z with its successor (by deleting its successor from the list
437 Z and adding in its size). */
438 Z if (block + _heapinfo[block].free.size == _heapinfo[block].free.next)
439 Z {
440 Z _heapinfo[block].free.size
441 Z += _heapinfo[_heapinfo[block].free.next].free.size;
442 Z _heapinfo[block].free.next
443 Z = _heapinfo[_heapinfo[block].free.next].free.next;
444 Z _heapinfo[_heapinfo[block].free.next].free.prev = block;
445 Z --_chunks_free;
446 Z }
447 Z
448 Z /* Now see if we can return stuff to the system. */
449 Z blocks = _heapinfo[block].free.size;
450 Z if (blocks >= FINAL_FREE_BLOCKS && block + blocks == _heaplimit
451 Z && (*__morecore)(0) == ADDRESS(block + blocks))
452 Z {
453 Z register size_t bytes = blocks * BLOCKSIZE;
454 Z _heaplimit -= blocks;
455 Z (*__morecore)(- bytes);
456 Z _heapinfo[_heapinfo[block].free.prev].free.next
457 Z = _heapinfo[block].free.next;
458 Z _heapinfo[_heapinfo[block].free.next].free.prev
459 Z = _heapinfo[block].free.prev;
460 Z block = _heapinfo[block].free.prev;
461 Z --_chunks_free;
462 Z _bytes_free -= bytes;
463 Z }
464 Z
465 Z /* Set the next search to begin at this block. */
466 Z _heapindex = block;
467 Z break;
468 Z
469 Z default:
470 Z /* Do some of the statistics. */
471 Z --_chunks_used;
472 Z _bytes_used -= 1 << type;
473 Z ++_chunks_free;
474 Z _bytes_free += 1 << type;
475 Z
476 Z /* Get the address of the first free fragment in this block. */
477 Z prev = (struct list *) ((char *) ADDRESS(block) +
478 Z (_heapinfo[block].busy.info.frag.first << type));
479 Z
480 Z if (_heapinfo[block].busy.info.frag.nfree == (BLOCKSIZE >> type) - 1)
481 Z {
482 Z /* If all fragments of this block are free, remove them
483 Z from the fragment list and free the whole block. */
484 Z next = prev;
485 Z for (i = 1; i < (size_t) (BLOCKSIZE >> type); ++i)
486 Z next = next->next;
487 Z prev->prev->next = next;
488 Z if (next != NULL)
489 Z next->prev = prev->prev;
490 Z _heapinfo[block].busy.type = 0;
491 Z _heapinfo[block].busy.info.size = 1;
492 Z
493 Z /* Keep the statistics accurate. */
494 Z ++_chunks_used;
495 Z _bytes_used += BLOCKSIZE;
496 Z _chunks_free -= BLOCKSIZE >> type;
497 Z _bytes_free -= BLOCKSIZE;
498 Z
499 Z free(ADDRESS(block));
500 Z }
501 Z else if (_heapinfo[block].busy.info.frag.nfree != 0)
502 Z {
503 Z /* If some fragments of this block are free, link this
504 Z fragment into the fragment list after the first free
505 Z fragment of this block. */
506 Z next = (struct list *) ptr;
507 Z next->next = prev->next;
508 Z next->prev = prev;
509 Z prev->next = next;
510 Z if (next->next != NULL)
511 Z next->next->prev = next;
512 Z ++_heapinfo[block].busy.info.frag.nfree;
513 Z }
514 Z else
515 Z {
516 Z /* No fragments of this block are free, so link this
517 Z fragment into the fragment list and announce that
518 Z it is the first free fragment of this block. */
519 Z prev = (struct list *) ptr;
520 Z _heapinfo[block].busy.info.frag.nfree = 1;
521 Z _heapinfo[block].busy.info.frag.first = (unsigned long int)
522 Z ((unsigned long int) ((char *) ptr - (char *) NULL)
523 Z % BLOCKSIZE >> type);
524 Z prev->next = _fraghead[type].next;
525 Z prev->prev = &_fraghead[type];
526 Z prev->prev->next = prev;
527 Z if (prev->next != NULL)
528 Z prev->next->prev = prev;
529 Z }
530 Z break;
531 Z }
532 Z}
533 Z
534 Z/* Return memory to the heap. */
535 Zvoid
536 ZDEFUN(free, (ptr), PTR ptr)
537 Z{
538 Z register struct alignlist *l;
539 Z
540 Z if (ptr == NULL)
541 Z return;
542 Z
543 Z for (l = _aligned_blocks; l != NULL; l = l->next)
544 Z if (l->aligned == ptr)
545 Z {
546 Z l->aligned = NULL; /* Mark the slot in the list as free. */
547 Z ptr = l->exact;
548 Z break;
549 Z }
550 Z
551 Z if (__free_hook != NULL)
552 Z (*__free_hook) (ptr);
553 Z else
554 Z __free (ptr);
555 Z}
556 STUNKYFLUFF
557 set `sum free.c`
558 if test 53143 != $1
559 then
560 echo free.c: Checksum error. Is: $1, should be: 53143.
561 fi
562 #
563 #
564 echo Extracting gmalloc-head.c:
565 sed 's/^Z//' >gmalloc-head.c <<\STUNKYFLUFF
566 Z/* DO NOT EDIT THIS FILE -- it is automagically generated. -*- C -*- */
567 Z
568 Z#define SKELETON
569 Z
570 Z#if defined(__GNU_LIBRARY__) || defined(STDC_HEADERS) || defined(USG)
571 Z#include <string.h>
572 Z#else
573 Z#define memset(s, zero, n) bzero ((s), (n))
574 Z#define memcpy(d, s, n) bcopy ((s), (d), (n))
575 Z#define memmove(d, s, n) bcopy ((s), (d), (n))
576 Z#endif
577 Z
578 Z#define _MALLOC_INTERNAL
579 Z
580 Z/* The malloc headers and source files from the C library follow here. */
581 STUNKYFLUFF
582 set `sum gmalloc-head.c`
583 if test 33445 != $1
584 then
585 echo gmalloc-head.c: Checksum error. Is: $1, should be: 33445.
586 fi
587 #
588 #
589 echo Extracting malloc.c:
590 sed 's/^Z//' >malloc.c <<\STUNKYFLUFF
591 Z/* Memory allocator `malloc'.
592 Z Copyright 1990, 1991 Free Software Foundation
593 Z Written May 1989 by Mike Haertel.
594 Z
595 ZThe GNU C Library is free software; you can redistribute it and/or
596 Zmodify it under the terms of the GNU Library General Public License as
597 Zpublished by the Free Software Foundation; either version 2 of the
598 ZLicense, or (at your option) any later version.
599 Z
600 ZThe GNU C Library is distributed in the hope that it will be useful,
601 Zbut WITHOUT ANY WARRANTY; without even the implied warranty of
602 ZMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
603 ZLibrary General Public License for more details.
604 Z
605 ZYou should have received a copy of the GNU Library General Public
606 ZLicense along with the GNU C Library; see the file COPYING.LIB. If
607 Znot, write to the Free Software Foundation, Inc., 675 Mass Ave,
608 ZCambridge, MA 02139, USA.
609 Z
610 Z The author may be reached (Email) at the address mike@ai.mit.edu,
611 Z or (US mail) as Mike Haertel c/o Free Software Foundation. */
612 Z
613 Z/* IGNORE(@ */
614 Z#include <ansidecl.h>
615 Z#include <stddef.h>
616 Z#include <stdlib.h>
617 Z/* @) */
618 Z
619 Z#define _MALLOC_INTERNAL
620 Z#include <malloc.h>
621 Z
622 Z#if defined(__GNU_LIBRARY__) || defined(STDC_HEADERS) || defined(USG)
623 Z#include <string.h>
624 Z#else
625 Z#define memset(s, zero, n) bzero ((s), (n))
626 Z#define memcpy(d, s, n) bcopy ((s), (d), (n))
627 Z#endif
628 Z
629 Z
630 Z/* How to really get more memory. */
631 ZPTR EXFUN((*__morecore), (ptrdiff_t __size)) = __default_morecore;
632 Z
633 Z/* Debugging hook for `malloc'. */
634 ZPTR EXFUN((*__malloc_hook), (size_t __size));
635 Z
636 Z/* Pointer to the base of the first block. */
637 Zchar *_heapbase;
638 Z
639 Z/* Block information table. Allocated with align/__free (not malloc/free). */
640 Zmalloc_info *_heapinfo;
641 Z
642 Z/* Number of info entries. */
643 Zstatic size_t heapsize;
644 Z
645 Z/* Search index in the info table. */
646 Zsize_t _heapindex;
647 Z
648 Z/* Limit of valid info table indices. */
649 Zsize_t _heaplimit;
650 Z
651 Z/* Free lists for each fragment size. */
652 Zstruct list _fraghead[BLOCKLOG];
653 Z
654 Z/* Instrumentation. */
655 Zsize_t _chunks_used;
656 Zsize_t _bytes_used;
657 Zsize_t _chunks_free;
658 Zsize_t _bytes_free;
659 Z
660 Z/* Are you experienced? */
661 Zint __malloc_initialized;
662 Z
663 Z/* Aligned allocation. */
664 Zstatic PTR
665 ZDEFUN(align, (size), size_t size)
666 Z{
667 Z PTR result;
668 Z unsigned long int adj;
669 Z
670 Z result = (*__morecore)(size);
671 Z adj = (unsigned long int) ((unsigned long int) ((char *) result -
672 Z (char *) NULL)) % BLOCKSIZE;
673 Z if (adj != 0)
674 Z {
675 Z adj = BLOCKSIZE - adj;
676 Z (void) (*__morecore)(adj);
677 Z result = (char *) result + adj;
678 Z }
679 Z return result;
680 Z}
681 Z
682 Z/* Set everything up and remember that we have. */
683 Zstatic int
684 ZDEFUN_VOID(initialize)
685 Z{
686 Z heapsize = HEAP / BLOCKSIZE;
687 Z _heapinfo = (malloc_info *) align(heapsize * sizeof(malloc_info));
688 Z if (_heapinfo == NULL)
689 Z return 0;
690 Z memset(_heapinfo, 0, heapsize * sizeof(malloc_info));
691 Z _heapinfo[0].free.size = 0;
692 Z _heapinfo[0].free.next = _heapinfo[0].free.prev = 0;
693 Z _heapindex = 0;
694 Z _heapbase = (char *) _heapinfo;
695 Z __malloc_initialized = 1;
696 Z return 1;
697 Z}
698 Z
699 Z/* Get neatly aligned memory, initializing or
700 Z growing the heap info table as necessary. */
701 Zstatic PTR
702 ZDEFUN(morecore, (size), size_t size)
703 Z{
704 Z PTR result;
705 Z malloc_info *newinfo, *oldinfo;
706 Z size_t newsize;
707 Z
708 Z result = align(size);
709 Z if (result == NULL)
710 Z return NULL;
711 Z
712 Z /* Check if we need to grow the info table. */
713 Z if ((size_t) BLOCK((char *) result + size) > heapsize)
714 Z {
715 Z newsize = heapsize;
716 Z while ((size_t) BLOCK((char *) result + size) > newsize)
717 Z newsize *= 2;
718 Z newinfo = (malloc_info *) align(newsize * sizeof(malloc_info));
719 Z if (newinfo == NULL)
720 Z {
721 Z (*__morecore)(- size);
722 Z return NULL;
723 Z }
724 Z memset(newinfo, 0, newsize * sizeof(malloc_info));
725 Z memcpy(newinfo, _heapinfo, heapsize * sizeof(malloc_info));
726 Z oldinfo = _heapinfo;
727 Z newinfo[BLOCK(oldinfo)].busy.type = 0;
728 Z newinfo[BLOCK(oldinfo)].busy.info.size
729 Z = BLOCKIFY(heapsize * sizeof(malloc_info));
730 Z _heapinfo = newinfo;
731 Z __free(oldinfo);
732 Z heapsize = newsize;
733 Z }
734 Z
735 Z _heaplimit = BLOCK((char *) result + size);
736 Z return result;
737 Z}
738 Z
739 Z/* Allocate memory from the heap. */
740 ZPTR
741 ZDEFUN(malloc, (size), size_t size)
742 Z{
743 Z PTR result;
744 Z size_t block, blocks, lastblocks, start;
745 Z register size_t i;
746 Z struct list *next;
747 Z
748 Z if (size == 0)
749 Z return NULL;
750 Z
751 Z if (__malloc_hook != NULL)
752 Z return (*__malloc_hook)(size);
753 Z
754 Z if (!__malloc_initialized)
755 Z if (!initialize())
756 Z return NULL;
757 Z
758 Z if (size < sizeof(struct list))
759 Z size = sizeof(struct list);
760 Z
761 Z /* Determine the allocation policy based on the request size. */
762 Z if (size <= BLOCKSIZE / 2)
763 Z {
764 Z /* Small allocation to receive a fragment of a block.
765 Z Determine the logarithm to base two of the fragment size. */
766 Z register size_t log = 1;
767 Z --size;
768 Z while ((size /= 2) != 0)
769 Z ++log;
770 Z
771 Z /* Look in the fragment lists for a
772 Z free fragment of the desired size. */
773 Z next = _fraghead[log].next;
774 Z if (next != NULL)
775 Z {
776 Z /* There are free fragments of this size.
777 Z Pop a fragment out of the fragment list and return it.
778 Z Update the block's nfree and first counters. */
779 Z result = (PTR) next;
780 Z next->prev->next = next->next;
781 Z if (next->next != NULL)
782 Z next->next->prev = next->prev;
783 Z block = BLOCK(result);
784 Z if (--_heapinfo[block].busy.info.frag.nfree != 0)
785 Z _heapinfo[block].busy.info.frag.first = (unsigned long int)
786 Z ((unsigned long int) ((char *) next->next - (char *) NULL)
787 Z % BLOCKSIZE) >> log;
788 Z
789 Z /* Update the statistics. */
790 Z ++_chunks_used;
791 Z _bytes_used += 1 << log;
792 Z --_chunks_free;
793 Z _bytes_free -= 1 << log;
794 Z }
795 Z else
796 Z {
797 Z /* No free fragments of the desired size, so get a new block
798 Z and break it into fragments, returning the first. */
799 Z result = malloc(BLOCKSIZE);
800 Z if (result == NULL)
801 Z return NULL;
802 Z
803 Z /* Link all fragments but the first into the free list. */
804 Z for (i = 1; i < (size_t) (BLOCKSIZE >> log); ++i)
805 Z {
806 Z next = (struct list *) ((char *) result + (i << log));
807 Z next->next = _fraghead[log].next;
808 Z next->prev = &_fraghead[log];
809 Z next->prev->next = next;
810 Z if (next->next != NULL)
811 Z next->next->prev = next;
812 Z }
813 Z
814 Z /* Initialize the nfree and first counters for this block. */
815 Z block = BLOCK(result);
816 Z _heapinfo[block].busy.type = log;
817 Z _heapinfo[block].busy.info.frag.nfree = i - 1;
818 Z _heapinfo[block].busy.info.frag.first = i - 1;
819 Z
820 Z _chunks_free += (BLOCKSIZE >> log) - 1;
821 Z _bytes_free += BLOCKSIZE - (1 << log);
822 Z _bytes_used -= BLOCKSIZE - (1 << log);
823 Z }
824 Z }
825 Z else
826 Z {
827 Z /* Large allocation to receive one or more blocks.
828 Z Search the free list in a circle starting at the last place visited.
829 Z If we loop completely around without finding a large enough
830 Z space we will have to get more memory from the system. */
831 Z blocks = BLOCKIFY(size);
832 Z start = block = MALLOC_SEARCH_START;
833 Z while (_heapinfo[block].free.size < blocks)
834 Z {
835 Z block = _heapinfo[block].free.next;
836 Z if (block == start)
837 Z {
838 Z /* Need to get more from the system. Check to see if
839 Z the new core will be contiguous with the final free
840 Z block; if so we don't need to get as much. */
841 Z block = _heapinfo[0].free.prev;
842 Z lastblocks = _heapinfo[block].free.size;
843 Z if (_heaplimit != 0 && block + lastblocks == _heaplimit &&
844 Z (*__morecore)(0) == ADDRESS(block + lastblocks) &&
845 Z (morecore((blocks - lastblocks) * BLOCKSIZE)) != NULL)
846 Z {
847 Z _heapinfo[block].free.size = blocks;
848 Z _bytes_free += (blocks - lastblocks) * BLOCKSIZE;
849 Z continue;
850 Z }
851 Z result = morecore(blocks * BLOCKSIZE);
852 Z if (result == NULL)
853 Z return NULL;
854 Z block = BLOCK(result);
855 Z _heapinfo[block].busy.type = 0;
856 Z _heapinfo[block].busy.info.size = blocks;
857 Z ++_chunks_used;
858 Z _bytes_used += blocks * BLOCKSIZE;
859 Z return result;
860 Z }
861 Z }
862 Z
863 Z /* At this point we have found a suitable free list entry.
864 Z Figure out how to remove what we need from the list. */
865 Z result = ADDRESS(block);
866 Z if (_heapinfo[block].free.size > blocks)
867 Z {
868 Z /* The block we found has a bit left over,
869 Z so relink the tail end back into the free list. */
870 Z _heapinfo[block + blocks].free.size
871 Z = _heapinfo[block].free.size - blocks;
872 Z _heapinfo[block + blocks].free.next
873 Z = _heapinfo[block].free.next;
874 Z _heapinfo[block + blocks].free.prev
875 Z = _heapinfo[block].free.prev;
876 Z _heapinfo[_heapinfo[block].free.prev].free.next
877 Z = _heapinfo[_heapinfo[block].free.next].free.prev
878 Z = _heapindex = block + blocks;
879 Z }
880 Z else
881 Z {
882 Z /* The block exactly matches our requirements,
883 Z so just remove it from the list. */
884 Z _heapinfo[_heapinfo[block].free.next].free.prev
885 Z = _heapinfo[block].free.prev;
886 Z _heapinfo[_heapinfo[block].free.prev].free.next
887 Z = _heapindex = _heapinfo[block].free.next;
888 Z --_chunks_free;
889 Z }
890 Z
891 Z _heapinfo[block].busy.type = 0;
892 Z _heapinfo[block].busy.info.size = blocks;
893 Z ++_chunks_used;
894 Z _bytes_used += blocks * BLOCKSIZE;
895 Z _bytes_free -= blocks * BLOCKSIZE;
896 Z }
897 Z
898 Z return result;
899 Z}
900 STUNKYFLUFF
901 set `sum malloc.c`
902 if test 64456 != $1
903 then
904 echo malloc.c: Checksum error. Is: $1, should be: 64456.
905 fi
906 #
907 #
908 echo Extracting malloc.h:
909 sed 's/^Z//' >malloc.h <<\STUNKYFLUFF
910 Z/* Declarations for `malloc' and friends.
911 Z Copyright 1990, 1991 Free Software Foundation
912 Z Written May 1989 by Mike Haertel.
913 Z
914 ZThe GNU C Library is free software; you can redistribute it and/or
915 Zmodify it under the terms of the GNU Library General Public License as
916 Zpublished by the Free Software Foundation; either version 2 of the
917 ZLicense, or (at your option) any later version.
918 Z
919 ZThe GNU C Library is distributed in the hope that it will be useful,
920 Zbut WITHOUT ANY WARRANTY; without even the implied warranty of
921 ZMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
922 ZLibrary General Public License for more details.
923 Z
924 ZYou should have received a copy of the GNU Library General Public
925 ZLicense along with the GNU C Library; see the file COPYING.LIB. If
926 Znot, write to the Free Software Foundation, Inc., 675 Mass Ave,
927 ZCambridge, MA 02139, USA.
928 Z
929 Z The author may be reached (Email) at the address mike@ai.mit.edu,
930 Z or (US mail) as Mike Haertel c/o Free Software Foundation. */
931 Z
932 Z#ifndef _MALLOC_H
933 Z
934 Z#define _MALLOC_H 1
935 Z
936 Z/* IGNORE(@ */
937 Z#include <features.h>
938 Z#define __need_NULL
939 Z#define __need_size_t
940 Z#define __need_ptrdiff_t
941 Z#include <stddef.h>
942 Z/* @) */
943 Z
944 Z#ifndef NULL
945 Z#define NULL 0
946 Z#endif
947 Z
948 Z#ifdef __STDC__
949 Z#include <stddef.h>
950 Z#else
951 Z#undef size_t
952 Z#define size_t unsigned int
953 Z#endif
954 Z
955 Z
956 Z/* Allocate SIZE bytes of memory. */
957 Zextern PTR EXFUN(malloc, (size_t __size));
958 Z/* Re-allocate the previously allocated block
959 Z in PTR, making the new block SIZE bytes long. */
960 Zextern PTR EXFUN(realloc, (PTR __ptr, size_t __size));
961 Z/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
962 Zextern PTR EXFUN(calloc, (size_t __nmemb, size_t __size));
963 Z/* Free a block allocated by `malloc', `realloc' or `calloc'. */
964 Zextern void EXFUN(free, (PTR __ptr));
965 Z
966 Z/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
967 Zextern PTR EXFUN(memalign, (size_t __alignment, size_t __size));
968 Z
969 Z/* Allocate SIZE bytes on a page boundary. */
970 Zextern PTR EXFUN(valloc, (size_t __size));
971 Z
972 Z
973 Z#ifdef _MALLOC_INTERNAL
974 Z
975 Z#if defined(__GNU_LIBRARY__) || defined(__STDC__)
976 Z#include <limits.h>
977 Z#else
978 Z#define CHAR_BIT 8
979 Z#endif
980 Z
981 Z/* The allocator divides the heap into blocks of fixed size; large
982 Z requests receive one or more whole blocks, and small requests
983 Z receive a fragment of a block. Fragment sizes are powers of two,
984 Z and all fragments of a block are the same size. When all the
985 Z fragments in a block have been freed, the block itself is freed. */
986 Z#define INT_BIT (CHAR_BIT * sizeof(int))
987 Z#define BLOCKLOG (INT_BIT > 16 ? 12 : 9)
988 Z#define BLOCKSIZE (1 << BLOCKLOG)
989 Z#define BLOCKIFY(SIZE) (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE)
990 Z
991 Z/* Determine the amount of memory spanned by the initial heap table
992 Z (not an absolute limit). */
993 Z#define HEAP (INT_BIT > 16 ? 4194304 : 65536)
994 Z
995 Z/* Number of contiguous free blocks allowed to build up at the end of
996 Z memory before they will be returned to the system. */
997 Z#define FINAL_FREE_BLOCKS 8
998 Z
999 Z/* Where to start searching the free list when looking for new memory.
1000 Z The two possible values are 0 and _heapindex. Starting at 0 seems
1001 Z to reduce total memory usage, while starting at _heapindex seems to
1002 Z run faster. */
1003 Z#define MALLOC_SEARCH_START _heapindex
1004 Z
1005 Z/* Data structure giving per-block information. */
1006 Ztypedef union
1007 Z {
1008 Z /* Heap information for a busy block. */
1009 Z struct
1010 Z {
1011 Z /* Zero for a large block, or positive giving the
1012 Z logarithm to the base two of the fragment size. */
1013 Z int type;
1014 Z union
1015 Z {
1016 Z struct
1017 Z {
1018 Z size_t nfree; /* Free fragments in a fragmented block. */
1019 Z size_t first; /* First free fragment of the block. */
1020 Z } frag;
1021 Z /* Size (in blocks) of a large cluster. */
1022 Z size_t size;
1023 Z } info;
1024 Z } busy;
1025 Z /* Heap information for a free block (that may be the first of
1026 Z a free cluster). */
1027 Z struct
1028 Z {
1029 Z size_t size; /* Size (in blocks) of a free cluster. */
1030 Z size_t next; /* Index of next free cluster. */
1031 Z size_t prev; /* Index of previous free cluster. */
1032 Z } free;
1033 Z } malloc_info;
1034 Z
1035 Z/* Pointer to first block of the heap. */
1036 Zextern char *_heapbase;
1037 Z
1038 Z/* Table indexed by block number giving per-block information. */
1039 Zextern malloc_info *_heapinfo;
1040 Z
1041 Z/* Address to block number and vice versa. */
1042 Z#define BLOCK(A) (((char *) (A) - _heapbase) / BLOCKSIZE + 1)
1043 Z/* The following line MUST be split! m4 will not process it otherwise. */
1044 Z#define ADDRESS(B) \
1045 Z ((PTR) (((B) - 1) * BLOCKSIZE + _heapbase))
1046 Z
1047 Z/* Current search index for the heap table. */
1048 Zextern size_t _heapindex;
1049 Z
1050 Z/* Limit of valid info table indices. */
1051 Zextern size_t _heaplimit;
1052 Z
1053 Z/* Doubly linked lists of free fragments. */
1054 Zstruct list
1055 Z {
1056 Z struct list *next;
1057 Z struct list *prev;
1058 Z };
1059 Z
1060 Z/* Free list headers for each fragment size. */
1061 Zextern struct list _fraghead[];
1062 Z
1063 Z/* List of blocks allocated with `memalign' (or `valloc'). */
1064 Zstruct alignlist
1065 Z {
1066 Z struct alignlist *next;
1067 Z PTR aligned; /* The address that memaligned returned. */
1068 Z PTR exact; /* The address that malloc returned. */
1069 Z };
1070 Zextern struct alignlist *_aligned_blocks;
1071 Z
1072 Z/* Instrumentation. */
1073 Zextern size_t _chunks_used;
1074 Zextern size_t _bytes_used;
1075 Zextern size_t _chunks_free;
1076 Zextern size_t _bytes_free;
1077 Z
1078 Z/* Internal version of `free' used in `morecore'. */
1079 Zextern void EXFUN(__free, (PTR __ptr));
1080 Z
1081 Z#endif /* _MALLOC_INTERNAL. */
1082 Z
1083 Z/* Underlying allocation function; successive calls should
1084 Z return contiguous pieces of memory. */
1085 Zextern PTR EXFUN((*__morecore), (ptrdiff_t __size));
1086 Z
1087 Z/* Default value of `__morecore'. */
1088 Zextern PTR EXFUN(__default_morecore, (ptrdiff_t __size));
1089 Z
1090 Z/* Nonzero if `malloc' has been called and done its initialization. */
1091 Zextern int __malloc_initialized;
1092 Z
1093 Z/* Hooks for debugging versions. */
1094 Zextern void EXFUN((*__free_hook), (PTR __ptr));
1095 Zextern PTR EXFUN((*__malloc_hook), (size_t __size));
1096 Zextern PTR EXFUN((*__realloc_hook), (PTR __ptr, size_t __size));
1097 Z
1098 Z/* Activate a standard collection of debugging hooks. */
1099 Zextern void EXFUN(mcheck, (void EXFUN((*__func), (void))));
1100 Z
1101 Z/* Statistics available to the user. */
1102 Zstruct mstats
1103 Z {
1104 Z size_t bytes_total; /* Total size of the heap. */
1105 Z size_t chunks_used; /* Chunks allocated by the user. */
1106 Z size_t bytes_used; /* Byte total of user-allocated chunks. */
1107 Z size_t chunks_free; /* Chunks in the free list. */
1108 Z size_t bytes_free; /* Byte total of chunks in the free list. */
1109 Z };
1110 Z
1111 Z/* Pick up the current statistics. */
1112 Zextern struct mstats EXFUN(mstats, (NOARGS));
1113 Z
1114 Z#endif /* malloc.h */
1115 STUNKYFLUFF
1116 set `sum malloc.h`
1117 if test 10676 != $1
1118 then
1119 echo malloc.h: Checksum error. Is: $1, should be: 10676.
1120 fi
1121 #
1122 #
1123 echo Extracting mcheck-init.c:
1124 sed 's/^Z//' >mcheck-init.c <<\STUNKYFLUFF
1125 Z/* Copyright (C) 1991 Free Software Foundation, Inc.
1126 ZThis file is part of the GNU C Library.
1127 Z
1128 ZThe GNU C Library is free software; you can redistribute it and/or
1129 Zmodify it under the terms of the GNU Library General Public License as
1130 Zpublished by the Free Software Foundation; either version 2 of the
1131 ZLicense, or (at your option) any later version.
1132 Z
1133 ZThe GNU C Library is distributed in the hope that it will be useful,
1134 Zbut WITHOUT ANY WARRANTY; without even the implied warranty of
1135 ZMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1136 ZLibrary General Public License for more details.
1137 Z
1138 ZYou should have received a copy of the GNU Library General Public
1139 ZLicense along with the GNU C Library; see the file COPYING.LIB. If
1140 Znot, write to the Free Software Foundation, Inc., 675 Mass Ave,
1141 ZCambridge, MA 02139, USA. */
1142 Z
1143 Z/* The object of this file should be installed as libmcheck.a,
1144 Z so one can do -lmcheck to turn on mcheck. */
1145 Z
1146 Z#ifdef __GNU_STAB__
1147 Z
1148 Z#include <ansidecl.h>
1149 Z#include <malloc.h>
1150 Z#include <gnu-stabs.h>
1151 Z
1152 Zstatic void
1153 ZDEFUN_VOID (turn_on_mcheck)
1154 Z{
1155 Z mcheck (NULL);
1156 Z}
1157 Z
1158 Ztext_set_element (__libc_subinit, turn_on_mcheck);
1159 Z
1160 Z#endif
1161 STUNKYFLUFF
1162 set `sum mcheck-init.c`
1163 if test 31836 != $1
1164 then
1165 echo mcheck-init.c: Checksum error. Is: $1, should be: 31836.
1166 fi
1167 #
1168 #
1169 echo Extracting mcheck.c:
1170 sed 's/^Z//' >mcheck.c <<\STUNKYFLUFF
1171 Z/* Standard debugging hooks for `malloc'.
1172 Z Copyright 1990, 1991 Free Software Foundation
1173 Z Written May 1989 by Mike Haertel.
1174 Z
1175 ZThe GNU C Library is free software; you can redistribute it and/or
1176 Zmodify it under the terms of the GNU Library General Public License as
1177 Zpublished by the Free Software Foundation; either version 2 of the
1178 ZLicense, or (at your option) any later version.
1179 Z
1180 ZThe GNU C Library is distributed in the hope that it will be useful,
1181 Zbut WITHOUT ANY WARRANTY; without even the implied warranty of
1182 ZMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1183 ZLibrary General Public License for more details.
1184 Z
1185 ZYou should have received a copy of the GNU Library General Public
1186 ZLicense along with the GNU C Library; see the file COPYING.LIB. If
1187 Znot, write to the Free Software Foundation, Inc., 675 Mass Ave,
1188 ZCambridge, MA 02139, USA.
1189 Z
1190 Z The author may be reached (Email) at the address mike@ai.mit.edu,
1191 Z or (US mail) as Mike Haertel c/o Free Software Foundation. */
1192 Z
1193 Z/* IGNORE(@ */
1194 Z#include <ansidecl.h>
1195 Z#include <stdlib.h>
1196 Z/* @) */
1197 Z
1198 Z#include <malloc.h>
1199 Z
1200 Z/* Old hook values. */
1201 Zstatic void EXFUN((*old_free_hook), (PTR ptr));
1202 Zstatic PTR EXFUN((*old_malloc_hook), (size_t size));
1203 Zstatic PTR EXFUN((*old_realloc_hook), (PTR ptr, size_t size));
1204 Z
1205 Z/* Function to call when something awful happens. */
1206 Zextern void EXFUN(abort, (NOARGS));
1207 Zstatic void EXFUN((*abortfunc), (NOARGS)) = (void EXFUN((*), (NOARGS))) abort;
1208 Z
1209 Z/* Arbitrary magical numbers. */
1210 Z#define MAGICWORD 0xfedabeeb
1211 Z#define MAGICBYTE ((char) 0xd7)
1212 Z
1213 Zstruct hdr
1214 Z {
1215 Z size_t size; /* Exact size requested by user. */
1216 Z unsigned long int magic; /* Magic number to check header integrity. */
1217 Z };
1218 Z
1219 Zstatic void
1220 ZDEFUN(checkhdr, (hdr), CONST struct hdr *hdr)
1221 Z{
1222 Z if (hdr->magic != MAGICWORD || ((char *) &hdr[1])[hdr->size] != MAGICBYTE)
1223 Z (*abortfunc)();
1224 Z}
1225 Z
1226 Zstatic void
1227 ZDEFUN(freehook, (ptr), PTR ptr)
1228 Z{
1229 Z struct hdr *hdr = ((struct hdr *) ptr) - 1;
1230 Z checkhdr(hdr);
1231 Z hdr->magic = 0;
1232 Z __free_hook = old_free_hook;
1233 Z free(hdr);
1234 Z __free_hook = freehook;
1235 Z}
1236 Z
1237 Zstatic PTR
1238 ZDEFUN(mallochook, (size), size_t size)
1239 Z{
1240 Z struct hdr *hdr;
1241 Z
1242 Z __malloc_hook = old_malloc_hook;
1243 Z hdr = (struct hdr *) malloc (sizeof(struct hdr) + size + 1);
1244 Z __malloc_hook = mallochook;
1245 Z if (hdr == NULL)
1246 Z return NULL;
1247 Z
1248 Z hdr->size = size;
1249 Z hdr->magic = MAGICWORD;
1250 Z ((char *) &hdr[1])[size] = MAGICBYTE;
1251 Z return (PTR) (hdr + 1);
1252 Z}
1253 Z
1254 Zstatic PTR
1255 ZDEFUN(reallochook, (ptr, size), PTR ptr AND size_t size)
1256 Z{
1257 Z struct hdr *hdr = ((struct hdr *) ptr) - 1;
1258 Z
1259 Z checkhdr(hdr);
1260 Z __free_hook = old_free_hook;
1261 Z __malloc_hook = old_malloc_hook;
1262 Z __realloc_hook = old_realloc_hook;
1263 Z hdr = (struct hdr *) realloc((PTR) hdr, sizeof(struct hdr) + size + 1);
1264 Z __free_hook = freehook;
1265 Z __malloc_hook = mallochook;
1266 Z __realloc_hook = reallochook;
1267 Z if (hdr == NULL)
1268 Z return NULL;
1269 Z
1270 Z hdr->size = size;
1271 Z ((char *) &hdr[1])[size] = MAGICBYTE;
1272 Z return (PTR) (hdr + 1);
1273 Z}
1274 Z
1275 Zvoid
1276 ZDEFUN(mcheck, (func), void EXFUN((*func), (void)))
1277 Z{
1278 Z static int mcheck_used = 0;
1279 Z
1280 Z if (func != NULL)
1281 Z abortfunc = func;
1282 Z
1283 Z /* These hooks may not be safely inserted if malloc is already in use. */
1284 Z if (!__malloc_initialized && !mcheck_used)
1285 Z {
1286 Z old_free_hook = __free_hook;
1287 Z __free_hook = freehook;
1288 Z old_malloc_hook = __malloc_hook;
1289 Z __malloc_hook = mallochook;
1290 Z old_realloc_hook = __realloc_hook;
1291 Z __realloc_hook = reallochook;
1292 Z mcheck_used = 1;
1293 Z }
1294 Z}
1295 STUNKYFLUFF
1296 set `sum mcheck.c`
1297 if test 15283 != $1
1298 then
1299 echo mcheck.c: Checksum error. Is: $1, should be: 15283.
1300 fi
1301 #
1302 #
1303 echo Extracting memalign.c:
1304 sed 's/^Z//' >memalign.c <<\STUNKYFLUFF
1305 Z/* Copyright (C) 1991 Free Software Foundation, Inc.
1306 ZThis file is part of the GNU C Library.
1307 Z
1308 ZThe GNU C Library is free software; you can redistribute it and/or
1309 Zmodify it under the terms of the GNU Library General Public License as
1310 Zpublished by the Free Software Foundation; either version 2 of the
1311 ZLicense, or (at your option) any later version.
1312 Z
1313 ZThe GNU C Library is distributed in the hope that it will be useful,
1314 Zbut WITHOUT ANY WARRANTY; without even the implied warranty of
1315 ZMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1316 ZLibrary General Public License for more details.
1317 Z
1318 ZYou should have received a copy of the GNU Library General Public
1319 ZLicense along with the GNU C Library; see the file COPYING.LIB. If
1320 Znot, write to the Free Software Foundation, Inc., 675 Mass Ave,
1321 ZCambridge, MA 02139, USA. */
1322 Z
1323 Z/* IGNORE(@ */
1324 Z#include <ansidecl.h>
1325 Z#include <stdlib.h>
1326 Z/* @) */
1327 Z
1328 Z#define _MALLOC_INTERNAL
1329 Z#include <malloc.h>
1330 Z
1331 ZPTR
1332 ZDEFUN(memalign, (alignment, size),
1333 Z size_t alignment AND size_t size)
1334 Z{
1335 Z PTR result;
1336 Z unsigned long int adj;
1337 Z
1338 Z size = ((size + alignment - 1) / alignment) * alignment;
1339 Z
1340 Z result = malloc (size);
1341 Z if (result == NULL)
1342 Z return NULL;
1343 Z adj = (unsigned long int) ((unsigned long int) ((char *) result -
1344 Z (char *) NULL)) % alignment;
1345 Z if (adj != 0)
1346 Z {
1347 Z struct alignlist *l;
1348 Z for (l = _aligned_blocks; l != NULL; l = l->next)
1349 Z if (l->aligned == NULL)
1350 Z /* This slot is free. Use it. */
1351 Z break;
1352 Z if (l == NULL)
1353 Z {
1354 Z l = (struct alignlist *) malloc (sizeof (struct alignlist));
1355 Z if (l == NULL)
1356 Z {
1357 Z free (result);
1358 Z return NULL;
1359 Z }
1360 Z }
1361 Z l->exact = result;
1362 Z result = l->aligned = (char *) result + alignment - adj;
1363 Z l->next = _aligned_blocks;
1364 Z _aligned_blocks = l;
1365 Z }
1366 Z
1367 Z return result;
1368 Z}
1369 STUNKYFLUFF
1370 set `sum memalign.c`
1371 if test 11691 != $1
1372 then
1373 echo memalign.c: Checksum error. Is: $1, should be: 11691.
1374 fi
1375 #
1376 #
1377 echo Extracting mstats.c:
1378 sed 's/^Z//' >mstats.c <<\STUNKYFLUFF
1379 Z/* Access the statistics maintained by `malloc'.
1380 Z Copyright 1990, 1991 Free Software Foundation
1381 Z Written May 1989 by Mike Haertel.
1382 Z
1383 ZThe GNU C Library is free software; you can redistribute it and/or
1384 Zmodify it under the terms of the GNU Library General Public License as
1385 Zpublished by the Free Software Foundation; either version 2 of the
1386 ZLicense, or (at your option) any later version.
1387 Z
1388 ZThe GNU C Library is distributed in the hope that it will be useful,
1389 Zbut WITHOUT ANY WARRANTY; without even the implied warranty of
1390 ZMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1391 ZLibrary General Public License for more details.
1392 Z
1393 ZYou should have received a copy of the GNU Library General Public
1394 ZLicense along with the GNU C Library; see the file COPYING.LIB. If
1395 Znot, write to the Free Software Foundation, Inc., 675 Mass Ave,
1396 ZCambridge, MA 02139, USA.
1397 Z
1398 Z The author may be reached (Email) at the address mike@ai.mit.edu,
1399 Z or (US mail) as Mike Haertel c/o Free Software Foundation. */
1400 Z
1401 Z/* IGNORE(@ */
1402 Z#include <ansidecl.h>
1403 Z/* @) */
1404 Z
1405 Z#define _MALLOC_INTERNAL
1406 Z#include <malloc.h>
1407 Z
1408 Zstruct mstats
1409 ZDEFUN_VOID(mstats)
1410 Z{
1411 Z struct mstats result;
1412 Z
1413 Z result.bytes_total = (char *) (*__morecore)(0) - _heapbase;
1414 Z result.chunks_used = _chunks_used;
1415 Z result.bytes_used = _bytes_used;
1416 Z result.chunks_free = _chunks_free;
1417 Z result.bytes_free = _bytes_free;
1418 Z return result;
1419 Z}
1420 STUNKYFLUFF
1421 set `sum mstats.c`
1422 if test 51328 != $1
1423 then
1424 echo mstats.c: Checksum error. Is: $1, should be: 51328.
1425 fi
1426 #
1427 #
1428 echo Extracting mtrace.awk:
1429 sed 's/^Z//' >mtrace.awk <<\STUNKYFLUFF
1430 Z#
1431 Z# Awk program to analyze mtrace.c output.
1432 Z#
1433 Z$1 == "+" { if (allocated[$2] != "")
1434 Z print "+", $2, "Alloc", NR, "duplicate:", allocated[$2];
1435 Z else
1436 Z allocated[$2] = $3;
1437 Z }
1438 Z$1 == "-" { if (allocated[$2] != "") {
1439 Z allocated[$2] = "";
1440 Z if (allocated[$2] != "")
1441 Z print "DELETE FAILED", $2, allocated[$2];
1442 Z } else
1443 Z print "-", $2, "Free", NR, "was never alloc'd";
1444 Z }
1445 Z$1 == "<" { if (allocated[$2] != "")
1446 Z allocated[$2] = "";
1447 Z else
1448 Z print "-", $2, "Realloc", NR, "was never alloc'd";
1449 Z }
1450 Z$1 == ">" { if (allocated[$2] != "")
1451 Z print "+", $2, "Realloc", NR, "duplicate:", allocated[$2];
1452 Z else
1453 Z allocated[$2] = $3;
1454 Z }
1455 Z
1456 Z# Ignore "= Start"
1457 Z$1 == "=" { }
1458 Z# Ignore failed realloc attempts for now
1459 Z$1 == "!" { }
1460 Z
1461 Z
1462 ZEND { for (x in allocated)
1463 Z if (allocated[x] != "")
1464 Z print "+", x, allocated[x];
1465 Z }
1466 STUNKYFLUFF
1467 set `sum mtrace.awk`
1468 if test 57510 != $1
1469 then
1470 echo mtrace.awk: Checksum error. Is: $1, should be: 57510.
1471 fi
1472 #
1473 #
1474 echo Extracting mtrace.c:
1475 sed 's/^Z//' >mtrace.c <<\STUNKYFLUFF
1476 Z/* More debugging hooks for `malloc'.
1477 Z Copyright 1991 Free Software Foundation
1478 Z Written April 2, 1991 by John Gilmore of Cygnus Support
1479 Z Based on mcheck.c by Mike Haertel.
1480 Z
1481 ZThis program is free software; you can redistribute it and/or modify
1482 Zit under the terms of the GNU General Public License as published by
1483 Zthe Free Software Foundation; either version 2 of the License, or
1484 Z(at your option) any later version.
1485 Z
1486 ZThis program is distributed in the hope that it will be useful,
1487 Zbut WITHOUT ANY WARRANTY; without even the implied warranty of
1488 ZMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1489 ZGNU General Public License for more details.
1490 Z
1491 ZYou should have received a copy of the GNU General Public License
1492 Zalong with this program; if not, write to the Free Software
1493 ZFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
1494 Z
1495 Z/* IGNORE(@ */
1496 Z#include <ansidecl.h>
1497 Z#include <stdlib.h>
1498 Z/* @) */
1499 Z
1500 Z#include <stdio.h>
1501 Z#include <malloc.h>
1502 Z
1503 Z#ifndef __GNU_LIBRARY__
1504 Zextern char *getenv ();
1505 Z#endif
1506 Z
1507 Zstatic FILE *mallstream;
1508 Zstatic char mallenv[] = "MALLOC_TRACE";
1509 Zstatic char mallbuf[BUFSIZ]; /* Buffer for the output. */
1510 Z
1511 Z/* Address to breakpoint on accesses to... */
1512 ZPTR mallwatch;
1513 Z
1514 Z/* Old hook values. */
1515 Zstatic void EXFUN((*old_free_hook), (PTR ptr));
1516 Zstatic PTR EXFUN((*old_malloc_hook), (size_t size));
1517 Zstatic PTR EXFUN((*old_realloc_hook), (PTR ptr, size_t size));
1518 Z
1519 Z/* This function is called when the block being alloc'd, realloc'd, or
1520 Z freed has an address matching the variable "mallwatch". In a debugger,
1521 Z set "mallwatch" to the address of interest, then put a breakpoint on
1522 Z tr_break. */
1523 Z
1524 Zvoid
1525 ZDEFUN_VOID(tr_break)
1526 Z{
1527 Z}
1528 Z
1529 Zstatic void
1530 ZDEFUN(tr_freehook, (ptr), PTR ptr)
1531 Z{
1532 Z fprintf(mallstream, "- %p\n", ptr); /* Be sure to print it first. */
1533 Z if (ptr == mallwatch)
1534 Z tr_break ();
1535 Z __free_hook = old_free_hook;
1536 Z free (ptr);
1537 Z __free_hook = tr_freehook;
1538 Z}
1539 Z
1540 Zstatic PTR
1541 ZDEFUN(tr_mallochook, (size), size_t size)
1542 Z{
1543 Z PTR hdr;
1544 Z
1545 Z __malloc_hook = old_malloc_hook;
1546 Z hdr = (PTR) malloc (size);
1547 Z __malloc_hook = tr_mallochook;
1548 Z
1549 Z /* We could be printing a NULL here; that's OK. */
1550 Z fprintf (mallstream, "+ %p %x\n", hdr, size);
1551 Z
1552 Z if (hdr == mallwatch)
1553 Z tr_break ();
1554 Z
1555 Z return hdr;
1556 Z}
1557 Z
1558 Zstatic PTR
1559 ZDEFUN(tr_reallochook, (ptr, size), PTR ptr AND size_t size)
1560 Z{
1561 Z PTR hdr;
1562 Z
1563 Z if (ptr == mallwatch)
1564 Z tr_break ();
1565 Z
1566 Z __free_hook = old_free_hook;
1567 Z __malloc_hook = old_malloc_hook;
1568 Z __realloc_hook = old_realloc_hook;
1569 Z hdr = (PTR) realloc (ptr, size);
1570 Z __free_hook = tr_freehook;
1571 Z __malloc_hook = tr_mallochook;
1572 Z __realloc_hook = tr_reallochook;
1573 Z if (hdr == NULL)
1574 Z /* Failed realloc. */
1575 Z fprintf (mallstream, "! %p %x\n", ptr, size);
1576 Z else
1577 Z fprintf (mallstream, "< %p\n> %p %x\n", ptr, hdr, size);
1578 Z
1579 Z if (hdr == mallwatch)
1580 Z tr_break ();
1581 Z
1582 Z return hdr;
1583 Z}
1584 Z
1585 Z/* We enable tracing if either the environment variable MALLOC_TRACE
1586 Z is set, or if the variable mallwatch has been patched to an address
1587 Z that the debugging user wants us to stop on. When patching mallwatch,
1588 Z don't forget to set a breakpoint on tr_break! */
1589 Z
1590 Zvoid
1591 ZDEFUN_VOID(mtrace)
1592 Z{
1593 Z char *mallfile;
1594 Z
1595 Z mallfile = getenv (mallenv);
1596 Z if (mallfile != NULL || mallwatch != NULL)
1597 Z {
1598 Z mallstream = fopen (mallfile != NULL ? mallfile : "/dev/null", "w");
1599 Z if (mallstream != NULL)
1600 Z {
1601 Z /* Be sure it doesn't malloc its buffer! */
1602 Z setbuf (mallstream, mallbuf);
1603 Z fprintf (mallstream, "= Start\n");
1604 Z old_free_hook = __free_hook;
1605 Z __free_hook = tr_freehook;
1606 Z old_malloc_hook = __malloc_hook;
1607 Z __malloc_hook = tr_mallochook;
1608 Z old_realloc_hook = __realloc_hook;
1609 Z __realloc_hook = tr_reallochook;
1610 Z }
1611 Z }
1612 Z}
1613 STUNKYFLUFF
1614 set `sum mtrace.c`
1615 if test 38600 != $1
1616 then
1617 echo mtrace.c: Checksum error. Is: $1, should be: 38600.
1618 fi
1619 #
1620 #
1621 echo Extracting realloc.c:
1622 sed 's/^Z//' >realloc.c <<\STUNKYFLUFF
1623 Z/* Change the size of a block allocated by `malloc'.
1624 Z Copyright 1990, 1991 Free Software Foundation
1625 Z Written May 1989 by Mike Haertel.
1626 Z
1627 ZThe GNU C Library is free software; you can redistribute it and/or
1628 Zmodify it under the terms of the GNU Library General Public License as
1629 Zpublished by the Free Software Foundation; either version 2 of the
1630 ZLicense, or (at your option) any later version.
1631 Z
1632 ZThe GNU C Library is distributed in the hope that it will be useful,
1633 Zbut WITHOUT ANY WARRANTY; without even the implied warranty of
1634 ZMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1635 ZLibrary General Public License for more details.
1636 Z
1637 ZYou should have received a copy of the GNU Library General Public
1638 ZLicense along with the GNU C Library; see the file COPYING.LIB. If
1639 Znot, write to the Free Software Foundation, Inc., 675 Mass Ave,
1640 ZCambridge, MA 02139, USA.
1641 Z
1642 Z The author may be reached (Email) at the address mike@ai.mit.edu,
1643 Z or (US mail) as Mike Haertel c/o Free Software Foundation. */
1644 Z
1645 Z/* IGNORE(@ */
1646 Z#include <ansidecl.h>
1647 Z#include <stdlib.h>
1648 Z/* @) */
1649 Z
1650 Z#if defined(__GNU_LIBRARY__) || defined(STDC_HEADERS) || defined(USG)
1651 Z#include <string.h>
1652 Z#else
1653 Z#define memcpy(d, s, n) bcopy((s), (d), (n))
1654 Z#endif
1655 Z
1656 Z#define _MALLOC_INTERNAL
1657 Z#include <malloc.h>
1658 Z
1659 Z#define MIN(A, B) ((A) < (B) ? (A) : (B))
1660 Z
1661 Z/* Debugging hook for realloc. */
1662 ZPTR EXFUN((*__realloc_hook), (PTR __ptr, size_t __size));
1663 Z
1664 Z/* Resize the given region to the new size, returning a pointer
1665 Z to the (possibly moved) region. This is optimized for speed;
1666 Z some benchmarks seem to indicate that greater compactness is
1667 Z achieved by unconditionally allocating and copying to a
1668 Z new region. This module has incestuous knowledge of the
1669 Z internals of both free and malloc. */
1670 ZPTR
1671 ZDEFUN(realloc, (ptr, size), PTR ptr AND size_t size)
1672 Z{
1673 Z PTR result;
1674 Z int type;
1675 Z size_t block, blocks, oldlimit;
1676 Z
1677 Z if (size == 0)
1678 Z {
1679 Z free(ptr);
1680 Z return malloc(0);
1681 Z }
1682 Z else if (ptr == NULL)
1683 Z return malloc(size);
1684 Z
1685 Z if (__realloc_hook != NULL)
1686 Z return (*__realloc_hook)(ptr, size);
1687 Z
1688 Z block = BLOCK(ptr);
1689 Z
1690 Z type = _heapinfo[block].busy.type;
1691 Z switch (type)
1692 Z {
1693 Z case 0:
1694 Z /* Maybe reallocate a large block to a small fragment. */
1695 Z if (size <= BLOCKSIZE / 2)
1696 Z {
1697 Z result = malloc(size);
1698 Z if (result != NULL)
1699 Z {
1700 Z memcpy(result, ptr, size);
1701 Z free(ptr);
1702 Z return result;
1703 Z }
1704 Z }
1705 Z
1706 Z /* The new size is a large allocation as well;
1707 Z see if we can hold it in place. */
1708 Z blocks = BLOCKIFY(size);
1709 Z if (blocks < _heapinfo[block].busy.info.size)
1710 Z {
1711 Z /* The new size is smaller; return
1712 Z excess memory to the free list. */
1713 Z _heapinfo[block + blocks].busy.type = 0;
1714 Z _heapinfo[block + blocks].busy.info.size
1715 Z = _heapinfo[block].busy.info.size - blocks;
1716 Z _heapinfo[block].busy.info.size = blocks;
1717 Z free(ADDRESS(block + blocks));
1718 Z result = ptr;
1719 Z }
1720 Z else if (blocks == _heapinfo[block].busy.info.size)
1721 Z /* No size change necessary. */
1722 Z result = ptr;
1723 Z else
1724 Z {
1725 Z /* Won't fit, so allocate a new region that will.
1726 Z Free the old region first in case there is sufficient
1727 Z adjacent free space to grow without moving. */
1728 Z blocks = _heapinfo[block].busy.info.size;
1729 Z /* Prevent free from actually returning memory to the system. */
1730 Z oldlimit = _heaplimit;
1731 Z _heaplimit = 0;
1732 Z free(ptr);
1733 Z _heaplimit = oldlimit;
1734 Z result = malloc(size);
1735 Z if (result == NULL)
1736 Z {
1737 Z (void) malloc(blocks * BLOCKSIZE);
1738 Z return NULL;
1739 Z }
1740 Z if (ptr != result)
1741 Z memmove(result, ptr, blocks * BLOCKSIZE);
1742 Z }
1743 Z break;
1744 Z
1745 Z default:
1746 Z /* Old size is a fragment; type is logarithm
1747 Z to base two of the fragment size. */
1748 Z if (size > (size_t) (1 << (type - 1)) && size <= (size_t) (1 << type))
1749 Z /* The new size is the same kind of fragment. */
1750 Z result = ptr;
1751 Z else
1752 Z {
1753 Z /* The new size is different; allocate a new space,
1754 Z and copy the lesser of the new size and the old. */
1755 Z result = malloc(size);
1756 Z if (result == NULL)
1757 Z return NULL;
1758 Z memcpy(result, ptr, MIN(size, (size_t) 1 << type));
1759 Z free(ptr);
1760 Z }
1761 Z break;
1762 Z }
1763 Z
1764 Z return result;
1765 Z}
1766 STUNKYFLUFF
1767 set `sum realloc.c`
1768 if test 3391 != $1
1769 then
1770 echo realloc.c: Checksum error. Is: $1, should be: 3391.
1771 fi
1772 #
1773 #
1774 echo Extracting valloc.c:
1775 sed 's/^Z//' >valloc.c <<\STUNKYFLUFF
1776 Z/* Allocate memory on a page boundary.
1777 Z Copyright (C) 1991 Free Software Foundation, Inc.
1778 Z
1779 ZThe GNU C Library is free software; you can redistribute it and/or
1780 Zmodify it under the terms of the GNU Library General Public License as
1781 Zpublished by the Free Software Foundation; either version 2 of the
1782 ZLicense, or (at your option) any later version.
1783 Z
1784 ZThe GNU C Library is distributed in the hope that it will be useful,
1785 Zbut WITHOUT ANY WARRANTY; without even the implied warranty of
1786 ZMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1787 ZLibrary General Public License for more details.
1788 Z
1789 ZYou should have received a copy of the GNU Library General Public
1790 ZLicense along with the GNU C Library; see the file COPYING.LIB. If
1791 Znot, write to the Free Software Foundation, Inc., 675 Mass Ave,
1792 ZCambridge, MA 02139, USA. */
1793 Z
1794 Z/* IGNORE(@ */
1795 Z#include <ansidecl.h>
1796 Z#include <stdlib.h>
1797 Z/* @) */
1798 Z
1799 Z#include <malloc.h>
1800 Z
1801 Z#ifdef __GNU_LIBRARY__
1802 Zextern size_t EXFUN(__getpagesize, (NOARGS));
1803 Z#else
1804 Z#ifndef USG
1805 Zextern size_t EXFUN(getpagesize, (NOARGS));
1806 Z#define __getpagesize() getpagesize()
1807 Z#else
1808 Z#include <sys/param.h>
1809 Z#ifdef EXEC_PAGESIZE
1810 Z#define __getpagesize() EXEC_PAGESIZE
1811 Z#else /* No EXEC_PAGESIZE. */
1812 Z#ifdef NBPG
1813 Z#ifndef CLSIZE
1814 Z#define CLSIZE 1
1815 Z#endif /* No CLSIZE. */
1816 Z#define __getpagesize() (NBPG * CLSIZE)
1817 Z#else /* No NBPG. */
1818 Z#define __getpagesize() NBPC
1819 Z#endif /* NBPG. */
1820 Z#endif /* EXEC_PAGESIZE. */
1821 Z#endif /* USG. */
1822 Z#endif
1823 Z
1824 Zstatic size_t pagesize;
1825 Z
1826 ZPTR
1827 ZDEFUN(valloc, (size), size_t size)
1828 Z{
1829 Z if (pagesize == 0)
1830 Z pagesize = __getpagesize();
1831 Z
1832 Z return memalign (pagesize, size);
1833 Z}
1834 STUNKYFLUFF
1835 set `sum valloc.c`
1836 if test 63930 != $1
1837 then
1838 echo valloc.c: Checksum error. Is: $1, should be: 63930.
1839 fi
1840 echo ALL DONE BUNKY!
1841 exit 0
This page took 0.072089 seconds and 4 git commands to generate.