8000 gcc/boehm-gc/ptr_chck.c at profile-stdlib · AEminium/gcc · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
328 lines (305 loc) · 9.38 KB

ptr_chck.c

File metadata and controls

328 lines (305 loc) · 9.38 KB
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. */
#ifdef __STDC__
void * GC_is_visible(void *p)
#else
char *GC_is_visible(p)
char *p;
#endif
{
register hdr *hhdr;
if ((word)p & (ALIGNMENT - 1)) goto fail;
if (!GC_is_initialized) GC_init();
# ifdef THREADS
hhdr = HDR((word)p);
if (hhdr != 0 && GC_base(p) == 0) {
goto fail;
} else {
/* May be inside thread stack. We can't do much. */
return(p);
}
# else
/* Check stack first: */
if (GC_on_stack(p)) return(p);
hhdr = HDR((word)p);
if (hhdr == 0) {
GC_bool result;
if (GC_is_static_root(p)) return(p);
/* Else do it again correctly: */
# if (defined(DYNAMIC_LOADING) || defined(MSWIN32) || \
defined(MSWINCE) || defined(PCR)) \
&& !defined(SRC_M3)
DISABLE_SIGNALS();
GC_register_dynamic_libraries();
result = GC_is_static_root(p);
ENABLE_SIGNALS();
if (result) 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 (!((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);
return(p);
}
GC_PTR GC_pre_incr (p, how_much)
GC_PTR *p;
size_t how_much;
{
GC_PTR initial = *p;
GC_PTR result = GC_same_obj((GC_PTR)((word)initial + how_much), initial);
if (!GC_all_interior_pointers) {
(void) GC_is_valid_displacement(result);
}
return (*p = result);
}
GC_PTR GC_post_incr (p, how_much)
GC_PTR *p;
size_t how_much;
{
GC_PTR initial = *p;
GC_PTR result = GC_same_obj((GC_PTR)((word)initial + how_much), initial);
if (!GC_all_interior_pointers) {
(void) GC_is_valid_displacement(result);
}
*p = result;
return(initial);
}
0