* parse-scan.y (interface_declaration): Call
[official-gcc.git] / boehm-gc / misc.c
blob72c87b0802c0961ebb5479e05ccd3d382c2dcd3c
1 /*
2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
5 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
8 * Permission is hereby granted to use or copy this program
9 * for any purpose, provided the above notices are retained on all copies.
10 * Permission to modify the code and to distribute modified code is granted,
11 * provided the above notices are retained, and a notice that the code was
12 * modified is included with the above copyright notice.
14 /* Boehm, July 31, 1995 5:02 pm PDT */
17 #include <stdio.h>
18 #include <signal.h>
20 #define I_HIDE_POINTERS /* To make GC_call_with_alloc_lock visible */
21 #include "gc_priv.h"
23 #ifdef SOLARIS_THREADS
24 # include <sys/syscall.h>
25 #endif
26 #ifdef MSWIN32
27 # include <windows.h>
28 #endif
30 # ifdef THREADS
31 # ifdef PCR
32 # include "il/PCR_IL.h"
33 PCR_Th_ML GC_allocate_ml;
34 # else
35 # ifdef SRC_M3
36 /* Critical section counter is defined in the M3 runtime */
37 /* That's all we use. */
38 # else
39 # ifdef SOLARIS_THREADS
40 mutex_t GC_allocate_ml; /* Implicitly initialized. */
41 # else
42 # ifdef WIN32_THREADS
43 GC_API CRITICAL_SECTION GC_allocate_ml;
44 # else
45 # if defined(IRIX_THREADS) || defined(LINUX_THREADS)
46 # ifdef UNDEFINED
47 pthread_mutex_t GC_allocate_ml = PTHREAD_MUTEX_INITIALIZER;
48 # endif
49 pthread_t GC_lock_holder = NO_THREAD;
50 # else
51 # if defined(QUICK_THREADS)
52 /* Nothing. */
53 # else
54 --> declare allocator lock here
55 # endif
56 # endif
57 # endif
58 # endif
59 # endif
60 # endif
61 # endif
63 #ifdef ECOS
64 #undef STACKBASE
65 #endif
67 GC_FAR struct _GC_arrays GC_arrays /* = { 0 } */;
70 GC_bool GC_debugging_started = FALSE;
71 /* defined here so we don't have to load debug_malloc.o */
73 void (*GC_check_heap)() = (void (*)())0;
75 void (*GC_start_call_back)() = (void (*)())0;
77 ptr_t GC_stackbottom = 0;
79 GC_bool GC_dont_gc = 0;
81 GC_bool GC_quiet = 0;
83 /*ARGSUSED*/
84 GC_PTR GC_default_oom_fn GC_PROTO((size_t bytes_requested))
86 return(0);
89 GC_PTR (*GC_oom_fn) GC_PROTO((size_t bytes_requested)) = GC_default_oom_fn;
91 extern signed_word GC_mem_found;
93 # ifdef MERGE_SIZES
94 /* Set things up so that GC_size_map[i] >= words(i), */
95 /* but not too much bigger */
96 /* and so that size_map contains relatively few distinct entries */
97 /* This is stolen from Russ Atkinson's Cedar quantization */
98 /* alogrithm (but we precompute it). */
101 void GC_init_size_map()
103 register unsigned i;
105 /* Map size 0 to 1. This avoids problems at lower levels. */
106 GC_size_map[0] = 1;
107 /* One word objects don't have to be 2 word aligned. */
108 for (i = 1; i < sizeof(word); i++) {
109 GC_size_map[i] = 1;
111 GC_size_map[sizeof(word)] = ROUNDED_UP_WORDS(sizeof(word));
112 for (i = sizeof(word) + 1; i <= 8 * sizeof(word); i++) {
113 # ifdef ALIGN_DOUBLE
114 GC_size_map[i] = (ROUNDED_UP_WORDS(i) + 1) & (~1);
115 # else
116 GC_size_map[i] = ROUNDED_UP_WORDS(i);
117 # endif
119 for (i = 8*sizeof(word) + 1; i <= 16 * sizeof(word); i++) {
120 GC_size_map[i] = (ROUNDED_UP_WORDS(i) + 1) & (~1);
122 /* We leave the rest of the array to be filled in on demand. */
125 /* Fill in additional entries in GC_size_map, including the ith one */
126 /* We assume the ith entry is currently 0. */
127 /* Note that a filled in section of the array ending at n always */
128 /* has length at least n/4. */
129 void GC_extend_size_map(i)
130 word i;
132 word orig_word_sz = ROUNDED_UP_WORDS(i);
133 word word_sz = orig_word_sz;
134 register word byte_sz = WORDS_TO_BYTES(word_sz);
135 /* The size we try to preserve. */
136 /* Close to to i, unless this would */
137 /* introduce too many distinct sizes. */
138 word smaller_than_i = byte_sz - (byte_sz >> 3);
139 word much_smaller_than_i = byte_sz - (byte_sz >> 2);
140 register word low_limit; /* The lowest indexed entry we */
141 /* initialize. */
142 register word j;
144 if (GC_size_map[smaller_than_i] == 0) {
145 low_limit = much_smaller_than_i;
146 while (GC_size_map[low_limit] != 0) low_limit++;
147 } else {
148 low_limit = smaller_than_i + 1;
149 while (GC_size_map[low_limit] != 0) low_limit++;
150 word_sz = ROUNDED_UP_WORDS(low_limit);
151 word_sz += word_sz >> 3;
152 if (word_sz < orig_word_sz) word_sz = orig_word_sz;
154 # ifdef ALIGN_DOUBLE
155 word_sz += 1;
156 word_sz &= ~1;
157 # endif
158 if (word_sz > MAXOBJSZ) {
159 word_sz = MAXOBJSZ;
161 /* If we can fit the same number of larger objects in a block, */
162 /* do so. */
164 size_t number_of_objs = BODY_SZ/word_sz;
165 word_sz = BODY_SZ/number_of_objs;
166 # ifdef ALIGN_DOUBLE
167 word_sz &= ~1;
168 # endif
170 byte_sz = WORDS_TO_BYTES(word_sz);
171 # ifdef ADD_BYTE_AT_END
172 /* We need one extra byte; don't fill in GC_size_map[byte_sz] */
173 byte_sz--;
174 # endif
176 for (j = low_limit; j <= byte_sz; j++) GC_size_map[j] = word_sz;
178 # endif
182 * The following is a gross hack to deal with a problem that can occur
183 * on machines that are sloppy about stack frame sizes, notably SPARC.
184 * Bogus pointers may be written to the stack and not cleared for
185 * a LONG time, because they always fall into holes in stack frames
186 * that are not written. We partially address this by clearing
187 * sections of the stack whenever we get control.
189 word GC_stack_last_cleared = 0; /* GC_no when we last did this */
190 # ifdef THREADS
191 # define CLEAR_SIZE 2048
192 # else
193 # define CLEAR_SIZE 213
194 # endif
195 # define DEGRADE_RATE 50
197 word GC_min_sp; /* Coolest stack pointer value from which we've */
198 /* already cleared the stack. */
200 # ifdef STACK_GROWS_DOWN
201 # define COOLER_THAN >
202 # define HOTTER_THAN <
203 # define MAKE_COOLER(x,y) if ((word)(x)+(y) > (word)(x)) {(x) += (y);} \
204 else {(x) = (word)ONES;}
205 # define MAKE_HOTTER(x,y) (x) -= (y)
206 # else
207 # define COOLER_THAN <
208 # define HOTTER_THAN >
209 # define MAKE_COOLER(x,y) if ((word)(x)-(y) < (word)(x)) {(x) -= (y);} else {(x) = 0;}
210 # define MAKE_HOTTER(x,y) (x) += (y)
211 # endif
213 word GC_high_water;
214 /* "hottest" stack pointer value we have seen */
215 /* recently. Degrades over time. */
217 word GC_words_allocd_at_reset;
219 #if defined(ASM_CLEAR_CODE) && !defined(THREADS)
220 extern ptr_t GC_clear_stack_inner();
221 #endif
223 #if !defined(ASM_CLEAR_CODE) && !defined(THREADS)
224 /* Clear the stack up to about limit. Return arg. */
225 /*ARGSUSED*/
226 ptr_t GC_clear_stack_inner(arg, limit)
227 ptr_t arg;
228 word limit;
230 word dummy[CLEAR_SIZE];
232 BZERO(dummy, CLEAR_SIZE*sizeof(word));
233 if ((word)(dummy) COOLER_THAN limit) {
234 (void) GC_clear_stack_inner(arg, limit);
236 /* Make sure the recursive call is not a tail call, and the bzero */
237 /* call is not recognized as dead code. */
238 GC_noop1((word)dummy);
239 return(arg);
241 #endif
243 /* Clear some of the inaccessible part of the stack. Returns its */
244 /* argument, so it can be used in a tail call position, hence clearing */
245 /* another frame. */
246 ptr_t GC_clear_stack(arg)
247 ptr_t arg;
249 register word sp = (word)GC_approx_sp(); /* Hotter than actual sp */
250 # ifdef THREADS
251 word dummy[CLEAR_SIZE];
252 # else
253 register word limit;
254 # endif
256 # define SLOP 400
257 /* Extra bytes we clear every time. This clears our own */
258 /* activation record, and should cause more frequent */
259 /* clearing near the cold end of the stack, a good thing. */
260 # define GC_SLOP 4000
261 /* We make GC_high_water this much hotter than we really saw */
262 /* saw it, to cover for GC noise etc. above our current frame. */
263 # define CLEAR_THRESHOLD 100000
264 /* We restart the clearing process after this many bytes of */
265 /* allocation. Otherwise very heavily recursive programs */
266 /* with sparse stacks may result in heaps that grow almost */
267 /* without bounds. As the heap gets larger, collection */
268 /* frequency decreases, thus clearing frequency would decrease, */
269 /* thus more junk remains accessible, thus the heap gets */
270 /* larger ... */
271 # ifdef THREADS
272 BZERO(dummy, CLEAR_SIZE*sizeof(word));
273 # else
274 if (GC_gc_no > GC_stack_last_cleared) {
275 /* Start things over, so we clear the entire stack again */
276 if (GC_stack_last_cleared == 0) GC_high_water = (word) GC_stackbottom;
277 GC_min_sp = GC_high_water;
278 GC_stack_last_cleared = GC_gc_no;
279 GC_words_allocd_at_reset = GC_words_allocd;
281 /* Adjust GC_high_water */
282 MAKE_COOLER(GC_high_water, WORDS_TO_BYTES(DEGRADE_RATE) + GC_SLOP);
283 if (sp HOTTER_THAN GC_high_water) {
284 GC_high_water = sp;
286 MAKE_HOTTER(GC_high_water, GC_SLOP);
287 limit = GC_min_sp;
288 MAKE_HOTTER(limit, SLOP);
289 if (sp COOLER_THAN limit) {
290 limit &= ~0xf; /* Make it sufficiently aligned for assembly */
291 /* implementations of GC_clear_stack_inner. */
292 GC_min_sp = sp;
293 return(GC_clear_stack_inner(arg, limit));
294 } else if (WORDS_TO_BYTES(GC_words_allocd - GC_words_allocd_at_reset)
295 > CLEAR_THRESHOLD) {
296 /* Restart clearing process, but limit how much clearing we do. */
297 GC_min_sp = sp;
298 MAKE_HOTTER(GC_min_sp, CLEAR_THRESHOLD/4);
299 if (GC_min_sp HOTTER_THAN GC_high_water) GC_min_sp = GC_high_water;
300 GC_words_allocd_at_reset = GC_words_allocd;
302 # endif
303 return(arg);
307 /* Return a pointer to the base address of p, given a pointer to a */
308 /* an address within an object. Return 0 o.w. */
309 # ifdef __STDC__
310 GC_PTR GC_base(GC_PTR p)
311 # else
312 GC_PTR GC_base(p)
313 GC_PTR p;
314 # endif
316 register word r;
317 register struct hblk *h;
318 register bottom_index *bi;
319 register hdr *candidate_hdr;
320 register word limit;
322 r = (word)p;
323 if (!GC_is_initialized) return 0;
324 h = HBLKPTR(r);
325 GET_BI(r, bi);
326 candidate_hdr = HDR_FROM_BI(bi, r);
327 if (candidate_hdr == 0) return(0);
328 /* If it's a pointer to the middle of a large object, move it */
329 /* to the beginning. */
330 while (IS_FORWARDING_ADDR_OR_NIL(candidate_hdr)) {
331 h = FORWARDED_ADDR(h,candidate_hdr);
332 r = (word)h + HDR_BYTES;
333 candidate_hdr = HDR(h);
335 if (candidate_hdr -> hb_map == GC_invalid_map) return(0);
336 /* Make sure r points to the beginning of the object */
337 r &= ~(WORDS_TO_BYTES(1) - 1);
339 register int offset = (char *)r - (char *)(HBLKPTR(r));
340 register signed_word sz = candidate_hdr -> hb_sz;
342 # ifdef ALL_INTERIOR_POINTERS
343 register map_entry_type map_entry;
345 map_entry = MAP_ENTRY((candidate_hdr -> hb_map), offset);
346 if (map_entry == OBJ_INVALID) {
347 return(0);
349 r -= WORDS_TO_BYTES(map_entry);
350 limit = r + WORDS_TO_BYTES(sz);
351 # else
352 register int correction;
354 offset = BYTES_TO_WORDS(offset - HDR_BYTES);
355 correction = offset % sz;
356 r -= (WORDS_TO_BYTES(correction));
357 limit = r + WORDS_TO_BYTES(sz);
358 if (limit > (word)(h + 1)
359 && sz <= BYTES_TO_WORDS(HBLKSIZE) - HDR_WORDS) {
360 return(0);
362 # endif
363 if ((word)p >= limit) return(0);
365 return((GC_PTR)r);
369 /* Return the size of an object, given a pointer to its base. */
370 /* (For small obects this also happens to work from interior pointers, */
371 /* but that shouldn't be relied upon.) */
372 # ifdef __STDC__
373 size_t GC_size(GC_PTR p)
374 # else
375 size_t GC_size(p)
376 GC_PTR p;
377 # endif
379 register int sz;
380 register hdr * hhdr = HDR(p);
382 sz = WORDS_TO_BYTES(hhdr -> hb_sz);
383 if (sz < 0) {
384 return(-sz);
385 } else {
386 return(sz);
390 size_t GC_get_heap_size GC_PROTO(())
392 return ((size_t) GC_heapsize);
395 size_t GC_get_bytes_since_gc GC_PROTO(())
397 return ((size_t) WORDS_TO_BYTES(GC_words_allocd));
400 GC_bool GC_is_initialized = FALSE;
402 #if defined(SOLARIS_THREADS) || defined(IRIX_THREADS)
403 extern void GC_thr_init();
404 #endif
406 void GC_init()
408 DCL_LOCK_STATE;
410 DISABLE_SIGNALS();
411 LOCK();
412 GC_init_inner();
413 UNLOCK();
414 ENABLE_SIGNALS();
418 #ifdef MSWIN32
419 extern void GC_init_win32();
420 #endif
422 extern void GC_setpagesize();
424 void GC_init_inner()
426 # ifndef THREADS
427 word dummy;
428 # endif
430 if (GC_is_initialized) return;
431 GC_setpagesize();
432 GC_exclude_static_roots(beginGC_arrays, endGC_arrays);
433 # ifdef MSWIN32
434 GC_init_win32();
435 # endif
436 # if defined(LINUX) && defined(POWERPC)
437 GC_init_linuxppc();
438 # endif
439 # ifdef SOLARIS_THREADS
440 GC_thr_init();
441 /* We need dirty bits in order to find live stack sections. */
442 GC_dirty_init();
443 # endif
444 # if defined(IRIX_THREADS) || defined(LINUX_THREADS)
445 GC_thr_init();
446 # endif
447 # if !defined(THREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) \
448 || defined(IRIX_THREADS) || defined(LINUX_THREADS) \
449 || defined (QUICK_THREADS)
450 if (GC_stackbottom == 0) {
451 GC_stackbottom = GC_get_stack_base();
453 # endif
454 if (sizeof (ptr_t) != sizeof(word)) {
455 ABORT("sizeof (ptr_t) != sizeof(word)\n");
457 if (sizeof (signed_word) != sizeof(word)) {
458 ABORT("sizeof (signed_word) != sizeof(word)\n");
460 if (sizeof (struct hblk) != HBLKSIZE) {
461 ABORT("sizeof (struct hblk) != HBLKSIZE\n");
463 # ifndef THREADS
464 # if defined(STACK_GROWS_UP) && defined(STACK_GROWS_DOWN)
465 ABORT(
466 "Only one of STACK_GROWS_UP and STACK_GROWS_DOWN should be defd\n");
467 # endif
468 # if !defined(STACK_GROWS_UP) && !defined(STACK_GROWS_DOWN)
469 ABORT(
470 "One of STACK_GROWS_UP and STACK_GROWS_DOWN should be defd\n");
471 # endif
472 # ifdef STACK_GROWS_DOWN
473 if ((word)(&dummy) > (word)GC_stackbottom) {
474 GC_err_printf0(
475 "STACK_GROWS_DOWN is defd, but stack appears to grow up\n");
476 # ifndef UTS4 /* Compiler bug workaround */
477 GC_err_printf2("sp = 0x%lx, GC_stackbottom = 0x%lx\n",
478 (unsigned long) (&dummy),
479 (unsigned long) GC_stackbottom);
480 # endif
481 ABORT("stack direction 3\n");
483 # else
484 if ((word)(&dummy) < (word)GC_stackbottom) {
485 GC_err_printf0(
486 "STACK_GROWS_UP is defd, but stack appears to grow down\n");
487 GC_err_printf2("sp = 0x%lx, GC_stackbottom = 0x%lx\n",
488 (unsigned long) (&dummy),
489 (unsigned long) GC_stackbottom);
490 ABORT("stack direction 4");
492 # endif
493 # endif
494 # if !defined(_AUX_SOURCE) || defined(__GNUC__)
495 if ((word)(-1) < (word)0) {
496 GC_err_printf0("The type word should be an unsigned integer type\n");
497 GC_err_printf0("It appears to be signed\n");
498 ABORT("word");
500 # endif
501 if ((signed_word)(-1) >= (signed_word)0) {
502 GC_err_printf0(
503 "The type signed_word should be a signed integer type\n");
504 GC_err_printf0("It appears to be unsigned\n");
505 ABORT("signed_word");
508 /* Add initial guess of root sets. Do this first, since sbrk(0) */
509 /* might be used. */
510 GC_register_data_segments();
511 GC_init_headers();
512 GC_bl_init();
513 GC_mark_init();
514 if (!GC_expand_hp_inner((word)MINHINCR)) {
515 GC_err_printf0("Can't start up: not enough memory\n");
516 EXIT();
518 /* Preallocate large object map. It's otherwise inconvenient to */
519 /* deal with failure. */
520 if (!GC_add_map_entry((word)0)) {
521 GC_err_printf0("Can't start up: not enough memory\n");
522 EXIT();
524 GC_register_displacement_inner(0L);
525 # ifdef MERGE_SIZES
526 GC_init_size_map();
527 # endif
528 # ifdef PCR
529 if (PCR_IL_Lock(PCR_Bool_false, PCR_allSigsBlocked, PCR_waitForever)
530 != PCR_ERes_okay) {
531 ABORT("Can't lock load state\n");
532 } else if (PCR_IL_Unlock() != PCR_ERes_okay) {
533 ABORT("Can't unlock load state\n");
535 PCR_IL_Unlock();
536 GC_pcr_install();
537 # endif
538 /* Get black list set up */
539 GC_gcollect_inner();
540 # ifdef STUBBORN_ALLOC
541 GC_stubborn_init();
542 # endif
543 GC_is_initialized = TRUE;
544 /* Convince lint that some things are used */
545 # ifdef LINT
547 extern char * GC_copyright[];
548 extern int GC_read();
549 extern void GC_register_finalizer_no_order();
551 GC_noop(GC_copyright, GC_find_header,
552 GC_push_one, GC_call_with_alloc_lock, GC_read,
553 GC_dont_expand,
554 # ifndef NO_DEBUGGING
555 GC_dump,
556 # endif
557 GC_register_finalizer_no_order);
559 # endif
562 void GC_enable_incremental GC_PROTO(())
564 DCL_LOCK_STATE;
566 # ifndef FIND_LEAK
567 DISABLE_SIGNALS();
568 LOCK();
569 if (GC_incremental) goto out;
570 GC_setpagesize();
571 # ifdef MSWIN32
573 extern GC_bool GC_is_win32s();
575 /* VirtualProtect is not functional under win32s. */
576 if (GC_is_win32s()) goto out;
578 # endif /* MSWIN32 */
579 # ifndef SOLARIS_THREADS
580 GC_dirty_init();
581 # endif
582 if (!GC_is_initialized) {
583 GC_init_inner();
585 if (GC_dont_gc) {
586 /* Can't easily do it. */
587 UNLOCK();
588 ENABLE_SIGNALS();
589 return;
591 if (GC_words_allocd > 0) {
592 /* There may be unmarked reachable objects */
593 GC_gcollect_inner();
594 } /* else we're OK in assuming everything's */
595 /* clean since nothing can point to an */
596 /* unmarked object. */
597 GC_read_dirty();
598 GC_incremental = TRUE;
599 out:
600 UNLOCK();
601 ENABLE_SIGNALS();
602 # endif
606 #ifdef MSWIN32
607 # define LOG_FILE "gc.log"
609 HANDLE GC_stdout = 0, GC_stderr;
610 int GC_tmp;
611 DWORD GC_junk;
613 void GC_set_files()
615 if (!GC_stdout) {
616 GC_stdout = CreateFile(LOG_FILE, GENERIC_WRITE,
617 FILE_SHARE_READ | FILE_SHARE_WRITE,
618 NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH,
619 NULL);
620 if (INVALID_HANDLE_VALUE == GC_stdout) ABORT("Open of log file failed");
622 if (GC_stderr == 0) {
623 GC_stderr = GC_stdout;
627 #endif
629 #if defined(OS2) || defined(MACOS)
630 FILE * GC_stdout = NULL;
631 FILE * GC_stderr = NULL;
632 int GC_tmp; /* Should really be local ... */
634 void GC_set_files()
636 if (GC_stdout == NULL) {
637 GC_stdout = stdout;
639 if (GC_stderr == NULL) {
640 GC_stderr = stderr;
643 #endif
645 #if !defined(OS2) && !defined(MACOS) && !defined(MSWIN32)
646 int GC_stdout = 1;
647 int GC_stderr = 2;
648 # if !defined(AMIGA)
649 # include <unistd.h>
650 # endif
651 #endif
653 #if !defined(MSWIN32) && !defined(OS2) && !defined(MACOS) && !defined(ECOS)
654 int GC_write(fd, buf, len)
655 int fd;
656 char *buf;
657 size_t len;
659 register int bytes_written = 0;
660 register int result;
662 while (bytes_written < len) {
663 # ifdef SOLARIS_THREADS
664 result = syscall(SYS_write, fd, buf + bytes_written,
665 len - bytes_written);
666 # else
667 result = write(fd, buf + bytes_written, len - bytes_written);
668 # endif
669 if (-1 == result) return(result);
670 bytes_written += result;
672 return(bytes_written);
674 #endif /* UN*X */
676 #if defined(ECOS)
677 int GC_write(fd, buf, len)
679 _Jv_diag_write (buf, len);
680 return len;
682 #endif
685 #ifdef MSWIN32
686 # define WRITE(f, buf, len) (GC_set_files(), \
687 GC_tmp = WriteFile((f), (buf), \
688 (len), &GC_junk, NULL),\
689 (GC_tmp? 1 : -1))
690 #else
691 # if defined(OS2) || defined(MACOS)
692 # define WRITE(f, buf, len) (GC_set_files(), \
693 GC_tmp = fwrite((buf), 1, (len), (f)), \
694 fflush(f), GC_tmp)
695 # else
696 # define WRITE(f, buf, len) GC_write((f), (buf), (len))
697 # endif
698 #endif
700 /* A version of printf that is unlikely to call malloc, and is thus safer */
701 /* to call from the collector in case malloc has been bound to GC_malloc. */
702 /* Assumes that no more than 1023 characters are written at once. */
703 /* Assumes that all arguments have been converted to something of the */
704 /* same size as long, and that the format conversions expect something */
705 /* of that size. */
706 void GC_printf(format, a, b, c, d, e, f)
707 char * format;
708 long a, b, c, d, e, f;
710 char buf[1025];
712 if (GC_quiet) return;
713 buf[1024] = 0x15;
714 (void) sprintf(buf, format, a, b, c, d, e, f);
715 if (buf[1024] != 0x15) ABORT("GC_printf clobbered stack");
716 if (WRITE(GC_stdout, buf, strlen(buf)) < 0) ABORT("write to stdout failed");
719 void GC_err_printf(format, a, b, c, d, e, f)
720 char * format;
721 long a, b, c, d, e, f;
723 char buf[1025];
725 buf[1024] = 0x15;
726 (void) sprintf(buf, format, a, b, c, d, e, f);
727 if (buf[1024] != 0x15) ABORT("GC_err_printf clobbered stack");
728 if (WRITE(GC_stderr, buf, strlen(buf)) < 0) ABORT("write to stderr failed");
731 void GC_err_puts(s)
732 char *s;
734 if (WRITE(GC_stderr, s, strlen(s)) < 0) ABORT("write to stderr failed");
737 # if defined(__STDC__) || defined(__cplusplus)
738 void GC_default_warn_proc(char *msg, GC_word arg)
739 # else
740 void GC_default_warn_proc(msg, arg)
741 char *msg;
742 GC_word arg;
743 # endif
745 GC_err_printf1(msg, (unsigned long)arg);
748 GC_warn_proc GC_current_warn_proc = GC_default_warn_proc;
750 # if defined(__STDC__) || defined(__cplusplus)
751 GC_warn_proc GC_set_warn_proc(GC_warn_proc p)
752 # else
753 GC_warn_proc GC_set_warn_proc(p)
754 GC_warn_proc p;
755 # endif
757 GC_warn_proc result;
759 LOCK();
760 result = GC_current_warn_proc;
761 GC_current_warn_proc = p;
762 UNLOCK();
763 return(result);
767 #ifndef PCR
768 void GC_abort(msg)
769 char * msg;
771 GC_err_printf1("%s\n", msg);
772 (void) abort();
774 #endif
776 #ifdef NEED_CALLINFO
778 void GC_print_callers (info)
779 struct callinfo info[NFRAMES];
781 register int i,j;
783 # if NFRAMES == 1
784 GC_err_printf0("\tCaller at allocation:\n");
785 # else
786 GC_err_printf0("\tCall chain at allocation:\n");
787 # endif
788 for (i = 0; i < NFRAMES; i++) {
789 if (info[i].ci_pc == 0) break;
790 # if NARGS > 0
791 GC_err_printf0("\t\targs: ");
792 for (j = 0; j < NARGS; j++) {
793 if (j != 0) GC_err_printf0(", ");
794 GC_err_printf2("%d (0x%X)", ~(info[i].ci_arg[j]),
795 ~(info[i].ci_arg[j]));
797 GC_err_printf0("\n");
798 # endif
799 GC_err_printf1("\t\t##PC##= 0x%X\n", info[i].ci_pc);
803 #endif /* SAVE_CALL_CHAIN */
805 # ifdef SRC_M3
806 void GC_enable()
808 GC_dont_gc--;
811 void GC_disable()
813 GC_dont_gc++;
815 # endif
817 #if !defined(NO_DEBUGGING)
819 void GC_dump()
821 GC_printf0("***Static roots:\n");
822 GC_print_static_roots();
823 GC_printf0("\n***Heap sections:\n");
824 GC_print_heap_sects();
825 GC_printf0("\n***Free blocks:\n");
826 GC_print_hblkfreelist();
827 GC_printf0("\n***Blocks in use:\n");
828 GC_print_block_list();
831 # endif /* NO_DEBUGGING */