From d692eb4322d9b4c3dac4498771fe6707ac87a353 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 16 Feb 2012 21:28:07 +0400 Subject: [PATCH] Add assertion ensuring proper alignment of 'pushed' GC symbols * finalize.c (GC_push_finalizer_structures): Assert word alignment of dl_head, fo_head, GC_finalize_now. * pthread_support.c (GC_thr_init): Assert word alignment of GC_threads (passed to GC_push_all). * win32_threads.c (GC_thr_init): Likewise. * thread_local_alloc.c (GC_init_thread_local): Assert word alignment of GC_thread_key. * typd_mlc.c (GC_add_ext_descriptor): Assert word alignment of GC_ext_descriptors. --- finalize.c | 4 ++++ pthread_support.c | 1 + thread_local_alloc.c | 1 + typd_mlc.c | 1 + win32_threads.c | 2 ++ 5 files changed, 9 insertions(+) diff --git a/finalize.c b/finalize.c index 012c3357..ae87e525 100644 --- a/finalize.c +++ b/finalize.c @@ -73,6 +73,10 @@ static signed_word log_fo_table_size = -1; GC_INNER void GC_push_finalizer_structures(void) { + GC_ASSERT((word)&dl_head % sizeof(word) == 0); + GC_ASSERT((word)&fo_head % sizeof(word) == 0); + GC_ASSERT((word)&GC_finalize_now % sizeof(word) == 0); + GC_push_all((ptr_t)(&dl_head), (ptr_t)(&dl_head) + sizeof(word)); GC_push_all((ptr_t)(&fo_head), (ptr_t)(&fo_head) + sizeof(word)); GC_push_all((ptr_t)(&GC_finalize_now), diff --git a/pthread_support.c b/pthread_support.c index a376bac2..75b6e76c 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -976,6 +976,7 @@ GC_INNER void GC_thr_init(void) if (GC_thr_initialized) return; GC_thr_initialized = TRUE; + GC_ASSERT((word)&GC_threads % sizeof(word) == 0); # ifdef HANDLE_FORK /* Prepare for a possible fork. */ pthread_atfork(GC_fork_prepare_proc, GC_fork_parent_proc, diff --git a/thread_local_alloc.c b/thread_local_alloc.c index 72d09c83..d7031e3b 100644 --- a/thread_local_alloc.c +++ b/thread_local_alloc.c @@ -90,6 +90,7 @@ GC_INNER void GC_init_thread_local(GC_tlfs p) GC_ASSERT(I_HOLD_LOCK()); if (!EXPECT(keys_initialized, TRUE)) { + GC_ASSERT((word)&GC_thread_key % sizeof(word) == 0); if (0 != GC_key_create(&GC_thread_key, 0)) { ABORT("Failed to create key for local allocator"); } diff --git a/typd_mlc.c b/typd_mlc.c index 0326532a..36d1e612 100644 --- a/typd_mlc.c +++ b/typd_mlc.c @@ -126,6 +126,7 @@ STATIC signed_word GC_add_ext_descriptor(const GC_word * bm, word nbits) word ed_size = GC_ed_size; if (ed_size == 0) { + GC_ASSERT((word)&GC_ext_descriptors % sizeof(word) == 0); GC_push_typed_structures = GC_push_typed_structures_proc; UNLOCK(); new_size = ED_INITIAL_SIZE; diff --git a/win32_threads.c b/win32_threads.c index 09e8a56a..153463aa 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -2251,6 +2251,8 @@ GC_INNER void GC_thr_init(void) GC_ASSERT(I_HOLD_LOCK()); if (GC_thr_initialized) return; + + GC_ASSERT((word)&GC_threads % sizeof(word) == 0); GC_main_thread = GetCurrentThreadId(); GC_thr_initialized = TRUE; -- 2.40.0