~ubuntu-branches/ubuntu/quantal/libgc/quantal

« back to all changes in this revision

Viewing changes to include/gc.h

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2011-02-19 12:19:56 UTC
  • mfrom: (1.3.2 upstream) (0.1.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110219121956-67rb69xlt5nud3v2
Tags: 1:7.1-5
Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * Copyright (c) 1991-1995 by Xerox Corporation.  All rights reserved.
4
4
 * Copyright 1996-1999 by Silicon Graphics.  All rights reserved.
5
5
 * Copyright 1999 by Hewlett-Packard Company.  All rights reserved.
 
6
 * Copyright (C) 2007 Free Software Foundation, Inc
6
7
 *
7
8
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8
9
 * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
30
31
 
31
32
# define _GC_H
32
33
 
 
34
# include "gc_version.h"
 
35
        /* Define version numbers here to allow test on build machine   */
 
36
        /* for cross-builds.  Note that this defines the header         */
 
37
        /* version number, which may or may not match that of the       */
 
38
        /* dynamic library.  The GC_version variable can be used        */
 
39
        /* to obtain the latter.                                        */
 
40
 
33
41
# include "gc_config_macros.h"
34
42
 
35
 
# if defined(__STDC__) || defined(__cplusplus) || defined(_AIX)
36
 
#   define GC_PROTO(args) args
37
 
    typedef void * GC_PTR;
38
 
#   define GC_CONST const
39
 
# else
40
 
#   define GC_PROTO(args) ()
41
 
    typedef char * GC_PTR;
42
 
#   define GC_CONST
43
 
#  endif
44
 
 
45
43
# ifdef __cplusplus
46
44
    extern "C" {
47
45
# endif
61
59
  /* Win64 isn't really supported yet, but this is the first step. And  */
62
60
  /* it might cause error messages to show up in more plausible places. */
63
61
  /* This needs basetsd.h, which is included by windows.h.              */
64
 
  typedef ULONG_PTR GC_word;
65
 
  typedef LONG_PTR GC_word;
 
62
  typedef unsigned long long GC_word;
 
63
  typedef long long GC_signed_word;
66
64
#endif
67
65
 
68
66
/* Public read-only variables */
83
81
 
84
82
/* Public R/W variables */
85
83
 
86
 
GC_API GC_PTR (*GC_oom_fn) GC_PROTO((size_t bytes_requested));
 
84
GC_API void * (*GC_oom_fn) (size_t bytes_requested);
87
85
                        /* When there is insufficient memory to satisfy */
88
86
                        /* an allocation request, we return             */
89
87
                        /* (*GC_oom_fn)().  By default this just        */
110
108
                        /* pointer recognition.                         */
111
109
                        /* MUST BE 0 or 1.                              */
112
110
 
113
 
GC_API int GC_quiet;    /* Disable statistics output.  Only matters if  */
114
 
                        /* collector has been compiled with statistics  */
115
 
                        /* enabled.  This involves a performance cost,  */
116
 
                        /* and is thus not the default.                 */
117
 
 
118
111
GC_API int GC_finalize_on_demand;
119
112
                        /* If nonzero, finalizers will only be run in   */
120
113
                        /* response to an explicit GC_invoke_finalizers */
128
121
                        /* it a bit safer to use non-topologically-     */
129
122
                        /* ordered finalization.  Default value is      */
130
123
                        /* determined by JAVA_FINALIZATION macro.       */
 
124
                        /* Enables register_finalizer_unreachable to    */
 
125
                        /* work correctly.                              */
131
126
 
132
 
GC_API void (* GC_finalizer_notifier) GC_PROTO((void));
 
127
GC_API void (* GC_finalizer_notifier)(void);
133
128
                        /* Invoked by the collector when there are      */
134
129
                        /* objects to be finalized.  Invoked at most    */
135
130
                        /* once per GC cycle.  Never invoked unless     */
189
184
GC_API GC_word GC_free_space_divisor;
190
185
                        /* We try to make sure that we allocate at      */
191
186
                        /* least N/GC_free_space_divisor bytes between  */
192
 
                        /* collections, where N is the heap size plus   */
 
187
                        /* collections, where N is twice the number     */
 
188
                        /* of traced bytes, plus the number of untraced */
 
189
                        /* bytes (bytes in "atomic" objects), plus      */
193
190
                        /* a rough estimate of the root set size.       */
 
191
                        /* N approximates GC tracing work per GC.       */
194
192
                        /* Initially, GC_free_space_divisor = 3.        */
195
193
                        /* Increasing its value will use less space     */
196
194
                        /* but more collection time.  Decreasing it     */
197
195
                        /* will appreciably decrease collection time    */
198
196
                        /* at the expense of space.                     */
199
 
                        /* GC_free_space_divisor = 1 will effectively   */
200
 
                        /* disable collections.                         */
201
197
 
202
198
GC_API GC_word GC_max_retries;
203
199
                        /* The maximum number of GCs attempted before   */
205
201
                        /* expansion fails.  Initially 0.               */
206
202
                        
207
203
 
208
 
GC_API char *GC_stackbottom;    /* Cool end of user stack.              */
 
204
GC_API char *GC_stackbottom;    /* Cool end of user stack.              */
209
205
                                /* May be set in the client prior to    */
210
206
                                /* calling any GC_ routines.  This      */
211
207
                                /* avoids some overhead, and            */
241
237
 
242
238
/* Public procedures */
243
239
 
244
 
/* Initialize the collector.  This is only required when using thread-local
245
 
 * allocation, since unlike the regular allocation routines, GC_local_malloc
246
 
 * is not self-initializing.  If you use GC_local_malloc you should arrange
247
 
 * to call this somehow (e.g. from a constructor) before doing any allocation.
248
 
 * For win32 threads, it needs to be called explicitly.
 
240
/* Initialize the collector.  Portable clients should call GC_INIT() from
 
241
 * the main program instead.
249
242
 */
250
 
GC_API void GC_init GC_PROTO((void));
 
243
GC_API void GC_init(void);
251
244
 
252
245
/*
253
246
 * general purpose allocation routines, with roughly malloc calling conv.
265
258
 * starting in 6.0.  GC_malloc_stubborn is an alias for GC_malloc unless
266
259
 * the collector is built with STUBBORN_ALLOC defined.
267
260
 */
268
 
GC_API GC_PTR GC_malloc GC_PROTO((size_t size_in_bytes));
269
 
GC_API GC_PTR GC_malloc_atomic GC_PROTO((size_t size_in_bytes));
270
 
GC_API char *GC_strdup GC_PROTO((const char *str));
271
 
GC_API GC_PTR GC_malloc_uncollectable GC_PROTO((size_t size_in_bytes));
272
 
GC_API GC_PTR GC_malloc_stubborn GC_PROTO((size_t size_in_bytes));
 
261
GC_API void * GC_malloc(size_t size_in_bytes);
 
262
GC_API void * GC_malloc_atomic(size_t size_in_bytes);
 
263
GC_API char * GC_strdup (const char *str);
 
264
GC_API void * GC_malloc_uncollectable(size_t size_in_bytes);
 
265
GC_API void * GC_malloc_stubborn(size_t size_in_bytes);
273
266
 
274
267
/* The following is only defined if the library has been suitably       */
275
268
/* compiled:                                                            */
276
 
GC_API GC_PTR GC_malloc_atomic_uncollectable GC_PROTO((size_t size_in_bytes));
 
269
GC_API void * GC_malloc_atomic_uncollectable(size_t size_in_bytes);
277
270
 
278
271
/* Explicitly deallocate an object.  Dangerous if used incorrectly.     */
279
272
/* Requires a pointer to the base of an object.                         */
281
274
/* An object should not be enable for finalization when it is           */
282
275
/* explicitly deallocated.                                              */
283
276
/* GC_free(0) is a no-op, as required by ANSI C for free.               */
284
 
GC_API void GC_free GC_PROTO((GC_PTR object_addr));
 
277
GC_API void GC_free(void * object_addr);
285
278
 
286
279
/*
287
280
 * Stubborn objects may be changed only if the collector is explicitly informed.
298
291
 * do so.  The same applies to dropping stubborn objects that are still
299
292
 * changeable.
300
293
 */
301
 
GC_API void GC_change_stubborn GC_PROTO((GC_PTR));
302
 
GC_API void GC_end_stubborn_change GC_PROTO((GC_PTR));
 
294
GC_API void GC_change_stubborn(void *);
 
295
GC_API void GC_end_stubborn_change(void *);
303
296
 
304
297
/* Return a pointer to the base (lowest address) of an object given     */
305
298
/* a pointer to a location within the object.                           */
311
304
/* object.                                                              */
312
305
/* Note that a deallocated object in the garbage collected heap         */
313
306
/* may be considered valid, even if it has been deallocated with        */
314
 
/* GC_free.                                                             */
315
 
GC_API GC_PTR GC_base GC_PROTO((GC_PTR displaced_pointer));
 
307
/* GC_free.                                                             */
 
308
GC_API void * GC_base(void * displaced_pointer);
316
309
 
317
310
/* Given a pointer to the base of an object, return its size in bytes.  */
318
311
/* The returned size may be slightly larger than what was originally    */
319
312
/* requested.                                                           */
320
 
GC_API size_t GC_size GC_PROTO((GC_PTR object_addr));
 
313
GC_API size_t GC_size(void * object_addr);
321
314
 
322
315
/* For compatibility with C library.  This is occasionally faster than  */
323
316
/* a malloc followed by a bcopy.  But if you rely on that, either here  */
327
320
/* If the argument is stubborn, the result will have changes enabled.   */
328
321
/* It is an error to have changes enabled for the original object.      */
329
322
/* Follows ANSI comventions for NULL old_object.                        */
330
 
GC_API GC_PTR GC_realloc
331
 
        GC_PROTO((GC_PTR old_object, size_t new_size_in_bytes));
 
323
GC_API void * GC_realloc(void * old_object, size_t new_size_in_bytes);
332
324
                                   
333
325
/* Explicitly increase the heap size.   */
334
326
/* Returns 0 on failure, 1 on success.  */
335
 
GC_API int GC_expand_hp GC_PROTO((size_t number_of_bytes));
 
327
GC_API int GC_expand_hp(size_t number_of_bytes);
336
328
 
337
329
/* Limit the heap size to n bytes.  Useful when you're debugging,       */
338
330
/* especially on systems that don't handle running out of memory well.  */
339
331
/* n == 0 ==> unbounded.  This is the default.                          */
340
 
GC_API void GC_set_max_heap_size GC_PROTO((GC_word n));
 
332
GC_API void GC_set_max_heap_size(GC_word n);
341
333
 
342
334
/* Inform the collector that a certain section of statically allocated  */
343
335
/* memory contains no pointers to garbage collected memory.  Thus it    */
344
336
/* need not be scanned.  This is sometimes important if the application */
345
337
/* maps large read/write files into the address space, which could be   */
346
338
/* mistaken for dynamic library data segments on some systems.          */
347
 
GC_API void GC_exclude_static_roots GC_PROTO((GC_PTR start, GC_PTR finish));
 
339
GC_API void GC_exclude_static_roots(void * low_address,
 
340
                                    void * high_address_plus_1);
348
341
 
349
342
/* Clear the set of root segments.  Wizards only. */
350
 
GC_API void GC_clear_roots GC_PROTO((void));
 
343
GC_API void GC_clear_roots(void);
351
344
 
352
345
/* Add a root segment.  Wizards only. */
353
 
GC_API void GC_add_roots GC_PROTO((char * low_address,
354
 
                                   char * high_address_plus_1));
 
346
GC_API void GC_add_roots(void * low_address, void * high_address_plus_1);
355
347
 
356
348
/* Remove a root segment.  Wizards only. */
357
 
GC_API void GC_remove_roots GC_PROTO((char * low_address, 
358
 
    char * high_address_plus_1));
 
349
GC_API void GC_remove_roots(void * low_address, void * high_address_plus_1);
359
350
 
360
351
/* Add a displacement to the set of those considered valid by the       */
361
352
/* collector.  GC_register_displacement(n) means that if p was returned */
369
360
/* retention.                                                           */
370
361
/* This is a no-op if the collector has recognition of                  */
371
362
/* arbitrary interior pointers enabled, which is now the default.       */
372
 
GC_API void GC_register_displacement GC_PROTO((GC_word n));
 
363
GC_API void GC_register_displacement(size_t n);
373
364
 
374
365
/* The following version should be used if any debugging allocation is  */
375
366
/* being done.                                                          */
376
 
GC_API void GC_debug_register_displacement GC_PROTO((GC_word n));
 
367
GC_API void GC_debug_register_displacement(size_t n);
377
368
 
378
369
/* Explicitly trigger a full, world-stop collection.    */
379
 
GC_API void GC_gcollect GC_PROTO((void));
 
370
GC_API void GC_gcollect(void);
380
371
 
381
372
/* Trigger a full world-stopped collection.  Abort the collection if    */
382
373
/* and when stop_func returns a nonzero value.  Stop_func will be       */
387
378
/* aborted collections do no useful work; the next collection needs     */
388
379
/* to start from the beginning.                                         */
389
380
/* Return 0 if the collection was aborted, 1 if it succeeded.           */
390
 
typedef int (* GC_stop_func) GC_PROTO((void));
391
 
GC_API int GC_try_to_collect GC_PROTO((GC_stop_func stop_func));
 
381
typedef int (* GC_stop_func)(void);
 
382
GC_API int GC_try_to_collect(GC_stop_func stop_func);
392
383
 
393
384
/* Return the number of bytes in the heap.  Excludes collector private  */
394
385
/* data structures.  Includes empty blocks and fragmentation loss.      */
395
386
/* Includes some pages that were allocated but never written.           */
396
 
GC_API size_t GC_get_heap_size GC_PROTO((void));
 
387
GC_API size_t GC_get_heap_size(void);
397
388
 
398
389
/* Return a lower bound on the number of free bytes in the heap.        */
399
 
GC_API size_t GC_get_free_bytes GC_PROTO((void));
 
390
GC_API size_t GC_get_free_bytes(void);
400
391
 
401
392
/* Return the number of bytes allocated since the last collection.      */
402
 
GC_API size_t GC_get_bytes_since_gc GC_PROTO((void));
 
393
GC_API size_t GC_get_bytes_since_gc(void);
403
394
 
404
395
/* Return the total number of bytes allocated in this process.          */
405
396
/* Never decreases, except due to wrapping.                             */
406
 
GC_API size_t GC_get_total_bytes GC_PROTO((void));
 
397
GC_API size_t GC_get_total_bytes(void);
407
398
 
408
399
/* Disable garbage collection.  Even GC_gcollect calls will be          */
409
400
/* ineffective.                                                         */
410
 
GC_API void GC_disable GC_PROTO((void));
 
401
GC_API void GC_disable(void);
411
402
 
412
403
/* Reenable garbage collection.  GC_disable() and GC_enable() calls     */
413
404
/* nest.  Garbage collection is enabled if the number of calls to both  */
414
405
/* both functions is equal.                                             */
415
 
GC_API void GC_enable GC_PROTO((void));
 
406
GC_API void GC_enable(void);
416
407
 
417
408
/* Enable incremental/generational collection.  */
418
409
/* Not advisable unless dirty bits are          */
426
417
/* Causes GC_local_gcj_malloc() to revert to    */
427
418
/* locked allocation.  Must be called           */
428
419
/* before any GC_local_gcj_malloc() calls.      */
429
 
GC_API void GC_enable_incremental GC_PROTO((void));
 
420
/* For best performance, should be called as early as possible. */
 
421
/* On some platforms, calling it later may have adverse effects.*/
 
422
/* Safe to call before GC_INIT().  Includes a GC_init() call.   */
 
423
GC_API void GC_enable_incremental(void);
430
424
 
431
425
/* Does incremental mode write-protect pages?  Returns zero or  */
432
426
/* more of the following, or'ed together:                       */
433
427
#define GC_PROTECTS_POINTER_HEAP  1 /* May protect non-atomic objs.     */
434
428
#define GC_PROTECTS_PTRFREE_HEAP  2
435
 
#define GC_PROTECTS_STATIC_DATA   4 /* Curently never.                  */
 
429
#define GC_PROTECTS_STATIC_DATA   4 /* Currently never.                 */
436
430
#define GC_PROTECTS_STACK         8 /* Probably impractical.            */
437
431
 
438
432
#define GC_PROTECTS_NONE 0
439
 
GC_API int GC_incremental_protection_needs GC_PROTO((void));
 
433
GC_API int GC_incremental_protection_needs(void);
440
434
 
441
435
/* Perform some garbage collection work, if appropriate.        */
442
436
/* Return 0 if there is no more work to be done.                */
445
439
/* progress requires it, e.g. if incremental collection is      */
446
440
/* disabled.  It is reasonable to call this in a wait loop      */
447
441
/* until it returns 0.                                          */
448
 
GC_API int GC_collect_a_little GC_PROTO((void));
 
442
GC_API int GC_collect_a_little(void);
449
443
 
450
444
/* Allocate an object of size lb bytes.  The client guarantees that     */
451
445
/* as long as the object is live, it will be referenced by a pointer    */
461
455
/* for arrays likely to be larger than 100K or so.  For other systems,  */
462
456
/* or if the collector is not configured to recognize all interior      */
463
457
/* pointers, the threshold is normally much higher.                     */
464
 
GC_API GC_PTR GC_malloc_ignore_off_page GC_PROTO((size_t lb));
465
 
GC_API GC_PTR GC_malloc_atomic_ignore_off_page GC_PROTO((size_t lb));
 
458
GC_API void * GC_malloc_ignore_off_page(size_t lb);
 
459
GC_API void * GC_malloc_atomic_ignore_off_page(size_t lb);
466
460
 
467
461
#if defined(__sgi) && !defined(__GNUC__) && _COMPILER_VERSION >= 720
468
462
#   define GC_ADD_CALLER
472
466
#if defined(__linux__) || defined(__GLIBC__)
473
467
# include <features.h>
474
468
# if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1 || __GLIBC__ > 2) \
475
 
     && !defined(__ia64__)
 
469
     && !defined(__ia64__) && !defined(__UCLIBC__)
476
470
#   ifndef GC_HAVE_BUILTIN_BACKTRACE
477
471
#     define GC_HAVE_BUILTIN_BACKTRACE
478
472
#   endif
482
476
# endif
483
477
#endif
484
478
 
 
479
#if defined(_MSC_VER) && _MSC_VER >= 1200 /* version 12.0+ (MSVC 6.0+)  */ \
 
480
    && !defined(_AMD64_)
 
481
# ifndef GC_HAVE_NO_BUILTIN_BACKTRACE
 
482
#   define GC_HAVE_BUILTIN_BACKTRACE
 
483
# endif
 
484
#endif
 
485
 
485
486
#if defined(GC_HAVE_BUILTIN_BACKTRACE) && !defined(GC_CAN_SAVE_CALL_STACKS)
486
487
# define GC_CAN_SAVE_CALL_STACKS
487
488
#endif
512
513
 
513
514
#ifdef GC_ADD_CALLER
514
515
#  define GC_EXTRAS GC_RETURN_ADDR, __FILE__, __LINE__
515
 
#  define GC_EXTRA_PARAMS GC_word ra, GC_CONST char * s, int i
 
516
#  define GC_EXTRA_PARAMS GC_word ra, const char * s, int i
516
517
#else
517
518
#  define GC_EXTRAS __FILE__, __LINE__
518
 
#  define GC_EXTRA_PARAMS GC_CONST char * s, int i
 
519
#  define GC_EXTRA_PARAMS const char * s, int i
519
520
#endif
520
521
 
521
522
/* Debugging (annotated) allocation.  GC_gcollect will check            */
522
523
/* objects allocated in this way for overwrites, etc.                   */
523
 
GC_API GC_PTR GC_debug_malloc
524
 
        GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
525
 
GC_API GC_PTR GC_debug_malloc_atomic
526
 
        GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
527
 
GC_API char *GC_debug_strdup
528
 
       GC_PROTO((const char *str, GC_EXTRA_PARAMS));
529
 
GC_API GC_PTR GC_debug_malloc_uncollectable
530
 
        GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
531
 
GC_API GC_PTR GC_debug_malloc_stubborn
532
 
        GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
533
 
GC_API GC_PTR GC_debug_malloc_ignore_off_page
534
 
        GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
535
 
GC_API GC_PTR GC_debug_malloc_atomic_ignore_off_page
536
 
        GC_PROTO((size_t size_in_bytes, GC_EXTRA_PARAMS));
537
 
GC_API void GC_debug_free GC_PROTO((GC_PTR object_addr));
538
 
GC_API GC_PTR GC_debug_realloc
539
 
        GC_PROTO((GC_PTR old_object, size_t new_size_in_bytes,
540
 
                  GC_EXTRA_PARAMS));
541
 
GC_API void GC_debug_change_stubborn GC_PROTO((GC_PTR));
542
 
GC_API void GC_debug_end_stubborn_change GC_PROTO((GC_PTR));
 
524
GC_API void * GC_debug_malloc(size_t size_in_bytes, GC_EXTRA_PARAMS);
 
525
GC_API void * GC_debug_malloc_atomic(size_t size_in_bytes, GC_EXTRA_PARAMS);
 
526
GC_API char * GC_debug_strdup(const char *str, GC_EXTRA_PARAMS);
 
527
GC_API void * GC_debug_malloc_uncollectable
 
528
        (size_t size_in_bytes, GC_EXTRA_PARAMS);
 
529
GC_API void * GC_debug_malloc_stubborn
 
530
        (size_t size_in_bytes, GC_EXTRA_PARAMS);
 
531
GC_API void * GC_debug_malloc_ignore_off_page
 
532
        (size_t size_in_bytes, GC_EXTRA_PARAMS);
 
533
GC_API void * GC_debug_malloc_atomic_ignore_off_page
 
534
        (size_t size_in_bytes, GC_EXTRA_PARAMS);
 
535
GC_API void GC_debug_free (void * object_addr);
 
536
GC_API void * GC_debug_realloc
 
537
        (void * old_object, size_t new_size_in_bytes, GC_EXTRA_PARAMS);
 
538
GC_API void GC_debug_change_stubborn(void *);
 
539
GC_API void GC_debug_end_stubborn_change(void *);
543
540
 
544
541
/* Routines that allocate objects with debug information (like the      */
545
542
/* above), but just fill in dummy file and line number information.     */
553
550
/*    platforms it may be more convenient not to recompile, e.g. for    */
554
551
/*    leak detection.  This can be accomplished by instructing the      */
555
552
/*    linker to replace malloc/realloc with these.                      */
556
 
GC_API GC_PTR GC_debug_malloc_replacement GC_PROTO((size_t size_in_bytes));
557
 
GC_API GC_PTR GC_debug_realloc_replacement
558
 
              GC_PROTO((GC_PTR object_addr, size_t size_in_bytes));
 
553
GC_API void * GC_debug_malloc_replacement (size_t size_in_bytes);
 
554
GC_API void * GC_debug_realloc_replacement
 
555
              (void * object_addr, size_t size_in_bytes);
559
556
                                 
560
557
# ifdef GC_DEBUG
561
558
#   define GC_MALLOC(sz) GC_debug_malloc(sz, GC_EXTRAS)
575
572
        GC_debug_register_finalizer_ignore_self(p, f, d, of, od)
576
573
#   define GC_REGISTER_FINALIZER_NO_ORDER(p, f, d, of, od) \
577
574
        GC_debug_register_finalizer_no_order(p, f, d, of, od)
 
575
#   define GC_REGISTER_FINALIZER_UNREACHABLE(p, f, d, of, od) \
 
576
        GC_debug_register_finalizer_unreachable(p, f, d, of, od)
578
577
#   define GC_MALLOC_STUBBORN(sz) GC_debug_malloc_stubborn(sz, GC_EXTRAS);
579
578
#   define GC_CHANGE_STUBBORN(p) GC_debug_change_stubborn(p)
580
579
#   define GC_END_STUBBORN_CHANGE(p) GC_debug_end_stubborn_change(p)
598
597
        GC_register_finalizer_ignore_self(p, f, d, of, od)
599
598
#   define GC_REGISTER_FINALIZER_NO_ORDER(p, f, d, of, od) \
600
599
        GC_register_finalizer_no_order(p, f, d, of, od)
 
600
#   define GC_REGISTER_FINALIZER_UNREACHABLE(p, f, d, of, od) \
 
601
        GC_register_finalizer_unreachable(p, f, d, of, od)
601
602
#   define GC_MALLOC_STUBBORN(sz) GC_malloc_stubborn(sz)
602
603
#   define GC_CHANGE_STUBBORN(p) GC_change_stubborn(p)
603
604
#   define GC_END_STUBBORN_CHANGE(p) GC_end_stubborn_change(p)
621
622
/* with Alan Demers, Dan Greene, Carl Hauser, Barry Hayes,              */
622
623
/* Christian Jacobi, and Russ Atkinson.  It's not perfect, and          */
623
624
/* probably nobody else agrees with it.     Hans-J. Boehm  3/13/92      */
624
 
typedef void (*GC_finalization_proc)
625
 
        GC_PROTO((GC_PTR obj, GC_PTR client_data));
 
625
typedef void (*GC_finalization_proc) (void * obj, void * client_data);
626
626
 
627
 
GC_API void GC_register_finalizer
628
 
        GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
629
 
                  GC_finalization_proc *ofn, GC_PTR *ocd));
 
627
GC_API void GC_register_finalizer(void * obj, GC_finalization_proc fn,
 
628
                                  void * cd, GC_finalization_proc *ofn,
 
629
                                  void * *ocd);
630
630
GC_API void GC_debug_register_finalizer
631
 
        GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
632
 
                  GC_finalization_proc *ofn, GC_PTR *ocd));
 
631
                 (void * obj, GC_finalization_proc fn, void * cd,
 
632
                  GC_finalization_proc *ofn, void * *ocd);
633
633
        /* When obj is no longer accessible, invoke             */
634
634
        /* (*fn)(obj, cd).  If a and b are inaccessible, and    */
635
635
        /* a points to b (after disappearing links have been    */
673
673
/* Note that cd will still be viewed as accessible, even if it  */
674
674
/* refers to the object itself.                                 */
675
675
GC_API void GC_register_finalizer_ignore_self
676
 
        GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
677
 
                  GC_finalization_proc *ofn, GC_PTR *ocd));
 
676
                (void * obj, GC_finalization_proc fn, void * cd,
 
677
                 GC_finalization_proc *ofn, void * *ocd);
678
678
GC_API void GC_debug_register_finalizer_ignore_self
679
 
        GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
680
 
                  GC_finalization_proc *ofn, GC_PTR *ocd));
 
