makelintstub revision 1.27 1 #!/bin/sh -
2 # $NetBSD: makelintstub,v 1.27 2020/05/16 18:31:47 christos Exp $
3 #
4 # Copyright (c) 1996, 1997 Christopher G. Demetriou
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 3. All advertising materials mentioning features or use of this software
16 # must display the following acknowledgement:
17 # This product includes software developed for the
18 # NetBSD Project. See http://www.NetBSD.org/ for
19 # information about NetBSD.
20 # 4. The name of the author may not be used to endorse or promote products
21 # derived from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #
34 # <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
35
36 usage()
37 {
38
39 cat << _EOF 1>&2
40 Usage: $PROG [-n|-p] [-o filename] [-s syscall.h] object ...
41 -n Create SYSCALL_NOERROR.
42 -p Create PSEUDO_NOERROR.
43 (also removes leading "_" on syscall name).
44 -o filename Output to filename.
45 -s syscall.h Header to #include instead of <sys/syscall.h>.
46
47 The CPP environment variable must be set
48 to the path to the C preprocessor.
49 _EOF
50 exit 1
51 }
52
53 header()
54 {
55
56 cat <<- __EOF__
57 /*
58 * THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT.
59 * It is generated by $PROG
60 */
61
62 #include <sys/param.h>
63 #include <sys/acl.h>
64 #include <sys/aio.h>
65 #include <sys/time.h>
66 #include <sys/mount.h>
67 #include <sys/stat.h>
68 #include <ufs/ufs/dinode.h>
69 #include <ufs/lfs/lfs.h>
70 #include <sys/resource.h>
71 #include <sys/poll.h>
72 #include <sys/uio.h>
73 #include <sys/ipc.h>
74 #include <sys/idtype.h>
75 #include <sys/lwpctl.h>
76 #include <sys/mqueue.h>
77 #include <sys/msg.h>
78 #include <sys/sem.h>
79 #include <sys/shm.h>
80 #include <sys/spawn.h>
81 #include <sys/sched.h>
82 #include <sys/timex.h>
83 #include <sys/socket.h>
84 #include <sys/event.h>
85 #include <sys/uuid.h>
86 #include <sys/quotactl.h>
87 #ifdef __STDC__
88 #include <stdarg.h>
89 #else
90 #include <varargs.h>
91 #endif
92
93 __EOF__
94 }
95
96 syscall_stub()
97 {
98
99 syscalldump="$1"
100 syscallname="$2"
101 funcname="$3"
102
103 arglist="$(
104 sed -e 'ta
105 :a
106 s,^/\* syscall: \"'"$syscallname"'\" ,,
107 tb
108 d
109 :b
110 s, \*/$,,' $syscalldump
111 )"
112
113 eval set -f -- "$arglist"
114
115 if [ $# -lt 3 ]; then
116 echo syscall $syscallname not found! 1>&2
117 exit 1
118 fi
119
120 shift # kill "ret:"
121 returntype=$1; shift
122 shift # kill "args:"
123
124 cat <<- __EOF__
125 /*ARGSUSED*/
126 $returntype
127 __EOF__
128
129 # do ANSI C function header
130 echo "#ifdef __STDC__"
131
132 echo "$funcname("
133 first=true; i=1
134 for arg; do
135 if $first; then
136 first=false
137 else
138 echo ", "
139 fi
140 case "$arg" in
141 "...") echo "...";;
142 *) echo "$arg arg$i"; i=$(($i + 1));;
143 esac
144 done
145 if $first; then
146 echo "void"
147 fi
148 echo ")"
149
150 # do K&R C function header
151 echo "#else"
152
153 echo "$funcname("
154 first=true; i=1
155 for arg; do
156 if $first; then
157 first=false
158 else
159 echo ", "
160 fi
161 case "$arg" in
162 "...") echo "va_alist";;
163 *) echo "arg$i"; i=$(($i + 1));;
164 esac
165 done
166 echo ")"
167 i=1
168 for arg; do
169 case "$arg" in
170 "...") echo " va_dcl";;
171 *) echo " $arg arg$i;"; i=$(($i + 1));;
172 esac
173 done
174
175 # do function body
176 echo "#endif"
177
178 echo "{"
179 if [ "$returntype" != "void" ]; then
180 echo " return (($returntype)0);"
181 fi
182 echo "}"
183 }
184
185 trailer()
186 {
187
188 cat <<- __EOF__
189 /* END */
190 __EOF__
191 }
192
193
194 pflag=false
195 nflag=false
196 oarg=""
197 syscallhdr=/usr/include/sys/syscall.h
198 syscalldump=/tmp/makelintstub.$$
199 PROG="$(basename "$0")"
200
201 if [ -z "${CPP}" ]; then
202 usage
203 fi
204
205 while getopts no:ps: i
206 do
207 case "$i" in
208 n) nflag=true;;
209 o) oarg=$OPTARG;;
210 p) pflag=true;;
211 s) syscallhdr=$OPTARG;;
212 *) usage;;
213 esac
214 done
215
216 shift $(expr $OPTIND - 1)
217
218 if $pflag && $nflag
219 then
220 echo "$PROG: -n flag and -p flag may not be used together" 1>&2
221 usage
222 fi
223
224 if [ -n "$oarg" ]; then
225 exec > $oarg
226 fi
227
228 trap "rm -f $syscalldump" 0 1 2 3 15
229
230 header
231
232 echo "#include \"$syscallhdr\"" | ${CPP} -D_LIBC -C > $syscalldump
233
234 for syscall; do
235 fnname=${syscall%.S}
236 if $pflag; then
237 scname=${fnname#_}
238 else
239 scname=$fnname
240 fi
241 syscall_stub $syscalldump $scname $fnname
242 echo ""
243 done
244
245 trailer
246
247 exit 0
248