Back to index

lightning-sunbird  0.9+nobinonly
Functions
ptr_chck.c File Reference
#include "gc_priv.h"
#include "gc_mark.h"

Go to the source code of this file.

Functions

void GC_default_same_obj_print_proc (GC_PTR p, GC_PTR q)
void GC_same_obj_print_proc GC_PROTO ((GC_PTR, GC_PTR))
GC_PTR GC_same_obj (char *p, char *q)
void GC_default_is_valid_displacement_print_proc (GC_PTR p)
void
GC_is_valid_displacement_print_proc 
GC_PROTO ((GC_PTR))
char * GC_is_valid_displacement (char *p)
void GC_default_is_visible_print_proc (GC_PTR p)
void GC_is_visible_print_proc GC_PROTO ((GC_PTR p))
GC_bool GC_on_stack (ptr_t p)
char * GC_is_visible (char *p)
GC_PTR GC_pre_incr (GC_PTR *p, size_t how_much)
GC_PTR GC_post_incr (GC_PTR *p, size_t how_much)

Function Documentation

Definition at line 126 of file ptr_chck.c.

{
    GC_err_printf1("0x%lx does not point to valid object displacement\n",
                 (unsigned long)p);
    ABORT("GC_is_valid_displacement test failed");
}

Definition at line 186 of file ptr_chck.c.

{
    GC_err_printf1("0x%lx is not a GC visible pointer location\n",
                 (unsigned long)p);
    ABORT("GC_is_visible test failed");
}

Definition at line 21 of file ptr_chck.c.

{
    GC_err_printf2("0x%lx and 0x%lx are not in the same object\n",
                 (unsigned long)p, (unsigned long)q);
    ABORT("GC_same_obj test failed");
}
char* GC_is_valid_displacement ( char *  p)

Definition at line 147 of file ptr_chck.c.

{
    register hdr *hhdr;
    register word pdispl;
    register struct hblk *h;
    register map_entry_type map_entry;
    register word sz;
    
    if (!GC_is_initialized) GC_init();
    hhdr = HDR((word)p);
    if (hhdr == 0) return(p);
    h = HBLKPTR(p);
#   ifdef ALL_INTERIOR_POINTERS
       while (IS_FORWARDING_ADDR_OR_NIL(hhdr)) {
          h = FORWARDED_ADDR(h, hhdr);
          hhdr = HDR(h);
       }
#   endif
    if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) {
       goto fail;
    }
    sz = WORDS_TO_BYTES(hhdr -> hb_sz);
    pdispl = HBLKDISPL(p);
    map_entry = MAP_ENTRY((hhdr -> hb_map), pdispl);
    if (map_entry == OBJ_INVALID
       || sz > MAXOBJSZ && (ptr_t)p >= (ptr_t)h + sz) {
       goto fail;
    }
    return(p);
fail:
    (*GC_is_valid_displacement_print_proc)((ptr_t)p);
    return(p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* GC_is_visible ( char *  p)

Definition at line 230 of file ptr_chck.c.

{
    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(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 & DS_TAGS) {
               case DS_LENGTH:
                   if ((word)((ptr_t)p - (ptr_t)base) > (word)descr) goto fail;
                   break;
               case 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 DS_PROC:
                   /* We could try to decipher this partially.        */
                   /* For now we just punt.                           */
                   break;
               case DS_PER_OBJECT:
                   descr = *(word *)((ptr_t)base + (descr & ~DS_TAGS));
                   goto retry;
           }
           return(p);
       }
#   endif
fail:
    (*GC_is_visible_print_proc)((ptr_t)p);
    return(p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 199 of file ptr_chck.c.

{
#   ifdef THREADS
       return(TRUE);
#   else
       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
}

Here is the caller graph for this function:

GC_PTR GC_post_incr ( GC_PTR p,
size_t  how_much 
)

Definition at line 314 of file ptr_chck.c.

{
    GC_PTR initial = *p;
    GC_PTR result = GC_same_obj((GC_PTR)((word)initial + how_much), initial);
 
#   ifndef ALL_INTERIOR_POINTERS
       (void) GC_is_valid_displacement(result);
#   endif   
    *p = result;
    return(initial);
}

Here is the call graph for this function:

Here is the caller graph for this function:

GC_PTR GC_pre_incr ( GC_PTR p,
size_t  how_much 
)

Definition at line 301 of file ptr_chck.c.

{
    GC_PTR initial = *p;
    GC_PTR result = GC_same_obj((GC_PTR)((word)initial + how_much), initial);
    
#   ifndef ALL_INTERIOR_POINTERS
       (void) GC_is_valid_displacement(result);
#   endif
    return (*p = result);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void GC_same_obj_print_proc GC_PROTO ( (GC_PTR, GC_PTR )
void GC_is_valid_displacement_print_proc GC_PROTO ( (GC_PTR )
void GC_is_visible_print_proc GC_PROTO ( (GC_PTR p )
GC_PTR GC_same_obj ( char *  p,
char *  q 
)

Definition at line 45 of file ptr_chck.c.

{
    register struct hblk *h;
    register hdr *hhdr;
    register ptr_t base, limit;
    register 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 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)((word *)h + HDR_WORDS + hhdr -> hb_sz);
       if ((ptr_t)p >= limit || (ptr_t)q >= limit || (ptr_t)q < (ptr_t)h ) {
           goto fail;
       }
       return(p);
    }
    sz = WORDS_TO_BYTES(hhdr -> hb_sz);
    if (sz > WORDS_TO_BYTES(MAXOBJSZ)) {
      base = (ptr_t)HBLKPTR(p);
      limit = base + sz;
      if ((ptr_t)p >= limit) {
        goto fail;
      }
    } else {
#     ifdef ALL_INTERIOR_POINTERS
       register map_entry_type map_entry;
       register int pdispl;
       
       pdispl = HBLKDISPL(p);
       map_entry = MAP_ENTRY((hhdr -> hb_map), pdispl);
       if (map_entry == OBJ_INVALID) {
            goto fail;
        } else {
            base = (char *)((word)p & ~(WORDS_TO_BYTES(1) - 1));
            base -= WORDS_TO_BYTES(map_entry);
       }
#     else
       register int offset = HBLKDISPL(p) - HDR_BYTES;
       register word correction = offset % sz;
       
       if (HBLKPTR(p) != HBLKPTR(q)) {
           /* The following computation otherwise fails in this case */
           goto fail;
       }
       base = (ptr_t)p - correction;
#     endif
      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).                                          */
    if ((ptr_t)q >= limit || (ptr_t)q < base) {
       goto fail;
    }
    return(p);
fail:
    (*GC_same_obj_print_proc)((ptr_t)p, (ptr_t)q);
    return(p);
}

Here is the call graph for this function:

Here is the caller graph for this function: