@@ -15,6 +15,7 @@ import (
1515)
1616
1717type TSDInfo = support.TSDInfo
18+ type DTVInfo = support.DTVInfo
1819
1920// LibcInfo contains introspection information extracted from the C-library
2021type LibcInfo struct {
@@ -24,15 +25,31 @@ type LibcInfo struct {
2425 DTVInfo DTVInfo
2526}
2627
28+ var (
29+ // regex for the libc
30+ libcRegex = regexp .MustCompile (`.*/(ld-musl|ld-linux|libc|libpthread)([-.].*)?\.so` )
31+ )
2732
28- // TODO comment
29- type DTVInfo struct {
30- // Offset is the offset of DTV from FS base (or from thread pointer)
31- Offset int64
32- // EntryWidth is the size of each DTV entry in bytes
33- EntryWidth uint32
34- // Indirect is 0 if DTV is at FS+offset, 1 if at [FS+0]+offset
35- Indirect uint8
33+ // IsPotentialLibcDSO determines if the DSO filename potentially contains libc code
34+ func IsPotentialLibcDSO (filename string ) bool {
35+ return libcRegex .MatchString (filename )
36+ }
37+
38+ func ExtractLibcInfo (ef * pfelf.File ) (* LibcInfo , error ) {
39+ tsdinfo , err := extractTSDInfo (ef )
40+ if err != nil {
41+ return nil , err
42+ }
43+
44+ dtvinfo , err := extractDTVInfo (ef )
45+ if err != nil {
46+ return & LibcInfo {}, err
47+ }
48+
49+ return & LibcInfo {
50+ TSDInfo : tsdinfo ,
51+ DTVInfo : dtvinfo ,
52+ }, nil
3653}
3754
3855// This code analyzes the C-library provided POSIX defined function which is used
@@ -80,33 +97,6 @@ type DTVInfo struct {
8097//
8198// Reading the value is basically "return self->specific_1stblock[key].data;"
8299
83- var (
84- // regex for the libc
85- libcRegex = regexp .MustCompile (`.*/(ld-musl|libc|libpthread)([-.].*)?\.so` )
86- )
87-
88- // IsPotentialTSDDSO determines if the DSO filename potentially contains pthread code
89- func IsPotentialTSDDSO (filename string ) bool {
90- return libcRegex .MatchString (filename )
91- }
92-
93- func ExtractLibcInfo (ef * pfelf.File ) (* LibcInfo , error ) {
94- tsdinfo , err := extractTSDInfo (ef )
95- if err != nil {
96- return nil , err
97- }
98-
99- dtvinfo , err := extractDTVInfo (ef )
100- if err != nil {
101- return & LibcInfo {}, err
102- }
103-
104- return & LibcInfo {
105- TSDInfo : tsdinfo ,
106- DTVInfo : dtvinfo ,
107- }, nil
108- }
109-
110100// extractTSDInfo extracts the introspection data for pthread thread specific data.
111101func extractTSDInfo (ef * pfelf.File ) (TSDInfo , error ) {
112102 _ , code , err := ef .SymbolData ("__pthread_getspecific" , 2048 )
0 commit comments