Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Mar 2003 19:07:21 +1100
From:      Peter Jeremy <peterjeremy@optushome.com.au>
To:        Sean Kelly <smkelly@zombie.org>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: Smarter kernel modules?
Message-ID:  <20030306080721.GA93885@cirb503493.alcatel.com.au>
In-Reply-To: <20030306074919.GA3045@edgemaster.zombie.org>
References:  <20030305.215901.36360277.imp@bsdimp.com> <20030306074919.GA3045@edgemaster.zombie.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Mar 06, 2003 at 01:49:20AM -0600, Sean Kelly wrote:
>> +/*
>> + * Define the version.  Change the symbol name when things get too
>> + * incompatible.  version_5_1 means the 'ABI compatible with FreeBSD 5.1'
>> + */
>> +char __version_5_1 = 1;
>...
>
>Wouldn't it make more sense to have a symbol name that doesn't change
>across versions? Something like '_module_version' perhaps. Then the value
>of the symbol is the version which the module corresponds to. This would
>let you use something like kern.osreldate or a per-subsystem version index.

No.  Warner's trick is that each module includes an unresolved
reference to the version symbol (in <module.h>), which is defined in
the kernel.  If the kernel run-time loader can't resolve the reference
(meaning that the version symbol has changed in the kernel) then it
will report and error and refuse to load the module - neither the
kernel nor the module need to know anything about versioning.  (Though
the name needs to be kept aligned in two different files).

The actual value of the symbol is irrelevant (though it could
potentially be used to differentiate different mostly-compatible
kernels).

>config.h:
>#define API_VERSION 500100
>
>mymodule.c:
>long _module_version = API_VERSION;

And I presume the kernel then verifies that _module_version in the
just-loaded .ko matches the kernel's idea of API_VERSION.  Overall,
this is equivalent to Warner's approach except that the kernel needs
to explicitly check the contents of _module_version (and the loader
needs to understand having identical symbols declared in multiple
modules - ie _module_version becomes a special name).

>Another benefit(?) is that if _module_version is missing, you can decide
>that you don't care about versioning and just load the module.

This exists implicitly in Warner's code as well - if there's no
reference to the kernel version symbol then the load will succeed
whatever the name of the version symbol in the kernel.

Peter

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030306080721.GA93885>