Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 if [ $# -ne 2 ]
0005 then
0006         echo "Usage: headers_install.sh INFILE OUTFILE"
0007         echo
0008         echo "Prepares kernel header files for use by user space, by removing"
0009         echo "all compiler.h definitions and #includes, removing any"
0010         echo "#ifdef __KERNEL__ sections, and putting __underscores__ around"
0011         echo "asm/inline/volatile keywords."
0012         echo
0013         echo "INFILE: header file to operate on"
0014         echo "OUTFILE: output file which the processed header is written to"
0015 
0016         exit 1
0017 fi
0018 
0019 # Grab arguments
0020 INFILE=$1
0021 OUTFILE=$2
0022 TMPFILE=$OUTFILE.tmp
0023 
0024 trap 'rm -f $OUTFILE $TMPFILE' EXIT
0025 
0026 # SPDX-License-Identifier with GPL variants must have "WITH Linux-syscall-note"
0027 if [ -n "$(sed -n -e "/SPDX-License-Identifier:.*GPL-/{/WITH Linux-syscall-note/!p}" $INFILE)" ]; then
0028         echo "error: $INFILE: missing \"WITH Linux-syscall-note\" for SPDX-License-Identifier" >&2
0029         exit 1
0030 fi
0031 
0032 sed -E -e '
0033         s/([[:space:](])(__user|__force|__iomem)[[:space:]]/\1/g
0034         s/__attribute_const__([[:space:]]|$)/\1/g
0035         s@^#include <linux/compiler(|_types).h>@@
0036         s/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g
0037         s/(^|[[:space:](])(inline|asm|volatile)([[:space:](]|$)/\1__\2__\3/g
0038         s@#(ifndef|define|endif[[:space:]]*/[*])[[:space:]]*_UAPI@#\1 @
0039 ' $INFILE > $TMPFILE || exit 1
0040 
0041 scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__ $TMPFILE > $OUTFILE
0042 [ $? -gt 1 ] && exit 1
0043 
0044 # Remove /* ... */ style comments, and find CONFIG_ references in code
0045 configs=$(sed -e '
0046 :comment
0047         s:/\*[^*][^*]*:/*:
0048         s:/\*\*\**\([^/]\):/*\1:
0049         t comment
0050         s:/\*\*/: :
0051         t comment
0052         /\/\*/! b check
0053         N
0054         b comment
0055 :print
0056         P
0057         D
0058 :check
0059         s:^\(CONFIG_[[:alnum:]_]*\):\1\n:
0060         t print
0061         s:^[[:alnum:]_][[:alnum:]_]*::
0062         s:^[^[:alnum:]_][^[:alnum:]_]*::
0063         t check
0064         d
0065 ' $OUTFILE)
0066 
0067 # The entries in the following list do not result in an error.
0068 # Please do not add a new entry. This list is only for existing ones.
0069 # The list will be reduced gradually, and deleted eventually. (hopefully)
0070 #
0071 # The format is <file-name>:<CONFIG-option> in each line.
0072 config_leak_ignores="
0073 arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PAGE_SIZE_16K
0074 arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PAGE_SIZE_4K
0075 arch/arc/include/uapi/asm/swab.h:CONFIG_ARC_HAS_SWAPE
0076 arch/arm/include/uapi/asm/ptrace.h:CONFIG_CPU_ENDIAN_BE8
0077 arch/hexagon/include/uapi/asm/ptrace.h:CONFIG_HEXAGON_ARCH_VERSION
0078 arch/hexagon/include/uapi/asm/user.h:CONFIG_HEXAGON_ARCH_VERSION
0079 arch/ia64/include/uapi/asm/cmpxchg.h:CONFIG_IA64_DEBUG_CMPXCHG
0080 arch/m68k/include/uapi/asm/ptrace.h:CONFIG_COLDFIRE
0081 arch/nios2/include/uapi/asm/swab.h:CONFIG_NIOS2_CI_SWAB_NO
0082 arch/nios2/include/uapi/asm/swab.h:CONFIG_NIOS2_CI_SWAB_SUPPORT
0083 arch/x86/include/uapi/asm/auxvec.h:CONFIG_IA32_EMULATION
0084 arch/x86/include/uapi/asm/auxvec.h:CONFIG_X86_64
0085 arch/x86/include/uapi/asm/mman.h:CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
0086 include/uapi/linux/atmdev.h:CONFIG_COMPAT
0087 include/uapi/linux/eventpoll.h:CONFIG_PM_SLEEP
0088 include/uapi/linux/hw_breakpoint.h:CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
0089 include/uapi/linux/pktcdvd.h:CONFIG_CDROM_PKTCDVD_WCACHE
0090 "
0091 
0092 for c in $configs
0093 do
0094         leak_error=1
0095 
0096         for ignore in $config_leak_ignores
0097         do
0098                 if echo "$INFILE:$c" | grep -q "$ignore$"; then
0099                         leak_error=
0100                         break
0101                 fi
0102         done
0103 
0104         if [ "$leak_error" = 1 ]; then
0105                 echo "error: $INFILE: leak $c to user-space" >&2
0106                 exit 1
0107         fi
0108 done
0109 
0110 rm -f $TMPFILE
0111 trap - EXIT