[PATCH 5/7] xfree86/loader: Split off some loader code into separate query functions.

Michal Suchanek hramrach at gmail.com
Mon Jul 23 08:14:33 PDT 2012


 * Add CanUnloadModule

Signed-off-by: Michal Suchanek <hramrach at gmail.com>
---
 hw/xfree86/loader/loaderProcs.h |    5 +++++
 hw/xfree86/loader/loadmod.c     |   42 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/hw/xfree86/loader/loaderProcs.h b/hw/xfree86/loader/loaderProcs.h
index 8b4b53f..5028554 100644
--- a/hw/xfree86/loader/loaderProcs.h
+++ b/hw/xfree86/loader/loaderProcs.h
@@ -87,6 +87,11 @@ unsigned long LoaderGetModuleVersion(ModuleDescPtr mod);
 void LoaderResetOptions(void);
 void LoaderSetOptions(unsigned long);
 
+Bool IsBuiltinModule(ModuleDescPtr mod);
+Bool IsDuplicated(ModuleDescPtr mod);
+Bool IsDuplicateModule(ModuleDescPtr mod);
+Bool CanUnloadModule(ModuleDescPtr mod);
+
 /* Options for LoaderSetOptions */
 #define LDR_OPT_ABI_MISMATCH_NONFATAL		0x0001
 
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index a6adae9..8a48adb 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -785,7 +785,7 @@ LoadSubModule(pointer _parent, const char *module,
 
     submod = doLoadModule(module, NULL, subdirlist, patternlist, options,
                           modreq, errmaj, errmin);
-    if (submod && submod != (ModuleDescPtr) 1) {
+    if (submod && !IsBuiltinModule(submod)) {
         parent->child = AddSibling(parent->child, submod);
         submod->parent = parent;
     }
@@ -803,6 +803,19 @@ NewModuleDesc(const char *name)
     return mdp;
 }
 
+/* An advisory function. When true is returned unloading the module should be
+ * safe. Uload can be attempted nonetheless. */
+int CanUnloadModule(ModuleDescPtr mod)
+{
+    if (IsBuiltinModule(mod))
+            return 0;
+    if (IsDuplicated(mod))
+            return 0;
+    /* Neither of the above can be true for modules for which IsDuplicateModule
+     * is true. */
+    return 1;
+}
+
 ModuleDescPtr
 DuplicateModule(ModuleDescPtr mod, ModuleDescPtr parent)
 {
@@ -1084,10 +1097,29 @@ UnloadModule(pointer mod)
     UnloadModuleOrDriver((ModuleDescPtr) mod);
 }
 
+/* Is given module builtin? */
+Bool IsBuiltinModule(ModuleDescPtr mod)
+{
+    return (mod == (ModuleDescPtr) 1);
+}
+
+/* Is given module duplicate of another? */
+Bool IsDuplicateModule(ModuleDescPtr mod)
+{
+    return (mod->TearDownData == ModuleDuplicated);
+}
+
+/* Do duplicates of given module exist? */
+Bool IsDuplicated(ModuleDescPtr mod)
+{
+    /* cannot tell until reference counting is added */
+    return TRUE;
+}
+
 static void
 UnloadModuleOrDriver(ModuleDescPtr mod)
 {
-    if (mod == (ModuleDescPtr) 1)
+    if (IsBuiltinModule(mod))
         return;
 
     if (mod == NULL || mod->name == NULL)
@@ -1100,7 +1132,7 @@ UnloadModuleOrDriver(ModuleDescPtr mod)
         LogMessageVerbSigSafe(X_INFO, 3, "UnloadModule: \"%s\"\n", mod->name);
 
     RemoveChild(mod);
-    if (mod->TearDownData != ModuleDuplicated) {
+    if (!IsDuplicateModule(mod)) {
         if ((mod->TearDownProc) && (mod->TearDownData))
             mod->TearDownProc(mod->TearDownData);
         LoaderUnload(mod->name, mod->handle);
@@ -1120,7 +1152,7 @@ UnloadSubModule(pointer _mod)
     ModuleDescPtr mod = (ModuleDescPtr) _mod;
 
     /* Some drivers are calling us on built-in submodules, ignore them */
-    if (mod == (ModuleDescPtr) 1)
+    if (IsBuiltinModule(mod))
         return;
     RemoveChild(mod);
     UnloadModuleOrDriver(mod);
@@ -1244,7 +1276,7 @@ LoaderGetCanonicalName(const char *modname, PatternPtr patterns)
 unsigned long
 LoaderGetModuleVersion(ModuleDescPtr mod)
 {
-    if (!mod || mod == (ModuleDescPtr) 1 || !mod->VersionInfo)
+    if (!mod || IsBuiltinModule(mod) || !mod->VersionInfo)
         return 0;
 
     return MODULE_VERSION_NUMERIC(mod->VersionInfo->majorversion,
-- 
1.7.10.4



More information about the xorg-devel mailing list