1 #!/bin/sh 2 3 output="linux_syscall_numbers.h" 4 5 if [ $# -gt 0 ]; then 6 output=$1 7 fi 8 echo "ltp testcases kernel include regen: output = "$output 9 10 rm -f "${output}".[1-9]* 11 output_pid="${output}.$$" 12 13 max_jobs=$(getconf _NPROCESSORS_ONLN 2>/dev/null) 14 : ${max_jobs:=1} 15 16 srcdir=${0%/*} 17 18 err() { 19 echo "$*" 1>&2 20 exit 1 21 } 22 23 cat << EOF > "${output_pid}" 24 /************************************************ 25 * GENERATED FILE: DO NOT EDIT/PATCH THIS FILE * 26 * change your arch specific .in file instead * 27 ************************************************/ 28 29 /* 30 * Here we stick all the ugly *fallback* logic for linux 31 * system call numbers (those __NR_ thingies). 32 * 33 * Licensed under the GPLv2 or later, see the COPYING file. 34 */ 35 36 #ifndef __LINUX_SYSCALL_NUMBERS_H__ 37 #define __LINUX_SYSCALL_NUMBERS_H__ 38 39 #include <errno.h> 40 #include <sys/syscall.h> 41 #include <asm/unistd.h> 42 #include "cleanup.c" 43 44 #define ltp_syscall(NR, ...) ({ \\ 45 int __ret; \\ 46 if (NR == __LTP__NR_INVALID_SYSCALL) { \\ 47 errno = ENOSYS; \\ 48 __ret = -1; \\ 49 } else { \\ 50 __ret = syscall(NR, ##__VA_ARGS__); \\ 51 } \\ 52 if (__ret == -1 && errno == ENOSYS) { \\ 53 tst_brkm(TCONF, CLEANUP, \\ 54 "syscall(%d) " #NR " not supported on your arch", \\ 55 NR); \\ 56 } \\ 57 __ret; \\ 58 }) 59 60 #define tst_syscall(NR, ...) ({ \\ 61 int tst_ret; \\ 62 if (NR == __LTP__NR_INVALID_SYSCALL) { \\ 63 errno = ENOSYS; \\ 64 tst_ret = -1; \\ 65 } else { \\ 66 tst_ret = syscall(NR, ##__VA_ARGS__); \\ 67 } \\ 68 if (tst_ret == -1 && errno == ENOSYS) { \\ 69 tst_brk(TCONF, "syscall(%d) " #NR "not supported", NR); \\ 70 } \\ 71 tst_ret; \\ 72 }) 73 74 EOF 75 76 jobs=0 77 for arch in $(cat "${srcdir}/order") ; do 78 ( 79 echo "Generating data for arch $arch ... " 80 81 ( 82 echo 83 case ${arch} in 84 sparc64) echo "#if defined(__sparc__) && defined(__arch64__)" ;; 85 sparc) echo "#if defined(__sparc__) && !defined(__arch64__)" ;; 86 *) echo "#ifdef __${arch}__" ;; 87 esac 88 while read line ; do 89 set -- ${line} 90 nr="__NR_$1" 91 shift 92 if [ $# -eq 0 ] ; then 93 err "invalid line found: $line" 94 fi 95 echo "# ifndef ${nr}" 96 echo "# define ${nr} $*" 97 echo "# endif" 98 done < "${srcdir}/${arch}.in" 99 echo "#endif" 100 echo 101 ) >> "${output_pid}.${arch}" 102 103 ) & 104 105 : $(( jobs += 1 )) 106 if [ ${jobs} -ge ${max_jobs} ] ; then 107 wait || exit 1 108 jobs=0 109 fi 110 done 111 112 echo "Generating stub list ... " 113 ( 114 echo 115 echo "/* Common stubs */" 116 echo "#define __LTP__NR_INVALID_SYSCALL -1" >> "${output_pid}" 117 for nr in $(awk '{print $1}' "${srcdir}/"*.in | sort -u) ; do 118 nr="__NR_${nr}" 119 echo "# ifndef ${nr}" 120 echo "# define ${nr} __LTP__NR_INVALID_SYSCALL" 121 echo "# endif" 122 done 123 echo "#endif" 124 ) >> "${output_pid}._footer" 125 126 wait || exit 1 127 128 printf "Combining them all ... " 129 for arch in $(cat "${srcdir}/order") _footer ; do 130 cat "${output_pid}.${arch}" 131 done >> "${output_pid}" 132 mv "${output_pid}" "${output}" 133 rm -f "${output_pid}"* 134 echo "OK!" 135