Thu Sep 24 14:30:52 2015 UTC ()
create an array of altsyscallnames, which are the syscall names that the
libc api uses. For example syscallnames[293] = "__sigprocmask14",
altsyscallnames[293] = "sigprocmask". This is so that things like dtrace
can use the system call names everyone uses. The array is sparse; if the
names were the same (or for compat names) they are not copied and the array
has NULL for them.


(christos)
diff -r1.153 -r1.154 src/sys/kern/makesyscalls.sh

cvs diff -r1.153 -r1.154 src/sys/kern/makesyscalls.sh (expand / switch to unified diff)

--- src/sys/kern/makesyscalls.sh 2015/05/09 10:57:04 1.153
+++ src/sys/kern/makesyscalls.sh 2015/09/24 14:30:52 1.154
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: makesyscalls.sh,v 1.153 2015/05/09 10:57:04 pooka Exp $ 1# $NetBSD: makesyscalls.sh,v 1.154 2015/09/24 14:30:52 christos Exp $
2# 2#
3# Copyright (c) 1994, 1996, 2000 Christopher G. Demetriou 3# Copyright (c) 1994, 1996, 2000 Christopher G. Demetriou
4# All rights reserved. 4# All rights reserved.
5# 5#
6# Redistribution and use in source and binary forms, with or without 6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions 7# modification, are permitted provided that the following conditions
8# are met: 8# are met:
9# 1. Redistributions of source code must retain the above copyright 9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer. 10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright 11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the 12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution. 13# documentation and/or other materials provided with the distribution.
14# 3. All advertising materials mentioning features or use of this software 14# 3. All advertising materials mentioning features or use of this software
@@ -72,33 +72,37 @@ rumpnoflags="\n\t\t.sy_flags = SYCALL_NO @@ -72,33 +72,37 @@ rumpnoflags="\n\t\t.sy_flags = SYCALL_NO
72rumpnosys="(sy_call_t *)rumpns_enosys" 72rumpnosys="(sy_call_t *)rumpns_enosys"
73rumpnomodule="(sy_call_t *)rumpns_sys_nomodule" 73rumpnomodule="(sy_call_t *)rumpns_sys_nomodule"
74 74
75case $1 in 75case $1 in
76/*) . $1;; 76/*) . $1;;
77*) . ./$1;; 77*) . ./$1;;
78esac 78esac
79 79
80# tmp files: 80# tmp files:
81sysdcl="sysent.dcl" 81sysdcl="sysent.dcl"
82sysprotos="sys.protos" 82sysprotos="sys.protos"
83syscompat_pref="sysent." 83syscompat_pref="sysent."
84sysent="sysent.switch" 84sysent="sysent.switch"
85sysnamesbottom="sysnames.bottom" 85sysnamesbottom="$sysnames.bottom"
 86sysnamesfriendly="$sysnames.friendly"
86rumptypes="rumphdr.types" 87rumptypes="rumphdr.types"
87rumpprotos="rumphdr.protos" 88rumpprotos="rumphdr.protos"
88systracetmp="systrace.$$" 89systracetmp="systrace.$$"
89systraceret="systraceret.$$" 90systraceret="systraceret.$$"
90 91
91trap "rm $sysdcl $sysprotos $sysent $sysnamesbottom $rumpsysent $rumptypes $rumpprotos $systracetmp $systraceret" 0 92cleanup() {
 93 rm $sysdcl $sysprotos $sysent $sysnamesbottom $sysnamesfriendly $rumpsysent $rumptypes $rumpprotos $systracetmp $systraceret
 94}
 95trap "cleanup" 0
92 96
93# Awk program (must support nawk extensions) 97# Awk program (must support nawk extensions)
94# Use "awk" at Berkeley, "nawk" or "gawk" elsewhere. 98# Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
95awk=${AWK:-awk} 99awk=${AWK:-awk}
96 100
97# Does this awk have a "toupper" function? 101# Does this awk have a "toupper" function?
98have_toupper="$($awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null)" 102have_toupper="$($awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null)"
99 103
100# If this awk does not define "toupper" then define our own. 104# If this awk does not define "toupper" then define our own.
101if [ "$have_toupper" = TRUE ] ; then 105if [ "$have_toupper" = TRUE ] ; then
102 # Used awk (GNU awk or nawk) provides it 106 # Used awk (GNU awk or nawk) provides it
103 toupper= 107 toupper=
104else 108else
@@ -161,27 +165,28 @@ BEGIN { @@ -161,27 +165,28 @@ BEGIN {
161 switchname = \"$switchname\" 165 switchname = \"$switchname\"
162 namesname = \"$namesname\" 166 namesname = \"$namesname\"
163 constprefix = \"$constprefix\" 167 constprefix = \"$constprefix\"
164 registertype = \"$registertype\" 168 registertype = \"$registertype\"
165 sysalign=\"$sysalign\" 169 sysalign=\"$sysalign\"
166 if (!registertype) { 170 if (!registertype) {
167 registertype = \"register_t\" 171 registertype = \"register_t\"
168 } 172 }
169 nsysent = \"$nsysent\" 173 nsysent = \"$nsysent\"
170 174
171 sysdcl = \"$sysdcl\" 175 sysdcl = \"$sysdcl\"
172 syscompat_pref = \"$syscompat_pref\" 176 syscompat_pref = \"$syscompat_pref\"
173 sysent = \"$sysent\" 177 sysent = \"$sysent\"
174 sysnamesbottom = \"$sysnamesbottom\" 178 sysnamesbottom = \"${sysnames}.bottom\"
 179 sysnamesfriendly = \"${sysnames}.friendly\"
175 rumpprotos = \"$rumpprotos\" 180 rumpprotos = \"$rumpprotos\"
176 rumptypes = \"$rumptypes\" 181 rumptypes = \"$rumptypes\"
177 sys_nosys = \"$sys_nosys\" 182 sys_nosys = \"$sys_nosys\"
178 maxsysargs = \"$maxsysargs\" 183 maxsysargs = \"$maxsysargs\"
179 rumpnoflags=\"$rumpnoflags\" 184 rumpnoflags=\"$rumpnoflags\"
180 rumpnosys=\"$rumpnosys\" 185 rumpnosys=\"$rumpnosys\"
181 rumpnomodule=\"$rumpnomodule\" 186 rumpnomodule=\"$rumpnomodule\"
182 infile = \"$2\" 187 infile = \"$2\"
183 188
184 compatopts = \"$compatopts\" 189 compatopts = \"$compatopts\"
185 "' 190 "'
186 191
187 if (rumpcalls != "/dev/null") 192 if (rumpcalls != "/dev/null")
@@ -301,28 +306,32 @@ NR == 1 { @@ -301,28 +306,32 @@ NR == 1 {
301 printf "\nvoid rumpns_sys_nomodule(void);\n" > rumpcalls 306 printf "\nvoid rumpns_sys_nomodule(void);\n" > rumpcalls
302 307
303 printf "\n#ifndef RUMP_CLIENT\n" > rumpsysent 308 printf "\n#ifndef RUMP_CLIENT\n" > rumpsysent
304 printf "int rumpns_enosys(void);\n" > rumpsysent 309 printf "int rumpns_enosys(void);\n" > rumpsysent
305 printf "#define\ts(type)\tsizeof(type)\n" > rumpsysent 310 printf "#define\ts(type)\tsizeof(type)\n" > rumpsysent
306 printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > rumpsysent 311 printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > rumpsysent
307 printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > rumpsysent 312 printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > rumpsysent
308 printf "struct sysent rump_sysent[] = {\n" > rumpsysent 313 printf "struct sysent rump_sysent[] = {\n" > rumpsysent
309 314
310 # System call names are included by userland (kdump(1)), so 315 # System call names are included by userland (kdump(1)), so
311 # hide the include files from it. 316 # hide the include files from it.
312 printf "#if defined(_KERNEL_OPT)\n" > sysnames 317 printf "#if defined(_KERNEL_OPT)\n" > sysnames
313 318
 319 printf "#else /* _KERNEL_OPT */\n" > sysnamesbottom
 320 printf "#include <sys/null.h>\n" > sysnamesbottom
