Keep track of the containing file for modules. This is a bit of a hack,

but I can't think of another (relatively) easy way of getting the info
since the boot-time initialization is not done immediately after "loading".
XXX module_register() gained an extra arg.  This might break the alpha
compile, if so, just add a zero to get the old behavior.
This commit is contained in:
Peter Wemm 1998-10-10 00:03:07 +00:00
parent e4f1a52f7a
commit f3b0d44290
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=40158

View file

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: kern_module.c,v 1.8 1998/07/14 05:09:45 bde Exp $ * $Id: kern_module.c,v 1.9 1998/10/03 11:05:45 dfr Exp $
*/ */
#include <sys/param.h> #include <sys/param.h>
@ -64,7 +64,7 @@ module_init(void* arg)
at_shutdown(module_shutdown, 0, SHUTDOWN_POST_SYNC); at_shutdown(module_shutdown, 0, SHUTDOWN_POST_SYNC);
} }
SYSINIT(module, SI_SUB_KMEM, SI_ORDER_ANY, module_init, 0); SYSINIT(module, SI_SUB_KLD, SI_ORDER_ANY, module_init, 0);
static void static void
module_shutdown(int arg1, void* arg2) module_shutdown(int arg1, void* arg2)
@ -81,17 +81,19 @@ module_register_init(void *arg)
moduledata_t* data = (moduledata_t*) arg; moduledata_t* data = (moduledata_t*) arg;
int error; int error;
if (error = module_register(data->name, data->evhand, data->priv)) error = module_register(data->name, data->evhand, data->priv, data->_file);
if (error)
printf("module_register_init: module_register(%s, %lx, %p) returned %d", printf("module_register_init: module_register(%s, %lx, %p) returned %d",
data->name, (u_long)(uintfptr_t)data->evhand, data->priv, error); data->name, (u_long)(uintfptr_t)data->evhand, data->priv, error);
} }
int int
module_register(const char* name, modeventhand_t handler, void* arg) module_register(const char* name, modeventhand_t handler, void* arg, void *file)
{ {
size_t namelen; size_t namelen;
module_t newmod; module_t newmod;
int error; int error;
linker_file_t container = file;
namelen = strlen(name) + 1; namelen = strlen(name) + 1;
newmod = (module_t) malloc(sizeof(struct module) + namelen, newmod = (module_t) malloc(sizeof(struct module) + namelen,
@ -107,9 +109,11 @@ module_register(const char* name, modeventhand_t handler, void* arg)
newmod->arg = arg; newmod->arg = arg;
TAILQ_INSERT_TAIL(&modules, newmod, link); TAILQ_INSERT_TAIL(&modules, newmod, link);
if (linker_current_file) { if (container == NULL)
TAILQ_INSERT_TAIL(&linker_current_file->modules, newmod, flink); container = linker_current_file;
newmod->file = linker_current_file; if (container) {
TAILQ_INSERT_TAIL(&container->modules, newmod, flink);
newmod->file = container;
} else } else
newmod->file = 0; newmod->file = 0;