1 /* $NetBSD: sys_module.c,v 1.9 2009/04/28 17:57:00 skrll Exp $ */
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 * System calls relating to loadable modules.
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: sys_module.c,v 1.9 2009/04/28 17:57:00 skrll Exp $");
36 #include <sys/param.h>
37 #include <sys/systm.h>
39 #include <sys/namei.h>
42 #include <sys/module.h>
43 #include <sys/syscall.h>
44 #include <sys/syscallargs.h>
47 handle_modctl_load(modctl_load_t
*ml
)
52 prop_dictionary_t dict
;
55 if ((ml
->ml_props
!= NULL
&& ml
->ml_propslen
== 0) ||
56 (ml
->ml_props
== NULL
&& ml
->ml_propslen
> 0)) {
62 error
= copyinstr(ml
->ml_filename
, path
, MAXPATHLEN
, NULL
);
66 if (ml
->ml_props
!= NULL
) {
67 propslen
= ml
->ml_propslen
+ 1;
68 props
= (char *)kmem_alloc(propslen
, KM_SLEEP
);
74 error
= copyinstr(ml
->ml_props
, props
, propslen
, NULL
);
78 dict
= prop_dictionary_internalize(props
);
88 error
= module_load(path
, ml
->ml_flags
, dict
, MODULE_CLASS_ANY
);
91 prop_object_release(dict
);
96 kmem_free(props
, propslen
);
106 sys_modctl(struct lwp
*l
, const struct sys_modctl_args
*uap
,
111 syscallarg(void *) arg;
113 char buf
[MAXMODNAME
];
125 arg
= SCARG(uap
, arg
);
127 switch (SCARG(uap
, cmd
)) {
129 error
= copyin(arg
, &ml
, sizeof(ml
));
132 error
= handle_modctl_load(&ml
);
136 error
= copyinstr(arg
, buf
, sizeof(buf
), NULL
);
138 error
= module_unload(buf
);
143 error
= copyin(arg
, &iov
, sizeof(iov
));
147 mutex_enter(&module_lock
);
148 mslen
= (module_count
+ 1) * sizeof(modstat_t
);
149 mso
= kmem_zalloc(mslen
, KM_SLEEP
);
151 mutex_exit(&module_lock
);
155 TAILQ_FOREACH(mod
, &module_list
, mod_chain
) {
157 strlcpy(ms
->ms_name
, mi
->mi_name
, sizeof(ms
->ms_name
));
158 if (mi
->mi_required
!= NULL
) {
159 strlcpy(ms
->ms_required
, mi
->mi_required
,
160 sizeof(ms
->ms_required
));
162 if (mod
->mod_kobj
!= NULL
) {
163 kobj_stat(mod
->mod_kobj
, &addr
, &size
);
167 ms
->ms_class
= mi
->mi_class
;
168 ms
->ms_refcnt
= mod
->mod_refcnt
;
169 ms
->ms_source
= mod
->mod_source
;
172 mutex_exit(&module_lock
);
173 error
= copyout(mso
, iov
.iov_base
,
174 min(mslen
- sizeof(modstat_t
), iov
.iov_len
));
175 kmem_free(mso
, mslen
);
177 iov
.iov_len
= mslen
- sizeof(modstat_t
);
178 error
= copyout(&iov
, arg
, sizeof(iov
));