314 printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom 321 printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
315 printf "const char *const %s[] = {\n",namesname > sysnamesbottom 322 printf "const char *const %s[] = {\n",namesname > sysnamesbottom
 323 printf "\n\n/* libc style syscall names */\n" > sysnamesfriendly
 324 printf "const char *const alt%s[] = {\n", namesname > sysnamesfriendly
316 325
317 printf " * created from%s\n */\n\n", $0 > sysnumhdr 326 printf " * created from%s\n */\n\n", $0 > sysnumhdr
318 printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr 327 printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
319 printf "#define _" constprefix "SYSCALL_H_\n\n" > sysnumhdr 328 printf "#define _" constprefix "SYSCALL_H_\n\n" > sysnumhdr
320 329
321 printf " * created from%s\n */\n\n", $0 > sysarghdr 330 printf " * created from%s\n */\n\n", $0 > sysarghdr
322 printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr 331 printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
323 printf "#define _" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr 332 printf "#define _" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
324 333
325 printf " * created from%s\n */\n\n", $0 > rumpcallshdr 334 printf " * created from%s\n */\n\n", $0 > rumpcallshdr
326 printf "#ifndef _RUMP_RUMP_SYSCALLS_H_\n" > rumpcallshdr 335 printf "#ifndef _RUMP_RUMP_SYSCALLS_H_\n" > rumpcallshdr
327 printf "#define _RUMP_RUMP_SYSCALLS_H_\n\n" > rumpcallshdr 336 printf "#define _RUMP_RUMP_SYSCALLS_H_\n\n" > rumpcallshdr
328 printf "#ifdef _KERNEL\n" > rumpcallshdr 337 printf "#ifdef _KERNEL\n" > rumpcallshdr
@@ -432,26 +441,27 @@ $1 ~ /^#/ && intable { @@ -432,26 +441,27 @@ $1 ~ /^#/ && intable {
432 exit 1 441 exit 1
433 } 442 }
434 if (auto_skip == savedepth) { 443 if (auto_skip == savedepth) {
435 print > sysautoload 444 print > sysautoload
436 } 445 }
437 auto_skip = skip_auto[savedepth]; 446 auto_skip = skip_auto[savedepth];
438 savedepth-- 447 savedepth--
439 } 448 }
440 print > sysent 449 print > sysent
441 print > sysarghdr 450 print > sysarghdr
442 print > sysnumhdr 451 print > sysnumhdr
443 print > sysprotos 452 print > sysprotos
444 print > sysnamesbottom 453 print > sysnamesbottom
 454 print > sysnamesfriendly
