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