Lines Matching refs:g
34 const Global *g; member
43 Global g; member
58 ALWAYS_INLINE void PoisonShadowForGlobal(const Global *g, u8 value) { in PoisonShadowForGlobal() argument
59 FastPoisonShadow(g->beg, g->size_with_redzone, value); in PoisonShadowForGlobal()
62 ALWAYS_INLINE void PoisonRedZones(const Global &g) { in PoisonRedZones() argument
63 uptr aligned_size = RoundUpTo(g.size, ASAN_SHADOW_GRANULARITY); in PoisonRedZones()
64 FastPoisonShadow(g.beg + aligned_size, g.size_with_redzone - aligned_size, in PoisonRedZones()
66 if (g.size != aligned_size) { in PoisonRedZones()
68 g.beg + RoundDownTo(g.size, ASAN_SHADOW_GRANULARITY), in PoisonRedZones()
69 g.size % ASAN_SHADOW_GRANULARITY, ASAN_SHADOW_GRANULARITY, in PoisonRedZones()
76 static bool IsAddressNearGlobal(uptr addr, const __asan_global &g) { in IsAddressNearGlobal() argument
77 if (addr <= g.beg - kMinimalDistanceFromAnotherGlobal) return false; in IsAddressNearGlobal()
78 if (addr >= g.beg + g.size_with_redzone) return false; in IsAddressNearGlobal()
82 static void ReportGlobal(const Global &g, const char *prefix) { in ReportGlobal() argument
84 bool symbolized = Symbolizer::GetOrInit()->SymbolizeData(g.beg, &info); in ReportGlobal()
89 prefix, (void *)&g, (void *)g.beg, g.size, g.size_with_redzone, g.name, in ReportGlobal()
90 g.module_name, (symbolized ? info.module : "?"), g.has_dynamic_init, in ReportGlobal()
91 (void *)g.odr_indicator); in ReportGlobal()
95 } else if (g.gcc_location != 0) { in ReportGlobal()
97 Report(" location: name=%s, %d\n", g.gcc_location->filename, g.gcc_location->line_no); in ReportGlobal()
101 static u32 FindRegistrationSite(const Global *g) { in FindRegistrationSite() argument
106 if (g >= grs.g_first && g <= grs.g_last) in FindRegistrationSite()
118 const Global &g = *l->g; in GetGlobalsForAddress() local
120 ReportGlobal(g, "Search"); in GetGlobalsForAddress()
121 if (IsAddressNearGlobal(addr, g)) { in GetGlobalsForAddress()
122 internal_memcpy(&globals[res], &g, sizeof(g)); in GetGlobalsForAddress()
124 reg_sites[res] = FindRegistrationSite(&g); in GetGlobalsForAddress()
141 static void CheckODRViolationViaIndicator(const Global *g) { in CheckODRViolationViaIndicator() argument
143 if (g->odr_indicator == UINTPTR_MAX) in CheckODRViolationViaIndicator()
145 u8 *odr_indicator = reinterpret_cast<u8 *>(g->odr_indicator); in CheckODRViolationViaIndicator()
153 if (g->odr_indicator == l->g->odr_indicator && in CheckODRViolationViaIndicator()
154 (flags()->detect_odr_violation >= 2 || g->size != l->g->size) && in CheckODRViolationViaIndicator()
155 !IsODRViolationSuppressed(g->name)) in CheckODRViolationViaIndicator()
156 ReportODRViolation(g, FindRegistrationSite(g), in CheckODRViolationViaIndicator()
157 l->g, FindRegistrationSite(l->g)); in CheckODRViolationViaIndicator()
164 static void CheckODRViolationViaPoisoning(const Global *g) { in CheckODRViolationViaPoisoning() argument
165 if (__asan_region_is_poisoned(g->beg, g->size_with_redzone)) { in CheckODRViolationViaPoisoning()
169 if (g->beg == l->g->beg && in CheckODRViolationViaPoisoning()
170 (flags()->detect_odr_violation >= 2 || g->size != l->g->size) && in CheckODRViolationViaPoisoning()
171 !IsODRViolationSuppressed(g->name)) in CheckODRViolationViaPoisoning()
172 ReportODRViolation(g, FindRegistrationSite(g), in CheckODRViolationViaPoisoning()
173 l->g, FindRegistrationSite(l->g)); in CheckODRViolationViaPoisoning()
194 static inline bool UseODRIndicator(const Global *g) { in UseODRIndicator() argument
195 return g->odr_indicator > 0; in UseODRIndicator()
201 static void RegisterGlobal(const Global *g) { in RegisterGlobal() argument
204 ReportGlobal(*g, "Added"); in RegisterGlobal()
206 CHECK(AddrIsInMem(g->beg)); in RegisterGlobal()
207 if (!AddrIsAlignedByGranularity(g->beg)) { in RegisterGlobal()
214 ReportODRViolation(g, FindRegistrationSite(g), g, FindRegistrationSite(g)); in RegisterGlobal()
215 CHECK(AddrIsAlignedByGranularity(g->beg)); in RegisterGlobal()
217 CHECK(AddrIsAlignedByGranularity(g->size_with_redzone)); in RegisterGlobal()
221 if (UseODRIndicator(g)) in RegisterGlobal()
222 CheckODRViolationViaIndicator(g); in RegisterGlobal()
224 CheckODRViolationViaPoisoning(g); in RegisterGlobal()
227 PoisonRedZones(*g); in RegisterGlobal()
229 l->g = g; in RegisterGlobal()
232 if (g->has_dynamic_init) { in RegisterGlobal()
237 DynInitGlobal dyn_global = { *g, false }; in RegisterGlobal()
242 static void UnregisterGlobal(const Global *g) { in UnregisterGlobal() argument
245 ReportGlobal(*g, "Removed"); in UnregisterGlobal()
247 CHECK(AddrIsInMem(g->beg)); in UnregisterGlobal()
248 CHECK(AddrIsAlignedByGranularity(g->beg)); in UnregisterGlobal()
249 CHECK(AddrIsAlignedByGranularity(g->size_with_redzone)); in UnregisterGlobal()
251 PoisonShadowForGlobal(g, 0); in UnregisterGlobal()
257 if (UseODRIndicator(g) && g->odr_indicator != UINTPTR_MAX) { in UnregisterGlobal()
258 u8 *odr_indicator = reinterpret_cast<u8 *>(g->odr_indicator); in UnregisterGlobal()
270 const Global *g = &dyn_g.g; in StopInitOrderChecking() local
272 PoisonShadowForGlobal(g, 0); in StopInitOrderChecking()
274 PoisonRedZones(*g); in StopInitOrderChecking()
293 void PrintGlobalNameIfASCII(InternalScopedString *str, const __asan_global &g) { in PrintGlobalNameIfASCII() argument
294 for (uptr p = g.beg; p < g.beg + g.size - 1; p++) { in PrintGlobalNameIfASCII()
298 if (*(char *)(g.beg + g.size - 1) != '\0') return; in PrintGlobalNameIfASCII()
299 str->AppendF(" '%s' is ascii string '%s'\n", MaybeDemangleGlobalName(g.name), in PrintGlobalNameIfASCII()
300 (char *)g.beg); in PrintGlobalNameIfASCII()
303 void PrintGlobalLocation(InternalScopedString *str, const __asan_global &g, in PrintGlobalLocation() argument
306 if (Symbolizer::GetOrInit()->SymbolizeData(g.beg, &info) && info.line != 0) { in PrintGlobalLocation()
308 } else if (g.gcc_location != 0) { in PrintGlobalLocation()
310 str->AppendF("%s", g.gcc_location->filename ? g.gcc_location->filename in PrintGlobalLocation()
311 : g.module_name); in PrintGlobalLocation()
312 if (g.gcc_location->line_no) in PrintGlobalLocation()
313 str->AppendF(":%d", g.gcc_location->line_no); in PrintGlobalLocation()
314 if (g.gcc_location->column_no) in PrintGlobalLocation()
315 str->AppendF(":%d", g.gcc_location->column_no); in PrintGlobalLocation()
317 str->AppendF("%s", g.module_name); in PrintGlobalLocation()
442 const Global *g = &dyn_g.g; in __asan_before_dynamic_init() local
445 if (g->module_name != module_name) in __asan_before_dynamic_init()
446 PoisonShadowForGlobal(g, kAsanInitializationOrderMagic); in __asan_before_dynamic_init()
465 const Global *g = &dyn_g.g; in __asan_after_dynamic_init() local
468 PoisonShadowForGlobal(g, 0); in __asan_after_dynamic_init()
470 PoisonRedZones(*g); in __asan_after_dynamic_init()