syscall3d.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1989-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> *
* David Korn <dgk@research.att.com> *
* Eduardo Krell <ekrell@adexus.cl> *
* *
***********************************************************************/
#pragma prototyped
/*
* 3d system call trace
*/
#define SYSTRACE3D 1
#include "3d.h"
#if SYSTRACE3D
#include "dir_3d.h"
#ifndef D_FILENO
#define D_FILENO(d) (1)
#endif
#ifndef D_TYPE
#define D_TYPE(d) (0)
#endif
typedef union
{
void* pointer;
int number;
char* string;
char** vector;
} ARG;
static void* dll;
#if _lib_strerror
#else
extern int sys_nerr;
extern char* sys_errlist[];
char*
{
static char msg[28];
return sys_errlist[err];
return msg;
}
#endif
#define MAXBUF 128
#define MAXLIN 79
#define MAXOUT 2048
static void
{
register char* b;
register char* be;
register char* se;
register int c;
if (n < 0)
else
{
b = *buf;
be -= 5;
se = s + n;
if (b < be - 1)
{
*b++ = ' ';
*b++ = '"';
{
if ((c = *((unsigned char*)s++)) < 040)
{
*b++ = '\\';
switch (c)
{
case '\007':
c = 'a';
break;
case '\b':
c = 'b';
break;
case '\f':
c = 'f';
break;
case '\n':
c = 'n';
break;
case '\r':
c = 'r';
break;
case '\t':
c = 't';
break;
case '\013':
c = 'v';
break;
case '\033':
c = 'E';
break;
default:
if (b < be - 3)
{
*b++ = '0';
if (n || ((c >> 3) & 07))
*b++ = '0' + ((c >> 3) & 07);
*b++ = '0' + (c & 07);
}
continue;
}
if (b < be)
*b++ = c;
}
else if (c < 0177)
*b++ = c;
else if (c == 0177)
{
*b++ = '^';
if (b >= be)
break;
*b++ = '?';
}
else if (b < be - 4)
{
*b++ = '\\';
*b++ = '0' + ((c >> 6) & 03);
*b++ = '0' + ((c >> 3) & 07);
*b++ = '0' + (c & 07);
}
}
{
b -= 4;
*b++ = '"';
*b++ = '.';
*b++ = '.';
*b++ = '.';
}
else if (b < be)
*b++ = '"';
}
*buf = b;
}
}
#if __gnu_linux__
#endif
#if _lib_syscall && _sys_syscall
#ifdef SYS_exit
static void
{
}
#endif
#endif
/*
* initialize the 3d syscall table
*/
void
callinit(void)
{
register Systrace_t* cp;
#endif
#endif
{
if (!(cp->func = (Sysfunc_t)dlsym(dll, cp->name)) && (*cp->name != '_' || !(cp->func = (Sysfunc_t)dlsym(dll, cp->name + 1)) || !*cp->name++))
#if !defined(SYS_EXIT) && _no_exit_exit
#endif
}
#ifdef SYS_EXIT
#endif
}
/*
* dump the 3d syscall table
*/
void
calldump(char** b, char* e)
{
register Systrace_t* cp;
register int m;
#if _no_exit_exit
#else
(Sysfunc_t)0
#endif
);
{
bprintf(b, e, " %03d%s %03d %12s", cp - sys_trace, (cp - sys_trace) == cp->index ? " " : "*", cp->call, cp->name);
}
}
#if _no_exit_exit
static int
oksys(void)
{
return 0;
}
void
{
{
}
}
#endif
{
initialize();
}
#if !_var_syscall
long
{
#if 0 /* to convince proto */
}
#endif
#else
long
{
#endif
register int n;
register long r;
register Systrace_t* cp;
register int ac;
int a;
int m;
int on;
char* b;
char* e;
char* t;
char** p;
int* ip;
#if _var_syscall
#endif
initialize();
#if _var_syscall
#endif
#if _var_syscall
#else
{
}
#endif
if (state.kernel || state.trace.pid <= 1 || (on = fsfd(&state.fs[FS_option])) <= 0 || !(state.test & 0100) && !(MSG_MASK(cp->call) & (state.trace.call & ~MSG_MASK(error_info.trace ? 0 : MSG_nop))))
on = 0;
else
{
{
a = A_INPUT;
if (call == SYS3D_write)
{
a = 0;
else if (m == 1 || m == 2)
{
n = errno;
if (!fstat(m, &st) && st.st_ino == state.fs[FS_option].st.st_ino && st.st_dev == state.fs[FS_option].st.st_dev)
a = 0;
errno = n;
}
}
if ((state.test & 020) && call == SYS3D_close) bprintf(&b, e, "%s%s%s", state.file[arg[1].number].reserved ? " [RESERVED]" : "", arg[1].number == TABLE_FD ? " [TABLE]" : "", arg[1].number == state.table.fd ? " [table]" : "");
{
switch (n)
{
case A_INPUT:
if (a)
{
break;
}
/*FALLTHROUGH*/
case A_OUTPUT:
case A_POINTER:
break;
case A_MODE:
break;
case A_STRING:
else
bprintf(&b, e, " (null)");
break;
case A_VECTOR:
bprintf(&b, e, " [");
if (*p)
bprintf(&b, e, "...");
bprintf(&b, e, " ]");
break;
default:
break;
}
}
if (!a)
*b++ = '\n';
{
bprintf(&b, e, " ) = ?\n");
}
n = errno;
errno = n;
}
else
{
{
*b++ = '\n';
for (n = 0; n < elementsof(sys_trace); n++)
{
{
else
bprintf(&b, e, "%5lu.%dk", sys_trace[n].units >> 10, ((sys_trace[n].units & ((1<<10)-1)) * 10) >> 10);
}
else
if (b < e)
*b++ = '\n';
}
*b++ = '\n';
n = errno;
errno = n;
}
}
}
break;
if (m >= 0)
{
r = (*state.trap.intercept[m].call)(&state.trap.intercept[m], cp->call, call, arg[1].pointer, arg[2].pointer, arg[3].pointer, arg[4].pointer, arg[5].pointer, arg[6].pointer);
}
else
{
#if _dynamic_syscall || _static_syscall
#if _dynamic_syscall
#else
#endif
{
{
case 0:
break;
case 1:
{
if (!(cp->last = (Sysfunc_t)dlsym(dll, cp->name)) && (*cp->name != '_' || !(cp->last = (Sysfunc_t)dlsym(dll, cp->name + 1)) || !*cp->name++))
{
/*
* longjmp gets you here
*/
}
{
}
}
break;
case 2:
case 3:
break;
default:
break;
}
r = (*func)(arg[1].pointer, arg[2].pointer, arg[3].pointer, arg[4].pointer, arg[5].pointer, arg[6].pointer);
}
else
#endif
#if _lib_syscall
r = syscall(cp->index, arg[1].pointer, arg[2].pointer, arg[3].pointer, arg[4].pointer, arg[5].pointer, arg[6].pointer);
r = syscall(cp->nov, arg[2].pointer, arg[3].pointer, arg[4].pointer, arg[5].pointer, arg[6].pointer, 0);
else
#endif
{
#ifndef ENOSYS
#endif
r = -1;
}
}
#if !_mangle_syscall
r = 0;
#endif
{
{
m = 0;
b = buf;
{
{
case A_OUTPUT:
switch (call)
{
case SYS3D_fstat:
#ifdef SYS3D_lstat
case SYS3D_lstat:
#endif
case SYS3D_stat:
if (!r)
{
/*UNDENT...*/
#ifdef _3D_STAT_VER
{
case _3D_STAT_VER:
#endif
{
bprintf(&b, e, " [ dev=%d ino=%d view=%d mode=0%o nlink=%d uid=%d gid=%d size=%u atime=%u mtime=%u ctime=%u ]", sp->st_dev, sp->st_ino, iview(sp), sp->st_mode, sp->st_nlink, sp->st_uid, sp->st_gid, sp->st_size, sp->st_atime, sp->st_mtime, sp->st_ctime);
continue;
}
#ifdef _3D_STAT_VER
#ifdef _3D_STAT64_VER
case _3D_STAT64_VER:
{
bprintf(&b, e, " [ dev=%d ino=%lld view=%d mode=0%o nlink=%d uid=%d gid=%d size=%llu atime=%u mtime=%u ctime=%u ]", sp->st_dev, sp->st_ino, iview(sp), sp->st_mode, sp->st_nlink, sp->st_uid, sp->st_gid, sp->st_size, sp->st_atime, sp->st_mtime, sp->st_ctime);
continue;
}
#endif
}
#endif
}
break;
#ifdef SYS3D_getdents
case SYS3D_getdents:
if (r > 0)
{
bprintf(&b, e, " [");
{
#ifdef DIRdirent
#else
#endif
}
bprintf(&b, e, " ]");
continue;
}
break;
#endif
case SYS3D_pipe:
if (!r)
{
continue;
}
break;
}
/*FALLTHROUGH*/
case A_INPUT:
if (n == A_OUTPUT && cp->type[n = 0] == A_SIZE || ac < (elementsof(cp->type) - 1) && cp->type[n = ac + 1] == A_SIZE)
{
break;
}
goto pointer;
case A_MODE:
break;
case A_POINTER:
break;
case A_STRING:
if (r == -1)
goto pointer;
break;
default:
break;
}
}
#if DEBUG_dirent
switch (call)
{
#ifdef SYS3D_readdir
case SYS3D_readdir:
{
break;
}
goto number;
#endif
#ifdef SYS3D_readdir64
case SYS3D_readdir64:
{
break;
}
goto number;
#endif
default:
break;
}
#else
#endif
if (r == -1)
n = errno;
t = buf;
while ((b - t) >= m)
{
char* w;
char* x;
char* z;
int c1;
int c2;
x = w = t + m;
z = t + m / 2;
while (x > z && *x != ' ') x--;
if (x <= z)
x = w;
c1 = *x;
*x++ = '\n';
c2 = *x;
*x++ = '\t';
*--x = c2;
if ((*--x = c1) == ' ')
x++;
t = x;
m = MAXLIN - 8;
}
*b++ = '\n';
errno = n;
}
{
}
}
return r;
}
#else
#endif