Lines Matching refs:g
34 const Global *g; member
44 Global g; member
59 ALWAYS_INLINE void PoisonShadowForGlobal(const Global *g, u8 value) { in PoisonShadowForGlobal() argument
60 FastPoisonShadow(g->beg, g->size_with_redzone, value); in PoisonShadowForGlobal()
63 ALWAYS_INLINE void PoisonRedZones(const Global &g) { in PoisonRedZones() argument
64 uptr aligned_size = RoundUpTo(g.size, SHADOW_GRANULARITY); in PoisonRedZones()
65 FastPoisonShadow(g.beg + aligned_size, g.size_with_redzone - aligned_size, in PoisonRedZones()
67 if (g.size != aligned_size) { in PoisonRedZones()
69 g.beg + RoundDownTo(g.size, SHADOW_GRANULARITY), in PoisonRedZones()
70 g.size % SHADOW_GRANULARITY, in PoisonRedZones()
78 static bool IsAddressNearGlobal(uptr addr, const __asan_global &g) { in IsAddressNearGlobal() argument
79 if (addr <= g.beg - kMinimalDistanceFromAnotherGlobal) return false; in IsAddressNearGlobal()
80 if (addr >= g.beg + g.size_with_redzone) return false; in IsAddressNearGlobal()
84 static void ReportGlobal(const Global &g, const char *prefix) { in ReportGlobal() argument
88 prefix, &g, (void *)g.beg, g.size, g.size_with_redzone, g.name, in ReportGlobal()
89 g.module_name, g.has_dynamic_init, (void *)g.odr_indicator); in ReportGlobal()
90 if (g.location) { in ReportGlobal()
91 Report(" location (%p): name=%s[%p], %d %d\n", g.location, in ReportGlobal()
92 g.location->filename, g.location->filename, g.location->line_no, in ReportGlobal()
93 g.location->column_no); in ReportGlobal()
97 static u32 FindRegistrationSite(const Global *g) { in FindRegistrationSite() argument
102 if (g >= grs.g_first && g <= grs.g_last) in FindRegistrationSite()
114 const Global &g = *l->g; in GetGlobalsForAddress() local
116 ReportGlobal(g, "Search"); in GetGlobalsForAddress()
117 if (IsAddressNearGlobal(addr, g)) { in GetGlobalsForAddress()
118 internal_memcpy(&globals[res], &g, sizeof(g)); in GetGlobalsForAddress()
120 reg_sites[res] = FindRegistrationSite(&g); in GetGlobalsForAddress()
137 static void CheckODRViolationViaIndicator(const Global *g) { in CheckODRViolationViaIndicator() argument
139 if (g->odr_indicator == UINTPTR_MAX) in CheckODRViolationViaIndicator()
141 u8 *odr_indicator = reinterpret_cast<u8 *>(g->odr_indicator); in CheckODRViolationViaIndicator()
149 if (g->odr_indicator == l->g->odr_indicator && in CheckODRViolationViaIndicator()
150 (flags()->detect_odr_violation >= 2 || g->size != l->g->size) && in CheckODRViolationViaIndicator()
151 !IsODRViolationSuppressed(g->name)) in CheckODRViolationViaIndicator()
152 ReportODRViolation(g, FindRegistrationSite(g), in CheckODRViolationViaIndicator()
153 l->g, FindRegistrationSite(l->g)); in CheckODRViolationViaIndicator()
160 static void CheckODRViolationViaPoisoning(const Global *g) { in CheckODRViolationViaPoisoning() argument
161 if (__asan_region_is_poisoned(g->beg, g->size_with_redzone)) { in CheckODRViolationViaPoisoning()
165 if (g->beg == l->g->beg && in CheckODRViolationViaPoisoning()
166 (flags()->detect_odr_violation >= 2 || g->size != l->g->size) && in CheckODRViolationViaPoisoning()
167 !IsODRViolationSuppressed(g->name)) in CheckODRViolationViaPoisoning()
168 ReportODRViolation(g, FindRegistrationSite(g), in CheckODRViolationViaPoisoning()
169 l->g, FindRegistrationSite(l->g)); in CheckODRViolationViaPoisoning()
190 static inline bool UseODRIndicator(const Global *g) { in UseODRIndicator() argument
191 return g->odr_indicator > 0; in UseODRIndicator()
197 static void RegisterGlobal(const Global *g) { in RegisterGlobal() argument
200 ReportGlobal(*g, "Added"); in RegisterGlobal()
202 CHECK(AddrIsInMem(g->beg)); in RegisterGlobal()
203 if (!AddrIsAlignedByGranularity(g->beg)) { in RegisterGlobal()
210 ReportODRViolation(g, FindRegistrationSite(g), g, FindRegistrationSite(g)); in RegisterGlobal()
211 CHECK(AddrIsAlignedByGranularity(g->beg)); in RegisterGlobal()
213 CHECK(AddrIsAlignedByGranularity(g->size_with_redzone)); in RegisterGlobal()
217 if (UseODRIndicator(g)) in RegisterGlobal()
218 CheckODRViolationViaIndicator(g); in RegisterGlobal()
220 CheckODRViolationViaPoisoning(g); in RegisterGlobal()
223 PoisonRedZones(*g); in RegisterGlobal()
225 l->g = g; in RegisterGlobal()
228 if (g->has_dynamic_init) { in RegisterGlobal()
233 DynInitGlobal dyn_global = { *g, false }; in RegisterGlobal()
238 static void UnregisterGlobal(const Global *g) { in UnregisterGlobal() argument
241 ReportGlobal(*g, "Removed"); in UnregisterGlobal()
243 CHECK(AddrIsInMem(g->beg)); in UnregisterGlobal()
244 CHECK(AddrIsAlignedByGranularity(g->beg)); in UnregisterGlobal()
245 CHECK(AddrIsAlignedByGranularity(g->size_with_redzone)); in UnregisterGlobal()
247 PoisonShadowForGlobal(g, 0); in UnregisterGlobal()
253 if (UseODRIndicator(g) && g->odr_indicator != UINTPTR_MAX) { in UnregisterGlobal()
254 u8 *odr_indicator = reinterpret_cast<u8 *>(g->odr_indicator); in UnregisterGlobal()
266 const Global *g = &dyn_g.g; in StopInitOrderChecking() local
268 PoisonShadowForGlobal(g, 0); in StopInitOrderChecking()
270 PoisonRedZones(*g); in StopInitOrderChecking()
289 void PrintGlobalNameIfASCII(InternalScopedString *str, const __asan_global &g) { in PrintGlobalNameIfASCII() argument
290 for (uptr p = g.beg; p < g.beg + g.size - 1; p++) { in PrintGlobalNameIfASCII()
294 if (*(char *)(g.beg + g.size - 1) != '\0') return; in PrintGlobalNameIfASCII()
295 str->append(" '%s' is ascii string '%s'\n", MaybeDemangleGlobalName(g.name), in PrintGlobalNameIfASCII()
296 (char *)g.beg); in PrintGlobalNameIfASCII()
299 static const char *GlobalFilename(const __asan_global &g) { in GlobalFilename() argument
300 const char *res = g.module_name; in GlobalFilename()
302 if (g.location) res = g.location->filename; in GlobalFilename()
307 void PrintGlobalLocation(InternalScopedString *str, const __asan_global &g) { in PrintGlobalLocation() argument
308 str->append("%s", GlobalFilename(g)); in PrintGlobalLocation()
309 if (!g.location) return; in PrintGlobalLocation()
310 if (g.location->line_no) str->append(":%d", g.location->line_no); in PrintGlobalLocation()
311 if (g.location->column_no) str->append(":%d", g.location->column_no); in PrintGlobalLocation()
432 const Global *g = &dyn_g.g; in __asan_before_dynamic_init() local
435 if (g->module_name != module_name) in __asan_before_dynamic_init()
436 PoisonShadowForGlobal(g, kAsanInitializationOrderMagic); in __asan_before_dynamic_init()
455 const Global *g = &dyn_g.g; in __asan_after_dynamic_init() local
458 PoisonShadowForGlobal(g, 0); in __asan_after_dynamic_init()
460 PoisonRedZones(*g); in __asan_after_dynamic_init()