2 # @(#)makesyscalls.sh 8.1 (Berkeley) 6/10/93
7 # name of compat options:
9 compat4
=COMPAT_FREEBSD4
10 compat6
=COMPAT_FREEBSD6
14 sysproto
="../sys/sysproto.h"
15 sysproto_h
=_SYS_SYSPROTO_H_
16 syshdr
="../sys/syscall.h"
17 sysmk
="../sys/syscall.mk"
21 namesname
="syscallnames"
22 systrace
="systrace_args.c"
25 sysaue
="sysent.aue.$$"
26 sysdcl
="sysent.dcl.$$"
27 syscompat
="sysent.compat.$$"
28 syscompatdcl
="sysent.compatdcl.$$"
29 syscompat4
="sysent.compat4.$$"
30 syscompat4dcl
="sysent.compat4dcl.$$"
31 syscompat6
="sysent.compat6.$$"
32 syscompat6dcl
="sysent.compat6dcl.$$"
33 sysent
="sysent.switch.$$"
34 sysinc
="sysinc.switch.$$"
35 sysarg
="sysarg.switch.$$"
36 sysprotoend
="sysprotoend.$$"
37 systracetmp
="systrace.$$"
39 trap "rm $sysaue $sysdcl $syscompat $syscompatdcl $syscompat4 $syscompat4dcl $syscompat6 $syscompat6dcl $sysent $sysinc $sysarg $sysprotoend $systracetmp" 0
41 touch $sysaue $sysdcl $syscompat $syscompatdcl $syscompat4 $syscompat4dcl $syscompat6 $syscompat6dcl $sysent $sysinc $sysarg $sysprotoend $systracetmp
44 0) echo "usage: $0 input-file <config-file>" 1>&2
49 if [ -n "$2" -a -f "$2" ]; then
63 /^#/!s/\([{}()*,]\)/ \1 /g
69 sysproto = \"$sysproto\"
70 sysprotoend = \"$sysprotoend\"
71 sysproto_h = \"$sysproto_h\"
72 syscompat = \"$syscompat\"
73 syscompatdcl = \"$syscompatdcl\"
74 syscompat4 = \"$syscompat4\"
75 syscompat4dcl = \"$syscompat4dcl\"
76 syscompat6 = \"$syscompat6\"
77 syscompat6dcl = \"$syscompat6dcl\"
82 sysnames = \"$sysnames\"
85 systrace = \"$systrace\"
86 systracetmp = \"$systracetmp\"
88 compat4 = \"$compat4\"
89 compat6 = \"$compat6\"
90 syscallprefix = \"$syscallprefix\"
91 switchname = \"$switchname\"
92 namesname = \"$namesname\"
96 printf "/*\n * System call switch table.\n *\n" > syssw
97 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syssw
98 printf " * $%s$\n", "FreeBSD" > syssw
100 printf "/*\n * System call prototypes.\n *\n" > sysarg
101 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarg
102 printf " * $%s$\n", "FreeBSD" > sysarg
104 printf "\n#ifdef %s\n\n", compat > syscompat
105 printf "\n#ifdef %s\n\n", compat4 > syscompat4
106 printf "\n#ifdef %s\n\n", compat6 > syscompat6
108 printf "/*\n * System call names.\n *\n" > sysnames
109 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
110 printf " * $%s$\n", "FreeBSD" > sysnames
112 printf "/*\n * System call numbers.\n *\n" > syshdr
113 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshdr
114 printf " * $%s$\n", "FreeBSD" > syshdr
115 printf "# FreeBSD system call names.\n" > sysmk
116 printf "# DO NOT EDIT-- this file is automatically generated.\n" > sysmk
117 printf "# $%s$\n", "FreeBSD" > sysmk
119 printf "/*\n * System call argument to DTrace register array converstion.\n *\n" > systrace
120 printf " * DO NOT EDIT-- this file is automatically generated.\n" > systrace
121 printf " * $%s$\n", "FreeBSD" > systrace
124 gsub("[$]FreeBSD: ", "", $0)
127 printf " * created from%s\n */\n\n", $0 > syssw
129 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
130 printf "struct sysent %s[] = {\n",switchname > sysent
132 printf " * created from%s\n */\n\n", $0 > sysarg
133 printf "#ifndef %s\n", sysproto_h > sysarg
134 printf "#define\t%s\n\n", sysproto_h > sysarg
135 printf "#include <sys/signal.h>\n" > sysarg
136 printf "#include <sys/acl.h>\n" > sysarg
137 printf "#include <sys/cpuset.h>\n" > sysarg
138 printf "#include <sys/_semaphore.h>\n" > sysarg
139 printf "#include <sys/ucontext.h>\n\n" > sysarg
140 printf "#include <bsm/audit_kevents.h>\n\n" > sysarg
141 printf "struct proc;\n\n" > sysarg
142 printf "struct thread;\n\n" > sysarg
143 printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) ? \\\n" > sysarg
144 printf "\t\t0 : sizeof(register_t) - sizeof(t))\n\n" > sysarg
145 printf "#if BYTE_ORDER == LITTLE_ENDIAN\n"> sysarg
146 printf "#define\tPADL_(t)\t0\n" > sysarg
147 printf "#define\tPADR_(t)\tPAD_(t)\n" > sysarg
148 printf "#else\n" > sysarg
149 printf "#define\tPADL_(t)\tPAD_(t)\n" > sysarg
150 printf "#define\tPADR_(t)\t0\n" > sysarg
151 printf "#endif\n\n" > sysarg
153 printf " * created from%s\n */\n\n", $0 > sysnames
154 printf "const char *%s[] = {\n", namesname > sysnames
156 printf " * created from%s\n */\n\n", $0 > syshdr
158 printf "# created from%s\nMIASM = ", $0 > sysmk
160 printf " * This file is part of the DTrace syscall provider.\n */\n\n" > systrace
161 printf "static void\nsystrace_args(int sysnum, void *params, u_int64_t *uarg, int *n_args)\n{\n" > systrace
162 printf "\tint64_t *iarg = (int64_t *) uarg;\n" > systrace
163 printf "\tswitch (sysnum) {\n" > systrace
165 printf "static void\nsystrace_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)\n{\n\tconst char *p = NULL;\n" > systracetmp
166 printf "\tswitch (sysnum) {\n" > systracetmp
170 NF == 0 || $1 ~ /^;/ {
173 $1 ~ /^#[ ]*include/ {
185 savesyscall = syscall
196 syscall = savesyscall
210 printf "%s: line %d: syscall number out of sync at %d\n",
216 function align_sysent_comment(column) {
217 printf("\t") > sysent
218 column = column + 8 - column % 8
219 while (column < 56) {
220 printf("\t") > sysent
224 function parserr(was, wanted) {
225 printf "%s: line %d: unexpected %s (expected %s)\n",
226 infile, NR, was, wanted
229 function parseline() {
230 f=4 # toss number, type, audit event
247 argssize = "AS(" $6 ")"
263 f++ #function return type
268 if (argalias == "") {
269 argalias = funcname "_args"
271 argalias = "o" argalias
273 argalias = "freebsd4_" argalias
275 argalias = "freebsd6_" argalias
285 parserr($f, "argument definition")
293 while (f < end && $(f+1) != ",") {
294 if (argtype[argc] != "" && oldf != "*")
295 argtype[argc] = argtype[argc]" ";
296 argtype[argc] = argtype[argc]$f;
300 if (argtype[argc] == "")
301 parserr($f, "argument definition")
303 f += 2; # skip name, and any comma
306 argssize = "AS(" argalias ")"
310 for (i = 5; i <= NF; i++)
311 comment = comment " " $i
315 # The AUE_ audit event identifier.
321 $3 == "STD" || $3 == "NODEF" || $3 == "NOARGS" || $3 == "NOPROTO" \
322 || $3 == "NOIMPL" || $3 == "NOSTD" {
324 printf("\t/* %s */\n\tcase %d: {\n", funcname, syscall) > systrace
325 printf("\t/* %s */\n\tcase %d:\n", funcname, syscall) > systracetmp
327 printf("\t\tswitch(ndx) {\n") > systracetmp
328 printf("\t\tstruct %s *p = params;\n", argalias) > systrace
329 for (i = 1; i <= argc; i++) {
330 printf("\t\tcase %d:\n\t\t\tp = \"%s\";\n\t\t\tbreak;\n", i - 1, argtype[i]) > systracetmp
331 if (index(argtype[i], "*") > 0 || argtype[i] == "caddr_t")
332 printf("\t\tuarg[%d] = (intptr_t) p->%s; /* %s */\n", \
334 argname[i], argtype[i]) > systrace
335 else if (substr(argtype[i], 1, 1) == "u" || argtype[i] == "size_t")
336 printf("\t\tuarg[%d] = p->%s; /* %s */\n", \
338 argname[i], argtype[i]) > systrace
340 printf("\t\tiarg[%d] = p->%s; /* %s */\n", \
342 argname[i], argtype[i]) > systrace
344 printf("\t\tdefault:\n\t\t\tbreak;\n\t\t};\n") > systracetmp
346 printf("\t\t*n_args = %d;\n\t\tbreak;\n\t}\n", argc) > systrace
347 printf("\t\tbreak;\n") > systracetmp
348 if ((!nosys || funcname != "nosys") && \
349 (funcname != "lkmnosys") && (funcname != "lkmressys")) {
350 if (argc != 0 && $3 != "NOARGS" && $3 != "NOPROTO") {
351 printf("struct %s {\n", argalias) > sysarg
352 for (i = 1; i <= argc; i++)
353 printf("\tchar %s_l_[PADL_(%s)]; " \
354 "%s %s; char %s_r_[PADR_(%s)];\n",
355 argname[i], argtype[i],
356 argtype[i], argname[i],
357 argname[i], argtype[i]) > sysarg
358 printf("};\n") > sysarg
360 else if ($3 != "NOARGS" && $3 != "NOPROTO" && \
362 printf("struct %s {\n\tregister_t dummy;\n};\n",
365 if (($3 != "NOPROTO" && $3 != "NODEF" && \
366 (funcname != "nosys" || !nosys)) || \
367 (funcname == "lkmnosys" && !lkmnosys) || \
368 funcname == "lkmressys") {
369 printf("%s\t%s(struct thread *, struct %s *)",
370 rettype, funcname, argalias) > sysdcl
371 printf(";\n") > sysdcl
372 printf("#define\t%sAUE_%s\t%s\n", syscallprefix,
373 funcalias, auditev) > sysaue
375 if (funcname == "nosys")
377 if (funcname == "lkmnosys")
379 printf("\t{ %s, (sy_call_t *)", argssize) > sysent
380 column = 8 + 2 + length(argssize) + 15
381 if ($3 == "NOIMPL") {
382 printf("%s },", "nosys, AUE_NULL, NULL, 0, 0") > sysent
383 column = column + length("nosys") + 3
384 } else if ($3 == "NOSTD") {
385 printf("%s },", "lkmressys, AUE_NULL, NULL, 0, 0") > sysent
386 column = column + length("lkmressys") + 3
388 printf("%s, %s, NULL, 0, 0 },", funcname, auditev) > sysent
389 column = column + length(funcname) + length(auditev) + 3
391 align_sysent_comment(column)
392 printf("/* %d = %s */\n", syscall, funcalias) > sysent
393 printf("\t\"%s\",\t\t\t/* %d = %s */\n",
394 funcalias, syscall, funcalias) > sysnames
396 printf("#define\t%s%s\t%d\n", syscallprefix,
397 funcalias, syscall) > syshdr
398 printf(" \\\n\t%s.o", funcalias) > sysmk
403 $3 == "COMPAT" || $3 == "COMPAT4" || $3 == "COMPAT6" || $3 == "CPT_NOA" {
404 if ($3 == "COMPAT" || $3 == "CPT_NOA") {
407 outdcl = syscompatdcl
410 } else if ($3 == "COMPAT4") {
413 outdcl = syscompat4dcl
416 } else if ($3 == "COMPAT6") {
419 outdcl = syscompat6dcl
424 if (argc != 0 && $3 != "CPT_NOA") {
425 printf("struct %s {\n", argalias) > out
426 for (i = 1; i <= argc; i++)
427 printf("\tchar %s_l_[PADL_(%s)]; %s %s; " \
428 "char %s_r_[PADR_(%s)];\n",
429 argname[i], argtype[i],
430 argtype[i], argname[i],
431 argname[i], argtype[i]) > out
434 else if($3 != "CPT_NOA")
435 printf("struct %s {\n\tregister_t dummy;\n};\n",
437 printf("%s\t%s%s(struct thread *, struct %s *);\n",
438 rettype, prefix, funcname, argalias) > outdcl
439 printf("\t{ %s(%s,%s), %s, NULL, 0, 0 },",
440 wrap, argssize, funcname, auditev) > sysent
441 align_sysent_comment(8 + 9 + \
442 length(argssize) + 1 + length(funcname) + length(auditev) + 4)
443 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
444 printf("\t\"%s.%s\",\t\t/* %d = old %s */\n",
445 wrap, funcalias, syscall, funcalias) > sysnames
446 if ($3 == "COMPAT" || $3 == "CPT_NOA") {
447 printf("\t\t\t\t/* %d is old %s */\n",
448 syscall, funcalias) > syshdr
450 printf("#define\t%s%s%s\t%d\n", syscallprefix,
451 prefix, funcalias, syscall) > syshdr
452 printf(" \\\n\t%s%s.o", prefix, funcalias) > sysmk
460 printf("%s\to%s();\n", rettype, funcname) > syscompatdcl
461 printf("\t{ compat(%s,%s), %s, NULL, 0, 0 },",
462 argssize, funcname, auditev) > sysent
463 align_sysent_comment(8 + 9 + \
464 length(argssize) + 1 + length(funcname) + length(auditev) + 4)
465 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
466 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
467 funcalias, syscall, funcalias) > sysnames
468 printf("#define\t%s%s\t%d\t/* compatibility; still used by libc */\n",
469 syscallprefix, funcalias, syscall) > syshdr
470 printf(" \\\n\t%s.o", funcalias) > sysmk
475 printf("\t{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0 },") > sysent
476 align_sysent_comment(34)
477 printf("/* %d = obsolete %s */\n", syscall, comment) > sysent
478 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
479 $4, syscall, comment) > sysnames
480 printf("\t\t\t\t/* %d is obsolete %s */\n",
481 syscall, comment) > syshdr
486 printf("\t{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0 },\t\t\t/* %d = %s */\n",
487 syscall, comment) > sysent
488 printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
489 syscall, syscall, comment) > sysnames
494 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $3
498 printf "\n#define AS(name) (sizeof(struct name) / sizeof(register_t))\n" > sysinc
500 if (ncompat != 0 || ncompat4 != 0 || ncompat6 != 0)
501 printf "#include \"opt_compat.h\"\n\n" > syssw
504 printf "\n#ifdef %s\n", compat > sysinc
505 printf "#define compat(n, name) n, (sy_call_t *)__CONCAT(o,name)\n" > sysinc
506 printf "#else\n" > sysinc
507 printf "#define compat(n, name) 0, (sy_call_t *)nosys\n" > sysinc
508 printf "#endif\n" > sysinc
512 printf "\n#ifdef %s\n", compat4 > sysinc
513 printf "#define compat4(n, name) n, (sy_call_t *)__CONCAT(freebsd4_,name)\n" > sysinc
514 printf "#else\n" > sysinc
515 printf "#define compat4(n, name) 0, (sy_call_t *)nosys\n" > sysinc
516 printf "#endif\n" > sysinc
520 printf "\n#ifdef %s\n", compat6 > sysinc
521 printf "#define compat6(n, name) n, (sy_call_t *)__CONCAT(freebsd6_,name)\n" > sysinc
522 printf "#else\n" > sysinc
523 printf "#define compat6(n, name) 0, (sy_call_t *)nosys\n" > sysinc
524 printf "#endif\n" > sysinc
527 printf("\n#endif /* %s */\n\n", compat) > syscompatdcl
528 printf("\n#endif /* %s */\n\n", compat4) > syscompat4dcl
529 printf("\n#endif /* %s */\n\n", compat6) > syscompat6dcl
531 printf("\n#undef PAD_\n") > sysprotoend
532 printf("#undef PADL_\n") > sysprotoend
533 printf("#undef PADR_\n") > sysprotoend
534 printf("\n#endif /* !%s */\n", sysproto_h) > sysprotoend
537 printf("};\n") > sysent
538 printf("};\n") > sysnames
539 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
541 printf "\tdefault:\n\t\t*n_args = 0;\n\t\tbreak;\n\t};\n}\n" > systrace
542 printf "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n" > systracetmp
545 cat $sysinc $sysent >> $syssw
546 cat $sysarg $sysdcl \
547 $syscompat $syscompatdcl \
548 $syscompat4 $syscompat4dcl \
549 $syscompat6 $syscompat6dcl \
550 $sysaue $sysprotoend > $sysproto
551 cat $systracetmp >> $systrace