1997-05-07 16:05:47 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997 Doug Rabson
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2005-01-19 17:53:06 +00:00
|
|
|
#include "opt_compat.h"
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1997-05-07 16:05:47 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
1999-08-21 06:24:40 +00:00
|
|
|
#include <sys/eventhandler.h>
|
1997-05-07 16:05:47 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/sysproto.h>
|
|
|
|
#include <sys/sysent.h>
|
1997-11-06 19:29:57 +00:00
|
|
|
#include <sys/proc.h>
|
2001-09-01 19:04:37 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
2004-08-20 21:47:48 +00:00
|
|
|
#include <sys/reboot.h>
|
2002-03-18 07:45:30 +00:00
|
|
|
#include <sys/sx.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/linker.h>
|
1997-05-07 16:05:47 +00:00
|
|
|
|
2000-12-08 20:09:00 +00:00
|
|
|
static MALLOC_DEFINE(M_MODULE, "module", "module data structures");
|
1997-05-07 16:05:47 +00:00
|
|
|
|
2000-05-26 02:09:24 +00:00
|
|
|
typedef TAILQ_HEAD(, module) modulelist_t;
|
1997-05-07 16:05:47 +00:00
|
|
|
struct module {
|
2002-02-20 14:30:02 +00:00
|
|
|
TAILQ_ENTRY(module) link; /* chain together all modules */
|
|
|
|
TAILQ_ENTRY(module) flink; /* all modules in a file */
|
|
|
|
struct linker_file *file; /* file which contains this module */
|
|
|
|
int refs; /* reference count */
|
|
|
|
int id; /* unique id number */
|
|
|
|
char *name; /* module name */
|
|
|
|
modeventhand_t handler; /* event handler */
|
|
|
|
void *arg; /* argument for handler */
|
|
|
|
modspecific_t data; /* module specific data */
|
1997-05-07 16:05:47 +00:00
|
|
|
};
|
|
|
|
|
2002-02-20 14:30:02 +00:00
|
|
|
#define MOD_EVENT(mod, type) (mod)->handler((mod), (type), (mod)->arg)
|
1997-05-07 16:05:47 +00:00
|
|
|
|
|
|
|
static modulelist_t modules;
|
2002-03-18 07:45:30 +00:00
|
|
|
struct sx modules_sx;
|
1997-05-07 16:05:47 +00:00
|
|
|
static int nextid = 1;
|
2002-02-20 14:30:02 +00:00
|
|
|
static void module_shutdown(void *, int);
|
1997-05-07 16:05:47 +00:00
|
|
|
|
1999-11-08 06:53:30 +00:00
|
|
|
static int
|
2002-02-20 14:30:02 +00:00
|
|
|
modevent_nop(module_t mod, int what, void *arg)
|
1999-11-08 06:53:30 +00:00
|
|
|
{
|
2004-07-14 22:37:36 +00:00
|
|
|
|
|
|
|
switch(what) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
return (0);
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
return (EBUSY);
|
|
|
|
default:
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
1999-11-08 06:53:30 +00:00
|
|
|
}
|
|
|
|
|
1997-05-07 16:05:47 +00:00
|
|
|
static void
|
2002-02-20 14:30:02 +00:00
|
|
|
module_init(void *arg)
|
1997-05-07 16:05:47 +00:00
|
|
|
{
|
2002-02-20 14:30:02 +00:00
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
sx_init(&modules_sx, "module subsystem sx lock");
|
2002-02-20 14:30:02 +00:00
|
|
|
TAILQ_INIT(&modules);
|
2003-01-07 22:24:13 +00:00
|
|
|
EVENTHANDLER_REGISTER(shutdown_final, module_shutdown, NULL,
|
2002-02-20 14:30:02 +00:00
|
|
|
SHUTDOWN_PRI_DEFAULT);
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
|
2008-03-16 10:58:09 +00:00
|
|
|
SYSINIT(module, SI_SUB_KLD, SI_ORDER_FIRST, module_init, 0);
|
1997-05-07 16:05:47 +00:00
|
|
|
|
|
|
|
static void
|
2002-02-20 14:30:02 +00:00
|
|
|
module_shutdown(void *arg1, int arg2)
|
1997-05-07 16:05:47 +00:00
|
|
|
{
|
2002-02-20 14:30:02 +00:00
|
|
|
module_t mod;
|
1997-05-07 16:05:47 +00:00
|
|
|
|
2004-08-20 21:47:48 +00:00
|
|
|
if (arg2 & RB_NOSYNC)
|
|
|
|
return;
|
2006-06-26 18:34:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_SLOCK;
|
2002-02-20 14:30:02 +00:00
|
|
|
TAILQ_FOREACH(mod, &modules, link)
|
|
|
|
MOD_EVENT(mod, MOD_SHUTDOWN);
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_SUNLOCK;
|
2006-06-26 18:34:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-01-29 08:36:45 +00:00
|
|
|
module_register_init(const void *arg)
|
1997-05-07 16:05:47 +00:00
|
|
|
{
|
2002-02-20 14:30:02 +00:00
|
|
|
const moduledata_t *data = (const moduledata_t *)arg;
|
|
|
|
int error;
|
|
|
|
module_t mod;
|
|
|
|
|
2006-06-26 18:34:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_SLOCK;
|
2002-02-20 14:30:02 +00:00
|
|
|
mod = module_lookupbyname(data->name);
|
|
|
|
if (mod == NULL)
|
2002-02-22 13:33:10 +00:00
|
|
|
panic("module_register_init: module named %s not found\n",
|
2002-02-20 14:30:02 +00:00
|
|
|
data->name);
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_SUNLOCK;
|
2002-02-20 14:30:02 +00:00
|
|
|
error = MOD_EVENT(mod, MOD_LOAD);
|
|
|
|
if (error) {
|
|
|
|
MOD_EVENT(mod, MOD_UNLOAD);
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_XLOCK;
|
2002-02-20 14:30:02 +00:00
|
|
|
module_release(mod);
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_XUNLOCK;
|
2002-02-26 00:55:27 +00:00
|
|
|
printf("module_register_init: MOD_LOAD (%s, %p, %p) error"
|
|
|
|
" %d\n", data->name, (void *)data->evhand, data->priv,
|
2002-02-22 13:33:10 +00:00
|
|
|
error);
|
2002-02-20 14:30:02 +00:00
|
|
|
}
|
2006-06-26 18:34:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-05-08 13:01:59 +00:00
|
|
|
module_register(const moduledata_t *data, linker_file_t container)
|
1997-05-07 16:05:47 +00:00
|
|
|
{
|
2002-02-20 14:30:02 +00:00
|
|
|
size_t namelen;
|
|
|
|
module_t newmod;
|
|
|
|
|
2006-06-15 08:53:09 +00:00
|
|
|
MOD_XLOCK;
|
2002-02-20 14:30:02 +00:00
|
|
|
newmod = module_lookupbyname(data->name);
|
|
|
|
if (newmod != NULL) {
|
2006-06-15 08:53:09 +00:00
|
|
|
MOD_XUNLOCK;
|
2002-02-22 13:33:10 +00:00
|
|
|
printf("module_register: module %s already exists!\n",
|
2002-02-20 14:30:02 +00:00
|
|
|
data->name);
|
2002-02-20 16:05:30 +00:00
|
|
|
return (EEXIST);
|
2002-02-20 14:30:02 +00:00
|
|
|
}
|
|
|
|
namelen = strlen(data->name) + 1;
|
2003-02-19 05:47:46 +00:00
|
|
|
newmod = malloc(sizeof(struct module) + namelen, M_MODULE, M_WAITOK);
|
2006-06-15 08:53:09 +00:00
|
|
|
if (newmod == NULL) {
|
|
|
|
MOD_XUNLOCK;
|
2002-02-20 16:05:30 +00:00
|
|
|
return (ENOMEM);
|
2006-06-15 08:53:09 +00:00
|
|
|
}
|
2002-02-20 14:30:02 +00:00
|
|
|
newmod->refs = 1;
|
|
|
|
newmod->id = nextid++;
|
|
|
|
newmod->name = (char *)(newmod + 1);
|
|
|
|
strcpy(newmod->name, data->name);
|
|
|
|
newmod->handler = data->evhand ? data->evhand : modevent_nop;
|
|
|
|
newmod->arg = data->priv;
|
|
|
|
bzero(&newmod->data, sizeof(newmod->data));
|
|
|
|
TAILQ_INSERT_TAIL(&modules, newmod, link);
|
|
|
|
|
|
|
|
if (container)
|
|
|
|
TAILQ_INSERT_TAIL(&container->modules, newmod, flink);
|
|
|
|
newmod->file = container;
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_XUNLOCK;
|
2002-02-20 16:05:30 +00:00
|
|
|
return (0);
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
module_reference(module_t mod)
|
|
|
|
{
|
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_XLOCK_ASSERT;
|
|
|
|
|
2002-02-20 14:30:02 +00:00
|
|
|
MOD_DPF(REFS, ("module_reference: before, refs=%d\n", mod->refs));
|
|
|
|
mod->refs++;
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
module_release(module_t mod)
|
|
|
|
{
|
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_XLOCK_ASSERT;
|
|
|
|
|
2002-02-20 14:30:02 +00:00
|
|
|
if (mod->refs <= 0)
|
|
|
|
panic("module_release: bad reference count");
|
1997-05-07 16:05:47 +00:00
|
|
|
|
2002-02-20 14:30:02 +00:00
|
|
|
MOD_DPF(REFS, ("module_release: before, refs=%d\n", mod->refs));
|
2002-03-18 07:45:30 +00:00
|
|
|
|
2002-02-20 14:30:02 +00:00
|
|
|
mod->refs--;
|
|
|
|
if (mod->refs == 0) {
|
|
|
|
TAILQ_REMOVE(&modules, mod, link);
|
|
|
|
if (mod->file)
|
|
|
|
TAILQ_REMOVE(&mod->file->modules, mod, flink);
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_XUNLOCK;
|
2002-02-20 14:30:02 +00:00
|
|
|
free(mod, M_MODULE);
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_XLOCK;
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module_t
|
2002-02-20 14:30:02 +00:00
|
|
|
module_lookupbyname(const char *name)
|
1997-05-07 16:05:47 +00:00
|
|
|
{
|
2002-02-20 14:30:02 +00:00
|
|
|
module_t mod;
|
|
|
|
int err;
|
1997-05-07 16:05:47 +00:00
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_LOCK_ASSERT;
|
|
|
|
|
2002-02-20 14:30:02 +00:00
|
|
|
TAILQ_FOREACH(mod, &modules, link) {
|
|
|
|
err = strcmp(mod->name, name);
|
|
|
|
if (err == 0)
|
2002-02-20 16:05:30 +00:00
|
|
|
return (mod);
|
2002-02-20 14:30:02 +00:00
|
|
|
}
|
2002-02-20 16:05:30 +00:00
|
|
|
return (NULL);
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_t
|
|
|
|
module_lookupbyid(int modid)
|
|
|
|
{
|
2002-03-18 07:45:30 +00:00
|
|
|
module_t mod;
|
1997-05-07 16:05:47 +00:00
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_LOCK_ASSERT;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(mod, &modules, link)
|
|
|
|
if (mod->id == modid)
|
|
|
|
return(mod);
|
|
|
|
return (NULL);
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-07-13 19:36:59 +00:00
|
|
|
module_unload(module_t mod, int flags)
|
1997-05-07 16:05:47 +00:00
|
|
|
{
|
2004-07-13 19:36:59 +00:00
|
|
|
int error;
|
2002-02-20 14:30:02 +00:00
|
|
|
|
2006-06-26 18:34:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2004-07-13 19:36:59 +00:00
|
|
|
error = MOD_EVENT(mod, MOD_QUIESCE);
|
2004-07-15 08:26:07 +00:00
|
|
|
if (error == EOPNOTSUPP || error == EINVAL)
|
2004-07-13 19:36:59 +00:00
|
|
|
error = 0;
|
2006-06-26 18:34:45 +00:00
|
|
|
if (error == 0 || flags == LINKER_UNLOAD_FORCE)
|
|
|
|
error = MOD_EVENT(mod, MOD_UNLOAD);
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
module_getid(module_t mod)
|
|
|
|
{
|
2002-02-20 14:30:02 +00:00
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_LOCK_ASSERT;
|
2002-02-20 16:05:30 +00:00
|
|
|
return (mod->id);
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_t
|
|
|
|
module_getfnext(module_t mod)
|
|
|
|
{
|
2002-02-20 14:30:02 +00:00
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_LOCK_ASSERT;
|
2002-02-20 16:05:30 +00:00
|
|
|
return (TAILQ_NEXT(mod, flink));
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
|
1999-01-09 14:59:50 +00:00
|
|
|
void
|
|
|
|
module_setspecific(module_t mod, modspecific_t *datap)
|
|
|
|
{
|
2002-02-20 14:30:02 +00:00
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_XLOCK_ASSERT;
|
2002-02-20 14:30:02 +00:00
|
|
|
mod->data = *datap;
|
1999-01-09 14:59:50 +00:00
|
|
|
}
|
|
|
|
|
2006-04-17 19:44:44 +00:00
|
|
|
linker_file_t
|
|
|
|
module_file(module_t mod)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (mod->file);
|
|
|
|
}
|
|
|
|
|
1997-05-07 16:05:47 +00:00
|
|
|
/*
|
|
|
|
* Syscalls.
|
|
|
|
*/
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
modnext(struct thread *td, struct modnext_args *uap)
|
1997-05-07 16:05:47 +00:00
|
|
|
{
|
2002-02-20 14:30:02 +00:00
|
|
|
module_t mod;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
td->td_retval[0] = -1;
|
2002-06-26 00:31:44 +00:00
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_SLOCK;
|
2002-12-14 01:56:26 +00:00
|
|
|
if (uap->modid == 0) {
|
2002-02-20 14:30:02 +00:00
|
|
|
mod = TAILQ_FIRST(&modules);
|
|
|
|
if (mod)
|
|
|
|
td->td_retval[0] = mod->id;
|
|
|
|
else
|
|
|
|
error = ENOENT;
|
|
|
|
goto done2;
|
|
|
|
}
|
2002-12-14 01:56:26 +00:00
|
|
|
mod = module_lookupbyid(uap->modid);
|
2002-02-20 14:30:02 +00:00
|
|
|
if (mod == NULL) {
|
|
|
|
error = ENOENT;
|
|
|
|
goto done2;
|
|
|
|
}
|
|
|
|
if (TAILQ_NEXT(mod, link))
|
|
|
|
td->td_retval[0] = TAILQ_NEXT(mod, link)->id;
|
2001-09-01 19:04:37 +00:00
|
|
|
else
|
2002-02-20 14:30:02 +00:00
|
|
|
td->td_retval[0] = 0;
|
2001-09-01 19:04:37 +00:00
|
|
|
done2:
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_SUNLOCK;
|
2002-02-20 14:30:02 +00:00
|
|
|
return (error);
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
modfnext(struct thread *td, struct modfnext_args *uap)
|
1997-05-07 16:05:47 +00:00
|
|
|
{
|
2002-02-20 14:30:02 +00:00
|
|
|
module_t mod;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
td->td_retval[0] = -1;
|
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_SLOCK;
|
2002-12-14 01:56:26 +00:00
|
|
|
mod = module_lookupbyid(uap->modid);
|
2002-02-20 14:30:02 +00:00
|
|
|
if (mod == NULL) {
|
|
|
|
error = ENOENT;
|
|
|
|
} else {
|
|
|
|
error = 0;
|
|
|
|
if (TAILQ_NEXT(mod, flink))
|
|
|
|
td->td_retval[0] = TAILQ_NEXT(mod, flink)->id;
|
|
|
|
else
|
|
|
|
td->td_retval[0] = 0;
|
|
|
|
}
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_SUNLOCK;
|
2002-02-20 14:30:02 +00:00
|
|
|
return (error);
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
|
1999-01-09 14:59:50 +00:00
|
|
|
struct module_stat_v1 {
|
2002-02-22 13:33:10 +00:00
|
|
|
int version; /* set to sizeof(struct module_stat) */
|
|
|
|
char name[MAXMODNAME];
|
|
|
|
int refs;
|
|
|
|
int id;
|
1999-01-09 14:59:50 +00:00
|
|
|
};
|
|
|
|
|
1997-05-07 16:05:47 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
modstat(struct thread *td, struct modstat_args *uap)
|
1997-05-07 16:05:47 +00:00
|
|
|
{
|
2002-02-20 14:30:02 +00:00
|
|
|
module_t mod;
|
2002-03-18 07:45:30 +00:00
|
|
|
modspecific_t data;
|
2002-02-20 14:30:02 +00:00
|
|
|
int error = 0;
|
2002-03-18 07:45:30 +00:00
|
|
|
int id, namelen, refs, version;
|
2002-02-20 14:30:02 +00:00
|
|
|
struct module_stat *stat;
|
2002-03-18 07:45:30 +00:00
|
|
|
char *name;
|
2002-02-20 14:30:02 +00:00
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_SLOCK;
|
2002-12-14 01:56:26 +00:00
|
|
|
mod = module_lookupbyid(uap->modid);
|
2002-02-20 14:30:02 +00:00
|
|
|
if (mod == NULL) {
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_SUNLOCK;
|
2002-06-26 00:31:44 +00:00
|
|
|
return (ENOENT);
|
2002-02-20 14:30:02 +00:00
|
|
|
}
|
2002-03-18 07:45:30 +00:00
|
|
|
id = mod->id;
|
|
|
|
refs = mod->refs;
|
|
|
|
name = mod->name;
|
|
|
|
data = mod->data;
|
|
|
|
MOD_SUNLOCK;
|
2002-12-14 01:56:26 +00:00
|
|
|
stat = uap->stat;
|
2002-02-20 14:30:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the version of the user's structure.
|
|
|
|
*/
|
|
|
|
if ((error = copyin(&stat->version, &version, sizeof(version))) != 0)
|
2002-06-26 00:31:44 +00:00
|
|
|
return (error);
|
2002-02-20 14:30:02 +00:00
|
|
|
if (version != sizeof(struct module_stat_v1)
|
2002-06-26 00:31:44 +00:00
|
|
|
&& version != sizeof(struct module_stat))
|
|
|
|
return (EINVAL);
|
2002-02-20 14:30:02 +00:00
|
|
|
namelen = strlen(mod->name) + 1;
|
|
|
|
if (namelen > MAXMODNAME)
|
|
|
|
namelen = MAXMODNAME;
|
2002-03-18 07:45:30 +00:00
|
|
|
if ((error = copyout(name, &stat->name[0], namelen)) != 0)
|
2002-06-26 00:31:44 +00:00
|
|
|
return (error);
|
2002-02-20 14:30:02 +00:00
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
if ((error = copyout(&refs, &stat->refs, sizeof(int))) != 0)
|
2002-06-26 00:31:44 +00:00
|
|
|
return (error);
|
2002-03-18 07:45:30 +00:00
|
|
|
if ((error = copyout(&id, &stat->id, sizeof(int))) != 0)
|
2002-06-26 00:31:44 +00:00
|
|
|
return (error);
|
2002-02-20 14:30:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* >v1 stat includes module data.
|
|
|
|
*/
|
2002-06-26 00:31:44 +00:00
|
|
|
if (version == sizeof(struct module_stat))
|
2002-03-18 07:45:30 +00:00
|
|
|
if ((error = copyout(&data, &stat->data,
|
|
|
|
sizeof(data))) != 0)
|
2002-06-26 00:31:44 +00:00
|
|
|
return (error);
|
2002-02-20 14:30:02 +00:00
|
|
|
td->td_retval[0] = 0;
|
2002-02-20 16:05:30 +00:00
|
|
|
return (error);
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
modfind(struct thread *td, struct modfind_args *uap)
|
1997-05-07 16:05:47 +00:00
|
|
|
{
|
2002-02-20 14:30:02 +00:00
|
|
|
int error = 0;
|
|
|
|
char name[MAXMODNAME];
|
|
|
|
module_t mod;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
if ((error = copyinstr(uap->name, name, sizeof name, 0)) != 0)
|
2002-06-26 00:31:44 +00:00
|
|
|
return (error);
|
2002-02-20 14:30:02 +00:00
|
|
|
|
2002-03-18 07:45:30 +00:00
|
|
|
MOD_SLOCK;
|
2002-02-20 14:30:02 +00:00
|
|
|
mod = module_lookupbyname(name);
|
|
|
|
if (mod == NULL)
|
|
|
|
error = ENOENT;
|
|
|
|
else
|
2002-03-18 07:45:30 +00:00
|
|
|
td->td_retval[0] = module_getid(mod);
|
|
|
|
MOD_SUNLOCK;
|
2002-02-20 16:05:30 +00:00
|
|
|
return (error);
|
1997-05-07 16:05:47 +00:00
|
|
|
}
|
2005-01-19 17:53:06 +00:00
|
|
|
|
2008-02-13 21:34:06 +00:00
|
|
|
MODULE_VERSION(kernel, __FreeBSD_version);
|
|
|
|
|
2005-01-19 17:53:06 +00:00
|
|
|
#ifdef COMPAT_IA32
|
|
|
|
#include <sys/mount.h>
|
2007-12-06 23:11:27 +00:00
|
|
|
#include <sys/socket.h>
|
2005-01-19 17:53:06 +00:00
|
|
|
#include <compat/freebsd32/freebsd32_util.h>
|
|
|
|
#include <compat/freebsd32/freebsd32.h>
|
|
|
|
#include <compat/freebsd32/freebsd32_proto.h>
|
|
|
|
|
|
|
|
typedef union modspecific32 {
|
|
|
|
int intval;
|
|
|
|
u_int32_t uintval;
|
|
|
|
int longval;
|
|
|
|
u_int32_t ulongval;
|
|
|
|
} modspecific32_t;
|
|
|
|
|
|
|
|
struct module_stat32 {
|
|
|
|
int version;
|
|
|
|
char name[MAXMODNAME];
|
|
|
|
int refs;
|
|
|
|
int id;
|
|
|
|
modspecific32_t data;
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
freebsd32_modstat(struct thread *td, struct freebsd32_modstat_args *uap)
|
|
|
|
{
|
|
|
|
module_t mod;
|
|
|
|
modspecific32_t data32;
|
|
|
|
int error = 0;
|
|
|
|
int id, namelen, refs, version;
|
|
|
|
struct module_stat32 *stat32;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
MOD_SLOCK;
|
|
|
|
mod = module_lookupbyid(uap->modid);
|
|
|
|
if (mod == NULL) {
|
|
|
|
MOD_SUNLOCK;
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
id = mod->id;
|
|
|
|
refs = mod->refs;
|
|
|
|
name = mod->name;
|
2005-02-18 22:14:40 +00:00
|
|
|
CP(mod->data, data32, intval);
|
|
|
|
CP(mod->data, data32, uintval);
|
|
|
|
CP(mod->data, data32, longval);
|
|
|
|
CP(mod->data, data32, ulongval);
|
2005-01-19 17:53:06 +00:00
|
|
|
MOD_SUNLOCK;
|
|
|
|
stat32 = uap->stat;
|
|
|
|
|
|
|
|
if ((error = copyin(&stat32->version, &version, sizeof(version))) != 0)
|
|
|
|
return (error);
|
|
|
|
if (version != sizeof(struct module_stat_v1)
|
|
|
|
&& version != sizeof(struct module_stat32))
|
|
|
|
return (EINVAL);
|
|
|
|
namelen = strlen(mod->name) + 1;
|
|
|
|
if (namelen > MAXMODNAME)
|
|
|
|
namelen = MAXMODNAME;
|
|
|
|
if ((error = copyout(name, &stat32->name[0], namelen)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if ((error = copyout(&refs, &stat32->refs, sizeof(int))) != 0)
|
|
|
|
return (error);
|
|
|
|
if ((error = copyout(&id, &stat32->id, sizeof(int))) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* >v1 stat includes module data.
|
|
|
|
*/
|
|
|
|
if (version == sizeof(struct module_stat32))
|
|
|
|
if ((error = copyout(&data32, &stat32->data,
|
|
|
|
sizeof(data32))) != 0)
|
|
|
|
return (error);
|
|
|
|
td->td_retval[0] = 0;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif
|