/* file, so this error would be caught by the linker. */
void * GC_clear_stack_inner(void *arg, ptr_t limit)
{
- word dummy[CLEAR_SIZE];
+ volatile word dummy[CLEAR_SIZE];
+ /* volatile prevents the following condition to */
+ /* be 'optimized' to TRUE constant. */
- BZERO(dummy, CLEAR_SIZE*sizeof(word));
+ BZERO((/* no volatile */ void *)dummy, sizeof(dummy));
if ((word)(&dummy[0]) COOLER_THAN (word)limit) {
(void) GC_clear_stack_inner(arg, limit);
}
{
/* LOCK(); -- no longer does anything this early. */
# if !defined(THREADS) && defined(GC_ASSERTIONS)
- word dummy;
+ volatile int dummy;
# endif
word initial_heap_sz;
IF_CANCEL(int cancel_state;)
GC_API void * GC_CALL GC_call_with_stack_base(GC_stack_base_func fn, void *arg)
{
- int dummy;
+ volatile int dummy;
struct GC_stack_base base;
base.mem_base = (void *)&dummy;
GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *sb)
{
- int dummy;
- ptr_t sp = (ptr_t)(&dummy);
- ptr_t trunc_sp = (ptr_t)((word)sp & ~(GC_page_size - 1));
+ volatile int dummy;
+ ptr_t trunc_sp = (ptr_t)((word)(&dummy) & ~(GC_page_size - 1));
/* FIXME: This won't work if called from a deeply recursive */
/* client code (and the committed stack space has grown). */
word size = GC_get_writable_length(trunc_sp, 0);
ptr_t GC_get_main_stack_base(void)
{
- ptr_t result; /* also used as "dummy" to get the approx. sp value */
+# if defined(GC_ASSERTIONS) \
+ || (!defined(STACKBOTTOM) \
+ && (defined(HEURISTIC1) || defined(HEURISTIC2)))
+ volatile int dummy;
+# endif
+ ptr_t result;
# if defined(LINUX) && !defined(NACL) \
&& (defined(USE_GET_STACKBASE_FOR_MAIN) \
|| (defined(THREADS) && !defined(REDIRECT_MALLOC)))
pthread_attr_t attr;
void *stackaddr;
size_t size;
+
if (pthread_getattr_np(pthread_self(), &attr) == 0) {
if (pthread_attr_getstack(&attr, &stackaddr, &size) == 0
&& stackaddr != NULL) {
# define STACKBOTTOM_ALIGNMENT_M1 ((word)STACK_GRAN - 1)
# ifdef HEURISTIC1
# ifdef STACK_GROWS_DOWN
- result = (ptr_t)((((word)(&result)) + STACKBOTTOM_ALIGNMENT_M1)
+ result = (ptr_t)((((word)(&dummy)) + STACKBOTTOM_ALIGNMENT_M1)
& ~STACKBOTTOM_ALIGNMENT_M1);
# else
- result = (ptr_t)(((word)(&result)) & ~STACKBOTTOM_ALIGNMENT_M1);
+ result = (ptr_t)(((word)(&dummy)) & ~STACKBOTTOM_ALIGNMENT_M1);
# endif
# endif /* HEURISTIC1 */
# ifdef LINUX_STACKBOTTOM
# endif
# ifdef HEURISTIC2
# ifdef STACK_GROWS_DOWN
- result = GC_find_limit((ptr_t)(&result), TRUE);
+ result = GC_find_limit((ptr_t)(&dummy), TRUE);
# ifdef HEURISTIC2_LIMIT
if ((word)result > (word)HEURISTIC2_LIMIT
- && (word)(&result) < (word)HEURISTIC2_LIMIT) {
+ && (word)(&dummy) < (word)HEURISTIC2_LIMIT) {
result = HEURISTIC2_LIMIT;
}
# endif
# else
- result = GC_find_limit((ptr_t)(&result), FALSE);
+ result = GC_find_limit((ptr_t)(&dummy), FALSE);
# ifdef HEURISTIC2_LIMIT
if ((word)result < (word)HEURISTIC2_LIMIT
- && (word)(&result) > (word)HEURISTIC2_LIMIT) {
+ && (word)(&dummy) > (word)HEURISTIC2_LIMIT) {
result = HEURISTIC2_LIMIT;
}
# endif
result = (ptr_t)(signed_word)(-sizeof(ptr_t));
# endif
# endif
- GC_ASSERT((word)(&result) HOTTER_THAN (word)result);
+ GC_ASSERT((word)(&dummy) HOTTER_THAN (word)result);
return(result);
}
# define GET_MAIN_STACKBASE_SPECIAL
GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *b)
{
# ifdef GC_ASSERTIONS
- int dummy;
+ volatile int dummy;
# endif
/* pthread_get_stackaddr_np() should return stack bottom (highest */
/* stack address plus 1). */
GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *b)
{
+# ifdef GC_ASSERTIONS
+ volatile int dummy;
+# endif
stack_t s;
pthread_t self = pthread_self();
+
if (self == stackbase_main_self)
{
/* If the client calls GC_get_stack_base() from the main thread */
ABORT("thr_stksegment failed");
}
/* s.ss_sp holds the pointer to the stack bottom. */
- GC_ASSERT((word)(&s) HOTTER_THAN (word)s.ss_sp);
+ GC_ASSERT((word)(&dummy) HOTTER_THAN (word)s.ss_sp);
if (!stackbase_main_self && thr_main() != 0)
{
/* FIXME - Implement better strategies here. */
GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *b)
{
- int dummy;
+ volatile int dummy;
IF_CANCEL(int cancel_state;)
DCL_LOCK_STATE;
b -> reg_base = GC_find_limit(GC_save_regs_in_stack(), FALSE);
# endif
# else
- b -> mem_base = GC_find_limit(&dummy, FALSE);
+ b -> mem_base = GC_find_limit((ptr_t)(&dummy), FALSE);
# endif
RESTORE_CANCEL(cancel_state);
UNLOCK();
/* This is always called from the main thread. Default implementation. */
ptr_t GC_get_main_stack_base(void)
{
+# ifdef GC_ASSERTIONS
+ volatile int dummy;
+# endif
struct GC_stack_base sb;
+
if (GC_get_stack_base(&sb) != GC_SUCCESS)
ABORT("GC_get_stack_base failed");
- GC_ASSERT((word)(&sb) HOTTER_THAN (word)sb.mem_base);
+ GC_ASSERT((word)(&dummy) HOTTER_THAN (word)sb.mem_base);
return (ptr_t)sb.mem_base;
}
#endif /* !GET_MAIN_STACKBASE_SPECIAL */
static void async_set_pht_entry_from_index(volatile page_hash_table db,
size_t index)
{
- unsigned int update_dummy;
+ volatile int update_dummy;
currently_updating = (word)(&update_dummy);
set_pht_entry_from_index(db, index);
/* If we get contention in the 10 or so instruction window here, */
STATIC void GC_suspend_handler_inner(ptr_t sig_arg,
void * context GC_ATTR_UNUSED)
{
+# ifndef SPARC
+ volatile int dummy;
+# endif
pthread_t self = pthread_self();
GC_thread me;
IF_CANCEL(int cancel_state;)
# ifdef SPARC
me -> stop_info.stack_ptr = GC_save_regs_in_stack();
# else
- me -> stop_info.stack_ptr = (ptr_t)(&me);
+ me -> stop_info.stack_ptr = (ptr_t)(&dummy);
# endif
# ifdef IA64
me -> backing_store_ptr = GC_save_regs_in_stack();
GC_API_OSCALL void nacl_pre_syscall_hook(void)
{
- int local_dummy = 0;
+ volatile int dummy;
+
if (GC_nacl_thread_idx != -1) {
NACL_STORE_REGS();
- GC_nacl_gc_thread_self->stop_info.stack_ptr = (ptr_t)(&local_dummy);
+ GC_nacl_gc_thread_self->stop_info.stack_ptr = (ptr_t)(&dummy);
GC_nacl_thread_parked[GC_nacl_thread_idx] = 1;
}
}
GC_API_OSCALL void __nacl_suspend_thread_if_needed(void)
{
+ volatile int dummy;
+
if (GC_nacl_park_threads_now) {
pthread_t self = pthread_self();
- int local_dummy = 0;
/* Don't try to park the thread parker. */
if (GC_nacl_thread_parker == self)
/* so don't bother storing registers again, the GC has a set. */
if (!GC_nacl_thread_parked[GC_nacl_thread_idx]) {
NACL_STORE_REGS();
- GC_nacl_gc_thread_self->stop_info.stack_ptr = (ptr_t)(&local_dummy);
+ GC_nacl_gc_thread_self->stop_info.stack_ptr = (ptr_t)(&dummy);
}
GC_nacl_thread_parked[GC_nacl_thread_idx] = 1;
while (GC_nacl_park_threads_now) {