]>
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 Apple Computer, Inc. All rights reserved.
7 # @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
13 # License may not be used to create, or enable the creation or
14 # redistribution of, unlawful or unlicensed copies of an Apple operating
15 # system, or to circumvent, violate, or enable the circumvention or
16 # violation of, any terms of an Apple operating system software license
19 # Please obtain a copy of the License at
20 # http://www.opensource.apple.com/apsl/ and read it before using this
23 # The Original Code and all software distributed under the License are
24 # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
25 # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
26 # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
27 # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
28 # Please see the License for the specific language governing rights and
29 # limitations under the License.
31 # @APPLE_LICENSE_OSREFERENCE_HEADER_END@
37 syscallnamesfile
="syscalls.c"
38 sysprotofile
="../sys/sysproto.h"
39 sysproto_h
=_SYS_SYSPROTO_H_
40 syshdrfile
="../sys/syscall.h"
41 syscall_h
=_SYS_SYSCALL_H_
42 syscalltablefile
="init_sysent.c"
45 namesname
="syscallnames"
48 syslegal
="sysent.syslegal.$$"
49 sysent
="sysent.switch.$$"
50 sysinc
="sysinc.switch.$$"
51 sysarg
="sysarg.switch.$$"
52 sysprotoend
="sysprotoend.$$"
53 syscallnamestempfile
="syscallnamesfile.$$"
54 syshdrtempfile
="syshdrtempfile.$$"
56 trap "rm $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile" 0
58 touch $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile
61 0) echo "usage: $0 input-file <config-file>" 1>&2
66 if [ -n "$2" -a -f "$2" ]; then
80 /^#/!s/\([{}()*,]\)/ \1 /g
84 syslegal = \"$syslegal\"
85 sysprotofile = \"$sysprotofile\"
86 sysprotoend = \"$sysprotoend\"
87 sysproto_h = \"$sysproto_h\"
88 syscall_h = \"$syscall_h\"
90 syscalltablefile = \"$syscalltablefile\"
93 syscallnamesfile = \"$syscallnamesfile\"
94 syscallnamestempfile = \"$syscallnamestempfile\"
95 syshdrfile = \"$syshdrfile\"
96 syshdrtempfile = \"$syshdrtempfile\"
97 syscallprefix = \"$syscallprefix\"
98 switchname = \"$switchname\"
99 namesname = \"$namesname\"
103 printf "/*\n" > syslegal
104 printf " * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.\n" > syslegal
105 printf " * \n" > syslegal
106 printf " * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ \n" > syslegal
107 printf " * \n" > syslegal
108 printf " * This file contains Original Code and/or Modifications of Original Code \n" > syslegal
109 printf " * as defined in and that are subject to the Apple Public Source License \n" > syslegal
110 printf " * Version 2.0 (the \"License\"). You may not use this file except in \n" > syslegal
111 printf " * compliance with the License. The rights granted to you under the \n" > syslegal
112 printf " * License may not be used to create, or enable the creation or \n" > syslegal
113 printf " * redistribution of, unlawful or unlicensed copies of an Apple operating \n" > syslegal
114 printf " * system, or to circumvent, violate, or enable the circumvention or \n" > syslegal
115 printf " * violation of, any terms of an Apple operating system software license \n" > syslegal
116 printf " * agreement. \n" > syslegal
117 printf " * \n" > syslegal
118 printf " * Please obtain a copy of the License at \n" > syslegal
119 printf " * http://www.opensource.apple.com/apsl/ and read it before using this \n" > syslegal
120 printf " * file. \n" > syslegal
121 printf " * \n" > syslegal
122 printf " * The Original Code and all software distributed under the License are \n" > syslegal
123 printf " * distributed on an \"AS IS\" basis, WITHOUT WARRANTY OF ANY KIND, EITHER \n" > syslegal
124 printf " * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, \n" > syslegal
125 printf " * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, \n" > syslegal
126 printf " * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. \n" > syslegal
127 printf " * Please see the License for the specific language governing rights and \n" > syslegal
128 printf " * limitations under the License. \n" > syslegal
129 printf " * \n" > syslegal
130 printf " * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ \n" > syslegal
131 printf " * \n" > syslegal
132 printf " * \n" > syslegal
133 printf " * System call switch table.\n *\n" > syslegal
134 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syslegal
135 printf " * created from %s\n */\n\n", infile > syslegal
138 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
139 printf "__private_extern__ struct sysent %s[] = {\n",switchname > sysent
141 printf "#ifndef %s\n", sysproto_h > sysarg
142 printf "#define\t%s\n\n", sysproto_h > sysarg
143 printf "#ifndef %s\n", syscall_h > syshdrtempfile
144 printf "#define\t%s\n\n", syscall_h > syshdrtempfile
145 printf "#include <sys/appleapiopts.h>\n" > syshdrtempfile
146 printf "#ifdef __APPLE_API_PRIVATE\n" > syshdrtempfile
147 printf "#include <sys/appleapiopts.h>\n" > sysarg
148 printf "#include <sys/cdefs.h>\n" > sysarg
149 printf "#include <sys/mount_internal.h>\n" > sysarg
150 printf "#include <sys/types.h>\n" > sysarg
151 printf "#include <sys/sem_internal.h>\n" > sysarg
152 printf "#include <sys/semaphore.h>\n" > sysarg
153 printf "#include <sys/wait.h>\n" > sysarg
154 printf "#include <mach/shared_memory_server.h>\n" > sysarg
155 printf "\n#ifdef KERNEL\n" > sysarg
156 printf "#ifdef __APPLE_API_PRIVATE\n" > sysarg
157 printf "#define\tPAD_(t)\t(sizeof(uint64_t) <= sizeof(t) \\\n " > sysarg
158 printf "\t\t? 0 : sizeof(uint64_t) - sizeof(t))\n" > sysarg
159 printf "#if BYTE_ORDER == LITTLE_ENDIAN\n"> sysarg
160 printf "#define\tPADL_(t)\t0\n" > sysarg
161 printf "#define\tPADR_(t)\tPAD_(t)\n" > sysarg
162 printf "#else\n" > sysarg
163 printf "#define\tPADL_(t)\tPAD_(t)\n" > sysarg
164 printf "#define\tPADR_(t)\t0\n" > sysarg
165 printf "#endif\n" > sysarg
166 printf "\n__BEGIN_DECLS\n" > sysarg
167 printf "#ifndef __MUNGE_ONCE\n" > sysarg
168 printf "#define __MUNGE_ONCE\n" > sysarg
169 printf "void munge_w(const void *, void *); \n" > sysarg
170 printf "void munge_ww(const void *, void *); \n" > sysarg
171 printf "void munge_www(const void *, void *); \n" > sysarg
172 printf "void munge_wwww(const void *, void *); \n" > sysarg
173 printf "void munge_wwwww(const void *, void *); \n" > sysarg
174 printf "void munge_wwwwww(const void *, void *); \n" > sysarg
175 printf "void munge_wwwwwww(const void *, void *); \n" > sysarg
176 printf "void munge_wwwwwwww(const void *, void *); \n" > sysarg
177 printf "void munge_wl(const void *, void *); \n" > sysarg
178 printf "void munge_wlw(const void *, void *); \n" > sysarg
179 printf "void munge_wwwl(const void *, void *); \n" > sysarg
180 printf "void munge_wwwlww(const void *, void *); \n" > sysarg
181 printf "void munge_wwwwl(const void *, void *); \n" > sysarg
182 printf "void munge_wwwwwl(const void *, void *); \n" > sysarg
183 printf "void munge_wsw(const void *, void *); \n" > sysarg
184 printf "void munge_wws(const void *, void *); \n" > sysarg
185 printf "void munge_wwwsw(const void *, void *); \n" > sysarg
186 printf "#ifdef __ppc__\n" > sysarg
187 printf "void munge_d(const void *, void *); \n" > sysarg
188 printf "void munge_dd(const void *, void *); \n" > sysarg
189 printf "void munge_ddd(const void *, void *); \n" > sysarg
190 printf "void munge_dddd(const void *, void *); \n" > sysarg
191 printf "void munge_ddddd(const void *, void *); \n" > sysarg
192 printf "void munge_dddddd(const void *, void *); \n" > sysarg
193 printf "void munge_ddddddd(const void *, void *); \n" > sysarg
194 printf "void munge_dddddddd(const void *, void *); \n" > sysarg
195 printf "#else \n" > sysarg
196 printf "#define munge_d NULL \n" > sysarg
197 printf "#define munge_dd NULL \n" > sysarg
198 printf "#define munge_ddd NULL \n" > sysarg
199 printf "#define munge_dddd NULL \n" > sysarg
200 printf "#define munge_ddddd NULL \n" > sysarg
201 printf "#define munge_dddddd NULL \n" > sysarg
202 printf "#define munge_ddddddd NULL \n" > sysarg
203 printf "#define munge_dddddddd NULL \n" > sysarg
204 printf "#endif // __ppc__\n" > sysarg
205 printf "#endif /* !__MUNGE_ONCE */\n" > sysarg
209 printf "const char *%s[] = {\n", namesname > syscallnamestempfile
212 NF == 0 || $1 ~ /^;/ {
215 $1 ~ /^#[ ]*include/ {
222 print > syscallnamestempfile
223 print > syshdrtempfile
225 savesyscall = syscall
231 print > syscallnamestempfile
232 print > syshdrtempfile
234 syscall = savesyscall
240 print > syscallnamestempfile
241 print > syshdrtempfile
246 printf "%s: line %d: syscall number out of sync at %d\n",
252 function align_comment(linesize, location, thefile) {
253 printf(" ") > thefile
254 while (linesize < location) {
255 printf(" ") > thefile
259 function parserr(was, wanted) {
260 printf "%s: line %d: unexpected %s (expected %s)\n",
261 infile, NR, was, wanted
265 function parseline() {
274 additional_comments = " "
276 # find start and end of call name and arguments
277 if ($current_field != "{")
278 parserr($current_field, "{")
279 args_start = current_field
281 while (current_field <= NF) {
282 if ($current_field == "}") {
283 args_end = current_field
289 printf "%s: line %d: invalid call name and arguments\n",
294 # find start and end of optional comments
296 if (current_field < NF && $current_field == "{") {
297 comments_start = current_field
298 while (current_field <= NF) {
299 if ($current_field == "}") {
300 comments_end = current_field
305 if (comments_end == 0) {
306 printf "%s: line %d: invalid comments \n",
312 if ($args_end != "}")
313 parserr($args_end, "}")
315 if ($args_end != ";")
316 parserr($args_end, ";")
318 if ($args_end != ")")
319 parserr($args_end, ")")
322 # extract additional comments
323 if (comments_start != 0) {
324 current_field = comments_start + 1
325 while (current_field < comments_end) {
326 additional_comments = additional_comments $current_field " "
331 # get function return type
332 current_field = args_start + 1
333 returntype = $current_field
335 # get function name and set up to get arguments
337 funcname = $current_field
338 argalias = funcname "_args"
339 current_field++ # bump past function name
341 if ($current_field != "(")
342 parserr($current_field, "(")
345 if (current_field == args_end) {
346 if ($current_field != "void")
347 parserr($current_field, "argument definition")
351 # extract argument types and names
352 while (current_field <= args_end) {
357 while (current_field < args_end && $(current_field + 1) != ",") {
358 if (argtype[argc] != "" && oldf != "*") {
359 argtype[argc] = argtype[argc] " ";
361 argtype[argc] = argtype[argc] $current_field;
362 ext_argtype[argc] = argtype[argc];
363 oldf = $current_field;
366 if (argtype[argc] == "")
367 parserr($current_field, "argument definition")
368 argname[argc] = $current_field;
369 current_field += 2; # skip name, and any comma
372 printf "%s: line %d: too many arguments!\n", infile, NR
376 argssize = "AC(" argalias ")"
381 add_sysnames_entry = 1
382 add_sysheader_entry = 1
383 add_sysproto_entry = 1
385 add_64bit_fakesafe = 0
386 add_cancel_enable = "0"
389 add_cancel_enable = "_SYSCALL_CANCEL_NONE"
391 else if ($2 == "PRE") {
392 add_cancel_enable = "_SYSCALL_CANCEL_PRE"
394 else if ($2 == "POST") {
395 add_cancel_enable = "_SYSCALL_CANCEL_POST"
398 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
404 my_funnel = "KERNEL_FUNNEL"
406 else if ($3 == "NONE") {
407 my_funnel = "NO_FUNNEL"
410 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $3
414 if ($4 != "ALL" && $4 != "UALL") {
417 add_sysnames_entry = 0
418 add_sysheader_entry = 0
419 add_sysproto_entry = 0
421 if (match($4, "[T]") != 0) {
425 if (match($4, "[N]") != 0) {
426 add_sysnames_entry = 1
429 if (match($4, "[H]") != 0) {
430 add_sysheader_entry = 1
433 if (match($4, "[P]") != 0) {
434 add_sysproto_entry = 1
437 if (match($4, "[U]") != 0) {
440 if (match($4, "[F]") != 0) {
441 add_64bit_fakesafe = 1
444 if (files_keyword_OK == 0) {
445 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $4
449 else if ($4 == "UALL") {
450 add_64bit_unsafe = 1;
456 # output function argument structures to sysproto.h and build the
457 # name of the appropriate argument mungers
460 if (funcname != "nosys" || (syscall == 0 && funcname == "nosys")) {
462 if (add_sysproto_entry == 1) {
463 printf("struct %s {\n", argalias) > sysarg
467 for (i = 1; i <= argc; i++) {
468 # Build name of argument munger.
469 # We account for all sys call argument types here.
470 # This is where you add any new types. With LP64 support
471 # each argument consumes 64-bits.
472 # see .../xnu/bsd/dev/ppc/munge.s for munge argument types.
473 if (argtype[i] == "long") {
474 if (add_64bit_unsafe == 0)
475 ext_argtype[i] = "user_long_t";
476 munge32 = munge32 "s"
477 munge64 = munge64 "d"
479 else if (argtype[i] == "u_long") {
480 if (add_64bit_unsafe == 0)
481 ext_argtype[i] = "user_ulong_t";
482 munge32 = munge32 "w"
483 munge64 = munge64 "d"
485 else if (argtype[i] == "size_t") {
486 if (add_64bit_unsafe == 0)
487 ext_argtype[i] = "user_size_t";
488 munge32 = munge32 "w"
489 munge64 = munge64 "d"
491 else if (argtype[i] == "ssize_t") {
492 if (add_64bit_unsafe == 0)
493 ext_argtype[i] = "user_ssize_t";
494 munge32 = munge32 "s"
495 munge64 = munge64 "d"
497 else if (argtype[i] == "user_ssize_t" || argtype[i] == "user_long_t") {
498 munge32 = munge32 "s"
499 munge64 = munge64 "d"
501 else if (argtype[i] == "user_addr_t" || argtype[i] == "user_size_t" ||
502 argtype[i] == "user_ulong_t") {
503 munge32 = munge32 "w"
504 munge64 = munge64 "d"
506 else if (argtype[i] == "caddr_t" || argtype[i] == "semun_t" ||
507 match(argtype[i], "[\*]") != 0) {
508 if (add_64bit_unsafe == 0)
509 ext_argtype[i] = "user_addr_t";
510 munge32 = munge32 "w"
511 munge64 = munge64 "d"
513 else if (argtype[i] == "int" || argtype[i] == "u_int" ||
514 argtype[i] == "uid_t" || argtype[i] == "pid_t" ||
515 argtype[i] == "id_t" || argtype[i] == "idtype_t" ||
516 argtype[i] == "socklen_t" || argtype[i] == "uint32_t" || argtype[i] == "int32_t" ||
517 argtype[i] == "sigset_t" || argtype[i] == "gid_t" ||
518 argtype[i] == "mode_t" || argtype[i] == "key_t" || argtype[i] == "time_t") {
519 munge32 = munge32 "w"
520 munge64 = munge64 "d"
522 else if (argtype[i] == "off_t" || argtype[i] == "int64_t" || argtype[i] == "uint64_t") {
523 munge32 = munge32 "l"
524 munge64 = munge64 "d"
527 printf "%s: line %d: invalid type \"%s\" \n",
528 infile, NR, argtype[i]
529 printf "You need to add \"%s\" into the type checking code. \n",
533 if (add_sysproto_entry == 1) {
534 printf("\tchar %s_l_[PADL_(%s)]; " \
535 "%s %s; char %s_r_[PADR_(%s)];\n",
536 argname[i], ext_argtype[i],
537 ext_argtype[i], argname[i],
538 argname[i], ext_argtype[i]) > sysarg
541 if (add_sysproto_entry == 1) {
542 printf("};\n") > sysarg
545 else if (add_sysproto_entry == 1) {
546 printf("struct %s {\n\tregister_t dummy;\n};\n", argalias) > sysarg
550 # output to init_sysent.c
552 if (add_sysent_entry == 0) {
556 munge_ret = "_SYSCALL_RET_NONE"
560 # figure out which return value type to munge
561 if (returntype == "user_addr_t") {
562 munge_ret = "_SYSCALL_RET_ADDR_T"
564 else if (returntype == "user_ssize_t") {
565 munge_ret = "_SYSCALL_RET_SSIZE_T"
567 else if (returntype == "user_size_t") {
568 munge_ret = "_SYSCALL_RET_SIZE_T"
570 else if (returntype == "int") {
571 munge_ret = "_SYSCALL_RET_INT_T"
573 else if (returntype == "u_int") {
574 munge_ret = "_SYSCALL_RET_UINT_T"
576 else if (returntype == "off_t") {
577 munge_ret = "_SYSCALL_RET_OFF_T"
579 else if (returntype == "void") {
580 munge_ret = "_SYSCALL_RET_NONE"
583 printf "%s: line %d: invalid return type \"%s\" \n",
584 infile, NR, returntype
585 printf "You need to add \"%s\" into the return type checking code. \n",
591 if (add_64bit_unsafe == 1 && add_64bit_fakesafe == 0)
592 my_funnel = my_funnel "|UNSAFE_64BIT";
594 printf("\t{%s, %s, %s, \(sy_call_t *\)%s, %s, %s, %s},",
595 argssize, add_cancel_enable, my_funnel, tempname, munge32, munge64, munge_ret) > sysent
596 linesize = length(argssize) + length(add_cancel_enable) + length(my_funnel) + length(tempname) + \
597 length(munge32) + length(munge64) + length(munge_ret) + 28
598 align_comment(linesize, 88, sysent)
599 printf("/* %d = %s%s*/\n", syscall, funcname, additional_comments) > sysent
601 # output to syscalls.c
602 if (add_sysnames_entry == 1) {
604 if (funcname == "nosys") {
608 tempname = "#" syscall
610 printf("\t\"%s\", ", tempname) > syscallnamestempfile
611 linesize = length(tempname) + 8
612 align_comment(linesize, 25, syscallnamestempfile)
613 if (substr(tempname,1,1) == "#") {
614 printf("/* %d =%s*/\n", syscall, additional_comments) > syscallnamestempfile
617 printf("/* %d = %s%s*/\n", syscall, tempname, additional_comments) > syscallnamestempfile
621 # output to syscalls.h
622 if (add_sysheader_entry == 1) {
627 if (tempname != "nosys") {
628 printf("#define\t%s%s", syscallprefix, tempname) > syshdrtempfile
629 linesize = length(syscallprefix) + length(tempname) + 12
630 align_comment(linesize, 30, syshdrtempfile)
631 printf("%d\n", syscall) > syshdrtempfile
632 # special case for gettimeofday on ppc - cctools project uses old name
633 if (tempname == "ppc_gettimeofday") {
634 printf("#define\t%s%s", syscallprefix, "gettimeofday") > syshdrtempfile
635 linesize = length(syscallprefix) + length(tempname) + 12
636 align_comment(linesize, 30, syshdrtempfile)
637 printf("%d\n", syscall) > syshdrtempfile
641 printf("\t\t\t/* %d %s*/\n", syscall, additional_comments) > syshdrtempfile
645 # output function prototypes to sysproto.h
646 if (add_sysproto_entry == 1) {
647 if (funcname =="exit") {
648 printf("void %s(struct proc *, struct %s *, int *);\n",
649 funcname, argalias) > sysprotoend
651 else if (funcname != "nosys" || (syscall == 0 && funcname == "nosys")) {
652 printf("int %s(struct proc *, struct %s *, %s *);\n",
653 funcname, argalias, returntype) > sysprotoend
662 printf "#define AC(name) (sizeof(struct name) / sizeof(uint64_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
676 printf("};\n") > syscallnamestempfile
677 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
679 printf("\n#endif /* __APPLE_API_PRIVATE */\n") > syshdrtempfile
680 printf("#endif /* !%s */\n", syscall_h) > syshdrtempfile
683 cat $syslegal $sysinc $sysent > $syscalltablefile
684 cat $syslegal $sysarg $sysprotoend > $sysprotofile
685 cat $syslegal $syscallnamestempfile > $syscallnamesfile
686 cat $syslegal $syshdrtempfile > $syshdrfile