Skip to content

Commit 8769834

Browse files
committed
Add two new memory region based checks to the Unwinder:
Check that the pc value for frames up the stack is in a mapped+executable region of memory. Check that the stack pointer for frames up the stack is in a mapped+readable region of memory. If the unwinder ever makes a mistake walking the stack, these checks will help to keep it from going too far into the weeds. These aren't fixing any bugs that I know of, but they add extra robustness to a complicated task. llvm-svn: 146478
1 parent cb349ee commit 8769834

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,17 @@ RegisterContextLLDB::InitializeNonZerothFrame()
236236
m_frame_type = eNotAValidFrame;
237237
return;
238238
}
239+
240+
// Test the pc value to see if we know it's in an unmapped/non-executable region of memory.
241+
// If so, our unwind has made a mistake somewhere and we should stop.
242+
uint32_t permissions;
243+
if (m_thread.GetProcess().GetLoadAddressPermissions(pc, permissions)
244+
&& (permissions & ePermissionsExecutable) == 0)
245+
{
246+
m_frame_type = eNotAValidFrame;
247+
return;
248+
}
249+
239250
m_thread.GetProcess().GetTarget().GetSectionLoadList().ResolveLoadAddress (pc, m_current_pc);
240251

241252
// If we don't have a Module for some reason, we're not going to find symbol/function information - just
@@ -287,6 +298,15 @@ RegisterContextLLDB::InitializeNonZerothFrame()
287298
m_frame_type = eNotAValidFrame;
288299
return;
289300
}
301+
302+
// cfa_regval should point into the stack memory; if we can query memory region permissions,
303+
// see if the memory is allocated & readable.
304+
if (m_thread.GetProcess().GetLoadAddressPermissions(cfa_regval, permissions)
305+
&& (permissions & ePermissionsReadable) == 0)
306+
{
307+
m_frame_type = eNotAValidFrame;
308+
return;
309+
}
290310
}
291311
else
292312
{

0 commit comments

Comments
 (0)