Skip to content

Commit 08fc476

Browse files
committed
tools beauty: Add script to generate table of mmap's 'prot' argument
Will be wired up in the following csets: $ tools/perf/trace/beauty/mmap_prot.sh static const char *mmap_prot[] = { [ilog2(0x1) + 1] = "READ", #ifndef PROT_READ #define PROT_READ 0x1 #endif [ilog2(0x2) + 1] = "WRITE", #ifndef PROT_WRITE #define PROT_WRITE 0x2 #endif [ilog2(0x4) + 1] = "EXEC", #ifndef PROT_EXEC #define PROT_EXEC 0x4 #endif [ilog2(0x8) + 1] = "SEM", #ifndef PROT_SEM #define PROT_SEM 0x8 #endif [ilog2(0x01000000) + 1] = "GROWSDOWN", #ifndef PROT_GROWSDOWN #define PROT_GROWSDOWN 0x01000000 #endif [ilog2(0x02000000) + 1] = "GROWSUP", #ifndef PROT_GROWSUP #define PROT_GROWSUP 0x02000000 #endif }; $ $ $ $ tools/perf/trace/beauty/mmap_prot.sh alpha static const char *mmap_prot[] = { [ilog2(0x4) + 1] = "EXEC", #ifndef PROT_EXEC #define PROT_EXEC 0x4 #endif [ilog2(0x01000000) + 1] = "GROWSDOWN", #ifndef PROT_GROWSDOWN #define PROT_GROWSDOWN 0x01000000 #endif [ilog2(0x02000000) + 1] = "GROWSUP", #ifndef PROT_GROWSUP #define PROT_GROWSUP 0x02000000 #endif [ilog2(0x1) + 1] = "READ", #ifndef PROT_READ #define PROT_READ 0x1 #endif [ilog2(0x8) + 1] = "SEM", #ifndef PROT_SEM #define PROT_SEM 0x8 #endif [ilog2(0x2) + 1] = "WRITE", #ifndef PROT_WRITE #define PROT_WRITE 0x2 #endif }; $ Cc: Adrian Hunter <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 6169322 commit 08fc476

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tools/perf/trace/beauty/mmap_prot.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: LGPL-2.1
3+
4+
if [ $# -ne 2 ] ; then
5+
[ $# -eq 1 ] && hostarch=$1 || hostarch=`uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/`
6+
asm_header_dir=tools/include/uapi/asm-generic
7+
arch_header_dir=tools/arch/${hostarch}/include/uapi/asm
8+
else
9+
asm_header_dir=$1
10+
arch_header_dir=$2
11+
fi
12+
13+
common_mman=${asm_header_dir}/mman-common.h
14+
arch_mman=${arch_header_dir}/mman.h
15+
16+
prefix="PROT"
17+
18+
printf "static const char *mmap_prot[] = {\n"
19+
regex=`printf '^[[:space:]]*#[[:space:]]*define[[:space:]]+%s_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' ${prefix}`
20+
([ ! -f ${arch_mman} ] || egrep -q '#[[:space:]]*include[[:space:]]+<uapi/asm-generic/mman.*' ${arch_mman}) &&
21+
(egrep $regex ${common_mman} | \
22+
egrep -vw PROT_NONE | \
23+
sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \
24+
xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef ${prefix}_%s\n#define ${prefix}_%s %s\n#endif\n")
25+
[ -f ${arch_mman} ] && egrep -q $regex ${arch_mman} &&
26+
(egrep $regex ${arch_mman} | \
27+
egrep -vw PROT_NONE | \
28+
sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \
29+
xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef ${prefix}_%s\n#define ${prefix}_%s %s\n#endif\n")
30+
printf "};\n"

0 commit comments

Comments
 (0)