]>
Commit | Line | Data |
---|---|---|
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 | ||
27 | set -e | |
28 | ||
b0d623f7 A |
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 | ||
91447636 A |
38 | # output files: |
39 | syscallnamesfile="syscalls.c" | |
b0d623f7 | 40 | sysprotofile="sysproto.h" |
91447636 | 41 | sysproto_h=_SYS_SYSPROTO_H_ |
b0d623f7 | 42 | syshdrfile="syscall.h" |
91447636 A |
43 | syscall_h=_SYS_SYSCALL_H_ |
44 | syscalltablefile="init_sysent.c" | |
b0d623f7 | 45 | auditevfile="audit_kevents.c" |
91447636 A |
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.$$" | |
b0d623f7 | 58 | audittempfile="audittempfile.$$" |
91447636 | 59 | |
b0d623f7 | 60 | trap "rm $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile $audittempfile" 0 |
91447636 | 61 | |
b0d623f7 | 62 | touch $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile $audittempfile |
91447636 A |
63 | |
64 | case $# 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 | ;; | |
69 | esac | |
70 | ||
b0d623f7 A |
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 | |
91447636 A |
103 | fi |
104 | ||
b0d623f7 A |
105 | |
106 | ||
91447636 A |
107 | sed -e ' |
108 | s/\$//g | |
109 | :join | |
110 | /\\$/{a\ | |
111 | ||
112 | N | |
113 | s/\\\n// | |
114 | b join | |
115 | } | |
116 | 2,${ | |
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 | |
fe8ab488 | 198 | printf "#if CONFIG_REQUIRES_U32_MUNGING\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 | |
fe8ab488 | 213 | printf "#include <sys/munge.h>\n" > sysarg |
91447636 A |
214 | |
215 | printf "\n" > sysarg | |
216 | ||
217 | printf "const char *%s[] = {\n", namesname > syscallnamestempfile | |
b0d623f7 A |
218 | |
219 | printf "#include <sys/param.h>\n" > audittempfile | |
220 | printf "#include <sys/types.h>\n\n" > audittempfile | |
221 | printf "#include <bsm/audit.h>\n" > audittempfile | |
222 | printf "#include <bsm/audit_kevents.h>\n\n" > audittempfile | |
223 | printf "#if CONFIG_AUDIT\n\n" > audittempfile | |
224 | printf "au_event_t sys_au_event[] = {\n" > audittempfile | |
91447636 A |
225 | next |
226 | } | |
227 | NF == 0 || $1 ~ /^;/ { | |
228 | next | |
229 | } | |
230 | $1 ~ /^#[ ]*include/ { | |
231 | print > sysinc | |
232 | next | |
233 | } | |
234 | $1 ~ /^#[ ]*if/ { | |
235 | print > sysent | |
236 | print > sysarg | |
237 | print > syscallnamestempfile | |
91447636 | 238 | print > sysprotoend |
b0d623f7 | 239 | print > audittempfile |
2d21ac55 A |
240 | savesyscall = syscall_num |
241 | skip_for_header = 0 | |
91447636 A |
242 | next |
243 | } | |
244 | $1 ~ /^#[ ]*else/ { | |
245 | print > sysent | |
246 | print > sysarg | |
247 | print > syscallnamestempfile | |
91447636 | 248 | print > sysprotoend |
b0d623f7 | 249 | print > audittempfile |
2d21ac55 A |
250 | syscall_num = savesyscall |
251 | skip_for_header = 1 | |
91447636 A |
252 | next |
253 | } | |
254 | $1 ~ /^#/ { | |
255 | print > sysent | |
256 | print > sysarg | |
257 | print > syscallnamestempfile | |
91447636 | 258 | print > sysprotoend |
b0d623f7 | 259 | print > audittempfile |
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 | ||
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 = "" | |
b0d623f7 | 285 | current_field = 4 # skip number, audit event, type |
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 | } | |
b0d623f7 A |
401 | |
402 | { | |
403 | auditev = $2; | |
404 | } | |
405 | ||
91447636 A |
406 | { |
407 | add_sysent_entry = 1 | |
408 | add_sysnames_entry = 1 | |
409 | add_sysheader_entry = 1 | |
410 | add_sysproto_entry = 1 | |
91447636 | 411 | |
91447636 | 412 | |
39236c6e | 413 | if ($3 != "ALL") { |
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 | ||
b0d623f7 | 420 | if (match($3, "[T]") != 0) { |
91447636 A |
421 | add_sysent_entry = 1 |
422 | files_keyword_OK = 1 | |
423 | } | |
b0d623f7 | 424 | if (match($3, "[N]") != 0) { |
91447636 A |
425 | add_sysnames_entry = 1 |
426 | files_keyword_OK = 1 | |
427 | } | |
b0d623f7 | 428 | if (match($3, "[H]") != 0) { |
91447636 A |
429 | add_sysheader_entry = 1 |
430 | files_keyword_OK = 1 | |
431 | } | |
b0d623f7 | 432 | if (match($3, "[P]") != 0) { |
91447636 A |
433 | add_sysproto_entry = 1 |
434 | files_keyword_OK = 1 | |
435 | } | |
91447636 A |
436 | |
437 | if (files_keyword_OK == 0) { | |
2d21ac55 | 438 | printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2 |
91447636 A |
439 | exit 1 |
440 | } | |
441 | } | |
91447636 A |
442 | |
443 | ||
444 | parseline() | |
445 | ||
446 | # output function argument structures to sysproto.h and build the | |
447 | # name of the appropriate argument mungers | |
448 | munge32 = "NULL" | |
2d21ac55 A |
449 | size32 = 0 |
450 | ||
451 | if ((funcname != "nosys" && funcname != "enosys") || (syscall_num == 0 && funcname == "nosys")) { | |
91447636 A |
452 | if (argc != 0) { |
453 | if (add_sysproto_entry == 1) { | |
454 | printf("struct %s {\n", argalias) > sysarg | |
455 | } | |
456 | munge32 = "munge_" | |
91447636 A |
457 | for (i = 1; i <= argc; i++) { |
458 | # Build name of argument munger. | |
459 | # We account for all sys call argument types here. | |
460 | # This is where you add any new types. With LP64 support | |
461 | # each argument consumes 64-bits. | |
fe8ab488 | 462 | # see .../xnu/bsd/dev/munge.c for munge argument types. |
91447636 | 463 | if (argtype[i] == "long") { |
39236c6e | 464 | ext_argtype[i] = "user_long_t"; |
91447636 | 465 | munge32 = munge32 "s" |
2d21ac55 | 466 | size32 += 4 |
91447636 A |
467 | } |
468 | else if (argtype[i] == "u_long") { | |
39236c6e | 469 | ext_argtype[i] = "user_ulong_t"; |
91447636 | 470 | munge32 = munge32 "w" |
2d21ac55 | 471 | size32 += 4 |
91447636 A |
472 | } |
473 | else if (argtype[i] == "size_t") { | |
39236c6e | 474 | ext_argtype[i] = "user_size_t"; |
91447636 | 475 | munge32 = munge32 "w" |
2d21ac55 | 476 | size32 += 4 |
91447636 A |
477 | } |
478 | else if (argtype[i] == "ssize_t") { | |
39236c6e | 479 | ext_argtype[i] = "user_ssize_t"; |
91447636 | 480 | munge32 = munge32 "s" |
2d21ac55 | 481 | size32 += 4 |
91447636 A |
482 | } |
483 | else if (argtype[i] == "user_ssize_t" || argtype[i] == "user_long_t") { | |
484 | munge32 = munge32 "s" | |
2d21ac55 | 485 | size32 += 4 |
91447636 A |
486 | } |
487 | else if (argtype[i] == "user_addr_t" || argtype[i] == "user_size_t" || | |
488 | argtype[i] == "user_ulong_t") { | |
489 | munge32 = munge32 "w" | |
2d21ac55 | 490 | size32 += 4 |
91447636 A |
491 | } |
492 | else if (argtype[i] == "caddr_t" || argtype[i] == "semun_t" || | |
39236c6e A |
493 | argtype[i] == "uuid_t" || match(argtype[i], "[\*]") != 0) { |
494 | ext_argtype[i] = "user_addr_t"; | |
91447636 | 495 | munge32 = munge32 "w" |
2d21ac55 | 496 | size32 += 4 |
91447636 A |
497 | } |
498 | else if (argtype[i] == "int" || argtype[i] == "u_int" || | |
499 | argtype[i] == "uid_t" || argtype[i] == "pid_t" || | |
500 | argtype[i] == "id_t" || argtype[i] == "idtype_t" || | |
501 | argtype[i] == "socklen_t" || argtype[i] == "uint32_t" || argtype[i] == "int32_t" || | |
b0d623f7 A |
502 | argtype[i] == "sigset_t" || argtype[i] == "gid_t" || argtype[i] == "unsigned int" || |
503 | argtype[i] == "mode_t" || argtype[i] == "key_t" || | |
39236c6e A |
504 | argtype[i] == "mach_port_name_t" || argtype[i] == "au_asid_t" || |
505 | argtype[i] == "associd_t" || argtype[i] == "connid_t") { | |
91447636 | 506 | munge32 = munge32 "w" |
2d21ac55 | 507 | size32 += 4 |
91447636 A |
508 | } |
509 | else if (argtype[i] == "off_t" || argtype[i] == "int64_t" || argtype[i] == "uint64_t") { | |
510 | munge32 = munge32 "l" | |
2d21ac55 | 511 | size32 += 8 |
91447636 A |
512 | } |
513 | else { | |
514 | printf "%s: line %d: invalid type \"%s\" \n", | |
515 | infile, NR, argtype[i] | |
516 | printf "You need to add \"%s\" into the type checking code. \n", | |
517 | argtype[i] | |
518 | exit 1 | |
519 | } | |
520 | if (add_sysproto_entry == 1) { | |
521 | printf("\tchar %s_l_[PADL_(%s)]; " \ | |
522 | "%s %s; char %s_r_[PADR_(%s)];\n", | |
523 | argname[i], ext_argtype[i], | |
524 | ext_argtype[i], argname[i], | |
525 | argname[i], ext_argtype[i]) > sysarg | |
526 | } | |
527 | } | |
528 | if (add_sysproto_entry == 1) { | |
529 | printf("};\n") > sysarg | |
530 | } | |
531 | } | |
532 | else if (add_sysproto_entry == 1) { | |
b0d623f7 | 533 | printf("struct %s {\n\tint32_t dummy;\n};\n", argalias) > sysarg |
91447636 A |
534 | } |
535 | } | |
536 | ||
537 | # output to init_sysent.c | |
538 | tempname = funcname | |
539 | if (add_sysent_entry == 0) { | |
540 | argssize = "0" | |
541 | munge32 = "NULL" | |
91447636 | 542 | munge_ret = "_SYSCALL_RET_NONE" |
2d21ac55 A |
543 | if (tempname != "enosys") { |
544 | tempname = "nosys" | |
545 | } | |
91447636 A |
546 | } |
547 | else { | |
548 | # figure out which return value type to munge | |
549 | if (returntype == "user_addr_t") { | |
550 | munge_ret = "_SYSCALL_RET_ADDR_T" | |
551 | } | |
552 | else if (returntype == "user_ssize_t") { | |
553 | munge_ret = "_SYSCALL_RET_SSIZE_T" | |
554 | } | |
555 | else if (returntype == "user_size_t") { | |
556 | munge_ret = "_SYSCALL_RET_SIZE_T" | |
557 | } | |
558 | else if (returntype == "int") { | |
559 | munge_ret = "_SYSCALL_RET_INT_T" | |
560 | } | |
b0d623f7 A |
561 | else if (returntype == "u_int" || returntype == "mach_port_name_t") { |
562 | munge_ret = "_SYSCALL_RET_UINT_T" | |
563 | } | |
564 | else if (returntype == "uint32_t") { | |
91447636 A |
565 | munge_ret = "_SYSCALL_RET_UINT_T" |
566 | } | |
d1ecb069 A |
567 | else if (returntype == "uint64_t") { |
568 | munge_ret = "_SYSCALL_RET_UINT64_T" | |
569 | } | |
91447636 A |
570 | else if (returntype == "off_t") { |
571 | munge_ret = "_SYSCALL_RET_OFF_T" | |
572 | } | |
573 | else if (returntype == "void") { | |
574 | munge_ret = "_SYSCALL_RET_NONE" | |
575 | } | |
576 | else { | |
577 | printf "%s: line %d: invalid return type \"%s\" \n", | |
578 | infile, NR, returntype | |
579 | printf "You need to add \"%s\" into the return type checking code. \n", | |
580 | returntype | |
581 | exit 1 | |
582 | } | |
583 | } | |
584 | ||
fe8ab488 A |
585 | printf("#if CONFIG_REQUIRES_U32_MUNGING\n") > sysent |
586 | printf("\t{ \(sy_call_t *\)%s, %s, %s, %s, %s},", | |
587 | tempname, munge32, munge_ret, argssize, size32) > sysent | |
588 | linesize = length(tempname) + length(munge32) + \ | |
39236c6e | 589 | length(munge_ret) + length(argssize) + length(size32) + 28 |
91447636 | 590 | align_comment(linesize, 88, sysent) |
2d21ac55 | 591 | printf("/* %d = %s%s*/\n", syscall_num, funcname, additional_comments) > sysent |
fe8ab488 A |
592 | printf("#else\n") > sysent |
593 | printf("\t{ \(sy_call_t *\)%s, %s, %s, %s},\n", | |
594 | tempname, munge_ret, argssize, size32) > sysent | |
595 | printf("#endif\n") > sysent | |
91447636 A |
596 | |
597 | # output to syscalls.c | |
598 | if (add_sysnames_entry == 1) { | |
599 | tempname = funcname | |
2d21ac55 A |
600 | if (funcname == "nosys" || funcname == "enosys") { |
601 | if (syscall_num == 0) | |
91447636 A |
602 | tempname = "syscall" |
603 | else | |
2d21ac55 | 604 | tempname = "#" syscall_num |
91447636 A |
605 | } |
606 | printf("\t\"%s\", ", tempname) > syscallnamestempfile | |
607 | linesize = length(tempname) + 8 | |
608 | align_comment(linesize, 25, syscallnamestempfile) | |
609 | if (substr(tempname,1,1) == "#") { | |
2d21ac55 | 610 | printf("/* %d =%s*/\n", syscall_num, additional_comments) > syscallnamestempfile |
91447636 A |
611 | } |
612 | else { | |
2d21ac55 | 613 | printf("/* %d = %s%s*/\n", syscall_num, tempname, additional_comments) > syscallnamestempfile |
91447636 A |
614 | } |
615 | } | |
616 | ||
617 | # output to syscalls.h | |
618 | if (add_sysheader_entry == 1) { | |
619 | tempname = funcname | |
2d21ac55 | 620 | if (syscall_num == 0) { |
91447636 A |
621 | tempname = "syscall" |
622 | } | |
2d21ac55 | 623 | if (tempname != "nosys" && tempname != "enosys") { |
91447636 A |
624 | printf("#define\t%s%s", syscallprefix, tempname) > syshdrtempfile |
625 | linesize = length(syscallprefix) + length(tempname) + 12 | |
626 | align_comment(linesize, 30, syshdrtempfile) | |
2d21ac55 | 627 | printf("%d\n", syscall_num) > syshdrtempfile |
91447636 A |
628 | # special case for gettimeofday on ppc - cctools project uses old name |
629 | if (tempname == "ppc_gettimeofday") { | |
630 | printf("#define\t%s%s", syscallprefix, "gettimeofday") > syshdrtempfile | |
631 | linesize = length(syscallprefix) + length(tempname) + 12 | |
632 | align_comment(linesize, 30, syshdrtempfile) | |
2d21ac55 | 633 | printf("%d\n", syscall_num) > syshdrtempfile |
91447636 A |
634 | } |
635 | } | |
2d21ac55 A |
636 | else if (skip_for_header == 0) { |
637 | printf("\t\t\t/* %d %s*/\n", syscall_num, additional_comments) > syshdrtempfile | |
91447636 A |
638 | } |
639 | } | |
640 | ||
641 | # output function prototypes to sysproto.h | |
642 | if (add_sysproto_entry == 1) { | |
643 | if (funcname =="exit") { | |
b0d623f7 | 644 | printf("void %s(struct proc *, struct %s *, int32_t *);\n", |
91447636 A |
645 | funcname, argalias) > sysprotoend |
646 | } | |
2d21ac55 | 647 | else if ((funcname != "nosys" && funcname != "enosys") || (syscall_num == 0 && funcname == "nosys")) { |
91447636 A |
648 | printf("int %s(struct proc *, struct %s *, %s *);\n", |
649 | funcname, argalias, returntype) > sysprotoend | |
650 | } | |
651 | } | |
b0d623f7 A |
652 | |
653 | # output to audit_kevents.c | |
654 | printf("\t%s,\t\t", auditev) > audittempfile | |
655 | printf("/* %d = %s%s*/\n", syscall_num, tempname, additional_comments) > audittempfile | |
91447636 | 656 | |
2d21ac55 | 657 | syscall_num++ |
91447636 A |
658 | next |
659 | } | |
660 | ||
661 | END { | |
2d21ac55 | 662 | printf "#define AC(name) (sizeof(struct name) / sizeof(syscall_arg_t))\n" > sysinc |
91447636 A |
663 | printf "\n" > sysinc |
664 | ||
665 | printf("\n__END_DECLS\n") > sysprotoend | |
666 | printf("#undef PAD_\n") > sysprotoend | |
667 | printf("#undef PADL_\n") > sysprotoend | |
668 | printf("#undef PADR_\n") > sysprotoend | |
669 | printf "\n#endif /* __APPLE_API_PRIVATE */\n" > sysprotoend | |
670 | printf "#endif /* KERNEL */\n" > sysprotoend | |
671 | printf("\n#endif /* !%s */\n", sysproto_h) > sysprotoend | |
672 | ||
673 | printf("};\n") > sysent | |
674 | printf("int nsysent = sizeof(sysent) / sizeof(sysent[0]);\n") > sysent | |
2d21ac55 A |
675 | printf("/* Verify that NUM_SYSENT reflects the latest syscall count */\n") > sysent |
676 | printf("int nsysent_size_check[((sizeof(sysent) / sizeof(sysent[0])) == NUM_SYSENT) ? 1 : -1] __unused;\n") > sysent | |
91447636 A |
677 | |
678 | printf("};\n") > syscallnamestempfile | |
2d21ac55 | 679 | printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall_num) \ |
91447636 A |
680 | > syshdrtempfile |
681 | printf("\n#endif /* __APPLE_API_PRIVATE */\n") > syshdrtempfile | |
682 | printf("#endif /* !%s */\n", syscall_h) > syshdrtempfile | |
b0d623f7 A |
683 | printf("};\n\n") > audittempfile |
684 | printf("#endif /* AUDIT */\n") > audittempfile | |
91447636 A |
685 | } ' |
686 | ||
2d21ac55 A |
687 | # define value in syscall table file to permit redifintion because of the way |
688 | # __private_extern__ (doesn't) work. | |
b0d623f7 A |
689 | if [ $output_syscalltablefile -eq 1 ]; then |
690 | cat $syslegal > $syscalltablefile | |
691 | printf "#define __INIT_SYSENT_C__ 1\n" >> $syscalltablefile | |
692 | cat $sysinc $sysent >> $syscalltablefile | |
693 | fi | |
694 | ||
695 | if [ $output_syscallnamesfile -eq 1 ]; then | |
696 | cat $syslegal $syscallnamestempfile > $syscallnamesfile | |
697 | fi | |
698 | ||
699 | if [ $output_sysprotofile -eq 1 ]; then | |
700 | cat $syslegal $sysarg $sysprotoend > $sysprotofile | |
701 | fi | |
702 | ||
703 | if [ $output_syshdrfile -eq 1 ]; then | |
704 | cat $syslegal $syshdrtempfile > $syshdrfile | |
705 | fi | |
706 | ||
707 | if [ $output_auditevfile -eq 1 ]; then | |
708 | cat $syslegal $audittempfile > $auditevfile | |
709 | fi |