CONFIG_* in UAPI headers

From: Eugene Syromyatnikov
Date: Thu Dec 01 2016 - 23:39:23 EST


Hello.

It was noticed during addition of support for the new arch_prctl code constants
to strace that these new constants (ARCH_MAP_VDSO_X32, ARCH_MAP_VDSO_32 and
ARCH_MAP_VDSO_64) are guarded with the CONFIG_CHECKPOINT_RESTORE ifdef.
However, from what I can see (by looking at headers in and around
/usr/include/linux in Debian and Red Hat distributions), kernel configuration
definitions are not exported as a part of the UAPI headers, so these definitions
would be unusable unless user application explicitly defines
CONFIG_CHECKPOINT_RESTORE macro, regardless of kernel support.

Further inspection of UAPI headers revealed that there are several other
examples of such CONFIG_*-guarded definitions, namely:
* include/uapi/asm-generic/fcntl.h â ifndef CONFIG_64BIT (however glibc
headers have own magic regarding fcntl constants)
* include/uapi/asm-generic/mman-common.h â
ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
* include/uapi/asm-generic/unistd.h â ifdef CONFIG_MMU
* include/uapi/linux/atmdev.h â ifdef CONFIG_COMPAT
* include/uapi/linux/elfcore.h â ifdef CONFIG_BINFMT_ELF_FDPIC
* include/uapi/linux/eventpoll.h â ifdef CONFIG_PM_SLEEP
* include/uapi/linux/fb.h â ifdef CONFIG_FB_BACKLIGHT
* include/uapi/linux/flat.h â ifdef CONFIG_BINFMT_SHARED_FLAT
* include/uapi/linux/hw_breakpoint.h â ifdef CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
* include/uapi/linux/pktcdvd.h â if defined(CONFIG_CDROM_PKTCDVD_WCACHE)
* arch/arc/include/uapi/asm/swab.h â ifdef CONFIG_ARC_HAS_SWAPE
* arch/arm/include/uapi/asm/ptrace.h â ifdef CONFIG_CPU_ENDIAN_BE8
* arch/hexagon/include/uapi/asm/ptrace.h â if CONFIG_HEXAGON_ARCH_VERSION >= 4
* arch/hexagon/include/uapi/asm/user.h â if CONFIG_HEXAGON_ARCH_VERSION < 4
* arch/m68k/include/uapi/asm/ptrace.h â ifdef CONFIG_COLDFIRE
* arch/nios2/include/uapi/asm/swab.h â ifdef CONFIG_NIOS2_CI_SWAB_SUPPORT
* arch/x86/include/uapi/asm/auxvec.h â if defined(CONFIG_IA32_EMULATION) ||
!defined(CONFIG_X86_64)
* arch/x86/include/uapi/asm/mman.h â
ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS (another piece of the new code
added in 4.9)
* arch/xtensa/include/uapi/asm/mman.h â ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED

Maybe most of these are false positives, but by looking at them it isn't clear
how user space should use definitions and code under under these checks, so
maybe it should be moved out from UAPI or at least fitted with comments
regarding necessity of these guards useful only in kernel space?

--
Eugene Syromyatnikov
mailto:evgsyr@xxxxxxxxx
xmpp:esyr@jabber.{ru|org}