]> git.saurik.com Git - apple/xnu.git/blob - bsd/kern/makesyscalls.sh
xnu-3789.70.16.tar.gz
[apple/xnu.git] / bsd / kern / makesyscalls.sh
1 #! /bin/sh -
2 # @(#)makesyscalls.sh 8.1 (Berkeley) 6/10/93
3 # $FreeBSD: src/sys/kern/makesyscalls.sh,v 1.60 2003/04/01 01:12:24 jeff Exp $
4 #
5 # Copyright (c) 2004-2008 Apple Inc. All rights reserved.
6 #
7 # @APPLE_OSREFERENCE_LICENSE_HEADER_START@
8 #
9 # This file contains Original Code and/or Modifications of Original Code
10 # as defined in and that are subject to the Apple Public Source License
11 # Version 2.0 (the 'License'). You may not use this file except in
12 # compliance with the License. Please obtain a copy of the License at
13 # http://www.opensource.apple.com/apsl/ and read it before using this
14 # file.
15 #
16 # The Original Code and all software distributed under the License are
17 # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
18 # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
19 # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
20 # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
21 # Please see the License for the specific language governing rights and
22 # limitations under the License.
23 #
24 # @APPLE_OSREFERENCE_LICENSE_HEADER_END@
25 #
26
27 set -e
28
29 input_file="" # first argument
30
31 # output type:
32 output_syscallnamesfile=0
33 output_sysprotofile=0
34 output_syshdrfile=0
35 output_syscalltablefile=0
36 output_auditevfile=0
37 output_tracecodes=0
38
39 use_stdout=0
40
41 # output files:
42 syscallnamesfile="syscalls.c"
43 sysprotofile="sysproto.h"
44 sysproto_h=_SYS_SYSPROTO_H_
45 syshdrfile="syscall.h"
46 syscall_h=_SYS_SYSCALL_H_
47 syscalltablefile="init_sysent.c"
48 auditevfile="audit_kevents.c"
49 syscallprefix="SYS_"
50 switchname="sysent"
51 namesname="syscallnames"
52 tracecodename="syscall.codes"
53
54 # tmp files:
55 syslegal="sysent.syslegal.$$"
56 sysent="sysent.switch.$$"
57 sysinc="sysinc.switch.$$"
58 sysarg="sysarg.switch.$$"
59 sysprotoend="sysprotoend.$$"
60 syscallnamestempfile="syscallnamesfile.$$"
61 syshdrtempfile="syshdrtempfile.$$"
62 audittempfile="audittempfile.$$"
63 tracecodetempfile="tracecodetempfile.$$"
64
65 trap "rm $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile $audittempfile $tracecodetempfile" 0
66
67 touch $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile $audittempfile $tracecodetempfile
68
69 case $# in
70 0)
71 echo "usage: $0 input-file [<names|proto|header|table|audit|trace> [<config-file>]]" 1>&2
72 exit 1
73 ;;
74 esac
75
76 input_file="$1"
77 shift
78
79 if [ -n "$1" ]; then
80 case $1 in
81 names)
82 output_syscallnamesfile=1
83 ;;
84 proto)
85 output_sysprotofile=1
86 ;;
87 header)
88 output_syshdrfile=1
89 ;;
90 table)
91 output_syscalltablefile=1
92 ;;
93 audit)
94 output_auditevfile=1
95 ;;
96 trace)
97 output_tracecodes=1
98 use_stdout=1
99 ;;
100 esac
101 shift;
102 else
103 output_syscallnamesfile=1
104 output_sysprotofile=1
105 output_syshdrfile=1
106 output_syscalltablefile=1
107 output_auditevfile=1
108 output_tracecodes=1
109 fi
110
111 if [ -n "$1" -a -f "$1" ]; then
112 . $1
113 fi
114
115
116
117 sed -e '
118 s/\$//g
119 :join
120 /\\$/{a\
121
122 N
123 s/\\\n//
124 b join
125 }
126 2,${
127 /^#/!s/\([{}()*,;]\)/ \1 /g
128 }
129 ' < "$input_file" | awk "
130 BEGIN {
131 syslegal = \"$syslegal\"
132 sysprotofile = \"$sysprotofile\"
133 sysprotoend = \"$sysprotoend\"
134 sysproto_h = \"$sysproto_h\"
135 syscall_h = \"$syscall_h\"
136 sysent = \"$sysent\"
137 syscalltablefile = \"$syscalltablefile\"
138 sysinc = \"$sysinc\"
139 sysarg = \"$sysarg\"
140 syscallnamesfile = \"$syscallnamesfile\"
141 syscallnamestempfile = \"$syscallnamestempfile\"
142 syshdrfile = \"$syshdrfile\"
143 syshdrtempfile = \"$syshdrtempfile\"
144 audittempfile = \"$audittempfile\"
145 tracecodetempfile = \"$tracecodetempfile\"
146 syscallprefix = \"$syscallprefix\"
147 switchname = \"$switchname\"
148 namesname = \"$namesname\"
149 infile = \"$input_file\"
150 "'
151
152 printf "/*\n" > syslegal
153 printf " * Copyright (c) 2004-2008 Apple Inc. All rights reserved.\n" > syslegal
154 printf " * \n" > syslegal
155 printf " * @APPLE_OSREFERENCE_LICENSE_HEADER_START@\n" > syslegal
156 printf " * \n" > syslegal
157 printf " * This file contains Original Code and/or Modifications of Original Code\n" > syslegal
158 printf " * as defined in and that are subject to the Apple Public Source License\n" > syslegal
159 printf " * Version 2.0 (the \047License\047). You may not use this file except in\n" > syslegal
160 printf " * compliance with the License. The rights granted to you under the License\n" > syslegal
161 printf " * may not be used to create, or enable the creation or redistribution of,\n" > syslegal
162 printf " * unlawful or unlicensed copies of an Apple operating system, or to\n" > syslegal
163 printf " * circumvent, violate, or enable the circumvention or violation of, any\n" > syslegal
164 printf " * terms of an Apple operating system software license agreement.\n" > syslegal
165 printf " * \n" > syslegal
166 printf " * Please obtain a copy of the License at\n" > syslegal
167 printf " * http://www.opensource.apple.com/apsl/ and read it before using this file.\n" > syslegal
168 printf " * \n" > syslegal
169 printf " * The Original Code and all software distributed under the License are\n" > syslegal
170 printf " * distributed on an \047AS IS\047 basis, WITHOUT WARRANTY OF ANY KIND, EITHER\n" > syslegal
171 printf " * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,\n" > syslegal
172 printf " * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,\n" > syslegal
173 printf " * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.\n" > syslegal
174 printf " * Please see the License for the specific language governing rights and\n" > syslegal
175 printf " * limitations under the License.\n" > syslegal
176 printf " * \n" > syslegal
177 printf " * @APPLE_OSREFERENCE_LICENSE_HEADER_END@\n" > syslegal
178 printf " * \n" > syslegal
179 printf " * \n" > syslegal
180 printf " * System call switch table.\n *\n" > syslegal
181 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syslegal
182 printf " * created from %s\n */\n\n", infile > syslegal
183 }
184 NR == 1 {
185 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
186 printf "__private_extern__ const struct sysent %s[] = {\n",switchname > sysent
187
188 printf "#ifndef %s\n", sysproto_h > sysarg
189 printf "#define\t%s\n\n", sysproto_h > sysarg
190 printf "#ifndef %s\n", syscall_h > syshdrtempfile
191 printf "#define\t%s\n\n", syscall_h > syshdrtempfile
192 printf "#include <sys/appleapiopts.h>\n" > syshdrtempfile
193 printf "#ifdef __APPLE_API_PRIVATE\n" > syshdrtempfile
194 printf "#include <sys/appleapiopts.h>\n" > sysarg
195 printf "#include <sys/cdefs.h>\n" > sysarg
196 printf "#include <sys/mount_internal.h>\n" > sysarg
197 printf "#include <sys/types.h>\n" > sysarg
198 printf "#include <sys/sem_internal.h>\n" > sysarg
199 printf "#include <sys/semaphore.h>\n" > sysarg
200 printf "#include <sys/wait.h>\n" > sysarg
201 printf "#include <mach/shared_region.h>\n" > sysarg
202 printf "\n#ifdef KERNEL\n" > sysarg
203 printf "#ifdef __APPLE_API_PRIVATE\n" > sysarg
204 printf "/*\n" > sysarg
205 printf " * The kernel may support multiple userspace ABIs, and must use\n" > sysarg
206 printf " * argument structures with elements large enough for any of them.\n" > sysarg
207 printf "*/\n" > sysarg
208 printf "\n" > sysarg
209 printf "#if CONFIG_REQUIRES_U32_MUNGING\n" > sysarg
210 printf "#define\tPAD_(t)\t(sizeof(uint64_t) <= sizeof(t) \\\n " > sysarg
211 printf "\t\t? 0 : sizeof(uint64_t) - sizeof(t))\n" > sysarg
212 printf "#else\n" > sysarg
213 printf "#define\tPAD_(t)\t(sizeof(uint32_t) <= sizeof(t) \\\n" > sysarg
214 printf " ? 0 : sizeof(uint32_t) - sizeof(t))\n" > sysarg
215 printf "#endif\n" > sysarg
216 printf "#if BYTE_ORDER == LITTLE_ENDIAN\n"> sysarg
217 printf "#define\tPADL_(t)\t0\n" > sysarg
218 printf "#define\tPADR_(t)\tPAD_(t)\n" > sysarg
219 printf "#else\n" > sysarg
220 printf "#define\tPADL_(t)\tPAD_(t)\n" > sysarg
221 printf "#define\tPADR_(t)\t0\n" > sysarg
222 printf "#endif\n" > sysarg
223 printf "\n__BEGIN_DECLS\n" > sysarg
224 printf "#include <sys/munge.h>\n" > sysarg
225
226 printf "\n" > sysarg
227
228 printf "const char *%s[] = {\n", namesname > syscallnamestempfile
229
230 printf "#include <sys/param.h>\n" > audittempfile
231 printf "#include <sys/types.h>\n\n" > audittempfile
232 printf "#include <bsm/audit.h>\n" > audittempfile
233 printf "#include <bsm/audit_kevents.h>\n\n" > audittempfile
234 printf "#if CONFIG_AUDIT\n\n" > audittempfile
235 printf "au_event_t sys_au_event[] = {\n" > audittempfile
236 next
237 }
238 NF == 0 || $1 ~ /^;/ {
239 next
240 }
241 $1 ~ /^#[ ]*include/ {
242 print > sysinc
243 next
244 }
245 $1 ~ /^#[ ]*if/ {
246 print > sysent
247 print > sysarg
248 print > syscallnamestempfile
249 print > sysprotoend
250 print > audittempfile
251 savesyscall = syscall_num
252 skip_for_header = 0
253 next
254 }
255 $1 ~ /^#[ ]*else/ {
256 print > sysent
257 print > sysarg
258 print > syscallnamestempfile
259 print > sysprotoend
260 print > audittempfile
261 syscall_num = savesyscall
262 skip_for_header = 1
263 next
264 }
265 $1 ~ /^#/ {
266 print > sysent
267 print > sysarg
268 print > syscallnamestempfile
269 print > sysprotoend
270 print > audittempfile
271 skip_for_header = 0
272 next
273 }
274 syscall_num != $1 {
275 printf "%s: line %d: syscall number out of sync at %d\n",
276 infile, NR, syscall_num
277 printf "line is:\n"
278 print
279 exit 1
280 }
281 function align_comment(linesize, location, thefile) {
282 printf(" ") > thefile
283 while (linesize < location) {
284 printf(" ") > thefile
285 linesize++
286 }
287 }
288 function parserr(was, wanted) {
289 printf "%s: line %d: unexpected %s (expected %s)\n",
290 infile, NR, was, wanted
291 exit 1
292 }
293
294 function parseline() {
295 funcname = ""
296 current_field = 4 # skip number, audit event, type
297 args_start = 0
298 args_end = 0
299 comments_start = 0
300 comments_end = 0
301 argc = 0
302 argssize = "0"
303 additional_comments = " "
304 obs_comments = "_"
305
306 # find start and end of call name and arguments
307 if ($current_field != "{")
308 parserr($current_field, "{")
309 args_start = current_field
310 current_field++
311 while (current_field <= NF) {
312 if ($current_field == "}") {
313 args_end = current_field
314 break
315 }
316 current_field++
317 }
318 if (args_end == 0) {
319 printf "%s: line %d: invalid call name and arguments\n",
320 infile, NR
321 exit 1
322 }
323
324 # find start and end of optional comments
325 current_field++
326 if (current_field < NF && $current_field == "{") {
327 comments_start = current_field
328 while (current_field <= NF) {
329 if ($current_field == "}") {
330 comments_end = current_field
331 break
332 }
333 current_field++
334 }
335 if (comments_end == 0) {
336 printf "%s: line %d: invalid comments \n",
337 infile, NR
338 exit 1
339 }
340 }
341
342 if ($args_end != "}")
343 parserr($args_end, "}")
344 args_end--
345 if ($args_end != ";")
346 parserr($args_end, ";")
347 args_end--
348
349 # skip any NO_SYSCALL_STUB qualifier
350 if ($args_end == "NO_SYSCALL_STUB")
351 args_end--
352
353 if ($args_end != ")")
354 parserr($args_end, ")")
355 args_end--
356
357 # extract additional comments
358 if (comments_start != 0) {
359 current_field = comments_start + 1
360 while (current_field < comments_end) {
361 additional_comments = additional_comments $current_field " "
362 obs_comments = obs_comments $current_field "_"
363 current_field++
364 }
365 }
366 sub(/old/, "obs", obs_comments)
367 obs_comments = substr(obs_comments, 1, length(obs_comments)-1)
368 if (obs_comments == "_") {
369 obs_comments = ""
370 }
371
372 # get function return type
373 current_field = args_start + 1
374 returntype = $current_field
375
376 # get function name and set up to get arguments
377 current_field++
378 funcname = $current_field
379 argalias = funcname "_args"
380 current_field++ # bump past function name
381
382 if ($current_field != "(")
383 parserr($current_field, "(")
384 current_field++
385
386 if (current_field == args_end) {
387 if ($current_field != "void")
388 parserr($current_field, "argument definition")
389 return
390 }
391
392 # extract argument types and names
393 while (current_field <= args_end) {
394 argc++
395 argtype[argc]=""
396 ext_argtype[argc]=""
397 oldf=""
398 while (current_field < args_end && $(current_field + 1) != ",") {
399 if (argtype[argc] != "" && oldf != "*") {
400 argtype[argc] = argtype[argc] " ";
401 }
402 argtype[argc] = argtype[argc] $current_field;
403 ext_argtype[argc] = argtype[argc];
404 oldf = $current_field;
405 current_field++
406 }
407 if (argtype[argc] == "")
408 parserr($current_field, "argument definition")
409 argname[argc] = $current_field;
410 current_field += 2; # skip name, and any comma
411 }
412 if (argc > 8) {
413 printf "%s: line %d: too many arguments!\n", infile, NR
414 exit 1
415 }
416 if (argc != 0)
417 argssize = "AC(" argalias ")"
418 }
419
420 {
421 auditev = $2;
422 }
423
424 {
425 add_sysent_entry = 1
426 add_sysnames_entry = 1
427 add_sysheader_entry = 1
428 add_sysproto_entry = 1
429
430
431 if ($3 != "ALL") {
432 files_keyword_OK = 0
433 add_sysent_entry = 0
434 add_sysnames_entry = 0
435 add_sysheader_entry = 0
436 add_sysproto_entry = 0
437
438 if (match($3, "[T]") != 0) {
439 add_sysent_entry = 1
440 files_keyword_OK = 1
441 }
442 if (match($3, "[N]") != 0) {
443 add_sysnames_entry = 1
444 files_keyword_OK = 1
445 }
446 if (match($3, "[H]") != 0) {
447 add_sysheader_entry = 1
448 files_keyword_OK = 1
449 }
450 if (match($3, "[P]") != 0) {
451 add_sysproto_entry = 1
452 files_keyword_OK = 1
453 }
454
455 if (files_keyword_OK == 0) {
456 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
457 exit 1
458 }
459 }
460
461
462 parseline()
463
464 # output function argument structures to sysproto.h and build the
465 # name of the appropriate argument mungers
466 munge32 = "NULL"
467 size32 = 0
468
469 if ((funcname != "nosys" && funcname != "enosys") || (syscall_num == 0 && funcname == "nosys")) {
470 if (argc != 0) {
471 if (add_sysproto_entry == 1) {
472 printf("struct %s {\n", argalias) > sysarg
473 }
474 munge32 = "munge_"
475 for (i = 1; i <= argc; i++) {
476 # Build name of argument munger.
477 # We account for all sys call argument types here.
478 # This is where you add any new types. With LP64 support
479 # each argument consumes 64-bits.
480 # see .../xnu/bsd/dev/munge.c for munge argument types.
481 if (argtype[i] == "long") {
482 ext_argtype[i] = "user_long_t";
483 munge32 = munge32 "s"
484 size32 += 4
485 }
486 else if (argtype[i] == "u_long") {
487 ext_argtype[i] = "user_ulong_t";
488 munge32 = munge32 "w"
489 size32 += 4
490 }
491 else if (argtype[i] == "size_t") {
492 ext_argtype[i] = "user_size_t";
493 munge32 = munge32 "w"
494 size32 += 4
495 }
496 else if (argtype[i] == "ssize_t") {
497 ext_argtype[i] = "user_ssize_t";
498 munge32 = munge32 "s"
499 size32 += 4
500 }
501 else if (argtype[i] == "user_ssize_t" || argtype[i] == "user_long_t") {
502 munge32 = munge32 "s"
503 size32 += 4
504 }
505 else if (argtype[i] == "user_addr_t" || argtype[i] == "user_size_t" ||
506 argtype[i] == "user_ulong_t") {
507 munge32 = munge32 "w"
508 size32 += 4
509 }
510 else if (argtype[i] == "caddr_t" || argtype[i] == "semun_t" ||
511 argtype[i] == "uuid_t" || match(argtype[i], "[\*]") != 0) {
512 ext_argtype[i] = "user_addr_t";
513 munge32 = munge32 "w"
514 size32 += 4
515 }
516 else if (argtype[i] == "int" || argtype[i] == "u_int" ||
517 argtype[i] == "uid_t" || argtype[i] == "pid_t" ||
518 argtype[i] == "id_t" || argtype[i] == "idtype_t" ||
519 argtype[i] == "socklen_t" || argtype[i] == "uint32_t" || argtype[i] == "int32_t" ||
520 argtype[i] == "sigset_t" || argtype[i] == "gid_t" || argtype[i] == "unsigned int" ||
521 argtype[i] == "mode_t" || argtype[i] == "key_t" ||
522 argtype[i] == "mach_port_name_t" || argtype[i] == "au_asid_t" ||
523 argtype[i] == "sae_associd_t" || argtype[i] == "sae_connid_t") {
524 munge32 = munge32 "w"
525 size32 += 4
526 }
527 else if (argtype[i] == "off_t" || argtype[i] == "int64_t" || argtype[i] == "uint64_t") {
528 munge32 = munge32 "l"
529 size32 += 8
530 }
531 else {
532 printf "%s: line %d: invalid type \"%s\" \n",
533 infile, NR, argtype[i]
534 printf "You need to add \"%s\" into the type checking code. \n",
535 argtype[i]
536 exit 1
537 }
538 if (add_sysproto_entry == 1) {
539 printf("\tchar %s_l_[PADL_(%s)]; " \
540 "%s %s; char %s_r_[PADR_(%s)];\n",
541 argname[i], ext_argtype[i],
542 ext_argtype[i], argname[i],
543 argname[i], ext_argtype[i]) > sysarg
544 }
545 }
546 if (add_sysproto_entry == 1) {
547 printf("};\n") > sysarg
548 }
549 }
550 else if (add_sysproto_entry == 1) {
551 printf("struct %s {\n\tint32_t dummy;\n};\n", argalias) > sysarg
552 }
553 }
554
555 # output to init_sysent.c
556 tempname = funcname
557 if (add_sysent_entry == 0) {
558 argssize = "0"
559 munge32 = "NULL"
560 munge_ret = "_SYSCALL_RET_NONE"
561 if (tempname != "enosys") {
562 tempname = "nosys"
563 }
564 }
565 else {
566 # figure out which return value type to munge
567 if (returntype == "user_addr_t") {
568 munge_ret = "_SYSCALL_RET_ADDR_T"
569 }
570 else if (returntype == "user_ssize_t") {
571 munge_ret = "_SYSCALL_RET_SSIZE_T"
572 }
573 else if (returntype == "user_size_t") {
574 munge_ret = "_SYSCALL_RET_SIZE_T"
575 }
576 else if (returntype == "int") {
577 munge_ret = "_SYSCALL_RET_INT_T"
578 }
579 else if (returntype == "u_int" || returntype == "mach_port_name_t") {
580 munge_ret = "_SYSCALL_RET_UINT_T"
581 }
582 else if (returntype == "uint32_t") {
583 munge_ret = "_SYSCALL_RET_UINT_T"
584 }
585 else if (returntype == "uint64_t") {
586 munge_ret = "_SYSCALL_RET_UINT64_T"
587 }
588 else if (returntype == "off_t") {
589 munge_ret = "_SYSCALL_RET_OFF_T"
590 }
591 else if (returntype == "void") {
592 munge_ret = "_SYSCALL_RET_NONE"
593 }
594 else {
595 printf "%s: line %d: invalid return type \"%s\" \n",
596 infile, NR, returntype
597 printf "You need to add \"%s\" into the return type checking code. \n",
598 returntype
599 exit 1
600 }
601 }
602
603 printf("#if CONFIG_REQUIRES_U32_MUNGING || (__arm__ && (__BIGGEST_ALIGNMENT__ > 4))\n") > sysent
604 printf("\t{ \(sy_call_t *\)%s, %s, %s, %s, %s},",
605 tempname, munge32, munge_ret, argssize, size32) > sysent
606 linesize = length(tempname) + length(munge32) + \
607 length(munge_ret) + length(argssize) + length(size32) + 28
608 align_comment(linesize, 88, sysent)
609 printf("/* %d = %s%s*/\n", syscall_num, funcname, additional_comments) > sysent
610 printf("#else\n") > sysent
611 printf("\t{ \(sy_call_t *\)%s, %s, %s, %s},\n",
612 tempname, munge_ret, argssize, size32) > sysent
613 printf("#endif\n") > sysent
614
615 # output to syscalls.c
616 if (add_sysnames_entry == 1) {
617 tempname = funcname
618 if (funcname == "nosys" || funcname == "enosys") {
619 if (syscall_num == 0)
620 tempname = "syscall"
621 else
622 tempname = "#" syscall_num
623 }
624 printf("\t\"%s\", ", tempname) > syscallnamestempfile
625 linesize = length(tempname) + 8
626 align_comment(linesize, 25, syscallnamestempfile)
627 if (substr(tempname,1,1) == "#") {
628 printf("/* %d =%s*/\n", syscall_num, additional_comments) > syscallnamestempfile
629 }
630 else {
631 printf("/* %d = %s%s*/\n", syscall_num, tempname, additional_comments) > syscallnamestempfile
632 }
633 }
634
635 # output to syscalls.h
636 if (add_sysheader_entry == 1) {
637 tempname = funcname
638 if (syscall_num == 0) {
639 tempname = "syscall"
640 }
641 if (tempname != "nosys" && tempname != "enosys") {
642 printf("#define\t%s%s", syscallprefix, tempname) > syshdrtempfile
643 linesize = length(syscallprefix) + length(tempname) + 12
644 align_comment(linesize, 30, syshdrtempfile)
645 printf("%d\n", syscall_num) > syshdrtempfile
646 }
647 else if (skip_for_header == 0) {
648 printf("\t\t\t/* %d %s*/\n", syscall_num, additional_comments) > syshdrtempfile
649 }
650 }
651
652 # output function prototypes to sysproto.h
653 if (add_sysproto_entry == 1) {
654 if (funcname =="exit") {
655 printf("void %s(struct proc *, struct %s *, int32_t *);\n",
656 funcname, argalias) > sysprotoend
657 }
658 else if ((funcname != "nosys" && funcname != "enosys") || (syscall_num == 0 && funcname == "nosys")) {
659 printf("int %s(struct proc *, struct %s *, %s *);\n",
660 funcname, argalias, returntype) > sysprotoend
661 }
662 }
663
664 # output to audit_kevents.c
665 printf("\t%s,\t\t", auditev) > audittempfile
666 printf("/* %d = %s%s*/\n", syscall_num, tempname, additional_comments) > audittempfile
667
668 tempname = funcname
669 if (skip_for_header == 0) {
670 if (tempname == "nosys" || tempname == "enosys") {
671 if (obs_comments == "") {
672 printf("0x40c%04x\tBSC_#%d%s\n", (syscall_num*4), syscall_num, obs_comments) > tracecodetempfile
673 } else {
674 printf("0x40c%04x\tBSC%s\n", (syscall_num*4), obs_comments) > tracecodetempfile
675 }
676 } else {
677 sub(/^_+/, "", tempname)
678 printf("0x40c%04x\tBSC_%s\n", (syscall_num*4), tempname) > tracecodetempfile
679 }
680 }
681
682 syscall_num++
683 next
684 }
685
686 END {
687 printf "#define AC(name) (sizeof(struct name) / sizeof(syscall_arg_t))\n" > sysinc
688 printf "\n" > sysinc
689
690 printf("\n__END_DECLS\n") > sysprotoend
691 printf("#undef PAD_\n") > sysprotoend
692 printf("#undef PADL_\n") > sysprotoend
693 printf("#undef PADR_\n") > sysprotoend
694 printf "\n#endif /* __APPLE_API_PRIVATE */\n" > sysprotoend
695 printf "#endif /* KERNEL */\n" > sysprotoend
696 printf("\n#endif /* !%s */\n", sysproto_h) > sysprotoend
697
698 printf("};\n") > sysent
699 printf("unsigned int nsysent = sizeof(sysent) / sizeof(sysent[0]);\n") > sysent
700
701 printf("};\n") > syscallnamestempfile
702 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall_num) \
703 > syshdrtempfile
704 printf("#define\t%sinvalid\t%d\n", syscallprefix, 63) \
705 > syshdrtempfile
706 printf("\n#endif /* __APPLE_API_PRIVATE */\n") > syshdrtempfile
707 printf("#endif /* !%s */\n", syscall_h) > syshdrtempfile
708 printf("};\n\n") > audittempfile
709 printf("#endif /* AUDIT */\n") > audittempfile
710 } '
711
712 # define value in syscall table file to permit redifintion because of the way
713 # __private_extern__ (doesn't) work.
714 if [ $output_syscalltablefile -eq 1 ]; then
715 cat $syslegal > $syscalltablefile
716 printf "#define __INIT_SYSENT_C__ 1\n" >> $syscalltablefile
717 cat $sysinc $sysent >> $syscalltablefile
718 fi
719
720 if [ $output_syscallnamesfile -eq 1 ]; then
721 cat $syslegal $syscallnamestempfile > $syscallnamesfile
722 fi
723
724 if [ $output_sysprotofile -eq 1 ]; then
725 cat $syslegal $sysarg $sysprotoend > $sysprotofile
726 fi
727
728 if [ $output_syshdrfile -eq 1 ]; then
729 cat $syslegal $syshdrtempfile > $syshdrfile
730 fi
731
732 if [ $output_auditevfile -eq 1 ]; then
733 cat $syslegal $audittempfile > $auditevfile
734 fi
735
736 if [ $output_tracecodes -eq 1 ]; then
737 if [ $use_stdout -eq 1 ]; then
738 cat $tracecodetempfile
739 else
740 cat $tracecodetempfile > $tracecodename
741 fi
742 fi