@@ -352,23 +352,69 @@ void __sanitizer::BufferedStackTrace::UnwindImpl(
352352
353353using namespace __msan ;
354354
355- #define MSAN_MAYBE_WARNING (type, size ) \
356- void __msan_maybe_warning_##size(type s, u32 o) { \
357- GET_CALLER_PC_BP; \
358- if (UNLIKELY (s)) { \
359- PrintWarningWithOrigin (pc, bp, o); \
360- if (__msan::flags ()->halt_on_error ) { \
361- Printf (" Exiting\n " ); \
362- Die (); \
363- } \
364- } \
355+ // N.B. Only [shadow, shadow+size) is defined. shadow is *not* a pointer into
356+ // an MSan shadow region.
357+ static void print_shadow_value (void *shadow, u64 size) {
358+ Printf (" Shadow value (%llu byte%s):" , size, size == 1 ? " " : " s" );
359+ for (unsigned int i = 0 ; i < size; i++) {
360+ if (i % 4 == 0 )
361+ Printf (" " );
362+
363+ unsigned char x = ((unsigned char *)shadow)[i];
364+ Printf (" %x%x" , x >> 4 , x & 0xf );
365+ }
366+ Printf (" \n " );
367+ Printf (
368+ " Caveat: the shadow value does not necessarily directly correspond to a "
369+ " single user variable. The correspondence is stronger, but not always "
370+ " perfect, when origin tracking is enabled.\n " );
371+ Printf (" \n " );
372+ }
373+
374+ #define MSAN_MAYBE_WARNING (type, size ) \
375+ void __msan_maybe_warning_##size(type s, u32 o) { \
376+ GET_CALLER_PC_BP; \
377+ \
378+ if (UNLIKELY (s)) { \
379+ if (Verbosity () >= 1 ) \
380+ print_shadow_value ((void *)(&s), sizeof (s)); \
381+ PrintWarningWithOrigin (pc, bp, o); \
382+ if (__msan::flags ()->halt_on_error ) { \
383+ Printf (" Exiting\n " ); \
384+ Die (); \
385+ } \
386+ } \
365387 }
366388
367389MSAN_MAYBE_WARNING (u8 , 1 )
368390MSAN_MAYBE_WARNING(u16 , 2 )
369391MSAN_MAYBE_WARNING(u32 , 4 )
370392MSAN_MAYBE_WARNING(u64 , 8 )
371393
394+ // N.B. Only [shadow, shadow+size) is defined. shadow is *not* a pointer into
395+ // an MSan shadow region.
396+ void __msan_maybe_warning_N(void *shadow, u64 size, u32 o) {
397+ GET_CALLER_PC_BP;
398+
399+ bool allZero = true ;
400+ for (unsigned int i = 0 ; i < size; i++) {
401+ if (((char *)shadow)[i]) {
402+ allZero = false ;
403+ break ;
404+ }
405+ }
406+
407+ if (UNLIKELY (!allZero)) {
408+ if (Verbosity () >= 1 )
409+ print_shadow_value (shadow, size);
410+ PrintWarningWithOrigin (pc, bp, o);
411+ if (__msan::flags ()->halt_on_error ) {
412+ Printf (" Exiting\n " );
413+ Die ();
414+ }
415+ }
416+ }
417+
372418#define MSAN_MAYBE_STORE_ORIGIN (type, size ) \
373419 void __msan_maybe_store_origin_##size(type s, void *p, u32 o) { \
374420 if (UNLIKELY (s)) { \
0 commit comments