toaruos/modules
K. Lange 053d49a231 Also calculate rough percentage
As this includes shm, it overestimates and values may add up to more than 100%
2018-09-14 21:11:26 +09:00
..
ac97.c Fix up AC97 driver? 2018-07-21 21:44:38 +09:00
ata.c Don't show /dev/cdrom0 if it's empty (for now) 2018-09-11 17:43:34 +09:00
ataold.c Don't use my given name in copyright headers; update everything to 2018 because why not 2018-05-01 17:12:56 +09:00
debug_sh.c Fix debug shell not being able to start a shell by allowing system() in kernel to take an env 2018-08-14 11:33:02 +09:00
dospart.c Don't use my given name in copyright headers; update everything to 2018 because why not 2018-05-01 17:12:56 +09:00
e1000.c [e1000] Write MAC into receive address field (fixes net in bochs) 2018-09-11 15:22:54 +09:00
ext2.c more filesystem permission things, add rm 2018-07-18 15:35:52 +09:00
hda.c Reorganize headers 2018-03-19 11:38:11 +09:00
iso9660.c Don't use my given name in copyright headers; update everything to 2018 because why not 2018-05-01 17:12:56 +09:00
lfbvideo.c [experimental] Enable write-combining in video memory with PAT? 2018-08-06 16:32:06 +09:00
link.ld Merge kernel 2018-03-16 21:56:19 +09:00
net.c Fix net reads when len < available packet size 2018-07-01 10:02:33 +09:00
packetfs.c more filesystem permission things, add rm 2018-07-18 15:35:52 +09:00
pcnet.c PIIX PIRQ handling? 2018-07-21 16:57:36 +09:00
pcspkr.c Remove unused debugshell dep for pcspkr 2018-07-20 19:07:23 +09:00
procfs.c Also calculate rough percentage 2018-09-14 21:11:26 +09:00
ps2kbd.c IRQ stuff 2018-07-21 16:02:39 +09:00
ps2mouse.c IRQ stuff 2018-07-21 16:02:39 +09:00
random.c Don't use my given name in copyright headers; update everything to 2018 because why not 2018-05-01 17:12:56 +09:00
README.md Add module README 2018-08-21 16:45:13 +09:00
rtl.c PIIX PIRQ handling? 2018-07-21 16:57:36 +09:00
serial.c IRQ stuff 2018-07-21 16:02:39 +09:00
snd.c Unify list, tree, hashmap implementations with userspace/kernel 2018-04-24 19:28:50 +09:00
tmpfs.c Reduce tmpfs debug message levels 2018-07-21 12:21:54 +09:00
usbuhci.c Don't use my given name in copyright headers; update everything to 2018 because why not 2018-05-01 17:12:56 +09:00
vbox.c Allow seamless and pointer integration to be turned off 2018-08-23 12:51:32 +09:00
vgadbg.c Reorganize headers 2018-03-19 11:38:11 +09:00
vgalog.c Fix warning from bad terminal callbacks in vgalog.ko 2018-09-02 00:14:10 +09:00
vidset.c Don't use my given name in copyright headers; update everything to 2018 because why not 2018-05-01 17:12:56 +09:00
vmware.c Fix absolute mouse cursors when in text mode 2018-05-15 16:37:51 +09:00
xtest.c Don't use my given name in copyright headers; update everything to 2018 because why not 2018-05-01 17:12:56 +09:00
zero.c Don't use my given name in copyright headers; update everything to 2018 because why not 2018-05-01 17:12:56 +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.