makesyscalls.sh revision 1.148 1 # $NetBSD: makesyscalls.sh,v 1.148 2015/03/07 21:49:56 christos Exp $
2 #
3 # Copyright (c) 1994, 1996, 2000 Christopher G. Demetriou
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. All advertising materials mentioning features or use of this software
15 # must display the following acknowledgement:
16 # This product includes software developed for the NetBSD Project
17 # by Christopher G. Demetriou.
18 # 4. The name of the author may not be used to endorse or promote products
19 # derived from this software without specific prior written permission
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 # @(#)makesyscalls.sh 8.1 (Berkeley) 6/10/93
33
34 set -e
35
36 case $# in
37 2) ;;
38 *) echo "Usage: $0 config-file input-file" 1>&2
39 exit 1
40 ;;
41 esac
42
43 # the config file sets the following variables:
44 # sysalign check for alignment of off_t/dev_t/time_t
45 # sysnames the syscall names file
46 # sysnumhdr the syscall numbers file
47 # syssw the syscall switch file
48 # sysarghdr the syscall argument struct definitions
49 # compatopts those syscall types that are for 'compat' syscalls
50 # switchname the name for the 'struct sysent' we define
51 # namesname the name for the 'const char *[]' we define
52 # constprefix the prefix for the system call constants
53 # registertype the type for register_t
54 # nsysent the size of the sysent table
55 # sys_nosys [optional] name of function called for unsupported
56 # syscalls, if not sys_nosys()
57 # maxsysargs [optiona] the maximum number or arguments
58 #
59 # NOTE THAT THIS makesyscalls.sh DOES NOT SUPPORT 'SYSLIBCOMPAT'.
60
61 # source the config file.
62 sys_nosys="sys_nosys" # default is sys_nosys(), if not specified otherwise
63 maxsysargs=8 # default limit is 8 (32bit) arguments
64 systrace="/dev/null"
65 rumpcalls="/dev/null"
66 rumpcallshdr="/dev/null"
67 rumpsysmap="/dev/null"
68 rumpsysent="rumpsysent.tmp"
69 rumpnoflags="\n\t\t.sy_flags = SYCALL_NOSYS,"
70 rumpnosys="(sy_call_t *)rumpns_enosys"
71 rumpnomodule="(sy_call_t *)rumpns_sys_nomodule"
72 . ./$1
73
74 # tmp files:
75 sysdcl="sysent.dcl"
76 sysprotos="sys.protos"
77 syscompat_pref="sysent."
78 sysent="sysent.switch"
79 sysnamesbottom="sysnames.bottom"
80 rumptypes="rumphdr.types"
81 rumpprotos="rumphdr.protos"
82 systracetmp="systrace.$$"
83 systraceret="systraceret.$$"
84
85 trap "rm $sysdcl $sysprotos $sysent $sysnamesbottom $rumpsysent $rumptypes $rumpprotos $systracetmp $systraceret" 0
86
87 # Awk program (must support nawk extensions)
88 # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
89 awk=${AWK:-awk}
90
91 # Does this awk have a "toupper" function?
92 have_toupper="$($awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null)"
93
94 # If this awk does not define "toupper" then define our own.
95 if [ "$have_toupper" = TRUE ] ; then
96 # Used awk (GNU awk or nawk) provides it
97 toupper=
98 else
99 # Provide our own toupper()
100 toupper='
101 function toupper(str) {
102 _toupper_cmd = "echo "str" |tr a-z A-Z"
103 _toupper_cmd | getline _toupper_str;
104 close(_toupper_cmd);
105 return _toupper_str;
106 }'
107 fi
108
109 # before handing it off to awk, make a few adjustments:
110 # (1) insert spaces around {, }, (, ), *, and commas.
111 # (2) get rid of any and all dollar signs (so that rcs id use safe)
112 #
113 # The awk script will deal with blank lines and lines that
114 # start with the comment character (';').
115
116 sed -e '
117 s/\$//g
118 :join
119 /\\$/{a\
120
121 N
122 s/\\\n//
123 b join
124 }
125 2,${
126 /^#/!s/\([{}()*,|]\)/ \1 /g
127 }
128 ' < $2 | $awk "
129 $toupper
130 BEGIN {
131 # Create a NetBSD tag that does not get expanded when checking
132 # this script out of CVS. (This part of the awk script is in a
133 # shell double-quoted string, so the backslashes are eaten by
134 # the shell.)
135 tag = \"\$\" \"NetBSD\" \"\$\"
136
137 # to allow nested #if/#else/#endif sets
138 savedepth = 0
139 # to track already processed syscalls
140
141 sysnames = \"$sysnames\"
142 sysprotos = \"$sysprotos\"
143 sysnumhdr = \"$sysnumhdr\"
144 sysarghdr = \"$sysarghdr\"
145 sysarghdrextra = \"$sysarghdrextra\"
146 systrace = \"$systrace\"
147 systracetmp = \"$systracetmp\"
148 systraceret = \"$systraceret\"
149 rumpcalls = \"$rumpcalls\"
150 rumpcallshdr = \"$rumpcallshdr\"
151 rumpsysent = \"$rumpsysent\"
152 rumpsysmap = \"$rumpsysmap\"
153 switchname = \"$switchname\"
154 namesname = \"$namesname\"
155 constprefix = \"$constprefix\"
156 registertype = \"$registertype\"
157 sysalign=\"$sysalign\"
158 if (!registertype) {
159 registertype = \"register_t\"
160 }
161 nsysent = \"$nsysent\"
162
163 sysdcl = \"$sysdcl\"
164 syscompat_pref = \"$syscompat_pref\"
165 sysent = \"$sysent\"
166 sysnamesbottom = \"$sysnamesbottom\"
167 rumpprotos = \"$rumpprotos\"
168 rumptypes = \"$rumptypes\"
169 sys_nosys = \"$sys_nosys\"
170 maxsysargs = \"$maxsysargs\"
171 infile = \"$2\"
172
173 compatopts = \"$compatopts\"
174 "'
175
176 if (rumpcalls != "/dev/null")
177 haverumpcalls = 1
178
179 printf "/* %s */\n\n", tag > sysdcl
180 printf "/*\n * System call switch table.\n *\n" > sysdcl
181 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
182
183 ncompat = split(compatopts,compat)
184 for (i = 1; i <= ncompat; i++) {
185 compat_upper[i] = toupper(compat[i])
186
187 printf "\n#ifdef %s\n", compat_upper[i] > sysent
188 printf "#define %s(func) __CONCAT(%s_,func)\n", compat[i], \
189 compat[i] > sysent
190 printf "#else\n" > sysent
191 printf "#define %s(func) %s\n", compat[i], sys_nosys > sysent
192 printf "#endif\n" > sysent
193 }
194
195 printf "\n#define\ts(type)\tsizeof(type)\n" > sysent
196 printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > sysent
197 printf "#define\tns(type)\t.sy_narg = n(type), .sy_argsize = s(type)\n\n", registertype > sysent
198 printf "struct sysent %s[] = {\n",switchname > sysent
199
200 printf "/* %s */\n\n", tag > sysnames
201 printf "/*\n * System call names.\n *\n" > sysnames
202 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
203
204 printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
205 if (haverumpcalls)
206 printf("#ifndef RUMP_CLIENT\n") > sysprotos
207
208 printf "/* %s */\n\n", tag > sysnumhdr
209 printf "/*\n * System call numbers.\n *\n" > sysnumhdr
210 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
211
212 printf "/* %s */\n\n", tag > sysarghdr
213 printf "/*\n * System call argument lists.\n *\n" > sysarghdr
214 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
215
216 printf "/* %s */\n\n", tag > rumpcalls
217 printf "/*\n * System call vector and marshalling for rump.\n *\n" > rumpcalls
218 printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcalls
219
220 printf "/* %s */\n\n", tag > rumpcallshdr
221 printf "/*\n * System call protos in rump namespace.\n *\n" > rumpcallshdr
222 printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcallshdr
223
224 printf "/* %s */\n\n", tag > systrace
225 printf "/*\n * System call argument to DTrace register array converstion.\n *\n" > systrace
226 printf " * DO NOT EDIT-- this file is automatically generated.\n" > systrace
227 }
228 NR == 1 {
229 sub(/ $/, "")
230 printf " * created from%s\n */\n\n", $0 > sysdcl
231 printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysdcl
232
233 printf " * created from%s\n */\n\n", $0 > sysnames
234 printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysnames
235
236 printf " * created from%s\n */\n\n", $0 > rumpcalls
237 printf "#ifdef RUMP_CLIENT\n" > rumpcalls
238 printf "#include <rump/rumpuser_port.h>\n" > rumpcalls
239 printf "#endif /* RUMP_CLIENT */\n\n" > rumpcalls
240 printf "#include <sys/param.h>\n\n" > rumpcalls
241 printf "#ifdef __NetBSD__\n" > rumpcalls
242 printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > rumpcalls
243
244 printf "#include <sys/fstypes.h>\n" > rumpcalls
245 printf "#include <sys/proc.h>\n" > rumpcalls
246 printf "#endif /* __NetBSD__ */\n\n" > rumpcalls
247 printf "#ifdef RUMP_CLIENT\n" > rumpcalls
248 printf "#include <errno.h>\n" > rumpcalls
249 printf "#include <stdint.h>\n" > rumpcalls
250 printf "#include <stdlib.h>\n" > rumpcalls
251 printf "#include <string.h>\n\n" > rumpcalls
252 printf "#include <srcsys/syscall.h>\n" > rumpcalls
253 printf "#include <srcsys/syscallargs.h>\n\n" > rumpcalls
254 printf "#include <rump/rumpclient.h>\n\n" > rumpcalls
255 printf "#define rsys_syscall(num, data, dlen, retval)\t\\\n" > rumpcalls
256 printf " rumpclient_syscall(num, data, dlen, retval)\n" > rumpcalls
257 printf "#define rsys_seterrno(error) errno = error\n" > rumpcalls
258 printf "#else\n" > rumpcalls
259 printf "#include <sys/syscall.h>\n" > rumpcalls
260 printf "#include <sys/syscallargs.h>\n\n" > rumpcalls
261 printf "#include <sys/syscallvar.h>\n\n" > rumpcalls
262 printf "#include <rump/rumpuser.h>\n" > rumpcalls
263 printf "#include \"rump_private.h\"\n\n" > rumpcalls
264 printf "#define rsys_syscall(num, data, dlen, retval)\t\\\n" > rumpcalls
265 printf " rump_syscall(num, data, dlen, retval)\n\n" > rumpcalls
266 printf "#define rsys_seterrno(error) rumpuser_seterrno(error)\n" \
267 > rumpcalls
268 printf "#endif\n\n" > rumpcalls
269
270 printf "#ifndef RUMP_KERNEL_IS_LIBC\n" > rumpcalls
271 printf "#define RUMP_SYS_COMPAT\n" > rumpcalls
272 printf "#endif\n\n" > rumpcalls
273
274 printf "#if\tBYTE_ORDER == BIG_ENDIAN\n" > rumpcalls
275 printf "#define SPARG(p,k)\t((p)->k.be.datum)\n" > rumpcalls
276 printf "#else /* LITTLE_ENDIAN, I hope dearly */\n" > rumpcalls
277 printf "#define SPARG(p,k)\t((p)->k.le.datum)\n" > rumpcalls
278 printf "#endif\n\n" > rumpcalls
279 printf "\nvoid rumpns_sys_nomodule(void);\n" > rumpcalls
280
281 printf "\n#ifndef RUMP_CLIENT\n" > rumpsysent
282 printf "int rumpns_enosys(void);\n" > rumpsysent
283 printf "#define\ts(type)\tsizeof(type)\n" > rumpsysent
284 printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > rumpsysent
285 printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > rumpsysent
286 printf "struct sysent rump_sysent[] = {\n" > rumpsysent
287
288 # System call names are included by userland (kdump(1)), so
289 # hide the include files from it.
290 printf "#if defined(_KERNEL_OPT)\n" > sysnames
291
292 printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
293 printf "const char *const %s[] = {\n",namesname > sysnamesbottom
294
295 printf " * created from%s\n */\n\n", $0 > sysnumhdr
296 printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
297 printf "#define _" constprefix "SYSCALL_H_\n\n" > sysnumhdr
298
299 printf " * created from%s\n */\n\n", $0 > sysarghdr
300 printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
301 printf "#define _" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
302
303 printf " * created from%s\n */\n\n", $0 > rumpcallshdr
304 printf "#ifndef _RUMP_RUMP_SYSCALLS_H_\n" > rumpcallshdr
305 printf "#define _RUMP_RUMP_SYSCALLS_H_\n\n" > rumpcallshdr
306 printf "#ifdef _KERNEL\n" > rumpcallshdr
307 printf "#error Interface not supported inside kernel\n" > rumpcallshdr
308 printf "#endif /* _KERNEL */\n\n" > rumpcallshdr
309 printf "#include <rump/rump_syscalls_compat.h>\n\n" > rumpcallshdr
310
311 printf "%s", sysarghdrextra > sysarghdr
312 # Write max number of system call arguments to both headers
313 printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
314 > sysnumhdr
315 printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
316 > sysarghdr
317 printf "#undef\tsyscallarg\n" > sysarghdr
318 printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
319 printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
320 printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
321 printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
322 printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
323 > sysarghdr
324 printf "\t\t\tint8_t pad[ /* CONSTCOND */\t\t\t\\\n" > sysarghdr
325 printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
326 registertype > sysarghdr
327 printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
328 printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
329 registertype > sysarghdr
330 printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
331 printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
332 printf "\t}\n" > sysarghdr
333 printf("\n#undef check_syscall_args\n") >sysarghdr
334 printf("#define check_syscall_args(call) /*LINTED*/ \\\n" \
335 "\ttypedef char call##_check_args" \
336 "[sizeof (struct call##_args) \\\n" \
337 "\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
338 constprefix, registertype) >sysarghdr
339
340 printf " * This file is part of the DTrace syscall provider.\n */\n\n" > systrace
341 printf "static void\nsystrace_args(register_t sysnum, const void *params, uintptr_t *uarg, size_t *n_args)\n{\n" > systrace
342 printf "\tintptr_t *iarg = (intptr_t *)uarg;\n" > systrace
343 printf "\tswitch (sysnum) {\n" > systrace
344
345 printf "static void\nsystrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)\n{\n\tconst char *p = NULL;\n" > systracetmp
346 printf "\tswitch (sysnum) {\n" > systracetmp
347
348 printf "static void\nsystrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)\n{\n\tconst char *p = NULL;\n" > systraceret
349 printf "\tswitch (sysnum) {\n" > systraceret
350
351 # compat types from syscalls.master. this is slightly ugly,
352 # but given that we have so few compats from over 17 years,
353 # a more complicated solution is not currently warranted.
354 uncompattypes["struct timeval50"] = "struct timeval";
355 uncompattypes["struct timespec50"] = "struct timespec";
356 uncompattypes["struct stat30"] = "struct stat";
357
358 next
359 }
360 NF == 0 || $1 ~ /^;/ {
361 next
362 }
363 $0 ~ /^%%$/ {
364 intable = 1
365 next
366 }
367 $1 ~ /^#[ ]*include/ {
368 print > sysdcl
369 print > sysnames
370 next
371 }
372 $1 ~ /^#/ && !intable {
373 print > sysdcl
374 print > sysnames
375 next
376 }
377 $1 ~ /^#/ && intable {
378 if ($1 ~ /^#[ ]*if/) {
379 savedepth++
380 savesyscall[savedepth] = syscall
381 }
382 if ($1 ~ /^#[ ]*else/) {
383 if (savedepth <= 0) {
384 printf("%s: line %d: unbalanced #else\n", \
385 infile, NR)
386 exit 1
387 }
388 syscall = savesyscall[savedepth]
389 }
390 if ($1 ~ /^#[ ]*endif/) {
391 if (savedepth <= 0) {
392 printf("%s: line %d: unbalanced #endif\n", \
393 infile, NR)
394 exit 1
395 }
396 savedepth--
397 }
398 print > sysent
399 print > sysarghdr
400 print > sysnumhdr
401 print > sysprotos
402 print > sysnamesbottom
403 print > systrace
404 print > systracetmp
405 print > systraceret
406
407 # XXX: technically we do not want to have conditionals in rump,
408 # but it is easier to just let the cpp handle them than try to
409 # figure out what we want here in this script
410 print > rumpsysent
411 next
412 }
413 syscall != $1 {
414 printf "%s: line %d: syscall number out of sync at %d\n", \
415 infile, NR, syscall
416 printf "line is:\n"
417 print
418 exit 1
419 }
420 function parserr(was, wanted) {
421 printf "%s: line %d: unexpected %s (expected <%s>)\n", \
422 infile, NR, was, wanted
423 printf "line is:\n"
424 print
425 exit 1
426 }
427 function fillerpsysent(syscall, flags, name, comment) {
428 return sprintf("\t{%s\n\t\t.sy_call = %s,\n\t},\t\t/* %d = filler */",\
429 flags, name, syscall, comment);
430 }
431 function parseline() {
432 f=3 # toss number and type
433 if ($2 == "INDIR")
434 sycall_flags="SYCALL_INDIRECT"
435 else
436 sycall_flags="0"
437 if ($NF != "}") {
438 funcalias=$NF
439 end=NF-1
440 } else {
441 funcalias=""
442 end=NF
443 }
444 if ($f == "INDIR") { # allow for "NOARG INDIR"
445 sycall_flags = "SYCALL_INDIRECT | " sycall_flags
446 f++
447 }
448 if ($f == "MODULAR") { # registered at runtime
449 modular = 1
450 f++
451 } else {
452 modular = 0;
453 }
454 if ($f == "RUMP") {
455 rumpable = 1
456 f++
457 } else {
458 rumpable = 0
459 }
460 if ($f ~ /^[a-z0-9_]*$/) { # allow syscall alias
461 funcalias=$f
462 f++
463 }
464 if ($f != "{")
465 parserr($f, "{")
466 f++
467 if ($end != "}")
468 parserr($end, "}")
469 end--
470 if ($end != ";")
471 parserr($end, ";")
472 end--
473 if ($end != ")")
474 parserr($end, ")")
475 end--
476
477 returntype = oldf = "";
478 do {
479 if (returntype != "" && oldf != "*")
480 returntype = returntype" ";
481 returntype = returntype$f;
482 oldf = $f;
483 f++
484 } while ($f != "|" && f < (end-1))
485 if (f == (end - 1)) {
486 parserr($f, "function argument definition (maybe \"|\"?)");
487 }
488 f++
489
490 fprefix=$f
491 f++
492 if ($f != "|") {
493 parserr($f, "function compat delimiter (maybe \"|\"?)");
494 }
495 f++
496
497 fcompat=""
498 if ($f != "|") {
499 fcompat=$f
500 f++
501 }
502
503 if ($f != "|") {
504 parserr($f, "function name delimiter (maybe \"|\"?)");
505 }
506 f++
507 fbase=$f
508
509 # pipe is special in how to returns its values.
510 # So just generate it manually if present.
511 if (rumpable == 1 && fbase == "pipe") {
512 rumpable = 0;
513 rumphaspipe = 1;
514 }
515
516 if (fcompat != "") {
517 funcname=fprefix "___" fbase "" fcompat
518 } else {
519 funcname=fprefix "_" fbase
520 }
521 if (returntype == "quad_t" || returntype == "off_t") {
522 if (sycall_flags == "0")
523 sycall_flags = "SYCALL_RET_64";
524 else
525 sycall_flags = "SYCALL_RET_64 | " sycall_flags;
526 }
527
528 if (funcalias == "") {
529 funcalias=funcname
530 sub(/^([^_]+_)*sys_/, "", funcalias)
531 realname=fbase
532 } else {
533 realname=funcalias
534 }
535 rumpfname=realname "" fcompat
536 f++
537
538 if ($f != "(")
539 parserr($f, "(")
540 f++
541
542 argc=0;
543 argalign=0;
544 if (f == end) {
545 if ($f != "void")
546 parserr($f, "argument definition")
547 isvarargs = 0;
548 varargc = 0;
549 argtype[0]="void";
550 return
551 }
552
553 # some system calls (open() and fcntl()) can accept a variable
554 # number of arguments. If syscalls accept a variable number of
555 # arguments, they must still have arguments specified for
556 # the remaining argument "positions," because of the way the
557 # kernel system call argument handling works.
558 #
559 # Indirect system calls, e.g. syscall(), are exceptions to this
560 # rule, since they are handled entirely by machine-dependent code
561 # and do not need argument structures built.
562
563 isvarargs = 0;
564 args64 = 0;
565 ptr = 0;
566 while (f <= end) {
567 if ($f == "...") {
568 f++;
569 isvarargs = 1;
570 varargc = argc;
571 continue;
572 }
573 argc++
574 argtype[argc]=""
575 oldf=""
576 while (f < end && $(f+1) != ",") {
577 if (argtype[argc] != "" && oldf != "*")
578 argtype[argc] = argtype[argc]" ";
579 argtype[argc] = argtype[argc]$f;
580 oldf = $f;
581 f++
582 }
583 if (argtype[argc] == "")
584 parserr($f, "argument definition")
585 if (argtype[argc] == "off_t" \
586 || argtype[argc] == "dev_t" \
587 || argtype[argc] == "time_t") {
588 if ((argalign % 2) != 0 && sysalign &&
589 funcname != "sys_posix_fadvise") # XXX for now
590 parserr($f, "a padding argument")
591 } else {
592 argalign++;
593 }
594 if (argtype[argc] == "quad_t" || argtype[argc] == "off_t" \
595 || argtype[argc] == "dev_t" || argtype[argc] == "time_t") {
596 if (sycall_flags == "0")
597 sycall_flags = "SYCALL_ARG"argc-1"_64";
598 else
599 sycall_flags = "SYCALL_ARG"argc-1"_64 | " sycall_flags;
600 args64++;
601 }
602 if (index(argtype[argc], "*") != 0 && ptr == 0) {
603 if (sycall_flags == "0")
604 sycall_flags = "SYCALL_ARG_PTR";
605 else
606 sycall_flags = "SYCALL_ARG_PTR | " sycall_flags;
607 ptr = 1;
608 }
609 argname[argc]=$f;
610 f += 2; # skip name, and any comma
611 }
612 if (args64 > 0)
613 sycall_flags = "SYCALL_NARGS64_VAL("args64") | " sycall_flags;
614 # must see another argument after varargs notice.
615 if (isvarargs) {
616 if (argc == varargc)
617 parserr($f, "argument definition")
618 } else
619 varargc = argc;
620 }
621
622 function printproto(wrap) {
623 printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
624 returntype) > sysnumhdr
625 for (i = 1; i <= varargc; i++)
626 printf(" \"%s\"", argtype[i]) > sysnumhdr
627 if (isvarargs)
628 printf(" \"...\"") > sysnumhdr
629 printf(" */\n") > sysnumhdr
630 printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
631 syscall) > sysnumhdr
632
633 # rumpalooza
634 if (!rumpable)
635 return
636
637 # accumulate fbases we have seen. we want the last
638 # occurence for the default __RENAME()
639 seen = funcseen[fbase]
640 funcseen[fbase] = rumpfname
641 # special case for mknod as type of last argument changed from
642 # uint32_t to dev_t
643 if ((seen && fbase != "mknod") || (!seen && fbase == "mknod"))
644 return
645
646 printf("%s rump_sys_%s(", returntype, realname) > rumpprotos
647
648 for (i = 1; i < varargc; i++)
649 if (argname[i] != "PAD")
650 printf("%s, ", uncompattype(argtype[i])) > rumpprotos
651
652 if (isvarargs)
653 printf("%s, ...)", uncompattype(argtype[varargc]))>rumpprotos
654 else
655 printf("%s)", uncompattype(argtype[argc])) > rumpprotos
656
657 printf(" __RENAME(RUMP_SYS_RENAME_%s)", toupper(fbase))> rumpprotos
658 printf(";\n") > rumpprotos
659
660 # generate forward-declares for types, apart from the
661 # braindead typedef jungle we cannot easily handle here
662 for (i = 1; i <= varargc; i++) {
663 type=uncompattype(argtype[i])
664 sub("const ", "", type)
665 ntype=type
666 sub(" *\\*.*", "", ntype);
667 if (!typeseen[ntype] && \
668 match(type, "struct") && match(type, "\\*")) {
669 typeseen[ntype] = 1
670 printf("%s;\n", ntype) > rumptypes
671 }
672 }
673 }
674
675 function printrumpsysent(insysent, compatwrap) {
676 if (modular) {
677 fn = rumpnomodule
678 flags = rumpnoflags
679 } else {
680 fn = rumpnosys
681 flags = ""
682 }
683 if (!insysent) {
684 printf("\t{%s\n\t\t.sy_call = %s,\n},\t\t/* %d = %s */\n", \
685 flags, fn, syscall, funcalias) > rumpsysent
686 return
687 }
688
689 printf("\t{") > rumpsysent
690 if (argc != 0) {
691 printf("\n\t\tns(struct %ssys_%s_args),", compatwrap_, funcalias) > rumpsysent
692 }
693
694 printf("\n\t\t.sy_call = %s,\n\t},", fn) > rumpsysent
695 printf("\t\t/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > rumpsysent
696 }
697
698 function iscompattype(type) {
699 for (var in uncompattypes) {
700 if (match(type, var)) {
701 return 1
702 }
703 }
704
705 return 0
706 }
707
708 function uncompattype(type) {
709 for (var in uncompattypes) {
710 if (match(type, var)) {
711 sub(var, uncompattypes[var], type)
712 return type
713 }
714 }
715
716 return type
717 }
718
719 function printrumpsysmap(syscall, wfn, funcalias, rumpentry) {
720 printf("%-4d %-22s %-18s %s\n",
721 syscall, wfn, funcalias, rumpentry) > rumpsysmap
722 }
723
724 function putsystrace(type, compatwrap_) {
725 printf("\t/* %s */\n\tcase %d: {\n", funcname, syscall) > systrace
726 printf("\t/* %s */\n\tcase %d:\n", funcname, syscall) > systracetmp
727 printf("\t/* %s */\n\tcase %d:\n", funcname, syscall) > systraceret
728 if (argc > 0) {
729 printf("\t\tswitch(ndx) {\n") > systracetmp
730 printf("\t\tstruct %s%s_args *p = params;\n", compatwrap_, funcname) > systrace
731 for (i = 1; i <= argc; i++) {
732 arg = argtype[i]
733 sub("__restrict$", "", arg)
734 printf("\t\tcase %d:\n\t\t\tp = \"%s\";\n\t\t\tbreak;\n", i - 1, arg) > systracetmp
735 if (arg ~ /.*p_t$/ || arg ~ /.*p$/ || arg ~ /.*_t_p$/ ||
736 arg ~ /.*_pointer_t$/)
737 printf("\t\tuarg[%d] = (intptr_t) SCARG(p, %s).i32; /* %s */\n", \
738 i - 1, \
739 argname[i], arg) > systrace
740 else if (index(arg, "*") > 0 || arg == "caddr_t")
741 printf("\t\tuarg[%d] = (intptr_t) SCARG(p, %s); /* %s */\n", \
742 i - 1, \
743 argname[i], arg) > systrace
744 else if (substr(arg, 1, 1) == "u" || arg == "size_t")
745 printf("\t\tuarg[%d] = SCARG(p, %s); /* %s */\n", \
746 i - 1, \
747 argname[i], arg) > systrace
748 else
749 printf("\t\tiarg[%d] = SCARG(p, %s); /* %s */\n", \
750 i - 1, \
751 argname[i], arg) > systrace
752 }
753 printf("\t\tdefault:\n\t\t\tbreak;\n\t\t};\n") > systracetmp
754
755 printf("\t\tif (ndx == 0 || ndx == 1)\n") > systraceret
756 printf("\t\t\tp = \"%s\";\n", returntype) > systraceret
757 printf("\t\tbreak;\n") > systraceret
758 }
759 printf("\t\t*n_args = %d;\n\t\tbreak;\n\t}\n", argc) > systrace
760 printf("\t\tbreak;\n") > systracetmp
761 }
762
763 function putent(type, compatwrap) {
764 # output syscall declaration for switch table.
765 if (compatwrap == "")
766 compatwrap_ = ""
767 else
768 compatwrap_ = compatwrap "_"
769 if (argc == 0)
770 arg_type = "void";
771 else {
772 arg_type = "struct " compatwrap_ funcname "_args";
773 }
774 putsystrace(type, compatwrap_)
775 proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
776 arg_type " *, register_t *);\n"
777 if (sysmap[proto] != 1) {
778 sysmap[proto] = 1;
779 print proto > sysprotos;
780 }
781
782 # output syscall switch entry
783 printf("\t{\n\t\t") > sysent
784 if (argc != 0) {
785 printf("ns(struct %s%s_args),", compatwrap_, funcname) > sysent
786 }
787 if (modular)
788 wfn = "sys_nomodule";
789 else if (compatwrap == "")
790 wfn = funcname;
791 else
792 wfn = compatwrap "(" funcname ")";
793 wfn_cast="(sy_call_t *)" wfn
794 if (sycall_flags != "0")
795 flags = "\n\t\t.sy_flags = " sycall_flags ","
796 else
797 flags = ""
798 printf("%s\n\t\t.sy_call = %s\n\t},", flags, wfn_cast) > sysent
799 printf("\t\t/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
800
801 # output syscall name for names table
802 printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
803 > sysnamesbottom
804
805 # output syscall number of header, if appropriate
806 if (type == "STD" || type == "NOARGS" || type == "INDIR" || \
807 type == "NOERR") {
808 # output a prototype, to be used to generate lint stubs in
809 # libc.
810 printproto("")
811 } else if (type == "COMPAT" || type == "EXTERN") {
812 # Just define the syscall number with a comment. These
813 # may be used by compatibility stubs in libc.
814 printproto(compatwrap_)
815 }
816
817 # output syscall argument structure, if it has arguments
818 if (argc != 0) {
819 printf("\n") > sysarghdr
820 if (haverumpcalls && !rumpable)
821 printf("#ifndef RUMP_CLIENT\n") > sysarghdr
822 printf("struct %s%s_args", compatwrap_, funcname) > sysarghdr
823 if (type != "NOARGS") {
824 print " {" >sysarghdr;
825 for (i = 1; i <= argc; i++)
826 printf("\tsyscallarg(%s) %s;\n", argtype[i],
827 argname[i]) > sysarghdr
828 printf "}" >sysarghdr;
829 }
830 printf(";\n") > sysarghdr
831 if (type != "NOARGS" && type != "INDIR") {
832 printf("check_syscall_args(%s%s)\n", compatwrap_,
833 funcname) >sysarghdr
834 }
835 if (haverumpcalls && !rumpable)
836 printf("#endif /* !RUMP_CLIENT */\n") > sysarghdr
837 }
838
839 if (!rumpable) {
840 if (funcname == "sys_pipe" && rumphaspipe == 1) {
841 insysent = 1
842 printrumpsysmap(syscall,
843 funcname, funcalias, "rump_sys_pipe")
844 } else {
845 insysent = 0
846 }
847 } else {
848 insysent = 1
849 }
850 printrumpsysent(insysent, compatwrap)
851
852 # output rump marshalling code if necessary
853 if (!rumpable) {
854 return
855 }
856
857 printrumpsysmap(syscall, wfn, funcalias, "rump___sysimpl_" rumpfname)
858
859 printf("\n") > rumpcalls
860
861 if (compatwrap)
862 printf("#ifdef RUMP_SYS_COMPAT\n") > rumpcalls
863
864 # need a local prototype, we export the re-re-named one in .h
865 printf("%s rump___sysimpl_%s(", returntype, rumpfname) \
866 > rumpcalls
867 for (i = 1; i < argc; i++) {
868 if (argname[i] != "PAD")
869 printf("%s, ", uncompattype(argtype[i])) > rumpcalls
870 }
871 printf("%s);", uncompattype(argtype[argc])) > rumpcalls
872
873 printf("\n%s\nrump___sysimpl_%s(", returntype, rumpfname) > rumpcalls
874 for (i = 1; i < argc; i++) {
875 if (argname[i] != "PAD")
876 printf("%s %s, ", uncompattype(argtype[i]), \
877 argname[i]) > rumpcalls
878 }
879 printf("%s %s)\n", uncompattype(argtype[argc]), argname[argc]) \
880 > rumpcalls
881 printf("{\n\tregister_t retval[2];\n") > rumpcalls
882 if (returntype != "void") {
883 if (type != "NOERR") {
884 printf("\tint error = 0;\n") > rumpcalls
885 }
886 # assume rumpcalls return only integral types
887 printf("\t%s rv = -1;\n", returntype) > rumpcalls
888 }
889
890 argarg = "NULL"
891 argsize = 0;
892 if (argc) {
893 argarg = "&callarg"
894 argsize = "sizeof(callarg)"
895 printf("\tstruct %s%s_args callarg;\n\n",compatwrap_,funcname) \
896 > rumpcalls
897 printf "\tmemset(&callarg, 0, sizeof(callarg));\n" > rumpcalls
898 for (i = 1; i <= argc; i++) {
899 if (argname[i] == "PAD") {
900 printf("\tSPARG(&callarg, %s) = 0;\n", \
901 argname[i]) > rumpcalls
902 } else {
903 if (iscompattype(argtype[i])) {
904 printf("\tSPARG(&callarg, %s) = " \
905 "(%s)%s;\n", argname[i], argtype[i], \
906 argname[i]) > rumpcalls
907 } else {
908 printf("\tSPARG(&callarg, %s) = %s;\n",\
909 argname[i], argname[i]) > rumpcalls
910 }
911 }
912 }
913 printf("\n") > rumpcalls
914 } else {
915 printf("\n") > rumpcalls
916 }
917 printf("\t") > rumpcalls
918 if (returntype != "void" && type != "NOERR")
919 printf("error = ") > rumpcalls
920 printf("rsys_syscall(%s%s%s, " \
921 "%s, %s, retval);\n", constprefix, compatwrap_, funcalias, \
922 argarg, argsize) > rumpcalls
923 if (type != "NOERR") {
924 printf("\trsys_seterrno(error);\n") > rumpcalls
925 printf("\tif (error == 0) {\n") > rumpcalls
926 indent="\t\t"
927 ending="\t}\n"
928 } else {
929 indent="\t"
930 ending=""
931 }
932 if (returntype != "void") {
933 printf("%sif (sizeof(%s) > sizeof(register_t))\n", \
934 indent, returntype) > rumpcalls
935 printf("%s\trv = *(%s *)retval;\n", \
936 indent, returntype) > rumpcalls
937 printf("%selse\n", indent, indent) > rumpcalls
938 printf("%s\trv = *retval;\n", indent, returntype) > rumpcalls
939 printf("%s", ending) > rumpcalls
940 printf("\treturn rv;\n") > rumpcalls
941 }
942 printf("}\n") > rumpcalls
943
944 printf("#ifdef RUMP_KERNEL_IS_LIBC\n") > rumpcalls
945
946 # create the bog-standard, non-renamed public name.
947 # this way we get e.g. select instead of just __select50
948 if (fcompat)
949 printf("__weak_alias(%s,rump___sysimpl_%s);\n", \
950 fbase, rumpfname) > rumpcalls
951
952 printf("__weak_alias(%s,rump___sysimpl_%s);\n", \
953 funcalias, rumpfname) > rumpcalls
954 printf("__weak_alias(_%s,rump___sysimpl_%s);\n", \
955 funcalias, rumpfname) > rumpcalls
956 printf("__strong_alias(_sys_%s,rump___sysimpl_%s);\n", \
957 funcalias, rumpfname) >rumpcalls
958
959 printf("#endif /* RUMP_KERNEL_IS_LIBC */\n") > rumpcalls
960
961 if (compatwrap)
962 printf("#endif /* RUMP_SYS_COMPAT */\n") > rumpcalls
963
964 }
965 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" \
966 || $2 == "NOERR" {
967 parseline()
968 putent($2, "")
969 syscall++
970 next
971 }
972 $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
973 if ($2 == "OBSOL")
974 comment="obsolete"
975 else if ($2 == "EXCL")
976 comment="excluded"
977 else if ($2 == "IGNORED")
978 comment="ignored"
979 else
980 comment="unimplemented"
981 for (i = 3; i <= NF; i++)
982 comment=comment " " $i
983
984 if ($2 == "IGNORED")
985 sys_stub = "(sy_call_t *)nullop";
986 else
987 sys_stub = sys_nosys;
988
989 print fillerpsysent(syscall, "", sys_stub, comment) > sysent
990 print fillerpsysent(syscall, rumpnoflags, rumpnosys, comment) > rumpsysent
991 printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
992 > sysnamesbottom
993 if ($2 != "UNIMPL")
994 printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
995 syscall++
996 next
997 }
998 $2 == "EXTERN" {
999 parseline()
1000 putent("EXTERN", "")
1001 syscall++
1002 next
1003 }
1004 {
1005 for (i = 1; i <= ncompat; i++) {
1006 if ($2 == compat_upper[i]) {
1007 parseline();
1008 putent("COMPAT", compat[i])
1009 syscall++
1010 next
1011 }
1012 }
1013 printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
1014 exit 1
1015 }
1016 END {
1017 # output pipe() syscall with its special retval[2] handling
1018 if (rumphaspipe) {
1019 printf("int rump_sys_pipe(int *);\n") > rumpprotos
1020 printf("\nint rump_sys_pipe(int *);\n") > rumpcalls
1021 printf("int\nrump_sys_pipe(int *fd)\n{\n") > rumpcalls
1022 printf("\tregister_t retval[2];\n") > rumpcalls
1023 printf("\tint error = 0;\n") > rumpcalls
1024 printf("\n\terror = rsys_syscall(SYS_pipe, ") > rumpcalls
1025 printf("NULL, 0, retval);\n") > rumpcalls
1026 printf("\tif (error) {\n") > rumpcalls
1027 printf("\t\trsys_seterrno(error);\n") > rumpcalls
1028 printf("\t} else {\n\t\tfd[0] = retval[0];\n") > rumpcalls
1029 printf("\t\tfd[1] = retval[1];\n\t}\n") > rumpcalls
1030 printf("\treturn error ? -1 : 0;\n}\n") > rumpcalls
1031 printf("#ifdef RUMP_KERNEL_IS_LIBC\n") > rumpcalls
1032 printf("__weak_alias(pipe,rump_sys_pipe);\n") > rumpcalls
1033 printf("__weak_alias(_pipe,rump_sys_pipe);\n") > rumpcalls
1034 printf("__strong_alias(_sys_pipe,rump_sys_pipe);\n") > rumpcalls
1035 printf("#endif\n") > rumpcalls
1036 }
1037
1038 # print default rump syscall interfaces
1039 for (var in funcseen) {
1040 printf("#ifndef RUMP_SYS_RENAME_%s\n", \
1041 toupper(var)) > rumpcallshdr
1042 printf("#define RUMP_SYS_RENAME_%s rump___sysimpl_%s\n", \
1043 toupper(var), funcseen[var]) > rumpcallshdr
1044 printf("#endif\n\n") > rumpcallshdr
1045 }
1046
1047 maxsyscall = syscall
1048 if (nsysent) {
1049 if (syscall > nsysent) {
1050 printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
1051 exit 1
1052 }
1053 while (syscall < nsysent) {
1054 print fillerpsysent(syscall, "", sys_nosys, "filler") > sysent
1055 print fillerpsysent(syscall, rumpnoflags, rumpnosys, "filler") > rumpsysent
1056 printf("\t/* %3d */\t\"# filler\",\n", syscall) \
1057 > sysnamesbottom
1058 syscall++
1059 }
1060 }
1061 printf("};\n") > sysent
1062 printf("};\n") > rumpsysent
1063 printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent
1064 printf("__strong_alias(rumpns_sysent,rump_sysent);\n") > rumpsysent
1065 printf("#endif /* RUMP_CLIENT */\n") > rumpsysent
1066 if (haverumpcalls)
1067 printf("#endif /* !RUMP_CLIENT */\n") > sysprotos
1068 printf("};\n") > sysnamesbottom
1069 printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
1070 if (nsysent)
1071 printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
1072 printf "\tdefault:\n\t\t*n_args = 0;\n\t\tbreak;\n\t};\n}\n" > systrace
1073 printf "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n" > systracetmp
1074 printf "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n" > systraceret
1075 } '
1076
1077 cat $sysprotos >> $sysarghdr
1078 echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
1079 echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
1080 printf "\n#endif /* _RUMP_RUMP_SYSCALLS_H_ */\n" >> $rumpprotos
1081 cat $sysdcl $sysent > $syssw
1082 cat $sysnamesbottom >> $sysnames
1083 cat $rumpsysent >> $rumpcalls
1084
1085 touch $rumptypes
1086 cat $rumptypes >> $rumpcallshdr
1087 echo >> $rumpcallshdr
1088 cat $rumpprotos >> $rumpcallshdr
1089
1090 #chmod 444 $sysnames $sysnumhdr $syssw
1091
1092 cat $systracetmp >> $systrace
1093 cat $systraceret >> $systrace
1094
1095 echo Generated following files:
1096 echo $sysarghdr $sysnumhdr $syssw $sysnames $systrace $rumpcalls $rumpcallshdr $rumpsysmap
1097