summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys/kern/kern_module.c2
-rw-r--r--sys/sys/module.h13
2 files changed, 15 insertions, 0 deletions
diff --git a/sys/kern/kern_module.c b/sys/kern/kern_module.c
index 9a1f159..72a6991 100644
--- a/sys/kern/kern_module.c
+++ b/sys/kern/kern_module.c
@@ -414,6 +414,8 @@ modfind(struct thread *td, struct modfind_args *uap)
return (error);
}
+MODULE_VERSION(kernel, __FreeBSD_version);
+
#ifdef COMPAT_IA32
#include <sys/mount.h>
#include <sys/socket.h>
diff --git a/sys/sys/module.h b/sys/sys/module.h
index b621ba3..bcffb45 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
OpenPOWER on IntegriCloud