]>
git.saurik.com Git - apple/xnu.git/blob - bsd/kern/makesyscalls.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 $
5 # Copyright (c) 2004-2008 Apple Inc. All rights reserved.
7 # @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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
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
18 # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
19 # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
24 # @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 input_file
="" # first argument
32 output_syscallnamesfile
=0
35 output_syscalltablefile
=0
42 syscallnamesfile
="syscalls.c"
43 sysprotofile
="sysproto.h"
44 sysproto_h
=_SYS_SYSPROTO_H_
45 syshdrfile
="syscall.h"
46 syscall_h
=_SYS_SYSCALL_H_
47 syscalltablefile
="init_sysent.c"
48 auditevfile
="audit_kevents.c"
51 namesname
="syscallnames"
52 tracecodename
="syscall.codes"
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.$$"
62 audittempfile
="audittempfile.$$"
63 tracecodetempfile
="tracecodetempfile.$$"
65 trap "rm $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile $audittempfile $tracecodetempfile" 0
67 touch $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile $audittempfile $tracecodetempfile
71 echo "usage: $0 input-file [<names|proto|header|table|audit|trace> [<config-file>]]" 1>&2
82 output_syscallnamesfile
=1
91 output_syscalltablefile
=1
103 output_syscallnamesfile
=1
104 output_sysprotofile
=1
106 output_syscalltablefile
=1
111 if [ -n "$1" -a -f "$1" ]; then
127 /^#/!s/\([{}()*,;]\)/ \1 /g
129 ' < "$input_file" | awk "
131 syslegal = \"$syslegal\"
132 sysprotofile = \"$sysprotofile\"
133 sysprotoend = \"$sysprotoend\"
134 sysproto_h = \"$sysproto_h\"
135 syscall_h = \"$syscall_h\"
137 syscalltablefile = \"$syscalltablefile\"
140 syscallnamesfile = \"$syscallnamesfile\"
141 syscallnamestempfile = \"$syscallnamestempfile\"
142 syshdrfile = \"$syshdrfile\"
143 syshdrtempfile = \"$syshdrtempfile\"
144 audittempfile = \"$audittempfile\"
145 tracecodetempfile = \"$tracecodetempfile\"
146 syscallprefix = \"$syscallprefix\"
147 switchname = \"$switchname\"
148 namesname = \"$namesname\"
149 infile = \"$input_file\"
152 printf "/*\n" > syslegal
153 printf " * Copyright (c) 2004-2008 Apple Inc. All rights reserved.\n" > syslegal
154 printf " * \n" > syslegal
155 printf " * @APPLE_OSREFERENCE_LICENSE_HEADER_START@\n" > syslegal
156 printf " * \n" > syslegal
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
165 printf " * \n" > syslegal
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
168 printf " * \n" > syslegal
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
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
185 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
186 printf "__private_extern__ const struct sysent %s[] = {\n",switchname > sysent
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
201 printf "#include <mach/shared_region.h>\n" > sysarg
202 printf "\n#ifdef KERNEL\n" > sysarg
203 printf "#ifdef __APPLE_API_PRIVATE\n" > sysarg
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
209 printf "#if CONFIG_REQUIRES_U32_MUNGING\n" > sysarg
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
212 printf "#else\n" > sysarg
213 printf "#define\tPAD_(t)\t(sizeof(uint32_t) <= sizeof(t) \\\n" > sysarg
214 printf " ? 0 : sizeof(uint32_t) - sizeof(t))\n" > sysarg
215 printf "#endif\n" > sysarg
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
224 printf "#include <sys/munge.h>\n" > sysarg
228 printf "const char *%s[] = {\n", namesname > syscallnamestempfile
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
238 NF == 0 || $1 ~ /^;/ {
241 $1 ~ /^#[ ]*include/ {
248 print > syscallnamestempfile
250 print > audittempfile
251 savesyscall = syscall_num
258 print > syscallnamestempfile
260 print > audittempfile
261 syscall_num = savesyscall
268 print > syscallnamestempfile
270 print > audittempfile
275 printf "%s: line %d: syscall number out of sync at %d\n",
276 infile, NR, syscall_num
281 function align_comment(linesize, location, thefile) {
282 printf(" ") > thefile
283 while (linesize < location) {
284 printf(" ") > thefile
288 function parserr(was, wanted) {
289 printf "%s: line %d: unexpected %s (expected %s)\n",
290 infile, NR, was, wanted
294 function parseline() {
296 current_field = 4 # skip number, audit event, type
303 additional_comments = " "
306 # find start and end of call name and arguments
307 if ($current_field != "{")
308 parserr($current_field, "{")
309 args_start = current_field
311 while (current_field <= NF) {
312 if ($current_field == "}") {
313 args_end = current_field
319 printf "%s: line %d: invalid call name and arguments\n",
324 # find start and end of optional comments
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
335 if (comments_end == 0) {
336 printf "%s: line %d: invalid comments \n",
342 if ($args_end != "}")
343 parserr($args_end, "}")
345 if ($args_end != ";")
346 parserr($args_end, ";")
349 # skip any NO_SYSCALL_STUB qualifier
350 if ($args_end == "NO_SYSCALL_STUB")
353 if ($args_end != ")")
354 parserr($args_end, ")")
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 " "
362 obs_comments = obs_comments $current_field "_"
366 sub(/old/, "obs", obs_comments)
367 obs_comments = substr(obs_comments, 1, length(obs_comments)-1)
368 if (obs_comments == "_") {
372 # get function return type
373 current_field = args_start + 1
374 returntype = $current_field
376 # get function name and set up to get arguments
378 funcname = $current_field
379 argalias = funcname "_args"
380 current_field++ # bump past function name
382 if ($current_field != "(")
383 parserr($current_field, "(")
386 if (current_field == args_end) {
387 if ($current_field != "void")
388 parserr($current_field, "argument definition")
392 # extract argument types and names
393 while (current_field <= args_end) {
398 while (current_field < args_end && $(current_field + 1) != ",") {
399 if (argtype[argc] != "" && oldf != "*") {
400 argtype[argc] = argtype[argc] " ";
402 argtype[argc] = argtype[argc] $current_field;
403 ext_argtype[argc] = argtype[argc];
404 oldf = $current_field;
407 if (argtype[argc] == "")
408 parserr($current_field, "argument definition")
409 argname[argc] = $current_field;
410 current_field += 2; # skip name, and any comma
413 printf "%s: line %d: too many arguments!\n", infile, NR
417 argssize = "AC(" argalias ")"
426 add_sysnames_entry = 1
427 add_sysheader_entry = 1
428 add_sysproto_entry = 1
434 add_sysnames_entry = 0
435 add_sysheader_entry = 0
436 add_sysproto_entry = 0
438 if (match($3, "[T]") != 0) {
442 if (match($3, "[N]") != 0) {
443 add_sysnames_entry = 1
446 if (match($3, "[H]") != 0) {
447 add_sysheader_entry = 1
450 if (match($3, "[P]") != 0) {
451 add_sysproto_entry = 1
455 if (files_keyword_OK == 0) {
456 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
464 # output function argument structures to sysproto.h and build the
465 # name of the appropriate argument mungers
469 if ((funcname != "nosys" && funcname != "enosys") || (syscall_num == 0 && funcname == "nosys")) {
471 if (add_sysproto_entry == 1) {
472 printf("struct %s {\n", argalias) > sysarg
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.
480 # see .../xnu/bsd/dev/munge.c for munge argument types.
481 if (argtype[i] == "long") {
482 ext_argtype[i] = "user_long_t";
483 munge32 = munge32 "s"
486 else if (argtype[i] == "u_long") {
487 ext_argtype[i] = "user_ulong_t";
488 munge32 = munge32 "w"
491 else if (argtype[i] == "size_t") {
492 ext_argtype[i] = "user_size_t";
493 munge32 = munge32 "w"
496 else if (argtype[i] == "ssize_t") {
497 ext_argtype[i] = "user_ssize_t";
498 munge32 = munge32 "s"
501 else if (argtype[i] == "user_ssize_t" || argtype[i] == "user_long_t") {
502 munge32 = munge32 "s"
505 else if (argtype[i] == "user_addr_t" || argtype[i] == "user_size_t" ||
506 argtype[i] == "user_ulong_t") {
507 munge32 = munge32 "w"
510 else if (argtype[i] == "caddr_t" || argtype[i] == "semun_t" ||
511 argtype[i] == "uuid_t" || match(argtype[i], "[\*]") != 0) {
512 ext_argtype[i] = "user_addr_t";
513 munge32 = munge32 "w"
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" ||
520 argtype[i] == "sigset_t" || argtype[i] == "gid_t" || argtype[i] == "unsigned int" ||
521 argtype[i] == "mode_t" || argtype[i] == "key_t" ||
522 argtype[i] == "mach_port_name_t" || argtype[i] == "au_asid_t" ||
523 argtype[i] == "sae_associd_t" || argtype[i] == "sae_connid_t") {
524 munge32 = munge32 "w"
527 else if (argtype[i] == "off_t" || argtype[i] == "int64_t" || argtype[i] == "uint64_t") {
528 munge32 = munge32 "l"
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",
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
546 if (add_sysproto_entry == 1) {
547 printf("};\n") > sysarg
550 else if (add_sysproto_entry == 1) {
551 printf("struct %s {\n\tint32_t dummy;\n};\n", argalias) > sysarg
555 # output to init_sysent.c
557 if (add_sysent_entry == 0) {
560 munge_ret = "_SYSCALL_RET_NONE"
561 if (tempname != "enosys") {
566 # figure out which return value type to munge
567 if (returntype == "user_addr_t") {
568 munge_ret = "_SYSCALL_RET_ADDR_T"
570 else if (returntype == "user_ssize_t") {
571 munge_ret = "_SYSCALL_RET_SSIZE_T"
573 else if (returntype == "user_size_t") {
574 munge_ret = "_SYSCALL_RET_SIZE_T"
576 else if (returntype == "int") {
577 munge_ret = "_SYSCALL_RET_INT_T"
579 else if (returntype == "u_int" || returntype == "mach_port_name_t") {
580 munge_ret = "_SYSCALL_RET_UINT_T"
582 else if (returntype == "uint32_t") {
583 munge_ret = "_SYSCALL_RET_UINT_T"
585 else if (returntype == "uint64_t") {
586 munge_ret = "_SYSCALL_RET_UINT64_T"
588 else if (returntype == "off_t") {
589 munge_ret = "_SYSCALL_RET_OFF_T"
591 else if (returntype == "void") {
592 munge_ret = "_SYSCALL_RET_NONE"
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",
603 printf("#if CONFIG_REQUIRES_U32_MUNGING || (__arm__ && (__BIGGEST_ALIGNMENT__ > 4))\n") > sysent
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) + \
607 length(munge_ret) + length(argssize) + length(size32) + 28
608 align_comment(linesize, 88, sysent)
609 printf("/* %d = %s%s*/\n", syscall_num, funcname, additional_comments) > sysent
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
615 # output to syscalls.c
616 if (add_sysnames_entry == 1) {
618 if (funcname == "nosys" || funcname == "enosys") {
619 if (syscall_num == 0)
622 tempname = "#" syscall_num
624 printf("\t\"%s\", ", tempname) > syscallnamestempfile
625 linesize = length(tempname) + 8
626 align_comment(linesize, 25, syscallnamestempfile)
627 if (substr(tempname,1,1) == "#") {
628 printf("/* %d =%s*/\n", syscall_num, additional_comments) > syscallnamestempfile
631 printf("/* %d = %s%s*/\n", syscall_num, tempname, additional_comments) > syscallnamestempfile
635 # output to syscalls.h
636 if (add_sysheader_entry == 1) {
638 if (syscall_num == 0) {
641 if (tempname != "nosys" && tempname != "enosys") {
642 printf("#define\t%s%s", syscallprefix, tempname) > syshdrtempfile
643 linesize = length(syscallprefix) + length(tempname) + 12
644 align_comment(linesize, 30, syshdrtempfile)
645 printf("%d\n", syscall_num) > syshdrtempfile
647 else if (skip_for_header == 0) {
648 printf("\t\t\t/* %d %s*/\n", syscall_num, additional_comments) > syshdrtempfile
652 # output function prototypes to sysproto.h
653 if (add_sysproto_entry == 1) {
654 if (funcname =="exit") {
655 printf("void %s(struct proc *, struct %s *, int32_t *);\n",
656 funcname, argalias) > sysprotoend
658 else if ((funcname != "nosys" && funcname != "enosys") || (syscall_num == 0 && funcname == "nosys")) {
659 printf("int %s(struct proc *, struct %s *, %s *);\n",
660 funcname, argalias, returntype) > sysprotoend
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
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
674 printf("0x40c%04x\tBSC%s\n", (syscall_num*4), obs_comments) > tracecodetempfile
677 sub(/^_+/, "", tempname)
678 printf("0x40c%04x\tBSC_%s\n", (syscall_num*4), tempname) > tracecodetempfile
687 printf "#define AC(name) (sizeof(struct name) / sizeof(syscall_arg_t))\n" > sysinc
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
698 printf("};\n") > sysent
699 printf("unsigned int nsysent = sizeof(sysent) / sizeof(sysent[0]);\n") > sysent
701 printf("};\n") > syscallnamestempfile
702 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall_num) \
704 printf("#define\t%sinvalid\t%d\n", syscallprefix, 63) \
706 printf("\n#endif /* __APPLE_API_PRIVATE */\n") > syshdrtempfile
707 printf("#endif /* !%s */\n", syscall_h) > syshdrtempfile
708 printf("};\n\n") > audittempfile
709 printf("#endif /* AUDIT */\n") > audittempfile
712 # define value in syscall table file to permit redifintion because of the way
713 # __private_extern__ (doesn't) work.
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
720 if [ $output_syscallnamesfile -eq 1 ]; then
721 cat $syslegal $syscallnamestempfile > $syscallnamesfile
724 if [ $output_sysprotofile -eq 1 ]; then
725 cat $syslegal $sysarg $sysprotoend > $sysprotofile
728 if [ $output_syshdrfile -eq 1 ]; then
729 cat $syslegal $syshdrtempfile > $syshdrfile
732 if [ $output_auditevfile -eq 1 ]; then
733 cat $syslegal $audittempfile > $auditevfile
736 if [ $output_tracecodes -eq 1 ]; then
737 if [ $use_stdout -eq 1 ]; then
738 cat $tracecodetempfile
740 cat $tracecodetempfile > $tracecodename