Skip to content

Instantly share code, notes, and snippets.

@semahawk
Created October 25, 2013 18:52
Show Gist options
  • Save semahawk/7159890 to your computer and use it in GitHub Desktop.
Save semahawk/7159890 to your computer and use it in GitHub Desktop.
SRCS=skelkld.c
KMOD=skeleton
.include <bsd.kmod.mk>
/*
* A simple KLD Skeleton example.
*
* http://www.freebsd.org/doc/en/books/arch-handbook/driverbasics-kld.html
*
*/
#include <sys/types.h>
#include <sys/module.h>
#include <sys/systm.h> /* uprintf */
#include <sys/errno.h>
#include <sys/param.h>
#include <sys/kernel.h>
/*
* Load handler that deals with the loading and unloading of a KLD.
*/
static int
skel_loader(struct module *m, int what, void *arg)
{
int err = 0;
switch (what){
case MOD_LOAD: /* kldload */
uprintf("Skeleton KLD loaded.\n");
break;
case MOD_UNLOAD: /* kldunload */
uprintf("Skeleton KLD unloaded.\n");
break;
default:
err = EOPNOTSUPP;
break;
}
return err;
}
/*
* Declare this module to the rest of the kernel
*/
static moduledata_t skel_mod = {
"skel",
skel_loader,
NULL
};
DECLARE_MODULE(skeleton, skel_mod, SI_SUB_KLD, SI_ORDER_ANY);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment