blob: dd554bd436cc654b9d01b0185f7bb615efffa9a2 [file] [log] [blame]
Rob Landleye0e2fa42013-03-27 10:24:11 +11001#!/bin/sh
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01002# SPDX-License-Identifier: GPL-2.0
Rob Landleye0e2fa42013-03-27 10:24:11 +11003
Masahiro Yamada555187a2019-06-04 19:14:05 +09004if [ $# -ne 2 ]
Rob Landleye0e2fa42013-03-27 10:24:11 +11005then
Masahiro Yamada555187a2019-06-04 19:14:05 +09006 echo "Usage: headers_install.sh INFILE OUTFILE"
Rob Landleye0e2fa42013-03-27 10:24:11 +11007 echo
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."
12 echo
Masahiro Yamada555187a2019-06-04 19:14:05 +090013 echo "INFILE: header file to operate on"
Masanari Iida0f50d212020-06-16 21:51:32 +090014 echo "OUTFILE: output file which the processed header is written to"
Rob Landleye0e2fa42013-03-27 10:24:11 +110015
16 exit 1
17fi
18
19# Grab arguments
Masahiro Yamada555187a2019-06-04 19:14:05 +090020INFILE=$1
21OUTFILE=$2
22TMPFILE=$OUTFILE.tmp
Rob Landleye0e2fa42013-03-27 10:24:11 +110023
Masahiro Yamada555187a2019-06-04 19:14:05 +090024trap 'rm -f $OUTFILE $TMPFILE' EXIT
Rob Landleye0e2fa42013-03-27 10:24:11 +110025
Masahiro Yamada62244552019-07-25 17:05:13 +090026# SPDX-License-Identifier with GPL variants must have "WITH Linux-syscall-note"
27if [ -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
29 exit 1
30fi
31
Masahiro Yamada555187a2019-06-04 19:14:05 +090032sed -E -e '
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
Rob Landleye0e2fa42013-03-27 10:24:11 +110040
Masahiro Yamada555187a2019-06-04 19:14:05 +090041scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__ $TMPFILE > $OUTFILE
42[ $? -gt 1 ] && exit 1
43
Masahiro Yamadac7c0eec2019-08-11 02:01:35 +090044# Remove /* ... */ style comments, and find CONFIG_ references in code
45configs=$(sed -e '
46:comment
47 s:/\*[^*][^*]*:/*:
48 s:/\*\*\**\([^/]\):/*\1:
49 t comment
50 s:/\*\*/: :
51 t comment
52 /\/\*/! b check
53 N
54 b comment
55:print
56 P
57 D
58:check
59 s:^\(CONFIG_[[:alnum:]_]*\):\1\n:
60 t print
61 s:^[[:alnum:]_][[:alnum:]_]*::
62 s:^[^[:alnum:]_][^[:alnum:]_]*::
63 t check
64 d
65' $OUTFILE)
66
Siddharth Gupta59675772020-05-05 18:52:37 -070067# The entries in the following list do not result in an error.
Masahiro Yamadac7c0eec2019-08-11 02:01:35 +090068# 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)
70#
71# The format is <file-name>:<CONFIG-option> in each line.
72config_leak_ignores="
73arch/alpha/include/uapi/asm/setup.h:CONFIG_ALPHA_LEGACY_START_ADDRESS
74arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PAGE_SIZE_16K
75arch/arc/include/uapi/asm/page.h:CONFIG_ARC_PAGE_SIZE_4K
76arch/arc/include/uapi/asm/swab.h:CONFIG_ARC_HAS_SWAPE
77arch/arm/include/uapi/asm/ptrace.h:CONFIG_CPU_ENDIAN_BE8
78arch/hexagon/include/uapi/asm/ptrace.h:CONFIG_HEXAGON_ARCH_VERSION
79arch/hexagon/include/uapi/asm/user.h:CONFIG_HEXAGON_ARCH_VERSION
80arch/ia64/include/uapi/asm/cmpxchg.h:CONFIG_IA64_DEBUG_CMPXCHG
81arch/m68k/include/uapi/asm/ptrace.h:CONFIG_COLDFIRE
82arch/nios2/include/uapi/asm/swab.h:CONFIG_NIOS2_CI_SWAB_NO
83arch/nios2/include/uapi/asm/swab.h:CONFIG_NIOS2_CI_SWAB_SUPPORT
Masahiro Yamadac7c0eec2019-08-11 02:01:35 +090084arch/x86/include/uapi/asm/auxvec.h:CONFIG_IA32_EMULATION
85arch/x86/include/uapi/asm/auxvec.h:CONFIG_X86_64
86arch/x86/include/uapi/asm/mman.h:CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
87include/uapi/asm-generic/fcntl.h:CONFIG_64BIT
88include/uapi/linux/atmdev.h:CONFIG_COMPAT
Masahiro Yamadac7c0eec2019-08-11 02:01:35 +090089include/uapi/linux/eventpoll.h:CONFIG_PM_SLEEP
90include/uapi/linux/hw_breakpoint.h:CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
91include/uapi/linux/pktcdvd.h:CONFIG_CDROM_PKTCDVD_WCACHE
Masahiro Yamadac7c0eec2019-08-11 02:01:35 +090092"
93
94for c in $configs
95do
Siddharth Gupta59675772020-05-05 18:52:37 -070096 leak_error=1
Masahiro Yamadac7c0eec2019-08-11 02:01:35 +090097
98 for ignore in $config_leak_ignores
99 do
100 if echo "$INFILE:$c" | grep -q "$ignore$"; then
Siddharth Gupta59675772020-05-05 18:52:37 -0700101 leak_error=
Masahiro Yamadac7c0eec2019-08-11 02:01:35 +0900102 break
103 fi
104 done
105
Siddharth Gupta59675772020-05-05 18:52:37 -0700106 if [ "$leak_error" = 1 ]; then
107 echo "error: $INFILE: leak $c to user-space" >&2
108 exit 1
Masahiro Yamadac7c0eec2019-08-11 02:01:35 +0900109 fi
110done
111
Masahiro Yamada555187a2019-06-04 19:14:05 +0900112rm -f $TMPFILE
Rob Landleye0e2fa42013-03-27 10:24:11 +1100113trap - EXIT