Re: [PATCH] x86 byteorder.h: use __asm__/__inline__ for userspace

From: Mike Frysinger
Date: Sat Dec 27 2008 - 15:57:52 EST


On Saturday 27 December 2008 15:45:25 H. Peter Anvin wrote:
> Mike Frysinger wrote:
> > On Saturday 27 December 2008 14:23:19 H. Peter Anvin wrote:
> >> Mike Frysinger wrote:
> >>> {su}{8,16,32,64} doesnt matter too much to me vs
> >>> {u,}int_t{8,16,32,64}_t. as long as people stop using
> >>> __{su}{8,16,32,64}. using the latter though does mean headers will
> >>> more likely be "just usable" w/out needing linux/types.h include. but
> >>> then people would be forced to include stdint.h or similar before a
> >>> linux header ... and that sucks.
> >>
> >> That is a total non-starter. This would mean that the C library itself
> >> cannot use these headers without exporting additional symbols into the
> >> namespace, *WHICH IT IS NOT ALLOWED TO DO*.
> >
> > which is already happening today you mean. grep the kernel headers and
> > you'll see a ton of [u]intXX_t hits.
>
> Now, keep in mind this is only true for headers exported to userspace.
> But this is correct - which is the base of this conversation (Sam
> suggesting that they should be warned about, and I suggested
> auto-converting them.)

if the topic is for autoconverting the uintXX_t (and related) types to __uXX
(and related), then that's easy to do i would think. i can post a patch to do
that.

> > this logic though means that the kernel should not be defining any
> > structures that the C library is defining (such as asm-generic/fcntl.h).
> > such structs should get renamed the same way as __[us]XX types
>
> This is also correct, at least for exported headers. For
> kernel-internal headers, it doesn't matter. Unfortunately we do have at
> least several cases of exported interfaces with globally visible names.
>
> There is one other exception of note, which is a header file which can
> only be included by the userspace *application*, using a nonportable
> top-level include (either directly <linux/*> or indirectly via <sys/*>).
> In those cases we can be looser about at least structure names. This
> is common for ioctl structures.

the structures that go through ioctls rarely are an issue. trouble often
brews when dealing with POSIX functions that have a very similar (if not
direct) version in the kernel interface that utilize structures. i mention
the fcntl structure because ive seen that with a couple of packages where the
version in the kernel headers conflicts with the version in the C library. or
where the kernel ABI structure is not directly compatible with the POSIX C
library structure ... the stat struct is an example of this where the C
library has to know the layout of both and converts one to the other.

looking at asm-generic/fcntl.h, i'd propose this change as a template:
...
#ifdef __KERNEL__
# define kernel_flock flock
#endif
struct kernel_flock {
...
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.