makesyscalls.sh revision 1.107 1 #! /bin/sh -
2 # $NetBSD: makesyscalls.sh,v 1.107 2010/12/30 16:49:24 pooka Exp $
3 #
4 # Copyright (c) 1994, 1996, 2000 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 NetBSD Project
18 # by Christopher G. Demetriou.
19 # 4. The name of the author may not be used to endorse or promote products
20 # derived from this software without specific prior written permission
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 # @(#)makesyscalls.sh 8.1 (Berkeley) 6/10/93
34
35 set -e
36
37 case $# in
38 2) ;;
39 *) echo "Usage: $0 config-file input-file" 1>&2
40 exit 1
41 ;;
42 esac
43
44 # the config file sets the following variables:
45 # sysalign check for alignment of off_t
46 # sysnames the syscall names file
47 # sysnumhdr the syscall numbers file
48 # syssw the syscall switch file
49 # sysarghdr the syscall argument struct definitions
50 # compatopts those syscall types that are for 'compat' syscalls
51 # switchname the name for the 'struct sysent' we define
52 # namesname the name for the 'const char *[]' we define
53 # constprefix the prefix for the system call constants
54 # registertype the type for register_t
55 # nsysent the size of the sysent table
56 # sys_nosys [optional] name of function called for unsupported
57 # syscalls, if not sys_nosys()
58 # maxsysargs [optiona] the maximum number or arguments
59 #
60 # NOTE THAT THIS makesyscalls.sh DOES NOT SUPPORT 'SYSLIBCOMPAT'.
61
62 # source the config file.
63 sys_nosys="sys_nosys" # default is sys_nosys(), if not specified otherwise
64 maxsysargs=8 # default limit is 8 (32bit) arguments
65 rumpcalls="/dev/null"
66 rumpcallshdr="/dev/null"
67 rumpsysent="rumpsysent.tmp"
68 . ./$1
69
70 # tmp files:
71 sysdcl="sysent.dcl"
72 sysprotos="sys.protos"
73 syscompat_pref="sysent."
74 sysent="sysent.switch"
75 sysnamesbottom="sysnames.bottom"
76
77 trap "rm $sysdcl $sysprotos $sysent $sysnamesbottom $rumpsysent" 0
78
79 # Awk program (must support nawk extensions)
80 # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
81 awk=${AWK:-awk}
82
83 # Does this awk have a "toupper" function?
84 have_toupper=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
85
86 # If this awk does not define "toupper" then define our own.
87 if [ "$have_toupper" = TRUE ] ; then
88 # Used awk (GNU awk or nawk) provides it
89 toupper=
90 else
91 # Provide our own toupper()
92 toupper='
93 function toupper(str) {
94 _toupper_cmd = "echo "str" |tr a-z A-Z"
95 _toupper_cmd | getline _toupper_str;
96 close(_toupper_cmd);
97 return _toupper_str;
98 }'
99 fi
100
101 # before handing it off to awk, make a few adjustments:
102 # (1) insert spaces around {, }, (, ), *, and commas.
103 # (2) get rid of any and all dollar signs (so that rcs id use safe)
104 #
105 # The awk script will deal with blank lines and lines that
106 # start with the comment character (';').
107
108 sed -e '
109 s/\$//g
110 :join
111 /\\$/{a\
112
113 N
114 s/\\\n//
115 b join
116 }
117 2,${
118 /^#/!s/\([{}()*,|]\)/ \1 /g
119 }
120 ' < $2 | $awk "
121 $toupper
122 BEGIN {
123 # Create a NetBSD tag that does not get expanded when checking
124 # this script out of CVS. (This part of the awk script is in a
125 # shell double-quoted string, so the backslashes are eaten by
126 # the shell.)
127 tag = \"\$\" \"NetBSD\" \"\$\"
128
129 # to allow nested #if/#else/#endif sets
130 savedepth = 0
131 # to track already processed syscalls
132
133 sysnames = \"$sysnames\"
134 sysprotos = \"$sysprotos\"
135 sysnumhdr = \"$sysnumhdr\"
136 sysarghdr = \"$sysarghdr\"
137 sysarghdrextra = \"$sysarghdrextra\"
138 rumpcalls = \"$rumpcalls\"
139 rumpcallshdr = \"$rumpcallshdr\"
140 rumpsysent = \"$rumpsysent\"
141 switchname = \"$switchname\"
142 namesname = \"$namesname\"
143 constprefix = \"$constprefix\"
144 registertype = \"$registertype\"
145 sysalign=\"$sysalign\"
146 if (!registertype) {
147 registertype = \"register_t\"
148 }
149 nsysent = \"$nsysent\"
150
151 sysdcl = \"$sysdcl\"
152 syscompat_pref = \"$syscompat_pref\"
153 sysent = \"$sysent\"
154 sysnamesbottom = \"$sysnamesbottom\"
155 sys_nosys = \"$sys_nosys\"
156 maxsysargs = \"$maxsysargs\"
157 infile = \"$2\"
158
159 compatopts = \"$compatopts\"
160 "'
161
162 printf "/* %s */\n\n", tag > sysdcl
163 printf "/*\n * System call switch table.\n *\n" > sysdcl
164 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
165
166 ncompat = split(compatopts,compat)
167 for (i = 1; i <= ncompat; i++) {
168 compat_upper[i] = toupper(compat[i])
169
170 printf "\n#ifdef %s\n", compat_upper[i] > sysent
171 printf "#define %s(func) __CONCAT(%s_,func)\n", compat[i], \
172 compat[i] > sysent
173 printf "#else\n" > sysent
174 printf "#define %s(func) %s\n", compat[i], sys_nosys > sysent
175 printf "#endif\n" > sysent
176 }
177
178 printf "\n#define\ts(type)\tsizeof(type)\n" > sysent
179 printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > sysent
180 printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > sysent
181 printf "struct sysent %s[] = {\n",switchname > sysent
182
183 printf "/* %s */\n\n", tag > sysnames
184 printf "/*\n * System call names.\n *\n" > sysnames
185 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
186
187 printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
188
189 printf "/* %s */\n\n", tag > sysnumhdr
190 printf "/*\n * System call numbers.\n *\n" > sysnumhdr
191 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
192
193 printf "/* %s */\n\n", tag > sysarghdr
194 printf "/*\n * System call argument lists.\n *\n" > sysarghdr
195 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
196
197 printf "/* %s */\n\n", tag > rumpcalls
198 printf "/*\n * System call vector and marshalling for rump.\n *\n" > rumpcalls
199 printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcalls
200
201 printf "/* %s */\n\n", tag > rumpcallshdr
202 printf "/*\n * System call protos in rump namespace.\n *\n" > rumpcallshdr
203 printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcallshdr
204 }
205 NR == 1 {
206 sub(/ $/, "")
207 printf " * created from%s\n */\n\n", $0 > sysdcl
208 printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysdcl
209
210 printf " * created from%s\n */\n\n", $0 > sysnames
211 printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysnames
212
213 printf " * created from%s\n */\n\n", $0 > rumpcalls
214 printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > rumpcalls
215
216 printf "#include <sys/param.h>\n" > rumpcalls
217 printf "#include <sys/fstypes.h>\n" > rumpcalls
218 printf "#include <sys/proc.h>\n" > rumpcalls
219 printf "#include <sys/syscall.h>\n" > rumpcalls
220 printf "#include <sys/syscallargs.h>\n\n" > rumpcalls
221 printf "#ifdef RUMP_CLIENT\n" > rumpcalls
222 printf "#include <errno.h>\n" > rumpcalls
223 printf "#include <rump/rumpclient.h>\n\n" > rumpcalls
224 printf "#define rsys_syscall(num, data, dlen, retval)\t\\\n" > rumpcalls
225 printf " rumpclient_syscall(num, data, dlen, retval)\n" > rumpcalls
226 printf "#define rsys_seterrno(error) errno = error\n" > rumpcalls
227 printf "#define rsys_alias(a,b)\n#else\n" > rumpcalls
228 printf "#include <sys/syscallvar.h>\n\n" > rumpcalls
229 printf "#include <rump/rumpuser.h>\n" > rumpcalls
230 printf "#include \"rump_private.h\"\n\n" > rumpcalls
231 printf "static int\nrsys_syscall" > rumpcalls
232 printf "(int num, void *data, size_t dlen, register_t *retval)" > rumpcalls
233 printf "\n{\n\tstruct sysent *callp = rump_sysent + num;\n" > rumpcalls
234 printf "\tint rv;\n" > rumpcalls
235 printf "\n\tKASSERT(num > 0 && num < SYS_NSYSENT);\n\n" > rumpcalls
236 printf "\trump_schedule();\n" > rumpcalls
237 printf "\trv = sy_call(callp, curlwp, data, retval);\n" > rumpcalls
238 printf "\trump_unschedule();\n\n\treturn rv;\n}\n\n" > rumpcalls
239 printf "#define rsys_seterrno(error) rumpuser_seterrno(error)\n" > rumpcalls
240 printf "#define rsys_alias(a,b) __weak_alias(a,b);\n#endif\n\n" > rumpcalls
241
242 printf "#if\tBYTE_ORDER == BIG_ENDIAN\n" > rumpcalls
243 printf "#define SPARG(p,k)\t((p)->k.be.datum)\n" > rumpcalls
244 printf "#else /* LITTLE_ENDIAN, I hope dearly */\n" > rumpcalls
245 printf "#define SPARG(p,k)\t((p)->k.le.datum)\n" > rumpcalls
246 printf "#endif\n\n" > rumpcalls
247 printf "#ifndef RUMP_CLIENT\n" > rumpcalls
248 printf "int rump_enosys(void);\n" > rumpcalls
249 printf "int\nrump_enosys()\n{\n\n\treturn ENOSYS;\n}\n" > rumpcalls
250 printf "#endif\n" > rumpcalls
251
252 printf "\n#ifndef RUMP_CLIENT\n" > rumpsysent
253 printf "#define\ts(type)\tsizeof(type)\n" > rumpsysent
254 printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > rumpsysent
255 printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > rumpsysent
256 printf "struct sysent rump_sysent[] = {\n" > rumpsysent
257
258 # System call names are included by userland (kdump(1)), so
259 # hide the include files from it.
260 printf "#if defined(_KERNEL_OPT)\n" > sysnames
261
262 printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
263 printf "const char *const %s[] = {\n",namesname > sysnamesbottom
264
265 printf " * created from%s\n */\n\n", $0 > sysnumhdr
266 printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
267 printf "#define _" constprefix "SYSCALL_H_\n\n" > sysnumhdr
268
269 printf " * created from%s\n */\n\n", $0 > sysarghdr
270 printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
271 printf "#define _" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
272
273 printf " * created from%s\n */\n\n", $0 > rumpcallshdr
274 printf "#ifndef _RUMP_RUMP_SYSCALLS_H_\n" > rumpcallshdr
275 printf "#define _RUMP_RUMP_SYSCALLS_H_\n\n" > rumpcallshdr
276 printf "#ifdef _KERNEL\n" > rumpcallshdr
277 printf "#error Interface not supported inside kernel\n" > rumpcallshdr
278 printf "#endif /* _KERNEL */\n\n" > rumpcallshdr
279 printf "#include <sys/types.h>\n" > rumpcallshdr
280 printf "#include <sys/select.h>\n\n" > rumpcallshdr
281 printf "#include <signal.h>\n\n" > rumpcallshdr
282
283 printf "%s", sysarghdrextra > sysarghdr
284 # Write max number of system call arguments to both headers
285 printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
286 > sysnumhdr
287 printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
288 > sysarghdr
289 printf "#undef\tsyscallarg\n" > sysarghdr
290 printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
291 printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
292 printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
293 printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
294 printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
295 > sysarghdr
296 printf "\t\t\tint8_t pad[ /* CONSTCOND */\t\t\t\\\n" > sysarghdr
297 printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
298 registertype > sysarghdr
299 printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
300 printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
301 registertype > sysarghdr
302 printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
303 printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
304 printf "\t}\n" > sysarghdr
305 printf("\n#undef check_syscall_args\n") >sysarghdr
306 printf("#define check_syscall_args(call) /*LINTED*/ \\\n" \
307 "\ttypedef char call##_check_args" \
308 "[sizeof (struct call##_args) \\\n" \
309 "\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
310 constprefix, registertype) >sysarghdr
311 next
312 }
313 NF == 0 || $1 ~ /^;/ {
314 next
315 }
316 $0 ~ /^%%$/ {
317 intable = 1
318 next
319 }
320 $1 ~ /^#[ ]*include/ {
321 print > sysdcl
322 print > sysnames
323 next
324 }
325 $1 ~ /^#/ && !intable {
326 print > sysdcl
327 print > sysnames
328 next
329 }
330 $1 ~ /^#/ && intable {
331 if ($1 ~ /^#[ ]*if/) {
332 savedepth++
333 savesyscall[savedepth] = syscall
334 }
335 if ($1 ~ /^#[ ]*else/) {
336 if (savedepth <= 0) {
337 printf("%s: line %d: unbalanced #else\n", \
338 infile, NR)
339 exit 1
340 }
341 syscall = savesyscall[savedepth]
342 }
343 if ($1 ~ /^#[ ]*endif/) {
344 if (savedepth <= 0) {
345 printf("%s: line %d: unbalanced #endif\n", \
346 infile, NR)
347 exit 1
348 }
349 savedepth--
350 }
351 print > sysent
352 print > sysarghdr
353 print > sysnumhdr
354 print > sysprotos
355 print > sysnamesbottom
356
357 # XXX: technically we do not want to have conditionals in rump,
358 # but it is easier to just let the cpp handle them than try to
359 # figure out what we want here in this script
360 print > rumpsysent
361 next
362 }
363 syscall != $1 {
364 printf "%s: line %d: syscall number out of sync at %d\n", \
365 infile, NR, syscall
366 printf "line is:\n"
367 print
368 exit 1
369 }
370 function parserr(was, wanted) {
371 printf "%s: line %d: unexpected %s (expected <%s>)\n", \
372 infile, NR, was, wanted
373 printf "line is:\n"
374 print
375 exit 1
376 }
377 function parseline() {
378 f=3 # toss number and type
379 if ($2 == "INDIR")
380 sycall_flags="SYCALL_INDIRECT"
381 else
382 sycall_flags="0"
383 if ($NF != "}") {
384 funcalias=$NF
385 end=NF-1
386 } else {
387 funcalias=""
388 end=NF
389 }
390 if ($f == "INDIR") { # allow for "NOARG INDIR"
391 sycall_flags = "SYCALL_INDIRECT | " sycall_flags
392 f++
393 }
394 if ($f == "MODULAR") { # registered at runtime
395 modular = 1
396 f++
397 } else {
398 modular = 0;
399 }
400 if ($f == "RUMP") {
401 rumpable = 1
402 f++
403 } else {
404 rumpable = 0
405 }
406 if ($f ~ /^[a-z0-9_]*$/) { # allow syscall alias
407 funcalias=$f
408 f++
409 }
410 if ($f != "{")
411 parserr($f, "{")
412 f++
413 if ($end != "}")
414 parserr($end, "}")
415 end--
416 if ($end != ";")
417 parserr($end, ";")
418 end--
419 if ($end != ")")
420 parserr($end, ")")
421 end--
422
423 returntype = oldf = "";
424 do {
425 if (returntype != "" && oldf != "*")
426 returntype = returntype" ";
427 returntype = returntype$f;
428 oldf = $f;
429 f++
430 } while ($f != "|" && f < (end-1))
431 if (f == (end - 1)) {
432 parserr($f, "function argument definition (maybe \"|\"?)");
433 }
434 f++
435
436 fprefix=$f
437 f++
438 if ($f != "|") {
439 parserr($f, "function compat delimiter (maybe \"|\"?)");
440 }
441 f++
442
443 fcompat=""
444 if ($f != "|") {
445 fcompat=$f
446 f++
447 }
448
449 if ($f != "|") {
450 parserr($f, "function name delimiter (maybe \"|\"?)");
451 }
452 f++
453 fbase=$f
454
455 # pipe is special in how to returns its values.
456 # So just generate it manually if present.
457 if (rumpable == 1 && fbase == "pipe") {
458 rumpable = 0;
459 rumphaspipe = 1;
460 }
461
462 funcstdname=fprefix "_" fbase
463 if (fcompat != "") {
464 funcname=fprefix "___" fbase "" fcompat
465 wantrename=1
466 } else {
467 funcname=funcstdname
468 wantrename=0
469 }
470 if (returntype == "quad_t" || returntype == "off_t") {
471 if (sycall_flags == "0")
472 sycall_flags = "SYCALL_RET_64";
473 else
474 sycall_flags = "SYCALL_RET_64 | " sycall_flags;
475 }
476
477 if (funcalias == "") {
478 funcalias=funcname
479 sub(/^([^_]+_)*sys_/, "", funcalias)
480 }
481 f++
482
483 if ($f != "(")
484 parserr($f, "(")
485 f++
486
487 argc=0;
488 argalign=0;
489 if (f == end) {
490 if ($f != "void")
491 parserr($f, "argument definition")
492 isvarargs = 0;
493 varargc = 0;
494 argtype[0]="void";
495 return
496 }
497
498 # some system calls (open() and fcntl()) can accept a variable
499 # number of arguments. If syscalls accept a variable number of
500 # arguments, they must still have arguments specified for
501 # the remaining argument "positions," because of the way the
502 # kernel system call argument handling works.
503 #
504 # Indirect system calls, e.g. syscall(), are exceptions to this
505 # rule, since they are handled entirely by machine-dependent code
506 # and do not need argument structures built.
507
508 isvarargs = 0;
509 args64 = 0;
510 while (f <= end) {
511 if ($f == "...") {
512 f++;
513 isvarargs = 1;
514 varargc = argc;
515 continue;
516 }
517 argc++
518 argtype[argc]=""
519 oldf=""
520 while (f < end && $(f+1) != ",") {
521 if (argtype[argc] != "" && oldf != "*")
522 argtype[argc] = argtype[argc]" ";
523 argtype[argc] = argtype[argc]$f;
524 oldf = $f;
525 f++
526 }
527 if (argtype[argc] == "")
528 parserr($f, "argument definition")
529 if (argtype[argc] == "off_t" \
530 || argtype[argc] == "dev_t" \
531 || argtype[argc] == "time_t") {
532 if ((argalign % 2) != 0 && sysalign &&
533 funcname != "sys_posix_fadvise") # XXX for now
534 parserr($f, "a padding argument")
535 } else {
536 argalign++;
537 }
538 if (argtype[argc] == "quad_t" || argtype[argc] == "off_t" \
539 || argtype[argc] == "dev_t" || argtype[argc] == "time_t") {
540 if (sycall_flags == "0")
541 sycall_flags = "SYCALL_ARG"argc-1"_64";
542 else
543 sycall_flags = "SYCALL_ARG"argc-1"_64 | " sycall_flags;
544 args64++;
545 }
546 argname[argc]=$f;
547 f += 2; # skip name, and any comma
548 }
549 if (args64 > 0)
550 sycall_flags = "SYCALL_NARGS64_VAL("args64") | " sycall_flags;
551 # must see another argument after varargs notice.
552 if (isvarargs) {
553 if (argc == varargc)
554 parserr($f, "argument definition")
555 } else
556 varargc = argc;
557 }
558
559 function printproto(wrap) {
560 printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
561 returntype) > sysnumhdr
562 for (i = 1; i <= varargc; i++)
563 printf(" \"%s\"", argtype[i]) > sysnumhdr
564 if (isvarargs)
565 printf(" \"...\"") > sysnumhdr
566 printf(" */\n") > sysnumhdr
567 printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
568 syscall) > sysnumhdr
569
570 # rumpalooza
571 if (!rumpable)
572 return
573
574 if (wantrename)
575 printf("%s rump_%s(", returntype, funcstdname) > rumpcallshdr
576 else
577 printf("%s rump_sys_%s(", returntype, funcalias) > rumpcallshdr
578 for (i = 1; i < varargc; i++)
579 if (argname[i] != "PAD")
580 printf("%s, ", argtype[i]) > rumpcallshdr
581 if (isvarargs)
582 printf("%s, ...)", argtype[varargc]) > rumpcallshdr
583 else
584 printf("%s)", argtype[argc]) > rumpcallshdr
585 if (wantrename)
586 printf(" __RENAME(rump_%s)", funcname) > rumpcallshdr
587 printf(";\n") > rumpcallshdr
588 }
589
590 function printrumpsysent(insysent, compatwrap) {
591 if (!insysent) {
592 eno[0] = "rump_enosys"
593 eno[1] = "sys_nomodule"
594 flags[0] = "SYCALL_NOSYS"
595 flags[1] = "0"
596 printf("\t{ 0, 0, %s,\n\t (sy_call_t *)%s }, \t" \
597 "/* %d = unrumped */\n", \
598 flags[modular], eno[modular], syscall) > rumpsysent
599 return
600 }
601
602 printf("\t{ ") > rumpsysent
603 if (argc == 0) {
604 printf("0, 0, ") > rumpsysent
605 } else {
606 printf("ns(struct sys_%s%s_args), ", compatwrap_, funcalias) > rumpsysent
607 }
608 printf("0,\n\t %s },", wfn) > rumpsysent
609 for (i = 0; i < (33 - length(wfn)) / 8; i++)
610 printf("\t") > rumpsysent
611 printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > rumpsysent
612 }
613
614 function putent(type, compatwrap) {
615 # output syscall declaration for switch table.
616 if (compatwrap == "")
617 compatwrap_ = ""
618 else
619 compatwrap_ = compatwrap "_"
620 if (argc == 0)
621 arg_type = "void";
622 else {
623 arg_type = "struct " compatwrap_ funcname "_args";
624 }
625 proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
626 arg_type " *, register_t *);\n"
627 if (sysmap[proto] != 1) {
628 sysmap[proto] = 1;
629 print proto > sysprotos;
630 }
631
632 # output syscall switch entry
633 printf("\t{ ") > sysent
634 if (argc == 0) {
635 printf("0, 0, ") > sysent
636 } else {
637 printf("ns(struct %s%s_args), ", compatwrap_, funcname) > sysent
638 }
639 if (modular)
640 wfn = "(sy_call_t *)sys_nomodule";
641 else if (compatwrap == "")
642 wfn = "(sy_call_t *)" funcname;
643 else
644 wfn = "(sy_call_t *)" compatwrap "(" funcname ")";
645 printf("%s,\n\t %s },", sycall_flags, wfn) > sysent
646 for (i = 0; i < (33 - length(wfn)) / 8; i++)
647 printf("\t") > sysent
648 printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
649
650 # output syscall name for names table
651 printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
652 > sysnamesbottom
653
654 # output syscall number of header, if appropriate
655 if (type == "STD" || type == "NOARGS" || type == "INDIR") {
656 # output a prototype, to be used to generate lint stubs in
657 # libc.
658 printproto("")
659 } else if (type == "COMPAT") {
660 # Just define the syscall number with a comment. These
661 # may be used by compatibility stubs in libc.
662 printproto(compatwrap_)
663 }
664
665 # output syscall argument structure, if it has arguments
666 if (argc != 0) {
667 printf("\nstruct %s%s_args", compatwrap_, funcname) > sysarghdr
668 if (type != "NOARGS") {
669 print " {" >sysarghdr;
670 for (i = 1; i <= argc; i++)
671 printf("\tsyscallarg(%s) %s;\n", argtype[i],
672 argname[i]) > sysarghdr
673 printf "}" >sysarghdr;
674 }
675 printf(";\n") > sysarghdr
676 if (type != "NOARGS" && type != "INDIR") {
677 printf("check_syscall_args(%s%s)\n", compatwrap_,
678 funcname) >sysarghdr
679 }
680 }
681
682 if (!rumpable) {
683 if (funcname == "sys_pipe" && rumphaspipe == 1)
684 insysent = 1
685 else
686 insysent = 0
687 } else {
688 insysent = 1
689 }
690 printrumpsysent(insysent, compatwrap)
691
692 # output rump marshalling code if necessary
693 if (!rumpable) {
694 return
695 }
696
697 # need a local prototype, we export the re-re-named one in .h
698 printf("\n%s rump_sys_%s(", returntype, funcalias) > rumpcalls
699 for (i = 1; i < argc; i++) {
700 if (argname[i] != "PAD")
701 printf("%s, ", argtype[i]) > rumpcalls
702 }
703 printf("%s);", argtype[argc]) > rumpcalls
704
705 printf("\n%s\nrump_sys_%s(", returntype, funcalias) > rumpcalls
706 for (i = 1; i < argc; i++) {
707 if (argname[i] != "PAD")
708 printf("%s %s, ", argtype[i], argname[i]) > rumpcalls
709 }
710 printf("%s %s)\n", argtype[argc], argname[argc]) > rumpcalls
711 printf("{\n\tregister_t rval[2] = {0, 0};\n\tint error = 0;\n") \
712 > rumpcalls
713
714 argarg = "NULL"
715 argsize = 0;
716 if (argc) {
717 argarg = "&callarg"
718 argsize = "sizeof(callarg)"
719 printf("\tstruct %s%s_args callarg;\n\n",compatwrap_,funcname) \
720 > rumpcalls
721 for (i = 1; i <= argc; i++) {
722 if (argname[i] == "PAD") {
723 printf("\tSPARG(&callarg, %s) = 0;\n", \
724 argname[i]) > rumpcalls
725 } else {
726 printf("\tSPARG(&callarg, %s) = %s;\n", \
727 argname[i], argname[i]) > rumpcalls
728 }
729 }
730 printf("\n") > rumpcalls
731 } else {
732 printf("\n") > rumpcalls
733 }
734 printf("\terror = rsys_syscall(%s%s, " \
735 "%s, %s, rval);\n", constprefix, funcalias, \
736 argarg, argsize) > rumpcalls
737 printf("\tif (error) {\n\t\trval[0] = -1;\n") > rumpcalls
738 if (returntype != "void") {
739 printf("\t\trsys_seterrno(error);\n\t}\n") > rumpcalls
740 printf("\treturn rval[0];\n") > rumpcalls
741 } else {
742 printf("\t}\n") > rumpcalls
743 }
744 printf("}\n") > rumpcalls
745 printf("rsys_alias(%s,rump_enosys)\n", funcname) > rumpcalls
746
747 }
748 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" {
749 parseline()
750 putent($2, "")
751 syscall++
752 next
753 }
754 $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
755 if ($2 == "OBSOL")
756 comment="obsolete"
757 else if ($2 == "EXCL")
758 comment="excluded"
759 else if ($2 == "IGNORED")
760 comment="ignored"
761 else
762 comment="unimplemented"
763 for (i = 3; i <= NF; i++)
764 comment=comment " " $i
765
766 if ($2 == "IGNORED")
767 sys_stub = "(sy_call_t *)nullop";
768 else
769 sys_stub = sys_nosys;
770
771 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = %s */\n", \
772 sys_stub, syscall, comment) > sysent
773 printf("\t{ 0, 0, SYCALL_NOSYS,\n\t %s },\t\t/* %d = %s */\n", \
774 "(sy_call_t *)rump_enosys", syscall, comment) > rumpsysent
775 printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
776 > sysnamesbottom
777 if ($2 != "UNIMPL")
778 printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
779 syscall++
780 next
781 }
782 {
783 for (i = 1; i <= ncompat; i++) {
784 if ($2 == compat_upper[i]) {
785 parseline();
786 putent("COMPAT", compat[i])
787 syscall++
788 next
789 }
790 }
791 printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
792 exit 1
793 }
794 END {
795 # output pipe() syscall with its special rval[2] handling
796 if (rumphaspipe) {
797 printf("int rump_sys_pipe(int *);\n") > rumpcallshdr
798 printf("\nint rump_sys_pipe(int *);\n") > rumpcalls
799 printf("int\nrump_sys_pipe(int *fd)\n{\n") > rumpcalls
800 printf("\tregister_t rval[2] = {0, 0};\n") > rumpcalls
801 printf("\tint error = 0;\n") > rumpcalls
802 printf("\n\terror = rsys_syscall(SYS_pipe, ") > rumpcalls
803 printf("NULL, 0, rval);\n") > rumpcalls
804 printf("\tif (error) {\n") > rumpcalls
805 printf("\t\trsys_seterrno(error);\n") > rumpcalls
806 printf("\t} else {\n\t\tfd[0] = rval[0];\n") > rumpcalls
807 printf("\t\tfd[1] = rval[1];\n\t}\n") > rumpcalls
808 printf("\treturn error ? -1 : 0;\n}\n") > rumpcalls
809 }
810
811 maxsyscall = syscall
812 if (nsysent) {
813 if (syscall > nsysent) {
814 printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
815 exit 1
816 }
817 while (syscall < nsysent) {
818 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = filler */\n", \
819 sys_nosys, syscall) > sysent
820 printf("\t{ 0, 0, SYCALL_NOSYS,\n\t %s },\t\t/* %d = filler */\n", \
821 "(sy_call_t *)rump_enosys", syscall) > rumpsysent
822 printf("\t/* %3d */\t\"# filler\",\n", syscall) \
823 > sysnamesbottom
824 syscall++
825 }
826 }
827 printf("};\n") > sysent
828 printf("};\n") > rumpsysent
829 printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent
830 printf("#endif /* RUMP_CLIENT */\n") > rumpsysent
831 printf("};\n") > sysnamesbottom
832 printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
833 if (nsysent)
834 printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
835 } '
836
837 cat $sysprotos >> $sysarghdr
838 echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
839 echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
840 printf "\n#include <rump/rump_syscalls_compat.h>\n" >> $rumpcallshdr
841 printf "\n#endif /* _RUMP_RUMP_SYSCALLS_H_ */\n" >> $rumpcallshdr
842 cat $sysdcl $sysent > $syssw
843 cat $sysnamesbottom >> $sysnames
844 cat $rumpsysent >> $rumpcalls
845
846 #chmod 444 $sysnames $sysnumhdr $syssw
847