| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 | #!/usr/bin/env bash# Script to test fpc to system syscall numbers# Location of syscall header in systemsyscall_header=/usr/include/syscall.hfpc_sysnr=./sysnr.incos=`uname -s`if [ "$os" == "OpenBSD" ] ; then  c_syscall_header=sys/syscall.helse  c_syscall_header=syscall.hfiif ! [ -f $fpc_sysnr ] ; then  cpu=`fpc -iTP`  fpc_sysnr=./$cpu/sysnr.incfiverbose=0os=`uname -s`# Test C file to grab all loaded headerscat > test-syscall.c <<EOF#include <${c_syscall_header}>intmain (){  return 0;}EOF# Default C compiler is gcc# Can be overwritten by setting CC variable# But I don't know if other compilers also generate# .i files with --save-temps optionif [ "$CC" == "" ] ; then  CC=gccfi# Use gcc with --save-temps option to create .i file$CC --save-temps -o test-syscall ./test-syscall.cres=$?if [ $res -ne 0 ] ; then  echo "Call to $CC failed"  exitfi# list of errno.h headers listedsyscall_headers=` sed -n "s:.*\"\(.*/.*\.h\)\".*:\1:p" test-syscall.i |sort | uniq`echo "Headers found are \"$syscall_headers\""if [ "$syscall_headers" != "" ] ; then  syscall_header="$syscall_headers"fifpc_syscall_prefix=syscall_nr_if [ "$os" == "Linux" ] ; then  # On Linux system, system call number are defined indirectly  # with #define SYS_XXX __NR_XXX  # We look directly for the __NT_ version  syscall_prefix=__NR_else  syscall_prefix=SYS_fi# You should only need to change the variables abovesed -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.shsed -n "s:^.*define[[:space:]]*${syscall_prefix}\\([_a-zA-Z0-9]*\\)[[:space:]]*\\([0-9]*\\).*:check_syscall_number_reverse ${fpc_syscall_prefix}\1 \2:p" ${syscall_header} > check_sys_list_reverse.sh function check_syscall_number (){  sys=$1  value=$2  obsolete=0  if [[ "$value" =~ ^[0-9]+$ ]] ; then    eval $sys=\$$value    if [ $verbose -ne 0 ] ; then      echo "$sys is $value"    fi  else    eval $sys=$value    if [ $verbose -ne 0 ] ; then      echo "$sys set to \"${$sys}\" trough \"$value\""    fi  fi  # Remember this value for later  eval $sys=$value  if [ $verbose -ne 0 ] ; then    echo Testing $sys value $value  fi  found=`sed -n "/#define[[:space:]]*${sys}[^A-Za-z0-9_]/p" ${syscall_header}`  val=`sed -n "s:#define[[:space:]]*${sys}[^A-Za-z0-9_][^A-Za-z0-9_]*\([0-9]*\).*:\1:p" ${syscall_header}`  if [ $verbose -ne 0 ] ; then    echo Test for $sys found \"${found}\" \"${value}\" \"${val}\"  fi  if [ "${val}" == "${value}" ] ; then    if [ $verbose -ne 0 ] ; then      echo ${sys} value ${val} is correct    fi  else    if [ "${val}" == "" ] ; then      found=`sed -n "/#define.*[^A-Za-z0-9_]${value}$/p" ${syscall_header}`      if [ "${found}" == "" ] ; then        found=`sed -n "s:\/\* ${value} is compa:/* ${value} is compa:p" ${syscall_header}`        if [ "$found" != "" ] ; then          obsolete=1        fi      fi    fi    if [ "$found" == "" ] ; then      found=`grep -n -w $value ${syscall_header}`    fi    if [ $obsolete -eq 1 ] ; then      echo Warning: ${sys} expected ${value}, is obsolete line is \"${found}\"    else      echo Problem: ${sys} expected ${value}, line is \"${found}\", val found is \"${val}\"    fi  fi}function check_syscall_number_reverse (){  sys=$1  value=$2  if [ $verbose -ne 0 ] ; then    echo Testing syscall header entry $sys value $value  fi  found=`sed -n "/.*${sys}/p" ${fpc_sysnr}`  val=`sed -n "s:.*${sys}[ \t]*=[ \t]*\([0-9]*\).*:\1:p" ${fpc_sysnr}`  if [ $verbose -ne 0 ] ; then    echo Test for $sys found \"${found}\" \"${value}\" \"${val}\"  fi  if [ "${val}" == "${value}" ] ; then    if [ $verbose -ne 0 ] ; then      echo ${sys} value ${val} is correct    fi  else    if [ "${val}" == "" ] ; then      found=`sed -n "/#define.*[^A-Za-z0-9_]${value}$/p" ${syscall_header}`      if [ "${found}" == "" ] ; then        found=`sed -n "s:\/\* ${value} is compa: ${value} is compa:p" ${syscall_header}`      fi    fi    echo Problem: ${sys} expected ${value}, line is \"${found}\", val found is \"${val}\"  fi}# Sustitution made to pass from fpc syscall number# to system define set -fecho "Checking values from \"${fpc_sysnr}\" in \"${syscall_header}\""source ./check_sys_list.shecho "Checking if values in \"${syscall_header}\" are missing in \"${fpc_sysnr}\""source ./check_sys_list_reverse.sh
 |