- TLVHandler *h = malloc(sizeof(TLVHandler));
- h->state = state;
- h->handler = Block_copy(handler);
-
- TLVHandler *old;
- do {
- old = tlv_handlers;
- h->next = old;
- } while (! OSAtomicCompareAndSwapPtrBarrier(old, h, (void * volatile *)&tlv_handlers));
-}
-
-
-void dyld_enumerate_tlv_storage(dyld_tlv_state_change_handler handler)
-{
- pthread_mutex_lock(&tlv_live_image_lock);
- unsigned int count = tlv_live_image_used_count;
- void *list[count];
- for (unsigned int i = 0; i < count; ++i) {
- list[i] = pthread_getspecific(tlv_live_images[i].key);
- }
- pthread_mutex_unlock(&tlv_live_image_lock);
-
- for (unsigned int i = 0; i < count; ++i) {
- if (list[i]) {
- dyld_tlv_info info = { sizeof(info), list[i], malloc_size(list[i]) };
- handler(dyld_tlv_state_allocated, &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.
+ if ( mh->flags & MH_HAS_TLV_DESCRIPTORS )
+ tlv_initialize_descriptors(mh);