Skip to content

Commit 6602e1f

Browse files
committed
Reordering KextImageInfo::LoadImageUsingMemoryModule
so we only call ModulesDidLoad at the end of the method after the new module has been added to the target and the sections have all been adjusted to their actual load addresses. Solves a problem where an operating system plugin in the kernel could be loaded multiple times; the first before the binary had even been added to the target. <rdar://problem/50523558>
1 parent e0407f5 commit 6602e1f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -791,25 +791,23 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
791791
module_spec.GetArchitecture() = target.GetArchitecture();
792792

793793
// For the kernel, we really do need an on-disk file copy of the binary
794-
// to do anything useful. This will force a clal to
794+
// to do anything useful. This will force a call to dsymForUUID if it
795+
// exists, instead of depending on the DebugSymbols preferences being
796+
// set.
795797
if (IsKernel()) {
796798
if (Symbols::DownloadObjectAndSymbolFile(module_spec, true)) {
797799
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
798800
m_module_sp = std::make_shared<Module>(module_spec.GetFileSpec(),
799801
target.GetArchitecture());
800-
if (m_module_sp.get() &&
801-
m_module_sp->MatchesModuleSpec(module_spec)) {
802-
ModuleList loaded_module_list;
803-
loaded_module_list.Append(m_module_sp);
804-
target.ModulesDidLoad(loaded_module_list);
805-
}
806802
}
807803
}
808804
}
809805

810806
// If the current platform is PlatformDarwinKernel, create a ModuleSpec
811807
// with the filename set to be the bundle ID for this kext, e.g.
812808
// "com.apple.filesystems.msdosfs", and ask the platform to find it.
809+
// PlatformDarwinKernel does a special scan for kexts on the local
810+
// system.
813811
PlatformSP platform_sp(target.GetPlatform());
814812
if (!m_module_sp && platform_sp) {
815813
ConstString platform_name(platform_sp->GetPluginName());
@@ -818,7 +816,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
818816
if (platform_name == g_platform_name) {
819817
ModuleSpec kext_bundle_module_spec(module_spec);
820818
FileSpec kext_filespec(m_name.c_str());
821-
FileSpecList search_paths = target.GetExecutableSearchPaths();
819+
FileSpecList search_paths = target.GetExecutableSearchPaths();
822820
kext_bundle_module_spec.GetFileSpec() = kext_filespec;
823821
platform_sp->GetSharedModule(kext_bundle_module_spec, process,
824822
m_module_sp, &search_paths, nullptr,
@@ -847,7 +845,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
847845
// UUIDs
848846
if (m_module_sp) {
849847
if (m_uuid.IsValid() && m_module_sp->GetUUID() == m_uuid) {
850-
target.GetImages().AppendIfNeeded(m_module_sp);
848+
target.GetImages().AppendIfNeeded(m_module_sp, false);
851849
if (IsKernel() &&
852850
target.GetExecutableModulePointer() != m_module_sp.get()) {
853851
target.SetExecutableModule(m_module_sp, eLoadDependentsNo);
@@ -945,6 +943,14 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
945943
s.Flush();
946944
}
947945

946+
// Notify the target about the module being added;
947+
// set breakpoints, load dSYM scripts, etc. as needed.
948+
if (is_loaded && m_module_sp) {
949+
ModuleList loaded_module_list;
950+
loaded_module_list.Append(m_module_sp);
951+
target.ModulesDidLoad(loaded_module_list);
952+
}
953+
948954
return is_loaded;
949955
}
950956

0 commit comments

Comments
 (0)