679
                (void * obj, GC_finalization_proc fn, void * cd,
 
680
                 GC_finalization_proc *ofn, void * *ocd);
681
681
 
682
682
/* Another version of the above.  It ignores all cycles.        */
683
683
/* It should probably only be used by Java implementations.     */
684
684
/* Note that cd will still be viewed as accessible, even if it  */
685
685
/* refers to the object itself.                                 */
686
686
GC_API void GC_register_finalizer_no_order
687
 
        GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
688
 
                  GC_finalization_proc *ofn, GC_PTR *ocd));
 
687
                (void * obj, GC_finalization_proc fn, void * cd,
 
688
                 GC_finalization_proc *ofn, void * *ocd);
689
689
GC_API void GC_debug_register_finalizer_no_order
690
 
        GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
691
 
                  GC_finalization_proc *ofn, GC_PTR *ocd));
 
690
                (void * obj, GC_finalization_proc fn, void * cd,
 
691
                 GC_finalization_proc *ofn, void * *ocd);
692
692
 
 
693
/* This is a special finalizer that is useful when an object's  */
 
694
/* finalizer must be run when the object is known to be no      */
 
695
/* longer reachable, not even from other finalizable objects.   */
 
696
/* It behaves like "normal" finalization, except that the       */
 
697
/* finalizer is not run while the object is reachable from      */
 
698
/* other objects specifying unordered finalization.             */
 
699
/* Effectively it allows an object referenced, possibly         */
 
700
/* indirectly, from an unordered finalizable object to override */
 
701
/* the unordered finalization request.                          */
 
702
/* This can be used in combination with finalizer_no_order so   */
 
703
/* as to release resources that must not be released while an   */
 
704
/* object can still be brought back to life by other            */
 
705
/* finalizers.                                                  */
 
706
/* Only works if GC_java_finalization is set.  Probably only    */
 
707
/* of interest when implementing a language that requires       */
 
708
/* unordered finalization (e.g. Java, C#).                      */
 
709
GC_API void GC_register_finalizer_unreachable
 
710
                 (void * obj, GC_finalization_proc fn, void * cd,
 
711
                  GC_finalization_proc *ofn, void * *ocd);
 
712
GC_API void GC_debug_register_finalizer_unreachable
 
713
                 (void * obj, GC_finalization_proc fn, void * cd,
 
714
                  GC_finalization_proc *ofn, void * *ocd);
693
715
 
694
716
/* The following routine may be used to break cycles between    */
695
717
/* finalizable objects, thus causing cyclic finalizable         */
698
720
/* where p is a pointer that is not followed by finalization    */
699
721
/* code, and should not be considered in determining            */
700
722
/* finalization order.                                          */
701
 
