diff --git a/sys/sys/module.h b/sys/sys/module.h --- a/sys/sys/module.h +++ b/sys/sys/module.h @@ -153,11 +153,35 @@ #endif /* - * The module declared with DECLARE_MODULE_TIED can only be loaded + * Modules declared with DECLARE_MODULE_RELENG can only be loaded into + * a kernel built on the same releng/X.Y branch. This is useful for + * modules that use kernel interfaces that are not stable on stable/X + * branches but are stable on release branches. + * + * Note that releng/X.Y versions have values 0..499 in the low three + * digits and stable/X versions have 500..999 in the low three digits. + * This macro requires an exact match like DECLARE_MODULE_TIED for + * stable/X but permits loading on newer kernels on the same + * releng/X.Y branch. + * + * This isn't quite right for main prior to X.0 whose low three digits + * also fall in the 0..499 range. + */ +#define MODULE_KERNEL_RELENG_MAXVER \ + ((__FreeBSD_version % 1000 <= 500) ? \ + (roundup(__FreeBSD_version, 500) - 1) : \ + __FreeBSD_version) + +#define DECLARE_MODULE_RELENG(name, data, sub, order) \ + DECLARE_MODULE_WITH_MAXVER(name, data, sub, order, \ + MODULE_KERNEL_RELENG_MAXVER) + +/* + * Modules declared with DECLARE_MODULE_TIED can only be loaded * into the kernel with exactly the same __FreeBSD_version. * * Use it for modules that use kernel interfaces that are not stable - * even on STABLE/X branches. + * even on stable/X branches. */ #define DECLARE_MODULE_TIED(name, data, sub, order) \ DECLARE_MODULE_WITH_MAXVER(name, data, sub, order, __FreeBSD_version)