From 554fdaa33a919e39b37c5635a9183216bc44ceeb Mon Sep 17 00:00:00 2001 From: Travis Geiselbrecht Date: Thu, 21 Jun 2007 05:07:14 +0000 Subject: [PATCH] Fix a bug that was tripping an assert in the kernel module code. When iterating through modules, the iterator was loading the module file, inserting it into the module image hash. Then, the first time get_module() was called on a module contained in the image, it was trying to load the image again. It probably actually was. Changed the logic to call get_module_image() which checks to see if it's already loaded. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21476 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/module.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/system/kernel/module.cpp b/src/system/kernel/module.cpp index bf509d90a2..2577c8d90f 100644 --- a/src/system/kernel/module.cpp +++ b/src/system/kernel/module.cpp @@ -359,16 +359,22 @@ get_module_image(const char *path, module_image **_image) TRACE(("get_module_image(path = \"%s\", _image = %p)\n", path, _image)); + recursive_lock_lock(&sModulesLock); + image = (module_image *)hash_lookup(sModuleImagesHash, path); if (image == NULL) { status_t status = load_module_image(path, &image); - if (status < B_OK) + if (status < B_OK) { + recursive_lock_unlock(&sModulesLock); return status; + } } atomic_add(&image->ref_count, 1); *_image = image; + recursive_lock_unlock(&sModulesLock); + return B_OK; } @@ -446,9 +452,8 @@ check_module_image(const char *path, const char *searchedName) int index = 0, match = B_ENTRY_NOT_FOUND; TRACE(("check_module_image(path = \"%s\", searchedName = \"%s\")\n", path, searchedName)); - ASSERT(hash_lookup(sModuleImagesHash, path) == NULL); - if (load_module_image(path, &image) < B_OK) + if (get_module_image(path, &image) < B_OK) return B_ENTRY_NOT_FOUND; for (info = image->info; *info; info++) { @@ -467,6 +472,9 @@ check_module_image(const char *path, const char *searchedName) unload_module_image(image, path); } + // decrement the ref we got in get_module_image + put_module_image(image); + return match; }