Skip to content

Commit

Permalink
Reapply [sanitizers] Avoid macro clash in SignalContext::WriteFlag (NFC)
Browse files Browse the repository at this point in the history
D116208 may cause a macro clash on older versions of linux, where
fs.h defines a READ macro. This is resolved by switching to a more
typical casing style for non-macro symbols.

Reapplying with changes to the symbol names in various platform
specific code, which I missed previously.

Differential Revision: https://reviews.llvm.org/D118783

(cherry picked from commit 36cae42)
  • Loading branch information
nikic committed Feb 9, 2022
1 parent b31913c commit c3c82dc
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions compiler-rt/lib/asan/asan_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ struct ErrorDeadlySignal : ErrorBase {
scariness.Scare(10, "null-deref");
} else if (signal.addr == signal.pc) {
scariness.Scare(60, "wild-jump");
} else if (signal.write_flag == SignalContext::WRITE) {
} else if (signal.write_flag == SignalContext::Write) {
scariness.Scare(30, "wild-addr-write");
} else if (signal.write_flag == SignalContext::READ) {
} else if (signal.write_flag == SignalContext::Read) {
scariness.Scare(20, "wild-addr-read");
} else {
scariness.Scare(25, "wild-addr");
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/sanitizer_common/sanitizer_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ struct SignalContext {
uptr sp;
uptr bp;
bool is_memory_access;
enum WriteFlag { UNKNOWN, READ, WRITE } write_flag;
enum WriteFlag { Unknown, Read, Write } write_flag;

// In some cases the kernel cannot provide the true faulting address; `addr`
// will be zero then. This field allows to distinguish between these cases
Expand Down
46 changes: 23 additions & 23 deletions compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,7 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
#else
uptr err = ucontext->uc_mcontext.gregs[REG_ERR];
#endif // SANITIZER_FREEBSD
return err & PF_WRITE ? WRITE : READ;
return err & PF_WRITE ? Write : Read;
#elif defined(__mips__)
uint32_t *exception_source;
uint32_t faulty_instruction;
Expand All @@ -1848,7 +1848,7 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
case 0x2a: // swl
case 0x2e: // swr
#endif
return SignalContext::WRITE;
return SignalContext::Write;

case 0x20: // lb
case 0x24: // lbu
Expand All @@ -1863,27 +1863,27 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
case 0x22: // lwl
case 0x26: // lwr
#endif
return SignalContext::READ;
return SignalContext::Read;
#if __mips_isa_rev == 6
case 0x3b: // pcrel
op_code = (faulty_instruction >> 19) & 0x3;
switch (op_code) {
case 0x1: // lwpc
case 0x2: // lwupc
return SignalContext::READ;
return SignalContext::Read;
}
#endif
}
return SignalContext::UNKNOWN;
return SignalContext::Unknown;
#elif defined(__arm__)
static const uptr FSR_WRITE = 1U << 11;
uptr fsr = ucontext->uc_mcontext.error_code;
return fsr & FSR_WRITE ? WRITE : READ;
return fsr & FSR_WRITE ? Write : Read;
#elif defined(__aarch64__)
static const u64 ESR_ELx_WNR = 1U << 6;
u64 esr;
if (!Aarch64GetESR(ucontext, &esr)) return UNKNOWN;
return esr & ESR_ELx_WNR ? WRITE : READ;
if (!Aarch64GetESR(ucontext, &esr)) return Unknown;
return esr & ESR_ELx_WNR ? Write : Read;
#elif defined(__sparc__)
// Decode the instruction to determine the access type.
// From OpenSolaris $SRC/uts/sun4/os/trap.c (get_accesstype).
Expand All @@ -1899,7 +1899,7 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
#endif
#endif
u32 instr = *(u32 *)pc;
return (instr >> 21) & 1 ? WRITE: READ;
return (instr >> 21) & 1 ? Write: Read;
#elif defined(__riscv)
#if SANITIZER_FREEBSD
unsigned long pc = ucontext->uc_mcontext.mc_gpregs.gp_sepc;
Expand All @@ -1919,7 +1919,7 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
#if __riscv_xlen == 64
case 0b10'011: // c.ldsp (rd != x0)
#endif
return rd ? SignalContext::READ : SignalContext::UNKNOWN;
return rd ? SignalContext::Read : SignalContext::Unknown;
case 0b00'010: // c.lw
#if __riscv_flen >= 32 && __riscv_xlen == 32
case 0b10'011: // c.flwsp
Expand All @@ -1931,7 +1931,7 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
case 0b00'001: // c.fld
case 0b10'001: // c.fldsp
#endif
return SignalContext::READ;
return SignalContext::Read;
case 0b00'110: // c.sw
case 0b10'110: // c.swsp
#if __riscv_flen >= 32 || __riscv_xlen == 64
Expand All @@ -1942,9 +1942,9 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
case 0b00'101: // c.fsd
case 0b10'101: // c.fsdsp
#endif
return SignalContext::WRITE;
return SignalContext::Write;
default:
return SignalContext::UNKNOWN;
return SignalContext::Unknown;
}
}
#endif
Expand All @@ -1962,9 +1962,9 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
#endif
case 0b100: // lbu
case 0b101: // lhu
return SignalContext::READ;
return SignalContext::Read;
default:
return SignalContext::UNKNOWN;
return SignalContext::Unknown;
}
case 0b0100011: // stores
switch (funct3) {
Expand All @@ -1974,9 +1974,9 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
#if __riscv_xlen == 64
case 0b011: // sd
#endif
return SignalContext::WRITE;
return SignalContext::Write;
default:
return SignalContext::UNKNOWN;
return SignalContext::Unknown;
}
#if __riscv_flen >= 32
case 0b0000111: // floating-point loads
Expand All @@ -1985,27 +1985,27 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
#if __riscv_flen == 64
case 0b011: // fld
#endif
return SignalContext::READ;
return SignalContext::Read;
default:
return SignalContext::UNKNOWN;
return SignalContext::Unknown;
}
case 0b0100111: // floating-point stores
switch (funct3) {
case 0b010: // fsw
#if __riscv_flen == 64
case 0b011: // fsd
#endif
return SignalContext::WRITE;
return SignalContext::Write;
default:
return SignalContext::UNKNOWN;
return SignalContext::Unknown;
}
#endif
default:
return SignalContext::UNKNOWN;
return SignalContext::Unknown;
}
#else
(void)ucontext;
return UNKNOWN; // FIXME: Implement.
return Unknown; // FIXME: Implement.
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,9 @@ void LogFullErrorReport(const char *buffer) {
SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
#if defined(__x86_64__) || defined(__i386__)
ucontext_t *ucontext = static_cast<ucontext_t*>(context);
return ucontext->uc_mcontext->__es.__err & 2 /*T_PF_WRITE*/ ? WRITE : READ;
return ucontext->uc_mcontext->__es.__err & 2 /*T_PF_WRITE*/ ? Write : Read;
#else
return UNKNOWN;
return Unknown;
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ static void ReportDeadlySignalImpl(const SignalContext &sig, u32 tid,
Report("Hint: pc points to the zero page.\n");
if (sig.is_memory_access) {
const char *access_type =
sig.write_flag == SignalContext::WRITE
sig.write_flag == SignalContext::Write
? "WRITE"
: (sig.write_flag == SignalContext::READ ? "READ" : "UNKNOWN");
: (sig.write_flag == SignalContext::Read ? "READ" : "UNKNOWN");
Report("The signal is caused by a %s memory access.\n", access_type);
if (!sig.is_true_faulting_addr)
Report("Hint: this fault was caused by a dereference of a high value "
Expand Down
10 changes: 5 additions & 5 deletions compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,21 +983,21 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {

// The write flag is only available for access violation exceptions.
if (exception_record->ExceptionCode != EXCEPTION_ACCESS_VIOLATION)
return SignalContext::UNKNOWN;
return SignalContext::Unknown;

// The contents of this array are documented at
// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_record
// The first element indicates read as 0, write as 1, or execute as 8. The
// second element is the faulting address.
switch (exception_record->ExceptionInformation[0]) {
case 0:
return SignalContext::READ;
return SignalContext::Read;
case 1:
return SignalContext::WRITE;
return SignalContext::Write;
case 8:
return SignalContext::UNKNOWN;
return SignalContext::Unknown;
}
return SignalContext::UNKNOWN;
return SignalContext::Unknown;
}

void SignalContext::DumpAllRegisters(void *context) {
Expand Down

0 comments on commit c3c82dc

Please sign in to comment.