1175936Sdes#!/bin/sh 2175936Sdes# 3223173Snetchild# Copyright (c) 2006 "David Kirchner" <dpk@dpk.net>. All rights reserved. 4223173Snetchild# 5223173Snetchild# Redistribution and use in source and binary forms, with or without 6223173Snetchild# modification, are permitted provided that the following conditions 7223173Snetchild# are met: 8223173Snetchild# 1. Redistributions of source code must retain the above copyright 9223173Snetchild# notice, this list of conditions and the following disclaimer. 10223173Snetchild# 2. Redistributions in binary form must reproduce the above copyright 11223173Snetchild# notice, this list of conditions and the following disclaimer in the 12223173Snetchild# documentation and/or other materials provided with the distribution. 13223173Snetchild# 14223173Snetchild# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15223173Snetchild# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16223173Snetchild# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17223173Snetchild# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18223173Snetchild# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19223173Snetchild# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20223173Snetchild# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21223173Snetchild# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22223173Snetchild# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23223173Snetchild# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24223173Snetchild# SUCH DAMAGE. 25223173Snetchild# 26175936Sdes# $FreeBSD$ 27175936Sdes# 28158766Snetchild# Generates kdump_subr.c 29158766Snetchild# mkioctls is a special-purpose script, and works fine as it is 30158766Snetchild# now, so it remains independent. The idea behind how it generates 31158766Snetchild# its list was heavily borrowed here. 32158766Snetchild# 33158766Snetchild# Some functions here are automatically generated. This can mean 34158766Snetchild# the user will see unusual kdump output or errors while building 35158766Snetchild# if the underlying .h files are changed significantly. 36158766Snetchild# 37158766Snetchild# Key: 38158766Snetchild# AUTO: Completely auto-generated with either the "or" or the "switch" 39158766Snetchild# method. 40158766Snetchild# AUTO - Special: Generated automatically, but with some extra commands 41158766Snetchild# that the auto_*_type() functions are inappropriate for. 42158766Snetchild# MANUAL: Manually entered and must therefore be manually updated. 43158766Snetchild 44175936Sdesset -e 45158766Snetchild 46158766SnetchildLC_ALL=C; export LC_ALL 47158766Snetchild 48158766Snetchildif [ -z "$1" ] 49158766Snetchildthen 50158766Snetchild echo "usage: sh $0 include-dir" 51158766Snetchild exit 1 52158766Snetchildfi 53158766Snetchildinclude_dir=$1 54158766Snetchild 55158766Snetchild# 56158766Snetchild# Automatically generates a C function that will print out the 57158766Snetchild# numeric input as a pipe-delimited string of the appropriate 58158766Snetchild# #define keys. ex: 59158766Snetchild# S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH 60158766Snetchild# The XOR is necessary to prevent including the "0"-value in every 61158766Snetchild# line. 62158766Snetchild# 63158766Snetchildauto_or_type () { 64158766Snetchild local name grep file 65158766Snetchild name=$1 66158766Snetchild grep=$2 67158766Snetchild file=$3 68158766Snetchild 69158766Snetchild cat <<_EOF_ 70158766Snetchild/* AUTO */ 71158766Snetchildvoid 72258442Sjhb$name(intmax_t arg) 73158766Snetchild{ 74258442Sjhb int or = 0; 75258442Sjhb printf("%#jx<", (uintmax_t)arg); 76158766Snetchild_EOF_ 77158766Snetchild egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \ 78158766Snetchild $include_dir/$file | \ 79158766Snetchild awk '{ for (i = 1; i <= NF; i++) \ 80158766Snetchild if ($i ~ /define/) \ 81158766Snetchild break; \ 82158766Snetchild ++i; \ 83258442Sjhb printf "\tif (!((arg > 0) ^ ((%s) > 0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }' 84158766Snetchildcat <<_EOF_ 85212728Srpaulo printf(">"); 86158766Snetchild if (or == 0) 87258442Sjhb printf("<invalid>%jd", arg); 88158766Snetchild} 89158766Snetchild 90158766Snetchild_EOF_ 91158766Snetchild} 92158766Snetchild 93158766Snetchild# 94158766Snetchild# Automatically generates a C function used when the argument 95158766Snetchild# maps to a single, specific #definition 96158766Snetchild# 97158766Snetchildauto_switch_type () { 98158766Snetchild local name grep file 99158766Snetchild name=$1 100158766Snetchild grep=$2 101158766Snetchild file=$3 102158766Snetchild 103158766Snetchild cat <<_EOF_ 104158766Snetchild/* AUTO */ 105158766Snetchildvoid 106258442Sjhb$name(intmax_t arg) 107158766Snetchild{ 108158766Snetchild switch (arg) { 109158766Snetchild_EOF_ 110158766Snetchild egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \ 111158766Snetchild $include_dir/$file | \ 112158766Snetchild awk '{ for (i = 1; i <= NF; i++) \ 113158766Snetchild if ($i ~ /define/) \ 114158766Snetchild break; \ 115158766Snetchild ++i; \ 116258442Sjhb printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }' 117158766Snetchildcat <<_EOF_ 118158766Snetchild default: /* Should not reach */ 119258442Sjhb printf("<invalid=%jd>", arg); 120158766Snetchild } 121158766Snetchild} 122158766Snetchild 123158766Snetchild_EOF_ 124158766Snetchild} 125158766Snetchild 126165756Srodrigc# 127165756Srodrigc# Automatically generates a C function used when the argument 128165756Srodrigc# maps to a #definition 129165756Srodrigc# 130165756Srodrigcauto_if_type () { 131165756Srodrigc local name grep file 132165756Srodrigc name=$1 133165756Srodrigc grep=$2 134165756Srodrigc file=$3 135165756Srodrigc 136165756Srodrigc cat <<_EOF_ 137165756Srodrigc/* AUTO */ 138165756Srodrigcvoid 139258442Sjhb$name(intmax_t arg) 140165756Srodrigc{ 141165756Srodrigc_EOF_ 142165756Srodrigc egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \ 143165756Srodrigc $include_dir/$file | \ 144165756Srodrigc awk '{ printf "\t"; \ 145165756Srodrigc if (NR > 1) \ 146165756Srodrigc printf "else " ; \ 147165756Srodrigc printf "if (arg == %s) \n\t\tprintf(\"%s\");\n", $2, $2 }' 148165756Srodrigccat <<_EOF_ 149165756Srodrigc else /* Should not reach */ 150258442Sjhb printf("<invalid=%jd>", arg); 151165756Srodrigc} 152165756Srodrigc 153165756Srodrigc_EOF_ 154165756Srodrigc} 155165756Srodrigc 156158766Snetchild# C start 157158766Snetchild 158158766Snetchildcat <<_EOF_ 159258442Sjhb#include <stdint.h> 160158766Snetchild#include <stdio.h> 161158766Snetchild#include <sys/fcntl.h> 162158766Snetchild#include <sys/stat.h> 163158766Snetchild#include <sys/unistd.h> 164158766Snetchild#include <sys/mman.h> 165158766Snetchild#include <sys/wait.h> 166158766Snetchild#define _KERNEL 167158766Snetchild#include <sys/socket.h> 168158766Snetchild#undef _KERNEL 169165758Srodrigc#include <netinet/in.h> 170158766Snetchild#include <sys/param.h> 171158766Snetchild#include <sys/mount.h> 172260208Sjhb#include <sys/procctl.h> 173168543Semaste#include <sys/ptrace.h> 174158766Snetchild#include <sys/resource.h> 175158766Snetchild#include <sys/reboot.h> 176158766Snetchild#include <sched.h> 177158766Snetchild#include <sys/linker.h> 178158766Snetchild#define _KERNEL 179158766Snetchild#include <sys/thr.h> 180158766Snetchild#undef _KERNEL 181158766Snetchild#include <sys/extattr.h> 182158766Snetchild#include <sys/acl.h> 183158766Snetchild#include <aio.h> 184158766Snetchild#include <sys/sem.h> 185158766Snetchild#include <sys/ipc.h> 186158766Snetchild#include <sys/rtprio.h> 187158766Snetchild#include <sys/shm.h> 188158766Snetchild#include <nfsserver/nfs.h> 189158766Snetchild#include <ufs/ufs/quota.h> 190237663Sjhb#include <vm/vm.h> 191237663Sjhb#include <vm/vm_param.h> 192158766Snetchild 193158766Snetchild#include "kdump_subr.h" 194158766Snetchild 195158766Snetchild/* 196158766Snetchild * These are simple support macros. print_or utilizes a variable 197158766Snetchild * defined in the calling function to track whether or not it should 198158766Snetchild * print a logical-OR character ('|') before a string. if_print_or 199158766Snetchild * simply handles the necessary "if" statement used in many lines 200158766Snetchild * of this file. 201158766Snetchild */ 202158766Snetchild#define print_or(str,orflag) do { \\ 203158766Snetchild if (orflag) putchar('|'); else orflag = 1; \\ 204158766Snetchild printf (str); } \\ 205158766Snetchild while (0) 206158766Snetchild#define if_print_or(i,flag,orflag) do { \\ 207158766Snetchild if ((i & flag) == flag) \\ 208158766Snetchild print_or(#flag,orflag); } \\ 209158766Snetchild while (0) 210158766Snetchild 211158766Snetchild/* MANUAL */ 212158766Snetchildextern char *signames[]; /* from kdump.c */ 213158766Snetchildvoid 214258442Sjhbsigname(int sig) 215158766Snetchild{ 216160295Skib if (sig > 0 && sig < NSIG) 217258442Sjhb printf("SIG%s",signames[sig]); 218160295Skib else 219258442Sjhb printf("SIG %d", sig); 220158766Snetchild} 221158766Snetchild 222158766Snetchild/* MANUAL */ 223158766Snetchildvoid 224258442Sjhbsemctlname(int cmd) 225158766Snetchild{ 226158766Snetchild switch (cmd) { 227158766Snetchild case GETNCNT: 228258442Sjhb printf("GETNCNT"); 229158766Snetchild break; 230158766Snetchild case GETPID: 231258442Sjhb printf("GETPID"); 232158766Snetchild break; 233158766Snetchild case GETVAL: 234258442Sjhb printf("GETVAL"); 235158766Snetchild break; 236158766Snetchild case GETALL: 237258442Sjhb printf("GETALL"); 238158766Snetchild break; 239158766Snetchild case GETZCNT: 240258442Sjhb printf("GETZCNT"); 241158766Snetchild break; 242158766Snetchild case SETVAL: 243258442Sjhb printf("SETVAL"); 244158766Snetchild break; 245158766Snetchild case SETALL: 246258442Sjhb printf("SETALL"); 247158766Snetchild break; 248158766Snetchild case IPC_RMID: 249258442Sjhb printf("IPC_RMID"); 250158766Snetchild break; 251158766Snetchild case IPC_SET: 252258442Sjhb printf("IPC_SET"); 253158766Snetchild break; 254158766Snetchild case IPC_STAT: 255258442Sjhb printf("IPC_STAT"); 256158766Snetchild break; 257158766Snetchild default: /* Should not reach */ 258258442Sjhb printf("<invalid=%d>", cmd); 259158766Snetchild } 260158766Snetchild} 261158766Snetchild 262158766Snetchild/* MANUAL */ 263158766Snetchildvoid 264258442Sjhbshmctlname(int cmd) 265258442Sjhb{ 266158766Snetchild switch (cmd) { 267158766Snetchild case IPC_RMID: 268258442Sjhb printf("IPC_RMID"); 269158766Snetchild break; 270158766Snetchild case IPC_SET: 271258442Sjhb printf("IPC_SET"); 272158766Snetchild break; 273158766Snetchild case IPC_STAT: 274258442Sjhb printf("IPC_STAT"); 275158766Snetchild break; 276158766Snetchild default: /* Should not reach */ 277258442Sjhb printf("<invalid=%d>", cmd); 278158766Snetchild } 279158766Snetchild} 280158766Snetchild 281158766Snetchild/* MANUAL */ 282158766Snetchildvoid 283258442Sjhbsemgetname(int flag) 284258442Sjhb{ 285258442Sjhb int or = 0; 286216130Sdelphij if_print_or(flag, IPC_CREAT, or); 287216130Sdelphij if_print_or(flag, IPC_EXCL, or); 288158766Snetchild if_print_or(flag, SEM_R, or); 289158766Snetchild if_print_or(flag, SEM_A, or); 290158766Snetchild if_print_or(flag, (SEM_R>>3), or); 291158766Snetchild if_print_or(flag, (SEM_A>>3), or); 292158766Snetchild if_print_or(flag, (SEM_R>>6), or); 293158766Snetchild if_print_or(flag, (SEM_A>>6), or); 294158766Snetchild} 295158766Snetchild 296158766Snetchild/* 297158766Snetchild * MANUAL 298158766Snetchild * 299158766Snetchild * Only used by SYS_open. Unless O_CREAT is set in flags, the 300158766Snetchild * mode argument is unused (and often bogus and misleading). 301158766Snetchild */ 302158766Snetchildvoid 303258442Sjhbflagsandmodename(int flags, int mode, int decimal) 304258442Sjhb{ 305258442Sjhb flagsname(flags); 306258442Sjhb putchar(','); 307158766Snetchild if ((flags & O_CREAT) == O_CREAT) { 308158766Snetchild modename (mode); 309158766Snetchild } else { 310158766Snetchild if (decimal) { 311258442Sjhb printf("<unused>%d", mode); 312158766Snetchild } else { 313258442Sjhb printf("<unused>%#x", (unsigned int)mode); 314158766Snetchild } 315158766Snetchild } 316158766Snetchild} 317158766Snetchild 318259829Sjhb/* MANUAL */ 319259829Sjhbvoid 320259829Sjhbidtypename(idtype_t idtype, int decimal) 321259829Sjhb{ 322259829Sjhb switch(idtype) { 323259829Sjhb case P_PID: 324259829Sjhb printf("P_PID"); 325259829Sjhb break; 326259829Sjhb case P_PPID: 327259829Sjhb printf("P_PPID"); 328259829Sjhb break; 329259829Sjhb case P_PGID: 330259829Sjhb printf("P_PGID"); 331259829Sjhb break; 332259829Sjhb case P_SID: 333259829Sjhb printf("P_SID"); 334259829Sjhb break; 335259829Sjhb case P_CID: 336259829Sjhb printf("P_CID"); 337259829Sjhb break; 338259829Sjhb case P_UID: 339259829Sjhb printf("P_UID"); 340259829Sjhb break; 341259829Sjhb case P_GID: 342259829Sjhb printf("P_GID"); 343259829Sjhb break; 344259829Sjhb case P_ALL: 345259829Sjhb printf("P_ALL"); 346259829Sjhb break; 347259829Sjhb case P_LWPID: 348259829Sjhb printf("P_LWPID"); 349259829Sjhb break; 350259829Sjhb case P_TASKID: 351259829Sjhb printf("P_TASKID"); 352259829Sjhb break; 353259829Sjhb case P_PROJID: 354259829Sjhb printf("P_PROJID"); 355259829Sjhb break; 356259829Sjhb case P_POOLID: 357259829Sjhb printf("P_POOLID"); 358259829Sjhb break; 359259829Sjhb case P_JAILID: 360259829Sjhb printf("P_JAILID"); 361259829Sjhb break; 362259829Sjhb case P_CTID: 363259829Sjhb printf("P_CTID"); 364259829Sjhb break; 365259829Sjhb case P_CPUID: 366259829Sjhb printf("P_CPUID"); 367259829Sjhb break; 368259829Sjhb case P_PSETID: 369259829Sjhb printf("P_PSETID"); 370259829Sjhb break; 371259829Sjhb default: 372259829Sjhb if (decimal) { 373259829Sjhb printf("%d", idtype); 374259829Sjhb } else { 375259829Sjhb printf("%#x", idtype); 376259829Sjhb } 377259829Sjhb } 378259829Sjhb} 379259829Sjhb 380158766Snetchild/* 381158766Snetchild * MANUAL 382158766Snetchild * 383158766Snetchild * [g|s]etsockopt's level argument can either be SOL_SOCKET or a value 384158766Snetchild * referring to a line in /etc/protocols . It might be appropriate 385158766Snetchild * to use getprotoent(3) here. 386158766Snetchild */ 387158766Snetchildvoid 388258442Sjhbsockoptlevelname(int level, int decimal) 389158766Snetchild{ 390158766Snetchild if (level == SOL_SOCKET) { 391258442Sjhb printf("SOL_SOCKET"); 392158766Snetchild } else { 393158766Snetchild if (decimal) { 394258442Sjhb printf("%d", level); 395158766Snetchild } else { 396258442Sjhb printf("%#x", (unsigned int)level); 397158766Snetchild } 398158766Snetchild } 399158766Snetchild} 400158766Snetchild 401237663Sjhb/* 402237663Sjhb * MANUAL 403237663Sjhb * 404237663Sjhb * Used for page fault type. Cannot use auto_or_type since the macro 405237663Sjhb * values contain a cast. Also, VM_PROT_NONE has to be handled specially. 406237663Sjhb */ 407237663Sjhbvoid 408237663Sjhbvmprotname (int type) 409237663Sjhb{ 410237663Sjhb int or = 0; 411237663Sjhb 412237663Sjhb if (type == VM_PROT_NONE) { 413237663Sjhb (void)printf("VM_PROT_NONE"); 414237663Sjhb return; 415237663Sjhb } 416237663Sjhb if_print_or(type, VM_PROT_READ, or); 417237663Sjhb if_print_or(type, VM_PROT_WRITE, or); 418237663Sjhb if_print_or(type, VM_PROT_EXECUTE, or); 419237663Sjhb if_print_or(type, VM_PROT_COPY, or); 420237663Sjhb} 421158766Snetchild_EOF_ 422158766Snetchild 423258442Sjhbauto_or_type "accessmodename" "[A-Z]_OK[[:space:]]+0?x?[0-9A-Fa-f]+" "sys/unistd.h" 424258442Sjhbauto_switch_type "acltypename" "ACL_TYPE_[A-Z4_]+[[:space:]]+0x[0-9]+" "sys/acl.h" 425258442Sjhbauto_switch_type "extattrctlname" "EXTATTR_NAMESPACE_[A-Z]+[[:space:]]+0x[0-9]+" "sys/extattr.h" 426258442Sjhbauto_switch_type "fadvisebehavname" "POSIX_FADV_[A-Z]+[[:space:]]+[0-9]+" "sys/fcntl.h" 427258442Sjhbauto_or_type "flagsname" "O_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h" 428258442Sjhbauto_or_type "flockname" "LOCK_[A-Z]+[[:space:]]+0x[0-9]+" "sys/fcntl.h" 429258442Sjhbauto_or_type "getfsstatflagsname" "MNT_[A-Z]+[[:space:]]+[1-9][0-9]*" "sys/mount.h" 430258442Sjhbauto_switch_type "kldsymcmdname" "KLDSYM_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h" 431258442Sjhbauto_switch_type "kldunloadfflagsname" "LINKER_UNLOAD_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h" 432258442Sjhbauto_switch_type "lio_listioname" "LIO_(NO)?WAIT[[:space:]]+[0-9]+" "aio.h" 433258442Sjhbauto_switch_type "madvisebehavname" "_?MADV_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h" 434258442Sjhbauto_switch_type "minheritname" "INHERIT_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h" 435258442Sjhbauto_or_type "mlockallname" "MCL_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h" 436258442Sjhbauto_or_type "mmapprotname" "PROT_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h" 437258442Sjhbauto_or_type "modename" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h" 438258442Sjhbauto_or_type "mountflagsname" "MNT_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mount.h" 439258442Sjhbauto_switch_type "msyncflagsname" "MS_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h" 440258442Sjhbauto_or_type "nfssvcname" "NFSSVC_[A-Z0-9]+[[:space:]]+0x[0-9]+" "nfs/nfssvc.h" 441258442Sjhbauto_switch_type "prioname" "PRIO_[A-Z]+[[:space:]]+[0-9]" "sys/resource.h" 442260208Sjhbauto_switch_type "procctlcmdname" "PROC_[A-Z]+[[:space:]]+[0-9]" "sys/procctl.h" 443258442Sjhbauto_switch_type "ptraceopname" "PT_[[:alnum:]_]+[[:space:]]+[0-9]+" "sys/ptrace.h" 444258442Sjhbauto_switch_type "quotactlname" "Q_[A-Z]+[[:space:]]+0x[0-9]+" "ufs/ufs/quota.h" 445258442Sjhbauto_or_type "rebootoptname" "RB_[A-Z]+[[:space:]]+0x[0-9]+" "sys/reboot.h" 446258442Sjhbauto_or_type "rforkname" "RF[A-Z]+[[:space:]]+\([0-9]+<<[0-9]+\)" "sys/unistd.h" 447258442Sjhbauto_switch_type "rlimitname" "RLIMIT_[A-Z]+[[:space:]]+[0-9]+" "sys/resource.h" 448258442Sjhbauto_switch_type "schedpolicyname" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sched.h" 449258442Sjhbauto_switch_type "sendfileflagsname" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h" 450258442Sjhbauto_or_type "shmatname" "SHM_[A-Z]+[[:space:]]+[0-9]{6}+" "sys/shm.h" 451258442Sjhbauto_switch_type "shutdownhowname" "SHUT_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h" 452258442Sjhbauto_switch_type "sigprocmaskhowname" "SIG_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h" 453258442Sjhbauto_if_type "sockdomainname" "PF_[[:alnum:]]+[[:space:]]+" "sys/socket.h" 454258442Sjhbauto_if_type "sockfamilyname" "AF_[[:alnum:]]+[[:space:]]+" "sys/socket.h" 455258442Sjhbauto_if_type "sockipprotoname" "IPPROTO_[[:alnum:]]+[[:space:]]+" "netinet/in.h" 456258442Sjhbauto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h" 457258442Sjhbauto_switch_type "socktypename" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h" 458258442Sjhbauto_or_type "thrcreateflagsname" "THR_[A-Z]+[[:space:]]+0x[0-9]+" "sys/thr.h" 459258442Sjhbauto_switch_type "vmresultname" "KERN_[A-Z]+[[:space:]]+[0-9]+" "vm/vm_param.h" 460259829Sjhbauto_or_type "wait6optname" "W[A-Z]+[[:space:]]+[0-9]+" "sys/wait.h" 461258442Sjhbauto_switch_type "whencename" "SEEK_[A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h" 462158766Snetchild 463158766Snetchildcat <<_EOF_ 464158766Snetchild/* 465158766Snetchild * AUTO - Special 466158766Snetchild * F_ is used to specify fcntl commands as well as arguments. Both sets are 467158766Snetchild * grouped in fcntl.h, and this awk script grabs the first group. 468158766Snetchild */ 469158766Snetchildvoid 470258442Sjhbfcntlcmdname(int cmd, int arg, int decimal) 471158766Snetchild{ 472158766Snetchild switch (cmd) { 473158766Snetchild_EOF_ 474261952Sjillesegrep "^#[[:space:]]*define[[:space:]]+F_[A-Z0-9_]+[[:space:]]+[0-9]+[[:space:]]*" \ 475158766Snetchild $include_dir/sys/fcntl.h | \ 476158766Snetchild awk 'BEGIN { o=0 } { for (i = 1; i <= NF; i++) \ 477158766Snetchild if ($i ~ /define/) \ 478158766Snetchild break; \ 479158766Snetchild ++i; \ 480158766Snetchild if (o <= $(i+1)) \ 481258442Sjhb printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i; \ 482158766Snetchild else \ 483158766Snetchild exit; \ 484158766Snetchild o = $(i+1) }' 485158766Snetchildcat <<_EOF_ 486158766Snetchild default: /* Should not reach */ 487258442Sjhb printf("<invalid=%d>", cmd); 488158766Snetchild } 489258442Sjhb putchar(','); 490158766Snetchild if (cmd == F_GETFD || cmd == F_SETFD) { 491158766Snetchild if (arg == FD_CLOEXEC) 492258442Sjhb printf("FD_CLOEXEC"); 493158766Snetchild else if (arg == 0) 494258442Sjhb printf("0"); 495158766Snetchild else { 496158766Snetchild if (decimal) 497258442Sjhb printf("<invalid>%d", arg); 498158766Snetchild else 499258442Sjhb printf("<invalid>%#x", (unsigned int)arg); 500158766Snetchild } 501158766Snetchild } else if (cmd == F_SETFL) { 502158766Snetchild flagsname(arg); 503158766Snetchild } else { 504158766Snetchild if (decimal) 505258442Sjhb printf("%d", arg); 506158766Snetchild else 507258442Sjhb printf("%#x", (unsigned int)arg); 508158766Snetchild } 509158766Snetchild} 510158766Snetchild 511158766Snetchild/* 512158766Snetchild * AUTO - Special 513158766Snetchild * 514258870Sjhb * The MAP_ALIGNED flag requires special handling. 515258870Sjhb */ 516258870Sjhbvoid 517258870Sjhbmmapflagsname(int flags) 518258870Sjhb{ 519258870Sjhb int align; 520258870Sjhb int or = 0; 521258870Sjhb printf("%#x<", flags); 522258870Sjhb_EOF_ 523258870Sjhbegrep "^#[[:space:]]*define[[:space:]]+MAP_[A-Z_]+[[:space:]]+0x[0-9A-Fa-f]+[[:space:]]*" \ 524258870Sjhb $include_dir/sys/mman.h | grep -v MAP_ALIGNED | \ 525258870Sjhb awk '{ for (i = 1; i <= NF; i++) \ 526258870Sjhb if ($i ~ /define/) \ 527258870Sjhb break; \ 528258870Sjhb ++i; \ 529258870Sjhb printf "\tif (!((flags > 0) ^ ((%s) > 0)))\n\t\tif_print_or(flags, %s, or);\n", $i, $i }' 530258870Sjhbcat <<_EOF_ 531258870Sjhb align = flags & MAP_ALIGNMENT_MASK; 532258870Sjhb if (align != 0) { 533258870Sjhb if (align == MAP_ALIGNED_SUPER) 534258870Sjhb print_or("MAP_ALIGNED_SUPER", or); 535258870Sjhb else { 536258870Sjhb print_or("MAP_ALIGNED", or); 537258870Sjhb printf("(%d)", align >> MAP_ALIGNMENT_SHIFT); 538258870Sjhb } 539258870Sjhb } 540258870Sjhb printf(">"); 541258870Sjhb if (or == 0) 542258870Sjhb printf("<invalid>%d", flags); 543258870Sjhb} 544258870Sjhb 545258870Sjhb/* 546258870Sjhb * AUTO - Special 547258870Sjhb * 548158766Snetchild * The only reason this is not fully automated is due to the 549158766Snetchild * grep -v RTP_PRIO statement. A better egrep line should 550158766Snetchild * make this capable of being a auto_switch_type() function. 551158766Snetchild */ 552158766Snetchildvoid 553258442Sjhbrtprioname(int func) 554158766Snetchild{ 555158766Snetchild switch (func) { 556158766Snetchild_EOF_ 557158766Snetchildegrep "^#[[:space:]]*define[[:space:]]+RTP_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" \ 558158766Snetchild $include_dir/sys/rtprio.h | grep -v RTP_PRIO | \ 559158766Snetchild awk '{ for (i = 1; i <= NF; i++) \ 560158766Snetchild if ($i ~ /define/) \ 561158766Snetchild break; \ 562158766Snetchild ++i; \ 563258442Sjhb printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }' 564158766Snetchildcat <<_EOF_ 565158766Snetchild default: /* Should not reach */ 566258442Sjhb printf("<invalid=%d>", func); 567158766Snetchild } 568158766Snetchild} 569158766Snetchild 570158766Snetchild/* 571158766Snetchild * AUTO - Special 572158766Snetchild * 573158766Snetchild * The send and recv functions have a flags argument which can be 574158766Snetchild * set to 0. There is no corresponding #define. The auto_ functions 575158766Snetchild * detect this as "invalid", which is incorrect here. 576158766Snetchild */ 577158766Snetchildvoid 578258442Sjhbsendrecvflagsname(int flags) 579158766Snetchild{ 580258442Sjhb int or = 0; 581175936Sdes 582158766Snetchild if (flags == 0) { 583258442Sjhb printf("0"); 584158766Snetchild return; 585158766Snetchild } 586212727Srpaulo 587212728Srpaulo printf("%#x<", flags); 588158766Snetchild_EOF_ 589158766Snetchildegrep "^#[[:space:]]*define[[:space:]]+MSG_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" $include_dir/sys/socket.h | \ 590158766Snetchild awk '{ for (i = 1; i <= NF; i++) \ 591158766Snetchild if ($i ~ /define/) \ 592158766Snetchild break; \ 593158766Snetchild ++i; \ 594158766Snetchild printf "\tif(!((flags>0)^((%s)>0)))\n\t\tif_print_or(flags, %s, or);\n", $i, $i }' 595158766Snetchildcat <<_EOF_ 596212728Srpaulo printf(">"); 597158766Snetchild} 598158766Snetchild 599158766Snetchild_EOF_ 600