@@ -122,6 +122,12 @@ private:
122
122
Array! (DSO * ) _deps; // D libraries needed by this DSO
123
123
void * _handle; // corresponding handle
124
124
}
125
+
126
+ // get the TLS range for the executing thread
127
+ void [] tlsRange () const nothrow @nogc
128
+ {
129
+ return getTLSRange (_tlsMod, _tlsSize);
130
+ }
125
131
}
126
132
127
133
/* ***
@@ -302,7 +308,7 @@ version (Shared)
302
308
// update the _tlsRange for the executing thread
303
309
void updateTLSRange () nothrow @nogc
304
310
{
305
- _tlsRange = getTLSRange( _pdso._tlsMod, _pdso._tlsSize );
311
+ _tlsRange = _pdso.tlsRange( );
306
312
}
307
313
}
308
314
Array! (ThreadDSO) _loadedDSOs;
@@ -404,15 +410,14 @@ extern(C) void _d_dso_registry(CompilerDSOData* data)
404
410
* thread with a refCnt of 1 and call the TlsCtors.
405
411
*/
406
412
immutable ushort refCnt = 1 , addCnt = 0 ;
407
- auto tlsRng = getTLSRange(pdso._tlsMod, pdso._tlsSize);
408
- _loadedDSOs.insertBack(ThreadDSO(pdso, refCnt, addCnt, tlsRng));
413
+ _loadedDSOs.insertBack(ThreadDSO(pdso, refCnt, addCnt, pdso.tlsRange()));
409
414
}
410
415
}
411
416
else
412
417
{
413
418
foreach (p; _loadedDSOs) assert (p ! is pdso);
414
419
_loadedDSOs.insertBack(pdso);
415
- _tlsRanges.insertBack(getTLSRange( pdso._tlsMod, pdso._tlsSize ));
420
+ _tlsRanges.insertBack(pdso.tlsRange( ));
416
421
}
417
422
418
423
// don't initialize modules before rt_init was called (see Bugzilla 11378)
@@ -509,8 +514,7 @@ version (Shared)
509
514
foreach (dep; pdso._deps)
510
515
incThreadRef(dep, false );
511
516
immutable ushort refCnt = 1 , addCnt = incAdd ? 1 : 0 ;
512
- auto tlsRng = getTLSRange(pdso._tlsMod, pdso._tlsSize);
513
- _loadedDSOs.insertBack(ThreadDSO(pdso, refCnt, addCnt, tlsRng));
517
+ _loadedDSOs.insertBack(ThreadDSO(pdso, refCnt, addCnt, pdso.tlsRange()));
514
518
pdso._moduleGroup.runTlsCtors();
515
519
}
516
520
}
@@ -623,22 +627,22 @@ void freeDSO(DSO* pdso) nothrow @nogc
623
627
version (Shared)
624
628
{
625
629
@nogc nothrow :
626
- link_map* linkMapForHandle (void * handle) nothrow @nogc
630
+ link_map* linkMapForHandle (void * handle)
627
631
{
628
632
link_map* map;
629
633
dlinfo(handle, RTLD_DI_LINKMAP , &map) == 0 || assert (0 );
630
634
return map;
631
635
}
632
636
633
- link_map* exeLinkMap (link_map* map) nothrow @nogc
637
+ link_map* exeLinkMap (link_map* map)
634
638
{
635
639
assert (map);
636
640
while (map.l_prev ! is null )
637
641
map = map.l_prev;
638
642
return map;
639
643
}
640
644
641
- DSO * dsoForHandle (void * handle) nothrow @nogc
645
+ DSO * dsoForHandle (void * handle)
642
646
{
643
647
DSO * pdso;
644
648
! pthread_mutex_lock(&_handleToDSOMutex) || assert (0 );
@@ -648,23 +652,23 @@ version (Shared)
648
652
return pdso;
649
653
}
650
654
651
- void setDSOForHandle (DSO * pdso, void * handle) nothrow @nogc
655
+ void setDSOForHandle (DSO * pdso, void * handle)
652
656
{
653
657
! pthread_mutex_lock(&_handleToDSOMutex) || assert (0 );
654
658
assert (handle ! in _handleToDSO);
655
659
_handleToDSO[handle] = pdso;
656
660
! pthread_mutex_unlock(&_handleToDSOMutex) || assert (0 );
657
661
}
658
662
659
- void unsetDSOForHandle (DSO * pdso, void * handle) nothrow @nogc
663
+ void unsetDSOForHandle (DSO * pdso, void * handle)
660
664
{
661
665
! pthread_mutex_lock(&_handleToDSOMutex) || assert (0 );
662
666
assert (_handleToDSO[handle] == pdso);
663
667
_handleToDSO.remove(handle);
664
668
! pthread_mutex_unlock(&_handleToDSOMutex) || assert (0 );
665
669
}
666
670
667
- void getDependencies (in ref dl_phdr_info info, ref Array! (DSO * ) deps) nothrow @nogc
671
+ void getDependencies (in ref dl_phdr_info info, ref Array! (DSO * ) deps)
668
672
{
669
673
// get the entries of the .dynamic section
670
674
ElfW! " Dyn" [] dyns;
@@ -716,7 +720,7 @@ version (Shared)
716
720
}
717
721
}
718
722
719
- void * handleForName (const char * name) nothrow @nogc
723
+ void * handleForName (const char * name)
720
724
{
721
725
auto handle = .dlopen(name, RTLD_NOLOAD | RTLD_LAZY );
722
726
if (handle ! is null ) .dlclose(handle); // drop reference count
@@ -770,59 +774,51 @@ void scanSegments(in ref dl_phdr_info info, DSO* pdso) nothrow @nogc
770
774
771
775
/* *************************
772
776
* Input:
773
- * result where the output is to be written; dl_phdr_info is a Linux struct
777
+ * result where the output is to be written; dl_phdr_info is an OS struct
774
778
* Returns:
775
779
* true if found, and *result is filled in
776
780
* References:
777
781
* http://linux.die.net/man/3/dl_iterate_phdr
778
782
*/
779
- version ( linux ) bool findDSOInfoForAddr(in void * addr, dl_phdr_info* result=null ) nothrow @nogc
783
+ bool findDSOInfoForAddr (in void * addr, dl_phdr_info* result=null ) nothrow @nogc
780
784
{
781
- static struct DG { const (void )* addr; dl_phdr_info* result; }
785
+ version (linux ) enum IterateManually = true ;
786
+ else version (NetBSD ) enum IterateManually = true ;
787
+ else enum IterateManually = false ;
782
788
783
- extern ( C ) int callback(dl_phdr_info * info, size_t sz, void * arg) nothrow @nogc
789
+ static if (IterateManually)
784
790
{
785
- auto p = cast (DG * )arg;
786
- if (findSegmentForAddr(* info, p.addr))
791
+ static struct DG { const (void )* addr; dl_phdr_info* result; }
792
+
793
+ extern (C ) int callback(dl_phdr_info* info, size_t sz, void * arg) nothrow @nogc
787
794
{
788
- if (p.result ! is null ) * p.result = * info;
789
- return 1 ; // break;
795
+ auto p = cast (DG * )arg;
796
+ if (findSegmentForAddr(* info, p.addr))
797
+ {
798
+ if (p.result ! is null ) * p.result = * info;
799
+ return 1 ; // break;
800
+ }
801
+ return 0 ; // continue iteration
790
802
}
791
- return 0 ; // continue iteration
792
- }
793
803
794
- auto dg = DG (addr, result);
804
+ auto dg = DG (addr, result);
795
805
796
- /* Linux function that walks through the list of an application's shared objects and
797
- * calls 'callback' once for each object, until either all shared objects
798
- * have been processed or 'callback' returns a nonzero value.
799
- */
800
- return dl_iterate_phdr (&callback, &dg) != 0 ;
801
- }
802
- else version (FreeBSD ) bool findDSOInfoForAddr(in void * addr, dl_phdr_info* result=null ) nothrow @nogc
803
- {
804
- return !! _rtld_addr_phdr(addr, result);
805
- }
806
- else version (NetBSD ) bool findDSOInfoForAddr(in void * addr, dl_phdr_info* result=null ) nothrow @nogc
807
- {
808
- static struct DG { const (void )* addr; dl_phdr_info* result; }
809
-
810
- extern (C ) int callback(dl_phdr_info* info, size_t sz, void * arg) nothrow @nogc
806
+ /* OS function that walks through the list of an application's shared objects and
807
+ * calls 'callback' once for each object, until either all shared objects
808
+ * have been processed or 'callback' returns a nonzero value.
809
+ */
810
+ return dl_iterate_phdr (&callback, &dg) != 0 ;
811
+ }
812
+ else version (FreeBSD )
811
813
{
812
- auto p = cast (DG * )arg;
813
- if (findSegmentForAddr(* info, p.addr))
814
- {
815
- if (p.result ! is null ) * p.result = * info;
816
- return 1 ; // break;
817
- }
818
- return 0 ; // continue iteration
814
+ return !! _rtld_addr_phdr(addr, result);
819
815
}
820
- auto dg = DG (addr, result);
821
- return dl_iterate_phdr (&callback, &dg) != 0 ;
822
- }
823
- else version ( DragonFlyBSD ) bool findDSOInfoForAddr( in void * addr, dl_phdr_info * result= null ) nothrow @nogc
824
- {
825
- return !! _rtld_addr_phdr(addr, result );
816
+ else version ( DragonFlyBSD )
817
+ {
818
+ return !! _rtld_addr_phdr(addr, result);
819
+ }
820
+ else
821
+ static assert ( 0 , " unimplemented " );
826
822
}
827
823
828
824
/* ********************************
0 commit comments