Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Nov 2011 20:02:02 +0100
From:      Robert Millan <rmh@freebsd.org>
To:        John Baldwin <jhb@freebsd.org>
Cc:        Kostik Belousov <kostikbel@gmail.com>, Adrian Chadd <adrian@freebsd.org>, freebsd-current@freebsd.org, freebsd-arch@freebsd.org
Subject:   Re: [PATCH] Detect GNU/kFreeBSD in user-visible kernel headers
Message-ID:  <CAOfDtXNy8r5ww5xSwhH-4w7daWdzB0KsVbO75JAOT=-Wzi%2BdHw@mail.gmail.com>
In-Reply-To: <201111170959.56767.jhb@freebsd.org>
References:  <CAOfDtXPX1Rv9T7%2B1jYQbkM14tRY7mqgCzPcUqvHxFaRObbwvEg@mail.gmail.com> <B188597B-4446-4EAB-A9BD-D9EBBEB8B1D7@bsdimp.com> <CAOfDtXMsmDa2XaZ0qmMKZxF5xagotw5EwaU=7y_GUxKLhaJ9OQ@mail.gmail.com> <201111170959.56767.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
2011/11/17 John Baldwin <jhb@freebsd.org>:
> I recall the discussion from earlier.  I can't recall if I had replied to it
> though. :-/  In my current opinion, I think it would be fine to define
> __FreeBSD_kernel__ on FreeBSD and to do it in <sys/param.h> for now until all
> the compilers we use have been updated to define it automatically (which may
> be a long time).  I think it will also be fine to patch in-system headers to
> use __FreeBSD_kernel__ once <sys/param.h> is defined.  Unfortunately headers
> in 3rd party software are going to have to check for both __FreeBSD__ and
> __FreeBSD_kernel__ to support both GNU/kFreeBSD and older FreeBSD for the
> foreseeable future.  I think that is fine, but that the sooner we add
> __FreeBSD_kernel__ on FreeBSD the sooner we get the clock started for a day
> when those extra checks can go away.  I would also be fine with MFC'ing the
> addition of __FreeBSD_kernel__ to older branches (at least 7 - 9) as well.

Well, here's a patch then.  I wrote a comment in it trying to explain
the situation.  Please let me know what you think.

[-- Attachment #2 --]
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__
+
 #ifdef _KERNEL
 #define	P_OSREL_SIGWAIT		700000
 #define	P_OSREL_SIGSEGV		700004

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOfDtXNy8r5ww5xSwhH-4w7daWdzB0KsVbO75JAOT=-Wzi%2BdHw>