]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/makesyscalls.sh
xnu-1504.9.17.tar.gz
[apple/xnu.git] / bsd / kern / makesyscalls.sh
index e2e5a7f95dbe1fa88c8e4560a720dfa5be4bf2f3..d8b11ba6c22708e25c8f520d9c0688cf04b2c7fd 100755 (executable)
@@ -2,36 +2,47 @@
 #      @(#)makesyscalls.sh     8.1 (Berkeley) 6/10/93
 # $FreeBSD: src/sys/kern/makesyscalls.sh,v 1.60 2003/04/01 01:12:24 jeff Exp $
 #
-# Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+# Copyright (c) 2004-2008 Apple Inc. All rights reserved.
 #
-# @APPLE_LICENSE_HEADER_START@
+# @APPLE_OSREFERENCE_LICENSE_HEADER_START@
 # 
-# The contents of this file constitute Original Code as defined in and
-# are subject to the Apple Public Source License Version 1.1 (the
-# "License").  You may not use this file except in compliance with the
-# License.  Please obtain a copy of the License at
-# http://www.apple.com/publicsource and read it before using this file.
+# This file contains Original Code and/or Modifications of Original Code
+# as defined in and that are subject to the Apple Public Source License
+# Version 2.0 (the 'License'). You may not use this file except in
+# compliance with the License. Please obtain a copy of the License at
+# http://www.opensource.apple.com/apsl/ and read it before using this
+# file.
 # 
-# This Original Code and all software distributed under the License are
-# distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+# The Original Code and all software distributed under the License are
+# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
-# License for the specific language governing rights and limitations
-# under the License.
+# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+# Please see the License for the specific language governing rights and
+# limitations under the License.
 # 
-# @APPLE_LICENSE_HEADER_END@
+# @APPLE_OSREFERENCE_LICENSE_HEADER_END@
 #
 
 set -e
 
+input_file="" # first argument
+
+# output type:
+output_syscallnamesfile=0
+output_sysprotofile=0
+output_syshdrfile=0
+output_syscalltablefile=0
+output_auditevfile=0
+
 # output files:
 syscallnamesfile="syscalls.c"
-sysprotofile="../sys/sysproto.h"
+sysprotofile="sysproto.h"
 sysproto_h=_SYS_SYSPROTO_H_
-syshdrfile="../sys/syscall.h"
+syshdrfile="syscall.h"
 syscall_h=_SYS_SYSCALL_H_
 syscalltablefile="init_sysent.c"
+auditevfile="audit_kevents.c"
 syscallprefix="SYS_"
 switchname="sysent"
 namesname="syscallnames"
@@ -44,21 +55,55 @@ sysarg="sysarg.switch.$$"
 sysprotoend="sysprotoend.$$"
 syscallnamestempfile="syscallnamesfile.$$"
 syshdrtempfile="syshdrtempfile.$$"
+audittempfile="audittempfile.$$"
 
-trap "rm $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile" 0
+trap "rm $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile $audittempfile" 0
 
-touch $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile
+touch $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile $audittempfile
 
 case $# in
-    0) echo "usage: $0 input-file <config-file>" 1>&2
+    0)
+       echo "usage: $0 input-file [<names|proto|header|table|audit> [<config-file>]]" 1>&2
        exit 1
        ;;
 esac
 
-if [ -n "$2" -a -f "$2" ]; then
-       . $2
+input_file="$1"
+shift
+
+if [ -n "$1" ]; then
+    case $1 in
+       names)
+           output_syscallnamesfile=1
+           ;;
+       proto)
+           output_sysprotofile=1
+           ;;
+       header)
+           output_syshdrfile=1
+           ;;
+       table)
+           output_syscalltablefile=1
+           ;;
+       audit)
+           output_auditevfile=1
+           ;;
+    esac
+    shift;
+else
+    output_syscallnamesfile=1
+    output_sysprotofile=1
+    output_syshdrfile=1
+    output_syscalltablefile=1
+    output_auditevfile=1
+fi
+
+if [ -n "$1" -a -f "$1" ]; then
+       . $1
 fi
 
