]> granicus.if.org Git - gc/commitdiff
Implement precise value boundary check in GC_is_thread_tsd_valid
authorIvan Maidanski <ivmai@mail.ru>
Tue, 15 Nov 2011 11:01:52 +0000 (15:01 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 15 Nov 2011 11:52:00 +0000 (15:52 +0400)
* pthread_support.c (GC_is_thread_tsd_valid): Check tsd more correctly
using GC_thread and thread_local_freelists declarations; remove FIXME.
* win32_threads.c (GC_is_thread_tsd_valid): Likewise.

pthread_support.c
win32_threads.c

index 38f4476d6aed7e2266d0d426554d2bf58a78d436..90af826984d5df0a1bfe865013ed2a8b027a01b9 100644 (file)
@@ -312,6 +312,7 @@ STATIC long GC_nprocs = 1;
 #   if defined(USE_CUSTOM_SPECIFIC)
       void GC_check_tsd_marks(tsd *key);
 #   endif
+
     /* Check that all thread-local free-lists are completely marked.    */
     /* Also check that thread-specific-data structures are marked.      */
     void GC_check_tls(void)
@@ -331,6 +332,7 @@ STATIC long GC_nprocs = 1;
 #       endif
     }
 # endif /* GC_ASSERTIONS */
+
 #endif /* THREAD_LOCAL_ALLOC */
 
 #ifdef PARALLEL_MARK
@@ -600,16 +602,14 @@ GC_INNER unsigned char *GC_check_finalizer_nested(void)
   /* This is called from thread-local GC_malloc(). */
   GC_bool GC_is_thread_tsd_valid(void *tsd)
   {
-    char *me;
+    GC_thread me;
     DCL_LOCK_STATE;
 
     LOCK();
-    me = (char *)GC_lookup_thread(pthread_self());
+    me = GC_lookup_thread(pthread_self());
     UNLOCK();
-    /* FIXME: We can check tsd more correctly (since now we have access */
-    /* to the right declarations).  This old algorithm (moved from      */
-    /* thread_local_alloc.c) checks only that it's close.               */
-    return((char *)tsd > me && (char *)tsd < me + 1000);
+    return (char *)tsd >= (char *)&me->tlfs
+            && (char *)tsd < (char *)&me->tlfs + sizeof(me->tlfs);
   }
 #endif /* GC_ASSERTIONS && THREAD_LOCAL_ALLOC */
 
index 0c841107de1fdb74b8213d6debcee4f7c6667daa..69817c8563c3668431986f3b79b3bf1208cd2fc7 100644 (file)
@@ -572,18 +572,16 @@ GC_INNER unsigned char *GC_check_finalizer_nested(void)
   /* This is called from thread-local GC_malloc(). */
   GC_bool GC_is_thread_tsd_valid(void *tsd)
   {
-    char *me;
+    GC_thread me;
     DCL_LOCK_STATE;
 
     LOCK();
-    me = (char *)GC_lookup_thread_inner(GetCurrentThreadId());
+    me = GC_lookup_thread_inner(GetCurrentThreadId());
     UNLOCK();
-    /* FIXME: We can check tsd more correctly (since now we have access */
-    /* to the right declarations).  This old algorithm (moved from      */
-    /* thread_local_alloc.c) checks only that it's close.               */
-    return((char *)tsd > me && (char *)tsd < me + 1000);
+    return (char *)tsd >= (char *)&me->tlfs
+            && (char *)tsd < (char *)&me->tlfs + sizeof(me->tlfs);
   }
-#endif
+#endif /* GC_ASSERTIONS && THREAD_LOCAL_ALLOC */
 
 /* Make sure thread descriptor t is not protected by the VDB            */
 /* implementation.                                                      */