mmap_flags.sh 1.8 KB

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