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 "struct proc;\n\n" > sysarg
  116                 printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) ? \\\n" > sysarg
  117                 printf "\t\t0 : sizeof(register_t) - sizeof(t))\n\n" > sysarg
  118 
  119                 printf " * created from%s\n */\n\n", $0 > sysnames
  120                 printf "char *%s[] = {\n", namesname > sysnames
  121 
  122                 printf " * created from%s\n */\n\n", $0 > syshdr
  123 
  124                 printf "# created from%s\nMIASM = ", $0 > sysmk
  125 
  126                 printf " * created from%s\n */\n\n", $0 > syshide
  127                 next
  128         }
  129         NF == 0 || $1 ~ /^;/ {
  130                 next
  131         }
  132         $1 ~ /^#[       ]*include/ {
  133                 print > sysinc
  134                 next
  135         }
  136         $1 ~ /^#[       ]*if/ {
  137                 print > sysent
  138                 print > sysdcl
  139                 print > sysarg
  140                 print > syscompat
  141                 print > sysnames
  142                 print > syshide
  143                 savesyscall = syscall
  144                 next
  145         }
  146         $1 ~ /^#[       ]*else/ {
  147                 print > sysent
  148                 print > sysdcl
  149                 print > sysarg
  150                 print > syscompat
  151                 print > sysnames
  152                 print > syshide
  153                 syscall = savesyscall
  154                 next
  155         }
  156         $1 ~ /^#/ {
  157                 print > sysent
  158                 print > sysdcl
  159                 print > sysarg
  160                 print > syscompat
  161                 print > sysnames
  162                 print > syshide
  163                 next
  164         }
  165         syscall != $1 {
  166                 printf "%s: line %d: syscall number out of sync at %d\n",
  167                     infile, NR, syscall
  168                 printf "line is:\n"
  169                 print
  170                 exit 1
  171         }
  172         function parserr(was, wanted) {
  173                 printf "%s: line %d: unexpected %s (expected %s)\n",
  174                     infile, NR, was, wanted
  175                 exit 1
  176         }
  177         function parseline() {
  178                 f=4                     # toss number and type
  179                 argc= 0;
  180                 bigargc = 0;
  181                 if ($NF != "}") {
  182                         funcalias=$(NF-2)
  183                         argalias=$(NF-1)
  184                         rettype=$NF
  185                         end=NF-3
  186                 } else {
  187                         funcalias=""
  188                         argalias=""
  189                         rettype="int"
  190                         end=NF
  191                 }
  192                 if ($2 == "NODEF") {
  193                         funcname=$4
  194                         return
  195                 }
  196                 if ($f != "{")
  197                         parserr($f, "{")
  198                 f++
  199                 if ($end != "}")
  200                         parserr($end, "}")
  201                 end--
  202                 if ($end != ";")
  203                         parserr($end, ";")
  204                 end--
  205                 if ($end != ")")
  206                         parserr($end, ")")
  207                 end--
  208 
  209                 f++     #function return type
  210 
  211                 funcname=$f
  212                 if (funcalias == "")
  213                         funcalias = funcname
  214                 if (argalias == "") {
  215                         argalias = funcname "_args"
  216                         if ($2 == "COMPAT")
  217                                 argalias = "o" argalias
  218                 }
  219                 f++
  220 
  221                 if ($f != "(")
  222                         parserr($f, ")")
  223                 f++
  224 
  225                 if (f == end) {
  226                         if ($f != "void")
  227                                 parserr($f, "argument definition")
  228                         return
  229                 }
  230 
  231                 while (f <= end) {
  232                         argc++
  233                         argtype[argc]=""
  234                         oldf=""
  235                         while (f < end && $(f+1) != ",") {
  236                                 if (argtype[argc] != "" && oldf != "*")
  237                                         argtype[argc] = argtype[argc]" ";
  238                                 argtype[argc] = argtype[argc]$f;
  239                                 oldf = $f;
  240                                 f++
  241                         }
  242                         if (argtype[argc] == "")
  243                                 parserr($f, "argument definition")
  244                         if (argtype[argc] == "off_t")
  245                                 bigargc++
  246                         argname[argc]=$f;
  247                         f += 2;                 # skip name, and any comma
  248                 }
  249         }
  250         {       comment = $4
  251                 if (NF < 7)
  252                         for (i = 5; i <= NF; i++)
  253                                 comment = comment " " $i
  254         }
  255         $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS"  || $2 == "NOPROTO" \
  256             || $2 == "NOIMPL" {
  257                 parseline()
  258                 if ((!nosys || funcname != "nosys") && \
  259                     (funcname != "lkmnosys")) {
  260                         if (argc != 0 && $2 != "NOARGS" && $2 != "NOPROTO") {
  261                                 printf("struct\t%s {\n", argalias) > sysarg
  262                                 for (i = 1; i <= argc; i++)
  263                                         printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
  264                                             argtype[i], argname[i],
  265                                             argname[i], argtype[i]) > sysarg
  266                                 printf("};\n") > sysarg
  267                         }
  268                         else if($2 != "NOARGS" && $2 != "NOPROTO")
  269                                 printf("struct\t%s {\n\tregister_t dummy;\n};\n",
  270                                     argalias) > sysarg
  271                 }
  272                 if ($2 != "NOPROTO" && (!nosys || funcname != "nosys") && \
  273                     (!lkmnosys || funcname != "lkmnosys")) {
  274                         printf("%s\t%s __P((struct proc *, struct %s *))",
  275                             rettype, funcname, argalias) > sysdcl
  276                         if (funcname == "exit")
  277                                 printf(" __dead2") > sysdcl
  278                         printf(";\n") > sysdcl
  279                 }
  280                 if (funcname == "nosys")
  281                         nosys = 1
  282                 if (funcname == "lkmnosys")
  283                         lkmnosys = 1
  284                 if ($2 != "NOIMPL") {
  285                         printf("\t{ %d, (sy_call_t *)%s },\t\t",
  286                             argc+bigargc, funcname) > sysent
  287                         if(length(funcname) < 11)
  288                                 printf("\t") > sysent
  289                         printf("/* %d = %s */\n", syscall, funcalias) > sysent
  290                 } else {
  291                         printf("\t{ %d, (sy_call_t *)%s },\t\t",
  292                             argc+bigargc, "nosys") > sysent
  293                         if(length("nosys") < 11)
  294                                 printf("\t") > sysent
  295                         printf("/* %d = %s */\n", syscall, funcalias) > sysent
  296                 }
  297                 printf("\t\"%s\",\t\t\t/* %d = %s */\n",
  298                     funcalias, syscall, funcalias) > sysnames
  299                 if ($2 != "NODEF") {
  300                         printf("#define\t%s%s\t%d\n", syscallprefix,
  301                             funcalias, syscall) > syshdr
  302                         printf(" \\\n\t%s.o", funcalias) > sysmk
  303                 }
  304                 if ($3 != "NOHIDE")
  305                         printf("HIDE_%s(%s)\n", $3, funcname) > syshide
  306                 syscall++
  307                 next
  308         }
  309         $2 == "COMPAT" || $2 == "CPT_NOA" {
  310                 ncompat++
  311                 parseline()
  312                 if (argc != 0 && $2 != "CPT_NOA") {
  313                         printf("struct\t%s {\n", argalias) > syscompat
  314                         for (i = 1; i <= argc; i++)
  315                                 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
  316                                     argtype[i], argname[i],
  317                                     argname[i], argtype[i]) > syscompat
  318                         printf("};\n") > syscompat
  319                 }
  320                 else if($2 != "CPT_NOA")
  321                         printf("struct\t%s {\n\tregister_t dummy;\n};\n",
  322                             argalias) > sysarg
  323                 printf("%s\to%s __P((struct proc *, struct %s *));\n",
  324                     rettype, funcname, argalias) > syscompatdcl
  325                 printf("\t{ compat(%d,%s) },\t\t/* %d = old %s */\n",
  326                     argc+bigargc, funcname, syscall, funcalias) > sysent
  327                 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
  328                     funcalias, syscall, funcalias) > sysnames
  329                 printf("\t\t\t\t/* %d is old %s */\n",
  330                     syscall, funcalias) > syshdr
  331                 if ($3 != "NOHIDE")
  332                         printf("HIDE_%s(%s)\n", $3, funcname) > syshide
  333                 syscall++
  334                 next
  335         }
  336         $2 == "LIBCOMPAT" {
  337                 ncompat++
  338                 parseline()
  339                 printf("%s\to%s();\n", rettype, funcname) > syscompatdcl
  340                 printf("\t{ compat(%d,%s) },\t\t/* %d = old %s */\n",
  341                     argc+bigargc, funcname, syscall, funcalias) > sysent
  342                 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
  343                     funcalias, syscall, funcalias) > sysnames
  344                 printf("#define\t%s%s\t%d\t/* compatibility; still used by libc */\n",
  345                     syscallprefix, funcalias, syscall) > syshdr
  346                 printf(" \\\n\t%s.o", funcalias) > sysmk
  347                 if ($3 != "NOHIDE")
  348                         printf("HIDE_%s(%s)\n", $3, funcname) > syshide
  349                 syscall++
  350                 next
  351         }
  352         $2 == "OBSOL" {
  353                 printf("\t{ 0, (sy_call_t *)nosys },\t\t\t/* %d = obsolete %s */\n",
  354                     syscall, comment) > sysent
  355                 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
  356                     $4, syscall, comment) > sysnames
  357                 printf("\t\t\t\t/* %d is obsolete %s */\n",
  358                     syscall, comment) > syshdr
  359                 if ($3 != "NOHIDE")
  360                         printf("HIDE_%s(%s)\n", $3, $4) > syshide
  361                 syscall++
  362                 next
  363         }
  364         $2 == "UNIMPL" {
  365                 printf("\t{ 0, (sy_call_t *)nosys },\t\t\t/* %d = %s */\n",
  366                     syscall, comment) > sysent
  367                 printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
  368                     syscall, syscall, comment) > sysnames
  369                 if ($3 != "NOHIDE")
  370                         printf("HIDE_%s(%s)\n", $3, $4) > syshide
  371                 syscall++
  372                 next
  373         }
  374         {
  375                 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
  376                 exit 1
  377         }
  378         END {
  379                 if (ncompat != 0) {
  380                         printf "#include \"opt_compat.h\"\n\n" > syssw
  381                         printf "\n#ifdef %s\n", compat > sysinc
  382                         printf "#define compat(n, name) n, (sy_call_t *)__CONCAT(o,name)\n" > sysinc
  383                         printf "#else\n" > sysinc
  384                         printf "#define compat(n, name) 0, (sy_call_t *)nosys\n" > sysinc
  385                         printf "#endif\n" > sysinc
  386                 }
  387 
  388                 printf("\n#endif /* %s */\n\n", compat) > syscompatdcl
  389                 printf("#undef PAD_\n") > syscompatdcl
  390                 printf("\n#endif /* !%s */\n", sysproto_h) > syscompatdcl
  391 
  392                 printf("\n") > sysmk
  393                 printf("};\n") > sysent
  394                 printf("};\n") > sysnames
  395                 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
  396                     > syshdr
  397         } '
  398 
  399 cat $sysinc $sysent >> $syssw
  400 cat $sysarg $sysdcl $syscompat $syscompatdcl > $sysproto

Cache object: 0f9b32112902920fe21ca1267557466b


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