]> git.saurik.com Git - apple/xnu.git/blob - bsd/kern/makesyscalls.sh
709cbab6efd34e9d9dd4549875e0e7d581bb0b80
[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) 2006 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 "#ifdef __ppc__\n" > sysarg
158 printf "#define\tPAD_(t)\t(sizeof(uint64_t) <= sizeof(t) \\\n " > sysarg
159 printf "\t\t? 0 : sizeof(uint64_t) - sizeof(t))\n" > sysarg
160 printf "#else\n" > sysarg
161 printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) \\\n " > sysarg
162 printf "\t\t? 0 : sizeof(register_t) - sizeof(t))\n" > sysarg
163 printf "#endif\n" > sysarg
164 printf "#if BYTE_ORDER == LITTLE_ENDIAN\n"> sysarg
165 printf "#define\tPADL_(t)\t0\n" > sysarg
166 printf "#define\tPADR_(t)\tPAD_(t)\n" > sysarg
167 printf "#else\n" > sysarg
168 printf "#define\tPADL_(t)\tPAD_(t)\n" > sysarg
169 printf "#define\tPADR_(t)\t0\n" > sysarg
170 printf "#endif\n" > sysarg
171 printf "\n__BEGIN_DECLS\n" > sysarg
172 printf "#ifndef __MUNGE_ONCE\n" > sysarg
173 printf "#define __MUNGE_ONCE\n" > sysarg
174 printf "#ifdef __ppc__\n" > sysarg
175 printf "void munge_w(const void *, void *); \n" > sysarg
176 printf "void munge_ww(const void *, void *); \n" > sysarg
177 printf "void munge_www(const void *, void *); \n" > sysarg
178 printf "void munge_wwww(const void *, void *); \n" > sysarg
179 printf "void munge_wwwww(const void *, void *); \n" > sysarg
180 printf "void munge_wwwwww(const void *, void *); \n" > sysarg
181 printf "void munge_wwwwwww(const void *, void *); \n" > sysarg
182 printf "void munge_wwwwwwww(const void *, void *); \n" > sysarg
183 printf "void munge_d(const void *, void *); \n" > sysarg
184 printf "void munge_dd(const void *, void *); \n" > sysarg
185 printf "void munge_ddd(const void *, void *); \n" > sysarg
186 printf "void munge_dddd(const void *, void *); \n" > sysarg
187 printf "void munge_ddddd(const void *, void *); \n" > sysarg
188 printf "void munge_dddddd(const void *, void *); \n" > sysarg
189 printf "void munge_ddddddd(const void *, void *); \n" > sysarg
190 printf "void munge_dddddddd(const void *, void *); \n" > sysarg
191 printf "void munge_wl(const void *, void *); \n" > sysarg
192 printf "void munge_wlw(const void *, void *); \n" > sysarg
193 printf "void munge_wwwl(const void *, void *); \n" > sysarg
194 printf "void munge_wwwwl(const void *, void *); \n" > sysarg
195 printf "void munge_wwwwwl(const void *, void *); \n" > sysarg
196 printf "void munge_wsw(const void *, void *); \n" > sysarg
197 printf "void munge_wws(const void *, void *); \n" > sysarg
198 printf "void munge_wwwsw(const void *, void *); \n" > sysarg
199 printf "#else \n" > sysarg
200 printf "#define munge_w NULL \n" > sysarg
201 printf "#define munge_ww NULL \n" > sysarg
202 printf "#define munge_www NULL \n" > sysarg
203 printf "#define munge_wwww NULL \n" > sysarg
204 printf "#define munge_wwwww NULL \n" > sysarg
205 printf "#define munge_wwwwww NULL \n" > sysarg
206 printf "#define munge_wwwwwww NULL \n" > sysarg
207 printf "#define munge_wwwwwwww NULL \n" > sysarg
208 printf "#define munge_d NULL \n" > sysarg
209 printf "#define munge_dd NULL \n" > sysarg
210 printf "#define munge_ddd NULL \n" > sysarg
211 printf "#define munge_dddd NULL \n" > sysarg
212 printf "#define munge_ddddd NULL \n" > sysarg
213 printf "#define munge_dddddd NULL \n" > sysarg
214 printf "#define munge_ddddddd NULL \n" > sysarg
215 printf "#define munge_dddddddd NULL \n" > sysarg
216 printf "#define munge_wl NULL \n" > sysarg
217 printf "#define munge_wlw NULL \n" > sysarg
218 printf "#define munge_wwwl NULL \n" > sysarg
219 printf "#define munge_wwwwl NULL \n" > sysarg
220 printf "#define munge_wwwwwl NULL \n" > sysarg
221 printf "#define munge_wsw NULL \n" > sysarg
222 printf "#define munge_wws NULL \n" > sysarg
223 printf "#define munge_wwwsw NULL \n" > sysarg
224 printf "#endif // __ppc__\n" > sysarg
225 printf "#endif /* !__MUNGE_ONCE */\n" > sysarg
226
227 printf "\n" > sysarg
228
229 printf "const char *%s[] = {\n", namesname > syscallnamestempfile
230 next
231 }
232 NF == 0 || $1 ~ /^;/ {
233 next
234 }
235 $1 ~ /^#[ ]*include/ {
236 print > sysinc
237 next
238 }
239 $1 ~ /^#[ ]*if/ {
240 print > sysent
241 print > sysarg
242 print > syscallnamestempfile
243 print > syshdrtempfile
244 print > sysprotoend
245 savesyscall = syscall
246 next
247 }
248 $1 ~ /^#[ ]*else/ {
249 print > sysent
250 print > sysarg
251 print > syscallnamestempfile
252 print > syshdrtempfile
253 print > sysprotoend
254 syscall = savesyscall
255 next
256 }
257 $1 ~ /^#/ {
258 print > sysent
259 print > sysarg
260 print > syscallnamestempfile
261 print > syshdrtempfile
262 print > sysprotoend
263 next
264 }
265 syscall != $1 {
266 printf "%s: line %d: syscall number out of sync at %d\n",
267 infile, NR, syscall
268 printf "line is:\n"
269 print
270 exit 1
271 }
272 function align_comment(linesize, location, thefile) {
273 printf(" ") > thefile
274 while (linesize < location) {
275 printf(" ") > thefile
276 linesize++
277 }
278 }
279 function parserr(was, wanted) {
280 printf "%s: line %d: unexpected %s (expected %s)\n",
281 infile, NR, was, wanted
282 exit 1
283 }
284
285 function parseline() {
286 funcname = ""
287 current_field = 5
288 args_start = 0
289 args_end = 0
290 comments_start = 0
291 comments_end = 0
292 argc = 0
293 argssize = "0"
294 additional_comments = " "
295
296 # find start and end of call name and arguments
297 if ($current_field != "{")
298 parserr($current_field, "{")
299 args_start = current_field
300 current_field++
301 while (current_field <= NF) {
302 if ($current_field == "}") {
303 args_end = current_field
304 break
305 }
306 current_field++
307 }
308 if (args_end == 0) {
309 printf "%s: line %d: invalid call name and arguments\n",
310 infile, NR
311 exit 1
312 }
313
314 # find start and end of optional comments
315 current_field++
316 if (current_field < NF && $current_field == "{") {
317 comments_start = current_field
318 while (current_field <= NF) {
319 if ($current_field == "}") {
320 comments_end = current_field
321 break
322 }
323 current_field++
324 }
325 if (comments_end == 0) {
326 printf "%s: line %d: invalid comments \n",
327 infile, NR
328 exit 1
329 }
330 }
331
332 if ($args_end != "}")
333 parserr($args_end, "}")
334 args_end--
335 if ($args_end != ";")
336 parserr($args_end, ";")
337 args_end--
338 if ($args_end != ")")
339 parserr($args_end, ")")
340 args_end--
341
342 # extract additional comments
343 if (comments_start != 0) {
344 current_field = comments_start + 1
345 while (current_field < comments_end) {
346 additional_comments = additional_comments $current_field " "
347 current_field++
348 }
349 }
350
351 # get function return type
352 current_field = args_start + 1
353 returntype = $current_field
354
355 # get function name and set up to get arguments
356 current_field++
357 funcname = $current_field
358 argalias = funcname "_args"
359 current_field++ # bump past function name
360
361 if ($current_field != "(")
362 parserr($current_field, "(")
363 current_field++
364
365 if (current_field == args_end) {
366 if ($current_field != "void")
367 parserr($current_field, "argument definition")
368 return
369 }
370
371 # extract argument types and names
372 while (current_field <= args_end) {
373 argc++
374 argtype[argc]=""
375 ext_argtype[argc]=""
376 oldf=""
377 while (current_field < args_end && $(current_field + 1) != ",") {
378 if (argtype[argc] != "" && oldf != "*") {
379 argtype[argc] = argtype[argc] " ";
380 }
381 argtype[argc] = argtype[argc] $current_field;
382 ext_argtype[argc] = argtype[argc];
383 oldf = $current_field;
384 current_field++
385 }
386 if (argtype[argc] == "")
387 parserr($current_field, "argument definition")
388 argname[argc] = $current_field;
389 current_field += 2; # skip name, and any comma
390 }
391 if (argc > 8) {
392 printf "%s: line %d: too many arguments!\n", infile, NR
393 exit 1
394 }
395 if (argc != 0)
396 argssize = "AC(" argalias ")"
397 }
398
399 {
400 add_sysent_entry = 1
401 add_sysnames_entry = 1
402 add_sysheader_entry = 1
403 add_sysproto_entry = 1
404 add_64bit_unsafe = 0
405 add_64bit_fakesafe = 0
406 add_cancel_enable = "0"
407
408 if ($2 == "NONE") {
409 add_cancel_enable = "_SYSCALL_CANCEL_NONE"
410 }
411 else if ($2 == "PRE") {
412 add_cancel_enable = "_SYSCALL_CANCEL_PRE"
413 }
414 else if ($2 == "POST") {
415 add_cancel_enable = "_SYSCALL_CANCEL_POST"
416 }
417 else {
418 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
419 exit 1
420
421 }
422
423 if ($3 == "KERN") {
424 my_funnel = "KERNEL_FUNNEL"
425 }
426 else if ($3 == "NONE") {
427 my_funnel = "NO_FUNNEL"
428 }
429 else {
430 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $3
431 exit 1
432 }
433
434 if ($4 != "ALL" && $4 != "UALL") {
435 files_keyword_OK = 0
436 add_sysent_entry = 0
437 add_sysnames_entry = 0
438 add_sysheader_entry = 0
439 add_sysproto_entry = 0
440
441 if (match($4, "[T]") != 0) {
442 add_sysent_entry = 1
443 files_keyword_OK = 1
444 }
445 if (match($4, "[N]") != 0) {
446 add_sysnames_entry = 1
447 files_keyword_OK = 1
448 }
449 if (match($4, "[H]") != 0) {
450 add_sysheader_entry = 1
451 files_keyword_OK = 1
452 }
453 if (match($4, "[P]") != 0) {
454 add_sysproto_entry = 1
455 files_keyword_OK = 1
456 }
457 if (match($4, "[U]") != 0) {
458 add_64bit_unsafe = 1
459 }
460 if (match($4, "[F]") != 0) {
461 add_64bit_fakesafe = 1
462 }
463
464 if (files_keyword_OK == 0) {
465 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $4
466 exit 1
467 }
468 }
469 else if ($4 == "UALL") {
470 add_64bit_unsafe = 1;
471 }
472
473
474 parseline()
475
476 # output function argument structures to sysproto.h and build the
477 # name of the appropriate argument mungers
478 munge32 = "NULL"
479 munge64 = "NULL"
480 if (funcname != "nosys" || (syscall == 0 && funcname == "nosys")) {
481 if (argc != 0) {
482 if (add_sysproto_entry == 1) {
483 printf("struct %s {\n", argalias) > sysarg
484 }
485 munge32 = "munge_"
486 munge64 = "munge_"
487 for (i = 1; i <= argc; i++) {
488 # Build name of argument munger.
489 # We account for all sys call argument types here.
490 # This is where you add any new types. With LP64 support
491 # each argument consumes 64-bits.
492 # see .../xnu/bsd/dev/ppc/munge.s for munge argument types.
493 if (argtype[i] == "long") {
494 if (add_64bit_unsafe == 0)
495 ext_argtype[i] = "user_long_t";
496 munge32 = munge32 "s"
497 munge64 = munge64 "d"
498 }
499 else if (argtype[i] == "u_long") {
500 if (add_64bit_unsafe == 0)
501 ext_argtype[i] = "user_ulong_t";
502 munge32 = munge32 "w"
503 munge64 = munge64 "d"
504 }
505 else if (argtype[i] == "size_t") {
506 if (add_64bit_unsafe == 0)
507 ext_argtype[i] = "user_size_t";
508 munge32 = munge32 "w"
509 munge64 = munge64 "d"
510 }
511 else if (argtype[i] == "ssize_t") {
512 if (add_64bit_unsafe == 0)
513 ext_argtype[i] = "user_ssize_t";
514 munge32 = munge32 "s"
515 munge64 = munge64 "d"
516 }
517 else if (argtype[i] == "user_ssize_t" || argtype[i] == "user_long_t") {
518 munge32 = munge32 "s"
519 munge64 = munge64 "d"
520 }
521 else if (argtype[i] == "user_addr_t" || argtype[i] == "user_size_t" ||
522 argtype[i] == "user_ulong_t") {
523 munge32 = munge32 "w"
524 munge64 = munge64 "d"
525 }
526 else if (argtype[i] == "caddr_t" || argtype[i] == "semun_t" ||
527 match(argtype[i], "[\*]") != 0) {
528 if (add_64bit_unsafe == 0)
529 ext_argtype[i] = "user_addr_t";
530 munge32 = munge32 "w"
531 munge64 = munge64 "d"
532 }
533 else if (argtype[i] == "int" || argtype[i] == "u_int" ||
534 argtype[i] == "uid_t" || argtype[i] == "pid_t" ||
535 argtype[i] == "id_t" || argtype[i] == "idtype_t" ||
536 argtype[i] == "socklen_t" || argtype[i] == "uint32_t" || argtype[i] == "int32_t" ||
537 argtype[i] == "sigset_t" || argtype[i] == "gid_t" ||
538 argtype[i] == "mode_t" || argtype[i] == "key_t" || argtype[i] == "time_t") {
539 munge32 = munge32 "w"
540 munge64 = munge64 "d"
541 }
542 else if (argtype[i] == "off_t" || argtype[i] == "int64_t" || argtype[i] == "uint64_t") {
543 munge32 = munge32 "l"
544 munge64 = munge64 "d"
545 }
546 else {
547 printf "%s: line %d: invalid type \"%s\" \n",
548 infile, NR, argtype[i]
549 printf "You need to add \"%s\" into the type checking code. \n",
550 argtype[i]
551 exit 1
552 }
553 if (add_sysproto_entry == 1) {
554 printf("\tchar %s_l_[PADL_(%s)]; " \
555 "%s %s; char %s_r_[PADR_(%s)];\n",
556 argname[i], ext_argtype[i],
557 ext_argtype[i], argname[i],
558 argname[i], ext_argtype[i]) > sysarg
559 }
560 }
561 if (add_sysproto_entry == 1) {
562 printf("};\n") > sysarg
563 }
564 }
565 else if (add_sysproto_entry == 1) {
566 printf("struct %s {\n\tregister_t dummy;\n};\n", argalias) > sysarg
567 }
568 }
569
570 # output to init_sysent.c
571 tempname = funcname
572 if (add_sysent_entry == 0) {
573 argssize = "0"
574 munge32 = "NULL"
575 munge64 = "NULL"
576 munge_ret = "_SYSCALL_RET_NONE"
577 tempname = "nosys"
578 }
579 else {
580 # figure out which return value type to munge
581 if (returntype == "user_addr_t") {
582 munge_ret = "_SYSCALL_RET_ADDR_T"
583 }
584 else if (returntype == "user_ssize_t") {
585 munge_ret = "_SYSCALL_RET_SSIZE_T"
586 }
587 else if (returntype == "user_size_t") {
588 munge_ret = "_SYSCALL_RET_SIZE_T"
589 }
590 else if (returntype == "int") {
591 munge_ret = "_SYSCALL_RET_INT_T"
592 }
593 else if (returntype == "u_int") {
594 munge_ret = "_SYSCALL_RET_UINT_T"
595 }
596 else if (returntype == "off_t") {
597 munge_ret = "_SYSCALL_RET_OFF_T"
598 }
599 else if (returntype == "void") {
600 munge_ret = "_SYSCALL_RET_NONE"
601 }
602 else {
603 printf "%s: line %d: invalid return type \"%s\" \n",
604 infile, NR, returntype
605 printf "You need to add \"%s\" into the return type checking code. \n",
606 returntype
607 exit 1
608 }
609 }
610
611 if (add_64bit_unsafe == 1 && add_64bit_fakesafe == 0)
612 my_funnel = my_funnel "|UNSAFE_64BIT";
613
614 printf("\t{%s, %s, %s, \(sy_call_t *\)%s, %s, %s, %s},",
615 argssize, add_cancel_enable, my_funnel, tempname, munge32, munge64, munge_ret) > sysent
616 linesize = length(argssize) + length(add_cancel_enable) + length(my_funnel) + length(tempname) + \
617 length(munge32) + length(munge64) + length(munge_ret) + 28
618 align_comment(linesize, 88, sysent)
619 printf("/* %d = %s%s*/\n", syscall, funcname, additional_comments) > sysent
620
621 # output to syscalls.c
622 if (add_sysnames_entry == 1) {
623 tempname = funcname
624 if (funcname == "nosys") {
625 if (syscall == 0)
626 tempname = "syscall"
627 else
628 tempname = "#" syscall
629 }
630 printf("\t\"%s\", ", tempname) > syscallnamestempfile
631 linesize = length(tempname) + 8
632 align_comment(linesize, 25, syscallnamestempfile)
633 if (substr(tempname,1,1) == "#") {
634 printf("/* %d =%s*/\n", syscall, additional_comments) > syscallnamestempfile
635 }
636 else {
637 printf("/* %d = %s%s*/\n", syscall, tempname, additional_comments) > syscallnamestempfile
638 }
639 }
640
641 # output to syscalls.h
642 if (add_sysheader_entry == 1) {
643 tempname = funcname
644 if (syscall == 0) {
645 tempname = "syscall"
646 }
647 if (tempname != "nosys") {
648 printf("#define\t%s%s", syscallprefix, tempname) > syshdrtempfile
649 linesize = length(syscallprefix) + length(tempname) + 12
650 align_comment(linesize, 30, syshdrtempfile)
651 printf("%d\n", syscall) > syshdrtempfile
652 # special case for gettimeofday on ppc - cctools project uses old name
653 if (tempname == "ppc_gettimeofday") {
654 printf("#define\t%s%s", syscallprefix, "gettimeofday") > syshdrtempfile
655 linesize = length(syscallprefix) + length(tempname) + 12
656 align_comment(linesize, 30, syshdrtempfile)
657 printf("%d\n", syscall) > syshdrtempfile
658 }
659 }
660 else {
661 printf("\t\t\t/* %d %s*/\n", syscall, additional_comments) > syshdrtempfile
662 }
663 }
664
665 # output function prototypes to sysproto.h
666 if (add_sysproto_entry == 1) {
667 if (funcname =="exit") {
668 printf("void %s(struct proc *, struct %s *, int *);\n",
669 funcname, argalias) > sysprotoend
670 }
671 else if (funcname != "nosys" || (syscall == 0 && funcname == "nosys")) {
672 printf("int %s(struct proc *, struct %s *, %s *);\n",
673 funcname, argalias, returntype) > sysprotoend
674 }
675 }
676
677 syscall++
678 next
679 }
680
681 END {
682 printf "#ifdef __ppc__\n" > sysinc
683 printf "#define AC(name) (sizeof(struct name) / sizeof(uint64_t))\n" > sysinc
684 printf "#else\n" > sysinc
685 printf "#define AC(name) (sizeof(struct name) / sizeof(register_t))\n" > sysinc
686 printf "#endif\n" > sysinc
687 printf "\n" > sysinc
688
689 printf("\n__END_DECLS\n") > sysprotoend
690 printf("#undef PAD_\n") > sysprotoend
691 printf("#undef PADL_\n") > sysprotoend
692 printf("#undef PADR_\n") > sysprotoend
693 printf "\n#endif /* __APPLE_API_PRIVATE */\n" > sysprotoend
694 printf "#endif /* KERNEL */\n" > sysprotoend
695 printf("\n#endif /* !%s */\n", sysproto_h) > sysprotoend
696
697 printf("};\n") > sysent
698 printf("int nsysent = sizeof(sysent) / sizeof(sysent[0]);\n") > sysent
699
700 printf("};\n") > syscallnamestempfile
701 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
702 > syshdrtempfile
703 printf("\n#endif /* __APPLE_API_PRIVATE */\n") > syshdrtempfile
704 printf("#endif /* !%s */\n", syscall_h) > syshdrtempfile
705 } '
706
707 cat $syslegal $sysinc $sysent > $syscalltablefile
708 cat $syslegal $sysarg $sysprotoend > $sysprotofile
709 cat $syslegal $syscallnamestempfile > $syscallnamesfile
710 cat $syslegal $syshdrtempfile > $syshdrfile