diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 5a6c843e0..7dd9fdc95 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -292,20 +292,19 @@ typedef struct hblkhdr hdr; #define GC_WORD_MAX (~(word)0) +/* Handy definitions to compare and adjust pointers in a stack. */ #ifdef STACK_GROWS_UP -# define COOLER_THAN < -# define HOTTER_THAN > -# define MAKE_COOLER(p,d) \ +# define HOTTER_THAN(p,q) ((word)(p) > (word)(q)) +# define MAKE_COOLER(p,d) \ (void)((p) -= (word)(p) >= (word)((d) * sizeof(*(p))) ? (d) : 0) -# define MAKE_HOTTER(x,y) (void)((x) += (y)) +# define MAKE_HOTTER(p,d) (void)((p) += (d)) #else -# define COOLER_THAN > -# define HOTTER_THAN < -# define MAKE_COOLER(p,d) \ +# define HOTTER_THAN(p,q) ((word)(p) < (word)(q)) +# define MAKE_COOLER(p,d) \ (void)((p) += (word)(p) <= (word)(GC_WORD_MAX \ - (d) * sizeof(*(p))) ? (d) : 0) -# define MAKE_HOTTER(x,y) (void)((x) -= (y)) -#endif +# define MAKE_HOTTER(p,d) (void)((p) -= (d)) +#endif /* !STACK_GROWS_UP */ #if defined(AMIGA) && defined(__SASC) # define GC_FAR __far @@ -2218,7 +2217,7 @@ void GC_register_data_segments(void); GC_INNER GC_bool GC_is_main_thread(void); # endif #else - GC_INNER GC_bool GC_is_static_root(void *p); + GC_INNER GC_bool GC_is_static_root(ptr_t p); /* Is the address p in one of the registered static */ /* root sections? */ # ifdef TRACE_BUF diff --git a/mark_rts.c b/mark_rts.c index 9cc7fe85c..b5bd50a2e 100644 --- a/mark_rts.c +++ b/mark_rts.c @@ -77,7 +77,7 @@ int GC_no_dls = 0; /* Register dynamic library data segments. */ #ifndef THREADS /* Primarily for debugging support: */ /* Is the address p in one of the registered static root sections? */ - GC_INNER GC_bool GC_is_static_root(void *p) + GC_INNER GC_bool GC_is_static_root(ptr_t p) { static int last_root_set = MAX_ROOT_SETS; int i; @@ -719,7 +719,7 @@ STATIC void GC_push_conditional_with_exclusions(ptr_t bottom, ptr_t top, { GC_ASSERT(I_HOLD_LOCK()); while (traced_stack_sect != NULL) { - GC_ASSERT((word)lo HOTTER_THAN (word)traced_stack_sect); + GC_ASSERT(HOTTER_THAN(lo, (ptr_t)traced_stack_sect)); # ifdef STACK_GROWS_UP GC_push_all_stack((ptr_t)traced_stack_sect, lo); # else @@ -729,7 +729,7 @@ STATIC void GC_push_conditional_with_exclusions(ptr_t bottom, ptr_t top, GC_ASSERT(lo != NULL); traced_stack_sect = traced_stack_sect -> prev; } - GC_ASSERT(!((word)hi HOTTER_THAN (word)lo)); + GC_ASSERT(!HOTTER_THAN(hi, lo)); # ifdef STACK_GROWS_UP /* We got them backwards! */ GC_push_all_stack(hi, lo); @@ -790,11 +790,11 @@ STATIC void GC_push_conditional_with_exclusions(ptr_t bottom, ptr_t top, ptr_t lo /* top */, ptr_t hi /* bottom */, ptr_t cold_gc_frame, struct GC_traced_stack_sect_s *traced_stack_sect) { - GC_ASSERT(traced_stack_sect == NULL || cold_gc_frame == NULL || - (word)cold_gc_frame HOTTER_THAN (word)traced_stack_sect); + GC_ASSERT(traced_stack_sect == NULL || cold_gc_frame == NULL + || HOTTER_THAN(cold_gc_frame, (ptr_t)traced_stack_sect)); while (traced_stack_sect != NULL) { - GC_ASSERT((word)lo HOTTER_THAN (word)traced_stack_sect); + GC_ASSERT(HOTTER_THAN(lo, (ptr_t)traced_stack_sect)); # ifdef STACK_GROWS_UP GC_push_all_stack_partially_eager((ptr_t)traced_stack_sect, lo, cold_gc_frame); @@ -808,7 +808,7 @@ STATIC void GC_push_conditional_with_exclusions(ptr_t bottom, ptr_t top, cold_gc_frame = NULL; /* Use at most once. */ } - GC_ASSERT(!((word)hi HOTTER_THAN (word)lo)); + GC_ASSERT(!HOTTER_THAN(hi, lo)); # ifdef STACK_GROWS_UP /* We got them backwards! */ GC_push_all_stack_partially_eager(hi, lo, cold_gc_frame); diff --git a/misc.c b/misc.c index f6056889f..537420bcf 100644 --- a/misc.c +++ b/misc.c @@ -311,7 +311,7 @@ STATIC void GC_init_size_map(void) volatile word dummy[CLEAR_SIZE]; BZERO((/* no volatile */ word *)((word)dummy), sizeof(dummy)); - if ((word)GC_approx_sp() COOLER_THAN (word)limit) { + if (HOTTER_THAN((/* no volatile */ ptr_t)limit, GC_approx_sp())) { (void)GC_clear_stack_inner(arg, limit); } /* Make sure the recursive call is not a tail call, and the bzero */ @@ -393,15 +393,14 @@ STATIC void GC_init_size_map(void) /* Adjust GC_high_water. */ GC_ASSERT(GC_high_water != NULL); MAKE_COOLER(GC_high_water, WORDS_TO_BYTES(DEGRADE_RATE) + GC_SLOP); - if ((word)sp HOTTER_THAN (word)GC_high_water) { + if (HOTTER_THAN(sp, GC_high_water)) GC_high_water = sp; - } MAKE_HOTTER(GC_high_water, GC_SLOP); { ptr_t limit = GC_min_sp; MAKE_HOTTER(limit, SLOP); - if ((word)sp COOLER_THAN (word)limit) { + if (HOTTER_THAN(limit, sp)) { limit = PTR_ALIGN_DOWN(limit, 0x10); GC_min_sp = sp; return GC_clear_stack_inner(arg, limit); @@ -411,7 +410,7 @@ STATIC void GC_init_size_map(void) /* Restart clearing process, but limit how much clearing we do. */ GC_min_sp = sp; MAKE_HOTTER(GC_min_sp, CLEAR_THRESHOLD/4); - if ((word)GC_min_sp HOTTER_THAN (word)GC_high_water) + if (HOTTER_THAN(GC_min_sp, GC_high_water)) GC_min_sp = GC_high_water; GC_bytes_allocd_at_reset = GC_bytes_allocd; } @@ -1345,7 +1344,7 @@ GC_API void GC_CALL GC_init(void) # endif GC_STATIC_ASSERT(sizeof(struct hblk) == HBLKSIZE); # ifndef THREADS - GC_ASSERT(!((word)GC_stackbottom HOTTER_THAN (word)GC_approx_sp())); + GC_ASSERT(!HOTTER_THAN(GC_stackbottom, GC_approx_sp())); # endif GC_init_headers(); # ifdef SEARCH_FOR_DATA_START @@ -2323,7 +2322,7 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn, void *client_data) /* Adjust our stack bottom pointer (this could happen if */ /* GC_get_main_stack_base() is unimplemented or broken for */ /* the platform). */ - if ((word)GC_stackbottom HOTTER_THAN (word)(&stacksect)) + if (HOTTER_THAN(GC_stackbottom, (ptr_t)(&stacksect))) GC_stackbottom = (ptr_t)COVERT_DATAFLOW(&stacksect); if (GC_blocked_sp == NULL) { diff --git a/os_dep.c b/os_dep.c index d50aa4f02..036576c3c 100644 --- a/os_dep.c +++ b/os_dep.c @@ -1342,8 +1342,8 @@ GC_INNER void GC_setpagesize(void) result = (ptr_t)GC_find_limit(sp, TRUE); # endif # if defined(HEURISTIC2_LIMIT) && !defined(CPPCHECK) - if ((word)result COOLER_THAN (word)HEURISTIC2_LIMIT - && (word)sp HOTTER_THAN (word)HEURISTIC2_LIMIT) + if (HOTTER_THAN(HEURISTIC2_LIMIT, result) + && HOTTER_THAN(sp, HEURISTIC2_LIMIT)) result = HEURISTIC2_LIMIT; # endif } @@ -1358,7 +1358,7 @@ GC_INNER void GC_setpagesize(void) # endif # endif # if !defined(CPPCHECK) - GC_ASSERT((word)GC_approx_sp() HOTTER_THAN (word)result); + GC_ASSERT(HOTTER_THAN(GC_approx_sp(), result)); # endif return result; } @@ -1438,7 +1438,7 @@ GC_INNER void GC_setpagesize(void) /* pthread_get_stackaddr_np() should return stack bottom (highest */ /* stack address plus 1). */ b -> mem_base = pthread_get_stackaddr_np(pthread_self()); - GC_ASSERT((word)GC_approx_sp() HOTTER_THAN (word)b->mem_base); + GC_ASSERT(HOTTER_THAN(GC_approx_sp(), (ptr_t)(b -> mem_base))); return GC_SUCCESS; } # define HAVE_GET_STACK_BASE @@ -1495,7 +1495,7 @@ GC_INNER void GC_setpagesize(void) ABORT("thr_stksegment failed"); } /* s.ss_sp holds the pointer to the stack bottom. */ - GC_ASSERT((word)GC_approx_sp() HOTTER_THAN (word)s.ss_sp); + GC_ASSERT(HOTTER_THAN(GC_approx_sp(), (ptr_t)s.ss_sp)); if (!stackbase_main_self && thr_main() != 0) { @@ -1572,7 +1572,7 @@ GC_INNER void GC_setpagesize(void) if (GC_get_stack_base(&sb) != GC_SUCCESS) ABORT("GC_get_stack_base failed"); - GC_ASSERT((word)GC_approx_sp() HOTTER_THAN (word)sb.mem_base); + GC_ASSERT(HOTTER_THAN(GC_approx_sp(), (ptr_t)sb.mem_base)); return (ptr_t)sb.mem_base; } #endif /* !GET_MAIN_STACKBASE_SPECIAL */ @@ -5347,9 +5347,9 @@ GC_API int GC_CALL GC_get_pages_executable(void) fp = (struct frame *)((long)(frame -> FR_SAVFP) + BIAS); # endif - for (; !((word)fp HOTTER_THAN (word)frame) + for (; !HOTTER_THAN((ptr_t)fp, (ptr_t)frame) # ifndef THREADS - && !((word)GC_stackbottom HOTTER_THAN (word)fp) + && !HOTTER_THAN(GC_stackbottom, (ptr_t)fp) # elif defined(STACK_GROWS_UP) && fp != NULL # endif diff --git a/pthread_support.c b/pthread_support.c index f7188eff7..f479bf6ef 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -2047,7 +2047,7 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn, void *client_data) /* GC_get_stack_base() was used which returned GC_SUCCESS). */ stack_end = crtn -> stack_end; /* read of a volatile field */ GC_ASSERT(stack_end != NULL); - if ((word)stack_end HOTTER_THAN (word)(&stacksect)) { + if (HOTTER_THAN(stack_end, (ptr_t)(&stacksect))) { crtn -> stack_end = (ptr_t)(&stacksect); # if defined(I386) && defined(GC_WIN32_THREADS) crtn -> initial_stack_base = (ptr_t)(&stacksect); diff --git a/ptr_chck.c b/ptr_chck.c index d9c6c4f87..54351ee47 100644 --- a/ptr_chck.c +++ b/ptr_chck.c @@ -136,10 +136,9 @@ GC_valid_ptr_print_proc_t GC_is_visible_print_proc = #ifndef THREADS /* Could p be a stack address? */ - STATIC GC_bool GC_on_stack(void *p) + STATIC GC_bool GC_on_stack(ptr_t p) { - return (word)p HOTTER_THAN (word)GC_stackbottom - && !((word)p HOTTER_THAN (word)GC_approx_sp()); + return HOTTER_THAN(p, GC_stackbottom) && !HOTTER_THAN(p, GC_approx_sp()); } #endif /* !THREADS */ @@ -159,16 +158,16 @@ GC_API void * GC_CALL GC_is_visible(void *p) } # else /* Check stack first: */ - if (GC_on_stack(p)) return p; + if (GC_on_stack((ptr_t)p)) return p; hhdr = HDR(p); if (NULL == hhdr) { - if (GC_is_static_root(p)) return p; + if (GC_is_static_root((ptr_t)p)) return p; /* Else do it again correctly: */ # if defined(DYNAMIC_LOADING) || defined(ANY_MSWIN) || defined(PCR) if (!GC_no_dls) { GC_register_dynamic_libraries(); - if (GC_is_static_root(p)) return p; + if (GC_is_static_root((ptr_t)p)) return p; } # endif goto fail; diff --git a/win32_threads.c b/win32_threads.c index 7956e42c9..9c4519101 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -846,7 +846,7 @@ STATIC word GC_push_stack_for(GC_thread thread, thread_id_t self_id, GC_log_printf("TIB stack limit/base: %p .. %p\n", (void *)tib->StackLimit, (void *)tib->StackBase); # endif - GC_ASSERT(!((word)stack_end COOLER_THAN (word)tib->StackBase)); + GC_ASSERT(!HOTTER_THAN((ptr_t)tib->StackBase, stack_end)); if (stack_end != crtn -> initial_stack_base /* We are in a coroutine (old-style way of the support). */ && ((word)stack_end <= (word)tib->StackLimit