Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/pgoyette-compat]: src/sys (Re)implement the alias list as a "const char ...



details:   https://anonhg.NetBSD.org/src/rev/818d28a30858
branches:  pgoyette-compat
changeset: 321007:818d28a30858
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sun Mar 11 07:25:59 2018 +0000

description:
(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.

diffstat:

 sys/kern/kern_module.c |  16 ++++++++--------
 sys/kern/sys_module.c  |  10 +++++-----
 sys/sys/module.h       |  21 +++++++++++++--------
 3 files changed, 26 insertions(+), 21 deletions(-)

diffs (163 lines):

diff -r d57ea61e7d38 -r 818d28a30858 sys/kern/kern_module.c
--- a/sys/kern/kern_module.c    Sun Mar 11 00:58:12 2018 +0000
+++ b/sys/kern/kern_module.c    Sun Mar 11 07:25:59 2018 +0000
@@ -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 @@
 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 @@
     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 @@
         * 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 @@
        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 @@
        /*
         * 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 "
diff -r d57ea61e7d38 -r 818d28a30858 sys/kern/sys_module.c
--- a/sys/kern/sys_module.c     Sun Mar 11 00:58:12 2018 +0000
+++ b/sys/kern/sys_module.c     Sun Mar 11 07:25:59 2018 +0000
@@ -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 @@
        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 @@
        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 @@
                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) {
diff -r d57ea61e7d38 -r 818d28a30858 sys/sys/module.h
--- a/sys/sys/module.h  Sun Mar 11 00:58:12 2018 +0000
+++ b/sys/sys/module.h  Sun Mar 11 07:25:59 2018 +0000
@@ -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 @@
        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 @@
 
 #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;



Home | Main Index | Thread Index | Old Index