GC_API int GC_register_disappearing_link GC_PROTO((GC_PTR * /* link */));
 
723
GC_API int GC_register_disappearing_link(void * * link );
702
724
        /* Link should point to a field of a heap allocated     */
703
725
        /* object obj.  *link will be cleared when obj is       */
704
726
        /* found to be inaccessible.  This happens BEFORE any   */
714
736
        /* be allowed here, instead of just clearing a pointer. */
715
737
        /* But this causes problems if that action alters, or   */
716
738
        /* examines connectivity.                               */
717
 
        /* Returns 1 if link was already registered, 0          */
718
 
        /* otherwise.                                           */
 
739
        /* Returns 1 if link was already registered, 0 if       */
 
740
        /* registration succeeded, 2 if it failed for lack of   */
 
741
        /* memory, and GC_oom_fn did not handle the problem.    */
719
742
        /* Only exists for backward compatibility.  See below:  */
720
743
        
721
 
GC_API int GC_general_register_disappearing_link
722
 
        GC_PROTO((GC_PTR * /* link */, GC_PTR obj));
 
744
GC_API int GC_general_register_disappearing_link (void * * link, void * obj);
723
745
        /* A slight generalization of the above. *link is       */
724
746
        /* cleared when obj first becomes inaccessible.  This   */
725
747
        /* can be used to implement weak pointers easily and    */
737
759
        /* the object containing link.  Explicitly deallocating */
738
760
        /* obj may or may not cause link to eventually be       */
739
761
        /* cleared.                                             */
740
 
GC_API int GC_unregister_disappearing_link GC_PROTO((GC_PTR * /* link */));
 
762
        /* This can be used to implement certain types of       */
 
763
        /* weak pointers.  Note however that this generally     */
 
764
        /* requires that thje allocation lock is held (see      */
 
765
        /* GC_call_with_allock_lock() below) when the disguised */
 
766
        /* pointer is accessed.  Otherwise a strong pointer     */
 
767
        /* could be recreated between the time the collector    */
 
768
        /* decides to reclaim the object and the link is        */
 
769
        /* cleared.                                             */
 
770
 
 
771
GC_API int GC_unregister_disappearing_link (void * * link);
741
772
        /* Returns 0 if link was not actually registered.       */
742
773
        /* Undoes a registration by either of the above two     */
743
774
        /* routines.                                            */
744
775
 
745
776
/* Returns !=0  if GC_invoke_finalizers has something to do.            */
746
 
GC_API int GC_should_invoke_finalizers GC_PROTO((void));
 
777
GC_API int GC_should_invoke_finalizers(void);
747
778
 
748
 
GC_API int GC_invoke_finalizers GC_PROTO((void));
 
779
GC_API int GC_invoke_finalizers(void);
749
780
        /* Run finalizers for all objects that are ready to     */
750
781
        /* be finalized.  Return the number of finalizers       */
751
782
        /* that were run.  Normally this is also called         */
752
783
        /* implicitly during some allocations.  If              */
753
 
        /* GC_finalize_on_demand is nonzero, it must be called  */
 
784
        /* GC-finalize_on_demand is nonzero, it must be called  */
754
785
        /* explicitly.                                          */
755
786
 
 
787
/* Explicitly tell the collector that an object is reachable    */
 
788
/* at a particular program point.  This prevents the argument   */
 
789
/* pointer from being optimized away, even it is otherwise no   */
 
790
/* longer needed.  It should have no visible effect in the      */
 
791
/* absence of finalizers or disappearing links.  But it may be  */
 
792
/* needed to prevent finalizers from running while the          */
 
793
/* associated external resource is still in use.                */
 
794
/* The function is sometimes called keep_alive in other         */
 
795
/* settings.                                                    */
 
796
# if defined(__GNUC__) && !defined(__INTEL_COMPILER)
 
797
#   define GC_reachable_here(ptr) \
 
798
    __asm__ volatile(" " : : "X"(ptr) : "memory");
 
799
# else
 
800
    GC_API void GC_noop1(GC_word x);
 
801
#   define GC_reachable_here(ptr) GC_noop1((GC_word)(ptr));
 
802
#endif
 
803
 
756
804
/* GC_set_warn_proc can be used to redirect or filter warning messages. */
757
805
/* p may not be a NULL pointer.                                         */
758
 
typedef void (*GC_warn_proc) GC_PROTO((char *msg, GC_word arg));
759
 
