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