kernel header separation
Subsystems (2)
In a continuing series of "Things we should have done 5 years ago, do they really need to be done before the release of 2.6.0", here's a prototype of splitting the kernel headers into stuff we want userspace to see and stuff we don't.
The basic principle is to put user headers in usr/include/linux and usr/include/asm-$(ARCH). Kernel headers may then include them as <user/foo.h> and <user-asm/foo.h>
This patch implents the 4 lines of Makefile magic necessary and converts cdrom.h to use this split. Note that we can convert headers as slowly as we care to with this scheme.
Index: Makefile
===================================================================
RCS file: /var/cvs/linux-2.6/Makefile,v
retrieving revision 1.28
Makefile +7 -1
@@ -472,7 +472,7 @@ $(SUBDIRS): prepare # module versions are listed in "prepare" .PHONY: prepare -prepare: include/linux/version.h include/asm include/config/MARKER +prepare: include/linux/version.h include/asm include/user include/config/MARKER ifdef KBUILD_MODULES ifeq ($(origin SUBDIRS),file) $(Q)rm -rf $(MODVERDIR)
@@ -513,6 +513,12 @@ export AFLAGS_vmlinux.lds.o += -P -C -U$ include/asm: @echo ' Making asm->asm-$(ARCH) symlink' @ln -s asm-$(ARCH) $@ + +# Can't rely on distributing these syminks as patches +include/user: + @echo ' Making user->usr/include/linux symlink' + @ln -s ../usr/include/linux $@ + @ln -s ../usr/include/asm-$(ARCH) include/user-asm # Split autoconf.h into include/linux/config/*
Index: include/linux/cdrom.h
===================================================================
RCS file: /var/cvs/linux-2.6/include/linux/cdrom.h,v retrieving revision 1.1
linux/cdrom.h +1 -706
719 lines not on this page · raw message
Index: usr/include/linux/cdrom.h
===================================================================
RCS file: usr/include/linux/cdrom.h
include/linux/cdrom.h new file +719 -0
719 lines not on this page · raw message
Signature · 3 lines
"It's not Hollywood. War is real, war is primarily not about defeat or victory, it is about death. I've seen thousands and thousands of dead bodies. Do you think I want to have an academic debate on this subject?" -- Robert Fisk
Quoted 6 lines · Matthew Wilcox
In a continuing series of "Things we should have done 5 years ago, do they really need to be done before the release of 2.6.0", here's a prototype of splitting the kernel headers into stuff we want userspace to see and stuff we don't.
Quoted 7 lines
The basic principle is to put user headers in
usr/include/linuxand usr/include/asm-$(ARCH). Kernel headers may then include them as <user/foo.h> and <user-asm/foo.h>This patch implents the 4 lines of
Makefilemagic necessary and convertscdrom.hto use this split. Note that we can convert headers as slowly as we care to with this scheme.
Wohoo!! Great stuff. I hope this effort continues....
Quoted 9 lines
RCS file:
usr/include/linux/cdrom.h
diff -Nusr/include/linux/cdrom.hinclude/linux/cdrom.h new file +4
-0@@ -0,0 +1,719 @@ +/* +* -- <linux/cdrom.h> +* General header file for linux CD-ROM drivers +* Copyright (C) 1992 David Giller, [email protected]
include/linux/cdrom.h line 14
Quoted 10 lines
include/linux/cdrom.h new file +10
-0+* 1994, 1995 Eberhard Moenkeberg, [email protected] +* 1996 David van Leeuwen, [email protected] +* 1997, 1998 Erik Andersen, [email protected] +* 1998-2000 Jens Axboe, [email protected] +*/ + +#ifndef _LUSER_CDROM_H +#define _LUSER_CDROM_H + +#include <linux/types.h>
Header files intended for use by users should probably drop linux/types.h just include <stdint.h>,,, Then convert the types over to ISO C99 types.
s/__u8/uint8_t/g
s/__u16/uint16_t/g
s/__u32/uint32_t/g
s/__u64/uint64_t/g
s/__s8/int8_t/g
s/__s16/int16_t/g
s/__s32/int32_t/g
s/__s64/int64_t/g
What do you think?
-Erik
--
Erik B. Andersen http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--
Quoted 3 lines · Erik Andersen
Header files intended for use by users should probably drop
linux/types.hjust include <stdint.h>,,, Then convert the types over to ISO C99 types.
Yes. Absolutely. In fact, we should do the rest of the kernel with as much fervour as we've been changing struct initialisers... but at least the user headers would be a good start.
Signature · 1 line
dwmw2
Quoted 8 lines · David Woodhouse
Quoted 3 lines · Erik Andersen
Header files intended for use by users should probably drop
linux/types.hjust include <stdint.h>,,, Then convert the types over to ISO C99 types.Yes. Absolutely. In fact, we should do the rest of the kernel with as much fervour as we've been changing struct initialisers... but at least the user headers would be a good start.
Absolutely!!!
-Erik
--
Erik B. Andersen http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--
Quoted 3 lines · Erik Andersen
Header files intended for use by users should probably drop
linux/types.hjust include <stdint.h>,,, Then convert the types over to ISO C99 types.
stdint.h is a userspace header. I suppose we could clone it for the kernel, but I don't see any need to.
Quoted 4 lines
s/__u8/uint8_t/g
s/__u16/uint16_t/g
s/__u32/uint32_t/g
s/__u64/uint64_t/g
i think all these _t types are ugly ;-(
Signature · 3 lines
"It's not Hollywood. War is real, war is primarily not about defeat or victory, it is about death. I've seen thousands and thousands of dead bodies. Do you think I want to have an academic debate on this subject?" -- Robert Fisk
Quoted 8 lines · Matthew Wilcox
Quoted 3 lines · Erik Andersen
Header files intended for use by users should probably drop
linux/types.hjust include <stdint.h>,,, Then convert the types over to ISO C99 types.
stdint.his a userspace header. I suppose we could clone it for the kernel, but I don't see any need to.
Quoted 6 lines
Quoted 4 lines
s/__u8/uint8_t/g
s/__u16/uint16_t/g
s/__u32/uint32_t/g
s/__u64/uint64_t/gi think all these _t types are ugly ;-(
They may be ugly, but they are standardized and have very precise meanings defined by ISO C99, which is a very good thing for code interoperability...
-Erik
--
Erik B. Andersen http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--
Quoted 6 lines · Erik Andersen
Quoted 1 line · Matthew Wilcox
i think all these _t types are ugly ;-(
They may be ugly, but they are standardized and have very precise meanings defined by ISO C99, which is a very good thing for code interoperability...
__u8 has a very precise meaning defined by Linux. If you're including a Linux header. that's what you need to worry about.
Signature · 3 lines
"It's not Hollywood. War is real, war is primarily not about defeat or victory, it is about death. I've seen thousands and thousands of dead bodies. Do you think I want to have an academic debate on this subject?" -- Robert Fisk
Quoted 10 lines · Matthew Wilcox
Quoted 6 lines · Erik Andersen
Quoted 1 line · Matthew Wilcox
i think all these _t types are ugly ;-(
They may be ugly, but they are standardized and have very precise meanings defined by ISO C99, which is a very good thing for code interoperability...
__u8has a very precise meaning defined by Linux. If you're including a Linux header. that's what you need to worry about.
It's a kernel-private type. If we're aiming for a clean set of headers, then ideally we should avoid gratuitously defining our own types when standards already exist.
Signature · 1 line
dwmw2
Quoted 6 lines · David Woodhouse
Quoted 2 lines
__u8has a very precise meaning defined by Linux. If you're including a Linux header. that's what you need to worry about.It's a kernel-private type. If we're aiming for a clean set of headers, then ideally we should avoid gratuitously defining our own types when standards already exist.
__u8 is intended to be used by non kernel stuff for headers. Thats why "__u8" not "u8" - so it doesnt pollute the sacred posix name space and have us lynched by glibc people
Quoted 11 lines · Alan Cox
Quoted 6 lines · David Woodhouse
Quoted 2 lines
__u8has a very precise meaning defined by Linux. If you're including a Linux header. that's what you need to worry about.It's a kernel-private type. If we're aiming for a clean set of headers, then ideally we should avoid gratuitously defining our own types when standards already exist.
__u8is intended to be used by non kernel stuff for headers. Thats why "__u8" not "u8" - so it doesnt pollute the sacred posix name space and have us lynched by glibc people
Well, strictly speaking, __u8 is an internal gcc not kernel type.
Now that C99 has defined size-based types, I would prefer that we start using those... They are a bit more verbose than "u8" but I think look better, and more important, are more portable in the long term than __u8.
Whenever I see "__u8", I think "non-standard, gcc-specific dependency"
Jeff
Quoted 1 line · Jeff Garzik
Well, strictly speaking,
__u8is an internal gcc not kernel type.
At the end of this round you score zero points.
__u8 is just a typedef. No magic.
Quoted 1 line · Jeff Garzik
Whenever I see "
__u8", I think "non-standard, gcc-specific dependency"
Ignore this, I stand corrected: these are kernel types.
Regardless, I still prefer the C99 size-specific types, as they are the most portable across all compilers, and you can depend on the compiler to provide them for you. No need to define them yourself.
Jeff
Quoted 8 lines · Jeff Garzik
Quoted 1 line · Jeff Garzik
Whenever I see "
__u8", I think "non-standard, gcc-specific dependency"Ignore this, I stand corrected: these are kernel types.
Regardless, I still prefer the C99 size-specific types, as they are the most portable across all compilers, and you can depend on the compiler to provide them for you. No need to define them yourself.
bzzt. glibc provides them, not gcc.
Signature · 3 lines
"It's not Hollywood. War is real, war is primarily not about defeat or victory, it is about death. I've seen thousands and thousands of dead bodies. Do you think I want to have an academic debate on this subject?" -- Robert Fisk
Quoted 11 lines · Matthew Wilcox
Quoted 8 lines · Jeff Garzik
Quoted 1 line · Jeff Garzik
Whenever I see "
__u8", I think "non-standard, gcc-specific dependency"Ignore this, I stand corrected: these are kernel types.
Regardless, I still prefer the C99 size-specific types, as they are the most portable across all compilers, and you can depend on the compiler to provide them for you. No need to define them yourself.
bzzt. glibc provides them, not gcc.
Actually, a freestanding environment is required (in C99) to provide <stdint.h>. gcc isn't quite there yet.
Andreas.
Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected] SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Quoted 1 line · Jeff Garzik
Well, strictly speaking,
__u8is an internal gcc not kernel type.
No, gcc does not define it at all.
Quoted 1 line
Whenever I see "
__u8", I think "non-standard, gcc-specific dependency"
Check out <asm/types.h>.
Andreas.
Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected] SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Quoted 14 lines · Erik Andersen
Quoted 13 lines · Matthew Wilcox
Quoted 3 lines · Erik Andersen
Header files intended for use by users should probably drop
linux/types.hjust include <stdint.h>,,, Then convert the types over to ISO C99 types.
stdint.his a userspace header. I suppose we could clone it for the kernel, but I don't see any need to.Quoted 4 lines
s/__u8/uint8_t/g
s/__u16/uint16_t/g
s/__u32/uint32_t/g
s/__u64/uint64_t/g
Quoted 7 lines
Quoted 1 line
i think all these _t types are ugly ;-(
They may be ugly, but they are standardized and have very precise meanings defined by ISO C99, which is a very good thing for code interoperability...
-Erik
On the other hand, the ISO C99 definition is probably something like:
an integral type capable of storing the values 0 through 255 inclusive. (ok, I don't have a copy of the new standard but I have seriously examined the old one.) I would not count on uint8_t necessarily being unsigned on unusual hardware. Linux on the other hand probably means __u8 as an exactly eight bit unsigned integer value. While these may LOOK like identical statements, Linux is [probably] making a significantly stronger statement.
I would say - keep the Linux types, and then document exactly what Linux means by them somewhere. In particular, if Linux were ported to a 9/18/36 bit platform, what would the semantics of __u8 be? (Ok, maybe the documentation should say such a port is not considered to be viable at this time.)
--David Garfield
Quoted 5 lines · David Garfield
On the other hand, the ISO C99 definition is probably something like:
an integral type capable of storing the values 0 through 255 inclusive. (ok, I don't have a copy of the new standard but I have seriously examined the old one.) I would not count onuint8_tnecessarily being unsigned on unusual hardware.
Why do you come with FUD and speculation when it is so easy to check the facts?
"The typedef name intN_t designates a signed integer type with width N,
no padding bits, and a two's complement representation. Thus, int8_t denotes a signed integer type with a width of exactly 8 bits.
The typedef name uintN_t designates an unsigned integer type with width N. Thus, uint24_t denotes an unsigned integer type with a width of exactly 24 bits.
These types are optional. However, if an implementation provides integer types with widths of 8, 16, 32, or 64 bits, it shall define the corresponding typedef names."
Quoted 15 lines · Andries Brouwer
Quoted 5 lines · David Garfield
On the other hand, the ISO C99 definition is probably something like:
an integral type capable of storing the values 0 through 255 inclusive. (ok, I don't have a copy of the new standard but I have seriously examined the old one.) I would not count onuint8_tnecessarily being unsigned on unusual hardware.Why do you come with FUD and speculation when it is so easy to check the facts?
"The typedef name
intN_tdesignates a signed integer type with width N,
no padding bits, and a two's complement representation. Thus,int8_tdenotes a signed integer type with a width of exactly 8 bits.
Quoted 5 lines
The typedef name
uintN_tdesignates an unsigned integer type with width N. Thus,uint24_tdenotes an unsigned integer type with a width of exactly 24 bits.These types are optional. However, if an implementation provides integer types with widths of 8, 16, 32, or 64 bits, it shall define the corresponding typedef names."
1) It was not my intent to produce FUD, and speculation is because I understood this was not a freely available standard (it can be found at http://anubis.dkuug.dk/JTC1/SC22/WG14/www/standards ).
2) I have now downloaded and read some of this standard. You do realize that a uint16_t can take 32 bits, don't you? (Hint: reread section 6.2.6.2 for the definition of width.)
3) There is still the issue that these types are not guaranteed to exist, as you have quoted. Also the issue that what Linux guarantees for these types is not specified.
--David Garfield
Quoted 5 lines · David Garfield
On the other hand, the ISO C99 definition is probably something like:
an integral type capable of storing the values 0 through 255 inclusive. (ok, I don't have a copy of the new standard but I have seriously examined the old one.) I would not count onuint8_tnecessarily being unsigned on unusual hardware. Linux on the other
While I can apprecieate the value of pure speculation uncluttered by facts, I think you may want to actually read what the ISO/IEC 9899:1999 (aka C99) has to say on the subject:
7.18.1.1 Exact-width integer types
1 The typedef name intN_t designates a signed integer type with
width N, no padding bits, and a two's complement representation. Thus, int8_t denotes a signed integer type with a width of exactly 8 bits.
2 The typedef name uintN_t designates an unsigned integer type
with width N. Thus, uint24_t denotes an unsigned integer type with a width of exactly 24 bits.
I had to buy my copy of C99, so I can't post the whole thing for the world I'm afraid. But you can visit the SuSv3 (which defers to the C99 standard in cases where they differ) and read their discussion of stdint.h, which is almost identical to the text in C99 and is available online here:
http://www.opengroup.org/onlinepubs/007904975/basedefs/stdint.h.html
-Erik
--
Erik B. Andersen http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--