summaryrefslogtreecommitdiff
path: root/lldb
diff options
context:
space:
mode:
authorJason Molenda <jmolenda@apple.com>2019-01-10 00:57:54 +0000
committerJason Molenda <jmolenda@apple.com>2019-01-10 00:57:54 +0000
commit18148d76cc15901767adf31df2f2235bec1d82ce (patch)
treef0ceaa6aaf0019a8833b27d0cfafce4762c8f72d /lldb
parent960c4577bfd28ec38a6c3a7a7119a5cff09aedae (diff)
A little cleanup / commenting on locating kernel binaries while I
was working on something else. DynamicLoaderDarwinKernel::SearchForKernelNearPC should have had an early return if the pc value is not in high memory; add that. The search for a kernel at 0x2000 offsets was a stopgap; it doesn't need to be checked any longer.
Diffstat (limited to 'lldb')
-rw-r--r--lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index 024f82800f6..3a80c68dd4d 100644
--- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -293,6 +293,18 @@ DynamicLoaderDarwinKernel::SearchForKernelNearPC(Process *process) {
return LLDB_INVALID_ADDRESS;
addr_t pc = thread->GetRegisterContext()->GetPC(LLDB_INVALID_ADDRESS);
+ // The kernel is always loaded in high memory, if the top bit is zero,
+ // this isn't a kernel.
+ if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 8) {
+ if ((pc & (1ULL << 63)) == 0) {
+ return LLDB_INVALID_ADDRESS;
+ }
+ } else {
+ if ((pc & (1ULL << 31)) == 0) {
+ return LLDB_INVALID_ADDRESS;
+ }
+ }
+
if (pc == LLDB_INVALID_ADDRESS)
return LLDB_INVALID_ADDRESS;
@@ -307,12 +319,13 @@ DynamicLoaderDarwinKernel::SearchForKernelNearPC(Process *process) {
// Search backwards 32 megabytes, looking for the start of the kernel at each
// one-megabyte boundary.
for (int i = 0; i < 32; i++, addr -= 0x100000) {
+ // x86_64 kernels are at offset 0
if (CheckForKernelImageAtAddress(addr, process).IsValid())
return addr;
+ // 32-bit arm kernels are at offset 0x1000 (one 4k page)
if (CheckForKernelImageAtAddress(addr + 0x1000, process).IsValid())
return addr + 0x1000;
- if (CheckForKernelImageAtAddress(addr + 0x2000, process).IsValid())
- return addr + 0x2000;
+ // 64-bit arm kernels are at offset 0x4000 (one 16k page)
if (CheckForKernelImageAtAddress(addr + 0x4000, process).IsValid())
return addr + 0x4000;
}
@@ -351,12 +364,13 @@ lldb::addr_t DynamicLoaderDarwinKernel::SearchForKernelViaExhaustiveSearch(
addr_t addr = kernel_range_low;
while (addr >= kernel_range_low && addr < kernel_range_high) {
+ // x86_64 kernels are at offset 0
if (CheckForKernelImageAtAddress(addr, process).IsValid())
return addr;
+ // 32-bit arm kernels are at offset 0x1000 (one 4k page)
if (CheckForKernelImageAtAddress(addr + 0x1000, process).IsValid())
return addr + 0x1000;
- if (CheckForKernelImageAtAddress(addr + 0x2000, process).IsValid())
- return addr + 0x2000;
+ // 64-bit arm kernels are at offset 0x4000 (one 16k page)
if (CheckForKernelImageAtAddress(addr + 0x4000, process).IsValid())
return addr + 0x4000;
addr += 0x100000;