K. Lange 36e9046ae8 Allow modules to install procfs entries 2 years ago
..
README.md 8bf3e55f4e Add module README 2 years ago
ac97.c 53b3d3781d Fix up AC97 driver? 2 years ago
ata.c b9e0a85817 Don't show /dev/cdrom0 if it's empty (for now) 2 years ago
ataold.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 2 years ago
debug_sh.c 864cbdb868 Fix debug shell not being able to start a shell by allowing system() in kernel to take an env 2 years ago
dospart.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 2 years ago
e1000.c cec9d43bcf [e1000] Write MAC into receive address field (fixes net in bochs) 2 years ago
ext2.c 35a2a4bc5c more filesystem permission things, add rm 2 years ago
hda.c 1355502e6c Reorganize headers 2 years ago
iso9660.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 2 years ago
lfbvideo.c 36e9046ae8 Allow modules to install procfs entries 2 years ago
link.ld 8080a74a2d Module dependencies 6 years ago
net.c 36e9046ae8 Allow modules to install procfs entries 2 years ago
packetfs.c 35a2a4bc5c more filesystem permission things, add rm 2 years ago
pcnet.c f10a54dd2b PIIX PIRQ handling? 2 years ago
pcspkr.c eb1c435697 Remove unused debugshell dep for pcspkr 2 years ago
portio.c c1e42d2e07 add /dev/port 2 years ago
procfs.c 36e9046ae8 Allow modules to install procfs entries 2 years ago
ps2kbd.c 095d087e1d IRQ stuff 2 years ago
ps2mouse.c 095d087e1d IRQ stuff 2 years ago
random.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 2 years ago
rtl.c f10a54dd2b PIIX PIRQ handling? 2 years ago
serial.c 095d087e1d IRQ stuff 2 years ago
snd.c 5dd763780a Unify list, tree, hashmap implementations with userspace/kernel 2 years ago
tmpfs.c c2b8449fd7 Reduce tmpfs debug message levels 2 years ago
usbuhci.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 2 years ago
vbox.c cdccc913ab Allow seamless and pointer integration to be turned off 2 years ago
vgadbg.c 1355502e6c Reorganize headers 2 years ago
vgalog.c 5ddce4e51d Fix warning from bad terminal callbacks in vgalog.ko 2 years ago
vidset.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 2 years ago
vmware.c c4c8b42c53 vmware module description update 2 years ago
xtest.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 2 years ago
zero.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 2 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.