blob: b5585416e3ff2d0935e193504498662a6ab7b83e [file]
From 5631e69a99889f5f124258c3a46130296f8d0643 Mon Sep 17 00:00:00 2001
From: Pierre Wielders <pierre@wielders.net>
Date: Sat, 21 Jan 2023 09:48:12 +0100
Subject: [PATCH] [DEADLOCK] Deadlock prevention by locking the
ServiceAdministartor vbefore loading a library. (#1202)
Co-authored-by: MFransen69 <39826971+MFransen69@users.noreply.github.com>
---
Source/WPEFramework/PluginServer.h | 7 ++++++-
Source/core/Services.h | 4 ++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/Source/WPEFramework/PluginServer.h b/Source/WPEFramework/PluginServer.h
index f3d25ca6..6b9a6c1e 100644
--- a/Source/WPEFramework/PluginServer.h
+++ b/Source/WPEFramework/PluginServer.h
@@ -1136,7 +1136,12 @@ namespace PluginHost {
if (progressedState == 0) {
progressedState = 1;
}
- Core::Library newLib = Core::Library(iter->c_str());
+
+ // Loading a library, in the static initializers, might register Service::MetaData structures. As
+ // the dlopen has a process wide system lock, make sure that the, during open used lock of the
+ // ServiceAdministrator, is already taken before entering the dlopen. This can only be achieved
+ // by forwarding this call to the ServiceAdministrator, so please so...
+ Core::Library newLib = Core::ServiceAdministrator::Instance().LoadLibrary(iter->c_str());
if (newLib.IsLoaded() == true) {
if (progressedState == 1) {
diff --git a/Source/core/Services.h b/Source/core/Services.h
index b8259922..eaf41802 100644
--- a/Source/core/Services.h
+++ b/Source/core/Services.h
@@ -96,6 +96,10 @@ namespace Core {
static ServiceAdministrator& Instance();
public:
+ Library LoadLibrary(const TCHAR libraryName[]) {
+ Core::SafeSyncType<Core::CriticalSection> lock(_adminLock);
+ return (Library(libraryName));
+ }
// There is *NO* locking around the _callback pointer. SO this callback
// must be set, before any Service Object is created ore released!!!
void Callback(ICallback* callback)
--
2.34.1