[BACK]Return to pcr_interface.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / gc

Annotation of OpenXM_contrib2/asir2000/gc/pcr_interface.c, Revision 1.1

1.1     ! noro        1: /*
        !             2:  * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
        !             3:  *
        !             4:  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
        !             5:  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
        !             6:  *
        !             7:  * Permission is hereby granted to use or copy this program
        !             8:  * for any purpose,  provided the above notices are retained on all copies.
        !             9:  * Permission to modify the code and to distribute modified code is granted,
        !            10:  * provided the above notices are retained, and a notice that the code was
        !            11:  * modified is included with the above copyright notice.
        !            12:  */
        !            13: /* Boehm, February 7, 1996 11:09 am PST */
        !            14: # include "gc_priv.h"
        !            15:
        !            16: # ifdef PCR
        !            17: /*
        !            18:  * Note that POSIX PCR requires an ANSI C compiler.  Hence we are allowed
        !            19:  * to make the same assumption here.
        !            20:  * We wrap all of the allocator functions to avoid questions of
        !            21:  * compatibility between the prototyped and nonprototyped versions of the f
        !            22:  */
        !            23: # include "config/PCR_StdTypes.h"
        !            24: # include "mm/PCR_MM.h"
        !            25: # include <errno.h>
        !            26:
        !            27: # define MY_MAGIC 17L
        !            28: # define MY_DEBUGMAGIC 42L
        !            29:
        !            30: void * GC_AllocProc(size_t size, PCR_Bool ptrFree, PCR_Bool clear )
        !            31: {
        !            32:     if (ptrFree) {
        !            33:         void * result = (void *)GC_malloc_atomic(size);
        !            34:         if (clear && result != 0) BZERO(result, size);
        !            35:         return(result);
        !            36:     } else {
        !            37:         return((void *)GC_malloc(size));
        !            38:     }
        !            39: }
        !            40:
        !            41: void * GC_DebugAllocProc(size_t size, PCR_Bool ptrFree, PCR_Bool clear )
        !            42: {
        !            43:     if (ptrFree) {
        !            44:         void * result = (void *)GC_debug_malloc_atomic(size, __FILE__,
        !            45:                                                             __LINE__);
        !            46:         if (clear && result != 0) BZERO(result, size);
        !            47:         return(result);
        !            48:     } else {
        !            49:         return((void *)GC_debug_malloc(size, __FILE__, __LINE__));
        !            50:     }
        !            51: }
        !            52:
        !            53: # define GC_ReallocProc GC_realloc
        !            54: void * GC_DebugReallocProc(void * old_object, size_t new_size_in_bytes)
        !            55: {
        !            56:     return(GC_debug_realloc(old_object, new_size_in_bytes, __FILE__, __LINE__));
        !            57: }
        !            58:
        !            59: # define GC_FreeProc GC_free
        !            60: # define GC_DebugFreeProc GC_debug_free
        !            61:
        !            62: typedef struct {
        !            63:   PCR_ERes (*ed_proc)(void *p, size_t size, PCR_Any data);
        !            64:   GC_bool ed_pointerfree;
        !            65:   PCR_ERes ed_fail_code;
        !            66:   PCR_Any ed_client_data;
        !            67: } enumerate_data;
        !            68:
        !            69: void GC_enumerate_block(h, ed)
        !            70: register struct hblk *h;
        !            71: enumerate_data * ed;
        !            72: {
        !            73:     register hdr * hhdr;
        !            74:     register int sz;
        !            75:     word *p;
        !            76:     word * lim;
        !            77:
        !            78:     hhdr = HDR(h);
        !            79:     sz = hhdr -> hb_sz;
        !            80:     if (sz >= 0 && ed -> ed_pointerfree
        !            81:        || sz <= 0 && !(ed -> ed_pointerfree)) return;
        !            82:     if (sz < 0) sz = -sz;
        !            83:     lim = (word *)(h+1) - sz;
        !            84:     p = (word *)h;
        !            85:     do {
        !            86:         if (PCR_ERes_IsErr(ed -> ed_fail_code)) return;
        !            87:         ed -> ed_fail_code =
        !            88:             (*(ed -> ed_proc))(p, WORDS_TO_BYTES(sz), ed -> ed_client_data);
        !            89:         p+= sz;
        !            90:     } while (p <= lim);
        !            91: }
        !            92:
        !            93: struct PCR_MM_ProcsRep * GC_old_allocator = 0;
        !            94:
        !            95: PCR_ERes GC_EnumerateProc(
        !            96:     PCR_Bool ptrFree,
        !            97:     PCR_ERes (*proc)(void *p, size_t size, PCR_Any data),
        !            98:     PCR_Any data
        !            99: )
        !           100: {
        !           101:     enumerate_data ed;
        !           102:
        !           103:     ed.ed_proc = proc;
        !           104:     ed.ed_pointerfree = ptrFree;
        !           105:     ed.ed_fail_code = PCR_ERes_okay;
        !           106:     ed.ed_client_data = data;
        !           107:     GC_apply_to_all_blocks(GC_enumerate_block, &ed);
        !           108:     if (ed.ed_fail_code != PCR_ERes_okay) {
        !           109:         return(ed.ed_fail_code);
        !           110:     } else {
        !           111:        /* Also enumerate objects allocated by my predecessors */
        !           112:        return((*(GC_old_allocator->mmp_enumerate))(ptrFree, proc, data));
        !           113:     }
        !           114: }
        !           115:
        !           116: void GC_DummyFreeProc(void *p) {}
        !           117:
        !           118: void GC_DummyShutdownProc(void) {}
        !           119:
        !           120: struct PCR_MM_ProcsRep GC_Rep = {
        !           121:        MY_MAGIC,
        !           122:        GC_AllocProc,
        !           123:        GC_ReallocProc,
        !           124:        GC_DummyFreeProc,       /* mmp_free */
        !           125:        GC_FreeProc,            /* mmp_unsafeFree */
        !           126:        GC_EnumerateProc,
        !           127:        GC_DummyShutdownProc    /* mmp_shutdown */
        !           128: };
        !           129:
        !           130: struct PCR_MM_ProcsRep GC_DebugRep = {
        !           131:        MY_DEBUGMAGIC,
        !           132:        GC_DebugAllocProc,
        !           133:        GC_DebugReallocProc,
        !           134:        GC_DummyFreeProc,       /* mmp_free */
        !           135:        GC_DebugFreeProc,               /* mmp_unsafeFree */
        !           136:        GC_EnumerateProc,
        !           137:        GC_DummyShutdownProc    /* mmp_shutdown */
        !           138: };
        !           139:
        !           140: GC_bool GC_use_debug = 0;
        !           141:
        !           142: void GC_pcr_install()
        !           143: {
        !           144:     PCR_MM_Install((GC_use_debug? &GC_DebugRep : &GC_Rep), &GC_old_allocator);
        !           145: }
        !           146:
        !           147: PCR_ERes
        !           148: PCR_GC_Setup(void)
        !           149: {
        !           150:     return PCR_ERes_okay;
        !           151: }
        !           152:
        !           153: PCR_ERes
        !           154: PCR_GC_Run(void)
        !           155: {
        !           156:
        !           157:     if( !PCR_Base_TestPCRArg("-nogc") ) {
        !           158:         GC_quiet = ( PCR_Base_TestPCRArg("-gctrace") ? 0 : 1 );
        !           159:         GC_use_debug = (GC_bool)PCR_Base_TestPCRArg("-debug_alloc");
        !           160:         GC_init();
        !           161:         if( !PCR_Base_TestPCRArg("-nogc_incremental") ) {
        !           162:             /*
        !           163:              * awful hack to test whether VD is implemented ...
        !           164:              */
        !           165:             if( PCR_VD_Start( 0, NIL, 0) != PCR_ERes_FromErr(ENOSYS) ) {
        !           166:                GC_enable_incremental();
        !           167:            }
        !           168:        }
        !           169:     }
        !           170:     return PCR_ERes_okay;
        !           171: }
        !           172:
        !           173: # endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>