Lines Matching full:g

37   const Global *g = nullptr;
46 Global g = {};
92 ALWAYS_INLINE void PoisonShadowForGlobal(const Global *g, u8 value) {
93 FastPoisonShadow(g->beg, g->size_with_redzone, value);
96 ALWAYS_INLINE void PoisonRedZones(const Global &g) {
97 uptr aligned_size = RoundUpTo(g.size, ASAN_SHADOW_GRANULARITY);
98 FastPoisonShadow(g.beg + aligned_size, g.size_with_redzone - aligned_size,
100 if (g.size != aligned_size) {
102 g.beg + RoundDownTo(g.size, ASAN_SHADOW_GRANULARITY),
103 g.size % ASAN_SHADOW_GRANULARITY, ASAN_SHADOW_GRANULARITY,
110 static void AddGlobalToList(ListOfGlobals &list, const Global *g) {
111 list.push_front(new (GetGlobalLowLevelAllocator()) GlobalListNode{g});
117 const Global *g = &dyn_g.g;
121 PoisonShadowForGlobal(g, 0);
123 PoisonRedZones(*g);
132 const Global *g = &dyn_g.g;
135 PoisonShadowForGlobal(g, kAsanInitializationOrderMagic);
139 static bool IsAddressNearGlobal(uptr addr, const __asan_global &g) {
140 if (addr <= g.beg - kMinimalDistanceFromAnotherGlobal) return false;
141 if (addr >= g.beg + g.size_with_redzone) return false;
145 static void ReportGlobal(const Global &g, const char *prefix) {
147 bool symbolized = Symbolizer::GetOrInit()->SymbolizeData(g.beg, &info);
152 prefix, (void *)&g, (void *)g.beg, g.size, g.size_with_redzone, g.name,
153 g.module_name, (symbolized ? info.module : "?"), g.has_dynamic_init,
154 (void *)g.odr_indicator);
158 } else if (g.gcc_location != 0) {
160 Report(" location: name=%s, %d\n", g.gcc_location->filename, g.gcc_location->line_no);
164 static u32 FindRegistrationSite(const Global *g) {
169 if (g >= grs.g_first && g <= grs.g_last)
181 const Global &g = *l.g;
183 ReportGlobal(g, "Search");
184 if (IsAddressNearGlobal(addr, g)) {
185 internal_memcpy(&globals[res], &g, sizeof(g));
187 reg_sites[res] = FindRegistrationSite(&g);
201 // Check ODR violation for given global G via special ODR indicator. We use
204 static void CheckODRViolationViaIndicator(const Global *g)
207 if (g->odr_indicator == UINTPTR_MAX)
210 ListOfGlobals &relevant_globals = GlobalsByIndicator(g->odr_indicator);
212 u8 *odr_indicator = reinterpret_cast<u8 *>(g->odr_indicator);
217 if ((flags()->detect_odr_violation >= 2 || g->size != l.g->size) &&
218 !IsODRViolationSuppressed(g->name))
219 ReportODRViolation(g, FindRegistrationSite(g), l.g,
220 FindRegistrationSite(l.g));
226 AddGlobalToList(relevant_globals, g);
229 // Check ODR violation for given global G by checking if it's already poisoned.
232 static void CheckODRViolationViaPoisoning(const Global *g)
234 if (__asan_region_is_poisoned(g->beg, g->size_with_redzone)) {
238 if (g->beg == l.g->beg &&
239 (flags()->detect_odr_violation >= 2 || g->size != l.g->size) &&
240 !IsODRViolationSuppressed(g->name)) {
241 ReportODRViolation(g, FindRegistrationSite(g), l.g,
242 FindRegistrationSite(l.g));
264 static inline bool UseODRIndicator(const Global *g) {
265 return g->odr_indicator > 0;
271 static void RegisterGlobal(const Global *g) SANITIZER_REQUIRES(mu_for_globals) {
274 ReportGlobal(*g, "Added");
276 CHECK(AddrIsInMem(g->beg));
277 if (!AddrIsAlignedByGranularity(g->beg)) {
284 ReportODRViolation(g, FindRegistrationSite(g), g, FindRegistrationSite(g));
285 CHECK(AddrIsAlignedByGranularity(g->beg));
287 CHECK(AddrIsAlignedByGranularity(g->size_with_redzone));
291 if (UseODRIndicator(g))
292 CheckODRViolationViaIndicator(g);
294 CheckODRViolationViaPoisoning(g);
297 PoisonRedZones(*g);
299 AddGlobalToList(list_of_all_globals, g);
301 if (g->has_dynamic_init) {
302 DynInitGlobals()[g->module_name].push_back(
303 new (GetGlobalLowLevelAllocator()) DynInitGlobal{*g, false});
307 static void UnregisterGlobal(const Global *g)
311 ReportGlobal(*g, "Removed");
313 CHECK(AddrIsInMem(g->beg));
314 CHECK(AddrIsAlignedByGranularity(g->beg));
315 CHECK(AddrIsAlignedByGranularity(g->size_with_redzone));
317 PoisonShadowForGlobal(g, 0);
323 if (UseODRIndicator(g) && g->odr_indicator != UINTPTR_MAX) {
324 u8 *odr_indicator = reinterpret_cast<u8 *>(g->odr_indicator);
355 void PrintGlobalNameIfASCII(InternalScopedString *str, const __asan_global &g) {
356 for (uptr p = g.beg; p < g.beg + g.size - 1; p++) {
360 if (*(char *)(g.beg + g.size - 1) != '\0') return;
361 str->AppendF(" '%s' is ascii string '%s'\n", MaybeDemangleGlobalName(g.name),
362 (char *)g.beg);
365 void PrintGlobalLocation(InternalScopedString *str, const __asan_global &g,
368 if (Symbolizer::GetOrInit()->SymbolizeData(g.beg, &info) && info.line != 0) {
370 } else if (g.gcc_location != 0) {
372 str->AppendF("%s", g.gcc_location->filename ? g.gcc_location->filename
373 : g.module_name);
374 if (g.gcc_location->line_no)
375 str->AppendF(":%d", g.gcc_location->line_no);
376 if (g.gcc_location->column_no)
377 str->AppendF(":%d", g.gcc_location->column_no);
379 str->AppendF("%s", g.module_name);