K. Lange df449d4b94 net: actually attempt to close sockets 3 years ago
..
README.md 8bf3e55f4e Add module README 3 years ago
ac97.c 53b3d3781d Fix up AC97 driver? 4 years ago
ata.c b9e0a85817 Don't show /dev/cdrom0 if it's empty (for now) 3 years ago
ataold.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago
debug_sh.c f9a64b6ac7 debug_sh: cleanup 3 years ago
dospart.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago
e1000.c 30b0b9477b e1000: add mobile chipset pci id 3 years ago
ext2.c 35a2a4bc5c more filesystem permission things, add rm 4 years ago
hda.c 1355502e6c Reorganize headers 4 years ago
iso9660.c c2e0255066 iso9660: permissions shouuld be 0555 3 years ago
lfbvideo.c 4d854b156c lfbvideo: allow display initialize to be triggered by ioctl 3 years ago
net.c df449d4b94 net: actually attempt to close sockets 3 years ago
packetfs.c 35a2a4bc5c more filesystem permission things, add rm 4 years ago
pcnet.c f10a54dd2b PIIX PIRQ handling? 4 years ago
pcspkr.c eb1c435697 Remove unused debugshell dep for pcspkr 4 years ago
portio.c c1e42d2e07 add /dev/port 3 years ago
procfs.c 3d2e94d387 procfs: indicate stopped (T) in status 3 years ago
ps2kbd.c 095d087e1d IRQ stuff 4 years ago
ps2mouse.c 095d087e1d IRQ stuff 4 years ago
random.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago
rtl.c f10a54dd2b PIIX PIRQ handling? 4 years ago
serial.c 81ba10fe3f serial: new direct tty serial driver 3 years ago
snd.c 5dd763780a Unify list, tree, hashmap implementations with userspace/kernel 4 years ago
tmpfs.c 758a8b6cf4 tmpfs: mount through startup, not on module load 3 years ago
usbuhci.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago
vbox.c cdccc913ab Allow seamless and pointer integration to be turned off 3 years ago
vgadbg.c 1355502e6c Reorganize headers 4 years ago
vgalog.c 31214693dd Fixes to build kernel and modules with clang 3 years ago
vidset.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago
vmware.c c4c8b42c53 vmware module description update 3 years ago
xtest.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago
zero.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago

README.md

Kernel Modules

The Toaru kernel supports loadable modules which provide most of the device driver support.

A simple module requires a load and unload method, which are exposed along with a module name through the MODULE_DEF macro available from <kernel/module.h>.

#include <kernel/module.h>

static int load(void) {
	/* Run on module installation */
	return 0;
}

static int unload(void) {
	/* Clean up for removal */
	return 0;
}

MODULE_DEF(example_mod, load, unload);

Module Dependencies

If your module depends on another module being loaded, list each dependency using the MODULE_DEPENDS macro:

MODULE_DEF(extension_mod, load, unload);
MODULE_DEPENDS(example_mod);

Currently, dependencies are tested at load time, but the kernel will not load dependencies for you.

Dependency lists can be parsed by external tools to ensure modules are properly linked.

Kernel Functions

All non-static kernel functions are available for use in modules. For example, the logging functions may be used:

#include <kernel/logging.h>
#include <kernel/module.h>

static int load(void) {
	debug_print(WARNING, "Hello, world.");
	return 0;
}

static int unload(void) {
	return 0;
}

MODULE_DEF(printing_mod, load, unload);

Background Tasks

Device drivers, such as those for network devices, may want to create a background process to manage tasks. This can be done through the create_kernel_tasklet interface at device startup.

#include <kernel/process.h>
#include <kernel/module.h>

static void tasklet_run(void * data, char * name) {
	/* Perform tasklet activities */
	while (1) {
		do_thing();
	}
}

static int load(void) {
	create_kernel_tasklet(tasklet_run, "[demo-tasklet]", NULL);
	return 0;
}

static int unload(void) {
	/* Maybe clean up your tasklet here. */
	return 0;
}

MODULE_DEF(tasklet_mod, load, unload);

Caveats

  • Currently, unloading modules is not supported.
  • Modules which are expected to be loaded at runtime should be very careful of memory allocations they make, as they happen in a context which may not be shared with other processes. If you wish to make use of memory mappings, ensure that you are creating a new kernel tasklet to perform work. Attempting to access mapped memory from an interrupt handler or a device driver may not be possible if it was mapped at module installation.