]>
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
39 syscallnamesfile
="syscalls.c"
40 sysprotofile
="sysproto.h"
41 sysproto_h
=_SYS_SYSPROTO_H_
42 syshdrfile
="syscall.h"
43 syscall_h
=_SYS_SYSCALL_H_
44 syscalltablefile
="init_sysent.c"
45 auditevfile
="audit_kevents.c"
48 namesname
="syscallnames"
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.$$"
58 audittempfile
="audittempfile.$$"
60 trap "rm $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile $audittempfile" 0
62 touch $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile $audittempfile
66 echo "usage: $0 input-file [<names|proto|header|table|audit> [<config-file>]]" 1>&2
77 output_syscallnamesfile
=1
86 output_syscalltablefile
=1
94 output_syscallnamesfile
=1
97 output_syscalltablefile
=1
101 if [ -n "$1" -a -f "$1" ]; then
117 /^#/!s/\([{}()*,;]\)/ \1 /g
119 ' < "$input_file" | awk "
121 syslegal = \"$syslegal\"
122 sysprotofile = \"$sysprotofile\"
123 sysprotoend = \"$sysprotoend\"
124 sysproto_h = \"$sysproto_h\"
125 syscall_h = \"$syscall_h\"
127 syscalltablefile = \"$syscalltablefile\"
130 syscallnamesfile = \"$syscallnamesfile\"
131 syscallnamestempfile = \"$syscallnamestempfile\"
132 syshdrfile = \"$syshdrfile\"
133 syshdrtempfile = \"$syshdrtempfile\"
134 audittempfile = \"$audittempfile\"
135 syscallprefix = \"$syscallprefix\"
136 switchname = \"$switchname\"
137 namesname = \"$namesname\"
138 infile = \"$input_file\"
141 printf "/*\n" > syslegal
142 printf " * Copyright (c) 2004-2008 Apple Inc. All rights reserved.\n" > syslegal
143 printf " * \n" > syslegal
144 printf " * @APPLE_OSREFERENCE_LICENSE_HEADER_START@\n" > syslegal
145 printf " * \n" > syslegal
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
154 printf " * \n" > syslegal
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
157 printf " * \n" > syslegal
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
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
174 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
175 printf "__private_extern__ const struct sysent %s[] = {\n",switchname > sysent
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
190 printf "#include <mach/shared_region.h>\n" > sysarg
191 printf "\n#ifdef KERNEL\n" > sysarg
192 printf "#ifdef __APPLE_API_PRIVATE\n" > sysarg
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
198 printf "#if CONFIG_REQUIRES_U32_MUNGING\n" > sysarg
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
201 printf "#else\n" > sysarg
202 printf "#define\tPAD_(t)\t(sizeof(uint32_t) <= sizeof(t) \\\n" > sysarg
203 printf " ? 0 : sizeof(uint32_t) - sizeof(t))\n" > sysarg
204 printf "#endif\n" > sysarg
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
213 printf "#include <sys/munge.h>\n" > sysarg
217 printf "const char *%s[] = {\n", namesname > syscallnamestempfile
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
227 NF == 0 || $1 ~ /^;/ {
230 $1 ~ /^#[ ]*include/ {
237 print > syscallnamestempfile
239 print > audittempfile
240 savesyscall = syscall_num
247 print > syscallnamestempfile
249 print > audittempfile
250 syscall_num = savesyscall
257 print > syscallnamestempfile
259 print > audittempfile
264 printf "%s: line %d: syscall number out of sync at %d\n",
265 infile, NR, syscall_num
270 function align_comment(linesize, location, thefile) {
271 printf(" ") > thefile
272 while (linesize < location) {
273 printf(" ") > thefile
277 function parserr(was, wanted) {
278 printf "%s: line %d: unexpected %s (expected %s)\n",
279 infile, NR, was, wanted
283 function parseline() {
285 current_field = 4 # skip number, audit event, type
292 additional_comments = " "
294 # find start and end of call name and arguments
295 if ($current_field != "{")
296 parserr($current_field, "{")
297 args_start = current_field
299 while (current_field <= NF) {
300 if ($current_field == "}") {
301 args_end = current_field
307 printf "%s: line %d: invalid call name and arguments\n",
312 # find start and end of optional comments
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
323 if (comments_end == 0) {
324 printf "%s: line %d: invalid comments \n",
330 if ($args_end != "}")
331 parserr($args_end, "}")
333 if ($args_end != ";")
334 parserr($args_end, ";")
337 # skip any NO_SYSCALL_STUB qualifier
338 if ($args_end == "NO_SYSCALL_STUB")
341 if ($args_end != ")")
342 parserr($args_end, ")")
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 " "
354 # get function return type
355 current_field = args_start + 1
356 returntype = $current_field
358 # get function name and set up to get arguments
360 funcname = $current_field
361 argalias = funcname "_args"
362 current_field++ # bump past function name
364 if ($current_field != "(")
365 parserr($current_field, "(")
368 if (current_field == args_end) {
369 if ($current_field != "void")
370 parserr($current_field, "argument definition")
374 # extract argument types and names
375 while (current_field <= args_end) {
380 while (current_field < args_end && $(current_field + 1) != ",") {
381 if (argtype[argc] != "" && oldf != "*") {
382 argtype[argc] = argtype[argc] " ";
384 argtype[argc] = argtype[argc] $current_field;
385 ext_argtype[argc] = argtype[argc];
386 oldf = $current_field;
389 if (argtype[argc] == "")
390 parserr($current_field, "argument definition")
391 argname[argc] = $current_field;
392 current_field += 2; # skip name, and any comma
395 printf "%s: line %d: too many arguments!\n", infile, NR
399 argssize = "AC(" argalias ")"
408 add_sysnames_entry = 1
409 add_sysheader_entry = 1
410 add_sysproto_entry = 1
416 add_sysnames_entry = 0
417 add_sysheader_entry = 0
418 add_sysproto_entry = 0
420 if (match($3, "[T]") != 0) {
424 if (match($3, "[N]") != 0) {
425 add_sysnames_entry = 1
428 if (match($3, "[H]") != 0) {
429 add_sysheader_entry = 1
432 if (match($3, "[P]") != 0) {
433 add_sysproto_entry = 1
437 if (files_keyword_OK == 0) {
438 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
446 # output function argument structures to sysproto.h and build the
447 # name of the appropriate argument mungers
451 if ((funcname != "nosys" && funcname != "enosys") || (syscall_num == 0 && funcname == "nosys")) {
453 if (add_sysproto_entry == 1) {
454 printf("struct %s {\n", argalias) > sysarg
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.
462 # see .../xnu/bsd/dev/munge.c for munge argument types.
463 if (argtype[i] == "long") {
464 ext_argtype[i] = "user_long_t";
465 munge32 = munge32 "s"
468 else if (argtype[i] == "u_long") {
469 ext_argtype[i] = "user_ulong_t";
470 munge32 = munge32 "w"
473 else if (argtype[i] == "size_t") {
474 ext_argtype[i] = "user_size_t";
475 munge32 = munge32 "w"
478 else if (argtype[i] == "ssize_t") {
479 ext_argtype[i] = "user_ssize_t";
480 munge32 = munge32 "s"
483 else if (argtype[i] == "user_ssize_t" || argtype[i] == "user_long_t") {
484 munge32 = munge32 "s"
487 else if (argtype[i] == "user_addr_t" || argtype[i] == "user_size_t" ||
488 argtype[i] == "user_ulong_t") {
489 munge32 = munge32 "w"
492 else if (argtype[i] == "caddr_t" || argtype[i] == "semun_t" ||
493 argtype[i] == "uuid_t" || match(argtype[i], "[\*]") != 0) {
494 ext_argtype[i] = "user_addr_t";
495 munge32 = munge32 "w"
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" ||
502 argtype[i] == "sigset_t" || argtype[i] == "gid_t" || argtype[i] == "unsigned int" ||
503 argtype[i] == "mode_t" || argtype[i] == "key_t" ||
504 argtype[i] == "mach_port_name_t" || argtype[i] == "au_asid_t" ||
505 argtype[i] == "associd_t" || argtype[i] == "connid_t") {
506 munge32 = munge32 "w"
509 else if (argtype[i] == "off_t" || argtype[i] == "int64_t" || argtype[i] == "uint64_t") {
510 munge32 = munge32 "l"
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",
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
528 if (add_sysproto_entry == 1) {
529 printf("};\n") > sysarg
532 else if (add_sysproto_entry == 1) {
533 printf("struct %s {\n\tint32_t dummy;\n};\n", argalias) > sysarg
537 # output to init_sysent.c
539 if (add_sysent_entry == 0) {
542 munge_ret = "_SYSCALL_RET_NONE"
543 if (tempname != "enosys") {
548 # figure out which return value type to munge
549 if (returntype == "user_addr_t") {
550 munge_ret = "_SYSCALL_RET_ADDR_T"
552 else if (returntype == "user_ssize_t") {
553 munge_ret = "_SYSCALL_RET_SSIZE_T"
555 else if (returntype == "user_size_t") {
556 munge_ret = "_SYSCALL_RET_SIZE_T"
558 else if (returntype == "int") {
559 munge_ret = "_SYSCALL_RET_INT_T"
561 else if (returntype == "u_int" || returntype == "mach_port_name_t") {
562 munge_ret = "_SYSCALL_RET_UINT_T"
564 else if (returntype == "uint32_t") {
565 munge_ret = "_SYSCALL_RET_UINT_T"
567 else if (returntype == "uint64_t") {
568 munge_ret = "_SYSCALL_RET_UINT64_T"
570 else if (returntype == "off_t") {
571 munge_ret = "_SYSCALL_RET_OFF_T"
573 else if (returntype == "void") {
574 munge_ret = "_SYSCALL_RET_NONE"
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",
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) + \
589 length(munge_ret) + length(argssize) + length(size32) + 28
590 align_comment(linesize, 88, sysent)
591 printf("/* %d = %s%s*/\n", syscall_num, funcname, additional_comments) > sysent
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
597 # output to syscalls.c
598 if (add_sysnames_entry == 1) {
600 if (funcname == "nosys" || funcname == "enosys") {
601 if (syscall_num == 0)
604 tempname = "#" syscall_num
606 printf("\t\"%s\", ", tempname) > syscallnamestempfile
607 linesize = length(tempname) + 8
608 align_comment(linesize, 25, syscallnamestempfile)
609 if (substr(tempname,1,1) == "#") {
610 printf("/* %d =%s*/\n", syscall_num, additional_comments) > syscallnamestempfile
613 printf("/* %d = %s%s*/\n", syscall_num, tempname, additional_comments) > syscallnamestempfile
617 # output to syscalls.h
618 if (add_sysheader_entry == 1) {
620 if (syscall_num == 0) {
623 if (tempname != "nosys" && tempname != "enosys") {
624 printf("#define\t%s%s", syscallprefix, tempname) > syshdrtempfile
625 linesize = length(syscallprefix) + length(tempname) + 12
626 align_comment(linesize, 30, syshdrtempfile)
627 printf("%d\n", syscall_num) > syshdrtempfile
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)
633 printf("%d\n", syscall_num) > syshdrtempfile
636 else if (skip_for_header == 0) {
637 printf("\t\t\t/* %d %s*/\n", syscall_num, additional_comments) > syshdrtempfile
641 # output function prototypes to sysproto.h
642 if (add_sysproto_entry == 1) {
643 if (funcname =="exit") {
644 printf("void %s(struct proc *, struct %s *, int32_t *);\n",
645 funcname, argalias) > sysprotoend
647 else if ((funcname != "nosys" && funcname != "enosys") || (syscall_num == 0 && funcname == "nosys")) {
648 printf("int %s(struct proc *, struct %s *, %s *);\n",
649 funcname, argalias, returntype) > sysprotoend
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
662 printf "#define AC(name) (sizeof(struct name) / sizeof(syscall_arg_t))\n" > sysinc
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
673 printf("};\n") > sysent
674 printf("int nsysent = sizeof(sysent) / sizeof(sysent[0]);\n") > sysent
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
678 printf("};\n") > syscallnamestempfile
679 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall_num) \
681 printf("\n#endif /* __APPLE_API_PRIVATE */\n") > syshdrtempfile
682 printf("#endif /* !%s */\n", syscall_h) > syshdrtempfile
683 printf("};\n\n") > audittempfile
684 printf("#endif /* AUDIT */\n") > audittempfile
687 # define value in syscall table file to permit redifintion because of the way
688 # __private_extern__ (doesn't) work.
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
695 if [ $output_syscallnamesfile -eq 1 ]; then
696 cat $syslegal $syscallnamestempfile > $syscallnamesfile
699 if [ $output_sysprotofile -eq 1 ]; then
700 cat $syslegal $sysarg $sysprotoend > $sysprotofile
703 if [ $output_syshdrfile -eq 1 ]; then
704 cat $syslegal $syshdrtempfile > $syshdrfile
707 if [ $output_auditevfile -eq 1 ]; then
708 cat $syslegal $audittempfile > $auditevfile