Source-Changes-HG archive

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

[src/trunk]: src/sys/compat/netbsd32 Put the code in charge of handling MODCT...



details:   https://anonhg.NetBSD.org/src/rev/76f7cc2cc523
branches:  trunk
changeset: 812342:76f7cc2cc523
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Dec 12 15:27:42 2015 +0000

description:
Put the code in charge of handling MODCTL_STAT (32bit) into a separate
function. No functional change.

diffstat:

 sys/compat/netbsd32/netbsd32_module.c |  128 ++++++++++++++++++---------------
 1 files changed, 69 insertions(+), 59 deletions(-)

diffs (163 lines):

diff -r dba24b708061 -r 76f7cc2cc523 sys/compat/netbsd32/netbsd32_module.c
--- a/sys/compat/netbsd32/netbsd32_module.c     Sat Dec 12 14:57:52 2015 +0000
+++ b/sys/compat/netbsd32/netbsd32_module.c     Sat Dec 12 15:27:42 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_module.c,v 1.2 2015/06/21 06:51:05 msaitoh Exp $      */
+/*     $NetBSD: netbsd32_module.c,v 1.3 2015/12/12 15:27:42 maxv Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_module.c,v 1.2 2015/06/21 06:51:05 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_module.c,v 1.3 2015/12/12 15:27:42 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/dirent.h>
@@ -42,6 +42,72 @@
 #include <compat/netbsd32/netbsd32_syscallargs.h>
 #include <compat/netbsd32/netbsd32_conv.h>
 
+static int
+modctl32_handle_stat(struct netbsd32_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++;
+       }
+       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, NETBSD32PTR64(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
 netbsd32_modctl(struct lwp *lwp, const struct netbsd32_modctl_args *uap,
        register_t *result)
@@ -51,12 +117,6 @@
                syscallarg(netbsd32_voidp) arg;
        } */
        char buf[MAXMODNAME];
-       size_t mslen;
-       module_t *mod;
-       modinfo_t *mi;
-       modstat_t *ms, *mso;
-       vaddr_t addr;
-       size_t size;
        struct netbsd32_iovec iov;
        struct netbsd32_modctl_load ml;
        int error;
@@ -88,57 +148,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++;
-               }
-               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, NETBSD32PTR64(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 = modctl32_handle_stat(&iov, arg);
                break;
 
        case MODCTL_EXISTS:



Home | Main Index | Thread Index | Old Index