GC_API GC_warn_proc GC_set_warn_proc GC_PROTO((GC_warn_proc p));
 
806
typedef void (*GC_warn_proc) (char *msg, GC_word arg);
 
807
GC_API GC_warn_proc GC_set_warn_proc(GC_warn_proc p);
760
808
    /* Returns old warning procedure.   */
761
809
 
762
 
GC_API GC_word GC_set_free_space_divisor GC_PROTO((GC_word value));
 
810
GC_API GC_word GC_set_free_space_divisor(GC_word value);
763
811
    /* Set free_space_divisor.  See above for definition.       */
764
812
    /* Returns old value.                                       */
765
813
        
774
822
# if defined(I_HIDE_POINTERS) || defined(GC_I_HIDE_POINTERS)
775
823
    typedef GC_word GC_hidden_pointer;
776
824
#   define HIDE_POINTER(p) (~(GC_hidden_pointer)(p))
777
 
#   define REVEAL_POINTER(p) ((GC_PTR)(HIDE_POINTER(p)))
 
825
#   define REVEAL_POINTER(p) ((void *)(HIDE_POINTER(p)))
778
826
    /* Converting a hidden pointer to a real pointer requires verifying */
779
827
    /* that the object still exists.  This involves acquiring the       */
780
828
    /* allocator lock to avoid a race with the collector.               */
781
829
# endif /* I_HIDE_POINTERS */
782
830
 
783
 
typedef GC_PTR (*GC_fn_type) GC_PROTO((GC_PTR client_data));
784
 
GC_API GC_PTR GC_call_with_alloc_lock
785
 
                GC_PROTO((GC_fn_type fn, GC_PTR client_data));
 
831
typedef void * (*GC_fn_type) (void * client_data);
 
832
GC_API void * GC_call_with_alloc_lock (GC_fn_type fn, void * client_data);
 
833
 
 
834
/* These routines are intended to explicitly notify the collector       */
 
835
/* of new threads.  Often this is unnecessary because thread creation   */
 
836
/* is implicitly intercepted by the collector, using header-file        */
 
837
/* defines, or linker-based interception.  In the long run the intent   */
 
838
/* is to always make redundant registration safe.  In the short run,    */
 
839
/* this is being implemented a platform at a time.                      */
 
840
/* The interface is complicated by the fact that we probably will not   */
 
841
/* ever be able to automatically determine the stack base for thread    */
 
842
/* stacks on all platforms.                                             */
 
843
 
 
844
/* Structure representing the base of a thread stack.  On most          */
 
845
/* platforms this contains just a single address.                       */
 
846
struct GC_stack_base {
 
847
        void * mem_base;        /* Base of memory stack.        */
 
848
#       if defined(__ia64) || defined(__ia64__)
 
849
          void * reg_base;      /* Base of separate register stack.     */
 
850
#       endif
 
851
};
 
852
 
 
853
typedef void * (*GC_stack_base_func)(struct GC_stack_base *sb, void *arg);
 
854
 
 
855
/* Call a function with a stack base structure corresponding to         */
 
856
/* somewhere in the GC_call_with_stack_base frame.  This often can      */
 
857
/* be used to provide a sufficiently accurate stack base.  And we       */
 
858
/* implement it everywhere.                                             */
 
859
GC_API void * GC_call_with_stack_base(GC_stack_base_func fn, void *arg);
 
860
 
 
861
/* Register the current thread, with the indicated stack base, as       */
 
862
/* a new thread whose stack(s) should be traced by the GC.  If a        */
 
863
/* platform does not implicitly do so, this must be called before a     */
 
864
/* thread can allocate garbage collected memory, or assign pointers     */
 
865
/* to the garbage collected heap.  Once registered, a thread will be    */
 
866
/* stopped during garbage collections.                                  */
 
867
/* Return codes:        */
 
868
#define GC_SUCCESS 0
 
869
#define GC_DUPLICATE 1  /* Was already registered.      */
 
870
#define GC_NO_THREADS 2 /* No thread support in GC.     */
 
871
#define GC_UNIMPLEMENTED 3      /* Not yet implemented on this platform. */
 
872
GC_API int GC_register_my_thread(struct GC_stack_base *);
 
873
 
 
874
/* Unregister the current thread.  The thread may no longer allocate    */
 
875
/* garbage collected memory or manipulate pointers to the               */
 
876
/* garbage collected heap after making this call.                       */
 
877
/* Specifically, if it wants to return or otherwise communicate a       */
 
878
/* pointer to the garbage-collected heap to another thread, it must     */
 
879
/* do this before calling GC_unregister_my_thread, most probably        */
 
880
/* by saving it in a global data structure.                             */
 
881
GC_API int GC_unregister_my_thread(void);
 
882
 
 
883
/* Attempt to fill in the GC_stack_base structure with the stack base   */
 
884
/* for this thread.  This appears to be required to implement anything  */
 
885
/* like the JNI AttachCurrentThread in an environment in which new      */
 
886
/* threads are not automatically registered with the collector.         */
 
887
/* It is also unfortunately hard to implement well on many platforms.   */
 
888
/* Returns GC_SUCCESS or GC_UNIMPLEMENTED.                              */
 
889
GC_API int GC_get_stack_base(struct GC_stack_base *);
786
890
 
787
891
/* The following routines are primarily intended for use with a         */
788
892
/* preprocessor which inserts calls to check C pointer arithmetic.      */
793
897
/* Returns the first argument.                                  */
794
898
/* Succeeds if neither p nor q points to the heap.              */
795
899
/* May succeed if both p and q point to between heap objects.   */
796
 
GC_API GC_PTR GC_same_obj GC_PROTO((GC_PTR p, GC_PTR q));
 
900
GC_API void * GC_same_obj (void * p, void * q);
797
901
 
798
902
/* Checked pointer pre- and post- increment operations.  Note that      */
799
903
/* the second argument is in units of bytes, not multiples of the       */
800
904
/* object size.  This should either be invoked from a macro, or the     */
801
905
/* call should be automatically generated.                              */
802
 
GC_API GC_PTR GC_pre_incr GC_PROTO((GC_PTR *p, size_t how_much));
803
 
GC_API GC_PTR GC_post_incr GC_PROTO((GC_PTR *p, size_t how_much));
 
906
GC_API void * GC_pre_incr (void * *p, size_t how_much);
 
907
GC_API void * GC_post_incr (void * *p, size_t how_much);
804
908
 
805
909
/* Check that p is visible                                              */
806
910
/* to the collector as a possibly pointer containing location.          */
810
914
/* untyped allocations.  The idea is that it should be possible, though */
811
915
/* slow, to add such a call to all indirect pointer stores.)            */
812
916
/* Currently useless for multithreaded worlds.                          */
813
 
GC_API GC_PTR GC_is_visible GC_PROTO((GC_PTR p));
 
917
GC_API void * GC_is_visible (void * p);
814
918
 
