toaruos/modules
2020-04-24 21:53:20 +09:00
..
ac97.c
ata.c ata: apply same change for atapi 2018-12-28 09:49:58 +09:00
ataold.c kernel: 64-bit offsets for VFS 2018-11-23 09:56:44 +09:00
debug_sh.c debug_sh: fix bad format string in pci command 2019-02-15 11:03:18 +09:00
dospart.c kernel: 64-bit offsets for VFS 2018-11-23 09:56:44 +09:00
e1000.c e1000: add mobile chipset pci id 2018-10-21 20:31:48 +09:00
ext2.c kernel: remove calls to calloc (they confuse the tracker) 2018-12-12 10:31:42 +09:00
hda.c
iso9660.c kernel: 64-bit offsets for VFS 2018-11-23 09:56:44 +09:00
lfbvideo.c kernel: 64-bit offsets for VFS 2018-11-23 09:56:44 +09:00
net.c kernel: change some log levels 2018-12-03 11:22:33 +09:00
packetfs.c kernel: 64-bit offsets for VFS 2018-11-23 09:56:44 +09:00
pcnet.c
pcspkr.c pcspkr: accept -1 and 0 as special lengths 2018-11-29 20:55:30 +09:00
portio.c portio: /dev/port is a block device, not a character device (it support seek) 2019-12-17 11:57:07 +09:00
procfs.c procfs: fix BAR5 typo 2019-02-15 10:57:57 +09:00
ps2kbd.c ps2kbd: why are we giving current_process this 2018-12-11 23:16:29 +09:00
ps2mouse.c
random.c kernel: 64-bit offsets for VFS 2018-11-23 09:56:44 +09:00
README.md Add module README 2018-08-21 16:45:13 +09:00
rtl.c
serial.c serial: new direct tty serial driver 2018-10-29 19:55:55 +09:00
snd.c kernel: 64-bit offsets for VFS 2018-11-23 09:56:44 +09:00
tarfs.c tarfs: minor speedup, assuming well-ordered archives 2018-12-20 19:06:46 +09:00
tmpfs.c tmpfs: probably off-by-one, let's be safe 2018-12-11 12:20:08 +09:00
usbuhci.c
vbox.c toggle-relative-mouse: add query option 'get' 2018-11-27 20:40:46 +09:00
vgadbg.c
vgalog.c vgalog: fix incomplete initializer 2020-03-28 23:56:08 +09:00
vidset.c
vmware.c vmware: initialize vmware_mouse_byte or it resolves incorrectly by linker 2020-04-24 21:53:20 +09:00
xtest.c
zero.c kernel: 64-bit offsets for VFS 2018-11-23 09:56:44 +09:00

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.