21
21
#include " asan_suppressions.h"
22
22
#include " asan_thread.h"
23
23
#include " sanitizer_common/sanitizer_common.h"
24
+ #include " sanitizer_common/sanitizer_list.h"
24
25
#include " sanitizer_common/sanitizer_mutex.h"
25
26
#include " sanitizer_common/sanitizer_placement_new.h"
26
27
#include " sanitizer_common/sanitizer_stackdepot.h"
@@ -30,13 +31,14 @@ namespace __asan {
30
31
31
32
typedef __asan_global Global;
32
33
33
- struct ListOfGlobals {
34
- const Global *g;
35
- ListOfGlobals *next;
34
+ struct GlobalListNode {
35
+ const Global *g = nullptr ;
36
+ GlobalListNode *next = nullptr ;
36
37
};
38
+ typedef IntrusiveList<GlobalListNode> ListOfGlobals;
37
39
38
40
static Mutex mu_for_globals;
39
- static ListOfGlobals * list_of_all_globals;
41
+ static ListOfGlobals list_of_all_globals;
40
42
41
43
static const int kDynamicInitGlobalsInitialCapacity = 512 ;
42
44
struct DynInitGlobal {
@@ -73,6 +75,10 @@ ALWAYS_INLINE void PoisonRedZones(const Global &g) {
73
75
74
76
const uptr kMinimalDistanceFromAnotherGlobal = 64 ;
75
77
78
+ static void AddGlobalToList (ListOfGlobals &list, const Global *g) {
79
+ list.push_front (new (GetGlobalLowLevelAllocator ()) GlobalListNode{g});
80
+ }
81
+
76
82
static bool IsAddressNearGlobal (uptr addr, const __asan_global &g) {
77
83
if (addr <= g.beg - kMinimalDistanceFromAnotherGlobal ) return false ;
78
84
if (addr >= g.beg + g.size_with_redzone ) return false ;
@@ -114,8 +120,8 @@ int GetGlobalsForAddress(uptr addr, Global *globals, u32 *reg_sites,
114
120
if (!flags ()->report_globals ) return 0 ;
115
121
Lock lock (&mu_for_globals);
116
122
int res = 0 ;
117
- for (ListOfGlobals *l = list_of_all_globals; l; l = l-> next ) {
118
- const Global &g = *l-> g ;
123
+ for (const auto &l : list_of_all_globals ) {
124
+ const Global &g = *l. g ;
119
125
if (flags ()->report_globals >= 2 )
120
126
ReportGlobal (g, " Search" );
121
127
if (IsAddressNearGlobal (addr, g)) {
@@ -149,12 +155,13 @@ static void CheckODRViolationViaIndicator(const Global *g) {
149
155
}
150
156
// If *odr_indicator is DEFINED, some module have already registered
151
157
// externally visible symbol with the same name. This is an ODR violation.
152
- for (ListOfGlobals *l = list_of_all_globals; l; l = l->next ) {
153
- if (g->odr_indicator == l->g ->odr_indicator &&
154
- (flags ()->detect_odr_violation >= 2 || g->size != l->g ->size ) &&
155
- !IsODRViolationSuppressed (g->name ))
156
- ReportODRViolation (g, FindRegistrationSite (g),
157
- l->g , FindRegistrationSite (l->g ));
158
+ for (const auto &l : list_of_all_globals) {
159
+ if (g->odr_indicator == l.g ->odr_indicator &&
160
+ (flags ()->detect_odr_violation >= 2 || g->size != l.g ->size ) &&
161
+ !IsODRViolationSuppressed (g->name )) {
162
+ ReportODRViolation (g, FindRegistrationSite (g), l.g ,
163
+ FindRegistrationSite (l.g ));
164
+ }
158
165
}
159
166
}
160
167
@@ -165,12 +172,13 @@ static void CheckODRViolationViaPoisoning(const Global *g) {
165
172
if (__asan_region_is_poisoned (g->beg , g->size_with_redzone )) {
166
173
// This check may not be enough: if the first global is much larger
167
174
// the entire redzone of the second global may be within the first global.
168
- for (ListOfGlobals *l = list_of_all_globals; l; l = l->next ) {
169
- if (g->beg == l->g ->beg &&
170
- (flags ()->detect_odr_violation >= 2 || g->size != l->g ->size ) &&
171
- !IsODRViolationSuppressed (g->name ))
172
- ReportODRViolation (g, FindRegistrationSite (g),
173
- l->g , FindRegistrationSite (l->g ));
175
+ for (const auto &l : list_of_all_globals) {
176
+ if (g->beg == l.g ->beg &&
177
+ (flags ()->detect_odr_violation >= 2 || g->size != l.g ->size ) &&
178
+ !IsODRViolationSuppressed (g->name )) {
179
+ ReportODRViolation (g, FindRegistrationSite (g), l.g ,
180
+ FindRegistrationSite (l.g ));
181
+ }
174
182
}
175
183
}
176
184
}
@@ -225,10 +233,9 @@ static void RegisterGlobal(const Global *g) {
225
233
}
226
234
if (CanPoisonMemory ())
227
235
PoisonRedZones (*g);
228
- ListOfGlobals *l = new (GetGlobalLowLevelAllocator ()) ListOfGlobals;
229
- l->g = g;
230
- l->next = list_of_all_globals;
231
- list_of_all_globals = l;
236
+
237
+ AddGlobalToList (list_of_all_globals, g);
238
+
232
239
if (g->has_dynamic_init ) {
233
240
if (!dynamic_init_globals) {
234
241
dynamic_init_globals = new (GetGlobalLowLevelAllocator ()) VectorOfGlobals;
0 commit comments