Loading...
src/threadLocalVariables.c dyld-239.4 dyld-421.1
--- dyld/dyld-239.4/src/threadLocalVariables.c
+++ dyld/dyld-421.1/src/threadLocalVariables.c
@@ -78,7 +78,7 @@
 
 
 
-#if __has_feature(tls)
+#if __has_feature(tls) || __arm64__ || __arm__
 
 typedef struct TLVHandler {
 	struct TLVHandler *next;
@@ -237,9 +237,9 @@
 					if ( (sect->flags & SECTION_TYPE) == S_THREAD_LOCAL_INIT_FUNCTION_POINTERS ) {
 						typedef void (*InitFunc)(void);
 						InitFunc* funcs = (InitFunc*)(sect->addr + slide);
-						const uint32_t count = sect->size / sizeof(uintptr_t);
-						for (uint32_t i=count; i > 0; --i) {
-							InitFunc func = funcs[i-1];
+						const size_t count = sect->size / sizeof(uintptr_t);
+						for (size_t j=count; j > 0; --j) {
+							InitFunc func = funcs[j-1];
 							func();
 						}
 					}
@@ -305,17 +305,13 @@
 	}
 }
 
-// called by dyld when a image is loaded
-static const char* tlv_load_notification(enum dyld_image_states state, uint32_t infoCount, const struct dyld_image_info info[])
-{
-	// this is called on all images, even those without TLVs, so we want
-	// this to be fast.  The linker sets MH_HAS_TLV_DESCRIPTORS so we don't
-	// have to search images just to find the don't have TLVs.
-	for (uint32_t i=0; i < infoCount; ++i) {
-		if ( info[i].imageLoadAddress->flags & MH_HAS_TLV_DESCRIPTORS )
-			tlv_initialize_descriptors(info[i].imageLoadAddress);
-	}
-	return NULL;
+
+void tlv_load_notification(const struct mach_header* mh, intptr_t slide)
+{
+	// This is called on all images, even those without TLVs. So we want this to be fast.
+	// The linker sets MH_HAS_TLV_DESCRIPTORS so we don't have to search images just to find the don't have TLVs.
+	if ( mh->flags & MH_HAS_TLV_DESCRIPTORS )
+		tlv_initialize_descriptors(mh);
 }
 
 
@@ -401,7 +397,7 @@
         if ( list->allocCount == list->allocCount ) {
             // handle resizing allocation 
             uint32_t newAllocCount = list->allocCount * 2;
-            uint32_t newAllocSize = offsetof(struct TLVTerminatorList, entries[newAllocCount]);
+            size_t newAllocSize = offsetof(struct TLVTerminatorList, entries[newAllocCount]);
             struct TLVTerminatorList* newlist = (struct TLVTerminatorList*)malloc(newAllocSize);
             newlist->allocCount = newAllocCount;
             newlist->useCount = list->useCount;
@@ -453,7 +449,8 @@
     (void)pthread_key_create(&tlv_terminators_key, &tlv_finalize);
        
     // register with dyld for notification when images are loaded
-    dyld_register_image_state_change_handler(dyld_image_state_bound, true, tlv_load_notification);
+	_dyld_register_func_for_add_image(tlv_load_notification);
+
 }