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