summaryrefslogtreecommitdiff
path: root/ptr_chck.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2011-07-26 18:09:54 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 18:09:54 +0200
commite35a4171fe47dfbf847e08988ea6cec4dfc8d124 (patch)
tree25f3501669fbf24a4b370c4f8b0c0701b1da4062 /ptr_chck.c
parentffa0c9ea38b3dd87e91b5ed2118c74002fed6782 (diff)
gc7.0alpha1 tarball importgc7_0alpha1
Diffstat (limited to 'ptr_chck.c')
-rw-r--r--ptr_chck.c126
1 files changed, 41 insertions, 85 deletions
diff --git a/ptr_chck.c b/ptr_chck.c
index d83d730..23e183c 100644
--- a/ptr_chck.c
+++ b/ptr_chck.c
@@ -18,19 +18,13 @@
#include "private/gc_pmark.h"
-#ifdef __STDC__
-void GC_default_same_obj_print_proc(GC_PTR p, GC_PTR q)
-#else
-void GC_default_same_obj_print_proc (p, q)
-GC_PTR p, q;
-#endif
+void GC_default_same_obj_print_proc(void * p, void * q)
{
- GC_err_printf2("0x%lx and 0x%lx are not in the same object\n",
- (unsigned long)p, (unsigned long)q);
+ GC_err_printf("%p and %p are not in the same object\n", p, q);
ABORT("GC_same_obj test failed");
}
-void (*GC_same_obj_print_proc) GC_PROTO((GC_PTR, GC_PTR))
+void (*GC_same_obj_print_proc) (void *, void *)
= GC_default_same_obj_print_proc;
/* Check that p and q point to the same object. Call */
@@ -42,17 +36,12 @@ void (*GC_same_obj_print_proc) GC_PROTO((GC_PTR, GC_PTR))
/* We assume this is performance critical. (It shouldn't */
/* be called by production code, but this can easily make */
/* debugging intolerably slow.) */
-#ifdef __STDC__
- GC_PTR GC_same_obj(register void *p, register void *q)
-#else
- GC_PTR GC_same_obj(p, q)
- register char *p, *q;
-#endif
+void * GC_same_obj(void *p, void *q)
{
- register struct hblk *h;
- register hdr *hhdr;
- register ptr_t base, limit;
- register word sz;
+ struct hblk *h;
+ hdr *hhdr;
+ ptr_t base, limit;
+ word sz;
if (!GC_is_initialized) GC_init();
hhdr = HDR((word)p);
@@ -72,13 +61,13 @@ void (*GC_same_obj_print_proc) GC_PROTO((GC_PTR, GC_PTR))
h = FORWARDED_ADDR(h, hhdr);
hhdr = HDR(h);
}
- limit = (ptr_t)((word *)h + hhdr -> hb_sz);
+ 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 = WORDS_TO_BYTES(hhdr -> hb_sz);
+ sz = hhdr -> hb_sz;
if (sz > MAXOBJBYTES) {
base = (ptr_t)HBLKPTR(p);
limit = base + sz;
@@ -86,19 +75,15 @@ void (*GC_same_obj_print_proc) GC_PROTO((GC_PTR, GC_PTR))
goto fail;
}
} else {
- register int map_entry;
- register int pdispl = HBLKDISPL(p);
+ int offset;
+ int pdispl = HBLKDISPL(p);
- map_entry = MAP_ENTRY((hhdr -> hb_map), pdispl);
- if (map_entry > CPP_MAX_OFFSET) {
- map_entry = BYTES_TO_WORDS(pdispl) % BYTES_TO_WORDS(sz);
- if (HBLKPTR(p) != HBLKPTR(q)) goto fail;
+ 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. */
- }
- base = (char *)((word)p & ~(WORDS_TO_BYTES(1) - 1));
- base -= WORDS_TO_BYTES(map_entry);
+ base = (ptr_t)p - offset;
limit = base + sz;
}
/* [base, limit) delimits the object containing p, if any. */
@@ -114,19 +99,13 @@ fail:
return(p);
}
-#ifdef __STDC__
-void GC_default_is_valid_displacement_print_proc (GC_PTR p)
-#else
-void GC_default_is_valid_displacement_print_proc (p)
-GC_PTR p;
-#endif
+void GC_default_is_valid_displacement_print_proc (void *p)
{
- GC_err_printf1("0x%lx does not point to valid object displacement\n",
- (unsigned long)p);
+ GC_err_printf("%p does not point to valid object displacement\n", p);
ABORT("GC_is_valid_displacement test failed");
}
-void (*GC_is_valid_displacement_print_proc) GC_PROTO((GC_PTR)) =
+void (*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 */
@@ -135,18 +114,13 @@ void (*GC_is_valid_displacement_print_proc) GC_PROTO((GC_PTR)) =
/* 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. */
-#ifdef __STDC__
- void * GC_is_valid_displacement(void *p)
-#else
- char *GC_is_valid_displacement(p)
- char *p;
-#endif
+void * GC_is_valid_displacement(void *p)
{
- register hdr *hhdr;
- register word pdispl;
- register struct hblk *h;
- register map_entry_type map_entry;
- register word sz;
+ hdr *hhdr;
+ word pdispl;
+ word offset;
+ struct hblk *h;
+ word sz;
if (!GC_is_initialized) GC_init();
hhdr = HDR((word)p);
@@ -161,11 +135,12 @@ void (*GC_is_valid_displacement_print_proc) GC_PROTO((GC_PTR)) =
if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) {
goto fail;
}
- sz = WORDS_TO_BYTES(hhdr -> hb_sz);
+ sz = hhdr -> hb_sz;
pdispl = HBLKDISPL(p);
- map_entry = MAP_ENTRY((hhdr -> hb_map), pdispl);
- if (map_entry == OBJ_INVALID
- || sz > MAXOBJBYTES && (ptr_t)p >= (ptr_t)h + sz) {
+ 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;
}
return(p);
@@ -174,24 +149,16 @@ fail:
return(p);
}
-#ifdef __STDC__
-void GC_default_is_visible_print_proc(GC_PTR p)
-#else
-void GC_default_is_visible_print_proc(p)
-GC_PTR p;
-#endif
+void GC_default_is_visible_print_proc(void * p)
{
- GC_err_printf1("0x%lx is not a GC visible pointer location\n",
- (unsigned long)p);
+ GC_err_printf("%p is not a GC visible pointer location\n", p);
ABORT("GC_is_visible test failed");
}
-void (*GC_is_visible_print_proc) GC_PROTO((GC_PTR p)) =
- GC_default_is_visible_print_proc;
+void (*GC_is_visible_print_proc)(void * p) = GC_default_is_visible_print_proc;
/* Could p be a stack address? */
-GC_bool GC_on_stack(p)
-ptr_t p;
+GC_bool GC_on_stack(ptr_t p)
{
# ifdef THREADS
return(TRUE);
@@ -218,14 +185,9 @@ ptr_t p;
/* 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
+void * GC_is_visible(void *p)
{
- register hdr *hhdr;
+ hdr *hhdr;
if ((word)p & (ALIGNMENT - 1)) goto fail;
if (!GC_is_initialized) GC_init();
@@ -249,10 +211,8 @@ ptr_t p;
# 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;
@@ -300,12 +260,10 @@ fail:
}
-GC_PTR GC_pre_incr (p, how_much)
-GC_PTR *p;
-size_t how_much;
+void * GC_pre_incr (void **p, size_t how_much)
{
- GC_PTR initial = *p;
- GC_PTR result = GC_same_obj((GC_PTR)((word)initial + how_much), initial);
+ void * initial = *p;
+ void * result = GC_same_obj((void *)((word)initial + how_much), initial);
if (!GC_all_interior_pointers) {
(void) GC_is_valid_displacement(result);
@@ -313,12 +271,10 @@ size_t how_much;
return (*p = result);
}
-GC_PTR GC_post_incr (p, how_much)
-GC_PTR *p;
-size_t how_much;
+void * GC_post_incr (void **p, size_t how_much)
{
- GC_PTR initial = *p;
- GC_PTR result = GC_same_obj((GC_PTR)((word)initial + how_much), initial);
+ void * initial = *p;
+ void * result = GC_same_obj((void *)((word)initial + how_much), initial);
if (!GC_all_interior_pointers) {
(void) GC_is_valid_displacement(result);