445 print > systrace 455 print > systrace
446 print > systracetmp 456 print > systracetmp
447 print > systraceret 457 print > systraceret
448 458
449 # XXX: technically we do not want to have conditionals in rump, 459 # XXX: technically we do not want to have conditionals in rump,
450 # but it is easier to just let the cpp handle them than try to 460 # but it is easier to just let the cpp handle them than try to
451 # figure out what we want here in this script 461 # figure out what we want here in this script
452 print > rumpsysent 462 print > rumpsysent
453 next 463 next
454} 464}
455syscall != $1 { 465syscall != $1 {
456 printf "%s: line %d: syscall number out of sync at %d\n", \ 466 printf "%s: line %d: syscall number out of sync at %d\n", \
457 infile, NR, syscall 467 infile, NR, syscall
@@ -842,26 +852,32 @@ function putent(type, compatwrap) { @@ -842,26 +852,32 @@ function putent(type, compatwrap) {
842 else 852 else
843 wfn = compatwrap "(" funcname ")"; 853 wfn = compatwrap "(" funcname ")";
844 wfn_cast="(sy_call_t *)" wfn 854 wfn_cast="(sy_call_t *)" wfn
845 if (sycall_flags != "0") 855 if (sycall_flags != "0")
846 flags = "\n\t\t.sy_flags = " sycall_flags "," 856 flags = "\n\t\t.sy_flags = " sycall_flags ","
847 else 857 else
848 flags = "" 858 flags = ""
849 printf("%s\n\t\t.sy_call = %s\n\t},", flags, wfn_cast) > sysent 859 printf("%s\n\t\t.sy_call = %s\n\t},", flags, wfn_cast) > sysent
850 printf("\t\t/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent 860 printf("\t\t/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
851 861
852 # output syscall name for names table 862 # output syscall name for names table
853 printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \ 863 printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
854 > sysnamesbottom 864 > sysnamesbottom
 865 if (compatwrap_ != "" || fbase == funcalias)
 866 printf("\t/* %3d */\tNULL, /* %s%s */\n", syscall, \
 867 compatwrap_, funcalias) > sysnamesfriendly
 868 else
 869 printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, \
 870 fbase) > sysnamesfriendly
855 871
856 # output syscall number of header, if appropriate 872 # output syscall number of header, if appropriate
857 if (type == "STD" || type == "NOARGS" || type == "INDIR" || \ 873 if (type == "STD" || type == "NOARGS" || type == "INDIR" || \
858 type == "NOERR") { 874 type == "NOERR") {
859 # output a prototype, to be used to generate lint stubs in 875 # output a prototype, to be used to generate lint stubs in
860 # libc. 876 # libc.
861 printproto("") 877 printproto("")
862 } else if (type == "COMPAT" || type == "EXTERN") { 878 } else if (type == "COMPAT" || type == "EXTERN") {
863 # Just define the syscall number with a comment. These 879 # Just define the syscall number with a comment. These
864 # may be used by compatibility stubs in libc. 880 # may be used by compatibility stubs in libc.
865 printproto(compatwrap_) 881 printproto(compatwrap_)
866 } 882 }
867 883
@@ -1031,26 +1047,28 @@ $2 == "OBSOL" || $2 == "UNIMPL" || $2 == @@ -1031,26 +1047,28 @@ $2 == "OBSOL" || $2 == "UNIMPL" || $2 ==
1031 comment="unimplemented" 1047 comment="unimplemented"
1032 for (i = 3; i <= NF; i++) 1048 for (i = 3; i <= NF; i++)
1033 comment=comment " " $i 1049 comment=comment " " $i
1034 1050
1035 if ($2 == "IGNORED") 1051 if ($2 == "IGNORED")
1036 sys_stub = "(sy_call_t *)nullop"; 1052 sys_stub = "(sy_call_t *)nullop";
1037 else 1053 else
1038 sys_stub = sys_nosys; 1054 sys_stub = sys_nosys;
1039 1055
1040 print fillerpsysent(syscall, "", sys_stub, comment) > sysent 1056 print fillerpsysent(syscall, "", sys_stub, comment) > sysent
1041 print fillerpsysent(syscall, rumpnoflags, rumpnosys, comment) > rumpsysent 1057 print fillerpsysent(syscall, rumpnoflags, rumpnosys, comment) > rumpsysent
1042 printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \ 1058 printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
1043 > sysnamesbottom 1059 > sysnamesbottom
 1060 printf("\t/* %3d */\tNULL, /* %s */\n", syscall, comment) \
 1061 > sysnamesfriendly
1044 if ($2 != "UNIMPL") 1062 if ($2 != "UNIMPL")
1045 printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr 1063 printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
1046 syscall++ 1064 syscall++
1047 next 1065 next
1048} 1066}
1049$2 == "EXTERN" { 1067$2 == "EXTERN" {
1050 parseline() 1068 parseline()
1051 putent("EXTERN", "") 1069 putent("EXTERN", "")
1052 syscall++ 1070 syscall++
1053 next 1071 next
1054} 1072}
1055{ 1073{
1056 for (i = 1; i <= ncompat; i++) { 1074 for (i = 1; i <= ncompat; i++) {
@@ -1096,52 +1114,56 @@ END { @@ -1096,52 +1114,56 @@ END {
1096 } 1114 }
1097 1115
1098 maxsyscall = syscall 1116 maxsyscall = syscall
1099 if (nsysent) { 1117 if (nsysent) {
1100 if (syscall > nsysent) { 1118 if (syscall > nsysent) {
1101 printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent) 1119 printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
1102 exit 1 1120 exit 1
1103 } 1121 }
1104 while (syscall < nsysent) { 1122 while (syscall < nsysent) {
1105 print fillerpsysent(syscall, "", sys_nosys, "filler") > sysent 1123 print fillerpsysent(syscall, "", sys_nosys, "filler") > sysent
1106 print fillerpsysent(syscall, rumpnoflags, rumpnosys, "filler") > rumpsysent 1124 print fillerpsysent(syscall, rumpnoflags, rumpnosys, "filler") > rumpsysent
1107 printf("\t/* %3d */\t\"# filler\",\n", syscall) \ 1125 printf("\t/* %3d */\t\"# filler\",\n", syscall) \
1108 > sysnamesbottom 1126 > sysnamesbottom
 1127 printf("\t/* %3d */\tNULL, /* filler */\n", syscall) \
 1128 > sysnamesfriendly
1109 syscall++ 1129 syscall++
1110 } 1130 }
1111 } 1131 }
1112 printf("};\n") > sysent 1132 printf("};\n") > sysent
1113 printf("};\n") > rumpsysent 1133 printf("};\n") > rumpsysent
1114 printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent 1134 printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent
1115 printf("__strong_alias(rumpns_sysent,rump_sysent);\n") > rumpsysent 1135 printf("__strong_alias(rumpns_sysent,rump_sysent);\n") > rumpsysent
1116 printf("#endif /* RUMP_CLIENT */\n") > rumpsysent 1136 printf("#endif /* RUMP_CLIENT */\n") > rumpsysent
1117 if (haverumpcalls) 1137 if (haverumpcalls)
1118 printf("#endif /* !RUMP_CLIENT */\n") > sysprotos 1138 printf("#endif /* !RUMP_CLIENT */\n") > sysprotos
1119 printf("};\n") > sysnamesbottom 1139 printf("};\n") > sysnamesbottom
 1140 printf("};\n") > sysnamesfriendly
1120 printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr 1141 printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
1121 if (nsysent) 1142 if (nsysent)
1122 printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr 1143 printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
1123 printf "\tdefault:\n\t\t*n_args = 0;\n\t\tbreak;\n\t};\n}\n" > systrace 1144 printf "\tdefault:\n\t\t*n_args = 0;\n\t\tbreak;\n\t};\n}\n" > systrace
1124 printf "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n" > systracetmp 1145 printf "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n" > systracetmp
1125 printf "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n" > systraceret 1146 printf "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n" > systraceret
1126} ' 1147} '
1127 1148
1128cat $sysprotos >> $sysarghdr 1149cat $sysprotos >> $sysarghdr
1129echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr 1150echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
1130echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr 1151echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
1131echo "};" >> $sysautoload 1152echo "};" >> $sysautoload
1132printf "\n#endif /* _RUMP_RUMP_SYSCALLS_H_ */\n" >> $rumpprotos 1153printf "\n#endif /* _RUMP_RUMP_SYSCALLS_H_ */\n" >> $rumpprotos
1133cat $sysdcl $sysent > $syssw 1154cat $sysdcl $sysent > $syssw
1134cat $sysnamesbottom >> $sysnames 1155cat $sysnamesbottom >> $sysnames
 1156cat $sysnamesfriendly >> $sysnames
1135cat $rumpsysent >> $rumpcalls 1157cat $rumpsysent >> $rumpcalls
1136 1158
1137touch $rumptypes 1159touch $rumptypes
1138cat $rumptypes >> $rumpcallshdr 1160cat $rumptypes >> $rumpcallshdr
1139echo >> $rumpcallshdr 1161echo >> $rumpcallshdr
1140cat $rumpprotos >> $rumpcallshdr 1162cat $rumpprotos >> $rumpcallshdr
1141 1163
1142#chmod 444 $sysnames $sysnumhdr $syssw 1164#chmod 444 $sysnames $sysnumhdr $syssw
1143 1165
1144cat $systracetmp >> $systrace 1166cat $systracetmp >> $systrace
1145cat $systraceret >> $systrace 1167cat $systraceret >> $systrace
1146 1168
1147echo Generated following files: 1169echo Generated following files: