[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 9 02:51:48 PST 2025


================
@@ -164,12 +164,17 @@ void lldb_private::ParseLinuxSMapRegions(llvm::StringRef linux_smap,
     if (!name.contains(' ')) {
       if (region) {
         if (name == "VmFlags") {
-          if (value.contains("mt"))
-            region->SetMemoryTagged(MemoryRegionInfo::eYes);
-          else
-            region->SetMemoryTagged(MemoryRegionInfo::eNo);
+          region->SetMemoryTagged(MemoryRegionInfo::eNo);
+          region->SetIsShadowStack(MemoryRegionInfo::eNo);
+
+          llvm::SmallVector<llvm::StringRef> flags;
+          value.split(flags, ' ', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
+          for (llvm::StringRef flag : flags)
----------------
DavidSpickett wrote:

> It would be nice to be lazy and only tokenise as much as we need from the string though. I'll see if there's an iterator version I can use.

You can do something like:
```
while value
  split by space
  if flag is not empty: check flag
```
But to make this early exit we'd need to know what we're looking for up front, which I can do but it's a bit complex for a single line that's going to be small 99% of the time.

I do use this strategy for patching in register information, but there it's because we're iterating over 100s of registers each time.

> You made me realise I don't actually have a test case to check we don't match on substrings though, so I will add that.

I added this in LinuxProcMapsTest.cpp

https://github.com/llvm/llvm-project/pull/117861


More information about the lldb-commits mailing list