########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1989-2011 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# Glenn Fowler <gsf@research.att.com> #
# David Korn <dgk@research.att.com> #
# Eduardo Krell <ekrell@adexus.cl> #
# #
########################################################################
#
# this is the worst iffe script, we promise
#
# @(#)syscall.sh (AT&T Research) 2011-12-06
#
eval $1
shift
case $1 in
esac
input=$1
comma=","
nl="
"
tmpsuf="i z m d r f u s n b g t e"
done
sys=
fun=
stdc=
sym=
vers=
weak=
*n*) integer inx ;;
esac
inx=0
A_OUTPUT=1
A_INPUT=2
A_ACCESS=3
A_MODE=4
A_NUMBER=5
A_OPEN=6
A_SIZE=8
A_STRING=9
A_VECTOR=A
echo "
#pragma prototyped"
echo "
#if defined(header)
#include \"${tmp}s.h\"
#endif
extern
#if defined(__cplusplus)
\"C\"
#endif
int syscall();
static int ((*i)())=syscall;
main() { return(i==0); }" > $tmp.c
do echo "
#include <$f>
then SYS_HEADER=$f
echo "
#include <$f>
" >> $tmp.f
#ifdef SYS_exit
int i;
#else
(
then l=fun
case $s in
_*) SYS_PREFIX=_ ;;
esac
fi
fi
break
fi
done
while :
#include <dlfcn.h>
#ifdef RTLD_LAZY
main()
{
return(0);
}
#else
(
} &&
echo "#define _dynamic_syscall 1" >> $tmp.m
lib=
do for s in "*.*" "*.[!a]*"
do for i in $d/$b.$s
do if test -f $i
then lib=$i
fi
done
?*) break 3 ;;
esac
done
done
done
*.[0-9]*.[0-9]*)
if test -f $i
then lib=$i
fi
;;
esac
case $lib in
/usr*) ;;
*) if test -f /usr$lib
then lib=/usr$lib
fi
;;
esac
case $lib in
esac
#include <dlfcn.h>
#ifdef RTLD_NEXT
main()
{
return 0;
}
#else
(
#endif' > ${tmp}h.c
} &&
then weak=1
fi
break
fi
then case $SYS_HEADER in
?*) echo "
#include <$f>
;;
esac
inc="#if defined(__STDPP__directive) && defined(__STDPP__hide)
__STDPP__directive pragma pp:hide syscall
#else
#define syscall ______syscall
#endif
#include <$SYS_HEADER>
#if defined(__STDPP__directive) && defined(__STDPP__hide)
__STDPP__directive pragma pp:nohide syscall
#else
#undef syscall
#endif"
{
case $SYS_HEADER in
*) echo "#define SYS_exit 1" ;;
esac
echo "main() { syscall(SYS_exit, 0); exit(1); }"
then case $SYS_HEADER in
esac
fi
break
fi
fi
if LD_PRELOAD=/dev/null ${_ld_preload_test-cat} </dev/null >/dev/null
then echo "
static int _lib_mangle_lib_;" >> $tmp.m
fi
break
done
echo iffe: test: type=$sys header=$SYS_HEADER ${SYS_CALL:+call=$SYS_CALL} ${SYS_PREFIX:+prefix=$SYS_PREFIX} >&$stderr
echo "#if SYSTRACE3D
/* output */
#define A_OUTPUT 0x$A_OUTPUT
/* input only */
#define A_INPUT 0x$A_INPUT
#define A_ACCESS 0x$A_ACCESS
#define A_MODE 0x$A_MODE
#define A_NUMBER 0x$A_NUMBER
#define A_OPEN 0x$A_OPEN
#define A_POINTER 0x$A_POINTER
#define A_SIZE 0x$A_SIZE
#define A_STRING 0x$A_STRING
#define A_VECTOR 0x$A_VECTOR
typedef struct
{
Sysfunc_t func;
short index;
short nov;
unsigned short call;
unsigned short args;
const char* name;
unsigned char type[8];
unsigned long count;
unsigned long megs;
unsigned long units;
Sysfunc_t last;
unsigned short active;
} Systrace_t;
" > $tmp.b
echo "static Systrace_t sys_trace[] =
{
" > $tmp.t
*) SYSCALL3D=1 ;;
esac
do case $i in
*e*) v=${i#-D}
v=${v%%=*}
;;
;;
esac
eval $v=1
;;
esac
done
exec <$input
ifi=0
'}
while :
do IFS=" "
read line || break
set $line
case $1 in
\#*) continue ;;
"") break ;;
"if") shift
eval $*
case $? in
esac
continue
;;
break
;;
esac
1*) shift
eval $*
case $? in
0) ;;
*) continue ;;
esac
i=0
;;
*) i=2
;;
esac
set $ifi
shift
;;
break
;;
esac
1*) i=0 ;;
*) i=2 ;;
esac
set $ifi
shift
;;
break
;;
esac
set $ifi
shift
ifi=$*
continue
;;
esac
0*) ;;
*) continue ;;
esac
l=$1
q=$2
r=$3
p=$4
shift 4
case $r in
esac
*u*) typeset -u u=$l ;;
esac
w=$l
case $l in
*e*) v=${u#?} ;;
esac
m=$l
;;
*) U=$u
m=_$l
;;
;;
dynamic:*)
# test if the _ version is a weak ref
#include <dlfcn.h>
main()
{
void* p;
void* u;
void* r;
p = dlopen(\"$lib\", 1);
u = dlsym(p, \"${i}$l\");
r = dlsym(p, \"$l\");
return(u == r);
} &&
./$tmp.x
then break
fi
;;
esac
w=${i}$l
*u*) typeset -u I=$i ;;
esac
{
echo "#undef $u"
echo "#define $u ${I}$u"
} >> $tmp.r
u=${I}$u
break
fi
done
{
echo "#undef $l /*MANGLENAME*/"
case $w in
$l) ;;
*) echo "#undef $w" ;;
esac
} >> $tmp.z
;;
esac
case $p in
void) b=0 a= ;;
*,*,*,*,*,*) b=6 a=a,b,c,d,e,f ;;
*,*,*,*,*) b=5 a=a,b,c,d,e ;;
*,*,*,*) b=4 a=a,b,c,d ;;
*,*,*) b=3 a=a,b,c ;;
*,*) b=2 a=a,b ;;
*) b=1 a=a ;;
esac
org=$p
A=$a
B=$b
alt=
def=
inc=
ind=
map=
num=
opt=
ref=
ver=
VER=
while :
do case $1 in
shift 2
;;
num*) shift
;;
shift 2
{
for i
do echo "#include <$i>"
done
echo "#ifdef __STDC__
extern $r $l($var);
#endif"
p=$var
case $p in
void) b=0 a= ;;
*,*,*,*,*,*) b=6 a=a,b,c,d,e,f ;;
*,*,*,*,*) b=5 a=a,b,c,d,e ;;
*,*,*,*) b=4 a=a,b,c,d ;;
*,*,*) b=3 a=a,b,c ;;
*,*) b=2 a=a,b ;;
*) b=1 a=a ;;
esac
org=$p
A=$a
B=$b
fi
break
;;
case $2 in
-) ref= ;;
*) ref=$2 ;;
esac
shift 2
case $l in
*u*) j=${l#?}
i=${l%$j}
xxx=_${i}x${j}
;;
;;
esac
;;
;;
esac
do echo "#include <$i>"
i=
do test -f "$j" && i="$i $j"
done
ver=`sed -e "/define[ ]*[A-Z_0-9]*64_VER/!d" -e 's/.*define[ ]*\([A-Z_0-9][A-Z_0-9]*\).*/\1/' $i </dev/null | sort -u`
*:*STAT*)
;;
*stat:*)for j in _SCO_STAT_VER
then ver=$j; break
fi
done
;;
esac
fi
;;
shift
;;
[0-9]*) num=$2 ;;
*) num=$1 ;;
esac
;;
*) num=$1
;;
esac
case $2 in
[0-9]*) shift 2 ;;
*) shift ;;
esac
;;
"") break
;;
*) case $# in
[012]) break ;;
*) shift 2 ;;
esac
;;
esac
done
esac
call=
do echo "#include <$i>"
;;
esac
then # hack test for last arg indirect in xxx version
"") {
echo "extern int foo(const char*);"
echo "extern int foo(const char**);"
then stdc=0
else stdc=1
fi
;;
esac
ra=$a
va=$a
1) {
do echo "#include <$i>"
done
echo "#ifdef INDIRECT"
echo "#define REFERENCE *"
echo "#else"
echo "#define REFERENCE"
echo "#endif"
echo "extern $r $xxx(const int, $p REFERENCE);"
then : ok
then ind="*"
*e*) i=${a%?}
ra="${i}&${a#$i}"
va="${i}*${a#$i}"
;;
;;
esac
fi
;;
esac
*u*) typeset -u y=$xxx ;;
esac
;;
esac
{
echo "#define SYS3D$m $inx"
echo "#ifndef SYS$m"
echo "#define SYS$m (-1)"
echo "#endif"
echo "#ifndef SYS$xxx"
echo "#define SYS$xxx (-1)"
echo "#endif"
echo "#define SYSNOV$xxx SYS$m"
} >> $tmp.f
esac
esac
{
case $y in
*e*) Y=${y#__} ;;
esac
echo "#undef $Y"
echo "#define $Y $y"
;;
*e*) Y=${y#_} ;;
esac
echo "#undef $Y"
echo "#define $Y $y"
;;
esac
echo "#undef $u"
echo "#define $u($a) $y(_3D${verid}${ra:+,}$ra)"
echo "#undef $y"
echo "#define $y(v${a:+,}$a) ${cast}SYSCALL(SYS3D$m,v${a:+,}$a)${tsac}"
} >> $tmp.u
case $p in
void) c=1
set $r int
;;
set int${comma}$p
c=$#
;;
esac
d=
s=
for i in 0 1 2 3 4 5
do case $# in
0) break ;;
esac
case $1 in
*"mode_t")
d=${d}${s}A_MODE
;;
*"size_t")
d=${d}${s}A_SIZE
;;
*"char* const*"|*"char**")
d=${d}${s}A_VECTOR
;;
*"char*")
case $r:$2 in
*"ssize_t":*"size_t")
shift
;;
*) d=${d}${s}A_STRING
;;
esac
;;
*"const void*")
d=${d}${s}A_INPUT
;;
*"void*")
d=${d}${s}A_OUTPUT
;;
*"struct stat*"|*"int*")
d=${d}${s}A_OUTPUT
;;
*) d=${d}${s}A_POINTER ;;
esac
;;
*"[]"|*"*")
d=${d}${s}A_POINTER
;;
*) d=${d}${s}A_NUMBER
;;
esac
s=,
shift
done
dynamic)x="0, "
;;
mangle) x="$u, "
echo "#undef $u
extern long $u();" >> $tmp.g
;;
*) x=
;;
esac
# NOTE: no varargs here
set $p
d=
f=
o=
for i in a b c d e f
do case $# in
0) break ;;
1) e=$ind ;;
*) e= ;;
esac
case $1 in
*e*) k=${1%\[\]} ;;
esac
i="$i"'[]'
;;
*) k=$1
;;
esac
case $k in
*char*) n=path ;;
*int*) n=fd ;;
*) n="<$k>${i}" ;;
esac
case $f in
'') f=$n ;;
*) f=$f,$n ;;
esac
case $d in
"") d="$k$e $n"
o="$k$e $n;"
;;
*) d="$d, $k$e $n"
o="$o $k$e $n;"
;;
esac
shift
done
echo "#define ${l}3d($a) $xxx __PARAM__((const int _3d_ver, $d),(_3d_ver${f:+,} $f)) __OTORP__(int _3d_ver; $o)" >> $tmp.d
case $v in
;;
esac
esac
continue
fi
;;
?*) echo "#include <${SYS_HEADER}>
#ifdef SYS_${l}
(
#endif
extern int ${l}();
case $s in
$l) ;;
#ifndef SYS_${s}
(
#else
int i;
then def=1
map=$s
fi
;;
esac
else def=1
fi
;;
esac
;;
esac
case $SYS_HEADER in
"") ;;
;;
esac
;;
esac
;;
;;
esac
;;
esac
;;
esac
;;
;;
esac
esac
fi
{
echo "#ifndef SYS$m"
echo "#define SYS$m (-1)"
echo "#endif"
} >> $tmp.f
;;
*) case $def:$SYS_HEADER in
:?*) echo "#include <${SYS_HEADER}>
#ifdef SYS${m}
(
#else
int i;
fi
;;
esac
;;
esac
;;
esac
nolib) ;;
"")
w=_no_$w
;;
*u*) typeset -u y=$alt ;;
esac
;;
esac
;;
sys) {
echo "#define SYS3D$m $inx"
echo "#ifndef SYS$m"
echo "#define SYS$m (-1)"
echo "#endif"
;;
esac
} >> $tmp.f
esac
{
echo "#undef $u"
echo "#define $u($a) ${cast}SYSCALL(SYS3D$m${A:+,}$A)${tsac}"
} >> $tmp.u
case $p in
void) set $r
c=0
;;
set $p
c=$#
set $r${comma}$p
;;
esac
d=
s=
for i in 0 1 2 3 4 5
do case $# in
0) break ;;
esac
case $1 in
*"mode_t")
d=${d}${s}A_MODE
;;
*"size_t")
d=${d}${s}A_SIZE
;;
*"char* const*"|*"char**")
d=${d}${s}A_VECTOR
;;
*"char*")
case $r:$2 in
*"ssize_t":*"size_t")
shift
;;
*) d=${d}${s}A_STRING
;;
esac
;;
*"const void*")
d=${d}${s}A_INPUT
;;
*"void*")
d=${d}${s}A_OUTPUT
;;
*"struct stat*"|*"int*")
d=${d}${s}A_OUTPUT
;;
*) d=${d}${s}A_POINTER ;;
esac
;;
*"[]"|*"*")
d=${d}${s}A_POINTER
;;
*) d=${d}${s}A_NUMBER
;;
esac
s=,
shift
done
mangle) x="$u, "
echo "#undef $u
extern long $u();" >> $tmp.g
;;
*) x="0, "
;;
esac
i=$l
case $i in
_exit) {
echo "static int hit;"
echo "void _exit(code) int code; { if (hit++) abort(); __exit(code); }"
echo "main() { return 0; }"
;;
?*:*) i=$map ;;
:?*) i=$w ;;
esac
;;
esac
;;
esac
;;
esac
i=
nolib) ;;
nosys) ;;
*) case $l:$w in
_*) ;;
*:_*) i=1 ;;
esac
;;
esac
case $i in
;;
*) case $p in
;;
set $p
d=
o=
va=$a
vo=
vx=
for i in a b c d e f
do case $# in
0) break ;;
esac
case $1 in
*...) d="$d, ..."
case $l in
*) t=int ;;
esac
o=va_dcl
set $p
for i in a b c d e f
do case $1 in
*...) break ;;
esac
shift
done
case $l in
esac
break
;;
*e*) k=${1%\[\]} ;;
esac
i="$i"'[]'
;;
*) k=$1
;;
esac
vx=$i
case $d in
"") d="$k $i"
o="$k $i;"
;;
*) d="$d, $k $i"
o="$o $k $i;"
;;
esac
shift
done
;;
esac
case $o in
?*) o="__OTORP__($o) " ;;
esac
case $r in
esac
z="$r $w"
W=
case $w in
esac
echo "#define ${l}3d ${ft}_3d_stub${m} = 0; extern __MANGLE__ $r $w __PROTO__(($p)); $r $l __PARAM__(($d),($va)) $o{$vo $fr$w($a); }$W $z" >> $tmp.d
;;
esac
nolib:*);;
nosys:*);;
esac
done
if test -f $tmp.t
then {
echo "};
"
echo "#define SYSCALL3D(z,a,b,c,d,e,f) (*sys_trace[z].func)(a,b,c,d,e,f)"
echo "#undef fstat"
case $_SYS_fstat_VER in
"") echo "#define fstat(a,b) SYSCALL3D(SYS3D_fstat,a,b,0,0,0,0)" ;;
esac
echo "#undef write"
echo "#define write(a,b,c) SYSCALL3D(SYS3D_write,a,b,c,0,0,0)"
;;
esac
;;
esac
echo "
#else
"
echo "
#define SYSCALL syscall3d
extern long syscall3d(int, ...);
#endif"
} >> $tmp.t
fi
echo "
#endif" >> $tmp.e
echo "
#ifdef SYSENT3D
extern int
$fun;
int (*_3d_sysent[])() = {
};
#else
extern int (*_3d_sysent[])();
#define PULL_IN_3D int (*pull_in_3d)() = _3d_sysent[0];
" >> $tmp.m
do vercall=
esac
?*) echo "#define _3D_${vercall}_VER ${ver}"
esac
done
;;
esac
done >> $tmp.f
do if test -f $tmp.$i
then echo
fi
done
echo