From db2565100a193fa71336be2951b342ef7596f828 Mon Sep 17 00:00:00 2001 From: ivmai Date: Wed, 16 Sep 2009 14:43:37 +0000 Subject: 2009-09-16 Ivan Maidanski * ChangeLog: Remove trailing spaces at EOLn; insert blank lines where missed. * doc/README: Expand all tabs to spaces; remove trailing spaces at EOLn; remove multiple trailing blank lines. * doc/README.autoconf: Ditto. * doc/README.DGUX386: Ditto. * doc/README.environment: Ditto. * doc/README.macros: Ditto. * doc/README.win32: Ditto. * tests/test.c: Ditto. * tests/test_cpp.cc: Ditto. * backgraph.c: Ditto. * blacklst.c: Ditto. * checksums.c: Ditto. * darwin_stop_world.c: Ditto. * dbg_mlc.c: Ditto. * dyn_load.c: Ditto. * finalize.c: Ditto. * gc_dlopen.c: Ditto. * gcj_mlc.c: Ditto. * headers.c: Ditto. * mach_dep.c: Ditto. * malloc.c: Ditto. * mallocx.c: Ditto. * new_hblk.c: Ditto. * obj_map.c: Ditto. * ptr_chck.c: Ditto. * real_malloc.c: Ditto. * reclaim.c: Ditto. * stubborn.c: Ditto. * thread_local_alloc.c: Ditto. * typd_mlc.c: Ditto. * gc_cpp.cc: Ditto. * include/gc_allocator.h: Ditto. * include/gc_backptr.h: Ditto. * include/gc_config_macros.h: Ditto. * include/gc_cpp.h: Ditto. * include/gc_gcj.h: Ditto. * include/gc_inline.h: Ditto. * include/gc_mark.h: Ditto. * include/gc_pthread_redirects.h: Ditto. * include/gc_typed.h: Ditto. * include/gc_version.h: Ditto. * include/javaxfc.h: Ditto. * include/new_gc_alloc.h: Ditto. * include/private/darwin_semaphore.h: Ditto. * include/private/dbg_mlc.h: Ditto. * include/private/gc_hdrs.h: Ditto. * include/private/gc_locks.h: Ditto. * include/private/gc_pmark.h: Ditto. * include/private/gcconfig.h: Ditto. * include/private/pthread_support.h: Ditto. * include/private/thread_local_alloc.h: Ditto. * darwin_stop_world.c: Add copyright header. * include/gc_backptr.h: Ditto. * include/gc_config_macros.h: Ditto. * include/gc_pthread_redirects.h: Ditto. * include/gc_version.h: Ditto. * include/javaxfc.h: Ditto. * include/private/darwin_semaphore.h: Ditto. * include/private/pthread_support.h: Ditto. * gc_cpp.cc: Make copyright header uniform across the package. * include/gc_cpp.h: Ditto. --- ptr_chck.c | 260 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 130 insertions(+), 130 deletions(-) (limited to 'ptr_chck.c') diff --git a/ptr_chck.c b/ptr_chck.c index 6b72ee2f..c168ff9f 100644 --- a/ptr_chck.c +++ b/ptr_chck.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved. * * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED @@ -25,47 +25,47 @@ STATIC void GC_CALLBACK GC_default_same_obj_print_proc(void * p, void * q) } void (GC_CALLBACK *GC_same_obj_print_proc) (void *, void *) - = GC_default_same_obj_print_proc; + = GC_default_same_obj_print_proc; -/* Check that p and q point to the same object. Call */ -/* *GC_same_obj_print_proc if they don't. */ -/* Returns the first argument. (Return value may be hard */ -/* to use,due to typing issues. But if we had a suitable */ -/* preprocessor ...) */ -/* Succeeds if neither p nor q points to the heap. */ -/* We assume this is performance critical. (It shouldn't */ -/* be called by production code, but this can easily make */ -/* debugging intolerably slow.) */ +/* Check that p and q point to the same object. Call */ +/* *GC_same_obj_print_proc if they don't. */ +/* Returns the first argument. (Return value may be hard */ +/* to use,due to typing issues. But if we had a suitable */ +/* preprocessor ...) */ +/* Succeeds if neither p nor q points to the heap. */ +/* We assume this is performance critical. (It shouldn't */ +/* be called by production code, but this can easily make */ +/* debugging intolerably slow.) */ GC_API void * GC_CALL GC_same_obj(void *p, void *q) { struct hblk *h; hdr *hhdr; ptr_t base, limit; word sz; - + if (!GC_is_initialized) GC_init(); hhdr = HDR((word)p); if (hhdr == 0) { - if (divHBLKSZ((word)p) != divHBLKSZ((word)q) - && HDR((word)q) != 0) { - goto fail; - } - return(p); + if (divHBLKSZ((word)p) != divHBLKSZ((word)q) + && HDR((word)q) != 0) { + goto fail; + } + return(p); } - /* If it's a pointer to the middle of a large object, move it */ - /* to the beginning. */ + /* If it's a pointer to the middle of a large object, move it */ + /* to the beginning. */ if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) { - h = HBLKPTR(p) - (word)hhdr; - hhdr = HDR(h); - while (IS_FORWARDING_ADDR_OR_NIL(hhdr)) { - h = FORWARDED_ADDR(h, hhdr); - hhdr = HDR(h); - } - limit = (ptr_t)h + hhdr -> hb_sz; - if ((ptr_t)p >= limit || (ptr_t)q >= limit || (ptr_t)q < (ptr_t)h ) { - goto fail; - } - return(p); + h = HBLKPTR(p) - (word)hhdr; + hhdr = HDR(h); + while (IS_FORWARDING_ADDR_OR_NIL(hhdr)) { + h = FORWARDED_ADDR(h, hhdr); + hhdr = HDR(h); + } + limit = (ptr_t)h + hhdr -> hb_sz; + if ((ptr_t)p >= limit || (ptr_t)q >= limit || (ptr_t)q < (ptr_t)h ) { + goto fail; + } + return(p); } sz = hhdr -> hb_sz; if (sz > MAXOBJBYTES) { @@ -77,21 +77,21 @@ GC_API void * GC_CALL GC_same_obj(void *p, void *q) } else { size_t offset; size_t pdispl = HBLKDISPL(p); - + offset = pdispl % sz; if (HBLKPTR(p) != HBLKPTR(q)) goto fail; - /* W/o this check, we might miss an error if */ - /* q points to the first object on a page, and */ - /* points just before the page. */ + /* W/o this check, we might miss an error if */ + /* q points to the first object on a page, and */ + /* points just before the page. */ base = (ptr_t)p - offset; limit = base + sz; } - /* [base, limit) delimits the object containing p, if any. */ - /* If p is not inside a valid object, then either q is */ - /* also outside any valid object, or it is outside */ - /* [base, limit). */ + /* [base, limit) delimits the object containing p, if any. */ + /* If p is not inside a valid object, then either q is */ + /* also outside any valid object, or it is outside */ + /* [base, limit). */ if ((ptr_t)q >= limit || (ptr_t)q < base) { - goto fail; + goto fail; } return(p); fail: @@ -105,15 +105,15 @@ STATIC void GC_CALLBACK GC_default_is_valid_displacement_print_proc (void *p) ABORT("GC_is_valid_displacement test failed"); } -void (GC_CALLBACK *GC_is_valid_displacement_print_proc)(void *) = - GC_default_is_valid_displacement_print_proc; +void (GC_CALLBACK *GC_is_valid_displacement_print_proc)(void *) = + GC_default_is_valid_displacement_print_proc; -/* Check that if p is a pointer to a heap page, then it points to */ -/* a valid displacement within a heap object. */ -/* Uninteresting with GC_all_interior_pointers. */ -/* Always returns its argument. */ -/* Note that we don't lock, since nothing relevant about the header */ -/* should change while we have a valid object pointer to the block. */ +/* Check that if p is a pointer to a heap page, then it points to */ +/* a valid displacement within a heap object. */ +/* Uninteresting with GC_all_interior_pointers. */ +/* Always returns its argument. */ +/* Note that we don't lock, since nothing relevant about the header */ +/* should change while we have a valid object pointer to the block. */ GC_API void * GC_CALL GC_is_valid_displacement(void *p) { hdr *hhdr; @@ -121,27 +121,27 @@ GC_API void * GC_CALL GC_is_valid_displacement(void *p) word offset; struct hblk *h; word sz; - + if (!GC_is_initialized) GC_init(); hhdr = HDR((word)p); if (hhdr == 0) return(p); h = HBLKPTR(p); if (GC_all_interior_pointers) { - while (IS_FORWARDING_ADDR_OR_NIL(hhdr)) { - h = FORWARDED_ADDR(h, hhdr); - hhdr = HDR(h); - } + while (IS_FORWARDING_ADDR_OR_NIL(hhdr)) { + h = FORWARDED_ADDR(h, hhdr); + hhdr = HDR(h); + } } if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) { - goto fail; + goto fail; } sz = hhdr -> hb_sz; pdispl = HBLKDISPL(p); offset = pdispl % sz; if ((sz > MAXOBJBYTES && (ptr_t)p >= (ptr_t)h + sz) - || !GC_valid_offsets[offset] - || (ptr_t)p - offset + sz > (ptr_t)(h + 1)) { - goto fail; + || !GC_valid_offsets[offset] + || (ptr_t)p - offset + sz > (ptr_t)(h + 1)) { + goto fail; } return(p); fail: @@ -156,42 +156,42 @@ STATIC void GC_CALLBACK GC_default_is_visible_print_proc(void * p) } void (GC_CALLBACK *GC_is_visible_print_proc)(void * p) = - GC_default_is_visible_print_proc; + GC_default_is_visible_print_proc; #ifndef THREADS /* Could p be a stack address? */ STATIC GC_bool GC_on_stack(ptr_t p) { - int dummy; -# ifdef STACK_GROWS_DOWN - if ((ptr_t)p >= (ptr_t)(&dummy) && (ptr_t)p < GC_stackbottom ) { - return(TRUE); - } -# else - if ((ptr_t)p <= (ptr_t)(&dummy) && (ptr_t)p > GC_stackbottom ) { - return(TRUE); - } -# endif - return(FALSE); + int dummy; +# ifdef STACK_GROWS_DOWN + if ((ptr_t)p >= (ptr_t)(&dummy) && (ptr_t)p < GC_stackbottom ) { + return(TRUE); + } +# else + if ((ptr_t)p <= (ptr_t)(&dummy) && (ptr_t)p > GC_stackbottom ) { + return(TRUE); + } +# endif + return(FALSE); } #endif -/* Check that p is visible */ -/* to the collector as a possibly pointer containing location. */ -/* If it isn't invoke *GC_is_visible_print_proc. */ -/* Returns the argument in all cases. May erroneously succeed */ -/* in hard cases. (This is intended for debugging use with */ -/* untyped allocations. The idea is that it should be possible, though */ -/* slow, to add such a call to all indirect pointer stores.) */ -/* Currently useless for multithreaded worlds. */ +/* Check that p is visible */ +/* to the collector as a possibly pointer containing location. */ +/* If it isn't invoke *GC_is_visible_print_proc. */ +/* Returns the argument in all cases. May erroneously succeed */ +/* in hard cases. (This is intended for debugging use with */ +/* untyped allocations. The idea is that it should be possible, though */ +/* slow, to add such a call to all indirect pointer stores.) */ +/* Currently useless for multithreaded worlds. */ GC_API void * GC_CALL GC_is_visible(void *p) { hdr *hhdr; - + if ((word)p & (ALIGNMENT - 1)) goto fail; if (!GC_is_initialized) GC_init(); # ifdef THREADS - hhdr = HDR((word)p); + hhdr = HDR((word)p); if (hhdr != 0 && GC_base(p) == 0) { goto fail; } else { @@ -199,56 +199,56 @@ GC_API void * GC_CALL GC_is_visible(void *p) return(p); } # else - /* Check stack first: */ - if (GC_on_stack(p)) return(p); - hhdr = HDR((word)p); - if (hhdr == 0) { - if (GC_is_static_root(p)) return(p); - /* Else do it again correctly: */ + /* Check stack first: */ + if (GC_on_stack(p)) return(p); + hhdr = HDR((word)p); + if (hhdr == 0) { + if (GC_is_static_root(p)) return(p); + /* Else do it again correctly: */ # if (defined(DYNAMIC_LOADING) || defined(MSWIN32) || \ - defined(MSWINCE) || defined(PCR)) - GC_register_dynamic_libraries(); - if (GC_is_static_root(p)) - return(p); -# endif - goto fail; - } else { - /* p points to the heap. */ - word descr; - ptr_t base = GC_base(p); /* Should be manually inlined? */ - - if (base == 0) goto fail; - if (HBLKPTR(base) != HBLKPTR(p)) hhdr = HDR((word)p); - descr = hhdr -> hb_descr; + defined(MSWINCE) || defined(PCR)) + GC_register_dynamic_libraries(); + if (GC_is_static_root(p)) + return(p); +# endif + goto fail; + } else { + /* p points to the heap. */ + word descr; + ptr_t base = GC_base(p); /* Should be manually inlined? */ + + if (base == 0) goto fail; + if (HBLKPTR(base) != HBLKPTR(p)) hhdr = HDR((word)p); + descr = hhdr -> hb_descr; retry: - switch(descr & GC_DS_TAGS) { - case GC_DS_LENGTH: - if ((word)((ptr_t)p - (ptr_t)base) > (word)descr) goto fail; - break; - case GC_DS_BITMAP: - if ((ptr_t)p - (ptr_t)base - >= WORDS_TO_BYTES(BITMAP_BITS) - || ((word)p & (sizeof(word) - 1))) goto fail; - if (!(((word)1 << (WORDSZ - ((ptr_t)p - (ptr_t)base) - 1)) - & descr)) goto fail; - break; - case GC_DS_PROC: - /* We could try to decipher this partially. */ - /* For now we just punt. */ - break; - case GC_DS_PER_OBJECT: - if ((signed_word)descr >= 0) { - descr = *(word *)((ptr_t)base + (descr & ~GC_DS_TAGS)); - } else { - ptr_t type_descr = *(ptr_t *)base; - descr = *(word *)(type_descr - - (descr - (GC_DS_PER_OBJECT - - GC_INDIR_PER_OBJ_BIAS))); - } - goto retry; - } - return(p); - } + switch(descr & GC_DS_TAGS) { + case GC_DS_LENGTH: + if ((word)((ptr_t)p - (ptr_t)base) > (word)descr) goto fail; + break; + case GC_DS_BITMAP: + if ((ptr_t)p - (ptr_t)base + >= WORDS_TO_BYTES(BITMAP_BITS) + || ((word)p & (sizeof(word) - 1))) goto fail; + if (!(((word)1 << (WORDSZ - ((ptr_t)p - (ptr_t)base) - 1)) + & descr)) goto fail; + break; + case GC_DS_PROC: + /* We could try to decipher this partially. */ + /* For now we just punt. */ + break; + case GC_DS_PER_OBJECT: + if ((signed_word)descr >= 0) { + descr = *(word *)((ptr_t)base + (descr & ~GC_DS_TAGS)); + } else { + ptr_t type_descr = *(ptr_t *)base; + descr = *(word *)(type_descr + - (descr - (GC_DS_PER_OBJECT + - GC_INDIR_PER_OBJ_BIAS))); + } + goto retry; + } + return(p); + } # endif fail: (*GC_is_visible_print_proc)((ptr_t)p); @@ -260,9 +260,9 @@ GC_API void * GC_CALL GC_pre_incr (void **p, ptrdiff_t how_much) { void * initial = *p; void * result = GC_same_obj((void *)((ptr_t)initial + how_much), initial); - + if (!GC_all_interior_pointers) { - (void) GC_is_valid_displacement(result); + (void) GC_is_valid_displacement(result); } return (*p = result); } @@ -271,9 +271,9 @@ GC_API void * GC_CALL GC_post_incr (void **p, ptrdiff_t how_much) { void * initial = *p; void * result = GC_same_obj((void *)((ptr_t)initial + how_much), initial); - + if (!GC_all_interior_pointers) { - (void) GC_is_valid_displacement(result); + (void) GC_is_valid_displacement(result); } *p = result; return(initial); -- cgit v1.2.1