@@ -420,99 +420,88 @@ MSAN_MAYBE_STORE_ORIGIN(u16, 2)
420
420
MSAN_MAYBE_STORE_ORIGIN(u32 , 4 )
421
421
MSAN_MAYBE_STORE_ORIGIN(u64 , 8 )
422
422
423
+ // These macros to reuse the function body are kludgy, but are the better than
424
+ // the alternatives:
425
+ // - call a common function: this pollutes the stack traces
426
+ // - have x_instname() be a simple macro wrapper around x(): the
427
+ // instrumentation pass expects function symbols
428
+ // - add instname as a parameter everywhere (with a check whether instname is
429
+ // null): this pollutes the fastpath
430
+ // - duplicate the function body: redundancy is redundant
431
+ #define __MSAN_WARNING_BODY \
432
+ GET_CALLER_PC_BP; \
433
+ PrintWarningWithOrigin (pc, bp, 0 ); \
434
+ if (__msan::flags()->halt_on_error) { \
435
+ if (__msan::flags ()->print_stats ) \
436
+ ReportStats (); \
437
+ Printf (" Exiting\n " ); \
438
+ Die (); \
439
+ }
440
+
423
441
void __msan_warning () {
424
442
WARN_IF_PRINT_FAULTING_INSTRUCTION_REQUESTED;
425
- GET_CALLER_PC_BP;
426
- PrintWarningWithOrigin (pc, bp, 0 );
427
- if (__msan::flags ()->halt_on_error ) {
428
- if (__msan::flags ()->print_stats )
429
- ReportStats ();
430
- Printf (" Exiting\n " );
431
- Die ();
432
- }
443
+ __MSAN_WARNING_BODY
433
444
}
434
445
446
+ void __msan_warning_instname (char *instname) {
447
+ PRINT_FAULTING_INSTRUCTION (instname);
448
+ __MSAN_WARNING_BODY
449
+ }
450
+
451
+ #define __MSAN_WARNING_NORETURN_BODY \
452
+ GET_CALLER_PC_BP; \
453
+ PrintWarningWithOrigin (pc, bp, 0 ); \
454
+ if (__msan::flags()->print_stats) \
455
+ ReportStats (); \
456
+ Printf (" Exiting\n " ); \
457
+ Die ();
458
+
435
459
void __msan_warning_noreturn () {
436
460
WARN_IF_PRINT_FAULTING_INSTRUCTION_REQUESTED;
437
- GET_CALLER_PC_BP;
438
- PrintWarningWithOrigin (pc, bp, 0 );
439
- if (__msan::flags ()->print_stats )
440
- ReportStats ();
441
- Printf (" Exiting\n " );
442
- Die ();
461
+ __MSAN_WARNING_NORETURN_BODY
443
462
}
444
463
445
- void __msan_warning_with_origin (u32 origin) {
446
- WARN_IF_PRINT_FAULTING_INSTRUCTION_REQUESTED;
447
- GET_CALLER_PC_BP;
448
- PrintWarningWithOrigin (pc, bp, origin);
449
- if (__msan::flags ()->halt_on_error ) {
450
- if (__msan::flags ()->print_stats )
451
- ReportStats ();
452
- Printf (" Exiting\n " );
453
- Die ();
454
- }
464
+ void __msan_warning_noreturn_instname (char *instname) {
465
+ PRINT_FAULTING_INSTRUCTION (instname);
466
+ __MSAN_WARNING_NORETURN_BODY
455
467
}
456
468
457
- void __msan_warning_with_origin_noreturn (u32 origin) {
469
+ #define __MSAN_WARNING_WITH_ORIGIN_BODY (origin ) \
470
+ GET_CALLER_PC_BP; \
471
+ PrintWarningWithOrigin (pc, bp, origin); \
472
+ if (__msan::flags()->halt_on_error) { \
473
+ if (__msan::flags ()->print_stats ) \
474
+ ReportStats (); \
475
+ Printf (" Exiting\n " ); \
476
+ Die (); \
477
+ }
478
+
479
+ void __msan_warning_with_origin (u32 origin) {
458
480
WARN_IF_PRINT_FAULTING_INSTRUCTION_REQUESTED;
459
- GET_CALLER_PC_BP;
460
- PrintWarningWithOrigin (pc, bp, origin);
461
- if (__msan::flags ()->print_stats )
462
- ReportStats ();
463
- Printf (" Exiting\n " );
464
- Die ();
481
+ __MSAN_WARNING_WITH_ORIGIN_BODY (origin)
465
482
}
466
483
467
- // We duplicate the non _instname function's body because:
468
- // - we don't want to pollute the stack traces with an additional function
469
- // call.
470
- // - we can't use a simple macro wrapper, because the instrumentation pass
471
- // expects function symbols.
472
- // - we don't add instname as a parameter everywhere (with a check whether the
473
- // value is null) to avoid polluting the fastpath.
474
- void __msan_warning_instname (char *instname) {
484
+ void __msan_warning_with_origin_instname (u32 origin, char *instname) {
475
485
PRINT_FAULTING_INSTRUCTION (instname);
476
- GET_CALLER_PC_BP;
477
- PrintWarningWithOrigin (pc, bp, 0 );
478
- if (__msan::flags ()->halt_on_error ) {
479
- if (__msan::flags ()->print_stats )
480
- ReportStats ();
481
- Printf (" Exiting\n " );
482
- Die ();
483
- }
486
+ __MSAN_WARNING_WITH_ORIGIN_BODY (origin)
484
487
}
485
488
486
- void __msan_warning_noreturn_instname (char *instname) {
487
- PRINT_FAULTING_INSTRUCTION (instname);
488
- GET_CALLER_PC_BP;
489
- PrintWarningWithOrigin (pc, bp, 0 );
490
- if (__msan::flags ()->print_stats )
491
- ReportStats ();
492
- Printf (" Exiting\n " );
489
+ #define __MSAN_WARNING_WITH_ORIGIN_NORETURN_BODY (origin ) \
490
+ GET_CALLER_PC_BP; \
491
+ PrintWarningWithOrigin (pc, bp, origin); \
492
+ if (__msan::flags()->print_stats) \
493
+ ReportStats (); \
494
+ Printf (" Exiting\n " ); \
493
495
Die ();
494
- }
495
496
496
- void __msan_warning_with_origin_instname (u32 origin, char *instname) {
497
- PRINT_FAULTING_INSTRUCTION (instname);
498
- GET_CALLER_PC_BP;
499
- PrintWarningWithOrigin (pc, bp, origin);
500
- if (__msan::flags ()->halt_on_error ) {
501
- if (__msan::flags ()->print_stats )
502
- ReportStats ();
503
- Printf (" Exiting\n " );
504
- Die ();
505
- }
497
+ void __msan_warning_with_origin_noreturn (u32 origin) {
498
+ WARN_IF_PRINT_FAULTING_INSTRUCTION_REQUESTED;
499
+ __MSAN_WARNING_WITH_ORIGIN_NORETURN_BODY (origin)
506
500
}
507
501
508
502
void __msan_warning_with_origin_noreturn_instname (u32 origin, char *instname) {
509
503
PRINT_FAULTING_INSTRUCTION (instname);
510
- GET_CALLER_PC_BP;
511
- PrintWarningWithOrigin (pc, bp, origin);
512
- if (__msan::flags ()->print_stats )
513
- ReportStats ();
514
- Printf (" Exiting\n " );
515
- Die ();
504
+ __MSAN_WARNING_WITH_ORIGIN_NORETURN_BODY (origin)
516
505
}
517
506
518
507
static void OnStackUnwind (const SignalContext &sig, const void *,
0 commit comments