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 72226145Sdes$name(intmax_t arg) 73158766Snetchild{ 74226145Sdes int or = 0; 75226145Sdes 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; \ 83226145Sdes 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) 87226153Sdes 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 106226145Sdes$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; \ 116226153Sdes printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }' 117158766Snetchildcat <<_EOF_ 118158766Snetchild default: /* Should not reach */ 119226153Sdes 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 139226145Sdes$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 */ 150226153Sdes printf("<invalid=%jd>", arg); 151165756Srodrigc} 152165756Srodrigc 153165756Srodrigc_EOF_ 154165756Srodrigc} 155165756Srodrigc 156158766Snetchild# C start 157158766Snetchild 158158766Snetchildcat <<_EOF_ 159226145Sdes#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> 172255708Sjhb#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> 190226159Sdes#include <sys/capability.h> 191233925Sjhb#include <vm/vm.h> 192233925Sjhb#include <vm/vm_param.h> 193158766Snetchild 194158766Snetchild#include "kdump_subr.h" 195158766Snetchild 196158766Snetchild/* 197158766Snetchild * These are simple support macros. print_or utilizes a variable 198158766Snetchild * defined in the calling function to track whether or not it should 199158766Snetchild * print a logical-OR character ('|') before a string. if_print_or 200158766Snetchild * simply handles the necessary "if" statement used in many lines 201158766Snetchild * of this file. 202158766Snetchild */ 203158766Snetchild#define print_or(str,orflag) do { \\ 204158766Snetchild if (orflag) putchar('|'); else orflag = 1; \\ 205158766Snetchild printf (str); } \\ 206158766Snetchild while (0) 207158766Snetchild#define if_print_or(i,flag,orflag) do { \\ 208158766Snetchild if ((i & flag) == flag) \\ 209158766Snetchild print_or(#flag,orflag); } \\ 210158766Snetchild while (0) 211158766Snetchild 212158766Snetchild/* MANUAL */ 213254291Sjillesvoid 214254291Sjillesatfdname(int fd, int decimal) 215254291Sjilles{ 216254291Sjilles if (fd == AT_FDCWD) 217254291Sjilles printf("AT_FDCWD"); 218254291Sjilles else if (decimal) 219254291Sjilles printf("%d", fd); 220254291Sjilles else 221254291Sjilles printf("%#x", fd); 222254291Sjilles} 223254291Sjilles 224254291Sjilles/* MANUAL */ 225158766Snetchildextern char *signames[]; /* from kdump.c */ 226158766Snetchildvoid 227226145Sdessigname(int sig) 228158766Snetchild{ 229160295Skib if (sig > 0 && sig < NSIG) 230226153Sdes printf("SIG%s",signames[sig]); 231160295Skib else 232226153Sdes printf("SIG %d", sig); 233158766Snetchild} 234158766Snetchild 235158766Snetchild/* MANUAL */ 236158766Snetchildvoid 237226145Sdessemctlname(int cmd) 238158766Snetchild{ 239158766Snetchild switch (cmd) { 240158766Snetchild case GETNCNT: 241226153Sdes printf("GETNCNT"); 242158766Snetchild break; 243158766Snetchild case GETPID: 244226153Sdes printf("GETPID"); 245158766Snetchild break; 246158766Snetchild case GETVAL: 247226153Sdes printf("GETVAL"); 248158766Snetchild break; 249158766Snetchild case GETALL: 250226153Sdes printf("GETALL"); 251158766Snetchild break; 252158766Snetchild case GETZCNT: 253226153Sdes printf("GETZCNT"); 254158766Snetchild break; 255158766Snetchild case SETVAL: 256226153Sdes printf("SETVAL"); 257158766Snetchild break; 258158766Snetchild case SETALL: 259226153Sdes printf("SETALL"); 260158766Snetchild break; 261158766Snetchild case IPC_RMID: 262226153Sdes printf("IPC_RMID"); 263158766Snetchild break; 264158766Snetchild case IPC_SET: 265226153Sdes printf("IPC_SET"); 266158766Snetchild break; 267158766Snetchild case IPC_STAT: 268226153Sdes printf("IPC_STAT"); 269158766Snetchild break; 270158766Snetchild default: /* Should not reach */ 271226153Sdes printf("<invalid=%d>", cmd); 272158766Snetchild } 273158766Snetchild} 274158766Snetchild 275158766Snetchild/* MANUAL */ 276158766Snetchildvoid 277226145Sdesshmctlname(int cmd) 278226145Sdes{ 279158766Snetchild switch (cmd) { 280158766Snetchild case IPC_RMID: 281226153Sdes printf("IPC_RMID"); 282158766Snetchild break; 283158766Snetchild case IPC_SET: 284226153Sdes printf("IPC_SET"); 285158766Snetchild break; 286158766Snetchild case IPC_STAT: 287226153Sdes printf("IPC_STAT"); 288158766Snetchild break; 289158766Snetchild default: /* Should not reach */ 290226153Sdes printf("<invalid=%d>", cmd); 291158766Snetchild } 292158766Snetchild} 293158766Snetchild 294158766Snetchild/* MANUAL */ 295158766Snetchildvoid 296226145Sdessemgetname(int flag) 297226145Sdes{ 298226145Sdes int or = 0; 299216130Sdelphij if_print_or(flag, IPC_CREAT, or); 300216130Sdelphij if_print_or(flag, IPC_EXCL, or); 301158766Snetchild if_print_or(flag, SEM_R, or); 302158766Snetchild if_print_or(flag, SEM_A, or); 303158766Snetchild if_print_or(flag, (SEM_R>>3), or); 304158766Snetchild if_print_or(flag, (SEM_A>>3), or); 305158766Snetchild if_print_or(flag, (SEM_R>>6), or); 306158766Snetchild if_print_or(flag, (SEM_A>>6), or); 307158766Snetchild} 308158766Snetchild 309158766Snetchild/* 310158766Snetchild * MANUAL 311158766Snetchild * 312158766Snetchild * Only used by SYS_open. Unless O_CREAT is set in flags, the 313158766Snetchild * mode argument is unused (and often bogus and misleading). 314158766Snetchild */ 315158766Snetchildvoid 316226145Sdesflagsandmodename(int flags, int mode, int decimal) 317226145Sdes{ 318226145Sdes flagsname(flags); 319226153Sdes putchar(','); 320158766Snetchild if ((flags & O_CREAT) == O_CREAT) { 321158766Snetchild modename (mode); 322158766Snetchild } else { 323158766Snetchild if (decimal) { 324226153Sdes printf("<unused>%d", mode); 325158766Snetchild } else { 326226153Sdes printf("<unused>%#x", (unsigned int)mode); 327158766Snetchild } 328158766Snetchild } 329158766Snetchild} 330158766Snetchild 331255493Sjhb/* MANUAL */ 332255493Sjhbvoid 333255493Sjhbidtypename(idtype_t idtype, int decimal) 334255493Sjhb{ 335255493Sjhb switch(idtype) { 336255493Sjhb case P_PID: 337255493Sjhb printf("P_PID"); 338255493Sjhb break; 339255493Sjhb case P_PPID: 340255493Sjhb printf("P_PPID"); 341255493Sjhb break; 342255493Sjhb case P_PGID: 343255493Sjhb printf("P_PGID"); 344255493Sjhb break; 345255493Sjhb case P_SID: 346255493Sjhb printf("P_SID"); 347255493Sjhb break; 348255493Sjhb case P_CID: 349255493Sjhb printf("P_CID"); 350255493Sjhb break; 351255493Sjhb case P_UID: 352255493Sjhb printf("P_UID"); 353255493Sjhb break; 354255493Sjhb case P_GID: 355255493Sjhb printf("P_GID"); 356255493Sjhb break; 357255493Sjhb case P_ALL: 358255493Sjhb printf("P_ALL"); 359255493Sjhb break; 360255493Sjhb case P_LWPID: 361255493Sjhb printf("P_LWPID"); 362255493Sjhb break; 363255493Sjhb case P_TASKID: 364255493Sjhb printf("P_TASKID"); 365255493Sjhb break; 366255493Sjhb case P_PROJID: 367255493Sjhb printf("P_PROJID"); 368255493Sjhb break; 369255493Sjhb case P_POOLID: 370255493Sjhb printf("P_POOLID"); 371255493Sjhb break; 372255493Sjhb case P_JAILID: 373255493Sjhb printf("P_JAILID"); 374255493Sjhb break; 375255493Sjhb case P_CTID: 376255493Sjhb printf("P_CTID"); 377255493Sjhb break; 378255493Sjhb case P_CPUID: 379255493Sjhb printf("P_CPUID"); 380255493Sjhb break; 381255493Sjhb case P_PSETID: 382255493Sjhb printf("P_PSETID"); 383255493Sjhb break; 384255493Sjhb default: 385255493Sjhb if (decimal) { 386255493Sjhb printf("%d", idtype); 387255493Sjhb } else { 388255493Sjhb printf("%#x", idtype); 389255493Sjhb } 390255493Sjhb } 391255493Sjhb} 392255493Sjhb 393158766Snetchild/* 394158766Snetchild * MANUAL 395158766Snetchild * 396158766Snetchild * [g|s]etsockopt's level argument can either be SOL_SOCKET or a value 397158766Snetchild * referring to a line in /etc/protocols . It might be appropriate 398158766Snetchild * to use getprotoent(3) here. 399158766Snetchild */ 400158766Snetchildvoid 401226145Sdessockoptlevelname(int level, int decimal) 402158766Snetchild{ 403158766Snetchild if (level == SOL_SOCKET) { 404226153Sdes printf("SOL_SOCKET"); 405158766Snetchild } else { 406158766Snetchild if (decimal) { 407226153Sdes printf("%d", level); 408158766Snetchild } else { 409226153Sdes printf("%#x", (unsigned int)level); 410158766Snetchild } 411158766Snetchild } 412158766Snetchild} 413158766Snetchild 414233925Sjhb/* 415233925Sjhb * MANUAL 416233925Sjhb * 417233925Sjhb * Used for page fault type. Cannot use auto_or_type since the macro 418233925Sjhb * values contain a cast. Also, VM_PROT_NONE has to be handled specially. 419233925Sjhb */ 420233925Sjhbvoid 421233925Sjhbvmprotname (int type) 422233925Sjhb{ 423233925Sjhb int or = 0; 424233925Sjhb 425233925Sjhb if (type == VM_PROT_NONE) { 426233925Sjhb (void)printf("VM_PROT_NONE"); 427233925Sjhb return; 428233925Sjhb } 429233925Sjhb if_print_or(type, VM_PROT_READ, or); 430233925Sjhb if_print_or(type, VM_PROT_WRITE, or); 431233925Sjhb if_print_or(type, VM_PROT_EXECUTE, or); 432233925Sjhb if_print_or(type, VM_PROT_COPY, or); 433233925Sjhb} 434254922Sjilles 435254922Sjilles/* 436254922Sjilles * MANUAL 437254922Sjilles */ 438254922Sjillesvoid 439254922Sjillessocktypenamewithflags(int type) 440254922Sjilles{ 441254922Sjilles if (type & SOCK_CLOEXEC) 442254922Sjilles printf("SOCK_CLOEXEC|"), type &= ~SOCK_CLOEXEC; 443254922Sjilles if (type & SOCK_NONBLOCK) 444254922Sjilles printf("SOCK_NONBLOCK|"), type &= ~SOCK_NONBLOCK; 445254922Sjilles socktypename(type); 446254922Sjilles} 447158766Snetchild_EOF_ 448158766Snetchild 449226147Sdesauto_or_type "accessmodename" "[A-Z]_OK[[:space:]]+0?x?[0-9A-Fa-f]+" "sys/unistd.h" 450226147Sdesauto_switch_type "acltypename" "ACL_TYPE_[A-Z4_]+[[:space:]]+0x[0-9]+" "sys/acl.h" 451247602Spjdauto_or_type "capfcntlname" "CAP_FCNTL_[A-Z]+[[:space:]]+\(1" "sys/capability.h" 452226147Sdesauto_switch_type "extattrctlname" "EXTATTR_NAMESPACE_[A-Z]+[[:space:]]+0x[0-9]+" "sys/extattr.h" 453232072Sjhbauto_switch_type "fadvisebehavname" "POSIX_FADV_[A-Z]+[[:space:]]+[0-9]+" "sys/fcntl.h" 454226147Sdesauto_or_type "flagsname" "O_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h" 455226147Sdesauto_or_type "flockname" "LOCK_[A-Z]+[[:space:]]+0x[0-9]+" "sys/fcntl.h" 456226147Sdesauto_or_type "getfsstatflagsname" "MNT_[A-Z]+[[:space:]]+[1-9][0-9]*" "sys/mount.h" 457226147Sdesauto_switch_type "kldsymcmdname" "KLDSYM_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h" 458226147Sdesauto_switch_type "kldunloadfflagsname" "LINKER_UNLOAD_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h" 459226147Sdesauto_switch_type "lio_listioname" "LIO_(NO)?WAIT[[:space:]]+[0-9]+" "aio.h" 460226147Sdesauto_switch_type "madvisebehavname" "_?MADV_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h" 461226147Sdesauto_switch_type "minheritname" "INHERIT_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h" 462226147Sdesauto_or_type "mlockallname" "MCL_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h" 463226147Sdesauto_or_type "mmapprotname" "PROT_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h" 464226147Sdesauto_or_type "modename" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h" 465226147Sdesauto_or_type "mountflagsname" "MNT_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mount.h" 466226147Sdesauto_switch_type "msyncflagsname" "MS_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h" 467246711Spluknetauto_or_type "nfssvcname" "NFSSVC_[A-Z0-9]+[[:space:]]+0x[0-9]+" "nfs/nfssvc.h" 468226147Sdesauto_switch_type "prioname" "PRIO_[A-Z]+[[:space:]]+[0-9]" "sys/resource.h" 469255708Sjhbauto_switch_type "procctlcmdname" "PROC_[A-Z]+[[:space:]]+[0-9]" "sys/procctl.h" 470226147Sdesauto_switch_type "ptraceopname" "PT_[[:alnum:]_]+[[:space:]]+[0-9]+" "sys/ptrace.h" 471226147Sdesauto_switch_type "quotactlname" "Q_[A-Z]+[[:space:]]+0x[0-9]+" "ufs/ufs/quota.h" 472226147Sdesauto_or_type "rebootoptname" "RB_[A-Z]+[[:space:]]+0x[0-9]+" "sys/reboot.h" 473226147Sdesauto_or_type "rforkname" "RF[A-Z]+[[:space:]]+\([0-9]+<<[0-9]+\)" "sys/unistd.h" 474226147Sdesauto_switch_type "rlimitname" "RLIMIT_[A-Z]+[[:space:]]+[0-9]+" "sys/resource.h" 475226147Sdesauto_switch_type "schedpolicyname" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sched.h" 476226147Sdesauto_switch_type "sendfileflagsname" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h" 477226147Sdesauto_or_type "shmatname" "SHM_[A-Z]+[[:space:]]+[0-9]{6}+" "sys/shm.h" 478226147Sdesauto_switch_type "shutdownhowname" "SHUT_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h" 479240820Sjillesauto_switch_type "sigbuscodename" "BUS_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h" 480240820Sjillesauto_switch_type "sigchldcodename" "CLD_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h" 481240820Sjillesauto_switch_type "sigfpecodename" "FPE_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h" 482226147Sdesauto_switch_type "sigprocmaskhowname" "SIG_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h" 483240820Sjillesauto_switch_type "sigillcodename" "ILL_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h" 484240820Sjillesauto_switch_type "sigsegvcodename" "SEGV_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h" 485240820Sjillesauto_switch_type "sigtrapcodename" "TRAP_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h" 486226147Sdesauto_if_type "sockdomainname" "PF_[[:alnum:]]+[[:space:]]+" "sys/socket.h" 487226147Sdesauto_if_type "sockfamilyname" "AF_[[:alnum:]]+[[:space:]]+" "sys/socket.h" 488226147Sdesauto_if_type "sockipprotoname" "IPPROTO_[[:alnum:]]+[[:space:]]+" "netinet/in.h" 489226147Sdesauto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h" 490226147Sdesauto_switch_type "socktypename" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h" 491226147Sdesauto_or_type "thrcreateflagsname" "THR_[A-Z]+[[:space:]]+0x[0-9]+" "sys/thr.h" 492233925Sjhbauto_switch_type "vmresultname" "KERN_[A-Z]+[[:space:]]+[0-9]+" "vm/vm_param.h" 493255493Sjhbauto_or_type "wait6optname" "W[A-Z]+[[:space:]]+[0-9]+" "sys/wait.h" 494226147Sdesauto_switch_type "whencename" "SEEK_[A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h" 495158766Snetchild 496158766Snetchildcat <<_EOF_ 497158766Snetchild/* 498158766Snetchild * AUTO - Special 499158766Snetchild * F_ is used to specify fcntl commands as well as arguments. Both sets are 500158766Snetchild * grouped in fcntl.h, and this awk script grabs the first group. 501158766Snetchild */ 502158766Snetchildvoid 503226145Sdesfcntlcmdname(int cmd, int arg, int decimal) 504158766Snetchild{ 505158766Snetchild switch (cmd) { 506158766Snetchild_EOF_ 507242482Sjillesegrep "^#[[:space:]]*define[[:space:]]+F_[A-Z0-9_]+[[:space:]]+[0-9]+[[:space:]]*" \ 508158766Snetchild $include_dir/sys/fcntl.h | \ 509158766Snetchild awk 'BEGIN { o=0 } { for (i = 1; i <= NF; i++) \ 510158766Snetchild if ($i ~ /define/) \ 511158766Snetchild break; \ 512158766Snetchild ++i; \ 513158766Snetchild if (o <= $(i+1)) \ 514226153Sdes printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i; \ 515158766Snetchild else \ 516158766Snetchild exit; \ 517158766Snetchild o = $(i+1) }' 518158766Snetchildcat <<_EOF_ 519158766Snetchild default: /* Should not reach */ 520226153Sdes printf("<invalid=%d>", cmd); 521158766Snetchild } 522226153Sdes putchar(','); 523158766Snetchild if (cmd == F_GETFD || cmd == F_SETFD) { 524158766Snetchild if (arg == FD_CLOEXEC) 525226153Sdes printf("FD_CLOEXEC"); 526158766Snetchild else if (arg == 0) 527226153Sdes printf("0"); 528158766Snetchild else { 529158766Snetchild if (decimal) 530226153Sdes printf("<invalid>%d", arg); 531158766Snetchild else 532226153Sdes printf("<invalid>%#x", (unsigned int)arg); 533158766Snetchild } 534158766Snetchild } else if (cmd == F_SETFL) { 535158766Snetchild flagsname(arg); 536158766Snetchild } else { 537158766Snetchild if (decimal) 538226153Sdes printf("%d", arg); 539158766Snetchild else 540226153Sdes printf("%#x", (unsigned int)arg); 541158766Snetchild } 542158766Snetchild} 543158766Snetchild 544158766Snetchild/* 545158766Snetchild * AUTO - Special 546158766Snetchild * 547254430Sjhb * The MAP_ALIGNED flag requires special handling. 548254430Sjhb */ 549254430Sjhbvoid 550254430Sjhbmmapflagsname(int flags) 551254430Sjhb{ 552254430Sjhb int align; 553254430Sjhb int or = 0; 554254430Sjhb printf("%#x<", flags); 555254430Sjhb_EOF_ 556254430Sjhbegrep "^#[[:space:]]*define[[:space:]]+MAP_[A-Z_]+[[:space:]]+0x[0-9A-Fa-f]+[[:space:]]*" \ 557254430Sjhb $include_dir/sys/mman.h | grep -v MAP_ALIGNED | \ 558254430Sjhb awk '{ for (i = 1; i <= NF; i++) \ 559254430Sjhb if ($i ~ /define/) \ 560254430Sjhb break; \ 561254430Sjhb ++i; \ 562254430Sjhb printf "\tif (!((flags > 0) ^ ((%s) > 0)))\n\t\tif_print_or(flags, %s, or);\n", $i, $i }' 563254430Sjhbcat <<_EOF_ 564255426Sjhb#ifdef MAP_32BIT 565255426Sjhb if (!((flags > 0) ^ ((MAP_32BIT) > 0))) 566255426Sjhb if_print_or(flags, MAP_32BIT, or); 567255426Sjhb#endif 568254430Sjhb align = flags & MAP_ALIGNMENT_MASK; 569254430Sjhb if (align != 0) { 570254430Sjhb if (align == MAP_ALIGNED_SUPER) 571254430Sjhb print_or("MAP_ALIGNED_SUPER", or); 572254430Sjhb else { 573254430Sjhb print_or("MAP_ALIGNED", or); 574254430Sjhb printf("(%d)", align >> MAP_ALIGNMENT_SHIFT); 575254430Sjhb } 576254430Sjhb } 577254430Sjhb printf(">"); 578254430Sjhb if (or == 0) 579254430Sjhb printf("<invalid>%d", flags); 580254430Sjhb} 581254430Sjhb 582254430Sjhb/* 583254430Sjhb * AUTO - Special 584254430Sjhb * 585158766Snetchild * The only reason this is not fully automated is due to the 586158766Snetchild * grep -v RTP_PRIO statement. A better egrep line should 587158766Snetchild * make this capable of being a auto_switch_type() function. 588158766Snetchild */ 589158766Snetchildvoid 590226145Sdesrtprioname(int func) 591158766Snetchild{ 592158766Snetchild switch (func) { 593158766Snetchild_EOF_ 594158766Snetchildegrep "^#[[:space:]]*define[[:space:]]+RTP_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" \ 595158766Snetchild $include_dir/sys/rtprio.h | grep -v RTP_PRIO | \ 596158766Snetchild awk '{ for (i = 1; i <= NF; i++) \ 597158766Snetchild if ($i ~ /define/) \ 598158766Snetchild break; \ 599158766Snetchild ++i; \ 600226153Sdes printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }' 601158766Snetchildcat <<_EOF_ 602158766Snetchild default: /* Should not reach */ 603226153Sdes printf("<invalid=%d>", func); 604158766Snetchild } 605158766Snetchild} 606158766Snetchild 607158766Snetchild/* 608158766Snetchild * AUTO - Special 609158766Snetchild * 610158766Snetchild * The send and recv functions have a flags argument which can be 611158766Snetchild * set to 0. There is no corresponding #define. The auto_ functions 612158766Snetchild * detect this as "invalid", which is incorrect here. 613158766Snetchild */ 614158766Snetchildvoid 615226145Sdessendrecvflagsname(int flags) 616158766Snetchild{ 617226145Sdes int or = 0; 618175936Sdes 619158766Snetchild if (flags == 0) { 620226153Sdes printf("0"); 621158766Snetchild return; 622158766Snetchild } 623212727Srpaulo 624212728Srpaulo printf("%#x<", flags); 625158766Snetchild_EOF_ 626158766Snetchildegrep "^#[[:space:]]*define[[:space:]]+MSG_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" $include_dir/sys/socket.h | \ 627158766Snetchild awk '{ for (i = 1; i <= NF; i++) \ 628158766Snetchild if ($i ~ /define/) \ 629158766Snetchild break; \ 630158766Snetchild ++i; \ 631158766Snetchild printf "\tif(!((flags>0)^((%s)>0)))\n\t\tif_print_or(flags, %s, or);\n", $i, $i }' 632158766Snetchildcat <<_EOF_ 633212728Srpaulo printf(">"); 634158766Snetchild} 635158766Snetchild 636240820Sjilles/* 637240820Sjilles * AUTO - Special 638240820Sjilles * 639240820Sjilles * Check general codes first, then defer to signal-specific codes. 640240820Sjilles */ 641240820Sjillesvoid 642240820Sjillessigcodename(int sig, int code) 643240820Sjilles{ 644240820Sjilles switch (code) { 645158766Snetchild_EOF_ 646240820Sjillesegrep "^#[[:space:]]*define[[:space:]]+SI_[A-Z]+[[:space:]]+0(x[0-9abcdef]+)?[[:space:]]*" \ 647240820Sjilles $include_dir/sys/signal.h | grep -v SI_UNDEFINED | \ 648240820Sjilles awk '{ for (i = 1; i <= NF; i++) \ 649240820Sjilles if ($i ~ /define/) \ 650240820Sjilles break; \ 651240820Sjilles ++i; \ 652240820Sjilles printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }' 653240820Sjillescat <<_EOF_ 654240820Sjilles default: 655240820Sjilles switch (sig) { 656240820Sjilles case SIGILL: 657240820Sjilles sigillcodename(code); 658240820Sjilles break; 659240820Sjilles case SIGBUS: 660240820Sjilles sigbuscodename(code); 661240820Sjilles break; 662240820Sjilles case SIGSEGV: 663240820Sjilles sigsegvcodename(code); 664240820Sjilles break; 665240820Sjilles case SIGFPE: 666240820Sjilles sigfpecodename(code); 667240820Sjilles break; 668240820Sjilles case SIGTRAP: 669240820Sjilles sigtrapcodename(code); 670240820Sjilles break; 671240820Sjilles case SIGCHLD: 672240820Sjilles sigchldcodename(code); 673240820Sjilles break; 674240820Sjilles default: 675240820Sjilles printf("<invalid=%#x>", code); 676240820Sjilles } 677240820Sjilles } 678240820Sjilles} 679255219Spjd 680255219Spjd_EOF_ 681255219Spjdegrep '#define[[:space:]]+CAP_[A-Z_]+[[:space:]]+CAPRIGHT\([0-9],[[:space:]]+0x[0-9]{16}ULL\)' \ 682255219Spjd $include_dir/sys/capability.h | \ 683255219Spjd sed -E 's/[ ]+/ /g' | \ 684255219Spjd awk -F '[ \(,\)]' ' 685255219Spjd BEGIN { 686255219Spjd printf "void\n" 687255219Spjd printf "capname(const cap_rights_t *rightsp)\n" 688255219Spjd printf "{\n" 689255219Spjd printf "\tint comma = 0;\n\n" 690255219Spjd printf "\tprintf(\"<\");\n" 691255219Spjd } 692255219Spjd { 693255219Spjd printf "\tif ((rightsp->cr_rights[%s] & %s) == %s) {\n", $4, $2, $2 694255219Spjd printf "\t\tif (comma) printf(\",\"); else comma = 1;\n" 695255219Spjd printf "\t\tprintf(\"%s\");\n", $2 696255219Spjd printf "\t}\n" 697255219Spjd } 698255219Spjd END { 699255219Spjd printf "\tprintf(\">\");\n" 700255219Spjd printf "}\n" 701255219Spjd }' 702