• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh -eu
2# SPDX-License-Identifier: GPL-2.0-or-later
3#
4# Generate the syscalls.h file, merging all architectures syscalls input file
5# which are in the current folder and defined inside supported-arch.txt file.
6
7SYSCALLS_FILE="$1"
8
9if [ -z "${SYSCALLS_FILE}" ]; then
10	echo "Please provide the syscalls.h directory:"
11	echo ""
12	echo "$0 path/of/syscalls.h"
13	echo ""
14	exit 1
15fi
16
17SCRIPT_DIR="$(realpath $(dirname "$0"))"
18SUPPORTED_ARCH="${SCRIPT_DIR}/supported-arch.txt"
19
20echo '// SPDX-License-Identifier: GPL-2.0-or-later
21/************************************************
22 * GENERATED FILE: DO NOT EDIT/PATCH THIS FILE  *
23 *  change your arch specific .in file instead  *
24 ************************************************/
25
26/*
27 * Here we stick all the ugly *fallback* logic for linux
28 * system call numbers (those __NR_ thingies).
29 */
30
31#ifndef LAPI_SYSCALLS_H__
32#define LAPI_SYSCALLS_H__
33
34#include <errno.h>
35#include <sys/syscall.h>
36#include <asm/unistd.h>
37
38#ifdef TST_TEST_H__
39#define TST_SYSCALL_BRK__(NR, SNR) ({ \
40tst_brk(TCONF, \
41	"syscall(%d) " SNR " not supported on your arch", NR); \
42})
43#else
44inline static void dummy_cleanup(void) {}
45
46#define TST_SYSCALL_BRK__(NR, SNR) ({ \
47tst_brkm(TCONF, dummy_cleanup, \
48	"syscall(%d) " SNR " not supported on your arch", NR); \
49})
50#endif
51
52#define tst_syscall(NR, ...) ({ \
53intptr_t tst_ret; \
54if (NR == __LTP__NR_INVALID_SYSCALL) { \
55	errno = ENOSYS; \
56	tst_ret = -1; \
57} else { \
58	tst_ret = syscall(NR, ##__VA_ARGS__); \
59} \
60if (tst_ret == -1 && errno == ENOSYS) { \
61	TST_SYSCALL_BRK__(NR, #NR); \
62} \
63tst_ret; \
64})
65
66#define __LTP__NR_INVALID_SYSCALL -1' >${SYSCALLS_FILE}
67
68while IFS= read -r arch; do
69	(
70		echo
71		case ${arch} in
72		sparc64) echo "#if defined(__sparc__) && defined(__arch64__)" ;;
73		sparc) echo "#if defined(__sparc__) && !defined(__arch64__)" ;;
74		s390) echo "#if defined(__s390__) && !defined(__s390x__)" ;;
75		mips64n32) echo "#if defined(__mips__) && defined(_ABIN32)" ;;
76		mips64) echo "#if defined(__mips__) && defined(_ABI64)" ;;
77		mipso32) echo "#if defined(__mips__) && defined(_ABIO32) && _MIPS_SZLONG == 32" ;;
78		parisc) echo "#ifdef __hppa__" ;;
79		loongarch64) echo "#ifdef __loongarch__" ;;
80		arm64) echo "#ifdef __aarch64__" ;;
81		*) echo "#ifdef __${arch}__" ;;
82		esac
83
84		while read -r line; do
85			set -- ${line}
86			syscall_nr="__NR_$1"
87			shift
88
89			echo "# ifndef ${syscall_nr}"
90			echo "#  define ${syscall_nr} $*"
91			echo "# endif"
92		done <"${SCRIPT_DIR}/${arch}.in"
93		echo "#endif"
94		echo
95	) >>${SYSCALLS_FILE}
96done <${SUPPORTED_ARCH}
97
98(
99	echo
100	echo "/* Common stubs */"
101	for num in $(awk '{print $1}' "${SCRIPT_DIR}/"*.in | sort -u); do
102		syscall_nr="__NR_${num}"
103
104		echo "# ifndef ${syscall_nr}"
105		echo "#  define ${syscall_nr} __LTP__NR_INVALID_SYSCALL"
106		echo "# endif"
107	done
108	echo "#endif"
109) >>${SYSCALLS_FILE}
110