5 # Generates kdump_subr.c
6 # mkioctls is a special-purpose script, and works fine as it is
7 # now, so it remains independent. The idea behind how it generates
8 # its list was heavily borrowed here.
10 # Some functions here are automatically generated. This can mean
11 # the user will see unusual kdump output or errors while building
12 # if the underlying .h files are changed significantly.
15 # AUTO: Completely auto-generated with either the "or" or the "switch"
17 # AUTO - Special: Generated automatically, but with some extra commands
18 # that the auto_*_type() functions are inappropriate for.
19 # MANUAL: Manually entered and must therefore be manually updated.
23 LC_ALL=C; export LC_ALL
27 echo "usage: sh $0 include-dir"
33 # Automatically generates a C function that will print out the
34 # numeric input as a pipe-delimited string of the appropriate
36 # S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
37 # The XOR is necessary to prevent including the "0"-value in every
54 egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
55 $include_dir/$file | \
56 awk '{ for (i = 1; i <= NF; i++) \
60 printf "\tif(!((arg>0)^((%s)>0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }'
64 (void)printf("<invalid>%ld", (long)arg);
71 # Automatically generates a C function used when the argument
72 # maps to a single, specific #definition
87 egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
88 $include_dir/$file | \
89 awk '{ for (i = 1; i <= NF; i++) \
93 printf "\tcase %s:\n\t\t(void)printf(\"%s\");\n\t\tbreak;\n", $i, $i }'
95 default: /* Should not reach */
96 (void)printf("<invalid=%ld>", (long)arg);
104 # Automatically generates a C function used when the argument
105 # maps to a #definition
119 egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
120 $include_dir/$file | \
121 awk '{ printf "\t"; \
124 printf "if (arg == %s) \n\t\tprintf(\"%s\");\n", $2, $2 }'
126 else /* Should not reach */
127 (void)printf("<invalid=%ld>", (long)arg);
137 #include <sys/fcntl.h>
138 #include <sys/stat.h>
139 #include <sys/unistd.h>
140 #include <sys/mman.h>
141 #include <sys/wait.h>
143 #include <sys/socket.h>
145 #include <netinet/in.h>
146 #include <sys/param.h>
147 #include <sys/mount.h>
148 #include <sys/ptrace.h>
149 #include <sys/resource.h>
150 #include <sys/reboot.h>
152 #include <sys/linker.h>
156 #include <sys/extattr.h>
161 #include <sys/rtprio.h>
163 #include <nfsserver/nfs.h>
164 #include <ufs/ufs/quota.h>
166 #include "kdump_subr.h"
169 * These are simple support macros. print_or utilizes a variable
170 * defined in the calling function to track whether or not it should
171 * print a logical-OR character ('|') before a string. if_print_or
172 * simply handles the necessary "if" statement used in many lines
175 #define print_or(str,orflag) do { \\
176 if (orflag) putchar('|'); else orflag = 1; \\
179 #define if_print_or(i,flag,orflag) do { \\
180 if ((i & flag) == flag) \\
181 print_or(#flag,orflag); } \\
185 extern char *signames[]; /* from kdump.c */
189 if (sig > 0 && sig < NSIG)
190 (void)printf("SIG%s",signames[sig]);
192 (void)printf("SIG %d", sig);
201 (void)printf("GETNCNT");
204 (void)printf("GETPID");
207 (void)printf("GETVAL");
210 (void)printf("GETALL");
213 (void)printf("GETZCNT");
216 (void)printf("SETVAL");
219 (void)printf("SETALL");
222 (void)printf("IPC_RMID");
225 (void)printf("IPC_SET");
228 (void)printf("IPC_STAT");
230 default: /* Should not reach */
231 (void)printf("<invalid=%ld>", (long)cmd);
237 shmctlname (int cmd) {
240 (void)printf("IPC_RMID");
243 (void)printf("IPC_SET");
246 (void)printf("IPC_STAT");
248 default: /* Should not reach */
249 (void)printf("<invalid=%ld>", (long)cmd);
255 semgetname (int flag) {
257 if_print_or(flag, IPC_CREAT, or);
258 if_print_or(flag, IPC_EXCL, or);
259 if_print_or(flag, SEM_R, or);
260 if_print_or(flag, SEM_A, or);
261 if_print_or(flag, (SEM_R>>3), or);
262 if_print_or(flag, (SEM_A>>3), or);
263 if_print_or(flag, (SEM_R>>6), or);
264 if_print_or(flag, (SEM_A>>6), or);
270 * Only used by SYS_open. Unless O_CREAT is set in flags, the
271 * mode argument is unused (and often bogus and misleading).
274 flagsandmodename (int flags, int mode, int decimal) {
277 if ((flags & O_CREAT) == O_CREAT) {
281 (void)printf("<unused>%ld", (long)mode);
283 (void)printf("<unused>%#lx", (long)mode);
291 * [g|s]etsockopt's level argument can either be SOL_SOCKET or a value
292 * referring to a line in /etc/protocols . It might be appropriate
293 * to use getprotoent(3) here.
296 sockoptlevelname (int level, int decimal)
298 if (level == SOL_SOCKET) {
299 (void)printf("SOL_SOCKET");
302 (void)printf("%ld", (long)level);
304 (void)printf("%#lx", (long)level);
311 auto_or_type "modename" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h"
312 auto_or_type "flagsname" "O_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h"
313 auto_or_type "accessmodename" "[A-Z]_OK[[:space:]]+0?x?[0-9A-Fa-f]+" "sys/unistd.h"
314 auto_or_type "mmapprotname" "PROT_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
315 auto_or_type "mmapflagsname" "MAP_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
316 auto_or_type "wait4optname" "W[A-Z]+[[:space:]]+[0-9]+" "sys/wait.h"
317 auto_or_type "getfsstatflagsname" "MNT_[A-Z]+[[:space:]]+[1-9][0-9]*" "sys/mount.h"
318 auto_or_type "mountflagsname" "MNT_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mount.h"
319 auto_or_type "rebootoptname" "RB_[A-Z]+[[:space:]]+0x[0-9]+" "sys/reboot.h"
320 auto_or_type "flockname" "LOCK_[A-Z]+[[:space:]]+0x[0-9]+" "sys/fcntl.h"
321 auto_or_type "thrcreateflagsname" "THR_[A-Z]+[[:space:]]+0x[0-9]+" "sys/thr.h"
322 auto_or_type "mlockallname" "MCL_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
323 auto_or_type "shmatname" "SHM_[A-Z]+[[:space:]]+[0-9]{6}+" "sys/shm.h"
324 auto_or_type "rforkname" "RF[A-Z]+[[:space:]]+\([0-9]+<<[0-9]+\)" "sys/unistd.h"
325 auto_or_type "nfssvcname" "NFSSVC_[A-Z]+[[:space:]]+0x[0-9]+" "nfsserver/nfs.h"
327 auto_switch_type "whencename" "SEEK_[A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h"
328 auto_switch_type "rlimitname" "RLIMIT_[A-Z]+[[:space:]]+[0-9]+" "sys/resource.h"
329 auto_switch_type "shutdownhowname" "SHUT_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
330 auto_switch_type "prioname" "PRIO_[A-Z]+[[:space:]]+[0-9]" "sys/resource.h"
331 auto_switch_type "madvisebehavname" "_?MADV_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
332 auto_switch_type "msyncflagsname" "MS_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
333 auto_switch_type "schedpolicyname" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sched.h"
334 auto_switch_type "kldunloadfflagsname" "LINKER_UNLOAD_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
335 auto_switch_type "extattrctlname" "EXTATTR_NAMESPACE_[A-Z]+[[:space:]]+0x[0-9]+" "sys/extattr.h"
336 auto_switch_type "kldsymcmdname" "KLDSYM_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
337 auto_switch_type "sendfileflagsname" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
338 auto_switch_type "acltypename" "ACL_TYPE_[A-Z4_]+[[:space:]]+0x[0-9]+" "sys/acl.h"
339 auto_switch_type "sigprocmaskhowname" "SIG_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
340 auto_switch_type "lio_listioname" "LIO_(NO)?WAIT[[:space:]]+[0-9]+" "aio.h"
341 auto_switch_type "minheritname" "INHERIT_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
342 auto_switch_type "quotactlname" "Q_[A-Z]+[[:space:]]+0x[0-9]+" "ufs/ufs/quota.h"
343 auto_if_type "sockdomainname" "PF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
344 auto_if_type "sockfamilyname" "AF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
345 auto_if_type "sockipprotoname" "IPPROTO_[[:alnum:]]+[[:space:]]+" "netinet/in.h"
346 auto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h"
347 auto_switch_type "socktypename" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h"
348 auto_switch_type "ptraceopname" "PT_[[:alnum:]]+[[:space:]]+[0-9]+" "sys/ptrace.h"
353 * F_ is used to specify fcntl commands as well as arguments. Both sets are
354 * grouped in fcntl.h, and this awk script grabs the first group.
357 fcntlcmdname (int cmd, int arg, int decimal)
361 egrep "^#[[:space:]]*define[[:space:]]+F_[A-Z]+[[:space:]]+[0-9]+[[:space:]]*" \
362 $include_dir/sys/fcntl.h | \
363 awk 'BEGIN { o=0 } { for (i = 1; i <= NF; i++) \
368 printf "\tcase %s:\n\t\t(void)printf(\"%s\");\n\t\tbreak;\n", $i, $i; \
373 default: /* Should not reach */
374 (void)printf("<invalid=%ld>", (long)cmd);
377 if (cmd == F_GETFD || cmd == F_SETFD) {
378 if (arg == FD_CLOEXEC)
379 (void)printf("FD_CLOEXEC");
384 (void)printf("<invalid>%ld", (long)arg);
386 (void)printf("<invalid>%#lx", (long)arg);
388 } else if (cmd == F_SETFL) {
392 (void)printf("%ld", (long)arg);
394 (void)printf("%#lx", (long)arg);
401 * The only reason this is not fully automated is due to the
402 * grep -v RTP_PRIO statement. A better egrep line should
403 * make this capable of being a auto_switch_type() function.
406 rtprioname (int func)
410 egrep "^#[[:space:]]*define[[:space:]]+RTP_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" \
411 $include_dir/sys/rtprio.h | grep -v RTP_PRIO | \
412 awk '{ for (i = 1; i <= NF; i++) \
416 printf "\tcase %s:\n\t\t(void)printf(\"%s\");\n\t\tbreak;\n", $i, $i }'
418 default: /* Should not reach */
419 (void)printf("<invalid=%ld>", (long)func);
426 * The send and recv functions have a flags argument which can be
427 * set to 0. There is no corresponding #define. The auto_ functions
428 * detect this as "invalid", which is incorrect here.
431 sendrecvflagsname (int flags)
440 printf("%#x<", flags);
442 egrep "^#[[:space:]]*define[[:space:]]+MSG_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" $include_dir/sys/socket.h | \
443 awk '{ for (i = 1; i <= NF; i++) \
447 printf "\tif(!((flags>0)^((%s)>0)))\n\t\tif_print_or(flags, %s, or);\n", $i, $i }'