+
+
 sed -e '
 s/\$//g
 :join
@@ -69,9 +114,9 @@ s/\$//g
        b join
        }
 2,${
-       /^#/!s/\([{}()*,]\)/ \1 /g
+       /^#/!s/\([{}()*,;]\)/ \1 /g
 }
-' < $1 | awk "
+' < "$input_file" | awk "
        BEGIN {
                syslegal = \"$syslegal\"
                sysprotofile = \"$sysprotofile\"
@@ -86,32 +131,39 @@ s/\$//g
                syscallnamestempfile = \"$syscallnamestempfile\"
                syshdrfile = \"$syshdrfile\"
                syshdrtempfile = \"$syshdrtempfile\"
+               audittempfile = \"$audittempfile\"
                syscallprefix = \"$syscallprefix\"
                switchname = \"$switchname\"
                namesname = \"$namesname\"
-               infile = \"$1\"
+               infile = \"$input_file\"
                "'
 
                printf "/*\n" > syslegal
-               printf " * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.\n" > syslegal
+               printf " * Copyright (c) 2004-2008 Apple Inc. All rights reserved.\n" > syslegal
                printf " * \n" > syslegal
-               printf " * @APPLE_LICENSE_HEADER_START@ \n" > syslegal
+               printf " * @APPLE_OSREFERENCE_LICENSE_HEADER_START@\n" > syslegal
                printf " * \n" > syslegal
-               printf " * The contents of this file constitute Original Code as defined in and \n" > syslegal
-               printf " * are subject to the Apple Public Source License Version 1.1 (the \n" > syslegal
-               printf " * \"License\").  You may not use this file except in compliance with the \n" > syslegal
-               printf " * License.  Please obtain a copy of the License at \n" > syslegal
-               printf " * http://www.apple.com/publicsource and read it before using this file. \n" > syslegal
+               printf " * This file contains Original Code and/or Modifications of Original Code\n" > syslegal
+               printf " * as defined in and that are subject to the Apple Public Source License\n" > syslegal
+               printf " * Version 2.0 (the \047License\047). You may not use this file except in\n" > syslegal
+               printf " * compliance with the License. The rights granted to you under the License\n" > syslegal
+               printf " * may not be used to create, or enable the creation or redistribution of,\n" > syslegal
+               printf " * unlawful or unlicensed copies of an Apple operating system, or to\n" > syslegal
+               printf " * circumvent, violate, or enable the circumvention or violation of, any\n" > syslegal
+               printf " * terms of an Apple operating system software license agreement.\n" > syslegal
                printf " * \n" > syslegal
-               printf " * This Original Code and all software distributed under the License are \n" > syslegal
-               printf " * distributed on an \"AS IS\" basis, WITHOUT WARRANTY OF ANY KIND, EITHER \n" > syslegal
-               printf " * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, \n" > syslegal
-               printf " * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, \n" > syslegal
-               printf " * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the \n" > syslegal
-               printf " * License for the specific language governing rights and limitations \n" > syslegal
-               printf " * under the License. \n" > syslegal
+               printf " * Please obtain a copy of the License at\n" > syslegal
+               printf " * http://www.opensource.apple.com/apsl/ and read it before using this file.\n" > syslegal
                printf " * \n" > syslegal
-               printf " * @APPLE_LICENSE_HEADER_END@ \n" > syslegal
+               printf " * The Original Code and all software distributed under the License are\n" > syslegal
+               printf " * distributed on an \047AS IS\047 basis, WITHOUT WARRANTY OF ANY KIND, EITHER\n" > syslegal
+               printf " * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,\n" > syslegal
+               printf " * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,\n" > syslegal
+               printf " * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.\n" > syslegal
+               printf " * Please see the License for the specific language governing rights and\n" > syslegal
+               printf " * limitations under the License.\n" > syslegal
+               printf " * \n" > syslegal
+               printf " * @APPLE_OSREFERENCE_LICENSE_HEADER_END@\n" > syslegal
                printf " * \n" > syslegal
                printf " * \n" > syslegal
                printf " * System call switch table.\n *\n" > syslegal
@@ -135,11 +187,16 @@ s/\$//g
                printf "#include <sys/sem_internal.h>\n" > sysarg
                printf "#include <sys/semaphore.h>\n" > sysarg
                printf "#include <sys/wait.h>\n" > sysarg
-               printf "#include <mach/shared_memory_server.h>\n" > sysarg
+               printf "#include <mach/shared_region.h>\n" > sysarg
                printf "\n#ifdef KERNEL\n" > sysarg
                printf "#ifdef __APPLE_API_PRIVATE\n" > sysarg
+               printf "#ifndef __arm__\n" > sysarg
                printf "#define\tPAD_(t)\t(sizeof(uint64_t) <= sizeof(t) \\\n " > sysarg
                printf "\t\t? 0 : sizeof(uint64_t) - sizeof(t))\n" > sysarg
+               printf "#else\n" > sysarg
+               printf "#define\tPAD_(t)\t(sizeof(uint32_t) <= sizeof(t) \\\n" > sysarg
+               printf "                ? 0 : sizeof(uint32_t) - sizeof(t))\n" > sysarg
+               printf "#endif\n" > sysarg
                printf "#if BYTE_ORDER == LITTLE_ENDIAN\n"> sysarg
                printf "#define\tPADL_(t)\t0\n" > sysarg
                printf "#define\tPADR_(t)\tPAD_(t)\n" > sysarg
@@ -150,6 +207,7 @@ s/\$//g
                printf "\n__BEGIN_DECLS\n" > sysarg
                printf "#ifndef __MUNGE_ONCE\n" > sysarg
                printf "#define __MUNGE_ONCE\n" > sysarg
+               printf "#ifndef __arm__\n" > sysarg
                printf "void munge_w(const void *, void *);  \n" > sysarg
                printf "void munge_ww(const void *, void *);  \n" > sysarg
                printf "void munge_www(const void *, void *);  \n" > sysarg
@@ -161,12 +219,42 @@ s/\$//g
                printf "void munge_wl(const void *, void *);  \n" > sysarg
                printf "void munge_wlw(const void *, void *);  \n" > sysarg
                printf "void munge_wwwl(const void *, void *);  \n" > sysarg
-               printf "void munge_wwwlww(const void *, void *); \n" > sysarg
+               printf "void munge_wwwlw(const void *, void *);  \n" > sysarg
+               printf "void munge_wwwlww(const void *, void *);  \n" > sysarg
+               printf "void munge_wwlwww(const void *, void *);  \n" > sysarg
+               printf "void munge_wwwwlw(const void *, void *);  \n" > sysarg
                printf "void munge_wwwwl(const void *, void *);  \n" > sysarg
                printf "void munge_wwwwwl(const void *, void *);  \n" > sysarg
+               printf "void munge_wwwwwwll(const void *, void *);  \n" > sysarg
+               printf "void munge_wwwwwwlw(const void *, void *);  \n" > sysarg
                printf "void munge_wsw(const void *, void *);  \n" > sysarg
                printf "void munge_wws(const void *, void *);  \n" > sysarg
                printf "void munge_wwwsw(const void *, void *);  \n" > sysarg
+               printf "void munge_llllll(const void *, void *); \n" > sysarg
+               printf "#else \n" > sysarg
+               printf "#define munge_w  NULL \n" > sysarg
+               printf "#define munge_ww  NULL \n" > sysarg
+               printf "#define munge_www  NULL \n" > sysarg
+               printf "#define munge_wwww  NULL \n" > sysarg
+               printf "#define munge_wwwww  NULL \n" > sysarg
+               printf "#define munge_wwwwww  NULL \n" > sysarg
+               printf "#define munge_wwwwwww  NULL \n" > sysarg
+               printf "#define munge_wwwwwwww  NULL \n" > sysarg
+               printf "#define munge_wl  NULL \n" > sysarg
+               printf "#define munge_wlw  NULL \n" > sysarg
+               printf "#define munge_wwwl  NULL \n" > sysarg
+               printf "#define munge_wwwlw  NULL \n" > sysarg
+               printf "#define munge_wwwlww  NULL\n" > sysarg
+               printf "#define munge_wwlwww  NULL \n" > sysarg
+               printf "#define munge_wwwwl  NULL \n" > sysarg
+               printf "#define munge_wwwwlw  NULL \n" > sysarg
+               printf "#define munge_wwwwwl  NULL \n" > sysarg
+               printf "#define munge_wwwwwwlw  NULL \n" > sysarg
+               printf "#define munge_wsw  NULL \n" > sysarg
+               printf "#define munge_wws  NULL \n" > sysarg
+               printf "#define munge_wwwsw  NULL \n" > sysarg
+               printf "#define munge_llllll  NULL \n" > sysarg
+               printf "#endif // ! __arm__\n" > sysarg
                printf "#ifdef __ppc__\n" > sysarg
                printf "void munge_d(const void *, void *);  \n" > sysarg
                printf "void munge_dd(const void *, void *);  \n" > sysarg
@@ -191,6 +279,13 @@ s/\$//g
                printf "\n" > sysarg
 
                printf "const char *%s[] = {\n", namesname > syscallnamestempfile
+
+               printf "#include <sys/param.h>\n" > audittempfile
+               printf "#include <sys/types.h>\n\n" > audittempfile
+               printf "#include <bsm/audit.h>\n" > audittempfile
+               printf "#include <bsm/audit_kevents.h>\n\n" > audittempfile
+               printf "#if CONFIG_AUDIT\n\n" > audittempfile
+               printf "au_event_t sys_au_event[] = {\n" > audittempfile
                next
        }
        NF == 0 || $1 ~ /^;/ {
@@ -204,31 +299,34 @@ s/\$//g
                print > sysent
                print > sysarg
                print > syscallnamestempfile
-               print > syshdrtempfile
                print > sysprotoend
-               savesyscall = syscall
+               print > audittempfile
+               savesyscall = syscall_num
+               skip_for_header = 0
                next
        }
        $1 ~ /^#[       ]*else/ {
                print > sysent
                print > sysarg
                print > syscallnamestempfile
