PR c++/26571
[official-gcc.git] / boehm-gc / include / gc.h
blob5ba1f4becfee9ab284c07b68d90307e8c33a5cb9
1 /*
2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
4 * Copyright 1996-1999 by Silicon Graphics. All rights reserved.
5 * Copyright 1999 by Hewlett-Packard Company. All rights reserved.
7 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 * Permission is hereby granted to use or copy this program
11 * for any purpose, provided the above notices are retained on all copies.
12 * Permission to modify the code and to distribute modified code is granted,
13 * provided the above notices are retained, and a notice that the code was
14 * modified is included with the above copyright notice.
18 * Note that this defines a large number of tuning hooks, which can
19 * safely be ignored in nearly all cases. For normal use it suffices
20 * to call only GC_MALLOC and perhaps GC_REALLOC.
21 * For better performance, also look at GC_MALLOC_ATOMIC, and
22 * GC_enable_incremental. If you need an action to be performed
23 * immediately before an object is collected, look at GC_register_finalizer.
24 * If you are using Solaris threads, look at the end of this file.
25 * Everything else is best ignored unless you encounter performance
26 * problems.
29 #ifndef _GC_H
31 # define _GC_H
33 /*
34 * As this header includes gc_config.h, preprocessor conflicts can occur with
35 * clients that include their own autoconf headers. The following #undef's
36 * work around some likely conflicts.
39 # ifdef PACKAGE_NAME
40 # undef PACKAGE_NAME
41 # endif
42 # ifdef PACKAGE_BUGREPORT
43 # undef PACKAGE_BUGREPORT
44 # endif
45 # ifdef PACKAGE_STRING
46 # undef PACKAGE_STRING
47 # endif
48 # ifdef PACKAGE_TARNAME
49 # undef PACKAGE_TARNAME
50 # endif
51 # ifdef PACKAGE_VERSION
52 # undef PACKAGE_VERSION
53 # endif
55 # include <gc_config.h>
56 # include "gc_config_macros.h"
58 # if defined(__STDC__) || defined(__cplusplus) || defined(_AIX)
59 # define GC_PROTO(args) args
60 typedef void * GC_PTR;
61 # define GC_CONST const
62 # else
63 # define GC_PROTO(args) ()
64 typedef char * GC_PTR;
65 # define GC_CONST
66 # endif
68 # ifdef __cplusplus
69 extern "C" {
70 # endif
72 /* Define word and signed_word to be unsigned and signed types of the */
73 /* size as char * or void *. There seems to be no way to do this */
74 /* even semi-portably. The following is probably no better/worse */
75 /* than almost anything else. */
76 /* The ANSI standard suggests that size_t and ptr_diff_t might be */
77 /* better choices. But those had incorrect definitions on some older */
78 /* systems. Notably "typedef int size_t" is WRONG. */
79 #ifndef _WIN64
80 typedef unsigned long GC_word;
81 typedef long GC_signed_word;
82 #else
83 /* Win64 isn't really supported yet, but this is the first step. And */
84 /* it might cause error messages to show up in more plausible places. */
85 /* This needs basetsd.h, which is included by windows.h. */
86 typedef ULONG_PTR GC_word;
87 typedef LONG_PTR GC_word;
88 #endif
90 /* Public read-only variables */
92 GC_API GC_word GC_gc_no;/* Counter incremented per collection. */
93 /* Includes empty GCs at startup. */
95 GC_API int GC_parallel; /* GC is parallelized for performance on */
96 /* multiprocessors. Currently set only */
97 /* implicitly if collector is built with */
98 /* -DPARALLEL_MARK and if either: */
99 /* Env variable GC_NPROC is set to > 1, or */
100 /* GC_NPROC is not set and this is an MP. */
101 /* If GC_parallel is set, incremental */
102 /* collection is only partially functional, */
103 /* and may not be desirable. */
106 /* Public R/W variables */
108 GC_API GC_PTR (*GC_oom_fn) GC_PROTO((size_t bytes_requested));
109 /* When there is insufficient memory to satisfy */
110 /* an allocation request, we return */
111 /* (*GC_oom_fn)(). By default this just */
112 /* returns 0. */
113 /* If it returns, it must return 0 or a valid */
114 /* pointer to a previously allocated heap */
115 /* object. */
117 GC_API int GC_find_leak;
118 /* Do not actually garbage collect, but simply */
119 /* report inaccessible memory that was not */
120 /* deallocated with GC_free. Initial value */
121 /* is determined by FIND_LEAK macro. */
123 GC_API int GC_all_interior_pointers;
124 /* Arrange for pointers to object interiors to */
125 /* be recognized as valid. May not be changed */
126 /* after GC initialization. */
127 /* Initial value is determined by */
128 /* -DALL_INTERIOR_POINTERS. */
129 /* Unless DONT_ADD_BYTE_AT_END is defined, this */
130 /* also affects whether sizes are increased by */
131 /* at least a byte to allow "off the end" */
132 /* pointer recognition. */
133 /* MUST BE 0 or 1. */
135 GC_API int GC_quiet; /* Disable statistics output. Only matters if */
136 /* collector has been compiled with statistics */
137 /* enabled. This involves a performance cost, */
138 /* and is thus not the default. */
140 GC_API int GC_finalize_on_demand;
141 /* If nonzero, finalizers will only be run in */
142 /* response to an explicit GC_invoke_finalizers */
143 /* call. The default is determined by whether */
144 /* the FINALIZE_ON_DEMAND macro is defined */
145 /* when the collector is built. */
147 GC_API int GC_java_finalization;
148 /* Mark objects reachable from finalizable */
149 /* objects in a separate postpass. This makes */
150 /* it a bit safer to use non-topologically- */
151 /* ordered finalization. Default value is */
152 /* determined by JAVA_FINALIZATION macro. */
154 GC_API void (* GC_finalizer_notifier) GC_PROTO((void));
155 /* Invoked by the collector when there are */
156 /* objects to be finalized. Invoked at most */
157 /* once per GC cycle. Never invoked unless */
158 /* GC_finalize_on_demand is set. */
159 /* Typically this will notify a finalization */
160 /* thread, which will call GC_invoke_finalizers */
161 /* in response. */
163 GC_API int GC_dont_gc; /* != 0 ==> Dont collect. In versions 6.2a1+, */
164 /* this overrides explicit GC_gcollect() calls. */
165 /* Used as a counter, so that nested enabling */
166 /* and disabling work correctly. Should */
167 /* normally be updated with GC_enable() and */
168 /* GC_disable() calls. */
169 /* Direct assignment to GC_dont_gc is */
170 /* deprecated. */
172 GC_API int GC_dont_expand;
173 /* Dont expand heap unless explicitly requested */
174 /* or forced to. */
176 GC_API int GC_use_entire_heap;
177 /* Causes the nonincremental collector to use the */
178 /* entire heap before collecting. This was the only */
179 /* option for GC versions < 5.0. This sometimes */
180 /* results in more large block fragmentation, since */
181 /* very larg blocks will tend to get broken up */
182 /* during each GC cycle. It is likely to result in a */
183 /* larger working set, but lower collection */
184 /* frequencies, and hence fewer instructions executed */
185 /* in the collector. */
187 GC_API int GC_full_freq; /* Number of partial collections between */
188 /* full collections. Matters only if */
189 /* GC_incremental is set. */
190 /* Full collections are also triggered if */
191 /* the collector detects a substantial */
192 /* increase in the number of in-use heap */
193 /* blocks. Values in the tens are now */
194 /* perfectly reasonable, unlike for */
195 /* earlier GC versions. */
197 GC_API GC_word GC_non_gc_bytes;
198 /* Bytes not considered candidates for collection. */
199 /* Used only to control scheduling of collections. */
200 /* Updated by GC_malloc_uncollectable and GC_free. */
201 /* Wizards only. */
203 GC_API int GC_no_dls;
204 /* Don't register dynamic library data segments. */
205 /* Wizards only. Should be used only if the */
206 /* application explicitly registers all roots. */
207 /* In Microsoft Windows environments, this will */
208 /* usually also prevent registration of the */
209 /* main data segment as part of the root set. */
211 GC_API GC_word GC_free_space_divisor;
212 /* We try to make sure that we allocate at */
213 /* least N/GC_free_space_divisor bytes between */
214 /* collections, where N is the heap size plus */
215 /* a rough estimate of the root set size. */
216 /* Initially, GC_free_space_divisor = 3. */
217 /* Increasing its value will use less space */
218 /* but more collection time. Decreasing it */
219 /* will appreciably decrease collection time */
220 /* at the expense of space. */
221 /* GC_free_space_divisor = 1 will effectively */
222 /* disable collections. */
224 GC_API GC_word GC_max_retries;
225 /* The maximum number of GCs attempted before */
226 /* reporting out of memory after heap */
227 /* expansion fails. Initially 0. */
230 GC_API char *GC_stackbottom; /* Cool end of user stack. */
231 /* May be set in the client prior to */
232 /* calling any GC_ routines. This */
233 /* avoids some overhead, and */
234 /* potentially some signals that can */
235 /* confuse debuggers. Otherwise the */
236 /* collector attempts to set it */
237 /* automatically. */
238 /* For multithreaded code, this is the */
239 /* cold end of the stack for the */
240 /* primordial thread. */
242 GC_API int GC_dont_precollect; /* Don't collect as part of */
243 /* initialization. Should be set only */
244 /* if the client wants a chance to */
245 /* manually initialize the root set */
246 /* before the first collection. */
247 /* Interferes with blacklisting. */
248 /* Wizards only. */
250 /* Public procedures */
252 /* Initialize the collector. This is only required when using thread-local
253 * allocation, since unlike the regular allocation routines, GC_local_malloc
254 * is not self-initializing. If you use GC_local_malloc you should arrange
255 * to call this somehow (e.g. from a constructor) before doing any allocation.
257 GC_API void GC_init GC_PROTO((void));
259 GC_API unsigned long GC_time_limit;
260 /* If incremental collection is enabled, */
261 /* We try to terminate collections */
262 /* after this many milliseconds. Not a */
263 /* hard time bound. Setting this to */
264 /* GC_TIME_UNLIMITED will essentially */
265 /* disable incremental collection while */
266 /* leaving generational collection */
267 /* enabled. */
268 # define GC_TIME_UNLIMITED 999999
269 /* Setting GC_time_limit to this value */
270 /* will disable the "pause time exceeded"*/
271 /* tests. */
273 /* Public procedures */
275 /* Initialize the collector. This is only required when using thread-local
276 * allocation, since unlike the regular allocation routines, GC_local_malloc
277 * is not self-initializing. If you use GC_local_malloc you should arrange
278 * to call this somehow (e.g. from a constructor) before doing any allocation.
279 * For win32 threads, it needs to be called explicitly.
281 GC_API void GC_init GC_PROTO((void));
284 * general purpose allocation routines, with roughly malloc calling conv.
285 * The atomic versions promise that no relevant pointers are contained
286 * in the object. The nonatomic versions guarantee that the new object
287 * is cleared. GC_malloc_stubborn promises that no changes to the object
288 * will occur after GC_end_stubborn_change has been called on the
289 * result of GC_malloc_stubborn. GC_malloc_uncollectable allocates an object
290 * that is scanned for pointers to collectable objects, but is not itself
291 * collectable. The object is scanned even if it does not appear to
292 * be reachable. GC_malloc_uncollectable and GC_free called on the resulting
293 * object implicitly update GC_non_gc_bytes appropriately.
295 * Note that the GC_malloc_stubborn support is stubbed out by default
296 * starting in 6.0. GC_malloc_stubborn is an alias for GC_malloc unless
297 * the collector is built with STUBBORN_ALLOC defined.
299 GC_API GC_PTR GC_malloc GC_PROTO((size_t size_in_bytes));
300 GC_API GC_PTR GC_malloc_atomic GC_PROTO((size_t size_in_bytes));
301 GC_API GC_PTR GC_malloc_uncollectable GC_PROTO((size_t size_in_bytes));
302 GC_API GC_PTR GC_malloc_stubborn GC_PROTO((size_t size_in_bytes));
304 /* The following is only defined if the library has been suitably */
305 /* compiled: */
306 GC_API GC_PTR GC_malloc_atomic_uncollectable GC_PROTO((size_t size_in_bytes));
308 /* Explicitly deallocate an object. Dangerous if used incorrectly. */
309 /* Requires a pointer to the base of an object. */
310 /* If the argument is stubborn, it should not be changeable when freed. */
311 /* An object should not be enable for finalization when it is */
312 /* explicitly deallocated. */
313 /* GC_free(0) is a no-op, as required by ANSI C for free. */
314 GC_API void GC_free GC_PROTO((GC_PTR object_addr));
317 * Stubborn objects may be changed only if the collector is explicitly informed.
318 * The collector is implicitly informed of coming change when such
319 * an object is first allocated. The following routines inform the
320 * collector that an object will no longer be changed, or that it will
321 * once again be changed. Only nonNIL pointer stores into the object
322 * are considered to be changes. The argument to GC_end_stubborn_change
323 * must be exacly the value returned by GC_malloc_stubborn or passed to
324 * GC_change_stubborn. (In the second case it may be an interior pointer
325 * within 512 bytes of the beginning of the objects.)
326 * There is a performance penalty for allowing more than
327 * one stubborn object to be changed at once, but it is acceptable to
328 * do so. The same applies to dropping stubborn objects that are still
329 * changeable.
331 GC_API void GC_change_stubborn GC_PROTO((GC_PTR));
332 GC_API void GC_end_stubborn_change GC_PROTO((GC_PTR));
334 /* Return a pointer to the base (lowest address) of an object given */
335 /* a pointer to a location within the object. */
336 /* I.e. map an interior pointer to the corresponding bas pointer. */
337 /* Note that with debugging allocation, this returns a pointer to the */
338 /* actual base of the object, i.e. the debug information, not to */
339 /* the base of the user object. */
340 /* Return 0 if displaced_pointer doesn't point to within a valid */
341 /* object. */
342 /* Note that a deallocated object in the garbage collected heap */
343 /* may be considered valid, even if it has been deallocated with */
344 /* GC_free. */
345 GC_API GC_PTR GC_base GC_PROTO((GC_PTR displaced_pointer));
347 /* Given a pointer to the base of an object, return its size in bytes. */
348 /* The returned size may be slightly larger than what was originally */
349 /* requested. */
350 GC_API size_t GC_size GC_PROTO((GC_PTR object_addr));
352 /* For compatibility with C library. This is occasionally faster than */
353 /* a malloc followed by a bcopy. But if you rely on that, either here */
354 /* or with the standard C library, your code is broken. In my */
355 /* opinion, it shouldn't have been invented, but now we're stuck. -HB */
356 /* The resulting object has the same kind as the original. */
357 /* If the argument is stubborn, the result will have changes enabled. */
358 /* It is an error to have changes enabled for the original object. */
359 /* Follows ANSI comventions for NULL old_object. */
360 GC_API GC_PTR GC_realloc
361 GC_PROTO((GC_PTR old_object, size_t new_size_in_bytes));
363 /* Explicitly increase the heap size. */
364 /* Returns 0 on failure, 1 on success. */
365 GC_API int GC_expand_hp GC_PROTO((size_t number_of_bytes));
367 /* Limit the heap size to n bytes. Useful when you're debugging, */
368 /* especially on systems that don't handle running out of memory well. */
369 /* n == 0 ==> unbounded. This is the default. */
370 GC_API void GC_set_max_heap_size GC_PROTO((GC_word n));
372 /* Inform the collector that a certain section of statically allocated */
373 /* memory contains no pointers to garbage collected memory. Thus it */
374 /* need not be scanned. This is sometimes important if the application */
375 /* maps large read/write files into the address space, which could be */
376 /* mistaken for dynamic library data segments on some systems. */
377 GC_API void GC_exclude_static_roots GC_PROTO((GC_PTR start, GC_PTR finish));
379 /* Clear the set of root segments. Wizards only. */
380 GC_API void GC_clear_roots GC_PROTO((void));
382 /* Add a root segment. Wizards only. */
383 GC_API void GC_add_roots GC_PROTO((char * low_address,
384 char * high_address_plus_1));
386 /* Remove a root segment. Wizards only. */
387 GC_API void GC_remove_roots GC_PROTO((char * low_address,
388 char * high_address_plus_1));
390 /* Add a displacement to the set of those considered valid by the */
391 /* collector. GC_register_displacement(n) means that if p was returned */
392 /* by GC_malloc, then (char *)p + n will be considered to be a valid */
393 /* pointer to p. N must be small and less than the size of p. */
394 /* (All pointers to the interior of objects from the stack are */
395 /* considered valid in any case. This applies to heap objects and */
396 /* static data.) */
397 /* Preferably, this should be called before any other GC procedures. */
398 /* Calling it later adds to the probability of excess memory */
399 /* retention. */
400 /* This is a no-op if the collector has recognition of */
401 /* arbitrary interior pointers enabled, which is now the default. */
402 GC_API void GC_register_displacement GC_PROTO((GC_word n));
404 /* The following version should be used if any debugging allocation is */
405 /* being done. */
406 GC_API void GC_debug_register_displacement GC_PROTO((GC_word n));
408 /* Explicitly trigger a full, world-stop collection. */
409 GC_API void GC_gcollect GC_PROTO((void));
411 /* Trigger a full world-stopped collection. Abort the collection if */
412 /* and when stop_func returns a nonzero value. Stop_func will be */
413 /* called frequently, and should be reasonably fast. This works even */
414 /* if virtual dirty bits, and hence incremental collection is not */
415 /* available for this architecture. Collections can be aborted faster */
416 /* than normal pause times for incremental collection. However, */
417 /* aborted collections do no useful work; the next collection needs */
418 /* to start from the beginning. */
419 /* Return 0 if the collection was aborted, 1 if it succeeded. */
420 typedef int (* GC_stop_func) GC_PROTO((void));
421 GC_API int GC_try_to_collect GC_PROTO((GC_stop_func stop_func));
423 /* Return the number of bytes in the heap. Excludes collector private */
424 /* data structures. Includes empty blocks and fragmentation loss. */
425 /* Includes some pages that were allocated but never written. */
426 GC_API size_t GC_get_heap_size GC_PROTO((void));
428 /* Return a lower bound on the number of free bytes in the heap. */
429 GC_API size_t GC_get_free_bytes GC_PROTO((void));
431 /* Return the number of bytes allocated since the last collection. */
432 GC_API size_t GC_get_bytes_since_gc GC_PROTO((void));
434 /* Return the total number of bytes allocated in this process. */
435 /* Never decreases, except due to wrapping. */
436 GC_API size_t GC_get_total_bytes GC_PROTO((void));
438 /* Disable garbage collection. Even GC_gcollect calls will be */
439 /* ineffective. */
440 GC_API void GC_disable GC_PROTO((void));
442 /* Reenable garbage collection. GC_disable() and GC_enable() calls */
443 /* nest. Garbage collection is enabled if the number of calls to both */
444 /* both functions is equal. */
445 GC_API void GC_enable GC_PROTO((void));
447 /* Enable incremental/generational collection. */
448 /* Not advisable unless dirty bits are */
449 /* available or most heap objects are */
450 /* pointerfree(atomic) or immutable. */
451 /* Don't use in leak finding mode. */
452 /* Ignored if GC_dont_gc is true. */
453 /* Only the generational piece of this is */
454 /* functional if GC_parallel is TRUE */
455 /* or if GC_time_limit is GC_TIME_UNLIMITED. */
456 /* Causes GC_local_gcj_malloc() to revert to */
457 /* locked allocation. Must be called */
458 /* before any GC_local_gcj_malloc() calls. */
459 GC_API void GC_enable_incremental GC_PROTO((void));
461 /* Does incremental mode write-protect pages? Returns zero or */
462 /* more of the following, or'ed together: */
463 #define GC_PROTECTS_POINTER_HEAP 1 /* May protect non-atomic objs. */
464 #define GC_PROTECTS_PTRFREE_HEAP 2
465 #define GC_PROTECTS_STATIC_DATA 4 /* Curently never. */
466 #define GC_PROTECTS_STACK 8 /* Probably impractical. */
468 #define GC_PROTECTS_NONE 0
469 GC_API int GC_incremental_protection_needs GC_PROTO((void));
471 /* Perform some garbage collection work, if appropriate. */
472 /* Return 0 if there is no more work to be done. */
473 /* Typically performs an amount of work corresponding roughly */
474 /* to marking from one page. May do more work if further */
475 /* progress requires it, e.g. if incremental collection is */
476 /* disabled. It is reasonable to call this in a wait loop */
477 /* until it returns 0. */
478 GC_API int GC_collect_a_little GC_PROTO((void));
480 /* Allocate an object of size lb bytes. The client guarantees that */
481 /* as long as the object is live, it will be referenced by a pointer */
482 /* that points to somewhere within the first 256 bytes of the object. */
483 /* (This should normally be declared volatile to prevent the compiler */
484 /* from invalidating this assertion.) This routine is only useful */
485 /* if a large array is being allocated. It reduces the chance of */
486 /* accidentally retaining such an array as a result of scanning an */
487 /* integer that happens to be an address inside the array. (Actually, */
488 /* it reduces the chance of the allocator not finding space for such */
489 /* an array, since it will try hard to avoid introducing such a false */
490 /* reference.) On a SunOS 4.X or MS Windows system this is recommended */
491 /* for arrays likely to be larger than 100K or so. For other systems, */
492 /* or if the collector is not configured to recognize all interior */
493 /* pointers, the threshold is normally much higher. */
494 GC_API GC_PTR GC_malloc_ignore_off_page GC_PROTO((size_t lb));
495 GC_API GC_PTR GC_malloc_atomic_ignore_off_page GC_PROTO((size_t lb));
497 #if defined(__sgi) && !defined(__GNUC__) && _COMPILER_VERSION >= 720
498 # define GC_ADD_CALLER
499 # define GC_RETURN_ADDR (GC_word)__return_address
500 #endif
502 #ifdef __linux__
503 # include <features.h>
504 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1 || __GLIBC__ > 2) \
505 && !defined(__ia64__)
506 # ifndef GC_HAVE_BUILTIN_BACKTRACE
507 # define GC_HAVE_BUILTIN_BACKTRACE
508 # endif
509 # endif
510 # if defined(__i386__) || defined(__x86_64__)
511 # define GC_CAN_SAVE_CALL_STACKS
512 # endif
513 #endif
515 #if defined(GC_HAVE_BUILTIN_BACKTRACE) && !defined(GC_CAN_SAVE_CALL_STACKS)
516 # define GC_CAN_SAVE_CALL_STACKS
517 #endif
519 #if defined(__sparc__)
520 # define GC_CAN_SAVE_CALL_STACKS
521 #endif
523 /* If we're on an a platform on which we can't save call stacks, but */
524 /* gcc is normally used, we go ahead and define GC_ADD_CALLER. */
525 /* We make this decision independent of whether gcc is actually being */
526 /* used, in order to keep the interface consistent, and allow mixing */
527 /* of compilers. */
528 /* This may also be desirable if it is possible but expensive to */
529 /* retrieve the call chain. */
530 #if (defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) \
531 || defined(__FreeBSD__)) & !defined(GC_CAN_SAVE_CALL_STACKS)
532 # define GC_ADD_CALLER
533 # if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
534 /* gcc knows how to retrieve return address, but we don't know */
535 /* how to generate call stacks. */
536 # define GC_RETURN_ADDR (GC_word)__builtin_return_address(0)
537 # else
538 /* Just pass 0 for gcc compatibility. */
539 # define GC_RETURN_ADDR 0
540 # endif
541 #endif
543 #ifdef GC_ADD_CALLER
544 # define GC_EXTRAS GC_RETURN_ADDR, __FILE__, __LINE__
545 # define GC_EXTRA_PARAMS GC_word ra, GC_CONST char * s, int i
546 #else
547 # define GC_EXTRAS __FILE__, __LINE__
548 # define GC_EXTRA_PARAMS GC_CONST char * s, int i
549 #endif
551 /* Debugging (annotated) allocation. GC_gcollect will check */
552 /* objects allocated in this way for overwrites, etc. */
553 GC_API GC_PTR GC_debug_malloc
554 GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
555 GC_API GC_PTR GC_debug_malloc_atomic
556 GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
557 GC_API GC_PTR GC_debug_malloc_uncollectable
558 GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
559 GC_API GC_PTR GC_debug_malloc_stubborn
560 GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
561 GC_API GC_PTR GC_debug_malloc_ignore_off_page
562 GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
563 GC_API GC_PTR GC_debug_malloc_atomic_ignore_off_page
564 GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
565 GC_API void GC_debug_free GC_PROTO((GC_PTR object_addr));
566 GC_API GC_PTR GC_debug_realloc
567 GC_PROTO((GC_PTR old_object, size_t new_size_in_bytes,
568 GC_EXTRA_PARAMS));
569 GC_API void GC_debug_change_stubborn GC_PROTO((GC_PTR));
570 GC_API void GC_debug_end_stubborn_change GC_PROTO((GC_PTR));
572 /* Routines that allocate objects with debug information (like the */
573 /* above), but just fill in dummy file and line number information. */
574 /* Thus they can serve as drop-in malloc/realloc replacements. This */
575 /* can be useful for two reasons: */
576 /* 1) It allows the collector to be built with DBG_HDRS_ALL defined */
577 /* even if some allocation calls come from 3rd party libraries */
578 /* that can't be recompiled. */
579 /* 2) On some platforms, the file and line information is redundant, */
580 /* since it can be reconstructed from a stack trace. On such */
581 /* platforms it may be more convenient not to recompile, e.g. for */
582 /* leak detection. This can be accomplished by instructing the */
583 /* linker to replace malloc/realloc with these. */
584 GC_API GC_PTR GC_debug_malloc_replacement GC_PROTO((size_t size_in_bytes));
585 GC_API GC_PTR GC_debug_realloc_replacement
586 GC_PROTO((GC_PTR object_addr, size_t size_in_bytes));
588 # ifdef GC_DEBUG
589 # define GC_MALLOC(sz) GC_debug_malloc(sz, GC_EXTRAS)
590 # define GC_MALLOC_ATOMIC(sz) GC_debug_malloc_atomic(sz, GC_EXTRAS)
591 # define GC_MALLOC_UNCOLLECTABLE(sz) \
592 GC_debug_malloc_uncollectable(sz, GC_EXTRAS)
593 # define GC_MALLOC_IGNORE_OFF_PAGE(sz) \
594 GC_debug_malloc_ignore_off_page(sz, GC_EXTRAS)
595 # define GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(sz) \
596 GC_debug_malloc_atomic_ignore_off_page(sz, GC_EXTRAS)
597 # define GC_REALLOC(old, sz) GC_debug_realloc(old, sz, GC_EXTRAS)
598 # define GC_FREE(p) GC_debug_free(p)
599 # define GC_REGISTER_FINALIZER(p, f, d, of, od) \
600 GC_debug_register_finalizer(p, f, d, of, od)
601 # define GC_REGISTER_FINALIZER_IGNORE_SELF(p, f, d, of, od) \
602 GC_debug_register_finalizer_ignore_self(p, f, d, of, od)
603 # define GC_REGISTER_FINALIZER_NO_ORDER(p, f, d, of, od) \
604 GC_debug_register_finalizer_no_order(p, f, d, of, od)
605 # define GC_MALLOC_STUBBORN(sz) GC_debug_malloc_stubborn(sz, GC_EXTRAS);
606 # define GC_CHANGE_STUBBORN(p) GC_debug_change_stubborn(p)
607 # define GC_END_STUBBORN_CHANGE(p) GC_debug_end_stubborn_change(p)
608 # define GC_GENERAL_REGISTER_DISAPPEARING_LINK(link, obj) \
609 GC_general_register_disappearing_link(link, GC_base(obj))
610 # define GC_REGISTER_DISPLACEMENT(n) GC_debug_register_displacement(n)
611 # else
612 # define GC_MALLOC(sz) GC_malloc(sz)
613 # define GC_MALLOC_ATOMIC(sz) GC_malloc_atomic(sz)
614 # define GC_MALLOC_UNCOLLECTABLE(sz) GC_malloc_uncollectable(sz)
615 # define GC_MALLOC_IGNORE_OFF_PAGE(sz) \
616 GC_malloc_ignore_off_page(sz)
617 # define GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(sz) \
618 GC_malloc_atomic_ignore_off_page(sz)
619 # define GC_REALLOC(old, sz) GC_realloc(old, sz)
620 # define GC_FREE(p) GC_free(p)
621 # define GC_REGISTER_FINALIZER(p, f, d, of, od) \
622 GC_register_finalizer(p, f, d, of, od)
623 # define GC_REGISTER_FINALIZER_IGNORE_SELF(p, f, d, of, od) \
624 GC_register_finalizer_ignore_self(p, f, d, of, od)
625 # define GC_REGISTER_FINALIZER_NO_ORDER(p, f, d, of, od) \
626 GC_register_finalizer_no_order(p, f, d, of, od)
627 # define GC_MALLOC_STUBBORN(sz) GC_malloc_stubborn(sz)
628 # define GC_CHANGE_STUBBORN(p) GC_change_stubborn(p)
629 # define GC_END_STUBBORN_CHANGE(p) GC_end_stubborn_change(p)
630 # define GC_GENERAL_REGISTER_DISAPPEARING_LINK(link, obj) \
631 GC_general_register_disappearing_link(link, obj)
632 # define GC_REGISTER_DISPLACEMENT(n) GC_register_displacement(n)
633 # endif
634 /* The following are included because they are often convenient, and */
635 /* reduce the chance for a misspecifed size argument. But calls may */
636 /* expand to something syntactically incorrect if t is a complicated */
637 /* type expression. */
638 # define GC_NEW(t) (t *)GC_MALLOC(sizeof (t))
639 # define GC_NEW_ATOMIC(t) (t *)GC_MALLOC_ATOMIC(sizeof (t))
640 # define GC_NEW_STUBBORN(t) (t *)GC_MALLOC_STUBBORN(sizeof (t))
641 # define GC_NEW_UNCOLLECTABLE(t) (t *)GC_MALLOC_UNCOLLECTABLE(sizeof (t))
643 /* Finalization. Some of these primitives are grossly unsafe. */
644 /* The idea is to make them both cheap, and sufficient to build */
645 /* a safer layer, closer to Modula-3, Java, or PCedar finalization. */
646 /* The interface represents my conclusions from a long discussion */
647 /* with Alan Demers, Dan Greene, Carl Hauser, Barry Hayes, */
648 /* Christian Jacobi, and Russ Atkinson. It's not perfect, and */
649 /* probably nobody else agrees with it. Hans-J. Boehm 3/13/92 */
650 typedef void (*GC_finalization_proc)
651 GC_PROTO((GC_PTR obj, GC_PTR client_data));
653 GC_API void GC_register_finalizer
654 GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
655 GC_finalization_proc *ofn, GC_PTR *ocd));
656 GC_API void GC_debug_register_finalizer
657 GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
658 GC_finalization_proc *ofn, GC_PTR *ocd));
659 /* When obj is no longer accessible, invoke */
660 /* (*fn)(obj, cd). If a and b are inaccessible, and */
661 /* a points to b (after disappearing links have been */
662 /* made to disappear), then only a will be */
663 /* finalized. (If this does not create any new */
664 /* pointers to b, then b will be finalized after the */
665 /* next collection.) Any finalizable object that */
666 /* is reachable from itself by following one or more */
667 /* pointers will not be finalized (or collected). */
668 /* Thus cycles involving finalizable objects should */
669 /* be avoided, or broken by disappearing links. */
670 /* All but the last finalizer registered for an object */
671 /* is ignored. */
672 /* Finalization may be removed by passing 0 as fn. */
673 /* Finalizers are implicitly unregistered just before */
674 /* they are invoked. */
675 /* The old finalizer and client data are stored in */
676 /* *ofn and *ocd. */
677 /* Fn is never invoked on an accessible object, */
678 /* provided hidden pointers are converted to real */
679 /* pointers only if the allocation lock is held, and */
680 /* such conversions are not performed by finalization */
681 /* routines. */
682 /* If GC_register_finalizer is aborted as a result of */
683 /* a signal, the object may be left with no */
684 /* finalization, even if neither the old nor new */
685 /* finalizer were NULL. */
686 /* Obj should be the nonNULL starting address of an */
687 /* object allocated by GC_malloc or friends. */
688 /* Note that any garbage collectable object referenced */
689 /* by cd will be considered accessible until the */
690 /* finalizer is invoked. */
692 /* Another versions of the above follow. It ignores */
693 /* self-cycles, i.e. pointers from a finalizable object to */
694 /* itself. There is a stylistic argument that this is wrong, */
695 /* but it's unavoidable for C++, since the compiler may */
696 /* silently introduce these. It's also benign in that specific */
697 /* case. And it helps if finalizable objects are split to */
698 /* avoid cycles. */
699 /* Note that cd will still be viewed as accessible, even if it */
700 /* refers to the object itself. */
701 GC_API void GC_register_finalizer_ignore_self
702 GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
703 GC_finalization_proc *ofn, GC_PTR *ocd));
704 GC_API void GC_debug_register_finalizer_ignore_self
705 GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
706 GC_finalization_proc *ofn, GC_PTR *ocd));
708 /* Another version of the above. It ignores all cycles. */
709 /* It should probably only be used by Java implementations. */
710 /* Note that cd will still be viewed as accessible, even if it */
711 /* refers to the object itself. */
712 GC_API void GC_register_finalizer_no_order
713 GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
714 GC_finalization_proc *ofn, GC_PTR *ocd));
715 GC_API void GC_debug_register_finalizer_no_order
716 GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
717 GC_finalization_proc *ofn, GC_PTR *ocd));
720 /* The following routine may be used to break cycles between */
721 /* finalizable objects, thus causing cyclic finalizable */
722 /* objects to be finalized in the correct order. Standard */
723 /* use involves calling GC_register_disappearing_link(&p), */
724 /* where p is a pointer that is not followed by finalization */
725 /* code, and should not be considered in determining */
726 /* finalization order. */
727 GC_API int GC_register_disappearing_link GC_PROTO((GC_PTR * /* link */));
728 /* Link should point to a field of a heap allocated */
729 /* object obj. *link will be cleared when obj is */
730 /* found to be inaccessible. This happens BEFORE any */
731 /* finalization code is invoked, and BEFORE any */
732 /* decisions about finalization order are made. */
733 /* This is useful in telling the finalizer that */
734 /* some pointers are not essential for proper */
735 /* finalization. This may avoid finalization cycles. */
736 /* Note that obj may be resurrected by another */
737 /* finalizer, and thus the clearing of *link may */
738 /* be visible to non-finalization code. */
739 /* There's an argument that an arbitrary action should */
740 /* be allowed here, instead of just clearing a pointer. */
741 /* But this causes problems if that action alters, or */
742 /* examines connectivity. */
743 /* Returns 1 if link was already registered, 0 */
744 /* otherwise. */
745 /* Only exists for backward compatibility. See below: */
747 GC_API int GC_general_register_disappearing_link
748 GC_PROTO((GC_PTR * /* link */, GC_PTR obj));
749 /* A slight generalization of the above. *link is */
750 /* cleared when obj first becomes inaccessible. This */
751 /* can be used to implement weak pointers easily and */
752 /* safely. Typically link will point to a location */
753 /* holding a disguised pointer to obj. (A pointer */
754 /* inside an "atomic" object is effectively */
755 /* disguised.) In this way soft */
756 /* pointers are broken before any object */
757 /* reachable from them are finalized. Each link */
758 /* May be registered only once, i.e. with one obj */
759 /* value. This was added after a long email discussion */
760 /* with John Ellis. */
761 /* Obj must be a pointer to the first word of an object */
762 /* we allocated. It is unsafe to explicitly deallocate */
763 /* the object containing link. Explicitly deallocating */
764 /* obj may or may not cause link to eventually be */
765 /* cleared. */
766 GC_API int GC_unregister_disappearing_link GC_PROTO((GC_PTR * /* link */));
767 /* Returns 0 if link was not actually registered. */
768 /* Undoes a registration by either of the above two */
769 /* routines. */
771 /* Returns !=0 if GC_invoke_finalizers has something to do. */
772 GC_API int GC_should_invoke_finalizers GC_PROTO((void));
774 GC_API int GC_invoke_finalizers GC_PROTO((void));
775 /* Run finalizers for all objects that are ready to */
776 /* be finalized. Return the number of finalizers */
777 /* that were run. Normally this is also called */
778 /* implicitly during some allocations. If */
779 /* GC-finalize_on_demand is nonzero, it must be called */
780 /* explicitly. */
782 /* GC_set_warn_proc can be used to redirect or filter warning messages. */
783 /* p may not be a NULL pointer. */
784 typedef void (*GC_warn_proc) GC_PROTO((char *msg, GC_word arg));
785 GC_API GC_warn_proc GC_set_warn_proc GC_PROTO((GC_warn_proc p));
786 /* Returns old warning procedure. */
788 GC_API GC_word GC_set_free_space_divisor GC_PROTO((GC_word value));
789 /* Set free_space_divisor. See above for definition. */
790 /* Returns old value. */
792 /* The following is intended to be used by a higher level */
793 /* (e.g. Java-like) finalization facility. It is expected */
794 /* that finalization code will arrange for hidden pointers to */
795 /* disappear. Otherwise objects can be accessed after they */
796 /* have been collected. */
797 /* Note that putting pointers in atomic objects or in */
798 /* nonpointer slots of "typed" objects is equivalent to */
799 /* disguising them in this way, and may have other advantages. */
800 # if defined(I_HIDE_POINTERS) || defined(GC_I_HIDE_POINTERS)
801 typedef GC_word GC_hidden_pointer;
802 # define HIDE_POINTER(p) (~(GC_hidden_pointer)(p))
803 # define REVEAL_POINTER(p) ((GC_PTR)(HIDE_POINTER(p)))
804 /* Converting a hidden pointer to a real pointer requires verifying */
805 /* that the object still exists. This involves acquiring the */
806 /* allocator lock to avoid a race with the collector. */
807 # endif /* I_HIDE_POINTERS */
809 typedef GC_PTR (*GC_fn_type) GC_PROTO((GC_PTR client_data));
810 GC_API GC_PTR GC_call_with_alloc_lock
811 GC_PROTO((GC_fn_type fn, GC_PTR client_data));
813 /* The following routines are primarily intended for use with a */
814 /* preprocessor which inserts calls to check C pointer arithmetic. */
815 /* They indicate failure by invoking the corresponding _print_proc. */
817 /* Check that p and q point to the same object. */
818 /* Fail conspicuously if they don't. */
819 /* Returns the first argument. */
820 /* Succeeds if neither p nor q points to the heap. */
821 /* May succeed if both p and q point to between heap objects. */
822 GC_API GC_PTR GC_same_obj GC_PROTO((GC_PTR p, GC_PTR q));
824 /* Checked pointer pre- and post- increment operations. Note that */
825 /* the second argument is in units of bytes, not multiples of the */
826 /* object size. This should either be invoked from a macro, or the */
827 /* call should be automatically generated. */
828 GC_API GC_PTR GC_pre_incr GC_PROTO((GC_PTR *p, size_t how_much));
829 GC_API GC_PTR GC_post_incr GC_PROTO((GC_PTR *p, size_t how_much));
831 /* Check that p is visible */
832 /* to the collector as a possibly pointer containing location. */
833 /* If it isn't fail conspicuously. */
834 /* Returns the argument in all cases. May erroneously succeed */
835 /* in hard cases. (This is intended for debugging use with */
836 /* untyped allocations. The idea is that it should be possible, though */
837 /* slow, to add such a call to all indirect pointer stores.) */
838 /* Currently useless for multithreaded worlds. */
839 GC_API GC_PTR GC_is_visible GC_PROTO((GC_PTR p));
841 /* Check that if p is a pointer to a heap page, then it points to */
842 /* a valid displacement within a heap object. */
843 /* Fail conspicuously if this property does not hold. */
844 /* Uninteresting with GC_all_interior_pointers. */
845 /* Always returns its argument. */
846 GC_API GC_PTR GC_is_valid_displacement GC_PROTO((GC_PTR p));
848 /* Safer, but slow, pointer addition. Probably useful mainly with */
849 /* a preprocessor. Useful only for heap pointers. */
850 #ifdef GC_DEBUG
851 # define GC_PTR_ADD3(x, n, type_of_result) \
852 ((type_of_result)GC_same_obj((x)+(n), (x)))
853 # define GC_PRE_INCR3(x, n, type_of_result) \
854 ((type_of_result)GC_pre_incr(&(x), (n)*sizeof(*x))
855 # define GC_POST_INCR2(x, type_of_result) \
856 ((type_of_result)GC_post_incr(&(x), sizeof(*x))
857 # ifdef __GNUC__
858 # define GC_PTR_ADD(x, n) \
859 GC_PTR_ADD3(x, n, typeof(x))
860 # define GC_PRE_INCR(x, n) \
861 GC_PRE_INCR3(x, n, typeof(x))
862 # define GC_POST_INCR(x, n) \
863 GC_POST_INCR3(x, typeof(x))
864 # else
865 /* We can't do this right without typeof, which ANSI */
866 /* decided was not sufficiently useful. Repeatedly */
867 /* mentioning the arguments seems too dangerous to be */
868 /* useful. So does not casting the result. */
869 # define GC_PTR_ADD(x, n) ((x)+(n))
870 # endif
871 #else /* !GC_DEBUG */
872 # define GC_PTR_ADD3(x, n, type_of_result) ((x)+(n))
873 # define GC_PTR_ADD(x, n) ((x)+(n))
874 # define GC_PRE_INCR3(x, n, type_of_result) ((x) += (n))
875 # define GC_PRE_INCR(x, n) ((x) += (n))
876 # define GC_POST_INCR2(x, n, type_of_result) ((x)++)
877 # define GC_POST_INCR(x, n) ((x)++)
878 #endif
880 /* Safer assignment of a pointer to a nonstack location. */
881 #ifdef GC_DEBUG
882 # if defined(__STDC__) || defined(_AIX)
883 # define GC_PTR_STORE(p, q) \
884 (*(void **)GC_is_visible(p) = GC_is_valid_displacement(q))
885 # else
886 # define GC_PTR_STORE(p, q) \
887 (*(char **)GC_is_visible(p) = GC_is_valid_displacement(q))
888 # endif
889 #else /* !GC_DEBUG */
890 # define GC_PTR_STORE(p, q) *((p) = (q))
891 #endif
893 /* Functions called to report pointer checking errors */
894 GC_API void (*GC_same_obj_print_proc) GC_PROTO((GC_PTR p, GC_PTR q));
896 GC_API void (*GC_is_valid_displacement_print_proc)
897 GC_PROTO((GC_PTR p));
899 GC_API void (*GC_is_visible_print_proc)
900 GC_PROTO((GC_PTR p));
903 /* For pthread support, we generally need to intercept a number of */
904 /* thread library calls. We do that here by macro defining them. */
906 #if !defined(GC_USE_LD_WRAP) && \
907 (defined(GC_PTHREADS) || defined(GC_SOLARIS_THREADS))
908 # include "gc_pthread_redirects.h"
909 #endif
911 # if defined(PCR) || defined(GC_SOLARIS_THREADS) || \
912 defined(GC_PTHREADS) || defined(GC_WIN32_THREADS)
913 /* Any flavor of threads except SRC_M3. */
915 /* Register the current thread as a new thread whose stack(s) should */
916 /* be traced by the GC. */
917 /* If a platform does not implicitly do so, this must be called before */
918 /* a thread can allocate garbage collected memory, or assign pointers */
919 /* to the garbage collected heap. Once registered, a thread will be */
920 /* stopped during garbage collections. */
921 GC_API void GC_register_my_thread GC_PROTO((void));
923 /* Register the current thread, with the indicated stack base, as */
924 /* a new thread whose stack(s) should be traced by the GC. If a */
925 /* platform does not implicitly do so, this must be called before a */
926 /* thread can allocate garbage collected memory, or assign pointers */
927 /* to the garbage collected heap. Once registered, a thread will be */
928 /* stopped during garbage collections. */
929 GC_API void GC_unregister_my_thread GC_PROTO((void));
931 GC_API GC_PTR GC_get_thread_stack_base GC_PROTO((void));
933 /* This returns a list of objects, linked through their first */
934 /* word. Its use can greatly reduce lock contention problems, since */
935 /* the allocation lock can be acquired and released many fewer times. */
936 /* lb must be large enough to hold the pointer field. */
937 /* It is used internally by gc_local_alloc.h, which provides a simpler */
938 /* programming interface on Linux. */
939 GC_PTR GC_malloc_many(size_t lb);
940 #define GC_NEXT(p) (*(GC_PTR *)(p)) /* Retrieve the next element */
941 /* in returned list. */
942 extern void GC_thr_init GC_PROTO((void));/* Needed for Solaris/X86 */
944 #endif /* THREADS && !SRC_M3 */
946 /* Register a callback to control the scanning of dynamic libraries.
947 When the GC scans the static data of a dynamic library, it will
948 first call a user-supplied routine with filename of the library and
949 the address and length of the memory region. This routine should
950 return nonzero if that region should be scanned. */
951 GC_API void GC_register_has_static_roots_callback
952 (int (*callback)(const char *, void *, size_t));
955 #if defined(GC_WIN32_THREADS) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
956 # include <windows.h>
959 * All threads must be created using GC_CreateThread, so that they will be
960 * recorded in the thread table. For backwards compatibility, this is not
961 * technically true if the GC is built as a dynamic library, since it can
962 * and does then use DllMain to keep track of thread creations. But new code
963 * should be built to call GC_CreateThread.
965 GC_API HANDLE WINAPI GC_CreateThread(
966 LPSECURITY_ATTRIBUTES lpThreadAttributes,
967 DWORD dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress,
968 LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId );
970 # if defined(_WIN32_WCE)
972 * win32_threads.c implements the real WinMain, which will start a new thread
973 * to call GC_WinMain after initializing the garbage collector.
975 int WINAPI GC_WinMain(
976 HINSTANCE hInstance,
977 HINSTANCE hPrevInstance,
978 LPWSTR lpCmdLine,
979 int nCmdShow );
981 # ifndef GC_BUILD
982 # define WinMain GC_WinMain
983 # define CreateThread GC_CreateThread
984 # endif
985 # endif /* defined(_WIN32_WCE) */
987 #endif /* defined(GC_WIN32_THREADS) && !cygwin */
990 * Fully portable code should call GC_INIT() from the main program
991 * before making any other GC_ calls. On most platforms this is a
992 * no-op and the collector self-initializes. But a number of platforms
993 * make that too hard.
995 #if (defined(sparc) || defined(__sparc)) && defined(sun)
997 * If you are planning on putting
998 * the collector in a SunOS 5 dynamic library, you need to call GC_INIT()
999 * from the statically loaded program section.
1000 * This circumvents a Solaris 2.X (X<=4) linker bug.
1002 # define GC_INIT() { extern end, etext; \
1003 GC_noop(&end, &etext); }
1004 #else
1005 # if defined(__CYGWIN32__) || defined (_AIX)
1007 * Similarly gnu-win32 DLLs need explicit initialization from
1008 * the main program, as does AIX.
1010 # ifdef __CYGWIN32__
1011 extern int _data_start__[];
1012 extern int _data_end__[];
1013 extern int _bss_start__[];
1014 extern int _bss_end__[];
1015 # define GC_MAX(x,y) ((x) > (y) ? (x) : (y))
1016 # define GC_MIN(x,y) ((x) < (y) ? (x) : (y))
1017 # define GC_DATASTART ((GC_PTR) GC_MIN(_data_start__, _bss_start__))
1018 # define GC_DATAEND ((GC_PTR) GC_MAX(_data_end__, _bss_end__))
1019 # ifdef GC_DLL
1020 # define GC_INIT() { GC_add_roots(GC_DATASTART, GC_DATAEND); }
1021 # else
1022 # define GC_INIT()
1023 # endif
1024 # endif
1025 # if defined(_AIX)
1026 extern int _data[], _end[];
1027 # define GC_DATASTART ((GC_PTR)((ulong)_data))
1028 # define GC_DATAEND ((GC_PTR)((ulong)_end))
1029 # define GC_INIT() { GC_add_roots(GC_DATASTART, GC_DATAEND); }
1030 # endif
1031 # else
1032 # if defined(__APPLE__) && defined(__MACH__) || defined(GC_WIN32_THREADS)
1033 # define GC_INIT() { GC_init(); }
1034 # else
1035 # define GC_INIT()
1036 # endif /* !__MACH && !GC_WIN32_THREADS */
1037 # endif /* !AIX && !cygwin */
1038 #endif /* !sparc */
1040 #if !defined(_WIN32_WCE) \
1041 && ((defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
1042 || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__))
1043 /* win32S may not free all resources on process exit. */
1044 /* This explicitly deallocates the heap. */
1045 GC_API void GC_win32_free_heap ();
1046 #endif
1048 #if ( defined(_AMIGA) && !defined(GC_AMIGA_MAKINGLIB) )
1049 /* Allocation really goes through GC_amiga_allocwrapper_do */
1050 # include "gc_amiga_redirects.h"
1051 #endif
1053 #if defined(GC_REDIRECT_TO_LOCAL) && !defined(GC_LOCAL_ALLOC_H)
1054 # include "gc_local_alloc.h"
1055 #endif
1057 #ifdef __cplusplus
1058 } /* end of extern "C" */
1059 #endif
1061 /* External thread suspension support. These functions do not implement
1062 * suspension counts or any other higher-level abstraction. Threads which
1063 * have been suspended numerous times will resume with the very first call
1064 * to GC_resume_thread.
1066 #if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS) \
1067 && !defined(GC_WIN32_THREADS) && !defined(GC_DARWIN_THREADS)
1068 GC_API void GC_suspend_thread GC_PROTO((pthread_t));
1069 GC_API void GC_resume_thread GC_PROTO((pthread_t));
1070 #endif
1071 #endif /* _GC_H */