]>
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_HEADER_START@
9 # The contents of this file constitute Original Code as defined in and
10 # are subject to the Apple Public Source License Version 1.1 (the
11 # "License"). You may not use this file except in compliance with the
12 # License. Please obtain a copy of the License at
13 # http://www.apple.com/publicsource and read it before using this file.
15 # This Original Code and all software distributed under the License are
16 # distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
20 # License for the specific language governing rights and limitations
23 # @APPLE_LICENSE_HEADER_END@
29 syscallnamesfile
="syscalls.c"
30 sysprotofile
="../sys/sysproto.h"
31 sysproto_h
=_SYS_SYSPROTO_H_
32 syshdrfile
="../sys/syscall.h"
33 syscall_h
=_SYS_SYSCALL_H_
34 syscalltablefile
="init_sysent.c"
37 namesname
="syscallnames"
40 syslegal
="sysent.syslegal.$$"
41 sysent
="sysent.switch.$$"
42 sysinc
="sysinc.switch.$$"
43 sysarg
="sysarg.switch.$$"
44 sysprotoend
="sysprotoend.$$"
45 syscallnamestempfile
="syscallnamesfile.$$"
46 syshdrtempfile
="syshdrtempfile.$$"
48 trap "rm $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile" 0
50 touch $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile
53 0) echo "usage: $0 input-file <config-file>" 1>&2
58 if [ -n "$2" -a -f "$2" ]; then
72 /^#/!s/\([{}()*,]\)/ \1 /g
76 syslegal = \"$syslegal\"
77 sysprotofile = \"$sysprotofile\"
78 sysprotoend = \"$sysprotoend\"
79 sysproto_h = \"$sysproto_h\"
80 syscall_h = \"$syscall_h\"
82 syscalltablefile = \"$syscalltablefile\"
85 syscallnamesfile = \"$syscallnamesfile\"
86 syscallnamestempfile = \"$syscallnamestempfile\"
87 syshdrfile = \"$syshdrfile\"
88 syshdrtempfile = \"$syshdrtempfile\"
89 syscallprefix = \"$syscallprefix\"
90 switchname = \"$switchname\"
91 namesname = \"$namesname\"
95 printf "/*\n" > syslegal
96 printf " * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.\n" > syslegal
97 printf " * \n" > syslegal
98 printf " * @APPLE_LICENSE_HEADER_START@ \n" > syslegal
99 printf " * \n" > syslegal
100 printf " * The contents of this file constitute Original Code as defined in and \n" > syslegal
101 printf " * are subject to the Apple Public Source License Version 1.1 (the \n" > syslegal
102 printf " * \"License\"). You may not use this file except in compliance with the \n" > syslegal
103 printf " * License. Please obtain a copy of the License at \n" > syslegal
104 printf " * http://www.apple.com/publicsource and read it before using this file. \n" > syslegal
105 printf " * \n" > syslegal
106 printf " * This Original Code and all software distributed under the License are \n" > syslegal
107 printf " * distributed on an \"AS IS\" basis, WITHOUT WARRANTY OF ANY KIND, EITHER \n" > syslegal
108 printf " * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, \n" > syslegal
109 printf " * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, \n" > syslegal
110 printf " * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the \n" > syslegal
111 printf " * License for the specific language governing rights and limitations \n" > syslegal
112 printf " * under the License. \n" > syslegal
113 printf " * \n" > syslegal
114 printf " * @APPLE_LICENSE_HEADER_END@ \n" > syslegal
115 printf " * \n" > syslegal
116 printf " * \n" > syslegal
117 printf " * System call switch table.\n *\n" > syslegal
118 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syslegal
119 printf " * created from %s\n */\n\n", infile > syslegal
122 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
123 printf "__private_extern__ struct sysent %s[] = {\n",switchname > sysent
125 printf "#ifndef %s\n", sysproto_h > sysarg
126 printf "#define\t%s\n\n", sysproto_h > sysarg
127 printf "#ifndef %s\n", syscall_h > syshdrtempfile
128 printf "#define\t%s\n\n", syscall_h > syshdrtempfile
129 printf "#include <sys/appleapiopts.h>\n" > syshdrtempfile
130 printf "#ifdef __APPLE_API_PRIVATE\n" > syshdrtempfile
131 printf "#include <sys/appleapiopts.h>\n" > sysarg
132 printf "#include <sys/cdefs.h>\n" > sysarg
133 printf "#include <sys/mount_internal.h>\n" > sysarg
134 printf "#include <sys/types.h>\n" > sysarg
135 printf "#include <sys/sem_internal.h>\n" > sysarg
136 printf "#include <sys/semaphore.h>\n" > sysarg
137 printf "#include <sys/wait.h>\n" > sysarg
138 printf "#include <mach/shared_memory_server.h>\n" > sysarg
139 printf "\n#ifdef KERNEL\n" > sysarg
140 printf "#ifdef __APPLE_API_PRIVATE\n" > sysarg
141 printf "#define\tPAD_(t)\t(sizeof(uint64_t) <= sizeof(t) \\\n " > sysarg
142 printf "\t\t? 0 : sizeof(uint64_t) - sizeof(t))\n" > sysarg
143 printf "#if BYTE_ORDER == LITTLE_ENDIAN\n"> sysarg
144 printf "#define\tPADL_(t)\t0\n" > sysarg
145 printf "#define\tPADR_(t)\tPAD_(t)\n" > sysarg
146 printf "#else\n" > sysarg
147 printf "#define\tPADL_(t)\tPAD_(t)\n" > sysarg
148 printf "#define\tPADR_(t)\t0\n" > sysarg
149 printf "#endif\n" > sysarg
150 printf "\n__BEGIN_DECLS\n" > sysarg
151 printf "#ifndef __MUNGE_ONCE\n" > sysarg
152 printf "#define __MUNGE_ONCE\n" > sysarg
153 printf "void munge_w(const void *, void *); \n" > sysarg
154 printf "void munge_ww(const void *, void *); \n" > sysarg
155 printf "void munge_www(const void *, void *); \n" > sysarg
156 printf "void munge_wwww(const void *, void *); \n" > sysarg
157 printf "void munge_wwwww(const void *, void *); \n" > sysarg
158 printf "void munge_wwwwww(const void *, void *); \n" > sysarg
159 printf "void munge_wwwwwww(const void *, void *); \n" > sysarg
160 printf "void munge_wwwwwwww(const void *, void *); \n" > sysarg
161 printf "void munge_wl(const void *, void *); \n" > sysarg
162 printf "void munge_wlw(const void *, void *); \n" > sysarg
163 printf "void munge_wwwl(const void *, void *); \n" > sysarg
164 printf "void munge_wwwlww(const void *, void *); \n" > sysarg
165 printf "void munge_wwwwl(const void *, void *); \n" > sysarg
166 printf "void munge_wwwwwl(const void *, void *); \n" > sysarg
167 printf "void munge_wsw(const void *, void *); \n" > sysarg
168 printf "void munge_wws(const void *, void *); \n" > sysarg
169 printf "void munge_wwwsw(const void *, void *); \n" > sysarg
170 printf "#ifdef __ppc__\n" > sysarg
171 printf "void munge_d(const void *, void *); \n" > sysarg
172 printf "void munge_dd(const void *, void *); \n" > sysarg
173 printf "void munge_ddd(const void *, void *); \n" > sysarg
174 printf "void munge_dddd(const void *, void *); \n" > sysarg
175 printf "void munge_ddddd(const void *, void *); \n" > sysarg
176 printf "void munge_dddddd(const void *, void *); \n" > sysarg
177 printf "void munge_ddddddd(const void *, void *); \n" > sysarg
178 printf "void munge_dddddddd(const void *, void *); \n" > sysarg
179 printf "#else \n" > sysarg
180 printf "#define munge_d NULL \n" > sysarg
181 printf "#define munge_dd NULL \n" > sysarg
182 printf "#define munge_ddd NULL \n" > sysarg
183 printf "#define munge_dddd NULL \n" > sysarg
184 printf "#define munge_ddddd NULL \n" > sysarg
185 printf "#define munge_dddddd NULL \n" > sysarg
186 printf "#define munge_ddddddd NULL \n" > sysarg
187 printf "#define munge_dddddddd NULL \n" > sysarg
188 printf "#endif // __ppc__\n" > sysarg
189 printf "#endif /* !__MUNGE_ONCE */\n" > sysarg
193 printf "const char *%s[] = {\n", namesname > syscallnamestempfile
196 NF == 0 || $1 ~ /^;/ {
199 $1 ~ /^#[ ]*include/ {
206 print > syscallnamestempfile
207 print > syshdrtempfile
209 savesyscall = syscall
215 print > syscallnamestempfile
216 print > syshdrtempfile
218 syscall = savesyscall
224 print > syscallnamestempfile
225 print > syshdrtempfile
230 printf "%s: line %d: syscall number out of sync at %d\n",
236 function align_comment(linesize, location, thefile) {
237 printf(" ") > thefile
238 while (linesize < location) {
239 printf(" ") > thefile
243 function parserr(was, wanted) {
244 printf "%s: line %d: unexpected %s (expected %s)\n",
245 infile, NR, was, wanted
249 function parseline() {
258 additional_comments = " "
260 # find start and end of call name and arguments
261 if ($current_field != "{")
262 parserr($current_field, "{")
263 args_start = current_field
265 while (current_field <= NF) {
266 if ($current_field == "}") {
267 args_end = current_field
273 printf "%s: line %d: invalid call name and arguments\n",
278 # find start and end of optional comments
280 if (current_field < NF && $current_field == "{") {
281 comments_start = current_field
282 while (current_field <= NF) {
283 if ($current_field == "}") {
284 comments_end = current_field
289 if (comments_end == 0) {
290 printf "%s: line %d: invalid comments \n",
296 if ($args_end != "}")
297 parserr($args_end, "}")
299 if ($args_end != ";")
300 parserr($args_end, ";")
302 if ($args_end != ")")
303 parserr($args_end, ")")
306 # extract additional comments
307 if (comments_start != 0) {
308 current_field = comments_start + 1
309 while (current_field < comments_end) {
310 additional_comments = additional_comments $current_field " "
315 # get function return type
316 current_field = args_start + 1
317 returntype = $current_field
319 # get function name and set up to get arguments
321 funcname = $current_field
322 argalias = funcname "_args"
323 current_field++ # bump past function name
325 if ($current_field != "(")
326 parserr($current_field, "(")
329 if (current_field == args_end) {
330 if ($current_field != "void")
331 parserr($current_field, "argument definition")
335 # extract argument types and names
336 while (current_field <= args_end) {
341 while (current_field < args_end && $(current_field + 1) != ",") {
342 if (argtype[argc] != "" && oldf != "*") {
343 argtype[argc] = argtype[argc] " ";
345 argtype[argc] = argtype[argc] $current_field;
346 ext_argtype[argc] = argtype[argc];
347 oldf = $current_field;
350 if (argtype[argc] == "")
351 parserr($current_field, "argument definition")
352 argname[argc] = $current_field;
353 current_field += 2; # skip name, and any comma
356 printf "%s: line %d: too many arguments!\n", infile, NR
360 argssize = "AC(" argalias ")"
365 add_sysnames_entry = 1
366 add_sysheader_entry = 1
367 add_sysproto_entry = 1
369 add_64bit_fakesafe = 0
370 add_cancel_enable = "0"
373 add_cancel_enable = "_SYSCALL_CANCEL_NONE"
375 else if ($2 == "PRE") {
376 add_cancel_enable = "_SYSCALL_CANCEL_PRE"
378 else if ($2 == "POST") {
379 add_cancel_enable = "_SYSCALL_CANCEL_POST"
382 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
388 my_funnel = "KERNEL_FUNNEL"
390 else if ($3 == "NONE") {
391 my_funnel = "NO_FUNNEL"
394 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $3
398 if ($4 != "ALL" && $4 != "UALL") {
401 add_sysnames_entry = 0
402 add_sysheader_entry = 0
403 add_sysproto_entry = 0
405 if (match($4, "[T]") != 0) {
409 if (match($4, "[N]") != 0) {
410 add_sysnames_entry = 1
413 if (match($4, "[H]") != 0) {
414 add_sysheader_entry = 1
417 if (match($4, "[P]") != 0) {
418 add_sysproto_entry = 1
421 if (match($4, "[U]") != 0) {
424 if (match($4, "[F]") != 0) {
425 add_64bit_fakesafe = 1
428 if (files_keyword_OK == 0) {
429 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $4
433 else if ($4 == "UALL") {
434 add_64bit_unsafe = 1;
440 # output function argument structures to sysproto.h and build the
441 # name of the appropriate argument mungers
444 if (funcname != "nosys" || (syscall == 0 && funcname == "nosys")) {
446 if (add_sysproto_entry == 1) {
447 printf("struct %s {\n", argalias) > sysarg
451 for (i = 1; i <= argc; i++) {
452 # Build name of argument munger.
453 # We account for all sys call argument types here.
454 # This is where you add any new types. With LP64 support
455 # each argument consumes 64-bits.
456 # see .../xnu/bsd/dev/ppc/munge.s for munge argument types.
457 if (argtype[i] == "long") {
458 if (add_64bit_unsafe == 0)
459 ext_argtype[i] = "user_long_t";
460 munge32 = munge32 "s"
461 munge64 = munge64 "d"
463 else if (argtype[i] == "u_long") {
464 if (add_64bit_unsafe == 0)
465 ext_argtype[i] = "user_ulong_t";
466 munge32 = munge32 "w"
467 munge64 = munge64 "d"
469 else if (argtype[i] == "size_t") {
470 if (add_64bit_unsafe == 0)
471 ext_argtype[i] = "user_size_t";
472 munge32 = munge32 "w"
473 munge64 = munge64 "d"
475 else if (argtype[i] == "ssize_t") {
476 if (add_64bit_unsafe == 0)
477 ext_argtype[i] = "user_ssize_t";
478 munge32 = munge32 "s"
479 munge64 = munge64 "d"
481 else if (argtype[i] == "user_ssize_t" || argtype[i] == "user_long_t") {
482 munge32 = munge32 "s"
483 munge64 = munge64 "d"
485 else if (argtype[i] == "user_addr_t" || argtype[i] == "user_size_t" ||
486 argtype[i] == "user_ulong_t") {
487 munge32 = munge32 "w"
488 munge64 = munge64 "d"
490 else if (argtype[i] == "caddr_t" || argtype[i] == "semun_t" ||
491 match(argtype[i], "[\*]") != 0) {
492 if (add_64bit_unsafe == 0)
493 ext_argtype[i] = "user_addr_t";
494 munge32 = munge32 "w"
495 munge64 = munge64 "d"
497 else if (argtype[i] == "int" || argtype[i] == "u_int" ||
498 argtype[i] == "uid_t" || argtype[i] == "pid_t" ||
499 argtype[i] == "id_t" || argtype[i] == "idtype_t" ||
500 argtype[i] == "socklen_t" || argtype[i] == "uint32_t" || argtype[i] == "int32_t" ||
501 argtype[i] == "sigset_t" || argtype[i] == "gid_t" ||
502 argtype[i] == "mode_t" || argtype[i] == "key_t" || argtype[i] == "time_t") {
503 munge32 = munge32 "w"
504 munge64 = munge64 "d"
506 else if (argtype[i] == "off_t" || argtype[i] == "int64_t" || argtype[i] == "uint64_t") {
507 munge32 = munge32 "l"
508 munge64 = munge64 "d"
511 printf "%s: line %d: invalid type \"%s\" \n",
512 infile, NR, argtype[i]
513 printf "You need to add \"%s\" into the type checking code. \n",
517 if (add_sysproto_entry == 1) {
518 printf("\tchar %s_l_[PADL_(%s)]; " \
519 "%s %s; char %s_r_[PADR_(%s)];\n",
520 argname[i], ext_argtype[i],
521 ext_argtype[i], argname[i],
522 argname[i], ext_argtype[i]) > sysarg
525 if (add_sysproto_entry == 1) {
526 printf("};\n") > sysarg
529 else if (add_sysproto_entry == 1) {
530 printf("struct %s {\n\tregister_t dummy;\n};\n", argalias) > sysarg
534 # output to init_sysent.c
536 if (add_sysent_entry == 0) {
540 munge_ret = "_SYSCALL_RET_NONE"
544 # figure out which return value type to munge
545 if (returntype == "user_addr_t") {
546 munge_ret = "_SYSCALL_RET_ADDR_T"
548 else if (returntype == "user_ssize_t") {
549 munge_ret = "_SYSCALL_RET_SSIZE_T"
551 else if (returntype == "user_size_t") {
552 munge_ret = "_SYSCALL_RET_SIZE_T"
554 else if (returntype == "int") {
555 munge_ret = "_SYSCALL_RET_INT_T"
557 else if (returntype == "u_int") {
558 munge_ret = "_SYSCALL_RET_UINT_T"
560 else if (returntype == "off_t") {
561 munge_ret = "_SYSCALL_RET_OFF_T"
563 else if (returntype == "void") {
564 munge_ret = "_SYSCALL_RET_NONE"
567 printf "%s: line %d: invalid return type \"%s\" \n",
568 infile, NR, returntype
569 printf "You need to add \"%s\" into the return type checking code. \n",
575 if (add_64bit_unsafe == 1 && add_64bit_fakesafe == 0)
576 my_funnel = my_funnel "|UNSAFE_64BIT";
578 printf("\t{%s, %s, %s, \(sy_call_t *\)%s, %s, %s, %s},",
579 argssize, add_cancel_enable, my_funnel, tempname, munge32, munge64, munge_ret) > sysent
580 linesize = length(argssize) + length(add_cancel_enable) + length(my_funnel) + length(tempname) + \
581 length(munge32) + length(munge64) + length(munge_ret) + 28
582 align_comment(linesize, 88, sysent)
583 printf("/* %d = %s%s*/\n", syscall, funcname, additional_comments) > sysent
585 # output to syscalls.c
586 if (add_sysnames_entry == 1) {
588 if (funcname == "nosys") {
592 tempname = "#" syscall
594 printf("\t\"%s\", ", tempname) > syscallnamestempfile
595 linesize = length(tempname) + 8
596 align_comment(linesize, 25, syscallnamestempfile)
597 if (substr(tempname,1,1) == "#") {
598 printf("/* %d =%s*/\n", syscall, additional_comments) > syscallnamestempfile
601 printf("/* %d = %s%s*/\n", syscall, tempname, additional_comments) > syscallnamestempfile
605 # output to syscalls.h
606 if (add_sysheader_entry == 1) {
611 if (tempname != "nosys") {
612 printf("#define\t%s%s", syscallprefix, tempname) > syshdrtempfile
613 linesize = length(syscallprefix) + length(tempname) + 12
614 align_comment(linesize, 30, syshdrtempfile)
615 printf("%d\n", syscall) > syshdrtempfile
616 # special case for gettimeofday on ppc - cctools project uses old name
617 if (tempname == "ppc_gettimeofday") {
618 printf("#define\t%s%s", syscallprefix, "gettimeofday") > syshdrtempfile
619 linesize = length(syscallprefix) + length(tempname) + 12
620 align_comment(linesize, 30, syshdrtempfile)
621 printf("%d\n", syscall) > syshdrtempfile
625 printf("\t\t\t/* %d %s*/\n", syscall, additional_comments) > syshdrtempfile
629 # output function prototypes to sysproto.h
630 if (add_sysproto_entry == 1) {
631 if (funcname =="exit") {
632 printf("void %s(struct proc *, struct %s *, int *);\n",
633 funcname, argalias) > sysprotoend
635 else if (funcname != "nosys" || (syscall == 0 && funcname == "nosys")) {
636 printf("int %s(struct proc *, struct %s *, %s *);\n",
637 funcname, argalias, returntype) > sysprotoend
646 printf "#define AC(name) (sizeof(struct name) / sizeof(uint64_t))\n" > sysinc
649 printf("\n__END_DECLS\n") > sysprotoend
650 printf("#undef PAD_\n") > sysprotoend
651 printf("#undef PADL_\n") > sysprotoend
652 printf("#undef PADR_\n") > sysprotoend
653 printf "\n#endif /* __APPLE_API_PRIVATE */\n" > sysprotoend
654 printf "#endif /* KERNEL */\n" > sysprotoend
655 printf("\n#endif /* !%s */\n", sysproto_h) > sysprotoend
657 printf("};\n") > sysent
658 printf("int nsysent = sizeof(sysent) / sizeof(sysent[0]);\n") > sysent
660 printf("};\n") > syscallnamestempfile
661 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
663 printf("\n#endif /* __APPLE_API_PRIVATE */\n") > syshdrtempfile
664 printf("#endif /* !%s */\n", syscall_h) > syshdrtempfile
667 cat $syslegal $sysinc $sysent > $syscalltablefile
668 cat $syslegal $sysarg $sysprotoend > $sysprotofile
669 cat $syslegal $syscallnamestempfile > $syscallnamesfile
670 cat $syslegal $syshdrtempfile > $syshdrfile