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