Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Put the code in charge of handling MODCTL_STAT into...



details:   https://anonhg.NetBSD.org/src/rev/c1ccf93b855d
branches:  trunk
changeset: 812340:c1ccf93b855d
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Dec 12 14:47:37 2015 +0000

description:
Put the code in charge of handling MODCTL_STAT into a separate function.

No functional change.

diffstat:

 sys/kern/sys_module.c |  130 ++++++++++++++++++++++++++-----------------------
 1 files changed, 70 insertions(+), 60 deletions(-)

diffs (165 lines):

diff -r b2f2f2256fc2 -r c1ccf93b855d sys/kern/sys_module.c
--- a/sys/kern/sys_module.c     Sat Dec 12 09:52:40 2015 +0000
+++ b/sys/kern/sys_module.c     Sat Dec 12 14:47:37 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_module.c,v 1.20 2015/11/04 04:28:58 pgoyette Exp $ */
+/*     $NetBSD: sys_module.c,v 1.21 2015/12/12 14:47:37 maxv 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.20 2015/11/04 04:28:58 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_module.c,v 1.21 2015/12/12 14:47:37 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_modular.h"
@@ -115,6 +115,73 @@
        return error;
 }
 
+static int
+handle_modctl_stat(struct iovec *iov, void *arg)
+{
+       modstat_t *ms, *mso;
+       modinfo_t *mi;
+       module_t *mod;
+       vaddr_t addr;
+       size_t size;
+       size_t mslen;
+       int error;
+
+       kernconfig_lock();
+       mslen = (module_count+module_builtinlist+1) * sizeof(modstat_t);
+       mso = kmem_zalloc(mslen, KM_SLEEP);
+       if (mso == NULL) {
+               kernconfig_unlock();
+               return ENOMEM;
+       }
+       ms = mso;
+       TAILQ_FOREACH(mod, &module_list, mod_chain) {
+               mi = mod->mod_info;
+               strlcpy(ms->ms_name, mi->mi_name, sizeof(ms->ms_name));
+               if (mi->mi_required != NULL) {
+                       strlcpy(ms->ms_required, mi->mi_required,
+                           sizeof(ms->ms_required));
+               }
+               if (mod->mod_kobj != NULL) {
+                       kobj_stat(mod->mod_kobj, &addr, &size);
+                       ms->ms_addr = addr;
+                       ms->ms_size = size;
+               }
+               ms->ms_class = mi->mi_class;
+               ms->ms_refcnt = mod->mod_refcnt;
+               ms->ms_source = mod->mod_source;
+               ms->ms_flags = mod->mod_flags;
+               ms++;
+       }
+       TAILQ_FOREACH(mod, &module_builtins, mod_chain) {
+               mi = mod->mod_info;
+               strlcpy(ms->ms_name, mi->mi_name, sizeof(ms->ms_name));
+               if (mi->mi_required != NULL) {
+                       strlcpy(ms->ms_required, mi->mi_required,
+                           sizeof(ms->ms_required));
+               }
+               if (mod->mod_kobj != NULL) {
+                       kobj_stat(mod->mod_kobj, &addr, &size);
+                       ms->ms_addr = addr;
+                       ms->ms_size = size;
+               }
+               ms->ms_class = mi->mi_class;
+               ms->ms_refcnt = -1;
+               KASSERT(mod->mod_source == MODULE_SOURCE_KERNEL);
+               ms->ms_source = mod->mod_source;
+               ms++;
+       }
+       kernconfig_unlock();
+       error = copyout(mso, iov->iov_base,
+           min(mslen - sizeof(modstat_t), iov->iov_len));
+       kmem_free(mso, mslen);
+       if (error == 0) {
+               iov->iov_len = mslen - sizeof(modstat_t);
+               error = copyout(iov, arg, sizeof(*iov));
+       }
+
+       return error;
+}
+
 int
 sys_modctl(struct lwp *l, const struct sys_modctl_args *uap,
           register_t *retval)
@@ -124,12 +191,6 @@
                syscallarg(void *)      arg;
        } */
        char buf[MAXMODNAME];
-       size_t mslen;
-       module_t *mod;
-       modinfo_t *mi;
-       modstat_t *ms, *mso;
-       vaddr_t addr;
-       size_t size;
        struct iovec iov;
        modctl_load_t ml;
        int error;
@@ -161,58 +222,7 @@
                if (error != 0) {
                        break;
                }
-               kernconfig_lock();
-               mslen = (module_count+module_builtinlist+1) * sizeof(modstat_t);
-               mso = kmem_zalloc(mslen, KM_SLEEP);
-               if (mso == NULL) {
-                       kernconfig_unlock();
-                       return ENOMEM;
-               }
-               ms = mso;
-               TAILQ_FOREACH(mod, &module_list, mod_chain) {
-                       mi = mod->mod_info;
-                       strlcpy(ms->ms_name, mi->mi_name, sizeof(ms->ms_name));
-                       if (mi->mi_required != NULL) {
-                               strlcpy(ms->ms_required, mi->mi_required,
-                                   sizeof(ms->ms_required));
-                       }
-                       if (mod->mod_kobj != NULL) {
-                               kobj_stat(mod->mod_kobj, &addr, &size);
-                               ms->ms_addr = addr;
-                               ms->ms_size = size;
-                       }
-                       ms->ms_class = mi->mi_class;
-                       ms->ms_refcnt = mod->mod_refcnt;
-                       ms->ms_source = mod->mod_source;
-                       ms->ms_flags = mod->mod_flags;
-                       ms++;
-               }
-               TAILQ_FOREACH(mod, &module_builtins, mod_chain) {
-                       mi = mod->mod_info;
-                       strlcpy(ms->ms_name, mi->mi_name, sizeof(ms->ms_name));
-                       if (mi->mi_required != NULL) {
-                               strlcpy(ms->ms_required, mi->mi_required,
-                                   sizeof(ms->ms_required));
-                       }
-                       if (mod->mod_kobj != NULL) {
-                               kobj_stat(mod->mod_kobj, &addr, &size);
-                               ms->ms_addr = addr;
-                               ms->ms_size = size;
-                       }
-                       ms->ms_class = mi->mi_class;
-                       ms->ms_refcnt = -1;
-                       KASSERT(mod->mod_source == MODULE_SOURCE_KERNEL);
-                       ms->ms_source = mod->mod_source;
-                       ms++;
-               }
-               kernconfig_unlock();
-               error = copyout(mso, iov.iov_base,
-                   min(mslen - sizeof(modstat_t), iov.iov_len));
-               kmem_free(mso, mslen);
-               if (error == 0) {
-                       iov.iov_len = mslen - sizeof(modstat_t);
-                       error = copyout(&iov, arg, sizeof(iov));
-               }
+               error = handle_modctl_stat(&iov, arg);
                break;
 
        case MODCTL_EXISTS:



Home | Main Index | Thread Index | Old Index