The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kern/makesyscalls.sh

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 #! /bin/sh -
    2 #       @(#)makesyscalls.sh     8.1 (Berkeley) 6/10/93
    3 # $FreeBSD: src/sys/kern/makesyscalls.sh,v 1.18.2.3 2000/05/01 11:29:16 peter Exp $
    4 
    5 set -e
    6 
    7 # name of compat option:
    8 compat=COMPAT_43
    9 
   10 # output files:
   11 sysnames="syscalls.c"
   12 sysproto="../sys/sysproto.h"
   13 sysproto_h=_SYS_SYSPROTO_H_
   14 syshdr="../sys/syscall.h"
   15 syssw="init_sysent.c"
   16 syshide="../sys/syscall-hide.h"
   17 syscallprefix="SYS_"
   18 switchname="sysent"
   19 namesname="syscallnames"
   20 
   21 # tmp files:
   22 sysdcl="sysent.dcl"
   23 syscompat="sysent.compat"
   24 syscompatdcl="sysent.compatdcl"
   25 sysent="sysent.switch"
   26 sysinc="sysinc.switch"
   27 sysarg="sysarg.switch"
   28 
   29 trap "rm $sysdcl $syscompat $syscompatdcl $sysent $sysinc $sysarg" 0
   30 
   31 case $# in
   32     0)  echo "Usage: $0 input-file <config-file>" 1>&2
   33         exit 1
   34         ;;
   35 esac
   36 
   37 if [ -f $2 ]; then
   38         . $2
   39 fi
   40 
   41 sed -e '
   42 s/\$//g
   43 :join
   44         /\\$/{a\
   45 
   46         N
   47         s/\\\n//
   48         b join
   49         }
   50 2,${
   51         /^#/!s/\([{}()*,]\)/ \1 /g
   52 }
   53 ' < $1 | awk "
   54         BEGIN {
   55                 sysdcl = \"$sysdcl\"
   56                 sysproto = \"$sysproto\"
   57                 sysproto_h = \"$sysproto_h\"
   58                 syscompat = \"$syscompat\"
   59                 syscompatdcl = \"$syscompatdcl\"
   60                 sysent = \"$sysent\"
   61                 sysinc = \"$sysinc\"
   62                 sysarg = \"$sysarg\"
   63                 sysnames = \"$sysnames\"
   64                 syshdr = \"$syshdr\"
   65                 compat = \"$compat\"
   66                 syshide = \"$syshide\"
   67                 syscallprefix = \"$syscallprefix\"
   68                 switchname = \"$switchname\"
   69                 namesname = \"$namesname\"
   70                 infile = \"$1\"
   71                 "'
   72 
   73                 printf "/*\n * System call switch table.\n *\n" > sysinc
   74                 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysinc
   75                 printf " * \$\FreeBSD\$\n" > sysinc
   76 
   77                 printf "/*\n * System call prototypes.\n *\n" > sysarg
   78                 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarg
   79                 printf " * \$\FreeBSD\$\n" > sysarg
   80 
   81                 printf "\n#ifdef %s\n\n", compat > syscompat
   82 
   83                 printf "/*\n * System call names.\n *\n" > sysnames
   84                 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
   85                 printf " * \$\FreeBSD\$\n" > sysnames
   86 
   87                 printf "/*\n * System call numbers.\n *\n" > syshdr
   88                 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshdr
   89                 printf " * \$\FreeBSD\$\n" > syshdr
   90                 printf "/*\n * System call hiders.\n *\n" > syshide
   91                 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshide
   92                 printf " * \$\FreeBSD\$\n" > syshide
   93         }
   94         NR == 1 {
   95                 gsub("[$]FreeBSD: ", "", $0)
   96                 gsub(" [$]", "", $0)
   97 
   98                 printf " * created from%s\n */\n\n", $0 > sysinc
   99 
  100                 printf "\n#ifdef %s\n", compat > sysent
  101                 printf "#define compat(n, name) n, (sy_call_t *)__CONCAT(o,name)\n" > sysent
  102                 printf("#else\n") > sysent
  103                 printf("#define compat(n, name) 0, (sy_call_t *)nosys\n") > sysent
  104                 printf("#endif\n\n") > sysent
  105                 printf("/* The casts are bogus but will do for now. */\n") > sysent
  106                 printf "struct sysent %s[] = {\n",switchname > sysent
  107 
  108                 printf " * created from%s\n */\n\n", $0 > sysarg
  109                 printf("#ifndef %s\n", sysproto_h) > sysarg
  110                 printf("#define\t%s\n\n", sysproto_h) > sysarg
  111                 printf "#include <sys/types.h>\n", $0 > sysarg
  112                 printf "#include <sys/param.h>\n", $0 > sysarg
  113                 printf "#include <sys/mount.h>\n\n", $0 > sysarg
  114 
  115                 printf " * created from%s\n */\n\n", $0 > sysnames
  116                 printf "char *%s[] = {\n", namesname > sysnames
  117 
  118                 printf " * created from%s\n */\n\n", $0 > syshdr
  119 
  120                 printf " * created from%s\n */\n\n", $0 > syshide
  121                 next
  122         }
  123         NF == 0 || $1 ~ /^;/ {
  124                 next
  125         }
  126         $1 ~ /^#[       ]*include/ {
  127                 print > sysinc
  128                 next
  129         }
  130         $1 ~ /^#[       ]*if/ {
  131                 print > sysent
  132                 print > sysdcl
  133                 print > sysarg
  134                 print > syscompat
  135                 print > sysnames
  136                 print > syshide
  137                 savesyscall = syscall
  138                 next
  139         }
  140         $1 ~ /^#[       ]*else/ {
  141                 print > sysent
  142                 print > sysdcl
  143                 print > sysarg
  144                 print > syscompat
  145                 print > sysnames
  146                 print > syshide
  147                 syscall = savesyscall
  148                 next
  149         }
  150         $1 ~ /^#/ {
  151                 print > sysent
  152                 print > sysdcl
  153                 print > sysarg
  154                 print > syscompat
  155                 print > sysnames
  156                 print > syshide
  157                 next
  158         }
  159         syscall != $1 {
  160                 printf "%s: line %d: syscall number out of sync at %d\n", \
  161                    infile, NR, syscall
  162                 printf "line is:\n"
  163                 print
  164                 exit 1
  165         }
  166         function parserr(was, wanted) {
  167                 printf "%s: line %d: unexpected %s (expected %s)\n", \
  168                     infile, NR, was, wanted
  169                 exit 1
  170         }
  171         function parseline() {
  172                 f=4                     # toss number and type
  173                 argc= 0;
  174                 bigargc = 0;
  175                 if ($NF != "}") {
  176                         funcalias=$(NF-2)
  177                         argalias=$(NF-1)
  178                         rettype=$NF
  179                         end=NF-3
  180                 } else {
  181                         funcalias=""
  182                         argalias=""
  183                         rettype="int"
  184                         end=NF
  185                 }
  186                 if ($2 == "NODEF") {
  187                         funcname=$4
  188                         return
  189                 }
  190                 if ($f != "{")
  191                         parserr($f, "{")
  192                 f++
  193                 if ($end != "}")
  194                         parserr($end, "}")
  195                 end--
  196                 if ($end != ";")
  197                         parserr($end, ";")
  198                 end--
  199                 if ($end != ")")
  200                         parserr($end, ")")
  201                 end--
  202 
  203                 f++     #function return type
  204 
  205                 funcname=$f
  206                 if (funcalias == "")
  207                         funcalias = funcname
  208                 if (argalias == "") {
  209                         argalias = funcname "_args"
  210                         if ($2 == "COMPAT")
  211                                 argalias = "o" argalias
  212                 }
  213                 f++
  214 
  215                 if ($f != "(")
  216                         parserr($f, ")")
  217                 f++
  218 
  219                 if (f == end) {
  220                         if ($f != "void")
  221                                 parserr($f, "argument definition")
  222                         return
  223                 }
  224 
  225                 while (f <= end) {
  226                         argc++
  227                         argtype[argc]=""
  228                         oldf=""
  229                         while (f < end && $(f+1) != ",") {
  230                                 if (argtype[argc] != "" && oldf != "*")
  231                                         argtype[argc] = argtype[argc]" ";
  232                                 argtype[argc] = argtype[argc]$f;
  233                                 oldf = $f;
  234                                 f++
  235                         }
  236                         if (argtype[argc] == "")
  237                                 parserr($f, "argument definition")
  238                         if (argtype[argc] == "off_t")
  239                                 bigargc++
  240                         argname[argc]=$f;
  241                         f += 2;                 # skip name, and any comma
  242                 }
  243         }
  244         {       comment = $4
  245                 if (NF < 7)
  246                         for (i = 5; i <= NF; i++)
  247                                 comment = comment " " $i
  248         }
  249         $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS"  || $2 == "NOPROTO" {
  250                 parseline()
  251                 if ((!nosys || funcname != "nosys") && \
  252                     (funcname != "lkmnosys")) {
  253                         if (argc != 0 && $2 != "NOARGS" && $2 != "NOPROTO") {
  254                                 printf("struct\t%s {\n", argalias) > sysarg
  255                                 for (i = 1; i <= argc; i++)
  256                                         printf("\t%s %s;\n", argtype[i],
  257                                             argname[i]) > sysarg
  258                                 printf("};\n") > sysarg
  259                         }
  260                         else if($2 != "NOARGS" && $2 != "NOPROTO")
  261                                 printf("struct\t%s {\n\tint dummy;\n};\n", \
  262                                         argalias) > sysarg
  263                 }
  264                 if ($2 != "NOPROTO" && (!nosys || funcname != "nosys") && \
  265                     (!lkmnosys || funcname != "lkmnosys")) {
  266                         printf("%s\t%s __P((struct proc *, struct %s *, int []))", \
  267                             rettype, funcname, argalias) > sysdcl
  268                         if (funcname == "exit")
  269                                 printf(" __dead2") > sysdcl
  270                         printf(";\n") > sysdcl
  271                 }
  272                 if (funcname == "nosys")
  273                         nosys = 1
  274                 if (funcname == "lkmnosys")
  275                         lkmnosys = 1
  276                 printf("\t{ %d, (sy_call_t *)%s },\t\t", \
  277                     argc+bigargc, funcname) > sysent
  278                 if(length(funcname) < 11)
  279                         printf("\t") > sysent
  280                 printf("/* %d = %s */\n", syscall, funcalias) > sysent
  281                 printf("\t\"%s\",\t\t\t/* %d = %s */\n", \
  282                     funcalias, syscall, funcalias) > sysnames
  283                 if ($2 != "NODEF")
  284                         printf("#define\t%s%s\t%d\n", syscallprefix, \
  285                             funcalias, syscall) > syshdr
  286                 if ($3 != "NOHIDE")
  287                         printf("HIDE_%s(%s)\n", $3, funcname) > syshide
  288                 syscall++
  289                 next
  290         }
  291         $2 == "COMPAT" || $2 == "CPT_NOA" {
  292                 parseline()
  293                 if (argc != 0 && $2 != "CPT_NOA") {
  294                         printf("struct\t%s {\n", argalias) > syscompat
  295                         for (i = 1; i <= argc; i++)
  296                                 printf("\t%s %s;\n", argtype[i],
  297                                     argname[i]) > syscompat
  298                         printf("};\n") > syscompat
  299                 }
  300                 else if($2 != "CPT_NOA")
  301                         printf("struct\t%s {\n\tint dummy;\n};\n", \
  302                                 argalias) > sysarg
  303                 printf("%s\to%s __P((struct proc *, struct %s *, int []));\n", \
  304                     rettype, funcname, argalias) > syscompatdcl
  305                 printf("\t{ compat(%d,%s) },\t\t/* %d = old %s */\n", \
  306                     argc+bigargc, funcname, syscall, funcalias) > sysent
  307                 printf("\t\"old.%s\",\t\t/* %d = old %s */\n", \
  308                     funcalias, syscall, funcalias) > sysnames
  309                 printf("\t\t\t\t/* %d is old %s */\n", \
  310                     syscall, funcalias) > syshdr
  311                 if ($3 != "NOHIDE")
  312                         printf("HIDE_%s(%s)\n", $3, funcname) > syshide
  313                 syscall++
  314                 next
  315         }
  316         $2 == "LIBCOMPAT" {
  317                 parseline()
  318                 printf("%s\to%s();\n", rettype, funcname) > syscompatdcl
  319                 printf("\t{ compat(%d,%s) },\t\t/* %d = old %s */\n", \
  320                     argc+bigargc, funcname, syscall, funcalias) > sysent
  321                 printf("\t\"old.%s\",\t\t/* %d = old %s */\n", \
  322                     funcalias, syscall, funcalias) > sysnames
  323                 printf("#define\t%s%s\t%d\t/* compatibility; still used by libc */\n", \
  324                     syscallprefix, funcalias, syscall) > syshdr
  325                 if ($3 != "NOHIDE")
  326                         printf("HIDE_%s(%s)\n", $3, funcname) > syshide
  327                 syscall++
  328                 next
  329         }
  330         $2 == "OBSOL" {
  331                 printf("\t{ 0, (sy_call_t *)nosys },\t\t\t/* %d = obsolete %s */\n", \
  332                     syscall, comment) > sysent
  333                 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n", \
  334                     $4, syscall, comment) > sysnames
  335                 printf("\t\t\t\t/* %d is obsolete %s */\n", \
  336                     syscall, comment) > syshdr
  337                 if ($3 != "NOHIDE")
  338                         printf("HIDE_%s(%s)\n", $3, $4) > syshide
  339                 syscall++
  340                 next
  341         }
  342         $2 == "UNIMPL" {
  343                 printf("\t{ 0, (sy_call_t *)nosys },\t\t\t/* %d = %s */\n", \
  344                     syscall, comment) > sysent
  345                 printf("\t\"#%d\",\t\t\t/* %d = %s */\n", \
  346                     syscall, syscall, comment) > sysnames
  347                 if ($3 != "NOHIDE")
  348                         printf("HIDE_%s(%s)\n", $3, $4) > syshide
  349                 syscall++
  350                 next
  351         }
  352         {
  353                 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
  354                 exit 1
  355         }
  356         END {
  357                 printf("\n#endif /* %s */\n", compat) > syscompatdcl
  358                 printf("\n#endif /* !%s */\n", sysproto_h) > syscompatdcl
  359 
  360                 printf("};\n") > sysent
  361                 printf("};\n") > sysnames
  362                 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
  363                         > syshdr
  364         } '
  365 
  366 cat $sysinc $sysent >$syssw
  367 cat $sysarg $sysdcl $syscompat $syscompatdcl > $sysproto

Cache object: 7bb7a99c6d2ec308dcda4e67ef1395f1


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.