/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1998-2012 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> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* time related system call intercept
* the env var WARP controls the seconds offset added to each time_t
* and the time progression factor
*/
#endif
#if defined(__STDPP__directive) && defined(__STDPP__hide)
__STDPP__directive pragma pp:hide alarm _alarm __alarm clock_gettime _clock_gettime __clock_gettime gettimeofday _gettimeofday __gettimeofday getitimer _getitimer __getitimer poll _poll __poll select _select __select setitimer _setitimer __setitimer time times utime _utime __utime utimensat _utimensat __utimensat utimes _utimes __utimes utimets _utimets __utimets fstat64 lstat64
__STDPP__directive pragma pp:hide execlp _execlp __execlp execve _execve __execve execvp _execvp __execvp execvpe _execvpe __execvpe
#else
#define alarm ______alarm
#define _alarm _______alarm
#define __alarm ________alarm
#define clock_gettime ______clock_gettime
#define _clock_gettime _______clock_gettime
#define __clock_gettime ________clock_gettime
#define gettimeofday ______gettimeofday
#define _gettimeofday _______gettimeofday
#define __gettimeofday ________gettimeofday
#define getitimer ______getitimer
#define _getitimer _______getitimer
#define __getitimer ________getitimer
#define poll ______poll
#define _poll _______poll
#define __poll ________poll
#define select ______select
#define _select _______select
#define __select ________select
#define setitimer ______setitimer
#define _setitimer _______setitimer
#define __setitimer ________setitimer
#define time ______time
#define times ______times
#define utime ______utime
#define _utime _______utime
#define __utime ________utime
#define utimes ______utimes
#define _utimes _______utimes
#define __utimes ________utimes
#define utimensat ______utimensat
#define _utimensat _______utimensat
#define __utimensat ________utimensat
#define utimets ______utimets
#define _utimets _______utimets
#define __utimets ________utimets
#define fstat64 ______fstat64
#define lstat64 ______lstat64
#define execlp ______execlp
#define _execlp _______execlp
#define __execlp ________execlp
#define execve ______execve
#define _execve _______execve
#define __execve ________execve
#define execvp ______execvp
#define _execvp _______execvp
#define __execvp ________execvp
#define execvpe ______execvpe
#define _execvpe _______execvpe
#define __execvpe ________execvpe
#endif
#ifdef __EXPORT__
#define extern __EXPORT__
#undef extern
#endif
#include <ast.h>
#include <dlldefs.h>
#include <ls.h>
#include <times.h>
#if _hdr_utime
#include <utime.h>
#else
struct utimbuf
{
};
#endif
#if !_typ_struct_timespec
struct timespec
{
};
#endif
#if defined(__STDPP__directive) && defined(__STDPP__hide)
__STDPP__directive pragma pp:nohide alarm _alarm __alarm clock_gettime _clock_gettime __clock_gettime gettimeofday _gettimeofday __gettimeofday getitimer _getitimer __getitimer poll _poll __poll select _select __select setitimer _setitimer __setitimer time times utime _utime __utime utimensat _utimensat __utimensat utimes _utimes __utimes utimets _utimets __utimets fstat64 lstat64
__STDPP__directive pragma pp:nohide execlp _execlp __execlp execve _execve __execve execvp _execvp __execvp execvpe _execvpe __execvpe
#else
#endif
#ifdef __EXPORT__
#define extern __EXPORT__
#endif
#if defined(LINUX_STAT_VERSION) && !defined(_STAT_VER)
#endif
typedef void* (*Syscall_f)(void*);
typedef unsigned int (*Alarm_f)(unsigned int);
typedef int (*Poll_f)(void*, int, int);
typedef int (*Close_f)(int);
typedef int (*Execlp_f)(const char*, const char*, ...);
typedef int (*Execve_f)(const char*, char* const[], char* const[]);
typedef int (*Execvp_f)(const char*, char* const[]);
typedef int (*Execvpe_f)(const char*, char* const[], char* const[]);
#if defined(_STAT_VER)
#if defined(_lib__xstat64) || defined(_lib___xstat64)
#endif
#else
#endif
#if defined(_lib_stat64)
#endif
#endif
#if _lib_getitimer
#endif
#if _lib_setitimer
#endif
#define UNWARP_ABS(t) ((t)=(t)?(((t)-state.warp)/(state.factor+1)+state.base/(state.factor+1)*state.factor):0)
typedef struct
{
const char* name;
const char* mangled;
int warped;
unsigned long level;
} Call_t;
static struct
{
long base;
void* dll;
long factor;
unsigned long level;
unsigned long mix;
int trace;
long warp;
} state;
#ifndef environ
extern char** environ;
#endif
/*
* synthesize the low order seconds in s
* under the influence of a warp factor
*/
static unsigned long
mix(unsigned long s)
{
}
/*
* initialize the warp environment
* and intercept call p
*/
static void
{
register int c;
register char* s;
register long n;
register int v;
char* o;
if (p->warped)
return;
{
#ifdef __EXPORT__
o = getenv("WARP");
#else
register char** e;
register char** p;
register char** x;
char* t;
e = environ;
o = 0;
while (s = *e++)
{
switch (s[0])
{
case 'L':
if (s[1] != 'D' || s[2] != '_' || s[3] != 'P' || s[4] != 'R' || s[5] != 'E' || s[6] != 'L' || s[7] != 'O' || s[8] != 'A' || s[9] != 'D' || s[10] != '=')
continue;
break;
case 'W':
if (s[1] != 'A' || s[2] != 'R' || s[3] != 'P' || s[4] != '=')
continue;
o = s + 5;
break;
case '_':
if (s[1] != 'R' || s[2] != 'L' || s[3] != 'D' || s[4] != '_' && s[4] != 'N')
continue;
break;
default:
continue;
}
if (p >= x)
break;
{
s = "warp: out of space [env]\n";
_exit(125);
}
*p++ = strcpy(t, s);
}
#endif
if (s = o)
{
v = 'w';
for (;;)
{
switch (*s++)
{
case 0:
break;
case ' ':
case '\t':
case '-':
case '+':
v = 'w';
continue;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
s--;
c = s > o && *(s - 1) == '-';
n = 0;
while (*s >= '0' && *s <= '9')
n = n * 10 + *s++ - '0';
if (n)
{
if (c)
n = -n;
switch (v)
{
case 'b':
break;
case 'f':
break;
case 'w':
break;
}
v = 'w';
}
continue;
case 't':
continue;
default:
v = *(s - 1);
continue;
}
break;
}
{
}
}
{
exit(2);
}
}
{
exit(2);
}
{
}
}
static unsigned int
{
unsigned int r;
intercept(p);
UNWARP_REL(s);
p->warped = 1;
else
WARP_REL(r);
return r;
}
extern unsigned int
{
}
#ifndef __EXPORT__
extern unsigned int
{
}
extern unsigned int
{
}
extern unsigned int
{
}
extern unsigned int
{
}
#endif
static int
{
int r;
intercept(p);
{
p->warped = 1;
else if (tv)
}
return r;
}
extern int
{
}
#ifndef __EXPORT__
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
#endif
static int
{
int r;
intercept(p);
to /= 1000;
UNWARP_REL(to);
to *= 1000;
p->warped = 1;
return r;
}
static int
{
}
#ifndef __EXPORT__
static int
{
}
static int
{
}
static int
{
}
static int
{
}
#endif
static int
warp_select(register Call_t* p, int n, void* rp, void* wp, void* ep, register const struct timeval* tv)
{
int r;
struct timeval x;
intercept(p);
x = *tv;
if (x.tv_sec)
{
UNWARP_REL(x.tv_sec);
if (x.tv_sec)
x.tv_usec = 0;
x.tv_usec = 10;
}
p->warped = 1;
return r;
}
static int
{
}
#ifndef __EXPORT__
static int
{
}
static int
{
}
static int
{
}
static int
{
}
#endif
static time_t
{
time_t t;
intercept(p);
{
p->warped = 1;
else
{
WARP_ABS(t);
if (clock)
}
}
return t;
}
extern time_t
{
}
#ifndef __EXPORT__
extern time_t
{
}
extern time_t
{
}
extern time_t
{
}
extern time_t
{
}
#endif
static clock_t
{
clock_t t;
intercept(p);
{
p->warped = 1;
else
WARP_REL(t);
}
return t;
}
extern clock_t
{
}
#ifndef __EXPORT__
extern clock_t
{
}
extern clock_t
{
}
extern clock_t
{
}
extern clock_t
{
}
#endif
static int
{
int r;
intercept(p);
{
p->warped = 1;
}
return r;
}
extern int
{
}
#ifndef __EXPORT__
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
#endif
static int
warp_utimensat(int dirfd, register Call_t* p, const char* path, const struct timespec* tv, int flags)
{
int r;
register int i;
intercept(p);
for (i = 0; i < elementsof(tb); i++)
{
}
{
p->warped = 1;
}
return r;
}
extern int
{
}
#ifndef __EXPORT__
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
#endif
static int
{
int r;
register int i;
intercept(p);
for (i = 0; i < elementsof(tb); i++)
{
}
{
p->warped = 1;
}
return r;
}
extern int
{
}
#ifndef __EXPORT__
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
#endif
static int
{
int r;
register int i;
intercept(p);
for (i = 0; i < elementsof(tb); i++)
{
}
{
p->warped = 1;
}
return r;
}
extern int
{
}
#ifndef __EXPORT__
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
#endif
#if defined(_STAT_VER)
static void
{
if (!p->warped)
{
p->warped = 1;
#if defined(_STAT64_VER)
else if (ver >= _STAT64_VER)
{
}
#endif
{
}
{
}
}
}
extern int
{
int r;
return r;
}
extern int
{
int r;
return r;
}
extern int
{
int r;
return r;
}
extern int
{
int r;
return r;
}
extern int
{
int r;
return r;
}
extern int
{
int r;
return r;
}
#if defined(_lib__xstat64) || defined(_lib___xstat64)
static void
{
if (!p->warped)
{
p->warped = 1;
#if defined(_STAT64_VER)
else if (ver >= _STAT64_VER)
{
}
#endif
{
}
{
}
}
}
extern int
{
int r;
return r;
}
extern int
{
int r;
return r;
}
extern int
{
int r;
return r;
}
extern int
{
int r;
return r;
}
extern int
{
int r;
return r;
}
extern int
{
int r;
return r;
}
#endif
#else
static void
{
if (!p->warped)
{
p->warped = 1;
else
{
}
}
}
static int
{
int r;
intercept(p);
return r;
}
extern int
{
}
#ifndef __EXPORT__
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
#if _WARP_stat32
extern int
{
}
#endif
#endif
static int
{
int r;
intercept(p);
return r;
}
extern int
{
}
#ifndef __EXPORT__
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
#if _WARP_stat32
extern int
{
}
extern int
{
}
#endif
#endif
static int
{
int r;
intercept(p);
return r;
}
extern int
{
}
#ifndef __EXPORT__
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
#if _WARP_stat32
extern int
{
}
#endif
#endif
#endif
#if defined(_lib_stat64)
static void
{
if (!p->warped)
{
p->warped = 1;
else
{
}
}
}
static int
{
int r;
intercept(p);
return r;
}
extern int
{
}
#ifndef __EXPORT__
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
#endif
static int
{
int r;
intercept(p);
return r;
}
extern int
{
}
#ifndef __EXPORT__
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
#endif
static int
{
int r;
intercept(p);
return r;
}
extern int
{
}
#ifndef __EXPORT__
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
#endif
#endif /* defined(_lib_stat64) */
#if _lib_clock_gettime && defined(CLOCK_REALTIME)
static int
{
int r;
intercept(p);
{
p->warped = 1;
else if (tv)
}
return r;
}
extern int
{
return warp_clock_gettime(&call, i, v);
}
#ifndef __EXPORT__
extern int
{
return warp_clock_gettime(&call, i, v);
}
extern int
{
return warp_clock_gettime(&call, i, v);
}
extern int
{
return warp_clock_gettime(&call, i, v);
}
extern int
{
return warp_clock_gettime(&call, i, v);
}
#endif
#endif /* _lib_clock_gettime */
#if _lib_getitimer
static int
{
int r;
intercept(p);
{
p->warped = 1;
else
{
}
}
return r;
}
extern int
{
return warp_getitimer(&call, i, v);
}
#ifndef __EXPORT__
extern int
{
return warp_getitimer(&call, i, v);
}
extern int
{
return warp_getitimer(&call, i, v);
}
extern int
{
return warp_getitimer(&call, i, v);
}
extern int
{
return warp_getitimer(&call, i, v);
}
#endif
#endif /* _lib_getitimer */
#if _lib_setitimer
static int
{
int r;
struct itimerval x;
intercept(p);
return (*(Setitimer_f)p->call)(i, v, o);
x = *v;
if (x.it_interval.tv_sec)
{
if (x.it_interval.tv_sec)
x.it_interval.tv_usec = 0;
}
{
}
{
p->warped = 1;
else if (o)
{
}
}
return r;
}
extern int
{
return warp_setitimer(&call, i, v, o);
}
#ifndef __EXPORT__
extern int
{
return warp_setitimer(&call, i, v, o);
}
extern int
{
return warp_setitimer(&call, i, v, o);
}
extern int
{
return warp_setitimer(&call, i, v, o);
}
extern int
{
return warp_setitimer(&call, i, v, o);
}
#endif
#endif /* _lib_setitimer */
#ifndef __EXPORT__
static char**
{
register char** e;
register char** x;
register char* s;
register char* t;
register char* u;
char** z;
char** env;
int n;
{
if (e = env)
{
while (s = *e++)
{
while (t = *x++)
{
u = s;
while (*t++ == *u++)
if (!*t)
goto found;
}
goto missing;
;
}
}
else
if (s)
{
{
s = "warp: execve env missing\n";
}
if (e = env)
{
while (*e++);
n = e - env;
}
else
n = 1;
while (*e++);
if (!(z = (char**)malloc(n * sizeof(char**))))
{
s = "warp: execve env malloc error\n";
_exit(125);
}
e = env;
env = z;
while (*z = *x++)
z++;
if (e)
while (*z++ = *e++);
{
z = env;
while (t = *z++)
{
s = "warp: execve new env ";
}
}
}
{
s = "warp: execve env ok\n";
}
}
{
s = "warp: execve skip check\n";
}
return env;
}
static int
{
int n;
char** env;
static int level;
intercept(p);
p->warped++;
level++;
level--;
p->warped--;
return n;
}
static int
{
int n;
char** env;
static int level;
intercept(p);
p->warped++;
level++;
level--;
p->warped--;
return n;
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
extern int
{
}
#endif