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#define ltp_syscall(NR, ...) ({ \\ 49 int __ret; \\ 50 if (NR == __LTP__NR_INVALID_SYSCALL) { \\ 51 errno = ENOSYS; \\ 52 __ret = -1; \\ 53 } else { \\ 54 __ret = syscall(NR, ##__VA_ARGS__); \\ 55 } \\ 56 if (__ret == -1 && errno == ENOSYS) { \\ 57 tst_brkm(TCONF, CLEANUP, \\ 58 "syscall(%d) " #NR " not supported on your arch", \\ 59 NR); \\ 60 } \\ 61 __ret; \\ 62}) 63 64#define tst_syscall(NR, ...) ({ \\ 65 int tst_ret; \\ 66 if (NR == __LTP__NR_INVALID_SYSCALL) { \\ 67 errno = ENOSYS; \\ 68 tst_ret = -1; \\ 69 } else { \\ 70 tst_ret = syscall(NR, ##__VA_ARGS__); \\ 71 } \\ 72 if (tst_ret == -1 && errno == ENOSYS) { \\ 73 tst_brk(TCONF, "syscall(%d) " #NR " not supported", NR); \\ 74 } \\ 75 tst_ret; \\ 76}) 77 78EOF 79 80jobs=0 81for arch in $(cat "${srcdir}/order") ; do 82 ( 83 echo "Generating data for arch $arch ... " 84 85 ( 86 echo 87 case ${arch} in 88 sparc64) echo "#if defined(__sparc__) && defined(__arch64__)" ;; 89 sparc) echo "#if defined(__sparc__) && !defined(__arch64__)" ;; 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