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