2011/11/18 Robert Millan <r...@freebsd.org>:
> 2011/11/17 John Baldwin <j...@freebsd.org>:
>> Hmm, I wonder if it's better to use the #ifndef approach rather than #undef
>> so that when compilers are updated to DTRT we will honor their settings?
>
> Well, the compiler is supposed to know better than sys/param.h,

I gave this a bit more thought....

The compiler knows about the system it was intended to build for, but
sys/param.h *is* part of the system we're building for.  It's
impossible for sys/param.h to have the wrong information unless it's
out of sync with the rest of the headers.

As for the compiler, on FreeBSD it's hard for the compiler to be out
of sync, because the system (in comparison with others) is tightly
packaed and upgrade procedures are well defined.

But if you take Debian, for example, we use the same compiler to build
8-STABLE, 9-STABLE and 10-CURRENT kernels.  The compiler has no idea
which version of FreeBSD the sources it is building come from.

I wouldn't put compilers in general in a position where they're forced
to know the FreeBSD major version beforehand because sys/param.h will
give preference to the information coming from compiler.

I propose this alternate patch which derives the major number from
__FreeBSD_version instead.
Index: sys/sys/param.h
===================================================================
--- sys/sys/param.h	(revision 227580)
+++ sys/sys/param.h	(working copy)
@@ -60,6 +60,23 @@
 #undef __FreeBSD_version
 #define __FreeBSD_version 1000001	/* Master, propagated to newvers */
 
+/*
+ * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
+ * which by definition is always true on FreeBSD :-). This macro may also
+ * be defined on other systems that use the kernel of FreeBSD, such as
+ * GNU/kFreeBSD.
+ *
+ * It is tempting to use this macro in userland code when we want to enable
+ * kernel-specific routines, and in fact it's fine to do this in code that
+ * is part of FreeBSD itself.  However, be aware that as presence of this
+ * macro is still not widespread (e.g. older FreeBSD versions, 3rd party
+ * compilers, etc), it is STRONGLY DISCOURAGED to check for this macro in
+ * external applications without also checking for __FreeBSD__ as an
+ * alternative.
+ */
+#undef __FreeBSD_kernel__
+#define __FreeBSD_kernel__ (__FreeBSD_version / 100000)
+
 #ifdef _KERNEL
 #define	P_OSREL_SIGWAIT		700000
 #define	P_OSREL_SIGSEGV		700004
_______________________________________________
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"

Reply via email to