• 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#define ltp_syscall(NR, ...) ({ \\
39	int __ret; \\
40	if (NR == __LTP__NR_INVALID_SYSCALL) { \\
41		errno = ENOSYS; \\
42		__ret = -1; \\
43	} else { \\
44		__ret = syscall(NR, ##__VA_ARGS__); \\
45	} \\
46	if (__ret == -1 && errno == ENOSYS) { \\
47		tst_brkm(TCONF, CLEANUP, \\
48			"syscall(%d) " #NR " not supported on your arch", \\
49			NR); \\
50	} \\
51	__ret; \\
52})
53
54#define tst_syscall(NR, ...) ({ \\
55	int tst_ret; \\
56	if (NR == __LTP__NR_INVALID_SYSCALL) { \\
57		errno = ENOSYS; \\
58		tst_ret = -1; \\
59	} else { \\
60		tst_ret = syscall(NR, ##__VA_ARGS__); \\
61	} \\
62	if (tst_ret == -1 && errno == ENOSYS) { \\
63		tst_brk(TCONF, "syscall(%d) " #NR " not supported", NR); \\
64	} \\
65	tst_ret; \\
66})
67
68EOF
69
70jobs=0
71for arch in $(cat "${srcdir}/order") ; do
72	(
73	echo "Generating data for arch $arch ... "
74
75	(
76	echo
77	case ${arch} in
78		sparc64) echo "#if defined(__sparc__) && defined(__arch64__)" ;;
79		sparc) echo "#if defined(__sparc__) && !defined(__arch64__)" ;;
80		s390) echo "#if defined(__s390__) && !defined(__s390x__)" ;;
81		mips_n32) echo "#if defined(__mips__) && defined(_ABIN32)" ;;
82		mips_n64) echo "#if defined(__mips__) && defined(_ABI64)" ;;
83		mips_o32) echo "#if defined(__mips__) && defined(_ABIO32) && _MIPS_SZLONG == 32" ;;
84		*) echo "#ifdef __${arch}__" ;;
85	esac
86	while read line ; do
87		set -- ${line}
88		nr="__NR_$1"
89		shift
90		if [ $# -eq 0 ] ; then
91			err "invalid line found: $line"
92		fi
93		echo "# ifndef ${nr}"
94		echo "#  define ${nr} $*"
95		echo "# endif"
96	done < "${srcdir}/${arch}.in"
97	echo "#endif"
98	echo
99	) >> "${output_pid}.${arch}"
100
101	) &
102
103	jobs=$(( jobs + 1 ))
104	if [ ${jobs} -ge ${max_jobs} ] ; then
105		wait || exit 1
106		jobs=0
107	fi
108done
109
110echo "Generating stub list ... "
111(
112echo
113echo "/* Common stubs */"
114echo "#define __LTP__NR_INVALID_SYSCALL -1" >> "${output_pid}"
115for nr in $(awk '{print $1}' "${srcdir}/"*.in | sort -u) ; do
116	nr="__NR_${nr}"
117	echo "# ifndef ${nr}"
118	echo "#  define ${nr} __LTP__NR_INVALID_SYSCALL"
119	echo "# endif"
120done
121echo "#endif"
122) >> "${output_pid}._footer"
123
124wait || exit 1
125
126printf "Combining them all ... "
127for arch in $(cat "${srcdir}/order") _footer ; do
128	cat "${output_pid}.${arch}"
129done >> "${output_pid}"
130mv "${output_pid}" "../${output}"
131rm -f "${output_pid}"*
132echo "OK!"
133