Skip to content

Commit

Permalink
[lldb] Rename MemoryTagManager RemoveNonAddressBits to RemoveTagBits
Browse files Browse the repository at this point in the history
This better describes the intent of the method. Which for AArch64
is removing the top byte which includes the memory tags.

It does not include pointer signatures, for those we need to use
the ABI plugin. The rename makes this a little more clear.

It's a bit awkward that the memory tag manager is removing the whole
top byte not just the memory tags but it's an improvement for now.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D117671
  • Loading branch information
DavidSpickett committed Jan 20, 2022
1 parent 782c0dd commit 585abe3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lldb/include/lldb/Target/MemoryTagManager.h
Expand Up @@ -35,8 +35,8 @@ class MemoryTagManager {
// you get will have been shifted down 56 before being returned.
virtual lldb::addr_t GetLogicalTag(lldb::addr_t addr) const = 0;

// Remove non address bits from a pointer
virtual lldb::addr_t RemoveNonAddressBits(lldb::addr_t addr) const = 0;
// Remove tag bits from a pointer
virtual lldb::addr_t RemoveTagBits(lldb::addr_t addr) const = 0;

// Return the difference between two addresses, ignoring any logical tags they
// have. If your tags are just part of a larger set of ignored bits, this
Expand Down
10 changes: 4 additions & 6 deletions lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
Expand Up @@ -1365,10 +1365,9 @@ Status NativeProcessLinux::ReadMemoryTags(int32_t type, lldb::addr_t addr,

// lldb will align the range it requests but it is not required to by
// the protocol so we'll do it again just in case.
// Remove non address bits too. Ptrace calls may work regardless but that
// Remove tag bits too. Ptrace calls may work regardless but that
// is not a guarantee.
MemoryTagManager::TagRange range(details->manager->RemoveNonAddressBits(addr),
len);
MemoryTagManager::TagRange range(details->manager->RemoveTagBits(addr), len);
range = details->manager->ExpandToGranule(range);

// Allocate enough space for all tags to be read
Expand Down Expand Up @@ -1420,10 +1419,9 @@ Status NativeProcessLinux::WriteMemoryTags(int32_t type, lldb::addr_t addr,

// lldb will align the range it requests but it is not required to by
// the protocol so we'll do it again just in case.
// Remove non address bits too. Ptrace calls may work regardless but that
// Remove tag bits too. Ptrace calls may work regardless but that
// is not a guarantee.
MemoryTagManager::TagRange range(details->manager->RemoveNonAddressBits(addr),
len);
MemoryTagManager::TagRange range(details->manager->RemoveTagBits(addr), len);
range = details->manager->ExpandToGranule(range);

// Not checking number of tags here, we may repeat them below
Expand Down
Expand Up @@ -20,7 +20,7 @@ MemoryTagManagerAArch64MTE::GetLogicalTag(lldb::addr_t addr) const {
}

lldb::addr_t
MemoryTagManagerAArch64MTE::RemoveNonAddressBits(lldb::addr_t addr) const {
MemoryTagManagerAArch64MTE::RemoveTagBits(lldb::addr_t addr) const {
// Here we're ignoring the whole top byte. If you've got MTE
// you must also have TBI (top byte ignore).
// The other 4 bits could contain other extension bits or
Expand All @@ -30,7 +30,7 @@ MemoryTagManagerAArch64MTE::RemoveNonAddressBits(lldb::addr_t addr) const {

ptrdiff_t MemoryTagManagerAArch64MTE::AddressDiff(lldb::addr_t addr1,
lldb::addr_t addr2) const {
return RemoveNonAddressBits(addr1) - RemoveNonAddressBits(addr2);
return RemoveTagBits(addr1) - RemoveTagBits(addr2);
}

lldb::addr_t MemoryTagManagerAArch64MTE::GetGranuleSize() const {
Expand Down Expand Up @@ -84,7 +84,7 @@ MemoryTagManagerAArch64MTE::MakeTaggedRange(

// Region addresses will not have memory tags. So when searching
// we must use an untagged address.
MemoryRegionInfo::RangeType tag_range(RemoveNonAddressBits(addr), len);
MemoryRegionInfo::RangeType tag_range(RemoveTagBits(addr), len);
tag_range = ExpandToGranule(tag_range);

// Make a copy so we can use the original for errors and the final return.
Expand Down
Expand Up @@ -27,7 +27,7 @@ class MemoryTagManagerAArch64MTE : public MemoryTagManager {
size_t GetTagSizeInBytes() const override;

lldb::addr_t GetLogicalTag(lldb::addr_t addr) const override;
lldb::addr_t RemoveNonAddressBits(lldb::addr_t addr) const override;
lldb::addr_t RemoveTagBits(lldb::addr_t addr) const override;
ptrdiff_t AddressDiff(lldb::addr_t addr1, lldb::addr_t addr2) const override;

TagRange ExpandToGranule(TagRange range) const override;
Expand Down
Expand Up @@ -247,16 +247,17 @@ TEST(MemoryTagManagerAArch64MTETest, MakeTaggedRange) {
ASSERT_EQ(*got, expected_range);
}

TEST(MemoryTagManagerAArch64MTETest, RemoveNonAddressBits) {
TEST(MemoryTagManagerAArch64MTETest, RemoveTagBits) {
MemoryTagManagerAArch64MTE manager;

ASSERT_EQ(0, 0);
// Removes the whole top byte
ASSERT_EQ((lldb::addr_t)0x00ffeedd11223344,
manager.RemoveNonAddressBits(0x00ffeedd11223344));
manager.RemoveTagBits(0x00ffeedd11223344));
ASSERT_EQ((lldb::addr_t)0x0000000000000000,
manager.RemoveNonAddressBits(0xFF00000000000000));
manager.RemoveTagBits(0xff00000000000000));
ASSERT_EQ((lldb::addr_t)0x0055555566666666,
manager.RemoveNonAddressBits(0xee55555566666666));
manager.RemoveTagBits(0xee55555566666666));
}

TEST(MemoryTagManagerAArch64MTETest, AddressDiff) {
Expand Down

0 comments on commit 585abe3

Please sign in to comment.