11.1Scgd#!/bin/sh - 21.28Schristos# $NetBSD: makelintstub,v 1.28 2024/01/20 14:52:49 christos Exp $ 31.1Scgd# 41.7Scgd# Copyright (c) 1996, 1997 Christopher G. Demetriou 51.7Scgd# All rights reserved. 61.7Scgd# 71.1Scgd# Redistribution and use in source and binary forms, with or without 81.1Scgd# modification, are permitted provided that the following conditions 91.1Scgd# are met: 101.1Scgd# 1. Redistributions of source code must retain the above copyright 111.1Scgd# notice, this list of conditions and the following disclaimer. 121.1Scgd# 2. Redistributions in binary form must reproduce the above copyright 131.1Scgd# notice, this list of conditions and the following disclaimer in the 141.1Scgd# documentation and/or other materials provided with the distribution. 151.1Scgd# 3. All advertising materials mentioning features or use of this software 161.1Scgd# must display the following acknowledgement: 171.7Scgd# This product includes software developed for the 181.14Ssalo# NetBSD Project. See http://www.NetBSD.org/ for 191.7Scgd# information about NetBSD. 201.1Scgd# 4. The name of the author may not be used to endorse or promote products 211.7Scgd# derived from this software without specific prior written permission. 221.7Scgd# 231.1Scgd# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 241.1Scgd# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 251.1Scgd# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 261.1Scgd# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 271.1Scgd# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 281.1Scgd# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 291.1Scgd# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 301.1Scgd# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 311.1Scgd# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 321.1Scgd# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 331.7Scgd# 341.7Scgd# <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> 351.1Scgd 361.2Sthorpejusage() 371.2Sthorpej{ 381.2Sthorpej 391.17Schristoscat << _EOF 1>&2 401.23SlukemUsage: $PROG [-n|-p] [-o filename] [-s syscall.h] object ... 411.22Slukem -n Create SYSCALL_NOERROR. 421.22Slukem -p Create PSEUDO_NOERROR. 431.22Slukem (also removes leading "_" on syscall name). 441.22Slukem -o filename Output to filename. 451.22Slukem -s syscall.h Header to #include instead of <sys/syscall.h>. 461.22Slukem 471.17Schristos The CPP environment variable must be set 481.17Schristos to the path to the C preprocessor. 491.17Schristos_EOF 501.1Scgd exit 1 511.2Sthorpej} 521.1Scgd 531.2Sthorpejheader() 541.2Sthorpej{ 551.1Scgd 561.2Sthorpej cat <<- __EOF__ 571.2Sthorpej /* 581.2Sthorpej * THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT. 591.26Schristos * It is generated by $PROG 601.2Sthorpej */ 611.2Sthorpej 621.2Sthorpej #include <sys/param.h> 631.27Schristos #include <sys/acl.h> 641.19Srmind #include <sys/aio.h> 651.2Sthorpej #include <sys/time.h> 661.2Sthorpej #include <sys/mount.h> 671.2Sthorpej #include <sys/stat.h> 681.3Sfvdl #include <ufs/ufs/dinode.h> 691.2Sthorpej #include <ufs/lfs/lfs.h> 701.2Sthorpej #include <sys/resource.h> 711.2Sthorpej #include <sys/poll.h> 721.2Sthorpej #include <sys/uio.h> 731.2Sthorpej #include <sys/ipc.h> 741.26Schristos #include <sys/idtype.h> 751.20She #include <sys/lwpctl.h> 761.19Srmind #include <sys/mqueue.h> 771.2Sthorpej #include <sys/msg.h> 781.2Sthorpej #include <sys/sem.h> 791.2Sthorpej #include <sys/shm.h> 801.25Smartin #include <sys/spawn.h> 811.21Srmind #include <sys/sched.h> 821.2Sthorpej #include <sys/timex.h> 831.2Sthorpej #include <sys/socket.h> 841.10Sjdolecek #include <sys/event.h> 851.16Stsarna #include <sys/uuid.h> 861.24Sdholland #include <sys/quotactl.h> 871.2Sthorpej #include <stdarg.h> 881.28Schristos #include <unistd.h> 891.28Schristos #include <stdlib.h> 901.28Schristos #include <spawn.h> 911.28Schristos #include <fcntl.h> 921.28Schristos 931.28Schristos #include "extern.h" 941.2Sthorpej 951.2Sthorpej __EOF__ 961.2Sthorpej} 971.2Sthorpej 981.2Sthorpejsyscall_stub() 991.2Sthorpej{ 1001.2Sthorpej 1011.4Smycroft syscalldump="$1" 1021.2Sthorpej syscallname="$2" 1031.2Sthorpej funcname="$3" 1041.2Sthorpej 1051.17Schristos arglist="$( 1061.4Smycroft sed -e 'ta 1071.4Smycroft :a 1081.9Sthorpej s,^/\* syscall: \"'"$syscallname"'\" ,, 1091.4Smycroft tb 1101.4Smycroft d 1111.4Smycroft :b 1121.4Smycroft s, \*/$,,' $syscalldump 1131.17Schristos )" 1141.2Sthorpej 1151.2Sthorpej eval set -f -- "$arglist" 1161.2Sthorpej 1171.4Smycroft if [ $# -lt 3 ]; then 1181.2Sthorpej echo syscall $syscallname not found! 1>&2 1191.2Sthorpej exit 1 1201.2Sthorpej fi 1211.1Scgd 1221.4Smycroft shift # kill "ret:" 1231.4Smycroft returntype=$1; shift 1241.4Smycroft shift # kill "args:" 1251.2Sthorpej 1261.2Sthorpej cat <<- __EOF__ 1271.2Sthorpej /*ARGSUSED*/ 1281.2Sthorpej $returntype 1291.2Sthorpej __EOF__ 1301.2Sthorpej 1311.2Sthorpej # do ANSI C function header 1321.5Smycroft echo "#ifdef __STDC__" 1331.2Sthorpej 1341.9Sthorpej echo "$funcname(" 1351.17Schristos first=true; i=1 1361.5Smycroft for arg; do 1371.17Schristos if $first; then 1381.17Schristos first=false 1391.5Smycroft else 1401.9Sthorpej echo ", " 1411.2Sthorpej fi 1421.5Smycroft case "$arg" in 1431.9Sthorpej "...") echo "...";; 1441.9Sthorpej *) echo "$arg arg$i"; i=$(($i + 1));; 1451.5Smycroft esac 1461.5Smycroft done 1471.17Schristos if $first; then 1481.9Sthorpej echo "void" 1491.9Sthorpej fi 1501.5Smycroft echo ")" 1511.1Scgd 1521.5Smycroft # do K&R C function header 1531.5Smycroft echo "#else" 1541.1Scgd 1551.9Sthorpej echo "$funcname(" 1561.17Schristos first=true; i=1 1571.5Smycroft for arg; do 1581.17Schristos if $first; then 1591.17Schristos first=false 1601.5Smycroft else 1611.9Sthorpej echo ", " 1621.2Sthorpej fi 1631.5Smycroft case "$arg" in 1641.9Sthorpej "...") echo "va_alist";; 1651.9Sthorpej *) echo "arg$i"; i=$(($i + 1));; 1661.5Smycroft esac 1671.2Sthorpej done 1681.2Sthorpej echo ")" 1691.2Sthorpej i=1 1701.5Smycroft for arg; do 1711.5Smycroft case "$arg" in 1721.5Smycroft "...") echo " va_dcl";; 1731.5Smycroft *) echo " $arg arg$i;"; i=$(($i + 1));; 1741.5Smycroft esac 1751.2Sthorpej done 1761.1Scgd 1771.2Sthorpej # do function body 1781.5Smycroft echo "#endif" 1791.5Smycroft 1801.2Sthorpej echo "{" 1811.2Sthorpej if [ "$returntype" != "void" ]; then 1821.2Sthorpej echo " return (($returntype)0);" 1831.2Sthorpej fi 1841.2Sthorpej echo "}" 1851.2Sthorpej} 1861.2Sthorpej 1871.2Sthorpejtrailer() 1881.2Sthorpej{ 1891.2Sthorpej 1901.2Sthorpej cat <<- __EOF__ 1911.2Sthorpej /* END */ 1921.2Sthorpej __EOF__ 1931.2Sthorpej} 1941.2Sthorpej 1951.2Sthorpej 1961.17Schristospflag=false 1971.17Schristosnflag=false 1981.2Sthorpejoarg="" 1991.2Sthorpejsyscallhdr=/usr/include/sys/syscall.h 2001.4Smycroftsyscalldump=/tmp/makelintstub.$$ 2011.17SchristosPROG="$(basename "$0")" 2021.2Sthorpej 2031.17Schristosif [ -z "${CPP}" ]; then 2041.9Sthorpej usage 2051.9Sthorpejfi 2061.9Sthorpej 2071.23Slukemwhile getopts no:ps: i 2081.17Schristosdo 2091.2Sthorpej case "$i" in 2101.17Schristos n) nflag=true;; 2111.17Schristos o) oarg=$OPTARG;; 2121.17Schristos p) pflag=true;; 2131.17Schristos s) syscallhdr=$OPTARG;; 2141.17Schristos *) usage;; 2151.2Sthorpej esac 2161.1Scgddone 2171.1Scgd 2181.17Schristosshift $(expr $OPTIND - 1) 2191.17Schristos 2201.17Schristosif $pflag && $nflag 2211.17Schristosthen 2221.17Schristos echo "$PROG: -n flag and -p flag may not be used together" 1>&2 2231.2Sthorpej usage 2241.2Sthorpejfi 2251.2Sthorpej 2261.17Schristosif [ -n "$oarg" ]; then 2271.2Sthorpej exec > $oarg 2281.2Sthorpejfi 2291.2Sthorpej 2301.17Schristostrap "rm -f $syscalldump" 0 1 2 3 15 2311.4Smycroft 2321.2Sthorpejheader 2331.17Schristos 2341.17Schristosecho "#include \"$syscallhdr\"" | ${CPP} -D_LIBC -C > $syscalldump 2351.17Schristos 2361.2Sthorpejfor syscall; do 2371.8Stv fnname=${syscall%.S} 2381.17Schristos if $pflag; then 2391.4Smycroft scname=${fnname#_} 2401.2Sthorpej else 2411.2Sthorpej scname=$fnname 2421.1Scgd fi 2431.4Smycroft syscall_stub $syscalldump $scname $fnname 2441.2Sthorpej echo "" 2451.1Scgddone 2461.17Schristos 2471.2Sthorpejtrailer 2481.1Scgd 2491.1Scgdexit 0 250