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

Cache object: 2815c497a5cf7bd0f9d8417b3bba9eac


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