Module Name:    src
Committed By:   pgoyette
Date:           Mon May 24 03:50:25 UTC 2010

Modified Files:
        src/sys/kern: kern_module.c vfs_subr.c
        src/sys/sys: module.h

Log Message:
Protect against attempting to load modules from the filesystem until we
have mounted the root file-system.  This allows us to load built-in and
boot-loader-provided modules much earlier during startup.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/kern/kern_module.c
cvs rdiff -u -r1.400 -r1.401 src/sys/kern/vfs_subr.c
cvs rdiff -u -r1.22 -r1.23 src/sys/sys/module.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_module.c
diff -u src/sys/kern/kern_module.c:1.65 src/sys/kern/kern_module.c:1.66
--- src/sys/kern/kern_module.c:1.65	Sun May  2 11:01:03 2010
+++ src/sys/kern/kern_module.c	Mon May 24 03:50:25 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_module.c,v 1.65 2010/05/02 11:01:03 pooka Exp $	*/
+/*	$NetBSD: kern_module.c,v 1.66 2010/05/24 03:50:25 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.65 2010/05/02 11:01:03 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.66 2010/05/24 03:50:25 pgoyette Exp $");
 
 #define _MODULE_INTERNAL
 
@@ -97,16 +97,26 @@
 
 static bool	module_merge_dicts(prop_dictionary_t, const prop_dictionary_t);
 
-int		module_eopnotsupp(void);
+int		module_eopnotsupp(const char *, int, bool, module_t *,
+				  prop_dictionary_t *);
+
+int		(*module_load_vfs_vec)(const char *, int, bool, module_t *,
+				       prop_dictionary_t *);
 
 int
-module_eopnotsupp(void)
+module_eopnotsupp(const char *name, int flags, bool autoload, module_t *mod,
+		  prop_dictionary_t *filedictp)
 {
-
 	return EOPNOTSUPP;
 }
 __weak_alias(module_load_vfs,module_eopnotsupp);
 
+void
+module_load_vfs_init(void)
+{
+	module_load_vfs_vec = module_load_vfs;
+}
+
 /*
  * module_error:
  *
@@ -314,6 +324,8 @@
 	mutex_init(&module_lock, MUTEX_DEFAULT, IPL_NONE);
 	cv_init(&module_thread_cv, "modunload");
 	mutex_init(&module_thread_lock, MUTEX_DEFAULT, IPL_NONE);
+	module_load_vfs_vec = module_eopnotsupp;
+
 #ifdef MODULAR	/* XXX */
 	module_init_md();
 #endif
@@ -846,7 +858,8 @@
 			return ENOMEM;
 		}
 
-		error = module_load_vfs(name, flags, autoload, mod, &filedict);
+		error = (*module_load_vfs_vec)(name, flags, autoload, mod,
+					       &filedict);
 		if (error != 0) {
 			kmem_free(mod, sizeof(*mod));
 			depth--;

Index: src/sys/kern/vfs_subr.c
diff -u src/sys/kern/vfs_subr.c:1.400 src/sys/kern/vfs_subr.c:1.401
--- src/sys/kern/vfs_subr.c:1.400	Fri Apr 30 10:03:13 2010
+++ src/sys/kern/vfs_subr.c	Mon May 24 03:50:25 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_subr.c,v 1.400 2010/04/30 10:03:13 pooka Exp $	*/
+/*	$NetBSD: vfs_subr.c,v 1.401 2010/05/24 03:50:25 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.400 2010/04/30 10:03:13 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.401 2010/05/24 03:50:25 pgoyette Exp $");
 
 #include "opt_ddb.h"
 #include "opt_compat_netbsd.h"
@@ -119,6 +119,7 @@
 #include <sys/atomic.h>
 #include <sys/kthread.h>
 #include <sys/wapbl.h>
+#include <sys/module.h>
 
 #include <miscfs/genfs/genfs.h>
 #include <miscfs/specfs/specdev.h>
@@ -2617,6 +2618,11 @@
 		initproc->p_cwdi->cwdi_cdir = rootvnode;
 		vref(initproc->p_cwdi->cwdi_cdir);
 		initproc->p_cwdi->cwdi_rdir = NULL;
+		/*
+		 * Enable loading of modules from the filesystem
+		 */
+		module_load_vfs_init();
+
 	}
 	return (error);
 }

Index: src/sys/sys/module.h
diff -u src/sys/sys/module.h:1.22 src/sys/sys/module.h:1.23
--- src/sys/sys/module.h:1.22	Mon Apr 26 23:18:51 2010
+++ src/sys/sys/module.h	Mon May 24 03:50:25 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: module.h,v 1.22 2010/04/26 23:18:51 pooka Exp $	*/
+/*	$NetBSD: module.h,v 1.23 2010/05/24 03:50:25 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -135,11 +135,15 @@
 void	module_rele(const char *);
 int	module_find_section(const char *, void **, size_t *);
 void	module_thread_kick(void);
+void	module_load_vfs_init(void);
 
 void	module_whatis(uintptr_t, void (*)(const char *, ...));
 void	module_print_list(void (*)(const char *, ...));
 
 #ifdef _MODULE_INTERNAL
+extern
+int	(*module_load_vfs_vec)(const char *, int, bool, module_t *,
+			       prop_dictionary_t *);
 int	module_load_vfs(const char *, int, bool, module_t *,
 			prop_dictionary_t *);
 void	module_error(const char *, ...)

Reply via email to