Messages in this thread Patch in this message | | | From | Arnd Bergmann <> | Subject | Re: [PATCH]: Make ioctl.h compatible with userland | Date | Tue, 12 Aug 2008 17:12:18 +0200 |
| |
[PATCH] Make _IOC_TYPECHECK use BUILD_BUG_ON_ZERO
This converts _IOC_TYPECHECK from a link error to a compile-time error using BUILD_BUG_ON_ZERO. This makes it possible to use the standard _IOC macros in user space even with non-optizing compilers.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
--- On Wednesday 30 July 2008, Andrew Morton wrote: > We could also replace that open-coded assertion with the shiny new > BUILD_BUG_ON(), which would a) be cleaner and b) fix the problem which > you describe. I expect that would be quite safe, but obviously doesn't > have all the testing which the above patch has, so shrug.
There is one significant difference: using BUILD_BUG_ON_ZERO will break user space code that uses broken ioctl number definitions like _IOC('x', 1, sizeof(int)) that were fixed up in the kernel but not in external copies of the definitions. I'm undecided whether such breakage would be a good or a bad thing.
--- a/include/asm-generic/ioctl.h +++ b/include/asm-generic/ioctl.h @@ -69,11 +69,9 @@ ((size) << _IOC_SIZESHIFT)) /* provoke compile error for invalid uses of size argument */ -extern unsigned int __invalid_size_argument_for_IOC; -#define _IOC_TYPECHECK(t) \ - ((sizeof(t) == sizeof(t[1]) && \ - sizeof(t) < (1 << _IOC_SIZEBITS)) ? \ - sizeof(t) : __invalid_size_argument_for_IOC) +#define _IOC_TYPECHECK(t) (sizeof(t) + \ + BUILD_BUG_ON_ZERO(sizeof(t) != sizeof(t[1]) || \ + sizeof(t) >= (1 << _IOC_SIZEBITS))) /* used to create numbers */ #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |