1 #!/bin/sh 1 #!/bin/sh 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 if [ $# -ne 2 ] 4 if [ $# -ne 2 ] 5 then 5 then 6 echo "Usage: headers_install.sh INFILE 6 echo "Usage: headers_install.sh INFILE OUTFILE" 7 echo 7 echo 8 echo "Prepares kernel header files for 8 echo "Prepares kernel header files for use by user space, by removing" 9 echo "all compiler.h definitions and # 9 echo "all compiler.h definitions and #includes, removing any" 10 echo "#ifdef __KERNEL__ sections, and 10 echo "#ifdef __KERNEL__ sections, and putting __underscores__ around" 11 echo "asm/inline/volatile keywords." 11 echo "asm/inline/volatile keywords." 12 echo 12 echo 13 echo "INFILE: header file to operate o 13 echo "INFILE: header file to operate on" 14 echo "OUTFILE: output file which the p !! 14 echo "OUTFILE: output file which the processed header is writen to" 15 15 16 exit 1 16 exit 1 17 fi 17 fi 18 18 19 # Grab arguments 19 # Grab arguments 20 INFILE=$1 20 INFILE=$1 21 OUTFILE=$2 21 OUTFILE=$2 22 TMPFILE=$OUTFILE.tmp 22 TMPFILE=$OUTFILE.tmp 23 23 24 trap 'rm -f $OUTFILE $TMPFILE' EXIT 24 trap 'rm -f $OUTFILE $TMPFILE' EXIT 25 25 26 # SPDX-License-Identifier with GPL variants mu 26 # SPDX-License-Identifier with GPL variants must have "WITH Linux-syscall-note" 27 if [ -n "$(sed -n -e "/SPDX-License-Identifier 27 if [ -n "$(sed -n -e "/SPDX-License-Identifier:.*GPL-/{/WITH Linux-syscall-note/!p}" $INFILE)" ]; then 28 echo "error: $INFILE: missing \"WITH L 28 echo "error: $INFILE: missing \"WITH Linux-syscall-note\" for SPDX-License-Identifier" >&2 29 exit 1 29 exit 1 30 fi 30 fi 31 31 32 sed -E -e ' 32 sed -E -e ' 33 s/([[:space:](])(__user|__force|__iome 33 s/([[:space:](])(__user|__force|__iomem)[[:space:]]/\1/g 34 s/__attribute_const__([[:space:]]|$)/\ 34 s/__attribute_const__([[:space:]]|$)/\1/g 35 s@^#include <linux/compiler(|_types).h 35 s@^#include <linux/compiler(|_types).h>@@ 36 s/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9 36 s/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g 37 s/(^|[[:space:](])(inline|asm|volatile 37 s/(^|[[:space:](])(inline|asm|volatile)([[:space:](]|$)/\1__\2__\3/g 38 s@#(ifndef|define|endif[[:space:]]*/[* 38 s@#(ifndef|define|endif[[:space:]]*/[*])[[:space:]]*_UAPI@#\1 @ 39 ' $INFILE > $TMPFILE || exit 1 39 ' $INFILE > $TMPFILE || exit 1 40 40 41 scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEAD 41 scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__ $TMPFILE > $OUTFILE 42 [ $? -gt 1 ] && exit 1 42 [ $? -gt 1 ] && exit 1 43 43 44 # Remove /* ... */ style comments, and find CO 44 # Remove /* ... */ style comments, and find CONFIG_ references in code 45 configs=$(sed -e ' 45 configs=$(sed -e ' 46 :comment 46 :comment 47 s:/\*[^*][^*]*:/*: 47 s:/\*[^*][^*]*:/*: 48 s:/\*\*\**\([^/]\):/*\1: 48 s:/\*\*\**\([^/]\):/*\1: 49 t comment 49 t comment 50 s:/\*\*/: : 50 s:/\*\*/: : 51 t comment 51 t comment 52 /\/\*/! b check 52 /\/\*/! b check 53 N 53 N 54 b comment 54 b comment 55 :print 55 :print 56 P 56 P 57 D 57 D 58 :check 58 :check 59 s:^\(CONFIG_[[:alnum:]_]*\):\1\n: 59 s:^\(CONFIG_[[:alnum:]_]*\):\1\n: 60 t print 60 t print 61 s:^[[:alnum:]_][[:alnum:]_]*:: 61 s:^[[:alnum:]_][[:alnum:]_]*:: 62 s:^[^[:alnum:]_][^[:alnum:]_]*:: 62 s:^[^[:alnum:]_][^[:alnum:]_]*:: 63 t check 63 t check 64 d 64 d 65 ' $OUTFILE) 65 ' $OUTFILE) 66 66 67 # The entries in the following list do not res 67 # The entries in the following list do not result in an error. 68 # Please do not add a new entry. This list is 68 # Please do not add a new entry. This list is only for existing ones. 69 # The list will be reduced gradually, and dele 69 # The list will be reduced gradually, and deleted eventually. (hopefully) 70 # 70 # 71 # The format is <file-name>:<CONFIG-option> in 71 # The format is <file-name>:<CONFIG-option> in each line. 72 config_leak_ignores=" 72 config_leak_ignores=" >> 73 arch/alpha/include/uapi/asm/setup.h:CONFIG_ALPHA_LEGACY_START_ADDRESS 73 arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PA 74 arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PAGE_SIZE_16K 74 arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PA 75 arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PAGE_SIZE_4K 75 arch/arc/include/uapi/asm/swab.h:CONFIG_ARC_HA 76 arch/arc/include/uapi/asm/swab.h:CONFIG_ARC_HAS_SWAPE 76 arch/arm/include/uapi/asm/ptrace.h:CONFIG_CPU_ 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 77 arch/nios2/include/uapi/asm/swab.h:CONFIG_NIOS 82 arch/nios2/include/uapi/asm/swab.h:CONFIG_NIOS2_CI_SWAB_NO 78 arch/nios2/include/uapi/asm/swab.h:CONFIG_NIOS 83 arch/nios2/include/uapi/asm/swab.h:CONFIG_NIOS2_CI_SWAB_SUPPORT >> 84 arch/sh/include/uapi/asm/ptrace.h:CONFIG_CPU_SH5 >> 85 arch/sh/include/uapi/asm/sigcontext.h:CONFIG_CPU_SH5 >> 86 arch/sh/include/uapi/asm/stat.h:CONFIG_CPU_SH5 79 arch/x86/include/uapi/asm/auxvec.h:CONFIG_IA32 87 arch/x86/include/uapi/asm/auxvec.h:CONFIG_IA32_EMULATION 80 arch/x86/include/uapi/asm/auxvec.h:CONFIG_X86_ 88 arch/x86/include/uapi/asm/auxvec.h:CONFIG_X86_64 >> 89 arch/x86/include/uapi/asm/mman.h:CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS >> 90 include/uapi/asm-generic/fcntl.h:CONFIG_64BIT >> 91 include/uapi/linux/atmdev.h:CONFIG_COMPAT >> 92 include/uapi/linux/elfcore.h:CONFIG_BINFMT_ELF_FDPIC >> 93 include/uapi/linux/eventpoll.h:CONFIG_PM_SLEEP >> 94 include/uapi/linux/hw_breakpoint.h:CONFIG_HAVE_MIXED_BREAKPOINTS_REGS >> 95 include/uapi/linux/pktcdvd.h:CONFIG_CDROM_PKTCDVD_WCACHE >> 96 include/uapi/linux/raw.h:CONFIG_MAX_RAW_DEVS 81 " 97 " 82 98 83 for c in $configs 99 for c in $configs 84 do 100 do 85 leak_error=1 101 leak_error=1 86 102 87 for ignore in $config_leak_ignores 103 for ignore in $config_leak_ignores 88 do 104 do 89 if echo "$INFILE:$c" | grep -q 105 if echo "$INFILE:$c" | grep -q "$ignore$"; then 90 leak_error= 106 leak_error= 91 break 107 break 92 fi 108 fi 93 done 109 done 94 110 95 if [ "$leak_error" = 1 ]; then 111 if [ "$leak_error" = 1 ]; then 96 echo "error: $INFILE: leak $c 112 echo "error: $INFILE: leak $c to user-space" >&2 97 exit 1 113 exit 1 98 fi 114 fi 99 done 115 done 100 116 101 rm -f $TMPFILE 117 rm -f $TMPFILE 102 trap - EXIT 118 trap - EXIT
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.