3 # Copyright (c) 2006 "David Kirchner" <dpk@dpk.net>. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # Generates kdump_subr.c
29 # mkioctls is a special-purpose script, and works fine as it is
30 # now, so it remains independent. The idea behind how it generates
31 # its list was heavily borrowed here.
33 # Some functions here are automatically generated. This can mean
34 # the user will see unusual kdump output or errors while building
35 # if the underlying .h files are changed significantly.
38 # AUTO: Completely auto-generated with either the "or" or the "switch"
40 # AUTO - Special: Generated automatically, but with some extra commands
41 # that the auto_*_type() functions are inappropriate for.
42 # MANUAL: Manually entered and must therefore be manually updated.
46 LC_ALL=C; export LC_ALL
50 echo "usage: sh $0 include-dir"
56 # Automatically generates a C function that will print out the
57 # numeric input as a pipe-delimited string of the appropriate
59 # S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
60 # The XOR is necessary to prevent including the "0"-value in every
75 printf("%#jx<", (uintmax_t)arg);
77 egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
78 $include_dir/$file | \
79 awk '{ for (i = 1; i <= NF; i++) \
83 printf "\tif (!((arg > 0) ^ ((%s) > 0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }'
87 printf("<invalid>%jd", arg);
94 # Automatically generates a C function used when the argument
95 # maps to a single, specific #definition
110 egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
111 $include_dir/$file | \
112 awk '{ for (i = 1; i <= NF; i++) \
116 printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }'
118 default: /* Should not reach */
119 printf("<invalid=%jd>", arg);
127 # Automatically generates a C function used when the argument
128 # maps to a #definition
142 egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
143 $include_dir/$file | \
144 awk '{ printf "\t"; \
147 printf "if (arg == %s) \n\t\tprintf(\"%s\");\n", $2, $2 }'
149 else /* Should not reach */
150 printf("<invalid=%jd>", arg);
161 #include <sys/fcntl.h>
162 #include <sys/stat.h>
163 #include <sys/unistd.h>
164 #include <sys/mman.h>
165 #include <sys/wait.h>
167 #include <sys/socket.h>
169 #include <netinet/in.h>
170 #include <sys/param.h>
171 #include <sys/mount.h>
172 #include <sys/ptrace.h>
173 #include <sys/resource.h>
174 #include <sys/reboot.h>
176 #include <sys/linker.h>
180 #include <sys/extattr.h>
185 #include <sys/rtprio.h>
187 #include <nfsserver/nfs.h>
188 #include <ufs/ufs/quota.h>
189 #include <sys/capability.h>
191 #include <vm/vm_param.h>
193 #include "kdump_subr.h"
196 * These are simple support macros. print_or utilizes a variable
197 * defined in the calling function to track whether or not it should
198 * print a logical-OR character ('|') before a string. if_print_or
199 * simply handles the necessary "if" statement used in many lines
202 #define print_or(str,orflag) do { \\
203 if (orflag) putchar('|'); else orflag = 1; \\
206 #define if_print_or(i,flag,orflag) do { \\
207 if ((i & flag) == flag) \\
208 print_or(#flag,orflag); } \\
212 extern char *signames[]; /* from kdump.c */
216 if (sig > 0 && sig < NSIG)
217 printf("SIG%s",signames[sig]);
219 printf("SIG %d", sig);
257 default: /* Should not reach */
258 printf("<invalid=%d>", cmd);
276 default: /* Should not reach */
277 printf("<invalid=%d>", cmd);
286 if_print_or(flag, IPC_CREAT, or);
287 if_print_or(flag, IPC_EXCL, or);
288 if_print_or(flag, SEM_R, or);
289 if_print_or(flag, SEM_A, or);
290 if_print_or(flag, (SEM_R>>3), or);
291 if_print_or(flag, (SEM_A>>3), or);
292 if_print_or(flag, (SEM_R>>6), or);
293 if_print_or(flag, (SEM_A>>6), or);
299 * Only used by SYS_open. Unless O_CREAT is set in flags, the
300 * mode argument is unused (and often bogus and misleading).
303 flagsandmodename(int flags, int mode, int decimal)
307 if ((flags & O_CREAT) == O_CREAT) {
311 printf("<unused>%d", mode);
313 printf("<unused>%#x", (unsigned int)mode);
321 * [g|s]etsockopt's level argument can either be SOL_SOCKET or a value
322 * referring to a line in /etc/protocols . It might be appropriate
323 * to use getprotoent(3) here.
326 sockoptlevelname(int level, int decimal)
328 if (level == SOL_SOCKET) {
329 printf("SOL_SOCKET");
334 printf("%#x", (unsigned int)level);
342 * Used for page fault type. Cannot use auto_or_type since the macro
343 * values contain a cast. Also, VM_PROT_NONE has to be handled specially.
346 vmprotname (int type)
350 if (type == VM_PROT_NONE) {
351 (void)printf("VM_PROT_NONE");
354 if_print_or(type, VM_PROT_READ, or);
355 if_print_or(type, VM_PROT_WRITE, or);
356 if_print_or(type, VM_PROT_EXECUTE, or);
357 if_print_or(type, VM_PROT_COPY, or);
361 auto_or_type "accessmodename" "[A-Z]_OK[[:space:]]+0?x?[0-9A-Fa-f]+" "sys/unistd.h"
362 auto_switch_type "acltypename" "ACL_TYPE_[A-Z4_]+[[:space:]]+0x[0-9]+" "sys/acl.h"
363 auto_or_type "capname" "CAP_[A-Z]+[[:space:]]+0x[01248]{16}ULL" "sys/capability.h"
364 auto_or_type "capfcntlname" "CAP_FCNTL_[A-Z]+[[:space:]]+\(1" "sys/capability.h"
365 auto_switch_type "extattrctlname" "EXTATTR_NAMESPACE_[A-Z]+[[:space:]]+0x[0-9]+" "sys/extattr.h"
366 auto_switch_type "fadvisebehavname" "POSIX_FADV_[A-Z]+[[:space:]]+[0-9]+" "sys/fcntl.h"
367 auto_or_type "flagsname" "O_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h"
368 auto_or_type "flockname" "LOCK_[A-Z]+[[:space:]]+0x[0-9]+" "sys/fcntl.h"
369 auto_or_type "getfsstatflagsname" "MNT_[A-Z]+[[:space:]]+[1-9][0-9]*" "sys/mount.h"
370 auto_switch_type "kldsymcmdname" "KLDSYM_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
371 auto_switch_type "kldunloadfflagsname" "LINKER_UNLOAD_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
372 auto_switch_type "lio_listioname" "LIO_(NO)?WAIT[[:space:]]+[0-9]+" "aio.h"
373 auto_switch_type "madvisebehavname" "_?MADV_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
374 auto_switch_type "minheritname" "INHERIT_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
375 auto_or_type "mlockallname" "MCL_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
376 auto_or_type "mmapflagsname" "MAP_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
377 auto_or_type "mmapprotname" "PROT_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
378 auto_or_type "modename" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h"
379 auto_or_type "mountflagsname" "MNT_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mount.h"
380 auto_switch_type "msyncflagsname" "MS_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
381 auto_or_type "nfssvcname" "NFSSVC_[A-Z0-9]+[[:space:]]+0x[0-9]+" "nfs/nfssvc.h"
382 auto_switch_type "prioname" "PRIO_[A-Z]+[[:space:]]+[0-9]" "sys/resource.h"
383 auto_switch_type "ptraceopname" "PT_[[:alnum:]_]+[[:space:]]+[0-9]+" "sys/ptrace.h"
384 auto_switch_type "quotactlname" "Q_[A-Z]+[[:space:]]+0x[0-9]+" "ufs/ufs/quota.h"
385 auto_or_type "rebootoptname" "RB_[A-Z]+[[:space:]]+0x[0-9]+" "sys/reboot.h"
386 auto_or_type "rforkname" "RF[A-Z]+[[:space:]]+\([0-9]+<<[0-9]+\)" "sys/unistd.h"
387 auto_switch_type "rlimitname" "RLIMIT_[A-Z]+[[:space:]]+[0-9]+" "sys/resource.h"
388 auto_switch_type "schedpolicyname" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sched.h"
389 auto_switch_type "sendfileflagsname" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
390 auto_or_type "shmatname" "SHM_[A-Z]+[[:space:]]+[0-9]{6}+" "sys/shm.h"
391 auto_switch_type "shutdownhowname" "SHUT_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
392 auto_switch_type "sigbuscodename" "BUS_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
393 auto_switch_type "sigchldcodename" "CLD_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
394 auto_switch_type "sigfpecodename" "FPE_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
395 auto_switch_type "sigprocmaskhowname" "SIG_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
396 auto_switch_type "sigillcodename" "ILL_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
397 auto_switch_type "sigsegvcodename" "SEGV_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
398 auto_switch_type "sigtrapcodename" "TRAP_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
399 auto_if_type "sockdomainname" "PF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
400 auto_if_type "sockfamilyname" "AF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
401 auto_if_type "sockipprotoname" "IPPROTO_[[:alnum:]]+[[:space:]]+" "netinet/in.h"
402 auto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h"
403 auto_switch_type "socktypename" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h"
404 auto_or_type "thrcreateflagsname" "THR_[A-Z]+[[:space:]]+0x[0-9]+" "sys/thr.h"
405 auto_switch_type "vmresultname" "KERN_[A-Z]+[[:space:]]+[0-9]+" "vm/vm_param.h"
406 auto_or_type "wait4optname" "W[A-Z]+[[:space:]]+[0-9]+" "sys/wait.h"
407 auto_switch_type "whencename" "SEEK_[A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h"
412 * F_ is used to specify fcntl commands as well as arguments. Both sets are
413 * grouped in fcntl.h, and this awk script grabs the first group.
416 fcntlcmdname(int cmd, int arg, int decimal)
420 egrep "^#[[:space:]]*define[[:space:]]+F_[A-Z0-9_]+[[:space:]]+[0-9]+[[:space:]]*" \
421 $include_dir/sys/fcntl.h | \
422 awk 'BEGIN { o=0 } { for (i = 1; i <= NF; i++) \
427 printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i; \
432 default: /* Should not reach */
433 printf("<invalid=%d>", cmd);
436 if (cmd == F_GETFD || cmd == F_SETFD) {
437 if (arg == FD_CLOEXEC)
438 printf("FD_CLOEXEC");
443 printf("<invalid>%d", arg);
445 printf("<invalid>%#x", (unsigned int)arg);
447 } else if (cmd == F_SETFL) {
453 printf("%#x", (unsigned int)arg);
460 * The only reason this is not fully automated is due to the
461 * grep -v RTP_PRIO statement. A better egrep line should
462 * make this capable of being a auto_switch_type() function.
469 egrep "^#[[:space:]]*define[[:space:]]+RTP_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" \
470 $include_dir/sys/rtprio.h | grep -v RTP_PRIO | \
471 awk '{ for (i = 1; i <= NF; i++) \
475 printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }'
477 default: /* Should not reach */
478 printf("<invalid=%d>", func);
485 * The send and recv functions have a flags argument which can be
486 * set to 0. There is no corresponding #define. The auto_ functions
487 * detect this as "invalid", which is incorrect here.
490 sendrecvflagsname(int flags)
499 printf("%#x<", flags);
501 egrep "^#[[:space:]]*define[[:space:]]+MSG_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" $include_dir/sys/socket.h | \
502 awk '{ for (i = 1; i <= NF; i++) \
506 printf "\tif(!((flags>0)^((%s)>0)))\n\t\tif_print_or(flags, %s, or);\n", $i, $i }'
514 * Check general codes first, then defer to signal-specific codes.
517 sigcodename(int sig, int code)
521 egrep "^#[[:space:]]*define[[:space:]]+SI_[A-Z]+[[:space:]]+0(x[0-9abcdef]+)?[[:space:]]*" \
522 $include_dir/sys/signal.h | grep -v SI_UNDEFINED | \
523 awk '{ for (i = 1; i <= NF; i++) \
527 printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }'
532 sigillcodename(code);
535 sigbuscodename(code);
538 sigsegvcodename(code);
541 sigfpecodename(code);
544 sigtrapcodename(code);
547 sigchldcodename(code);
550 printf("<invalid=%#x>", code);