-               print > syshdrtempfile
                print > sysprotoend
-               syscall = savesyscall
+               print > audittempfile
+               syscall_num = savesyscall
+               skip_for_header = 1
                next
        }
        $1 ~ /^#/ {
                print > sysent
                print > sysarg
                print > syscallnamestempfile
-               print > syshdrtempfile
                print > sysprotoend
+               print > audittempfile
+               skip_for_header = 0
                next
        }
-       syscall != $1 {
+       syscall_num != $1 {
                printf "%s: line %d: syscall number out of sync at %d\n",
-                   infile, NR, syscall
+                   infile, NR, syscall_num
                printf "line is:\n"
                print
                exit 1
@@ -248,7 +346,7 @@ s/\$//g
        
        function parseline() {
                funcname = ""
-               current_field = 5
+               current_field = 4       # skip number, audit event, type
                args_start = 0
                args_end = 0
                comments_start = 0
@@ -299,6 +397,11 @@ s/\$//g
                if ($args_end != ";")
                        parserr($args_end, ";")
                args_end--
+
+               # skip any NO_SYSCALL_STUB qualifier
+               if ($args_end == "NO_SYSCALL_STUB")
+                       args_end--
+
                if ($args_end != ")")
                        parserr($args_end, ")")
                args_end--
@@ -359,7 +462,11 @@ s/\$//g
                if (argc != 0)
                        argssize = "AC(" argalias ")"
        }
-       
+
+       {
+               auditev = $2;
+       }
+
        {
                add_sysent_entry = 1
                add_sysnames_entry = 1
@@ -367,70 +474,46 @@ s/\$//g
                add_sysproto_entry = 1
                add_64bit_unsafe = 0
                add_64bit_fakesafe = 0
-               add_cancel_enable = "0"
-
-               if ($2 == "NONE") {
-                       add_cancel_enable = "_SYSCALL_CANCEL_NONE"
-               }
-               else if ($2 == "PRE") {
-                       add_cancel_enable = "_SYSCALL_CANCEL_PRE"
-               }
-               else if ($2 == "POST") {
-                       add_cancel_enable = "_SYSCALL_CANCEL_POST"
-               } 
-               else {
-                       printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
-                       exit 1
+               add_resv = "0"
+               my_flags = "0"
 
-               }
 
-               if ($3 == "KERN") {
-                       my_funnel = "KERNEL_FUNNEL"
-               }
-               else if ($3 == "NONE") {
-                       my_funnel = "NO_FUNNEL"
-               }
-               else {
-                       printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $3
-                       exit 1
-               }
-               
-               if ($4 != "ALL" && $4 != "UALL") {
+               if ($3 != "ALL" && $3 != "UALL") {
                        files_keyword_OK = 0
                        add_sysent_entry = 0
                        add_sysnames_entry = 0
                        add_sysheader_entry = 0
                        add_sysproto_entry = 0
                        
-                       if (match($4, "[T]") != 0) {
+                       if (match($3, "[T]") != 0) {
                                add_sysent_entry = 1
                                files_keyword_OK = 1
                        }
-                       if (match($4, "[N]") != 0) {
+                       if (match($3, "[N]") != 0) {
                                add_sysnames_entry = 1
                                files_keyword_OK = 1
                        }
-                       if (match($4, "[H]") != 0) {
+                       if (match($3, "[H]") != 0) {
                                add_sysheader_entry = 1
                                files_keyword_OK = 1
                        }
-                       if (match($4, "[P]") != 0) {
+                       if (match($3, "[P]") != 0) {
                                add_sysproto_entry = 1
                                files_keyword_OK = 1
                        }
-                       if (match($4, "[U]") != 0) {
+                       if (match($3, "[U]") != 0) {
                                add_64bit_unsafe = 1
                        }
-                       if (match($4, "[F]") != 0) {
+                       if (match($3, "[F]") != 0) {
                                add_64bit_fakesafe = 1
                        }
                        
                        if (files_keyword_OK == 0) {
-                               printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $4
+                               printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
                                exit 1
                        }
                }
-               else if ($4 == "UALL") {
+               else if ($3 == "UALL") {
                        add_64bit_unsafe = 1;
                }
                
@@ -441,7 +524,9 @@ s/\$//g
                # name of the appropriate argument mungers
                munge32 = "NULL"
                munge64 = "NULL"
-               if (funcname != "nosys" || (syscall == 0 && funcname == "nosys")) {
+               size32 = 0
+
+               if ((funcname != "nosys" && funcname != "enosys") || (syscall_num == 0 && funcname == "nosys")) {
                        if (argc != 0) {
                                if (add_sysproto_entry == 1) {
                                        printf("struct %s {\n", argalias) > sysarg
@@ -459,33 +544,39 @@ s/\$//g
                                                        ext_argtype[i] = "user_long_t";
                                                munge32 = munge32 "s"
                                                munge64 = munge64 "d"
+                                               size32 += 4
                                        }
                                        else if (argtype[i] == "u_long") {
                                                if (add_64bit_unsafe == 0)
                                                        ext_argtype[i] = "user_ulong_t";
                                                munge32 = munge32 "w"
                                                munge64 = munge64 "d"
+                                               size32 += 4
                                        }
                                        else if (argtype[i] == "size_t") {
                                                if (add_64bit_unsafe == 0)
                                                        ext_argtype[i] = "user_size_t";
                                                munge32 = munge32 "w"
                                                munge64 = munge64 "d"
+                                               size32 += 4
                                        }
                                        else if (argtype[i] == "ssize_t") {
                                                if (add_64bit_unsafe == 0)
                                                        ext_argtype[i] = "user_ssize_t";
                                                munge32 = munge32 "s"
                                                munge64 = munge64 "d"
+                                               size32 += 4
                                        }
                                        else if (argtype[i] == "user_ssize_t" || argtype[i] == "user_long_t") {
                                                munge32 = munge32 "s"
                                                munge64 = munge64 "d"
+                                               size32 += 4
                                        }
                                        else if (argtype[i] == "user_addr_t" || argtype[i] == "user_size_t" ||
                                                argtype[i] == "user_ulong_t") {
                                                munge32 = munge32 "w"
                                                munge64 = munge64 "d"
+                                               size32 += 4
                                        }
                                        else if (argtype[i] == "caddr_t" || argtype[i] == "semun_t" ||
                                                match(argtype[i], "[\*]") != 0) {
@@ -493,19 +584,23 @@ s/\$//g
                                                        ext_argtype[i] = "user_addr_t";
                                                munge32 = munge32 "w"
                                                munge64 = munge64 "d"
+                                               size32 += 4
                                        }
                                        else if (argtype[i] == "int" || argtype[i] == "u_int" ||
                                                         argtype[i] == "uid_t" || argtype[i] == "pid_t" ||
                                                         argtype[i] == "id_t" || argtype[i] == "idtype_t" ||
                                                         argtype[i] == "socklen_t" || argtype[i] == "uint32_t" || argtype[i] == "int32_t" ||
-                                                        argtype[i] == "sigset_t" || argtype[i] == "gid_t" ||
-                                                        argtype[i] == "mode_t" || argtype[i] == "key_t" || argtype[i] == "time_t") {
+                                                        argtype[i] == "sigset_t" || argtype[i] == "gid_t" || argtype[i] == "unsigned int" ||
+                                                        argtype[i] == "mode_t" || argtype[i] == "key_t" ||
+                                                        argtype[i] == "mach_port_name_t") {
                                                munge32 = munge32 "w"
                                                munge64 = munge64 "d"
+                                               size32 += 4
                                        }
                                        else if (argtype[i] == "off_t" || argtype[i] == "int64_t" || argtype[i] == "uint64_t") {
                                                munge32 = munge32 "l"
                                                munge64 = munge64 "d"
+                                               size32 += 8
                                        }
                                        else {
                                                printf "%s: line %d: invalid type \"%s\" \n", 
@@ -527,7 +622,7 @@ s/\$//g
                                }
                        }
                        else if (add_sysproto_entry == 1) { 
-                               printf("struct %s {\n\tregister_t dummy;\n};\n", argalias) > sysarg
+                               printf("struct %s {\n\tint32_t dummy;\n};\n", argalias) > sysarg
                        }
                }
                
@@ -538,7 +633,9 @@ s/\$//g
                        munge32 = "NULL"
                        munge64 = "NULL"
                        munge_ret = "_SYSCALL_RET_NONE"
-                       tempname = "nosys"
+                       if (tempname != "enosys") {
+                               tempname = "nosys"
+                       }
                }
                else {
                        # figure out which return value type to munge
@@ -554,9 +651,15 @@ s/\$//g
                        else if (returntype == "int") {
                                munge_ret = "_SYSCALL_RET_INT_T"
                        }
-                       else if (returntype == "u_int") {
+                       else if (returntype == "u_int" || returntype == "mach_port_name_t") {
                                munge_ret = "_SYSCALL_RET_UINT_T"
                        }
+                       else if (returntype == "uint32_t") {
+                               munge_ret = "_SYSCALL_RET_UINT_T"
+                       }
+                       else if (returntype == "uint64_t") {
+                               munge_ret = "_SYSCALL_RET_UINT64_T"
+                       }
                        else if (returntype == "off_t") {
                                munge_ret = "_SYSCALL_RET_OFF_T"
                        }
@@ -573,77 +676,81 @@ s/\$//g
                }
 
                if (add_64bit_unsafe == 1  && add_64bit_fakesafe == 0)
-                       my_funnel = my_funnel "|UNSAFE_64BIT";
+                       my_flags = "UNSAFE_64BIT";
 
-               printf("\t{%s, %s, %s, \(sy_call_t *\)%s, %s, %s, %s},", 
-                               argssize, add_cancel_enable, my_funnel, tempname, munge32, munge64, munge_ret) > sysent
-               linesize = length(argssize) + length(add_cancel_enable) + length(my_funnel) + length(tempname) + \
+               printf("\t{%s, %s, %s, \(sy_call_t *\)%s, %s, %s, %s, %s},", 
+                               argssize, add_resv, my_flags, tempname, munge32, munge64, munge_ret, size32) > sysent
+               linesize = length(argssize) + length(add_resv) + length(my_flags) + length(tempname) + \
                                length(munge32) + length(munge64) + length(munge_ret) + 28
                align_comment(linesize, 88, sysent)
-               printf("/* %d = %s%s*/\n", syscall, funcname, additional_comments) > sysent
+               printf("/* %d = %s%s*/\n", syscall_num, funcname, additional_comments) > sysent
                
                # output to syscalls.c
                if (add_sysnames_entry == 1) {
                        tempname = funcname
-                       if (funcname == "nosys") {
-                               if (syscall == 0)
+                       if (funcname == "nosys" || funcname == "enosys") {
+                               if (syscall_num == 0)
                                        tempname = "syscall"
                                else
-                                       tempname = "#" syscall
+                                       tempname = "#" syscall_num
                        }
                        printf("\t\"%s\", ", tempname) > syscallnamestempfile
                        linesize = length(tempname) + 8
                        align_comment(linesize, 25, syscallnamestempfile)
                        if (substr(tempname,1,1) == "#") {
-                               printf("/* %d =%s*/\n", syscall, additional_comments) > syscallnamestempfile
+                               printf("/* %d =%s*/\n", syscall_num, additional_comments) > syscallnamestempfile
                        }
                        else {
-                               printf("/* %d = %s%s*/\n", syscall, tempname, additional_comments) > syscallnamestempfile
+                               printf("/* %d = %s%s*/\n", syscall_num, tempname, additional_comments) > syscallnamestempfile
                        }
                }
 
                # output to syscalls.h
                if (add_sysheader_entry == 1) {
                        tempname = funcname
-                       if (syscall == 0) {
+                       if (syscall_num == 0) {
                                tempname = "syscall"
                        }
-                       if (tempname != "nosys") {
+                       if (tempname != "nosys" && tempname != "enosys") {
                                printf("#define\t%s%s", syscallprefix, tempname) > syshdrtempfile
                                linesize = length(syscallprefix) + length(tempname) + 12
                                align_comment(linesize, 30, syshdrtempfile)
-                               printf("%d\n", syscall) > syshdrtempfile
+                               printf("%d\n", syscall_num) > syshdrtempfile
                                # special case for gettimeofday on ppc - cctools project uses old name
                                if (tempname == "ppc_gettimeofday") {
                                        printf("#define\t%s%s", syscallprefix, "gettimeofday") > syshdrtempfile
                                        linesize = length(syscallprefix) + length(tempname) + 12
                                        align_comment(linesize, 30, syshdrtempfile)
-                                       printf("%d\n", syscall) > syshdrtempfile
+                                       printf("%d\n", syscall_num) > syshdrtempfile
                                }
                        }
-                       else {
-                               printf("\t\t\t/* %d %s*/\n", syscall, additional_comments) > syshdrtempfile
+                       else if (skip_for_header == 0) {
+                               printf("\t\t\t/* %d %s*/\n", syscall_num, additional_comments) > syshdrtempfile
                        }
                }
                
                # output function prototypes to sysproto.h
                if (add_sysproto_entry == 1) {
                        if (funcname =="exit") {
-                               printf("void %s(struct proc *, struct %s *, int *);\n", 
+                               printf("void %s(struct proc *, struct %s *, int32_t *);\n", 
                                                funcname, argalias) > sysprotoend
                        }
-                       else if (funcname != "nosys" || (syscall == 0 && funcname == "nosys")) {
+                       else if ((funcname != "nosys" && funcname != "enosys") || (syscall_num == 0 && funcname == "nosys")) {
                                printf("int %s(struct proc *, struct %s *, %s *);\n", 
                                                funcname, argalias, returntype) > sysprotoend
                        }
                }
+
+               # output to audit_kevents.c
+               printf("\t%s,\t\t", auditev) > audittempfile
+               printf("/* %d = %s%s*/\n", syscall_num, tempname, additional_comments) > audittempfile 
                
-               syscall++
+               syscall_num++
                next
        }
 
        END {
-               printf "#define AC(name) (sizeof(struct name) / sizeof(uint64_t))\n" > sysinc
+               printf "#define AC(name) (sizeof(struct name) / sizeof(syscall_arg_t))\n" > sysinc
                printf "\n" > sysinc
 
                printf("\n__END_DECLS\n") > sysprotoend
@@ -656,15 +763,38 @@ s/\$//g
 
                printf("};\n") > sysent
                printf("int     nsysent = sizeof(sysent) / sizeof(sysent[0]);\n") > sysent
+               printf("/* Verify that NUM_SYSENT reflects the latest syscall count */\n") > sysent
+               printf("int     nsysent_size_check[((sizeof(sysent) / sizeof(sysent[0])) == NUM_SYSENT) ? 1 : -1] __unused;\n") > sysent
 
                printf("};\n") > syscallnamestempfile
-               printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
+               printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall_num) \
                    > syshdrtempfile
                printf("\n#endif /* __APPLE_API_PRIVATE */\n") > syshdrtempfile
                printf("#endif /* !%s */\n", syscall_h) > syshdrtempfile
+               printf("};\n\n") > audittempfile
+               printf("#endif /* AUDIT */\n") > audittempfile
        } '
 
-cat $syslegal $sysinc $sysent > $syscalltablefile
-cat $syslegal $sysarg $sysprotoend > $sysprotofile
-cat $syslegal $syscallnamestempfile > $syscallnamesfile
-cat $syslegal $syshdrtempfile > $syshdrfile
+# define value in syscall table file to permit redifintion because of the way
+# __private_extern__ (doesn't) work.
+if [ $output_syscalltablefile -eq 1 ]; then
+    cat $syslegal > $syscalltablefile
+    printf "#define __INIT_SYSENT_C__ 1\n" >> $syscalltablefile
+    cat $sysinc $sysent >> $syscalltablefile
+fi
+
+if [ $output_syscallnamesfile -eq 1 ]; then
+    cat $syslegal $syscallnamestempfile > $syscallnamesfile
+fi
+
+if [ $output_sysprotofile -eq 1 ]; then
+    cat $syslegal $sysarg $sysprotoend > $sysprotofile
+fi
+
+if [ $output_syshdrfile -eq 1 ]; then
+    cat $syslegal $syshdrtempfile > $syshdrfile
+fi
+
+if [ $output_auditevfile -eq 1 ]; then
+    cat $syslegal $audittempfile > $auditevfile
+fi