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-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
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=4                     # toss number, type, audit event
  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 ($3 == "NODEF") {
  217                         auditev="AUE_NULL"
  218                         funcname=$4
  219                         argssize = "AS(" $6 ")"
  220                         return
  221                 }
  222                 if ($f != "{")
  223                         parserr($f, "{")
  224                 f++
  225                 if ($end != "}")
  226                         parserr($end, "}")
  227                 end--
  228                 if ($end != ";")
  229                         parserr($end, ";")
  230                 end--
  231                 if ($end != ")")
  232                         parserr($end, ")")
  233                 end--
  234 
  235                 f++     #function return type
  236 
  237                 funcname=$f
  238                 if (funcalias == "")
  239                         funcalias = funcname
  240                 if (argalias == "") {
  241                         argalias = funcname "_args"
  242                         if ($3 == "COMPAT")
  243                                 argalias = "o" argalias
  244                         if ($3 == "COMPAT4")
  245                                 argalias = "freebsd4_" argalias
  246                 }
  247                 f++
  248 
  249                 if ($f != "(")
  250                         parserr($f, ")")
  251                 f++
  252 
  253                 if (f == end) {
  254                         if ($f != "void")
  255                                 parserr($f, "argument definition")
  256                         return
  257                 }
  258 
  259                 while (f <= end) {
  260                         argc++
  261                         argtype[argc]=""
  262                         oldf=""
  263                         while (f < end && $(f+1) != ",") {
  264                                 if (argtype[argc] != "" && oldf != "*")
  265                                         argtype[argc] = argtype[argc]" ";
  266                                 argtype[argc] = argtype[argc]$f;
  267                                 oldf = $f;
  268                                 f++
  269                         }
  270                         if (argtype[argc] == "")
  271                                 parserr($f, "argument definition")
  272                         argname[argc]=$f;
  273                         f += 2;                 # skip name, and any comma
  274                 }
  275                 if (argc != 0)
  276                         argssize = "AS(" argalias ")"
  277         }
  278         {       comment = $4
  279                 if (NF < 7)
  280                         for (i = 5; i <= NF; i++)
  281                                 comment = comment " " $i
  282         }
  283 
  284         #
  285         # The AUE_ audit event identifier.
  286         #
  287         {
  288                 auditev = $2;
  289         }
  290 
  291         # The 'M' type prefix
  292         #
  293         {
  294                 mpsafe = "SYF_MPSAFE | ";
  295                 if ($3 == "MSTD") {
  296                         $3 = "STD";
  297                 } else if ($3 == "MNODEF") {
  298                         $3 = "NODEF";
  299                 } else if ($3 == "MNOARGS") {
  300                         $3 = "NOARGS";
  301                 } else if ($3 == "MNOPROTO") {
  302                         $3 = "NOPROTO";
  303                 } else if ($3 == "MNOIMPL") {
  304                         $3 = "NOIMPL";
  305                 } else if ($3 == "MNOSTD") {
  306                         $3 = "NOSTD";
  307                 } else if ($3 == "MCOMPAT") {
  308                         $3 = "COMPAT";
  309                 } else if ($3 == "MCOMPAT4") {
  310                         $3 = "COMPAT4";
  311                 } else if ($3 == "MCPT_NOA") {
  312                         $3 = "CPT_NOA";
  313                 } else if ($3 == "MLIBCOMPAT") {
  314                         $3 = "LIBCOMPAT";
  315                 } else if ($3 == "MOBSOL") {
  316                         $3 = "OBSOL";
  317                 } else if ($3 == "MUNIMPL") {
  318                         $3 = "UNIMPL";
  319                 } else {
  320                         mpsafe = "";
  321                 }
  322         }
  323         $3 == "STD" || $3 == "NODEF" || $3 == "NOARGS"  || $3 == "NOPROTO" \
  324             || $3 == "NOIMPL" || $3 == "NOSTD" {
  325                 parseline()
  326                 if ((!nosys || funcname != "nosys") && \
  327                     (funcname != "lkmnosys") && (funcname != "lkmressys")) {
  328                         if (argc != 0 && $3 != "NOARGS" && $3 != "NOPROTO") {
  329                                 printf("struct %s {\n", argalias) > sysarg
  330                                 for (i = 1; i <= argc; i++)
  331                                         printf("\tchar %s_l_[PADL_(%s)]; " \
  332                                             "%s %s; char %s_r_[PADR_(%s)];\n",
  333                                             argname[i], argtype[i],
  334                                             argtype[i], argname[i],
  335                                             argname[i], argtype[i]) > sysarg
  336                                 printf("};\n") > sysarg
  337                         }
  338                         else if ($3 != "NOARGS" && $3 != "NOPROTO" && \
  339                             $3 != "NODEF")
  340                                 printf("struct %s {\n\tregister_t dummy;\n};\n",
  341                                     argalias) > sysarg
  342                 }
  343                 if (($3 != "NOPROTO" && $3 != "NODEF" && \
  344                     (funcname != "nosys" || !nosys)) || \
  345                     (funcname == "lkmnosys" && !lkmnosys) || \
  346                     funcname == "lkmressys") {
  347                         printf("%s\t%s(struct thread *, struct %s *)",
  348                             rettype, funcname, argalias) > sysdcl
  349                         printf(";\n") > sysdcl
  350                 }
  351                 if (funcname == "nosys")
  352                         nosys = 1
  353                 if (funcname == "lkmnosys")
  354                         lkmnosys = 1
  355                 printf("\t{ %s%s, (sy_call_t *)", mpsafe, argssize) > sysent
  356                 column = 8 + 2 + length(mpsafe) + length(argssize) + 15
  357                 if ($3 == "NOIMPL") {
  358                         printf("%s },", "nosys, AUE_NULL") > sysent
  359                         column = column + length("nosys") + 3
  360                 } else if ($3 == "NOSTD") {
  361                         printf("%s },", "lkmressys, AUE_NULL") > sysent
  362                         column = column + length("lkmressys") + 3
  363                 } else {
  364                         printf("%s, %s },", funcname, auditev) > sysent
  365                         column = column + length(funcname) + length(auditev) + 3
  366                 } 
  367                 align_sysent_comment(column)
  368                 printf("/* %d = %s */\n", syscall, funcalias) > sysent
  369                 printf("\t\"%s\",\t\t\t/* %d = %s */\n",
  370                     funcalias, syscall, funcalias) > sysnames
  371                 if ($3 != "NODEF") {
  372                         printf("#define\t%s%s\t%d\n", syscallprefix,
  373                             funcalias, syscall) > syshdr
  374                         printf(" \\\n\t%s.o", funcalias) > sysmk
  375                 }
  376                 syscall++
  377                 next
  378         }
  379         $3 == "COMPAT" || $3 == "COMPAT4" || $3 == "CPT_NOA" {
  380                 if ($3 == "COMPAT" || $3 == "CPT_NOA") {
  381                         ncompat++
  382                         out = syscompat
  383                         outdcl = syscompatdcl
  384                         wrap = "compat"
  385                         prefix = "o"
  386                 } else if ($3 == "COMPAT4") {
  387                         ncompat4++
  388                         out = syscompat4
  389                         outdcl = syscompat4dcl
  390                         wrap = "compat4"
  391                         prefix = "freebsd4_"
  392                 }
  393                 parseline()
  394                 if (argc != 0 && $3 != "CPT_NOA") {
  395                         printf("struct %s {\n", argalias) > out
  396                         for (i = 1; i <= argc; i++)
  397                                 printf("\tchar %s_l_[PADL_(%s)]; %s %s; " \
  398                                     "char %s_r_[PADR_(%s)];\n",
  399                                     argname[i], argtype[i],
  400                                     argtype[i], argname[i],
  401                                     argname[i], argtype[i]) > out
  402                         printf("};\n") > out
  403                 }
  404                 else if($3 != "CPT_NOA")
  405                         printf("struct %s {\n\tregister_t dummy;\n};\n",
  406                             argalias) > sysarg
  407                 printf("%s\t%s%s(struct thread *, struct %s *);\n",
  408                     rettype, prefix, funcname, argalias) > outdcl
  409                 printf("\t{ %s(%s%s,%s), %s },",
  410                     wrap, mpsafe, argssize, funcname, auditev) > sysent
  411                 align_sysent_comment(8 + 9 + length(mpsafe) + \
  412                     length(argssize) + 1 + length(funcname) + length(auditev) + 4)
  413                 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
  414                 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
  415                     funcalias, syscall, funcalias) > sysnames
  416                 printf("\t\t\t\t/* %d is old %s */\n",
  417                     syscall, funcalias) > syshdr
  418                 syscall++
  419                 next
  420         }
  421         $3 == "LIBCOMPAT" {
  422                 ncompat++
  423                 parseline()
  424                 printf("%s\to%s();\n", rettype, funcname) > syscompatdcl
  425                 printf("\t{ compat(%s%s,%s), %s },",
  426                     mpsafe, argssize, funcname, auditev) > sysent
  427                 align_sysent_comment(8 + 9 + length(mpsafe) + \
  428                     length(argssize) + 1 + length(funcname) + length(auditev) + 4)
  429                 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
  430                 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
  431                     funcalias, syscall, funcalias) > sysnames
  432                 printf("#define\t%s%s\t%d\t/* compatibility; still used by libc */\n",
  433                     syscallprefix, funcalias, syscall) > syshdr
  434                 printf(" \\\n\t%s.o", funcalias) > sysmk
  435                 syscall++
  436                 next
  437         }
  438         $3 == "OBSOL" {
  439                 printf("\t{ 0, (sy_call_t *)nosys, AUE_NULL },") > sysent
  440                 align_sysent_comment(34)
  441                 printf("/* %d = obsolete %s */\n", syscall, comment) > sysent
  442                 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
  443                     $4, syscall, comment) > sysnames
  444                 printf("\t\t\t\t/* %d is obsolete %s */\n",
  445                     syscall, comment) > syshdr
  446                 syscall++
  447                 next
  448         }
  449         $3 == "UNIMPL" {
  450                 printf("\t{ 0, (sy_call_t *)nosys, AUE_NULL },\t\t\t/* %d = %s */\n",
  451                     syscall, comment) > sysent
  452                 printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
  453                     syscall, syscall, comment) > sysnames
  454                 syscall++
  455                 next
  456         }
  457         {
  458                 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $3
  459                 exit 1
  460         }
  461         END {
  462                 printf "\n#define AS(name) (sizeof(struct name) / sizeof(register_t))\n" > sysinc
  463 
  464                 if (ncompat != 0 || ncompat4 != 0)
  465                         printf "#include \"opt_compat.h\"\n\n" > syssw
  466                 printf "#include \<bsm/audit_kevents.h\>\n" > syssw
  467 
  468                 if (ncompat != 0) {
  469                         printf "\n#ifdef %s\n", compat > sysinc
  470                         printf "#define compat(n, name) n, (sy_call_t *)__CONCAT(o,name)\n" > sysinc
  471                         printf "#else\n" > sysinc
  472                         printf "#define compat(n, name) 0, (sy_call_t *)nosys\n" > sysinc
  473                         printf "#endif\n" > sysinc
  474                 }
  475 
  476                 if (ncompat4 != 0) {
  477                         printf "\n#ifdef %s\n", compat4 > sysinc
  478                         printf "#define compat4(n, name) n, (sy_call_t *)__CONCAT(freebsd4_,name)\n" > sysinc
  479                         printf "#else\n" > sysinc
  480                         printf "#define compat4(n, name) 0, (sy_call_t *)nosys\n" > sysinc
  481                         printf "#endif\n" > sysinc
  482                 }
  483 
  484                 printf("\n#endif /* %s */\n\n", compat) > syscompatdcl
  485 
  486                 printf("\n#endif /* %s */\n\n", compat4) > syscompat4dcl
  487 
  488                 printf("#undef PAD_\n") > sysprotoend
  489                 printf("#undef PADL_\n") > sysprotoend
  490                 printf("#undef PADR_\n") > sysprotoend
  491                 printf("\n#endif /* !%s */\n", sysproto_h) > sysprotoend
  492 
  493                 printf("\n") > sysmk
  494                 printf("};\n") > sysent
  495                 printf("};\n") > sysnames
  496                 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
  497                     > syshdr
  498         } '
  499 
  500 cat $sysinc $sysent >> $syssw
  501 cat $sysarg $sysdcl \
  502         $syscompat $syscompatdcl \
  503         $syscompat4 $syscompat4dcl \
  504         $sysprotoend > $sysproto
  505 

Cache object: c2098d624ba59df2f25c6a24541350ca


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