blob: 1411aa99df10346a7d58a2de8656b1e925d10e6f [file] [log] [blame]
#!/bin/sh
output="linux_syscall_numbers.h"
output_pid="linux_syscall_numbers.$$.h"
srcdir=${0%/*}
cat << EOF > "${output_pid}"
/************************************************
* GENERATED FILE: DO NOT EDIT/PATCH THIS FILE *
* change your arch specific .in file instead *
************************************************/
/*
* Here we stick all the ugly *fallback* logic for linux
* system call numbers (those __NR_ thingies).
*
* Licensed under the GPLv2 or later, see the COPYING file.
*/
#ifndef __LINUX_SYSCALL_NUMBERS_H__
#define __LINUX_SYSCALL_NUMBERS_H__
#include <errno.h>
#include <sys/syscall.h>
/*
* Allow callers to implement their own cleanup functions so that this doesn't
* result in compile-time errors and folks get the granularity they desire
* when writing testcases.
*/
static void syscall_cleanup_stub(void) __attribute__ ((weakref ("cleanup")));
static void cleanup(void);
#define syscall(NR, ...) ({ \\
int __ret; \\
if (NR == 0) { \\
errno = ENOSYS; \\
__ret = -1; \\
} else { \\
__ret = syscall(NR, ##__VA_ARGS__); \\
} \\
if (__ret == -1 && errno == ENOSYS) { \\
tst_brkm(TCONF, syscall_cleanup_stub, \\
"syscall " #NR " not supported on your arch"); \\
errno = ENOSYS; \\
} \\
__ret; \\
})
EOF
for arch in $(cat ${srcdir}/order) ; do
echo -n "Generating data for arch $arch ... "
echo "" >> "${output_pid}"
echo "#ifdef __${arch}__" >> "${output_pid}"
while read line ; do
set -- $line
nr="__NR_$1"
shift
if [ -z "$*" ] ; then
echo "invalid line found"
exit 1
fi
cat <<-EOF >> "${output_pid}"
# ifndef $nr
# define $nr $*
# endif
EOF
done < ${srcdir}/${arch}.in
echo "#endif" >> "${output_pid}"
echo "" >> "${output_pid}"
echo "OK!"
done
echo -n "Generating stub list ... "
echo "" >> "${output_pid}"
echo "/* Common stubs */" >> "${output_pid}"
for nr in $(awk '{print $1}' ${srcdir}/*.in | sort -u) ; do
nr="__NR_$nr"
cat <<-EOF >> "${output_pid}"
# ifndef $nr
# define $nr 0
# endif
EOF
done
echo "" >> "${output_pid}"
echo "OK!"
echo "" >> "${output_pid}"
echo "#endif" >> "${output_pid}"
# There's still a race here, but it's much lower than before...
mv "${output_pid}" "${output}"