Subject: Re: foo_init()s in main() [was: CVS commit: src/sys]
To: None <tech-kern@NetBSD.org>
From: None <joerg@britannica.bec.de>
List: tech-kern
Date: 11/22/2005 11:06:46
On Tue, Nov 22, 2005 at 08:50:32PM +1100, Simon Burge wrote:
> Martin Husemann wrote:
> 
> > On Tue, Nov 22, 2005 at 11:29:35AM +1100, Simon Burge wrote:
> > > It really seems like we should do something to automate this, say based
> > > on the FreeBSD sysinit stuff or linksets or something.
> > 
> > Yes, we should.
> > Could anyone give a summary of "FreeBSD sysinit" stuff?
> 
> In a very brief nut-shell there's a macro SYSINIT:
> 
> 	#define SYSINIT(uniquifier, subsystem, order, func, ident) \
> 	  ...
> 
> which builds a link set of initialisation functions.
> 
> "uniquifier" is used to build the link set variable name. "subsystem" is
> a numeric constant that defines the order of the function in the startup
> sequence [1]. "order" sorts orders within a subsystem [2]. "func" is the
> function, and "ident" appears to be an arg to "func".
> 
> To pick an example at random, net/route.c then says:
> 
>    SYSINIT(route, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, route_init, 0);

Jup, that's it. There's one more point (somewhat hidden): every module
has an SYSINIT as well, where it can simulate the module load event even
if it is built into the kernel.

Joerg