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