Add precautions so that threads won't race to exit1() and get stuck there.
[dragonfly.git] / sys / kern / makesyscalls.sh
blobc8f3bdcc215d16bc87fcf3c8e6ac1de4cb585453
1 #! /bin/sh -
2 # @(#)makesyscalls.sh 8.1 (Berkeley) 6/10/93
3 # $FreeBSD: src/sys/kern/makesyscalls.sh,v 1.39.2.4 2001/10/20 09:01:24 marcel Exp $
4 # $DragonFly: src/sys/kern/makesyscalls.sh,v 1.16 2006/08/06 18:56:44 dillon Exp $
6 set -e
8 # name of compat option:
9 compat=COMPAT_43
10 # name of DragonFly 1.2 compat option
11 compatdf12=COMPAT_DF12
13 # output files:
14 sysnames="syscalls.c"
15 sysproto="../sys/sysproto.h"
16 sysunion="../sys/sysunion.h"
17 sysproto_h=_SYS_SYSPROTO_H_
18 syshdr="../sys/syscall.h"
19 sysmk="../sys/syscall.mk"
20 syssw="init_sysent.c"
21 syshide="../sys/syscall-hide.h"
22 syscallprefix="SYS_"
23 switchname="sysent"
24 namesname="syscallnames"
26 # tmp files:
27 sysdcl="sysent.dcl.$$"
28 syscompat="sysent.compat.$$"
29 syscompatdf12="sysent.compatdf12.$$"
30 syscompatdcl="sysent.compatdcl.$$"
31 syscompatdcldf12="sysent.compatdcldf12.$$"
32 sysent="sysent.switch.$$"
33 sysinc="sysinc.switch.$$"
34 sysarg="sysarg.switch.$$"
35 sysun="sysunion.switch.$$"
37 trap "rm $sysdcl $syscompat $syscompatdf12 $syscompatdcl $syscompatdcldf12 $sysent $sysinc $sysarg $sysun" 0
39 touch $sysdcl $syscompat $syscompatdf12 $syscompatdcl $syscompatdf12 $sysent $sysinc $sysarg $sysun
41 case $# in
42 0) echo "Usage: $0 input-file <config-file>" 1>&2
43 exit 1
45 esac
47 if [ -n "$2" -a -f "$2" ]; then
48 . $2
51 sed -e '
52 s/\$//g
53 :join
54 /\\$/{a\
57 s/\\\n//
58 b join
60 2,${
61 /^#/!s/\([{}()*,]\)/ \1 /g
63 ' < $1 | awk "
64 BEGIN {
65 sysdcl = \"$sysdcl\"
66 sysproto = \"$sysproto\"
67 sysproto_h = \"$sysproto_h\"
68 syscompat = \"$syscompat\"
69 syscompatdf12 = \"$syscompatdf12\"
70 syscompatdcl = \"$syscompatdcl\"
71 syscompatdcldf12 = \"$syscompatdcldf12\"
72 sysent = \"$sysent\"
73 syssw = \"$syssw\"
74 sysinc = \"$sysinc\"
75 sysarg = \"$sysarg\"
76 sysun = \"$sysun\"
77 sysnames = \"$sysnames\"
78 syshdr = \"$syshdr\"
79 sysmk = \"$sysmk\"
80 compat = \"$compat\"
81 compatdf12 = \"$compatdf12\"
82 syshide = \"$syshide\"
83 syscallprefix = \"$syscallprefix\"
84 switchname = \"$switchname\"
85 namesname = \"$namesname\"
86 infile = \"$1\"
89 printf "/*\n * System call switch table.\n *\n" > syssw
90 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syssw
91 printf " * \$\DragonFly\$\n" > syssw
93 printf "/*\n * System call prototypes.\n *\n" > sysarg
94 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarg
95 printf " * \$\DragonFly\$\n" > sysarg
97 printf "\n#ifdef %s\n\n", compat > syscompat
98 printf "\n#ifdef %s\n\n", compatdf12 > syscompatdf12
100 printf "/*\n * System call names.\n *\n" > sysnames
101 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
102 printf " * \$\DragonFly\$\n" > sysnames
104 printf "/*\n * System call numbers.\n *\n" > syshdr
105 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshdr
106 printf " * \$\DragonFly\$\n" > syshdr
107 printf "# DragonFly system call names.\n" > sysmk
108 printf "# DO NOT EDIT-- this file is automatically generated.\n" > sysmk
109 printf "# \$\DragonFly\$\n" > sysmk
110 printf "/*\n * System call hiders.\n *\n" > syshide
111 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshide
112 printf " * \$\DragonFly\$\n" > syshide
114 printf "/*\n * Union of syscall args for messaging.\n *\n" > sysun
115 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysun
116 printf " * \$\DragonFly\$\n" > sysun
117 printf "\n#ifdef _KERNEL\n\n" > sysdcl
118 printf "\n#ifdef _KERNEL\n\n" > syscompatdcl
119 printf "\n#ifdef _KERNEL\n\n" > syscompatdcldf12
121 NR == 1 {
122 gsub("[$]DragonFly: ", "", $0)
123 gsub(" [$]", "", $0)
125 printf " * created from%s\n */\n\n", $0 > syssw
127 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
128 printf "struct sysent %s[] = {\n",switchname > sysent
130 printf " * created from%s\n */\n\n", $0 > sysarg
131 printf "#ifndef %s\n", sysproto_h > sysarg
132 printf "#define\t%s\n\n", sysproto_h > sysarg
133 printf "#include <sys/signal.h>\n\n" > sysarg
134 printf "#include <sys/acl.h>\n\n" > sysarg
135 printf "#include <sys/msgport.h>\n\n" > sysarg
136 printf "#include <sys/sysmsg.h>\n\n" > sysarg
137 printf "#include <sys/syslink.h>\n\n" > sysarg
138 printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) ? \\\n" > sysarg
139 printf "\t\t0 : sizeof(register_t) - sizeof(t))\n\n" > sysarg
141 printf " * created from%s\n */\n\n", $0 > sysnames
142 printf "char *%s[] = {\n", namesname > sysnames
144 printf " * created from%s\n */\n\n", $0 > syshdr
146 printf "# created from%s\nMIASM = ", $0 > sysmk
148 printf " * created from%s\n */\n\n", $0 > syshide
149 printf " * created from%s\n */\n\n", $0 > sysun
150 printf "union sysunion {\n" > sysun
151 printf "#ifdef _KERNEL /* header only applies in kernel */\n" > sysun
152 printf "\tstruct\tlwkt_msg lmsg;\n" > sysun
153 printf "\tstruct\tsysmsg sysmsg;\n" > sysun
154 printf "#endif\n" > sysun
156 next
158 NF == 0 || $1 ~ /^;/ {
159 next
161 $1 ~ /^#[ ]*include/ {
162 print > sysinc
163 next
165 $1 ~ /^#[ ]*if/ {
166 print > sysent
167 print > sysdcl
168 print > sysarg
169 print > syscompat
170 print > syscompatdf12
171 print > sysnames
172 print > syshide
173 print > sysun
174 savesyscall = syscall
175 next
177 $1 ~ /^#[ ]*else/ {
178 print > sysent
179 print > sysdcl
180 print > sysarg
181 print > sysun
182 print > syscompat
183 print > syscompatdf12
184 print > sysnames
185 print > syshide
186 syscall = savesyscall
187 next
189 $1 ~ /^#/ {
190 print > sysent
191 print > sysdcl
192 print > sysarg
193 print > sysun
194 print > syscompat
195 print > syscompatdf12
196 print > sysnames
197 print > syshide
198 next
200 syscall != $1 {
201 printf "%s: line %d: syscall number out of sync at %d\n",
202 infile, NR, syscall
203 printf "line is:\n"
204 print
205 exit 1
207 function align_sysent_comment(column) {
208 printf("\t") > sysent
209 column = column + 8 - column % 8
210 while (column < 56) {
211 printf("\t") > sysent
212 column = column + 8
215 function parserr(was, wanted) {
216 printf "%s: line %d: unexpected %s (expected %s)\n",
217 infile, NR, was, wanted
218 exit 1
220 function parseline() {
221 f=4 # toss number and type
222 argc= 0;
223 argssize = "0"
224 if ($NF != "}") {
225 funcalias=$(NF-2)
226 argalias=$(NF-1)
227 rettype=$NF
228 end=NF-3
229 } else {
230 funcalias=""
231 argalias=""
232 rettype="int"
233 end=NF
235 if ($2 == "NODEF") {
236 funcname=$4
237 argssize = "AS(" $6 ")"
238 return
240 if ($f != "{")
241 parserr($f, "{")
243 if ($end != "}")
244 parserr($end, "}")
245 end--
246 if ($end != ";")
247 parserr($end, ";")
248 end--
249 if ($end != ")")
250 parserr($end, ")")
251 end--
253 f++ #function return type
255 funcname=$f
256 usefuncname=$f
257 if (funcalias == "")
258 funcalias = funcname
259 if (argalias == "") {
260 argalias = funcname "_args"
261 if ($2 == "COMPAT") {
262 argalias = "o" argalias
263 usefuncname = "sys_o" funcname
265 if ($2 == "COMPAT_DF12") {
266 argalias = "dfbsd12_" argalias
267 usefuncname = "sys_dfbsd12_" funcname
272 if ($f != "(")
273 parserr($f, ")")
276 if (f == end) {
277 if ($f != "void")
278 parserr($f, "argument definition")
279 return
282 while (f <= end) {
283 argc++
284 argtype[argc]=""
285 oldf=""
286 while (f < end && $(f+1) != ",") {
287 if (argtype[argc] != "" && oldf != "*")
288 argtype[argc] = argtype[argc]" ";
289 argtype[argc] = argtype[argc]$f;
290 oldf = $f;
293 if (argtype[argc] == "")
294 parserr($f, "argument definition")
295 argname[argc]=$f;
296 f += 2; # skip name, and any comma
298 if (argc != 0)
299 argssize = "AS(" argalias ")"
301 { comment = $4
302 if (NF < 7)
303 for (i = 5; i <= NF; i++)
304 comment = comment " " $i
306 # if the "MPSAFE" keyword is found, note it and shift the line
307 mpsafe = ""
308 $2 == "MPSAFE" {
309 for (i = 2; i <= NF; i++)
310 $i = $(i + 1);
311 NF -= 1;
312 mpsafe = "SYF_MPSAFE | "
314 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "NOPROTO" \
315 || $2 == "NOIMPL" {
316 parseline()
317 if ((!nosys || funcname != "nosys") && \
318 (funcname != "lkmnosys")) {
319 if (argc != 0 && $2 != "NOARGS" && $2 != "NOPROTO") {
320 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
321 printf("struct\t%s {\n", argalias) > sysarg
322 printf("#ifdef _KERNEL\n") > sysarg
323 printf("\tstruct sysmsg sysmsg;\n") > sysarg
324 printf("#endif\n") > sysarg
325 for (i = 1; i <= argc; i++)
326 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
327 argtype[i], argname[i],
328 argname[i], argtype[i]) > sysarg
329 printf("};\n") > sysarg
331 else if ($2 != "NOARGS" && $2 != "NOPROTO" && \
332 $2 != "NODEF") {
333 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
334 printf("struct\t%s {\n", argalias) > sysarg
335 printf("#ifdef _KERNEL\n") > sysarg
336 printf("\tstruct sysmsg sysmsg;\n") > sysarg
337 printf("#endif\n") > sysarg
338 printf("\tregister_t dummy;\n") > sysarg
339 printf("};\n") > sysarg
342 if (($2 != "NOPROTO" && $2 != "NODEF" && \
343 (funcname != "nosys" || !nosys)) || \
344 (funcname == "lkmnosys" && !lkmnosys) || \
345 funcname == "lkmressys") {
346 printf("%s\tsys_%s (struct %s *)",
347 rettype, funcname, argalias) > sysdcl
348 printf(";\n") > sysdcl
350 if (funcname == "nosys")
351 nosys = 1
352 if (funcname == "lkmnosys")
353 lkmnosys = 1
354 printf("\t{ %s%s, (sy_call_t *)", mpsafe, argssize) > sysent
355 column = 8 + 2 + length(mpsafe) + length(argssize) + 15
356 if ($2 != "NOIMPL") {
357 printf("sys_%s },", funcname) > sysent
358 column = column + length(funcname) + 7
359 } else {
360 printf("sys_%s },", "nosys") > sysent
361 column = column + length("nosys") + 7
363 align_sysent_comment(column)
364 printf("/* %d = %s */\n", syscall, funcalias) > sysent
365 printf("\t\"%s\",\t\t\t/* %d = %s */\n",
366 funcalias, syscall, funcalias) > sysnames
367 if ($2 != "NODEF") {
368 printf("#define\t%s%s\t%d\n", syscallprefix,
369 funcalias, syscall) > syshdr
370 printf(" \\\n\t%s.o", funcalias) > sysmk
372 if ($3 != "NOHIDE")
373 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
374 syscall++
375 next
377 $2 == "COMPAT" || $2 == "CPT_NOA" {
378 ncompat++
379 parseline()
380 if (argc != 0 && $2 != "CPT_NOA") {
381 printf("#ifdef %s\n", compat) > sysun
382 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
383 printf("#endif\n") > sysun
384 printf("struct\t%s {\n", argalias) > syscompat
385 printf("#ifdef _KERNEL\n") > syscompat
386 printf("\tstruct sysmsg sysmsg;\n") > syscompat
387 printf("#endif\n") > syscompat
388 for (i = 1; i <= argc; i++)
389 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
390 argtype[i], argname[i],
391 argname[i], argtype[i]) > syscompat
392 printf("};\n") > syscompat
394 else if($2 != "CPT_NOA") {
395 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
396 printf("struct\t%s {\n", argalias) > sysarg
397 printf("#ifdef _KERNEL\n") > sysarg
398 printf("\tstruct sysmsg sysmsg;\n") > sysarg
399 printf("#endif\n") > sysarg
400 printf("\tregister_t dummy;\n") > sysarg
401 printf("};\n") > sysarg
403 printf("%s\tsys_o%s (struct %s *);\n",
404 rettype, funcname, argalias) > syscompatdcl
405 printf("\t{ compat(%s%s,%s) },",
406 mpsafe, argssize, funcname) > sysent
407 align_sysent_comment(8 + 9 + length(mpsafe) + \
408 length(argssize) + 1 + length(funcname) + 4)
409 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
410 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
411 funcalias, syscall, funcalias) > sysnames
412 printf("\t\t\t\t/* %d is old %s */\n",
413 syscall, funcalias) > syshdr
414 if ($3 != "NOHIDE")
415 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
416 syscall++
417 next
419 $2 == "COMPAT_DF12" {
420 ncompatdf12++
421 parseline()
422 if (argc != 0) {
423 printf("#ifdef %s\n", compatdf12) > sysun
424 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
425 printf("#endif\n") > sysun
426 printf("struct\t%s {\n", argalias) > syscompatdf12
427 printf("#ifdef _KERNEL\n") > syscompatdf12
428 printf("\tstruct sysmsg sysmsg;\n") > syscompatdf12
429 printf("#endif\n") > syscompatdf12
430 for (i = 1; i <= argc; i++)
431 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
432 argtype[i], argname[i],
433 argname[i], argtype[i]) > syscompatdf12
434 printf("};\n") > syscompatdf12
436 else {
437 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
438 printf("struct\t%s {\n", argalias) > sysarg
439 printf("#ifdef _KERNEL\n") > sysarg
440 printf("\tstruct sysmsg sysmsg;\n") > sysarg
441 printf("#endif\n") > sysarg
442 printf("\tregister_t dummy;\n") > sysarg
443 printf("};\n") > sysarg
445 printf("%s\tsys_dfbsd12_%s (struct %s *);\n",
446 rettype, funcname, argalias) > syscompatdcldf12
447 printf("\t{ compatdf12(%s%s,%s) },",
448 mpsafe, argssize, funcname) > sysent
449 align_sysent_comment(8 + 9 + length(mpsafe) + \
450 length(argssize) + 1 + length(funcname) + 4)
451 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
452 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
453 funcalias, syscall, funcalias) > sysnames
454 printf("\t\t\t\t/* %d is old %s */\n",
455 syscall, funcalias) > syshdr
456 if ($3 != "NOHIDE")
457 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
458 syscall++
459 next
461 $2 == "LIBCOMPAT" {
462 ncompat++
463 parseline()
464 printf("%s\tsys_o%s();\n", rettype, funcname) > syscompatdcl
465 printf("\t{ compat(%s%s,%s) },",
466 mpsafe, argssize, funcname) > sysent
467 align_sysent_comment(8 + 9 + length(mpsafe) + \
468 length(argssize) + 1 + length(funcname) + 4)
469 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
470 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
471 funcalias, syscall, funcalias) > sysnames
472 printf("#define\t%s%s\t%d\t/* compatibility; still used by libc */\n",
473 syscallprefix, funcalias, syscall) > syshdr
474 printf(" \\\n\t%s.o", funcalias) > sysmk
475 if ($3 != "NOHIDE")
476 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
477 syscall++
478 next
480 $2 == "OBSOL" {
481 printf("\t{ 0, (sy_call_t *)sys_nosys },") > sysent
482 align_sysent_comment(37)
483 printf("/* %d = obsolete %s */\n", syscall, comment) > sysent
484 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
485 $4, syscall, comment) > sysnames
486 printf("\t\t\t\t/* %d is obsolete %s */\n",
487 syscall, comment) > syshdr
488 if ($3 != "NOHIDE")
489 printf("HIDE_%s(%s)\n", $3, $4) > syshide
490 syscall++
491 next
493 $2 == "UNIMPL" {
494 printf("\t{ 0, (sy_call_t *)sys_nosys },\t\t\t/* %d = %s */\n",
495 syscall, comment) > sysent
496 printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
497 syscall, syscall, comment) > sysnames
498 if ($3 != "NOHIDE")
499 printf("HIDE_%s(%s)\n", $3, $4) > syshide
500 syscall++
501 next
504 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
505 exit 1
507 END {
508 printf "\n#define AS(name) ((sizeof(struct name) - sizeof(struct sysmsg)) / sizeof(register_t))\n" > sysinc
509 if (ncompat != 0) {
510 printf "#include \"opt_compat.h\"\n\n" > syssw
511 printf "\n#ifdef %s\n", compat > sysinc
512 printf "#define compat(n, name) n, (sy_call_t *)__CONCAT(sys_,__CONCAT(o,name))\n" > sysinc
513 printf "#else\n" > sysinc
514 printf "#define compat(n, name) 0, (sy_call_t *)sys_nosys\n" > sysinc
515 printf "#endif\n" > sysinc
518 if (ncompatdf12 != 0) {
519 printf "#include \"opt_compatdf12.h\"\n\n" > syssw
520 printf "\n#ifdef %s\n", compatdf12 > sysinc
521 printf "#define compatdf12(n, name) n, (sy_call_t *)__CONCAT(sys_,__CONCAT(dfbsd12_,name))\n" > sysinc
522 printf "#else\n" > sysinc
523 printf "#define compatdf12(n, name) 0, (sy_call_t *)sys_nosys\n" > sysinc
524 printf "#endif\n" > sysinc
527 printf("\n#endif /* _KERNEL */\n") > syscompatdcl
528 printf("\n#endif /* _KERNEL */\n") > syscompatdcldf12
529 printf("\n#endif /* %s */\n\n", compat) > syscompatdcl
530 printf("\n#endif /* %s */\n\n", compatdf12) > syscompatdcldf12
532 printf("\n") > sysmk
533 printf("};\n") > sysent
534 printf("};\n") > sysnames
535 printf("};\n") > sysun
536 printf("\n#endif /* !%s */\n", sysproto_h) > sysdcl
537 printf("#undef PAD_\n") > sysdcl
538 printf("\n#endif /* _KERNEL */\n") > sysdcl
539 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
540 > syshdr
543 cat $sysinc $sysent >> $syssw
544 cat $sysarg $syscompat $syscompatdcl $syscompatdf12 $syscompatdcldf12 $sysdcl > $sysproto
545 cat $sysun > $sysunion