https://github.com/jasonmolenda created https://github.com/llvm/llvm-project/pull/126604
A DriverKit process is a kernel extension that runs in userland, instead of running in the kernel address space/priv levels, they've been around a couple of years. From lldb's perspective a DriverKit process is no different from any other userland level process, but it has a different Triple so we need to handle those cases in the lldb codebase. Some of the DriverKit triple handling had been upstreamed to llvm-project, but I noticed a few cases that had not yet. Cleaning that up. >From a8323ec70bc4c40b02272fa540b1b00fe69c88d5 Mon Sep 17 00:00:00 2001 From: Jason Molenda <jmole...@apple.com> Date: Mon, 10 Feb 2025 13:41:55 -0800 Subject: [PATCH] [lldb] [darwin] Upstream a few DriverKit cases A DriverKit process is a kernel extension that runs in userland, instead of running in the kernel address space/priv levels, they've been around a couple of years. From lldb's perspective a DriverKit process is no different from any other userland level process, but it has a different Triple so we need to handle those cases in the lldb codebase. Some of the DriverKit triple handling had been upstreamed to llvm-project, but I noticed a few cases that had not yet. Cleaning that up. --- .../Darwin-Kernel/DynamicLoaderDarwinKernel.cpp | 6 ++++-- .../DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp | 2 ++ .../DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp | 3 ++- .../DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp | 3 ++- .../source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp | 1 + .../Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp | 3 ++- lldb/source/Utility/ArchSpec.cpp | 6 ++++++ lldb/unittests/Utility/ArchSpecTest.cpp | 6 ++++++ 8 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp index ab013e79047ea30..b8941dae0107838 100644 --- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp +++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp @@ -168,8 +168,9 @@ DynamicLoader *DynamicLoaderDarwinKernel::CreateInstance(Process *process, case llvm::Triple::IOS: case llvm::Triple::TvOS: case llvm::Triple::WatchOS: - case llvm::Triple::XROS: case llvm::Triple::BridgeOS: + case llvm::Triple::DriverKit: + case llvm::Triple::XROS: if (triple_ref.getVendor() != llvm::Triple::Apple) { return nullptr; } @@ -243,6 +244,7 @@ DynamicLoaderDarwinKernel::SearchForKernelWithDebugHints(Process *process) { Status read_err; addr_t kernel_addresses_64[] = { 0xfffffff000002010ULL, + 0xfffffe0000004010ULL, // newest arm64 devices, large memory support 0xfffffff000004010ULL, // newest arm64 devices 0xffffff8000004010ULL, // 2014-2015-ish arm64 devices 0xffffff8000002010ULL, // oldest arm64 devices @@ -1092,7 +1094,7 @@ void DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded() { static ConstString arm64_T1Sz_value("gT1Sz"); const Symbol *symbol = m_kernel.GetModule()->FindFirstSymbolWithNameAndType( - kext_summary_symbol, eSymbolTypeData); + kext_summary_symbol, eSymbolTypeAny); if (symbol) { m_kext_summary_header_ptr_addr = symbol->GetAddress(); // Update all image infos diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp index 14d05a1a4494cfe..f9b49c50355d5a1 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp @@ -419,6 +419,8 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo( image_infos[i].os_type = llvm::Triple::WatchOS; else if (os_name == "bridgeos") image_infos[i].os_type = llvm::Triple::BridgeOS; + else if (os_name == "driverkit") + image_infos[i].os_type = llvm::Triple::DriverKit; else if (os_name == "xros") image_infos[i].os_type = llvm::Triple::XROS; else if (os_name == "maccatalyst") { diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp index 5b11059bcc50cbb..08bef4999eb9adc 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp @@ -55,8 +55,9 @@ DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process *process, case llvm::Triple::IOS: case llvm::Triple::TvOS: case llvm::Triple::WatchOS: - case llvm::Triple::XROS: case llvm::Triple::BridgeOS: + case llvm::Triple::DriverKit: + case llvm::Triple::XROS: create = triple_ref.getVendor() == llvm::Triple::Apple; break; default: diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp index 8fc77cbe1170129..b05ed1ce2c8230b 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -75,8 +75,9 @@ DynamicLoader *DynamicLoaderMacOSXDYLD::CreateInstance(Process *process, case llvm::Triple::IOS: case llvm::Triple::TvOS: case llvm::Triple::WatchOS: - case llvm::Triple::XROS: case llvm::Triple::BridgeOS: + case llvm::Triple::DriverKit: + case llvm::Triple::XROS: create = triple_ref.getVendor() == llvm::Triple::Apple; break; default: diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp index 605e3d570496914..4fbead97e9c1afd 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp @@ -129,6 +129,7 @@ PlatformSP PlatformDarwinKernel::CreateInstance(bool force, case llvm::Triple::XROS: case llvm::Triple::TvOS: case llvm::Triple::BridgeOS: + case llvm::Triple::DriverKit: break; // Only accept "vendor" for vendor if the host is Apple and it "unknown" // wasn't specified (it was just returned because it was NOT specified) diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp index e4324f0a52a2b3e..b23f64210cc80cf 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp @@ -62,8 +62,9 @@ SystemRuntime *SystemRuntimeMacOSX::CreateInstance(Process *process) { case llvm::Triple::IOS: case llvm::Triple::TvOS: case llvm::Triple::WatchOS: - case llvm::Triple::XROS: case llvm::Triple::BridgeOS: + case llvm::Triple::DriverKit: + case llvm::Triple::XROS: create = triple_ref.getVendor() == llvm::Triple::Apple; break; default: diff --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp index b13e8ff1ec373de..495215459336a75 100644 --- a/lldb/source/Utility/ArchSpec.cpp +++ b/lldb/source/Utility/ArchSpec.cpp @@ -1040,6 +1040,12 @@ bool ArchSpec::IsMatch(const ArchSpec &rhs, MatchType match) const { rhs_triple_os == llvm::Triple::IOS && rhs_triple_env == llvm::Triple::MacABI)) return true; + // x86_64-apple-driverkit, x86_64-apple-macosx are compatible, no match. + if ((lhs_triple_os == llvm::Triple::DriverKit && + rhs_triple_os == llvm::Triple::MacOSX) || + (lhs_triple_os == llvm::Triple::MacOSX && + rhs_triple_os == llvm::Triple::DriverKit)) + return true; } // x86_64-apple-ios-macabi and x86_64-apple-ios are not compatible. diff --git a/lldb/unittests/Utility/ArchSpecTest.cpp b/lldb/unittests/Utility/ArchSpecTest.cpp index 74a4b48456b0168..2c78629849c642d 100644 --- a/lldb/unittests/Utility/ArchSpecTest.cpp +++ b/lldb/unittests/Utility/ArchSpecTest.cpp @@ -400,6 +400,12 @@ TEST(ArchSpecTest, Compatibility) { B.MergeFrom(A); ASSERT_TRUE(B.IsExactMatch(C)); } + { + ArchSpec A("x86_64-apple-driverkit19.0"); + ArchSpec B("x86_64-apple-macosx10.15.0"); + ASSERT_FALSE(A.IsExactMatch(B)); + ASSERT_TRUE(A.IsCompatibleMatch(B)); + } } TEST(ArchSpecTest, OperatorBool) { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits