This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New way for syncing with kernel headers


On Fri, Dec 08, 2017 at 10:03:25PM +0100, Florian Weimer wrote:
> On 12/08/2017 09:32 PM, Dmitry V. Levin wrote:
> > On Fri, Dec 08, 2017 at 02:21:27PM +0100, Florian Weimer wrote:
> >> Would this be an acceptable way to obtain definitions from the Linux
> >> headers in places where namespace cleanliness is not a must?
> >>
> >> /* Obtain the definitions of the MEMBARRIER_CMD_* constants.  */
> >>
> >> #include <linux/version.h>
> >> #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
> >> # include <linux/membarrier.h>
> >> #else
> >>
> >> /* Definitions from Linux 4.14 follow.  */
> >>
> >> enum membarrier_cmd
> >> {
> >>     MEMBARRIER_CMD_QUERY = 0,
> >>     MEMBARRIER_CMD_SHARED = 1,
> >>     MEMBARRIER_CMD_PRIVATE_EXPEDITED = 8,
> >>     MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED = 16,
> >> };
> >>
> >> #endif
> > 
> > Isn't it going to break when userspace uses e.g.
> > LINUX_VERSION_CODE == KERNEL_VERSION(4, 13, 0)
> > and includes <linux/membarrier.h> after this header?
> 
> Ugh, good point.
> 
> If I use 4.3 as the version guard (where <linux/membarrier.h> was 
> introduced first), someone with 4.13 kernel headers will not able to 
> compile a test using MEMBARRIER_CMD_PRIVATE_EXPEDITED.  So that doesn't 
> work, either.
> 
> But if we copy the header contents, like we currently do in most cases, 
> you can include the UAPI header afterwards, either.  So maybe the 

s/you can/you cannot/

> proposed approach is still an improvement because you don't have to 
> include the UAPI header at all if your glibc version is sufficiently 
> recent because the glibc header will give you the UAPI header plus 
> whatever system call wrappers glibc provides.

Yes, the proposed approach is an improvement.

Relatively portable software would have to be able to include
the UAPI header, too.  Maybe we should document the least troublesome
way of implementing this, e.g.

#if defined HAVE_SYS_MEMBARRIER_H
# include <sys/membarrier.h>
#elif defined HAVE_LINUX_MEMBARRIER_H
# include <linux/membarrier.h>
#else
# error membarrier API is not available
#endif


-- 
ldv

Attachment: signature.asc
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]