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