Sysinit

Reference 1

generic call sort and dispatch mechanism;

dynamic initialization of kernel;

allows kernel subsystems to be reordered, and added, removed, and replaced at kernel link time when kernel or one of its module is loaded;

without having to edit a statically ordered initialization routing and recompile the kernel;

kernel linker

Linker: take static data declared at multiple locations throughout a program’s source and group it together as a single contiguous chunk of data. This linker technique is called a “linker set”.

SYSINIT uses two linker sets to maintain two data sets containing each consumer’s call order, function, and a pointer to the data to pass to that function. Startup and shutdown data sets.

Two priorities:

  • subsystem ID, predcalared orders insys/kernel.h: sysinit_sub_id;
  • secondary priority within a subsystem, predcalared orders in sys/kernel.h:sysinit_elem_order;

Two Uses of SYSINIT:

  • function dispatch at system startup and kernel module loads;
  • function dispatch at system shutdown and kernel module unload.

  • system startup SYSINIT to initialize data structures. e.g. process scheduling subsystem uses a SYSINIT to initialize the run queue data structure.

Definition

in sys/kernel.h

SYSINIT(uniquifier, subsystem, order, func, ident) // for startup data set SYSUNINIT(uniquifier, subsystem, order, func, ident) // for shutdown data set

SYSINIT() macro: takes a uniquifier (that SYSINIT uses to identify the particular function dispatch data), the subsystem order, the subsystem element order, the function to call, and the data to pass the function. All functions must take a constant pointer argument.

Example:

#include <sys/kernel.h>

void foo_null(void *unused)
{
        foo_doo();
}
SYSINIT(foo, SI_SUB_FOO, SI_ORDER_FOO, foo_null, NULL);

struct foo foo_voodoo = {
        FOO_VOODOO;
}

void foo_arg(void *vdata)
{
        struct foo *foo = (struct foo *)vdata;
        foo_data(foo);
}
SYSINIT(bar, SI_SUB_FOO, SI_ORDER_FOO, foo_arg, &foo_voodoo);

SI_SUB_FOO and SI_ORDER_FOO defined in sysinit_sub_id and sysinit_elem_order enum’s.

Created Oct 30, 2019 // Last Updated Oct 30, 2019

If you could revise
the fundmental principles of
computer system design
to improve security...

... what would you change?