815
919
/* Check that if p is a pointer to a heap page, then it points to       */
816
920
/* a valid displacement within a heap object.                           */
817
921
/* Fail conspicuously if this property does not hold.                   */
818
922
/* Uninteresting with GC_all_interior_pointers.                         */
819
923
/* Always returns its argument.                                         */
820
 
GC_API GC_PTR GC_is_valid_displacement GC_PROTO((GC_PTR p));
 
924
GC_API void * GC_is_valid_displacement (void *  p);
 
925
 
 
926
/* Explicitly dump the GC state.  This is most often called from the    */
 
927
/* debugger, or by setting the GC_DUMP_REGULARLY environment variable,  */
 
928
/* but it may be useful to call it from client code during debugging.   */
 
929
void GC_dump(void);
821
930
 
822
931
/* Safer, but slow, pointer addition.  Probably useful mainly with      */
823
932
/* a preprocessor.  Useful only for heap pointers.                      */
853
962
 
854
963
/* Safer assignment of a pointer to a nonstack location.        */
855
964
#ifdef GC_DEBUG
856
 
# if defined(__STDC__) || defined(_AIX)
857
965
#   define GC_PTR_STORE(p, q) \
858
966
        (*(void **)GC_is_visible(p) = GC_is_valid_displacement(q))
859
 
# else
860
 
#   define GC_PTR_STORE(p, q) \
861
 
        (*(char **)GC_is_visible(p) = GC_is_valid_displacement(q))
862
 
# endif
863
967
#else /* !GC_DEBUG */
864
 
#   define GC_PTR_STORE(p, q) *((p) = (q))
 
968
#   define GC_PTR_STORE(p, q) (*(p) = (q))
865
969
#endif
866
970
 
867
971
/* Functions called to report pointer checking errors */
868
 
GC_API void (*GC_same_obj_print_proc) GC_PROTO((GC_PTR p, GC_PTR q));
869
 
 
870
 
GC_API void (*GC_is_valid_displacement_print_proc)
871
 
        GC_PROTO((GC_PTR p));
872
 
 
873
 
GC_API void (*GC_is_visible_print_proc)
874
 
        GC_PROTO((GC_PTR p));
 
972
GC_API void (*GC_same_obj_print_proc) (void * p, void * q);
 
973
 
 
974
GC_API void (*GC_is_valid_displacement_print_proc) (void * p);
 
975
 
 
976
GC_API void (*GC_is_visible_print_proc) (void * p);
875
977
 
876
978
 
877
979
/* For pthread support, we generally need to intercept a number of      */
878
980
/* thread library calls.  We do that here by macro defining them.       */
879
981
 
880
 
#if !defined(GC_USE_LD_WRAP) && \
881
 
    (defined(GC_PTHREADS) || defined(GC_SOLARIS_THREADS))
 
982
#if !defined(GC_USE_LD_WRAP) && !defined(GC_NO_THREAD_REDIRECTS) \
 
983
    && defined(GC_PTHREADS)
882
984
# include "gc_pthread_redirects.h"
883
985
#endif
884
986
 
885
987
# if defined(PCR) || defined(GC_SOLARIS_THREADS) || \
886
988
     defined(GC_PTHREADS) || defined(GC_WIN32_THREADS)
887
 
        /* Any flavor of threads except SRC_M3. */
 
989
        /* Any flavor of threads.       */
888
990
/* This returns a list of objects, linked through their first           */
889
991
/* word.  Its use can greatly reduce lock contention problems, since    */
890
992
/* the allocation lock can be acquired and released many fewer times.   */
891
 
/* lb must be large enough to hold the pointer field.                   */
892
993
/* It is used internally by gc_local_alloc.h, which provides a simpler  */
893
994
/* programming interface on Linux.                                      */
894
 
GC_PTR GC_malloc_many(size_t lb);
895
 
#define GC_NEXT(p) (*(GC_PTR *)(p))     /* Retrieve the next element    */
 
995
void * GC_malloc_many(size_t lb);
 
996
#define GC_NEXT(p) (*(void * *)(p))     /* Retrieve the next element    */
896
997
                                        /* in returned list.            */
897
 
extern void GC_thr_init GC_PROTO((void));/* Needed for Solaris/X86      */
898
 
 
899
 
#endif /* THREADS && !SRC_M3 */
900
 
 
901
 
#if defined(GC_WIN32_THREADS) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
 
998
 
 
999
#endif /* THREADS */
 
1000
 
 
1001
/* Register a callback to control the scanning of dynamic libraries.
 
1002
   When the GC scans the static data of a dynamic library, it will
 
1003
   first call a user-supplied routine with filename of the library and
 
1004
   the address and length of the memory region.  This routine should
 
1005
   return nonzero if that region should be scanned.  */
 
1006
GC_API void 
 
1007
GC_register_has_static_roots_callback
 
1008
  (int (*callback)(const char *, void *, size_t));
 
1009
 
 
1010
 
 
1011
#if defined(GC_WIN32_THREADS) && !defined(__CYGWIN32__) \
 
1012
        && !defined(__CYGWIN__) \
 
1013
        && !defined(GC_PTHREADS)
 
1014
 
 
1015
#ifdef __cplusplus
 
1016
    }  /* Including windows.h in an extern "C" context no longer works. */
 
1017
#endif
 
1018
 
 
1019
#ifndef GC_NO_THREAD_DECLS
902
1020
# include <windows.h>
903
1021
 
 
1022
#ifdef __cplusplus
 
