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

Cache object: 69e8c6420a02c5c80a4d2b0b116c88fe


[ 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.