-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmakesyscalls-fake.sh
executable file
·130 lines (125 loc) · 2.8 KB
/
makesyscalls-fake.sh
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#! /bin/sh -
#
# $FreeBSD$
set -e
case $# in
0) echo "usage: $0 input-file <config-file>" 1>&2
exit 1
;;
esac
if [ -n "$2" -a -f "$2" ]; then
. $2
fi
sed -e '
s/\$//g
:join
/\\$/{a\
N
s/\\\n//
b join
}
2,${
/^#/!s/\([{}()*,]\)/ \1 /g
}
' < $1 | awk '
BEGIN {
printf "#include <sys/param.h>\n"
printf "#include <machine/atomic.h>\n"
printf "\n"
printf "#include <sys/_semaphore.h>\n"
printf "#include <sys/aio.h>\n"
printf "#include <sys/cpuset.h>\n"
printf "#include <sys/jail.h>\n"
printf "#include <sys/linker.h>\n"
printf "#include <sys/mac.h>\n"
printf "#include <sys/module.h>\n"
printf "#include <sys/mount.h>\n"
printf "#include <sys/mqueue.h>\n"
printf "#include <sys/msg.h>\n"
printf "#include <sys/poll.h>\n"
printf "#include <sys/proc.h>\n"
printf "#include <sys/resource.h>\n"
printf "#include <sys/sem.h>\n"
printf "#include <sys/shm.h>\n"
printf "#include <sys/signal.h>\n"
printf "#include <sys/signalvar.h>\n"
printf "#include <sys/socket.h>\n"
printf "#include <sys/stat.h>\n"
printf "#include <sys/thr.h>\n"
printf "#include <sys/time.h>\n"
printf "#include <sys/timex.h>\n"
printf "#include <sys/timeffc.h>\n"
printf "#include <sys/ucontext.h>\n"
printf "#include <sys/utsname.h>\n"
printf "#include <sys/uuid.h>\n"
printf "#include <sys/wait.h>\n"
printf "\n"
printf "#ifndef _ACL_PRIVATE\n"
printf "#define _ACL_PRIVATE\n"
printf "#endif\n"
printf "#include <sys/acl.h>\n"
printf "\n"
printf "#ifndef EBUSY\n"
printf "#define errno 0\n"
printf "#define EBUSY 0\n"
printf "#endif\n"
printf "#include <sys/umtx.h>\n"
printf "\n"
# existing compat shims
printf "struct ostat;\n"
printf "struct nstat;\n"
printf "struct ostatfs;\n"
printf "struct osigaction;\n"
printf "struct osigcontext;\n"
printf "struct oaiocb;\n"
printf "union semun_old;\n"
printf "typedef unsigned int osigset_t;\n"
printf "struct msqid_ds_old;\n"
printf "struct shmid_ds_old;\n"
# TODO
printf "struct ucontext4;\n"
printf "struct sctp_sndrcvinfo;\n"
printf "\n"
}
NF < 4 || $1 !~ /^[0-9]+$/ {
next
}
$3 ~ "UNIMPL" || $3 ~ "OBSOL" || $3 ~ "NODEF" || $3 ~ "NOPROTO" ||
$3 ~ "NOSTD"{
next
}
$4 == "{" {
if ($3 ~ /COMPAT[0-9]*/) {
n = split($3, flags, /\|/)
for (i = 1; i <= n; i++) {
if (flags[i] == "COMPAT") {
$6 = "o" $6
} else if (flags[i] ~ /COMPAT[0-9]+/) {
sub(/COMPAT/, "freebsd", flags[i])
$6 = flags[i] "_" $6
}
}
}
$6 = "__sysfake_" $6
r = ""
if ($5 != "void")
r = "0"
def = ""
impl = ""
for ( i = 5; i <= NF; i++) {
if ($i == ";")
break;
if ($i == "," || $i == ")")
impl = impl " __unused"
impl = impl " " $i
def = def " " $i
}
printf "%s;\n", def
printf "%s\n{ return %s; }\n", impl, r
next
}
{
printf "invalid line: "
print
}
'