Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,35 @@ static void DescribeAddressBriefly(Stream &strm, const Address &addr,
strm.Printf(".\n");
}

static constexpr uint8_t g_mte_tag_shift = 64 - 8;
static constexpr uintptr_t g_mte_tag_mask = (uintptr_t)0x0f << g_mte_tag_shift;

bool StopInfoMachException::DetermineTagMismatch(ExecutionContext &exe_ctx) {
const bool IsBadAccess = m_value == 1; // EXC_BAD_ACCESS
const bool IsMTETagFault = (m_exc_code == 0x106); // EXC_ARM_MTE_TAG_FAULT
if (!IsBadAccess || !IsMTETagFault)
return false;

if (m_exc_data_count < 2)
return false;

const uint64_t bad_address = m_exc_subcode;

StreamString strm;
strm.Printf("EXC_ARM_MTE_TAG_FAULT (code=%" PRIu64 ", address=0x%" PRIx64
")\n",
m_exc_code, bad_address);

const uint8_t tag = (bad_address & g_mte_tag_mask) >> g_mte_tag_shift;
const uint64_t canonical_addr = bad_address & ~g_mte_tag_mask;
strm.Printf(
"Note: MTE tag mismatch detected: pointer tag=%d, address=0x%" PRIx64,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Linux version will go and fetch the allocation tag, but I am not sure whether you have access to process here to do that.

tag, canonical_addr);
m_description = std::string(strm.GetString());

return true;
}

bool StopInfoMachException::DeterminePtrauthFailure(ExecutionContext &exe_ctx) {
bool IsBreakpoint = m_value == 6; // EXC_BREAKPOINT
bool IsBadAccess = m_value == 1; // EXC_BAD_ACCESS
Expand Down Expand Up @@ -266,6 +295,8 @@ const char *StopInfoMachException::GetDescription() {
case llvm::Triple::aarch64:
if (DeterminePtrauthFailure(exe_ctx))
return m_description.c_str();
if (DetermineTagMismatch(exe_ctx))
return m_description.c_str();
break;

default:
Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Plugins/Process/Utility/StopInfoMachException.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class StopInfoMachException : public StopInfo {
/// is auth-related failure, and returns false otherwise.
bool DeterminePtrauthFailure(ExecutionContext &exe_ctx);

bool DetermineTagMismatch(ExecutionContext &exe_ctx);

public:
// Constructors and Destructors
StopInfoMachException(Thread &thread, uint32_t exc_type,
Expand Down
Loading