Linux 5.13-rc6
[sfrench/cifs-2.6.git] / tools / perf / trace / beauty / mmap_flags.sh
1 #!/bin/sh
2 # SPDX-License-Identifier: LGPL-2.1
3
4 if [ $# -ne 3 ] ; then
5         [ $# -eq 1 ] && hostarch=$1 || hostarch=`uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/`
6         linux_header_dir=tools/include/uapi/linux
7         header_dir=tools/include/uapi/asm-generic
8         arch_header_dir=tools/arch/${hostarch}/include/uapi/asm
9 else
10         linux_header_dir=$1
11         header_dir=$2
12         arch_header_dir=$3
13 fi
14
15 linux_mman=${linux_header_dir}/mman.h
16 arch_mman=${arch_header_dir}/mman.h
17
18 # those in egrep -vw are flags, we want just the bits
19
20 printf "static const char *mmap_flags[] = {\n"
21 regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*'
22 egrep -q $regex ${arch_mman} && \
23 (egrep $regex ${arch_mman} | \
24         sed -r "s/$regex/\2 \1 \1 \1 \2/g"      | \
25         xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")
26 egrep -q $regex ${linux_mman} && \
27 (egrep $regex ${linux_mman} | \
28         egrep -vw 'MAP_(UNINITIALIZED|TYPE|SHARED_VALIDATE)' | \
29         sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \
30         xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")
31 ([ ! -f ${arch_mman} ] || egrep -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.*' ${arch_mman}) &&
32 (egrep $regex ${header_dir}/mman-common.h | \
33         egrep -vw 'MAP_(UNINITIALIZED|TYPE|SHARED_VALIDATE)' | \
34         sed -r "s/$regex/\2 \1 \1 \1 \2/g"      | \
35         xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")
36 ([ ! -f ${arch_mman} ] || egrep -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.h>.*' ${arch_mman}) &&
37 (egrep $regex ${header_dir}/mman.h | \
38         sed -r "s/$regex/\2 \1 \1 \1 \2/g"      | \
39         xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")
40 printf "};\n"