mmap_prot.sh 1.2 KB

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