Re: [RFC] Splitting kernel headers and deprecating __KERNEL__

Werner Almesberger
2004-12-14T05:52:06Z

Linus Torvalds wrote:
> Ok, this discussion has gone on for too long anyway, but let's make it
> easier for everybody. The kernel uses u8/u16/u32 because:
>
> - the kernel should not depend on, or pollute user-space naming.
> YOU MUST NOT USE "uint32_t" when that may not be defined, and
> user-space rules for when it is defined are arcane and totally
> arbitrary.

Hmm, so you're predicting problems if user space includes something
that uses uint32_t ? Wouldn't either of these work (descriptive file
names for clarity):

1) include/linux-user/foo.h:
#include <stdint.h>
#include <linux-kernel-and-user-common/foo.h>

include/linux/foo.h:
#include <linux/stdint.h>
#include <linux-kernel-and-user-common/foo.h>

(And document that anything under linux-user may pull in a
certain set of standard headers, such as stdint.h, maybe
sys/types.h, etc.)

2) include/linux-user/foo.h:
#ifndef __KERNEL__
#include <stdint.h>
#else
#include <linux/stdint.h> /* if we want this */
#endif
...
foo stuff (or some include)
...

Idem. (Sort of the opposite of what we have today.)

3) just require that some stdint.h has been included before
including linux-user/foo.h

For user space that absolutely insists on doing its own uint32_t,
a refined variant of case 3 (i.e. detailing of what exactly is
expected to be defined) or, in case 1, direct use of
linux-kernel-and-user-common/foo.h along with the definition from
case 3 should work.

There are other cases where a header file may pull in other
definitions, e.g. for fcntl.h, POSIX decrees

| Inclusion of the <fcntl.h> header may also make visible all
| symbols from <sys/stat.h> and <unistd.h>.

So the semantics of for cases 1 and 2 would be consistent with
current POSIX practice.

What am I missing ?

- Werner

--
_________________________________________________________________________
/ Werner Almesberger, Buenos Aires, Argentina wa@almesberger.net /
/_http://www.almesberger.net/____________________________________________/