1023
    extern "C" {
 
1024
#endif
904
1025
  /*
905
 
   * All threads must be created using GC_CreateThread, so that they will be
906
 
   * recorded in the thread table.  For backwards compatibility, this is not
907
 
   * technically true if the GC is built as a dynamic library, since it can
908
 
   * and does then use DllMain to keep track of thread creations.  But new code
909
 
   * should be built to call GC_CreateThread.
 
1026
   * All threads must be created using GC_CreateThread or GC_beginthreadex,
 
1027
   * or must explicitly call GC_register_my_thread,
 
1028
   * so that they will be recorded in the thread table.
 
1029
   * For backwards compatibility, it is possible to build the GC
 
1030
   * with GC_DLL defined, and to call GC_use_DllMain().
 
1031
   * This implicitly registers all created threads, but appears to be
 
1032
   * less robust.
 
1033
   *
 
1034
   * Currently the collector expects all threads to fall through and
 
1035
   * terminate normally, or call GC_endthreadex() or GC_ExitThread,
 
1036
   * so that the thread is properly unregistered.  (An explicit call
 
1037
   * to GC_unregister_my_thread() should also work, but risks unregistering
 
1038
   * the thread twice.)
910
1039
   */
911
1040
   GC_API HANDLE WINAPI GC_CreateThread(
912
1041
      LPSECURITY_ATTRIBUTES lpThreadAttributes,
913
1042
      DWORD dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress,
914
1043
      LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId );
915
1044
 
 
1045
#  if defined(_MSC_VER) && _MSC_VER >= 1200 && !defined(_UINTPTR_T_DEFINED)
 
1046
     typedef unsigned long uintptr_t;
 
1047
#  endif
 
1048
 
 
1049
   GC_API uintptr_t GC_beginthreadex(
 
1050
     void *security, unsigned stack_size,
 
1051
     unsigned ( __stdcall *start_address )( void * ),
 
1052
     void *arglist, unsigned initflag, unsigned *thrdaddr);
 
1053
 
 
1054
   GC_API void GC_endthreadex(unsigned retval);
 
1055
 
 
1056
   GC_API void WINAPI GC_ExitThread(DWORD dwExitCode);
 
1057
 
916
1058
# if defined(_WIN32_WCE)
917
1059
  /*
918
1060
   * win32_threads.c implements the real WinMain, which will start a new thread
919
1061
   * to call GC_WinMain after initializing the garbage collector.
920
1062
   */
921
 
  int WINAPI GC_WinMain(
 
1063
  GC_API int WINAPI GC_WinMain(
922
1064
      HINSTANCE hInstance,
923
1065
      HINSTANCE hPrevInstance,
924
1066
      LPWSTR lpCmdLine,
925
1067
      int nCmdShow );
926
 
 
927
1068
#  ifndef GC_BUILD
928
1069
#    define WinMain GC_WinMain
929
 
#    define CreateThread GC_CreateThread
930
1070
#  endif
931
1071
# endif /* defined(_WIN32_WCE) */
 
1072
#endif /* !GC_NO_THREAD_DECLS */
 
1073
 
 
1074
  /*
 
1075
   * Use implicit thread registration via DllMain.
 
1076
   * Must be called before GC_INIT and other GC routines.
 
1077
   * Should be avoided if GC_beginthreadex and friends can be called
 
1078
   * instead.
 
1079
   */
 
1080
GC_API void GC_use_DllMain(void);
 
1081
 
 
1082
# ifndef GC_NO_THREAD_REDIRECTS
 
1083
#   define CreateThread GC_CreateThread
 
1084
#   define ExitThread GC_ExitThread
 
1085
#   define _beginthreadex GC_beginthreadex
 
1086
#   define _endthreadex GC_endthreadex
 
1087
#   define _beginthread { > "Please use _beginthreadex instead of _beginthread" < }
 
1088
# endif /* !GC_NO_THREAD_REDIRECTS */
932
1089
 
933
1090
#endif /* defined(GC_WIN32_THREADS)  && !cygwin */
934
1091
 
937
1094
  * before making any other GC_ calls.  On most platforms this is a
938
1095
  * no-op and the collector self-initializes.  But a number of platforms
939
1096
  * make that too hard.
 
1097
  * A GC_INIT call is required if the collector is built with THREAD_LOCAL_ALLOC
 
1098
  * defined and the initial allocation call is not to GC_malloc() or
 
1099
  * GC_malloc_atomic().
940
1100
  */
941
 
#if (defined(sparc) || defined(__sparc)) && defined(sun)
942
 
    /*
943
 
     * If you are planning on putting
944
 
     * the collector in a SunOS 5 dynamic library, you need to call GC_INIT()
945
 
     * from the statically loaded program section.
946
 
     * This circumvents a Solaris 2.X (X<=4) linker bug.
947
 
     */
948
 
    extern int _end[], _etext[];
949
 
#   ifdef __cplusplus
950
 
      extern "C" void GC_noop1(GC_word);
951
 
#   else
952
 
      void GC_noop1();
953
 
#   endif /* !__cplusplus */
954
 
#   define GC_INIT() { GC_noop1((GC_word)_end); \
955
 
                       GC_noop1((GC_word)_etext); }
956
 
#else
957
 
# if defined(__CYGWIN32__) || defined (_AIX)
 
1101
#if defined(__CYGWIN32__) || defined (_AIX)
958
1102
    /*
959
1103
     * Similarly gnu-win32 DLLs need explicit initialization from
960
1104
     * the main program, as does AIX.
966
1110
      extern int _bss_end__[];
967
1111
#     define GC_MAX(x,y) ((x) > (y) ? (x) : (y))
968
1112
#     define GC_MIN(x,y) ((x) < (y) ? (x) : (y))
969
 
#     define GC_DATASTART ((GC_PTR) GC_MIN(_data_start__, _bss_start__))
970
 
#     define GC_DATAEND  ((GC_PTR) GC_MAX(_data_end__, _bss_end__))
971
 
#     ifdef GC_DLL
972
 
#       define GC_INIT() { GC_add_roots(GC_DATASTART, GC_DATAEND); }
973
 
#     else
974
 
#       define GC_INIT()
975
 
#     endif
 
1113
#     define GC_DATASTART ((void *) GC_MIN(_data_start__, _bss_start__))
 
1114
#     define GC_DATAEND  ((void *) GC_MAX(_data_end__, _bss_end__))
 
1115
#     define GC_INIT() { GC_add_roots(GC_DATASTART, GC_DATAEND); \
 
1116
                           GC_gcollect(); /* For blacklisting. */}
 
1117
        /* Required at least if GC is in dll.  And doesn't hurt. */
976
1118
#   endif
977
1119
#   if defined(_AIX)
978
1120
      extern int _data[], _end[];
979
 
#     define GC_DATASTART ((GC_PTR)((ulong)_data))
980
 
#     define GC_DATAEND ((GC_PTR)((ulong)_end))
 
1121
#     define GC_DATASTART ((void *)((ulong)_data))
 
1122
#     define GC_DATAEND ((void *)((ulong)_end))
981
1123
#     define GC_INIT() { GC_add_roots(GC_DATASTART, GC_DATAEND); }
982
1124
#   endif
983
 
# else
984
 
#  if defined(__APPLE__) && defined(__MACH__) || defined(GC_WIN32_THREADS)
 
1125
#else
985
1126
#   define GC_INIT() { GC_init(); }
986
 
#  else
987
 
#   define GC_INIT()
988
 
#  endif /* !__MACH && !GC_WIN32_THREADS */
989
 
# endif /* !AIX && !cygwin */
990
 
#endif /* !sparc */
 
1127
#endif
991
1128
 
992
1129
#if !defined(_WIN32_WCE) \
993
1130
    && ((defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
1002
1139
# include "gc_amiga_redirects.h"
1003
1140
#endif
1004
1141
 
1005
 
#if defined(GC_REDIRECT_TO_LOCAL) && !defined(GC_LOCAL_ALLOC_H)
1006
 
#  include  "gc_local_alloc.h"
 
1142
#if defined(GC_REDIRECT_TO_LOCAL)
 
1143
  /* Now redundant; that's the default with THREAD_LOCAL_ALLOC */
1007
1144
#endif
1008
1145
 
1009
1146
#ifdef __cplusplus