1#!/bin/sh 2 3output="syscalls.h" 4 5# For soon to be able to provide an argument 6# for output file so the header generation can 7# be added as a dependency in Android.bp 8if [ $# -gt 0 ]; then 9 output=$1 10 echo "ltp syscalls gen output: "$output 11 rm -f "${output}" 12fi 13 14rm -f "${output}".[1-9]* 15output_pid="${output}.$$" 16 17max_jobs=$(getconf _NPROCESSORS_ONLN 2>/dev/null) 18: ${max_jobs:=1} 19 20srcdir=${0%/*} 21 22err() { 23 echo "$*" 1>&2 24 exit 1 25} 26 27cat << EOF > "${output_pid}" 28/************************************************ 29 * GENERATED FILE: DO NOT EDIT/PATCH THIS FILE * 30 * change your arch specific .in file instead * 31 ************************************************/ 32 33/* 34 * Here we stick all the ugly *fallback* logic for linux 35 * system call numbers (those __NR_ thingies). 36 * 37 * Licensed under the GPLv2 or later, see the COPYING file. 38 */ 39 40#ifndef LAPI_SYSCALLS_H__ 41#define LAPI_SYSCALLS_H__ 42 43#include <errno.h> 44#include <sys/syscall.h> 45#include <asm/unistd.h> 46#include "cleanup.c" 47 48#ifdef TST_TEST_H__ 49#define TST_SYSCALL_BRK__(NR, SNR) ({ \\ 50 tst_brk(TCONF, \\ 51 "syscall(%d) " SNR " not supported on your arch", NR); \\ 52}) 53#else 54#define TST_SYSCALL_BRK__(NR, SNR) ({ \\ 55 tst_brkm(TCONF, CLEANUP, \\ 56 "syscall(%d) " SNR " not supported on your arch", NR); \\ 57}) 58#endif 59 60#define tst_syscall(NR, ...) ({ \\ 61 intptr_t 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_SYSCALL_BRK__(NR, #NR); \\ 70 } \\ 71 tst_ret; \\ 72}) 73 74EOF 75 76jobs=0 77for 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 s390) echo "#if defined(__s390__) && !defined(__s390x__)" ;; 87 mips_n32) echo "#if defined(__mips__) && defined(_ABIN32)" ;; 88 mips_n64) echo "#if defined(__mips__) && defined(_ABI64)" ;; 89 mips_o32) echo "#if defined(__mips__) && defined(_ABIO32) && _MIPS_SZLONG == 32" ;; 90 *) echo "#ifdef __${arch}__" ;; 91 esac 92 while read line ; do 93 set -- ${line} 94 nr="__NR_$1" 95 shift 96 if [ $# -eq 0 ] ; then 97 err "invalid line found: $line" 98 fi 99 echo "# ifndef ${nr}" 100 echo "# define ${nr} $*" 101 echo "# endif" 102 done < "${srcdir}/${arch}.in" 103 echo "#endif" 104 echo 105 ) >> "${output_pid}.${arch}" 106 107 ) & 108 109 jobs=$(( jobs + 1 )) 110 if [ ${jobs} -ge ${max_jobs} ] ; then 111 wait || exit 1 112 jobs=0 113 fi 114done 115 116echo "Generating stub list ... " 117( 118echo 119echo "/* Common stubs */" 120echo "#define __LTP__NR_INVALID_SYSCALL -1" >> "${output_pid}" 121for nr in $(awk '{print $1}' "${srcdir}/"*.in | sort -u) ; do 122 nr="__NR_${nr}" 123 echo "# ifndef ${nr}" 124 echo "# define ${nr} __LTP__NR_INVALID_SYSCALL" 125 echo "# endif" 126done 127echo "#endif" 128) >> "${output_pid}._footer" 129 130wait || exit 1 131 132printf "Combining them all ... " 133for arch in $(cat "${srcdir}/order") _footer ; do 134 cat "${output_pid}.${arch}" 135done >> "${output_pid}" 136if [ $# -gt 0 ]; then 137 mv "${output_pid}" "${output}" 138else 139 mv "${output_pid}" "../${output}" 140fi 141rm -f "${output_pid}"* 142echo "OK!" 143