aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/module.h
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2008-02-13 21:34:06 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2008-02-13 21:34:06 +0000
commit74712770546bf340a05465b7c9df2920c307fe8c (patch)
tree4734b09151b6cbfec94b1e271c004388dfe14c0d /sys/sys/module.h
parentd98b6d44968cd95cda700d1ba6305f807ada1f50 (diff)
downloadsrc-74712770546bf340a05465b7c9df2920c307fe8c.tar.gz
src-74712770546bf340a05465b7c9df2920c307fe8c.zip
Add an automatic kernel module version dependency to prevent loading
modules using invalid ABI versions (e.g. a 7.x module with an 8.x kernel) for a given kernel: - Add a 'kernel' module version whose value is __FreeBSD_version. - Add a version dependency on 'kernel' in every module that has an acceptable version range of __FreeBSD_version up to the end of the branch __FreeBSD_version is part of. E.g. a module compiled on 701000 would work on kernels with versions between 701000 and 799999 inclusive. Discussed on: arch@ MFC after: 1 week
Notes
Notes: svn path=/head/; revision=176252
Diffstat (limited to 'sys/sys/module.h')
-rw-r--r--sys/sys/module.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/sys/sys/module.h b/sys/sys/module.h
index b621ba3d12e6..bcffb452905b 100644
--- a/sys/sys/module.h
+++ b/sys/sys/module.h
@@ -114,7 +114,20 @@ struct mod_metadata {
MODULE_METADATA(_md_##module##_on_##mdepend, MDT_DEPEND, \
&_##module##_depend_on_##mdepend, #mdepend)
+/*
+ * Every kernel has a 'kernel' module with the version set to
+ * __FreeBSD_version. We embed a MODULE_DEPEND() inside every module
+ * that depends on the 'kernel' module. It uses the current value of
+ * __FreeBSD_version as the minimum and preferred versions. For the
+ * maximum version it rounds the version up to the end of its branch
+ * (i.e. M99999 for M.x). This allows a module built on M.x to work
+ * on M.y systems where y >= x, but fail on M.z systems where z < x.
+ */
+#define MODULE_KERNEL_MAXVER (roundup(__FreeBSD_version, 100000) - 1)
+
#define DECLARE_MODULE(name, data, sub, order) \
+ MODULE_DEPEND(name, kernel, __FreeBSD_version, \
+ __FreeBSD_version, MODULE_KERNEL_MAXVER); \
MODULE_METADATA(_md_##name, MDT_MODULE, &data, #name); \
SYSINIT(name##module, sub, order, module_register_init, &data) \
struct __hack