]>
git.saurik.com Git - apple/xnu.git/blob - bsd/kern/makesyscalls.sh
b86904d7897e3fd35de9d230fdd6120c64526d8c
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 "#ifdef __ppc__\n" > sysarg
142 printf "#define\tPAD_(t)\t(sizeof(uint64_t) <= sizeof(t) \\\n " > sysarg
143 printf "\t\t? 0 : sizeof(uint64_t) - sizeof(t))\n" > sysarg
144 printf "#else\n" > sysarg
145 printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) \\\n " > sysarg
146 printf "\t\t? 0 : sizeof(register_t) - sizeof(t))\n" > sysarg
147 printf "#endif\n" > sysarg
148 printf "#if BYTE_ORDER == LITTLE_ENDIAN\n"> sysarg
149 printf "#define\tPADL_(t)\t0\n" > sysarg
150 printf "#define\tPADR_(t)\tPAD_(t)\n" > sysarg
151 printf "#else\n" > sysarg
152 printf "#define\tPADL_(t)\tPAD_(t)\n" > sysarg
153 printf "#define\tPADR_(t)\t0\n" > sysarg
154 printf "#endif\n" > sysarg
155 printf "\n__BEGIN_DECLS\n" > sysarg
156 printf "#ifndef __MUNGE_ONCE\n" > sysarg
157 printf "#define __MUNGE_ONCE\n" > sysarg
158 printf "#ifdef __ppc__\n" > sysarg
159 printf "void munge_w(const void *, void *); \n" > sysarg
160 printf "void munge_ww(const void *, void *); \n" > sysarg
161 printf "void munge_www(const void *, void *); \n" > sysarg
162 printf "void munge_wwww(const void *, void *); \n" > sysarg
163 printf "void munge_wwwww(const void *, void *); \n" > sysarg
164 printf "void munge_wwwwww(const void *, void *); \n" > sysarg
165 printf "void munge_wwwwwww(const void *, void *); \n" > sysarg
166 printf "void munge_wwwwwwww(const void *, void *); \n" > sysarg
167 printf "void munge_d(const void *, void *); \n" > sysarg
168 printf "void munge_dd(const void *, void *); \n" > sysarg
169 printf "void munge_ddd(const void *, void *); \n" > sysarg
170 printf "void munge_dddd(const void *, void *); \n" > sysarg
171 printf "void munge_ddddd(const void *, void *); \n" > sysarg
172 printf "void munge_dddddd(const void *, void *); \n" > sysarg
173 printf "void munge_ddddddd(const void *, void *); \n" > sysarg
174 printf "void munge_dddddddd(const void *, void *); \n" > sysarg
175 printf "void munge_wl(const void *, void *); \n" > sysarg
176 printf "void munge_wlw(const void *, void *); \n" > sysarg
177 printf "void munge_wwwl(const void *, void *); \n" > sysarg
178 printf "void munge_wwwwl(const void *, void *); \n" > sysarg
179 printf "void munge_wwwwwl(const void *, void *); \n" > sysarg
180 printf "void munge_wsw(const void *, void *); \n" > sysarg
181 printf "void munge_wws(const void *, void *); \n" > sysarg
182 printf "void munge_wwwsw(const void *, void *); \n" > sysarg
183 printf "#else \n" > sysarg
184 printf "#define munge_w NULL \n" > sysarg
185 printf "#define munge_ww NULL \n" > sysarg
186 printf "#define munge_www NULL \n" > sysarg
187 printf "#define munge_wwww NULL \n" > sysarg
188 printf "#define munge_wwwww NULL \n" > sysarg
189 printf "#define munge_wwwwww NULL \n" > sysarg
190 printf "#define munge_wwwwwww NULL \n" > sysarg
191 printf "#define munge_wwwwwwww NULL \n" > sysarg
192 printf "#define munge_d NULL \n" > sysarg
193 printf "#define munge_dd NULL \n" > sysarg
194 printf "#define munge_ddd NULL \n" > sysarg
195 printf "#define munge_dddd NULL \n" > sysarg
196 printf "#define munge_ddddd NULL \n" > sysarg
197 printf "#define munge_dddddd NULL \n" > sysarg
198 printf "#define munge_ddddddd NULL \n" > sysarg
199 printf "#define munge_dddddddd NULL \n" > sysarg
200 printf "#define munge_wl NULL \n" > sysarg
201 printf "#define munge_wlw NULL \n" > sysarg
202 printf "#define munge_wwwl NULL \n" > sysarg
203 printf "#define munge_wwwwl NULL \n" > sysarg
204 printf "#define munge_wwwwwl NULL \n" > sysarg
205 printf "#define munge_wsw NULL \n" > sysarg
206 printf "#define munge_wws NULL \n" > sysarg
207 printf "#define munge_wwwsw NULL \n" > sysarg
208 printf "#endif // __ppc__\n" > sysarg
209 printf "#endif /* !__MUNGE_ONCE */\n" > sysarg
213 printf "const char *%s[] = {\n", namesname > syscallnamestempfile
216 NF == 0 || $1 ~ /^;/ {
219 $1 ~ /^#[ ]*include/ {
226 print > syscallnamestempfile
227 print > syshdrtempfile
229 savesyscall = syscall
235 print > syscallnamestempfile
236 print > syshdrtempfile
238 syscall = savesyscall
244 print > syscallnamestempfile
245 print > syshdrtempfile
250 printf "%s: line %d: syscall number out of sync at %d\n",
256 function align_comment(linesize, location, thefile) {
257 printf(" ") > thefile
258 while (linesize < location) {
259 printf(" ") > thefile
263 function parserr(was, wanted) {
264 printf "%s: line %d: unexpected %s (expected %s)\n",
265 infile, NR, was, wanted
269 function parseline() {
278 additional_comments = " "
280 # find start and end of call name and arguments
281 if ($current_field != "{")
282 parserr($current_field, "{")
283 args_start = current_field
285 while (current_field <= NF) {
286 if ($current_field == "}") {
287 args_end = current_field
293 printf "%s: line %d: invalid call name and arguments\n",
298 # find start and end of optional comments
300 if (current_field < NF && $current_field == "{") {
301 comments_start = current_field
302 while (current_field <= NF) {
303 if ($current_field == "}") {
304 comments_end = current_field
309 if (comments_end == 0) {
310 printf "%s: line %d: invalid comments \n",
316 if ($args_end != "}")
317 parserr($args_end, "}")
319 if ($args_end != ";")
320 parserr($args_end, ";")
322 if ($args_end != ")")
323 parserr($args_end, ")")
326 # extract additional comments
327 if (comments_start != 0) {
328 current_field = comments_start + 1
329 while (current_field < comments_end) {
330 additional_comments = additional_comments $current_field " "
335 # get function return type
336 current_field = args_start + 1
337 returntype = $current_field
339 # get function name and set up to get arguments
341 funcname = $current_field
342 argalias = funcname "_args"
343 current_field++ # bump past function name
345 if ($current_field != "(")
346 parserr($current_field, "(")
349 if (current_field == args_end) {
350 if ($current_field != "void")
351 parserr($current_field, "argument definition")
355 # extract argument types and names
356 while (current_field <= args_end) {
361 while (current_field < args_end && $(current_field + 1) != ",") {
362 if (argtype[argc] != "" && oldf != "*") {
363 argtype[argc] = argtype[argc] " ";
365 argtype[argc] = argtype[argc] $current_field;
366 ext_argtype[argc] = argtype[argc];
367 oldf = $current_field;
370 if (argtype[argc] == "")
371 parserr($current_field, "argument definition")
372 argname[argc] = $current_field;
373 current_field += 2; # skip name, and any comma
376 printf "%s: line %d: too many arguments!\n", infile, NR
380 argssize = "AC(" argalias ")"
385 add_sysnames_entry = 1
386 add_sysheader_entry = 1
387 add_sysproto_entry = 1
389 add_64bit_fakesafe = 0
390 add_cancel_enable = "0"
393 add_cancel_enable = "_SYSCALL_CANCEL_NONE"
395 else if ($2 == "PRE") {
396 add_cancel_enable = "_SYSCALL_CANCEL_PRE"
398 else if ($2 == "POST") {
399 add_cancel_enable = "_SYSCALL_CANCEL_POST"
402 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
408 my_funnel = "KERNEL_FUNNEL"
410 else if ($3 == "NONE") {
411 my_funnel = "NO_FUNNEL"
414 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $3
418 if ($4 != "ALL" && $4 != "UALL") {
421 add_sysnames_entry = 0
422 add_sysheader_entry = 0
423 add_sysproto_entry = 0
425 if (match($4, "[T]") != 0) {
429 if (match($4, "[N]") != 0) {
430 add_sysnames_entry = 1
433 if (match($4, "[H]") != 0) {
434 add_sysheader_entry = 1
437 if (match($4, "[P]") != 0) {
438 add_sysproto_entry = 1
441 if (match($4, "[U]") != 0) {
444 if (match($4, "[F]") != 0) {
445 add_64bit_fakesafe = 1
448 if (files_keyword_OK == 0) {
449 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $4
453 else if ($4 == "UALL") {
454 add_64bit_unsafe = 1;
460 # output function argument structures to sysproto.h and build the
461 # name of the appropriate argument mungers
464 if (funcname != "nosys" || (syscall == 0 && funcname == "nosys")) {
466 if (add_sysproto_entry == 1) {
467 printf("struct %s {\n", argalias) > sysarg
471 for (i = 1; i <= argc; i++) {
472 # Build name of argument munger.
473 # We account for all sys call argument types here.
474 # This is where you add any new types. With LP64 support
475 # each argument consumes 64-bits.
476 # see .../xnu/bsd/dev/ppc/munge.s for munge argument types.
477 if (argtype[i] == "long") {
478 if (add_64bit_unsafe == 0)
479 ext_argtype[i] = "user_long_t";
480 munge32 = munge32 "s"
481 munge64 = munge64 "d"
483 else if (argtype[i] == "u_long") {
484 if (add_64bit_unsafe == 0)
485 ext_argtype[i] = "user_ulong_t";
486 munge32 = munge32 "w"
487 munge64 = munge64 "d"
489 else if (argtype[i] == "size_t") {
490 if (add_64bit_unsafe == 0)
491 ext_argtype[i] = "user_size_t";
492 munge32 = munge32 "w"
493 munge64 = munge64 "d"
495 else if (argtype[i] == "ssize_t") {
496 if (add_64bit_unsafe == 0)
497 ext_argtype[i] = "user_ssize_t";
498 munge32 = munge32 "s"
499 munge64 = munge64 "d"
501 else if (argtype[i] == "user_ssize_t" || argtype[i] == "user_long_t") {
502 munge32 = munge32 "s"
503 munge64 = munge64 "d"
505 else if (argtype[i] == "user_addr_t" || argtype[i] == "user_size_t" ||
506 argtype[i] == "user_ulong_t") {
507 munge32 = munge32 "w"
508 munge64 = munge64 "d"
510 else if (argtype[i] == "caddr_t" || argtype[i] == "semun_t" ||
511 match(argtype[i], "[\*]") != 0) {
512 if (add_64bit_unsafe == 0)
513 ext_argtype[i] = "user_addr_t";
514 munge32 = munge32 "w"
515 munge64 = munge64 "d"
517 else if (argtype[i] == "int" || argtype[i] == "u_int" ||
518 argtype[i] == "uid_t" || argtype[i] == "pid_t" ||
519 argtype[i] == "id_t" || argtype[i] == "idtype_t" ||
520 argtype[i] == "socklen_t" || argtype[i] == "uint32_t" || argtype[i] == "int32_t" ||
521 argtype[i] == "sigset_t" || argtype[i] == "gid_t" ||
522 argtype[i] == "mode_t" || argtype[i] == "key_t" || argtype[i] == "time_t") {
523 munge32 = munge32 "w"
524 munge64 = munge64 "d"
526 else if (argtype[i] == "off_t" || argtype[i] == "int64_t" || argtype[i] == "uint64_t") {
527 munge32 = munge32 "l"
528 munge64 = munge64 "d"
531 printf "%s: line %d: invalid type \"%s\" \n",
532 infile, NR, argtype[i]
533 printf "You need to add \"%s\" into the type checking code. \n",
537 if (add_sysproto_entry == 1) {
538 printf("\tchar %s_l_[PADL_(%s)]; " \
539 "%s %s; char %s_r_[PADR_(%s)];\n",
540 argname[i], ext_argtype[i],
541 ext_argtype[i], argname[i],
542 argname[i], ext_argtype[i]) > sysarg
545 if (add_sysproto_entry == 1) {
546 printf("};\n") > sysarg
549 else if (add_sysproto_entry == 1) {
550 printf("struct %s {\n\tregister_t dummy;\n};\n", argalias) > sysarg
554 # output to init_sysent.c
556 if (add_sysent_entry == 0) {
560 munge_ret = "_SYSCALL_RET_NONE"
564 # figure out which return value type to munge
565 if (returntype == "user_addr_t") {
566 munge_ret = "_SYSCALL_RET_ADDR_T"
568 else if (returntype == "user_ssize_t") {
569 munge_ret = "_SYSCALL_RET_SSIZE_T"
571 else if (returntype == "user_size_t") {
572 munge_ret = "_SYSCALL_RET_SIZE_T"
574 else if (returntype == "int") {
575 munge_ret = "_SYSCALL_RET_INT_T"
577 else if (returntype == "u_int") {
578 munge_ret = "_SYSCALL_RET_UINT_T"
580 else if (returntype == "off_t") {
581 munge_ret = "_SYSCALL_RET_OFF_T"
583 else if (returntype == "void") {
584 munge_ret = "_SYSCALL_RET_NONE"
587 printf "%s: line %d: invalid return type \"%s\" \n",
588 infile, NR, returntype
589 printf "You need to add \"%s\" into the return type checking code. \n",
595 if (add_64bit_unsafe == 1 && add_64bit_fakesafe == 0)
596 my_funnel = my_funnel "|UNSAFE_64BIT";
598 printf("\t{%s, %s, %s, \(sy_call_t *\)%s, %s, %s, %s},",
599 argssize, add_cancel_enable, my_funnel, tempname, munge32, munge64, munge_ret) > sysent
600 linesize = length(argssize) + length(add_cancel_enable) + length(my_funnel) + length(tempname) + \
601 length(munge32) + length(munge64) + length(munge_ret) + 28
602 align_comment(linesize, 88, sysent)
603 printf("/* %d = %s%s*/\n", syscall, funcname, additional_comments) > sysent
605 # output to syscalls.c
606 if (add_sysnames_entry == 1) {
608 if (funcname == "nosys") {
612 tempname = "#" syscall
614 printf("\t\"%s\", ", tempname) > syscallnamestempfile
615 linesize = length(tempname) + 8
616 align_comment(linesize, 25, syscallnamestempfile)
617 if (substr(tempname,1,1) == "#") {
618 printf("/* %d =%s*/\n", syscall, additional_comments) > syscallnamestempfile
621 printf("/* %d = %s%s*/\n", syscall, tempname, additional_comments) > syscallnamestempfile
625 # output to syscalls.h
626 if (add_sysheader_entry == 1) {
631 if (tempname != "nosys") {
632 printf("#define\t%s%s", syscallprefix, tempname) > syshdrtempfile
633 linesize = length(syscallprefix) + length(tempname) + 12
634 align_comment(linesize, 30, syshdrtempfile)
635 printf("%d\n", syscall) > syshdrtempfile
636 # special case for gettimeofday on ppc - cctools project uses old name
637 if (tempname == "ppc_gettimeofday") {
638 printf("#define\t%s%s", syscallprefix, "gettimeofday") > syshdrtempfile
639 linesize = length(syscallprefix) + length(tempname) + 12
640 align_comment(linesize, 30, syshdrtempfile)
641 printf("%d\n", syscall) > syshdrtempfile
645 printf("\t\t\t/* %d %s*/\n", syscall, additional_comments) > syshdrtempfile
649 # output function prototypes to sysproto.h
650 if (add_sysproto_entry == 1) {
651 if (funcname =="exit") {
652 printf("void %s(struct proc *, struct %s *, int *);\n",
653 funcname, argalias) > sysprotoend
655 else if (funcname != "nosys" || (syscall == 0 && funcname == "nosys")) {
656 printf("int %s(struct proc *, struct %s *, %s *);\n",
657 funcname, argalias, returntype) > sysprotoend
666 printf "#ifdef __ppc__\n" > sysinc
667 printf "#define AC(name) (sizeof(struct name) / sizeof(uint64_t))\n" > sysinc
668 printf "#else\n" > sysinc
669 printf "#define AC(name) (sizeof(struct name) / sizeof(register_t))\n" > sysinc
670 printf "#endif\n" > sysinc
673 printf("\n__END_DECLS\n") > sysprotoend
674 printf("#undef PAD_\n") > sysprotoend
675 printf("#undef PADL_\n") > sysprotoend
676 printf("#undef PADR_\n") > sysprotoend
677 printf "\n#endif /* __APPLE_API_PRIVATE */\n" > sysprotoend
678 printf "#endif /* KERNEL */\n" > sysprotoend
679 printf("\n#endif /* !%s */\n", sysproto_h) > sysprotoend
681 printf("};\n") > sysent
682 printf("int nsysent = sizeof(sysent) / sizeof(sysent[0]);\n") > sysent
684 printf("};\n") > syscallnamestempfile
685 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
687 printf("\n#endif /* __APPLE_API_PRIVATE */\n") > syshdrtempfile
688 printf("#endif /* !%s */\n", syscall_h) > syshdrtempfile
691 cat $syslegal $sysinc $sysent > $syscalltablefile
692 cat $syslegal $sysarg $sysprotoend > $sysprotofile
693 cat $syslegal $syscallnamestempfile > $syscallnamesfile
694 cat $syslegal $syshdrtempfile > $syshdrfile