Module Name:    src
Committed By:   pgoyette
Date:           Sun Mar 11 07:26:00 UTC 2018

Modified Files:
        src/sys/kern [pgoyette-compat]: kern_module.c sys_module.c
        src/sys/sys [pgoyette-compat]: module.h

Log Message:
(Re)implement the alias list as a "const char * const (*list)[]" and
store a pointer to this list in the mod_info structure (which lives
in the modules' linkset data).  Don't allow any duplication of module
names _or_ aliases when loading; for dependencies, they will be met
if the required module name matches any loaded module name or alias.


To generate a diff of this commit:
cvs rdiff -u -r1.130.2.1 -r1.130.2.2 src/sys/kern/kern_module.c
cvs rdiff -u -r1.23.2.1 -r1.23.2.2 src/sys/kern/sys_module.c
cvs rdiff -u -r1.41.14.5 -r1.41.14.6 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.130.2.1 src/sys/kern/kern_module.c:1.130.2.2
--- src/sys/kern/kern_module.c:1.130.2.1	Sun Mar 11 00:44:32 2018
+++ src/sys/kern/kern_module.c	Sun Mar 11 07:25:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_module.c,v 1.130.2.1 2018/03/11 00:44:32 pgoyette Exp $	*/
+/*	$NetBSD: kern_module.c,v 1.130.2.2 2018/03/11 07:25:59 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.130.2.1 2018/03/11 00:44:32 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.130.2.2 2018/03/11 07:25:59 pgoyette Exp $");
 
 #define _MODULE_INTERNAL
 
@@ -666,9 +666,9 @@ module_unload(const char *name)
 int
 module_alias_lookup(const char *name, module_t *mod)
 {
-	const char * const *aliasp;
+	const char * const	aliasp[];
 
-	aliasp = mod->mod_info->mi_aliases;
+	aliasp = *mod->mod_info->mi_aliases;
 	if (aliasp == NULL)
 		return 0;
 	while (*aliasp)
@@ -784,7 +784,7 @@ module_do_builtin(const module_t *pmod, 
     prop_dictionary_t props)
 {
 	const char *p, *s;
-	const char * const *aliasp;
+	const char * const	aliasp[];
 	char buf[MAXMODNAME];
 	modinfo_t *mi = NULL;
 	module_t *mod, *mod2, *mod_loaded, *prev_active;
@@ -858,7 +858,7 @@ module_do_builtin(const module_t *pmod, 
 	 * Retrieve that none of the module's aliases already exist
 	 */
 
-	if ((aliasp = mod->mod_info->mi_aliases) != NULL) {
+	if ((aliasp = *mod->mod_info->mi_aliases) != NULL) {
 		while (*aliasp)
 			if (module_lookup(*aliasp++) != NULL)
 				return EEXIST;
@@ -910,7 +910,7 @@ module_do_load(const char *name, bool is
 	prop_dictionary_t filedict;
 	char buf[MAXMODNAME];
 	const char *s, *p;
-	const char * const *aliasp;
+	const char * const aliasp[];
 	int error;
 	size_t len;
 
@@ -1171,7 +1171,7 @@ module_do_load(const char *name, bool is
 	/*
 	 * One last check for duplicate module name/alias
 	 */
-	if ((aliasp = mod->mod_info->mi_aliases) != NULL)
+	if ((aliasp = *mod->mod_info->mi_aliases) != NULL)
 		while (*aliasp != NULL)
 			if (module_lookup(*aliasp) != NULL) {
 				module_error("Module `%s' alias `%s' already "

Index: src/sys/kern/sys_module.c
diff -u src/sys/kern/sys_module.c:1.23.2.1 src/sys/kern/sys_module.c:1.23.2.2
--- src/sys/kern/sys_module.c:1.23.2.1	Sun Mar 11 00:44:32 2018
+++ src/sys/kern/sys_module.c	Sun Mar 11 07:25:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_module.c,v 1.23.2.1 2018/03/11 00:44:32 pgoyette Exp $	*/
+/*	$NetBSD: sys_module.c,v 1.23.2.2 2018/03/11 07:25:59 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_module.c,v 1.23.2.1 2018/03/11 00:44:32 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_module.c,v 1.23.2.2 2018/03/11 07:25:59 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_modular.h"
@@ -122,7 +122,7 @@ handle_modctl_stat(struct iovec *iov, vo
 	int error;
 	int mscnt;
 	bool stataddr;
-	const char * const *aliasp;
+	const char * const aliasp[];
 
 	/* If not privileged, don't expose kernel addresses. */
 	error = kauth_authorize_system(kauth_cred_get(), KAUTH_SYSTEM_MODULE,
@@ -134,7 +134,7 @@ handle_modctl_stat(struct iovec *iov, vo
 	TAILQ_FOREACH(mod, &module_list, mod_chain) {
 		mscnt++;
 		mi = mod->mod_info;
-		if ((aliasp = mi->mi_aliases) != NULL) {
+		if ((aliasp = *mi->mi_aliases) != NULL) {
 			while (*aliasp++ != NULL)
 				mslen++;
 		}
@@ -159,7 +159,7 @@ handle_modctl_stat(struct iovec *iov, vo
 		ms->ms_source = mod->mod_source;
 		ms->ms_flags = mod->mod_flags;
 		ms++;
-		aliasp = mi->mi_aliases;
+		aliasp = *mi->mi_aliases;
 		if (aliasp == NULL)
 			continue;
 		while (*aliasp) {

Index: src/sys/sys/module.h
diff -u src/sys/sys/module.h:1.41.14.5 src/sys/sys/module.h:1.41.14.6
--- src/sys/sys/module.h:1.41.14.5	Sun Mar 11 00:58:12 2018
+++ src/sys/sys/module.h	Sun Mar 11 07:25:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: module.h,v 1.41.14.5 2018/03/11 00:58:12 pgoyette Exp $	*/
+/*	$NetBSD: module.h,v 1.41.14.6 2018/03/11 07:25:59 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@ typedef struct modinfo {
 	int			(*mi_modcmd)(modcmd_t, void *);
 	const char		*mi_name;
 	const char		*mi_required;
-	const char * const	*mi_aliases;
+	const char * const	(*mi_aliases)[];
 } const modinfo_t;
 
 /* Per module information, maintained by kern_module.c */ 
@@ -152,22 +152,27 @@ static void __CONCAT(moddtor_,name)(void
 
 #endif /* RUMP_USE_CTOR */
 
-#define	MODULE(class, name, required)				\
-	MODULE_WITH_ALIAS(class, name, required, NULL)
-
-#define	MODULE_WITH_ALIAS(class, name, required, aliases)	\
+#define	MODULE_WITH_ALIASES(class, name, required, aliases)	\
 static int __CONCAT(name,_modcmd)(modcmd_t, void *);		\
-static const char * const * __CONCAT(name,_aliases) = { aliases }; \
 static const modinfo_t __CONCAT(name,_modinfo) = {		\
 	.mi_version = __NetBSD_Version__,			\
 	.mi_class = (class),					\
 	.mi_modcmd = __CONCAT(name,_modcmd),			\
 	.mi_name = __STRING(name),				\
-	.mi_aliases = __CONCAT(name,_aliases),			\
+	.mi_aliases = (aliases),				\
 	.mi_required = (required)				\
 }; 								\
 _MODULE_REGISTER(name)
 
+#define	MODULE(class, name, required)				\
+	MODULE_WITH_ALIASES(class, name, required, NULL)
+
+#ifdef PRG
+static mod_alias_list __CONCAT(name,_aliases) = { aliases };	\
+	.mi_aliases = & __CONCAT(name,_aliases),		\
+
+#endif
+
 TAILQ_HEAD(modlist, module);
 
 extern struct vm_map	*module_map;

Reply via email to