New way for syncing with kernel headers

Florian Weimer fweimer@redhat.com
Fri Dec 8 21:03:00 GMT 2017


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 
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.

Thanks,
Florian



More information about the Libc-alpha mailing list