* Added a get_safemode_boolean() function for easy access to the safemode
options. * module_init() now sets sDisableUserAddOns to whatever the safemode settings say, ie. the B_SAFEMODE_DISABLE_USER_ADD_ONS setting is now respected by the module code. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24315 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
a1dac092fa
commit
637eef896b
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
* Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _KERNEL_SAFEMODE_H
|
#ifndef _KERNEL_SAFEMODE_H
|
||||||
@ -25,6 +25,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
status_t get_safemode_option(const char *parameter, char *buffer, size_t *_bufferSize);
|
status_t get_safemode_option(const char *parameter, char *buffer, size_t *_bufferSize);
|
||||||
|
bool get_safemode_boolean(const char *parameter, bool defaultValue);
|
||||||
status_t _user_get_safemode_option(const char *parameter, char *buffer, size_t *_bufferSize);
|
status_t _user_get_safemode_option(const char *parameter, char *buffer, size_t *_bufferSize);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -33,6 +33,20 @@ get_safemode_option(const char *parameter, char *buffer, size_t *_bufferSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" bool
|
||||||
|
get_safemode_boolean(const char *parameter, bool defaultValue)
|
||||||
|
{
|
||||||
|
char value[16];
|
||||||
|
size_t length = sizeof(value);
|
||||||
|
|
||||||
|
if (get_safemode_option(parameter, value, &length) != B_OK)
|
||||||
|
return defaultValue;
|
||||||
|
|
||||||
|
return !strcmp(value, "on") || !strcmp(value, "true") || !strcmp(value, "1")
|
||||||
|
|| !strcmp(value, "yes") || !strcmp(value, "enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2007, Haiku Inc. All rights reserved.
|
* Copyright 2002-2008, Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Copyright 2001, Thomas Kurschel. All rights reserved.
|
* Copyright 2001, Thomas Kurschel. All rights reserved.
|
||||||
* Distributed under the terms of the NewOS License.
|
* Distributed under the terms of the NewOS License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Manages kernel add-ons and their exported modules. */
|
/*! Manages kernel add-ons and their exported modules. */
|
||||||
|
|
||||||
|
|
||||||
#include <kmodule.h>
|
#include <kmodule.h>
|
||||||
@ -22,6 +22,7 @@
|
|||||||
#include <vfs.h>
|
#include <vfs.h>
|
||||||
#include <boot/elf.h>
|
#include <boot/elf.h>
|
||||||
#include <fs/KPath.h>
|
#include <fs/KPath.h>
|
||||||
|
#include <safemode.h>
|
||||||
#include <util/AutoLock.h>
|
#include <util/AutoLock.h>
|
||||||
#include <util/khash.h>
|
#include <util/khash.h>
|
||||||
|
|
||||||
@ -37,10 +38,9 @@
|
|||||||
|
|
||||||
#define MODULE_HASH_SIZE 16
|
#define MODULE_HASH_SIZE 16
|
||||||
|
|
||||||
/** The modules referenced by this structure are built-in
|
/*! The modules referenced by this structure are built-in
|
||||||
* modules that can't be loaded from disk.
|
modules that can't be loaded from disk.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern module_info gDeviceManagerModule;
|
extern module_info gDeviceManagerModule;
|
||||||
extern module_info gDeviceRootModule;
|
extern module_info gDeviceRootModule;
|
||||||
extern module_info gDeviceForDriversModule;
|
extern module_info gDeviceForDriversModule;
|
||||||
@ -157,15 +157,14 @@ static const char * const sModulePaths[] = {
|
|||||||
#define NUM_MODULE_PATHS (sizeof(sModulePaths) / sizeof(sModulePaths[0]))
|
#define NUM_MODULE_PATHS (sizeof(sModulePaths) / sizeof(sModulePaths[0]))
|
||||||
#define FIRST_USER_MODULE_PATH (NUM_MODULE_PATHS - 1) /* first user path */
|
#define FIRST_USER_MODULE_PATH (NUM_MODULE_PATHS - 1) /* first user path */
|
||||||
|
|
||||||
/* we store the loaded modules by directory path, and all known modules by module name
|
/* We store the loaded modules by directory path, and all known modules
|
||||||
* in a hash table for quick access
|
* by module name in a hash table for quick access
|
||||||
*/
|
*/
|
||||||
static hash_table *sModuleImagesHash;
|
static hash_table *sModuleImagesHash;
|
||||||
static hash_table *sModulesHash;
|
static hash_table *sModulesHash;
|
||||||
|
|
||||||
|
|
||||||
/** calculates hash for a module using its name */
|
/*! Calculates hash for a module using its name */
|
||||||
|
|
||||||
static uint32
|
static uint32
|
||||||
module_hash(void *_module, const void *_key, uint32 range)
|
module_hash(void *_module, const void *_key, uint32 range)
|
||||||
{
|
{
|
||||||
@ -182,8 +181,7 @@ module_hash(void *_module, const void *_key, uint32 range)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** compares a module to a given name */
|
/*! Compares a module to a given name */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
module_compare(void *_module, const void *_key)
|
module_compare(void *_module, const void *_key)
|
||||||
{
|
{
|
||||||
@ -196,8 +194,7 @@ module_compare(void *_module, const void *_key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** calculates the hash of a module image using its path */
|
/*! Calculates the hash of a module image using its path */
|
||||||
|
|
||||||
static uint32
|
static uint32
|
||||||
module_image_hash(void *_module, const void *_key, uint32 range)
|
module_image_hash(void *_module, const void *_key, uint32 range)
|
||||||
{
|
{
|
||||||
@ -214,8 +211,7 @@ module_image_hash(void *_module, const void *_key, uint32 range)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** compares a module image to a path */
|
/*! Compares a module image to a path */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
module_image_compare(void *_module, const void *_key)
|
module_image_compare(void *_module, const void *_key)
|
||||||
{
|
{
|
||||||
@ -228,11 +224,10 @@ module_image_compare(void *_module, const void *_key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Try to load the module image at the specified location.
|
/*! Try to load the module image at the specified location.
|
||||||
* If it could be loaded, it returns B_OK, and stores a pointer
|
If it could be loaded, it returns B_OK, and stores a pointer
|
||||||
* to the module_image object in "_moduleImage".
|
to the module_image object in "_moduleImage".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
load_module_image(const char *path, module_image **_moduleImage)
|
load_module_image(const char *path, module_image **_moduleImage)
|
||||||
{
|
{
|
||||||
@ -361,10 +356,9 @@ get_module_image(const char *path, module_image **_image)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Extract the information from the module_info structure pointed at
|
/*! Extract the information from the module_info structure pointed at
|
||||||
* by "info" and create the entries required for access to it's details.
|
by "info" and create the entries required for access to it's details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
create_module(module_info *info, const char *file, int offset, module **_module)
|
create_module(module_info *info, const char *file, int offset, module **_module)
|
||||||
{
|
{
|
||||||
@ -419,13 +413,12 @@ create_module(module_info *info, const char *file, int offset, module **_module)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Loads the file at "path" and scans all modules contained therein.
|
/*! Loads the file at "path" and scans all modules contained therein.
|
||||||
* Returns B_OK if "searchedName" could be found under those modules,
|
Returns B_OK if "searchedName" could be found under those modules,
|
||||||
* B_ENTRY_NOT_FOUND if not.
|
B_ENTRY_NOT_FOUND if not.
|
||||||
* Must only be called for files that haven't been scanned yet.
|
Must only be called for files that haven't been scanned yet.
|
||||||
* "searchedName" is allowed to be NULL (if all modules should be scanned)
|
"searchedName" is allowed to be NULL (if all modules should be scanned)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
check_module_image(const char *path, const char *searchedName)
|
check_module_image(const char *path, const char *searchedName)
|
||||||
{
|
{
|
||||||
@ -463,10 +456,9 @@ check_module_image(const char *path, const char *searchedName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** This is only called if we fail to find a module already in our cache...
|
/*! This is only called if we fail to find a module already in our cache...
|
||||||
* saves us some extra checking here :)
|
saves us some extra checking here :)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static module *
|
static module *
|
||||||
search_module(const char *name)
|
search_module(const char *name)
|
||||||
{
|
{
|
||||||
@ -546,8 +538,7 @@ get_dependent_modules(struct module *module)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Initializes a loaded module depending on its state */
|
/*! Initializes a loaded module depending on its state */
|
||||||
|
|
||||||
static inline status_t
|
static inline status_t
|
||||||
init_module(module *module)
|
init_module(module *module)
|
||||||
{
|
{
|
||||||
@ -604,8 +595,7 @@ init_module(module *module)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Uninitializes a module depeding on its state */
|
/*! Uninitializes a module depeding on its state */
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
uninit_module(module *module)
|
uninit_module(module *module)
|
||||||
{
|
{
|
||||||
@ -999,14 +989,12 @@ dump_modules(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark - Exported Kernel API (private part)
|
||||||
// Exported Kernel API (private part)
|
|
||||||
|
|
||||||
|
|
||||||
/** Unloads a module in case it's not in use. This is the counterpart
|
/*! Unloads a module in case it's not in use. This is the counterpart
|
||||||
* to load_module().
|
to load_module().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
unload_module(const char *path)
|
unload_module(const char *path)
|
||||||
{
|
{
|
||||||
@ -1024,15 +1012,14 @@ unload_module(const char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Unlike get_module(), this function lets you specify the add-on to
|
/*! Unlike get_module(), this function lets you specify the add-on to
|
||||||
* be loaded by path.
|
be loaded by path.
|
||||||
* However, you must not use the exported modules without having called
|
However, you must not use the exported modules without having called
|
||||||
* get_module() on them. When you're done with the NULL terminated
|
get_module() on them. When you're done with the NULL terminated
|
||||||
* \a modules array, you have to call unload_module(), no matter if
|
\a modules array, you have to call unload_module(), no matter if
|
||||||
* you're actually using any of the modules or not - of course, the
|
you're actually using any of the modules or not - of course, the
|
||||||
* add-on won't be unloaded until the last put_module().
|
add-on won't be unloaded until the last put_module().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
load_module(const char *path, module_info ***_modules)
|
load_module(const char *path, module_info ***_modules)
|
||||||
{
|
{
|
||||||
@ -1046,10 +1033,9 @@ load_module(const char *path, module_info ***_modules)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Setup the module structures and data for use - must be called
|
/*! Setup the module structures and data for use - must be called
|
||||||
* before any other module call.
|
before any other module call.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
module_init(kernel_args *args)
|
module_init(kernel_args *args)
|
||||||
{
|
{
|
||||||
@ -1081,7 +1067,8 @@ module_init(kernel_args *args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToDo: set sDisableUserAddOns from kernel_args!
|
sDisableUserAddOns = get_safemode_boolean(B_SAFEMODE_DISABLE_USER_ADD_ONS,
|
||||||
|
false);
|
||||||
|
|
||||||
add_debugger_command("modules", &dump_modules,
|
add_debugger_command("modules", &dump_modules,
|
||||||
"list all known & loaded modules");
|
"list all known & loaded modules");
|
||||||
@ -1090,19 +1077,17 @@ module_init(kernel_args *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark - Exported Kernel API (public part)
|
||||||
// Exported Kernel API (public part)
|
|
||||||
|
|
||||||
|
|
||||||
/** This returns a pointer to a structure that can be used to
|
/*! This returns a pointer to a structure that can be used to
|
||||||
* iterate through a list of all modules available under
|
iterate through a list of all modules available under
|
||||||
* a given prefix.
|
a given prefix.
|
||||||
* All paths will be searched and the returned list will
|
All paths will be searched and the returned list will
|
||||||
* contain all modules available under the prefix.
|
contain all modules available under the prefix.
|
||||||
* The structure is then used by read_next_module_name(), and
|
The structure is then used by read_next_module_name(), and
|
||||||
* must be freed by calling close_module_list().
|
must be freed by calling close_module_list().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void *
|
void *
|
||||||
open_module_list(const char *prefix)
|
open_module_list(const char *prefix)
|
||||||
{
|
{
|
||||||
@ -1180,9 +1165,7 @@ open_module_list(const char *prefix)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Frees the cookie allocated by open_module_list()
|
/*! Frees the cookie allocated by open_module_list() */
|
||||||
*/
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
close_module_list(void *cookie)
|
close_module_list(void *cookie)
|
||||||
{
|
{
|
||||||
@ -1216,12 +1199,11 @@ close_module_list(void *cookie)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Return the next module name from the available list, using
|
/*! Return the next module name from the available list, using
|
||||||
* a structure previously created by a call to open_module_list().
|
a structure previously created by a call to open_module_list().
|
||||||
* Returns B_OK as long as it found another module, B_ENTRY_NOT_FOUND
|
Returns B_OK as long as it found another module, B_ENTRY_NOT_FOUND
|
||||||
* when done.
|
when done.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
read_next_module_name(void *cookie, char *buffer, size_t *_bufferSize)
|
read_next_module_name(void *cookie, char *buffer, size_t *_bufferSize)
|
||||||
{
|
{
|
||||||
@ -1250,12 +1232,11 @@ read_next_module_name(void *cookie, char *buffer, size_t *_bufferSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Iterates through all loaded modules, and stores its path in "buffer".
|
/*! Iterates through all loaded modules, and stores its path in "buffer".
|
||||||
* ToDo: check if the function in BeOS really does that (could also mean:
|
ToDo: check if the function in BeOS really does that (could also mean:
|
||||||
* iterate through all modules that are currently loaded; have a valid
|
iterate through all modules that are currently loaded; have a valid
|
||||||
* module_image pointer, which would be hard to test for)
|
module_image pointer, which would be hard to test for)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
get_next_loaded_module_name(uint32 *_cookie, char *buffer, size_t *_bufferSize)
|
get_next_loaded_module_name(uint32 *_cookie, char *buffer, size_t *_bufferSize)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user