2 # SPDX-License-Identifier: GPL-2.0
6 echo "Usage: headers_install.sh INFILE OUTFILE"
8 echo "Prepares kernel header files for use by user space, by removing"
9 echo "all compiler.h definitions and #includes, removing any"
10 echo "#ifdef __KERNEL__ sections, and putting __underscores__ around"
11 echo "asm/inline/volatile keywords."
13 echo "INFILE: header file to operate on"
14 echo "OUTFILE: output file which the processed header is writen to"
24 trap 'rm -f $OUTFILE $TMPFILE' EXIT
26 # SPDX-License-Identifier with GPL variants must have "WITH Linux-syscall-note"
27 if [ -n "$(sed -n -e "/SPDX-License-Identifier:.*GPL-/{/WITH Linux-syscall-note/!p}" $INFILE)" ]; then
28 echo "error: $INFILE: missing \"WITH Linux-syscall-note\" for SPDX-License-Identifier" >&2
33 s/([[:space:](])(__user|__force|__iomem)[[:space:]]/\1/g
34 s/__attribute_const__([[:space:]]|$)/\1/g
35 s@^#include <linux/compiler(|_types).h>@@
36 s/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g
37 s/(^|[[:space:](])(inline|asm|volatile)([[:space:](]|$)/\1__\2__\3/g
38 s@#(ifndef|define|endif[[:space:]]*/[*])[[:space:]]*_UAPI@#\1 @
39 ' $INFILE > $TMPFILE || exit 1
41 scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__ $TMPFILE > $OUTFILE
42 [ $? -gt 1 ] && exit 1
44 # Remove /* ... */ style comments, and find CONFIG_ references in code
48 s:/\*\*\**\([^/]\):/*\1:
59 s:^\(CONFIG_[[:alnum:]_]*\):\1\n:
61 s:^[[:alnum:]_][[:alnum:]_]*::
62 s:^[^[:alnum:]_][^[:alnum:]_]*::
67 # The entries in the following list are not warned.
68 # Please do not add a new entry. This list is only for existing ones.
69 # The list will be reduced gradually, and deleted eventually. (hopefully)
71 # The format is <file-name>:<CONFIG-option> in each line.
73 arch/alpha/include/uapi/asm/setup.h:CONFIG_ALPHA_LEGACY_START_ADDRESS
74 arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PAGE_SIZE_16K
75 arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PAGE_SIZE_4K
76 arch/arc/include/uapi/asm/swab.h:CONFIG_ARC_HAS_SWAPE
77 arch/arm/include/uapi/asm/ptrace.h:CONFIG_CPU_ENDIAN_BE8
78 arch/hexagon/include/uapi/asm/ptrace.h:CONFIG_HEXAGON_ARCH_VERSION
79 arch/hexagon/include/uapi/asm/user.h:CONFIG_HEXAGON_ARCH_VERSION
80 arch/ia64/include/uapi/asm/cmpxchg.h:CONFIG_IA64_DEBUG_CMPXCHG
81 arch/m68k/include/uapi/asm/ptrace.h:CONFIG_COLDFIRE
82 arch/nios2/include/uapi/asm/swab.h:CONFIG_NIOS2_CI_SWAB_NO
83 arch/nios2/include/uapi/asm/swab.h:CONFIG_NIOS2_CI_SWAB_SUPPORT
84 arch/x86/include/uapi/asm/auxvec.h:CONFIG_IA32_EMULATION
85 arch/x86/include/uapi/asm/auxvec.h:CONFIG_X86_64
86 arch/x86/include/uapi/asm/mman.h:CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
87 include/uapi/asm-generic/fcntl.h:CONFIG_64BIT
88 include/uapi/linux/atmdev.h:CONFIG_COMPAT
89 include/uapi/linux/elfcore.h:CONFIG_BINFMT_ELF_FDPIC
90 include/uapi/linux/eventpoll.h:CONFIG_PM_SLEEP
91 include/uapi/linux/hw_breakpoint.h:CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
92 include/uapi/linux/pktcdvd.h:CONFIG_CDROM_PKTCDVD_WCACHE
93 include/uapi/linux/raw.h:CONFIG_MAX_RAW_DEVS
100 for ignore in $config_leak_ignores
102 if echo "$INFILE:$c" | grep -q "$ignore$"; then
108 if [ "$warn" = 1 ]; then
109 echo "warning: $INFILE: leak $c to user-space" >&2