check_sys.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env bash
  2. # Script to test fpc to system syscall numbers
  3. # Location of syscall header in system
  4. syscall_header=/usr/include/syscall.h
  5. fpc_sysnr=./sysnr.inc
  6. if ! [ -f $fpc_sysnr ] ; then
  7. cpu=`fpc -iTP`
  8. fpc_sysnr=./$cpu/sysnr.inc
  9. fi
  10. verbose=0
  11. os=`uname -s`
  12. # Test C file to grab all loaded headers
  13. cat > test-syscall.c <<EOF
  14. #include <syscall.h>
  15. int
  16. main ()
  17. {
  18. return 0;
  19. }
  20. EOF
  21. # Default C compiler is gcc
  22. # Can be overwritten by setting CC variable
  23. # But I don't know if other compilers also generate
  24. # .i files with --save-temps option
  25. if [ "$CC" == "" ] ; then
  26. CC=gcc
  27. fi
  28. # Use gcc with --save-temps option to create .i file
  29. $CC --save-temps -o test-syscall ./test-syscall.c
  30. # list of errno.h headers listed
  31. syscall_headers=` sed -n "s:.*\"\(.*/.*\.h\)\".*:\1:p" test-syscall.i |sort | uniq`
  32. echo "Headers found are \"$syscall_headers\""
  33. if [ "$syscall_headers" != "" ] ; then
  34. syscall_header="$syscall_headers"
  35. fi
  36. # Sustitution made to pass from fpc syscall number
  37. # to system define
  38. fpc_syscall_prefix=syscall_nr_
  39. if [ "$os" == "Linux" ] ; then
  40. # On Linux system, system call number are defined indirectly
  41. # with #define SYS_XXX __NR_XXX
  42. # We look directly for the __NT_ version
  43. syscall_prefix=__NR_
  44. else
  45. syscall_prefix=SYS_
  46. fi
  47. # You should only need to change the variables above
  48. sed -n "s:^[ \t]*${fpc_syscall_prefix}\\([_a-zA-Z0-9]*\\)[ \t]*=[ \t]*\\([0-9]*\\).*:check_syscall_number ${syscall_prefix}\1 \2:p" ${fpc_sysnr} > check_sys_list.sh
  49. function check_syscall_number ()
  50. {
  51. sys=$1
  52. value=$2
  53. if [ $verbose -ne 0 ] ; then
  54. echo Testing $sys value $value
  55. fi
  56. found=`sed -n "/#define[[:space:]]*${sys}[^A-Za-z0-9_]/p" ${syscall_header}`
  57. val=`sed -n "s:#define[[:space:]]*${sys}[^A-Za-z0-9_][^A-Za-z0-9_]*\([0-9]*\).*:\1:p" ${syscall_header}`
  58. if [ $verbose -ne 0 ] ; then
  59. echo Test for $sys found \"${found}\" \"${value}\" \"${val}\"
  60. fi
  61. if [ "${val}" == "${value}" ] ; then
  62. if [ $verbose -ne 0 ] ; then
  63. echo ${sys} value ${val} is correct
  64. fi
  65. else
  66. if [ "${val}" == "" ] ; then
  67. found=`sed -n "/#define.*[^A-Za-z0-9_]${value}$/p" ${syscall_header}`
  68. if [ "${found}" == "" ] ; then
  69. found=`sed -n "s:\/\* ${value} is compa: ${value} is compa:p" ${syscall_header}`
  70. fi
  71. fi
  72. if [ "$found" == "" ] ; then
  73. found=`grep -n -w $value ${syscall_header}`
  74. fi
  75. echo problem for ${sys} expected ${value}, line is \"${found}\", val found is \"${val}\"
  76. fi
  77. }
  78. set -f
  79. echo "Checking in ${syscall_header}"
  80. source ./check_sys_list.sh