From 24b62c894f6eedf71185e326e377b40bfe3aa113 Mon Sep 17 00:00:00 2001 From: dfr Date: Sat, 9 Jan 1999 14:59:50 +0000 Subject: Implement a mechanism for a module to report a small amount of module specific data back to the user via kldstat(2). Use that mechanism in the syscall handler to report the syscall number used. --- sys/kern/kern_module.c | 29 +++++++++++++++++++++++++++-- sys/kern/kern_syscalls.c | 5 ++++- 2 files changed, 31 insertions(+), 3 deletions(-) (limited to 'sys/kern') diff --git a/sys/kern/kern_module.c b/sys/kern/kern_module.c index 34b5c67..5fd126f 100644 --- a/sys/kern/kern_module.c +++ b/sys/kern/kern_module.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: kern_module.c,v 1.11 1998/10/16 03:55:00 peter Exp $ + * $Id: kern_module.c,v 1.12 1998/11/06 02:18:57 peter Exp $ */ #include @@ -48,6 +48,7 @@ struct module { char *name; /* module name */ modeventhand_t handler; /* event handler */ void *arg; /* argument for handler */ + modspecific_t data; /* module specific data */ }; #define MOD_EVENT(mod, type) (mod)->handler((mod), (type), (mod)->arg) @@ -107,6 +108,7 @@ module_register(const char* name, modeventhand_t handler, void* arg, void *file) strcpy(newmod->name, name); newmod->handler = handler; newmod->arg = arg; + bzero(&newmod->data, sizeof(newmod->data)); TAILQ_INSERT_TAIL(&modules, newmod, link); if (container == NULL) @@ -196,6 +198,12 @@ module_getfnext(module_t mod) return TAILQ_NEXT(mod, flink); } +void +module_setspecific(module_t mod, modspecific_t *datap) +{ + mod->data = *datap; +} + /* * Syscalls. */ @@ -243,6 +251,13 @@ modfnext(struct proc* p, struct modfnext_args* uap) return 0; } +struct module_stat_v1 { + int version; /* set to sizeof(struct module_stat) */ + char name[MAXMODNAME]; + int refs; + int id; +}; + int modstat(struct proc* p, struct modstat_args* uap) { @@ -263,7 +278,8 @@ modstat(struct proc* p, struct modstat_args* uap) */ if (error = copyin(&stat->version, &version, sizeof(version))) goto out; - if (version != sizeof(struct module_stat)) { + if (version != sizeof(struct module_stat_v1) + && version != sizeof(struct module_stat)) { error = EINVAL; goto out; } @@ -279,6 +295,15 @@ modstat(struct proc* p, struct modstat_args* uap) if (error = copyout(&mod->id, &stat->id, sizeof(int))) goto out; + /* + * >v1 stat includes module data. + */ + if (version == sizeof(struct module_stat)) { + if (error = copyout(&mod->data, &stat->data, sizeof(mod->data))) + goto out; + } else + printf("kldstat: v1 request\n"); + p->p_retval[0] = 0; out: diff --git a/sys/kern/kern_syscalls.c b/sys/kern/kern_syscalls.c index e8dc83b..e4fba20 100644 --- a/sys/kern/kern_syscalls.c +++ b/sys/kern/kern_syscalls.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: kern_syscalls.c,v 1.1 1999/01/03 06:00:55 root Exp root $ + * $Id: kern_syscalls.c,v 1.1 1999/01/09 14:15:41 dfr Exp $ */ #include @@ -72,6 +72,7 @@ int syscall_module_handler(struct module *mod, int what, void *arg) { struct syscall_module_data *data = (struct syscall_module_data*)arg; + modspecific_t ms; int error; switch (what) { @@ -80,6 +81,8 @@ syscall_module_handler(struct module *mod, int what, void *arg) &data->old_sysent); if (error) return error; + ms.intval = *data->offset; + module_setspecific(mod, &ms); break; case MOD_UNLOAD : error = syscall_deregister(data->offset, &data->old_sysent); -- cgit v1.1