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