/*- * Copyright (c) 1999 Assar Westerlund * 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. * * $FreeBSD: src/share/examples/kld/syscall/module/syscall.c,v 1.2 1999/08/28 00:19:23 peter Exp $ */ /* * adapted for kobj example */ #include #include #include #include #include #include #include #include #include #include "hello_if.h" static void my_hello_world(kobj_t o) { printf("hello world!\n"); } static void my_hello_static_world(kobj_t o) { printf("hello static world!\n"); } static kobj_method_t hello_methods[] = { KOBJMETHOD(hello_world, my_hello_world), KOBJMETHOD(hello_static_world, my_hello_static_world), { 0, 0 } }; static kobj_method_t null_methods[] = { { 0, 0 } }; static DEFINE_CLASS(hello, hello_methods, sizeof(struct kobj)); static DEFINE_CLASS(null, null_methods, sizeof(struct kobj)); static int hello(struct proc *p, void *unused) { kobj_t o; kobj_class_compile(&hello_class); HELLO_STATIC_WORLD(&hello_class); o = kobj_create(&null_class, M_TEMP, M_WAITOK); HELLO_WORLD(o); kobj_class_free(&null_class); kobj_init(o, &hello_class); HELLO_WORLD(o); kobj_delete(o, M_TEMP); return 0; } static struct sysent hello_sysent = { 0, /* sy_narg */ hello /* sy_call */ }; static int offset = NO_SYSCALL; static int load (struct module *module, int cmd, void *arg) { int error = 0; switch (cmd) { case MOD_LOAD : printf ("syscall loaded at %d\n", offset); break; case MOD_UNLOAD : printf ("syscall unloaded from %d\n", offset); break; default : error = EINVAL; break; } return error; } SYSCALL_MODULE(syscall, &offset, &hello_sysent, load, NULL);