blob: 7df4bf5b55a3cc2a8c5a31462129e8ac829a4e59 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
#
# Generate C file mapping errno codes to errno names.
#
# Copyright IBM Corp. 2018
# Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
gcc="$1"
toolsdir="$2"
include_path="-I$toolsdir/include/uapi"
arch_string()
{
echo "$1" |sed -e 'y/- /__/' |tr '[[:upper:]]' '[[:lower:]]'
}
asm_errno_file()
{
arch="$1"
header="$toolsdir/arch/$arch/include/uapi/asm/errno.h"
if test -r "$header"; then
echo "$header"
else
echo "$toolsdir/include/uapi/asm-generic/errno.h"
fi
}
create_errno_lookup_func()
{
arch=$(arch_string "$1")
printf "static const char *errno_to_name__%s(int err)\n{\n\tswitch (err) {\n" $arch
while read name nr; do
printf '\tcase %d: return "%s";\n' $nr $name
done
printf '\tdefault: return "(unknown)";\n\t}\n}\n'
}
process_arch()
{
arch="$1"
asm_errno=$(asm_errno_file "$arch")
$gcc $CFLAGS $include_path -E -dM -x c $asm_errno \
|grep -hE '^#define[[:blank:]]+(E[^[:blank:]]+)[[:blank:]]+([[:digit:]]+).*' \
|awk '{ print $2","$3; }' \
|sort -t, -k2 -nu \
|IFS=, create_errno_lookup_func "$arch"
}
create_arch_errno_table_func()
{
archlist="$1"
default="$2"
printf 'arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *arch)\n'
printf '{\n'
for arch in $archlist; do
printf '\tif (!strcmp(arch, "%s"))\n' $(arch_string "$arch")
printf '\t\treturn errno_to_name__%s;\n' $(arch_string "$arch")
done
printf '\treturn errno_to_name__%s;\n' $(arch_string "$default")
printf '}\n'
}
cat <<EoHEADER
/* SPDX-License-Identifier: GPL-2.0 */
#include <string.h>
EoHEADER
# Create list of architectures that have a specific errno.h.
archlist=""
for f in $toolsdir/arch/*/include/uapi/asm/errno.h; do
d=${f%/include/uapi/asm/errno.h}
arch="${d##*/}"
test -f $toolsdir/arch/$arch/include/uapi/asm/errno.h && archlist="$archlist $arch"
done
for arch in generic $archlist; do
process_arch "$arch"
done
create_arch_errno_table_func "$archlist" "generic"
|