xref: /netbsd-src/external/gpl3/binutils.old/dist/gprofng/libcollector/iotrace.c (revision c42dbd0ed2e61fe6eda8590caa852ccf34719964)
1 /* Copyright (C) 2021 Free Software Foundation, Inc.
2    Contributed by Oracle.
3 
4    This file is part of GNU Binutils.
5 
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3, or (at your option)
9    any later version.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, 51 Franklin Street - Fifth Floor, Boston,
19    MA 02110-1301, USA.  */
20 
21 /*
22  *	IO events
23  */
24 #include "config.h"
25 #include <dlfcn.h>
26 #include <errno.h>
27 #include <stdarg.h>
28 #include <stdlib.h>
29 
30 // create() and others are defined in fcntl.h.
31 // Our 'create' should not have the __nonnull attribute
32 #undef __nonnull
33 #define __nonnull(x)
34 #include <fcntl.h>
35 
36 #include "gp-defs.h"
37 #include "collector_module.h"
38 #include "gp-experiment.h"
39 #include "data_pckts.h"
40 #include "tsd.h"
41 
42 /* TprintfT(<level>,...) definitions.  Adjust per module as needed */
43 #define DBG_LT0 0 // for high-level configuration, unexpected errors/warnings
44 #define DBG_LTT 0 // for interposition on GLIBC functions
45 #define DBG_LT1 1 // for configuration details, warnings
46 #define DBG_LT2 2
47 #define DBG_LT3 3
48 
49 /* define the packet that will be written out */
50 typedef struct IOTrace_packet
51 { /* IO tracing packet */
52   Common_packet comm;
53   IOTrace_type iotype;      /* IO type */
54   int32_t fd;               /* file descriptor */
55   Size_type nbyte;          /* number of bytes */
56   hrtime_t requested;       /* time of IO requested */
57   int32_t ofd;              /* original file descriptor */
58   FileSystem_type fstype;   /* file system type */
59   char fname;               /* file name */
60 } IOTrace_packet;
61 
62 typedef long long offset_t;
63 
64 static int open_experiment (const char *);
65 static int start_data_collection (void);
66 static int stop_data_collection (void);
67 static int close_experiment (void);
68 static int detach_experiment (void);
69 static int init_io_intf ();
70 
71 static ModuleInterface module_interface ={
72   SP_IOTRACE_FILE,          /* description */
73   NULL,                     /* initInterface */
74   open_experiment,          /* openExperiment */
75   start_data_collection,    /* startDataCollection */
76   stop_data_collection,     /* stopDataCollection */
77   close_experiment,         /* closeExperiment */
78   detach_experiment         /* detachExperiment (fork child) */
79 };
80 
81 static CollectorInterface *collector_interface = NULL;
82 static struct Heap *io_heap = NULL;
83 static int io_mode = 0;
84 static CollectorModule io_hndl = COLLECTOR_MODULE_ERR;
85 static unsigned io_key = COLLECTOR_TSD_INVALID_KEY;
86 
87 #define CHCK_REENTRANCE(x)   (!io_mode || ((x) = collector_interface->getKey( io_key )) == NULL || (*(x) != 0))
88 #define RECHCK_REENTRANCE(x) (!io_mode || ((x) = collector_interface->getKey( io_key )) == NULL || (*(x) == 0))
89 #define PUSH_REENTRANCE(x)   ((*(x))++)
90 #define POP_REENTRANCE(x)    ((*(x))--)
91 
92 #define CALL_REAL(x)         (__real_##x)
93 #define NULL_PTR(x)          (__real_##x == NULL)
94 
95 #define gethrtime collector_interface->getHiResTime
96 
97 #ifdef DEBUG
98 #define Tprintf(...)    if (collector_interface) collector_interface->writeDebugInfo( 0, __VA_ARGS__ )
99 #define TprintfT(...)   if (collector_interface) collector_interface->writeDebugInfo( 1, __VA_ARGS__ )
100 #else
101 #define Tprintf(...)
102 #define TprintfT(...)
103 #endif
104 
105 /* interposition function handles */
106 static int (*__real_open)(const char *path, int oflag, ...) = NULL;
107 static int (*__real_fcntl)(int fildes, int cmd, ...) = NULL;
108 static int (*__real_openat)(int fildes, const char *path, int oflag, ...) = NULL;
109 static int (*__real_close)(int fildes) = NULL;
110 static FILE *(*__real_fopen)(const char *filename, const char *mode) = NULL;
111 static int (*__real_fclose)(FILE *stream) = NULL;
112 static int (*__real_dup)(int fildes) = NULL;
113 static int (*__real_dup2)(int fildes, int fildes2) = NULL;
114 static int (*__real_pipe)(int fildes[2]) = NULL;
115 static int (*__real_socket)(int domain, int type, int protocol) = NULL;
116 static int (*__real_mkstemp)(char *template) = NULL;
117 static int (*__real_mkstemps)(char *template, int slen) = NULL;
118 static int (*__real_creat)(const char *path, mode_t mode) = NULL;
119 static FILE *(*__real_fdopen)(int fildes, const char *mode) = NULL;
120 static ssize_t (*__real_read)(int fildes, void *buf, size_t nbyte) = NULL;
121 static ssize_t (*__real_write)(int fildes, const void *buf, size_t nbyte) = NULL;
122 static ssize_t (*__real_readv)(int fildes, const struct iovec *iov, int iovcnt) = NULL;
123 static ssize_t (*__real_writev)(int fildes, const struct iovec *iov, int iovcnt) = NULL;
124 static size_t (*__real_fread)(void *ptr, size_t size, size_t nitems, FILE *stream) = NULL;
125 static size_t (*__real_fwrite)(const void *ptr, size_t size, size_t nitems, FILE *stream) = NULL;
126 static ssize_t (*__real_pread)(int fildes, void *buf, size_t nbyte, off_t offset) = NULL;
127 static ssize_t (*__real_pwrite)(int fildes, const void *buf, size_t nbyte, off_t offset) = NULL;
128 static ssize_t (*__real_pwrite64)(int fildes, const void *buf, size_t nbyte, off64_t offset) = NULL;
129 static char *(*__real_fgets)(char *s, int n, FILE *stream) = NULL;
130 static int (*__real_fputs)(const char *s, FILE *stream) = NULL;
131 static int (*__real_fputc)(int c, FILE *stream) = NULL;
132 static int (*__real_fprintf)(FILE *stream, const char *format, ...) = NULL;
133 static int (*__real_vfprintf)(FILE *stream, const char *format, va_list ap) = NULL;
134 static off_t (*__real_lseek)(int fildes, off_t offset, int whence) = NULL;
135 static offset_t (*__real_llseek)(int fildes, offset_t offset, int whence) = NULL;
136 static int (*__real_chmod)(const char *path, mode_t mode) = NULL;
137 static int (*__real_access)(const char *path, int amode) = NULL;
138 static int (*__real_rename)(const char *old, const char *new) = NULL;
139 static int (*__real_mkdir)(const char *path, mode_t mode) = NULL;
140 static int (*__real_getdents)(int fildes, struct dirent *buf, size_t nbyte) = NULL;
141 static int (*__real_unlink)(const char *path) = NULL;
142 static int (*__real_fseek)(FILE *stream, long offset, int whence) = NULL;
143 static void (*__real_rewind)(FILE *stream) = NULL;
144 static long (*__real_ftell)(FILE *stream) = NULL;
145 static int (*__real_fgetpos)(FILE *stream, fpos_t *pos) = NULL;
146 static int (*__real_fsetpos)(FILE *stream, const fpos_t *pos) = NULL;
147 static int (*__real_fsync)(int fildes) = NULL;
148 static struct dirent *(*__real_readdir)(DIR *dirp) = NULL;
149 static int (*__real_flock)(int fd, int operation) = NULL;
150 static int (*__real_lockf)(int fildes, int function, off_t size) = NULL;
151 static int (*__real_fflush)(FILE *stream) = NULL;
152 
153 #if WSIZE(32)
154 static int (*__real_open64)(const char *path, int oflag, ...) = NULL;
155 static int (*__real_creat64)(const char *path, mode_t mode) = NULL;
156 static int (*__real_fgetpos64)(FILE *stream, fpos64_t *pos) = NULL;
157 static int (*__real_fsetpos64)(FILE *stream, const fpos64_t *pos) = NULL;
158 
159 #if ARCH(Intel)
160 static FILE *(*__real_fopen_2_1)(const char *filename, const char *mode) = NULL;
161 static int (*__real_fclose_2_1)(FILE *stream) = NULL;
162 static FILE *(*__real_fdopen_2_1)(int fildes, const char *mode) = NULL;
163 static int (*__real_fgetpos_2_2)(FILE *stream, fpos_t *pos) = NULL;
164 static int (*__real_fsetpos_2_2)(FILE *stream, const fpos_t *pos) = NULL;
165 static int (*__real_fgetpos64_2_2)(FILE *stream, fpos64_t *pos) = NULL;
166 static int (*__real_fsetpos64_2_2)(FILE *stream, const fpos64_t *pos) = NULL;
167 static int (*__real_open64_2_2)(const char *path, int oflag, ...) = NULL;
168 static ssize_t (*__real_pread_2_2)(int fildes, void *buf, size_t nbyte, off_t offset) = NULL;
169 static ssize_t (*__real_pwrite_2_2)(int fildes, const void *buf, size_t nbyte, off_t offset) = NULL;
170 static ssize_t (*__real_pwrite64_2_2)(int fildes, const void *buf, size_t nbyte, off64_t offset) = NULL;
171 static FILE *(*__real_fopen_2_0)(const char *filename, const char *mode) = NULL;
172 static int (*__real_fclose_2_0)(FILE *stream) = NULL;
173 static FILE *(*__real_fdopen_2_0)(int fildes, const char *mode) = NULL;
174 static int (*__real_fgetpos_2_0)(FILE *stream, fpos_t *pos) = NULL;
175 static int (*__real_fsetpos_2_0)(FILE *stream, const fpos_t *pos) = NULL;
176 static int (*__real_fgetpos64_2_1)(FILE *stream, fpos64_t *pos) = NULL;
177 static int (*__real_fsetpos64_2_1)(FILE *stream, const fpos64_t *pos) = NULL;
178 static int (*__real_open64_2_1)(const char *path, int oflag, ...) = NULL;
179 static ssize_t (*__real_pread_2_1)(int fildes, void *buf, size_t nbyte, off_t offset) = NULL;
180 static ssize_t (*__real_pwrite_2_1)(int fildes, const void *buf, size_t nbyte, off_t offset) = NULL;
181 static ssize_t (*__real_pwrite64_2_1)(int fildes, const void *buf, size_t nbyte, off64_t offset) = NULL;
182 #endif /* ARCH() */
183 #endif /* WSIZE(32) */
184 
185 static int
collector_align_pktsize(int sz)186 collector_align_pktsize (int sz)
187 {
188   int pktSize = sz;
189   if (sz <= 0)
190     return sz;
191   if ((sz % 8) != 0)
192     {
193       pktSize = (sz / 8) + 1;
194       pktSize *= 8;
195     }
196   return pktSize;
197 }
198 
199 static void
collector_memset(void * s,int c,size_t n)200 collector_memset (void *s, int c, size_t n)
201 {
202   unsigned char *s1 = s;
203   while (n--)
204     *s1++ = (unsigned char) c;
205 }
206 
207 static size_t
collector_strlen(const char * s)208 collector_strlen (const char *s)
209 {
210   if (s == NULL)
211     return 0;
212   int len = -1;
213   while (s[++len] != '\0')
214     ;
215   return len;
216 }
217 
218 static size_t
collector_strncpy(char * dst,const char * src,size_t dstsize)219 collector_strncpy (char *dst, const char *src, size_t dstsize)
220 {
221   size_t i;
222   for (i = 0; i < dstsize; i++)
223     {
224       dst[i] = src[i];
225       if (src[i] == '\0')
226 	break;
227     }
228   return i;
229 }
230 
231 static char *
collector_strchr(const char * s,int c)232 collector_strchr (const char *s, int c)
233 {
234   do
235     {
236       if (*s == (char) c)
237 	return ((char *) s);
238     }
239   while (*s++);
240   return (NULL);
241 }
242 
243 static FileSystem_type
collector_fstype(const char * path)244 collector_fstype (const char *path)
245 {
246   return UNKNOWNFS_TYPE;
247 }
248 
249 void
__collector_module_init(CollectorInterface * _collector_interface)250 __collector_module_init (CollectorInterface *_collector_interface)
251 {
252   if (_collector_interface == NULL)
253     return;
254   collector_interface = _collector_interface;
255   Tprintf (0, "iotrace: __collector_module_init\n");
256   io_hndl = collector_interface->registerModule (&module_interface);
257   /* Initialize next module */
258   ModuleInitFunc next_init = (ModuleInitFunc) dlsym (RTLD_NEXT, "__collector_module_init");
259   if (next_init != NULL)
260     next_init (_collector_interface);
261   return;
262 }
263 
264 static int
open_experiment(const char * exp)265 open_experiment (const char *exp)
266 {
267   if (collector_interface == NULL)
268     {
269       Tprintf (0, "iotrace: collector_interface is null.\n");
270       return COL_ERROR_IOINIT;
271     }
272   if (io_hndl == COLLECTOR_MODULE_ERR)
273     {
274       Tprintf (0, "iotrace: handle create failed.\n");
275       collector_interface->writeLog ("<event kind=\"%s\" id=\"%d\">data handle not created</event>\n",
276 				     SP_JCMD_CERROR, COL_ERROR_IOINIT);
277       return COL_ERROR_IOINIT;
278     }
279   TprintfT (0, "iotrace: open_experiment %s\n", exp);
280   if (NULL_PTR (fopen))
281     init_io_intf ();
282   if (io_heap == NULL)
283     {
284       io_heap = collector_interface->newHeap ();
285       if (io_heap == NULL)
286 	{
287 	  Tprintf (0, "iotrace: new heap failed.\n");
288 	  collector_interface->writeLog ("<event kind=\"%s\" id=\"%d\">new iotrace heap not created</event>\n",
289 					 SP_JCMD_CERROR, COL_ERROR_IOINIT);
290 	  return COL_ERROR_IOINIT;
291 	}
292     }
293 
294   const char *params = collector_interface->getParams ();
295   while (params)
296     {
297       if ((params[0] == 'i') && (params[1] == ':'))
298 	{
299 	  params += 2;
300 	  break;
301 	}
302       params = collector_strchr (params, ';');
303       if (params)
304 	params++;
305     }
306   if (params == NULL)  /* IO data collection not specified */
307     return COL_ERROR_IOINIT;
308 
309   io_key = collector_interface->createKey (sizeof ( int), NULL, NULL);
310   if (io_key == (unsigned) - 1)
311     {
312       Tprintf (0, "iotrace: TSD key create failed.\n");
313       collector_interface->writeLog ("<event kind=\"%s\" id=\"%d\">TSD key not created</event>\n",
314 				     SP_JCMD_CERROR, COL_ERROR_IOINIT);
315       return COL_ERROR_IOINIT;
316     }
317 
318   collector_interface->writeLog ("<profile name=\"%s\">\n", SP_JCMD_IOTRACE);
319   collector_interface->writeLog ("  <profdata fname=\"%s\"/>\n",
320 				 module_interface.description);
321   /* Record IOTrace_packet description */
322   IOTrace_packet *pp = NULL;
323   collector_interface->writeLog ("  <profpckt kind=\"%d\" uname=\"IO tracing data\">\n", IOTRACE_PCKT);
324   collector_interface->writeLog ("    <field name=\"LWPID\" uname=\"Lightweight process id\" offset=\"%d\" type=\"%s\"/>\n",
325 				 &pp->comm.lwp_id, sizeof (pp->comm.lwp_id) == 4 ? "INT32" : "INT64");
326   collector_interface->writeLog ("    <field name=\"THRID\" uname=\"Thread number\" offset=\"%d\" type=\"%s\"/>\n",
327 				 &pp->comm.thr_id, sizeof (pp->comm.thr_id) == 4 ? "INT32" : "INT64");
328   collector_interface->writeLog ("    <field name=\"CPUID\" uname=\"CPU id\" offset=\"%d\" type=\"%s\"/>\n",
329 				 &pp->comm.cpu_id, sizeof (pp->comm.cpu_id) == 4 ? "INT32" : "INT64");
330   collector_interface->writeLog ("    <field name=\"TSTAMP\" uname=\"High resolution timestamp\" offset=\"%d\" type=\"%s\"/>\n",
331 				 &pp->comm.tstamp, sizeof (pp->comm.tstamp) == 4 ? "INT32" : "INT64");
332   collector_interface->writeLog ("    <field name=\"FRINFO\" offset=\"%d\" type=\"%s\"/>\n",
333 				 &pp->comm.frinfo, sizeof (pp->comm.frinfo) == 4 ? "INT32" : "INT64");
334   collector_interface->writeLog ("    <field name=\"IOTYPE\" uname=\"IO trace function type\" offset=\"%d\" type=\"%s\"/>\n",
335 				 &pp->iotype, sizeof (pp->iotype) == 4 ? "INT32" : "INT64");
336   collector_interface->writeLog ("    <field name=\"IOFD\" uname=\"File descriptor\" offset=\"%d\" type=\"%s\"/>\n",
337 				 &pp->fd, sizeof (pp->fd) == 4 ? "INT32" : "INT64");
338   collector_interface->writeLog ("    <field name=\"IONBYTE\" uname=\"Number of bytes\" offset=\"%d\" type=\"%s\"/>\n",
339 				 &pp->nbyte, sizeof (pp->nbyte) == 4 ? "INT32" : "INT64");
340   collector_interface->writeLog ("    <field name=\"IORQST\" uname=\"Time of IO requested\" offset=\"%d\" type=\"%s\"/>\n",
341 				 &pp->requested, sizeof (pp->requested) == 4 ? "INT32" : "INT64");
342   collector_interface->writeLog ("    <field name=\"IOOFD\" uname=\"Original file descriptor\" offset=\"%d\" type=\"%s\"/>\n",
343 				 &pp->ofd, sizeof (pp->ofd) == 4 ? "INT32" : "INT64");
344   collector_interface->writeLog ("    <field name=\"IOFSTYPE\" uname=\"File system type\" offset=\"%d\" type=\"%s\"/>\n",
345 				 &pp->fstype, sizeof (pp->fstype) == 4 ? "INT32" : "INT64");
346   collector_interface->writeLog ("    <field name=\"IOFNAME\" uname=\"File name\" offset=\"%d\" type=\"%s\"/>\n",
347 				 &pp->fname, "STRING");
348   collector_interface->writeLog ("  </profpckt>\n");
349   collector_interface->writeLog ("</profile>\n");
350   return COL_ERROR_NONE;
351 }
352 
353 static int
start_data_collection(void)354 start_data_collection (void)
355 {
356   io_mode = 1;
357   Tprintf (0, "iotrace: start_data_collection\n");
358   return 0;
359 }
360 
361 static int
stop_data_collection(void)362 stop_data_collection (void)
363 {
364   io_mode = 0;
365   Tprintf (0, "iotrace: stop_data_collection\n");
366   return 0;
367 }
368 
369 static int
close_experiment(void)370 close_experiment (void)
371 {
372   io_mode = 0;
373   io_key = COLLECTOR_TSD_INVALID_KEY;
374   if (io_heap != NULL)
375     {
376       collector_interface->deleteHeap (io_heap);
377       io_heap = NULL;
378     }
379   Tprintf (0, "iotrace: close_experiment\n");
380   return 0;
381 }
382 
383 static int
detach_experiment(void)384 detach_experiment (void)
385 {
386   /* fork child.  Clean up state but don't write to experiment */
387   io_mode = 0;
388   io_key = COLLECTOR_TSD_INVALID_KEY;
389   if (io_heap != NULL)
390     {
391       collector_interface->deleteHeap (io_heap);
392       io_heap = NULL;
393     }
394   Tprintf (0, "iotrace: detach_experiment\n");
395   return 0;
396 }
397 
398 static int
init_io_intf()399 init_io_intf ()
400 {
401   void *dlflag;
402   int rc = 0;
403   /* if we detect recursion/reentrance, SEGV so we can get a stack */
404   static int init_io_intf_started;
405   static int init_io_intf_finished;
406   init_io_intf_started++;
407   if (!init_io_intf_finished && init_io_intf_started >= 3)
408     {
409       /* pull the plug if recursion occurs... */
410       abort ();
411     }
412 
413   /* lookup fprint to print fatal error message */
414   void *ptr = dlsym (RTLD_NEXT, "fprintf");
415   if (ptr)
416     __real_fprintf = (int (*)(FILE*, const char*, ...)) ptr;
417   else
418     abort ();
419 
420 #if ARCH(Intel)
421 #if WSIZE(32)
422 #define SYS_FOPEN_X_VERSION "GLIBC_2.1"
423 #define SYS_FGETPOS_X_VERSION "GLIBC_2.2"
424 #define SYS_FGETPOS64_X_VERSION "GLIBC_2.2"
425 #define SYS_OPEN64_X_VERSION "GLIBC_2.2"
426 #define SYS_PREAD_X_VERSION "GLIBC_2.2"
427 #define SYS_PWRITE_X_VERSION "GLIBC_2.2"
428 #define SYS_PWRITE64_X_VERSION "GLIBC_2.2"
429 #else /* WSIZE(64) */
430 #define SYS_FOPEN_X_VERSION "GLIBC_2.2.5"
431 #define SYS_FGETPOS_X_VERSION "GLIBC_2.2.5"
432 #endif
433 #elif ARCH(SPARC)
434 #if WSIZE(32)
435 #define SYS_FOPEN_X_VERSION "GLIBC_2.1"
436 #define SYS_FGETPOS_X_VERSION "GLIBC_2.2"
437 #else /* WSIZE(64) */
438 #define SYS_FOPEN_X_VERSION "GLIBC_2.2"
439 #define SYS_FGETPOS_X_VERSION "GLIBC_2.2"
440 #endif
441 #elif ARCH(Aarch64)
442 #define SYS_FOPEN_X_VERSION      "GLIBC_2.17"
443 #define SYS_FGETPOS_X_VERSION    "GLIBC_2.17"
444 #endif /* ARCH() */
445 
446 #if WSIZE(32)
447   dlflag = RTLD_NEXT;
448   __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (dlflag, "fopen", SYS_FOPEN_X_VERSION);
449   if (__real_fopen == NULL)
450     {
451       /* We are probably dlopened after libc,
452        * try to search in the previously loaded objects
453        */
454       __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (RTLD_DEFAULT, "fopen", SYS_FOPEN_X_VERSION);
455       if (__real_fopen != NULL)
456 	{
457 	  Tprintf (0, "iotrace: WARNING: init_io_intf() using RTLD_DEFAULT for Linux io routines\n");
458 	  dlflag = RTLD_DEFAULT;
459 	}
460       else
461 	{
462 	  CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen\n");
463 	  rc = COL_ERROR_IOINIT;
464 	}
465     }
466 
467   __real_fclose = (int (*)(FILE*))dlvsym (dlflag, "fclose", SYS_FOPEN_X_VERSION);
468   if (__real_fclose == NULL)
469     {
470       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose\n");
471       rc = COL_ERROR_IOINIT;
472     }
473 
474   __real_fdopen = (FILE * (*)(int, const char*))dlvsym (dlflag, "fdopen", SYS_FOPEN_X_VERSION);
475   if (__real_fdopen == NULL)
476     {
477       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen\n");
478       rc = COL_ERROR_IOINIT;
479     }
480 
481   __real_fgetpos = (int (*)(FILE*, fpos_t*))dlvsym (dlflag, "fgetpos", SYS_FGETPOS_X_VERSION);
482   if (__real_fgetpos == NULL)
483     {
484       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos\n");
485       rc = COL_ERROR_IOINIT;
486     }
487 
488   __real_fsetpos = (int (*)(FILE*, const fpos_t*))dlvsym (dlflag, "fsetpos", SYS_FGETPOS_X_VERSION);
489   if (__real_fsetpos == NULL)
490     {
491       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos\n");
492       rc = COL_ERROR_IOINIT;
493     }
494 
495 
496 #if ARCH(Intel)
497   __real_fopen_2_1 = __real_fopen;
498   __real_fclose_2_1 = __real_fclose;
499   __real_fdopen_2_1 = __real_fdopen;
500   __real_fgetpos_2_2 = __real_fgetpos;
501   __real_fsetpos_2_2 = __real_fsetpos;
502 
503   __real_fopen_2_0 = (FILE * (*)(const char*, const char*))dlvsym (dlflag, "fopen", "GLIBC_2.0");
504   if (__real_fopen_2_0 == NULL)
505     {
506       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen_2_0\n");
507       rc = COL_ERROR_IOINIT;
508     }
509 
510   __real_fclose_2_0 = (int (*)(FILE*))dlvsym (dlflag, "fclose", "GLIBC_2.0");
511   if (__real_fclose_2_0 == NULL)
512     {
513       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose_2_0\n");
514       rc = COL_ERROR_IOINIT;
515     }
516 
517   __real_fdopen_2_0 = (FILE * (*)(int, const char*))dlvsym (dlflag, "fdopen", "GLIBC_2.0");
518   if (__real_fdopen_2_0 == NULL)
519     {
520       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen_2_0\n");
521       rc = COL_ERROR_IOINIT;
522     }
523 
524   __real_fgetpos_2_0 = (int (*)(FILE*, fpos_t*))dlvsym (dlflag, "fgetpos", "GLIBC_2.0");
525   if (__real_fgetpos_2_0 == NULL)
526     {
527       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos_2_0\n");
528       rc = COL_ERROR_IOINIT;
529     }
530 
531   __real_fsetpos_2_0 = (int (*)(FILE*, const fpos_t*))dlvsym (dlflag, "fsetpos", "GLIBC_2.0");
532   if (__real_fsetpos_2_0 == NULL)
533     {
534       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos_2_0\n");
535       rc = COL_ERROR_IOINIT;
536     }
537 
538   __real_fgetpos64_2_1 = (int (*)(FILE*, fpos64_t*))dlvsym (dlflag, "fgetpos64", "GLIBC_2.1");
539   if (__real_fgetpos64_2_1 == NULL)
540     {
541       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos64_2_1\n");
542       rc = COL_ERROR_IOINIT;
543     }
544 
545   __real_fsetpos64_2_1 = (int (*)(FILE*, const fpos64_t*))dlvsym (dlflag, "fsetpos64", "GLIBC_2.1");
546   if (__real_fsetpos64_2_1 == NULL)
547     {
548       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos64_2_1\n");
549       rc = COL_ERROR_IOINIT;
550     }
551 
552   __real_open64_2_1 = (int (*)(const char*, int, ...))dlvsym (dlflag, "open64", "GLIBC_2.1");
553   if (__real_open64_2_1 == NULL)
554     {
555       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open64_2_1\n");
556       rc = COL_ERROR_IOINIT;
557     }
558 
559   __real_pread_2_1 = (int (*)(int fildes, void *buf, size_t nbyte, off_t offset))dlvsym (dlflag, "pread", "GLIBC_2.1");
560   if (__real_pread_2_1 == NULL)
561     {
562       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread_2_1\n");
563       rc = COL_ERROR_IOINIT;
564     }
565 
566   __real_pwrite_2_1 = (int (*)(int fildes, const void *buf, size_t nbyte, off_t offset))dlvsym (dlflag, "pwrite", "GLIBC_2.1");
567   if (__real_pwrite_2_1 == NULL)
568     {
569       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite_2_1\n");
570       rc = COL_ERROR_IOINIT;
571     }
572 
573   __real_pwrite64_2_1 = (int (*)(int fildes, const void *buf, size_t nbyte, off64_t offset))dlvsym (dlflag, "pwrite64", "GLIBC_2.1");
574   if (__real_pwrite64_2_1 == NULL)
575     {
576       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite64_2_1\n");
577       rc = COL_ERROR_IOINIT;
578     }
579 
580   __real_fgetpos64_2_2 = (int (*)(FILE*, fpos64_t*))dlvsym (dlflag, "fgetpos64", SYS_FGETPOS64_X_VERSION);
581   if (__real_fgetpos64_2_2 == NULL)
582     {
583       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos64_2_2\n");
584       rc = COL_ERROR_IOINIT;
585     }
586 
587   __real_fsetpos64_2_2 = (int (*)(FILE*, const fpos64_t*))dlvsym (dlflag, "fsetpos64", SYS_FGETPOS64_X_VERSION);
588   if (__real_fsetpos64_2_2 == NULL)
589     {
590       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos64_2_2\n");
591       rc = COL_ERROR_IOINIT;
592     }
593 
594   __real_open64_2_2 = (int (*)(const char*, int, ...))dlvsym (dlflag, "open64", SYS_OPEN64_X_VERSION);
595   if (__real_open64_2_2 == NULL)
596     {
597       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open64_2_2\n");
598       rc = COL_ERROR_IOINIT;
599     }
600 
601   __real_pread_2_2 = (int (*)(int fildes, void *buf, size_t nbyte, off_t offset))dlvsym (dlflag, "pread", SYS_PREAD_X_VERSION);
602   if (__real_pread_2_2 == NULL)
603     {
604       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread_2_2\n");
605       rc = COL_ERROR_IOINIT;
606     }
607 
608   __real_pwrite_2_2 = (int (*)(int fildes, const void *buf, size_t nbyte, off_t offset))dlvsym (dlflag, "pwrite", SYS_PWRITE_X_VERSION);
609   if (__real_pwrite_2_2 == NULL)
610     {
611       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite_2_2\n");
612       rc = COL_ERROR_IOINIT;
613     }
614 
615   __real_pwrite64_2_2 = (int (*)(int fildes, const void *buf, size_t nbyte, off64_t offset))dlvsym (dlflag, "pwrite64", SYS_PWRITE64_X_VERSION);
616   if (__real_pwrite64_2_2 == NULL)
617     {
618       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite64_2_2\n");
619       rc = COL_ERROR_IOINIT;
620     }
621 
622 #endif
623 
624 #else /* WSIZE(64) */
625   dlflag = RTLD_NEXT;
626   __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (dlflag, "fopen", SYS_FOPEN_X_VERSION);
627   if (__real_fopen == NULL)
628     {
629       /* We are probably dlopened after libc,
630        * try to search in the previously loaded objects
631        */
632       __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (RTLD_DEFAULT, "fopen", SYS_FOPEN_X_VERSION);
633       if (__real_fopen != NULL)
634 	{
635 	  Tprintf (0, "iotrace: WARNING: init_io_intf() using RTLD_DEFAULT for Linux io routines\n");
636 	  dlflag = RTLD_DEFAULT;
637 	}
638       else
639 	{
640 	  CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen\n");
641 	  rc = COL_ERROR_IOINIT;
642 	}
643     }
644 
645   __real_fclose = (int (*)(FILE*))dlvsym (dlflag, "fclose", SYS_FOPEN_X_VERSION);
646   if (__real_fclose == NULL)
647     {
648       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose\n");
649       rc = COL_ERROR_IOINIT;
650     }
651 
652   __real_fdopen = (FILE * (*)(int, const char*))dlvsym (dlflag, "fdopen", SYS_FOPEN_X_VERSION);
653   if (__real_fdopen == NULL)
654     {
655       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen\n");
656       rc = COL_ERROR_IOINIT;
657     }
658 
659   __real_fgetpos = (int (*)(FILE*, fpos_t*))dlvsym (dlflag, "fgetpos", SYS_FGETPOS_X_VERSION);
660   if (__real_fgetpos == NULL)
661     {
662       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos\n");
663       rc = COL_ERROR_IOINIT;
664     }
665 
666   __real_fsetpos = (int (*)(FILE*, const fpos_t*))dlvsym (dlflag, "fsetpos", SYS_FGETPOS_X_VERSION);
667   if (__real_fsetpos == NULL)
668     {
669       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos\n");
670       rc = COL_ERROR_IOINIT;
671     }
672 #endif /* WSIZE(32) */
673 
674   __real_open = (int (*)(const char*, int, ...))dlsym (dlflag, "open");
675   if (__real_open == NULL)
676     {
677       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open\n");
678       rc = COL_ERROR_IOINIT;
679     }
680 
681 #if WSIZE(32)
682   __real_open64 = (int (*)(const char*, int, ...))dlsym (dlflag, "open64");
683   if (__real_open64 == NULL)
684     {
685       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open64\n");
686       rc = COL_ERROR_IOINIT;
687     }
688 #endif
689 
690   __real_fcntl = (int (*)(int, int, ...))dlsym (dlflag, "fcntl");
691   if (__real_fcntl == NULL)
692     {
693       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fcntl\n");
694       rc = COL_ERROR_IOINIT;
695     }
696 
697   __real_openat = (int (*)(int, const char*, int, ...))dlsym (dlflag, "openat");
698   if (__real_openat == NULL)
699     {
700       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT openat\n");
701       rc = COL_ERROR_IOINIT;
702     }
703 
704   __real_close = (int (*)(int))dlsym (dlflag, "close");
705   if (__real_close == NULL)
706     {
707       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT close\n");
708       rc = COL_ERROR_IOINIT;
709     }
710 
711   __real_dup = (int (*)(int))dlsym (dlflag, "dup");
712   if (__real_dup == NULL)
713     {
714       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT dup\n");
715       rc = COL_ERROR_IOINIT;
716     }
717 
718   __real_dup2 = (int (*)(int, int))dlsym (dlflag, "dup2");
719   if (__real_dup2 == NULL)
720     {
721       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT dup2\n");
722       rc = COL_ERROR_IOINIT;
723     }
724 
725   __real_pipe = (int (*)(int[]))dlsym (dlflag, "pipe");
726   if (__real_pipe == NULL)
727     {
728       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pipe\n");
729       rc = COL_ERROR_IOINIT;
730     }
731 
732   __real_socket = (int (*)(int, int, int))dlsym (dlflag, "socket");
733   if (__real_socket == NULL)
734     {
735       __real_socket = (int (*)(int, int, int))dlsym (RTLD_NEXT, "socket");
736       if (__real_socket == NULL)
737 	{
738 #if 0
739 	  CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT socket\n");
740 	  rc = COL_ERROR_IOINIT;
741 #endif
742 	}
743     }
744 
745   __real_mkstemp = (int (*)(char*))dlsym (dlflag, "mkstemp");
746   if (__real_mkstemp == NULL)
747     {
748       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT mkstemp\n");
749       rc = COL_ERROR_IOINIT;
750     }
751 
752   __real_mkstemps = (int (*)(char*, int))dlsym (dlflag, "mkstemps");
753   if (__real_mkstemps == NULL)
754     {
755 #if 0
756       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT mkstemps\n");
757       rc = COL_ERROR_IOINIT;
758 #endif
759     }
760 
761   __real_creat = (int (*)(const char*, mode_t))dlsym (dlflag, "creat");
762   if (__real_creat == NULL)
763     {
764       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT creat\n");
765       rc = COL_ERROR_IOINIT;
766     }
767 
768 #if WSIZE(32)
769   __real_creat64 = (int (*)(const char*, mode_t))dlsym (dlflag, "creat64");
770   if (__real_creat64 == NULL)
771     {
772       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT creat64\n");
773       rc = COL_ERROR_IOINIT;
774     }
775 #endif
776 
777   __real_read = (ssize_t (*)(int, void*, size_t))dlsym (dlflag, "read");
778   if (__real_read == NULL)
779     {
780       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT read\n");
781       rc = COL_ERROR_IOINIT;
782     }
783 
784   __real_write = (ssize_t (*)(int, const void*, size_t))dlsym (dlflag, "write");
785   if (__real_write == NULL)
786     {
787       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT write\n");
788       rc = COL_ERROR_IOINIT;
789     }
790 
791   __real_readv = (ssize_t (*)(int, const struct iovec*, int))dlsym (dlflag, "readv");
792   if (__real_readv == NULL)
793     {
794       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT readv\n");
795       rc = COL_ERROR_IOINIT;
796     }
797 
798   __real_writev = (ssize_t (*)(int, const struct iovec*, int))dlsym (dlflag, "writev");
799   if (__real_writev == NULL)
800     {
801       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT writev\n");
802       rc = COL_ERROR_IOINIT;
803     }
804 
805   __real_fread = (size_t (*)(void*, size_t, size_t, FILE*))dlsym (dlflag, "fread");
806   if (__real_fread == NULL)
807     {
808       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fread\n");
809       rc = COL_ERROR_IOINIT;
810     }
811 
812   __real_fwrite = (size_t (*)(const void*, size_t, size_t, FILE*))dlsym (dlflag, "fwrite");
813   if (__real_fwrite == NULL)
814     {
815       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fwrite\n");
816       rc = COL_ERROR_IOINIT;
817     }
818 
819   __real_pread = (ssize_t (*)(int, void*, size_t, off_t))dlsym (dlflag, "pread");
820   if (__real_pread == NULL)
821     {
822       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread\n");
823       rc = COL_ERROR_IOINIT;
824     }
825 
826   __real_pwrite = (ssize_t (*)(int, const void*, size_t, off_t))dlsym (dlflag, "pwrite");
827   if (__real_pwrite == NULL)
828     {
829       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite\n");
830       rc = COL_ERROR_IOINIT;
831     }
832 
833   __real_pwrite64 = (ssize_t (*)(int, const void*, size_t, off64_t))dlsym (dlflag, "pwrite64");
834   if (__real_pwrite64 == NULL)
835     {
836       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite64\n");
837       rc = COL_ERROR_IOINIT;
838     }
839 
840   __real_fgets = (char* (*)(char*, int, FILE*))dlsym (dlflag, "fgets");
841   if (__real_fgets == NULL)
842     {
843       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgets\n");
844       rc = COL_ERROR_IOINIT;
845     }
846 
847   __real_fputs = (int (*)(const char*, FILE*))dlsym (dlflag, "fputs");
848   if (__real_fputs == NULL)
849     {
850       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fputs\n");
851       rc = COL_ERROR_IOINIT;
852     }
853 
854   __real_fputc = (int (*)(int, FILE*))dlsym (dlflag, "fputc");
855   if (__real_fputc == NULL)
856     {
857       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fputc\n");
858       rc = COL_ERROR_IOINIT;
859     }
860 
861   __real_vfprintf = (int (*)(FILE*, const char*, va_list))dlsym (dlflag, "vfprintf");
862   if (__real_vfprintf == NULL)
863     {
864       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT vfprintf\n");
865       rc = COL_ERROR_IOINIT;
866     }
867 
868 
869   __real_lseek = (off_t (*)(int, off_t, int))dlsym (dlflag, "lseek");
870   if (__real_lseek == NULL)
871     {
872       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT lseek\n");
873       rc = COL_ERROR_IOINIT;
874     }
875 
876   __real_llseek = (offset_t (*)(int, offset_t, int))dlsym (dlflag, "llseek");
877   if (__real_llseek == NULL)
878     {
879       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT llseek\n");
880       rc = COL_ERROR_IOINIT;
881     }
882 
883   __real_chmod = (int (*)(const char*, mode_t))dlsym (dlflag, "chmod");
884   if (__real_chmod == NULL)
885     {
886       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT chmod\n");
887       rc = COL_ERROR_IOINIT;
888     }
889 
890   __real_access = (int (*)(const char*, int))dlsym (dlflag, "access");
891   if (__real_access == NULL)
892     {
893       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT access\n");
894       rc = COL_ERROR_IOINIT;
895     }
896 
897   __real_rename = (int (*)(const char*, const char*))dlsym (dlflag, "rename");
898   if (__real_rename == NULL)
899     {
900       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT rename\n");
901       rc = COL_ERROR_IOINIT;
902     }
903 
904   __real_mkdir = (int (*)(const char*, mode_t))dlsym (dlflag, "mkdir");
905   if (__real_mkdir == NULL)
906     {
907       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT mkdir\n");
908       rc = COL_ERROR_IOINIT;
909     }
910 
911   __real_getdents = (int (*)(int, struct dirent*, size_t))dlsym (dlflag, "getdents");
912   if (__real_getdents == NULL)
913     {
914 #if 0
915       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT getdents\n");
916       rc = COL_ERROR_IOINIT;
917 #endif
918     }
919 
920   __real_unlink = (int (*)(const char*))dlsym (dlflag, "unlink");
921   if (__real_unlink == NULL)
922     {
923       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT unlink\n");
924       rc = COL_ERROR_IOINIT;
925     }
926 
927   __real_fseek = (int (*)(FILE*, long, int))dlsym (dlflag, "fseek");
928   if (__real_fseek == NULL)
929     {
930       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fseek\n");
931       rc = COL_ERROR_IOINIT;
932     }
933 
934   __real_rewind = (void (*)(FILE*))dlsym (dlflag, "rewind");
935   if (__real_rewind == NULL)
936     {
937       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT rewind\n");
938       rc = COL_ERROR_IOINIT;
939     }
940 
941   __real_ftell = (long (*)(FILE*))dlsym (dlflag, "ftell");
942   if (__real_ftell == NULL)
943     {
944       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT ftell\n");
945       rc = COL_ERROR_IOINIT;
946     }
947 
948   __real_fsync = (int (*)(int))dlsym (dlflag, "fsync");
949   if (__real_fsync == NULL)
950     {
951       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsync\n");
952       rc = COL_ERROR_IOINIT;
953     }
954 
955   __real_readdir = (struct dirent * (*)(DIR*))dlsym (dlflag, "readdir");
956   if (__real_readdir == NULL)
957     {
958       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT readdir\n");
959       rc = COL_ERROR_IOINIT;
960     }
961 
962   __real_flock = (int (*)(int, int))dlsym (dlflag, "flock");
963   if (__real_flock == NULL)
964     {
965       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT flock\n");
966       rc = COL_ERROR_IOINIT;
967     }
968 
969   __real_lockf = (int (*)(int, int, off_t))dlsym (dlflag, "lockf");
970   if (__real_lockf == NULL)
971     {
972       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT lockf\n");
973       rc = COL_ERROR_IOINIT;
974     }
975 
976   __real_fflush = (int (*)(FILE*))dlsym (dlflag, "fflush");
977   if (__real_fflush == NULL)
978     {
979       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fflush\n");
980       rc = COL_ERROR_IOINIT;
981     }
982 
983 #if WSIZE(32)
984   __real_fgetpos64 = (int (*)(FILE*, fpos64_t*))dlsym (dlflag, "fgetpos64");
985   if (__real_fgetpos64 == NULL)
986     {
987       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos64\n");
988       rc = COL_ERROR_IOINIT;
989     }
990 
991   __real_fsetpos64 = (int (*)(FILE*, const fpos64_t*))dlsym (dlflag, "fsetpos64");
992   if (__real_fsetpos64 == NULL)
993     {
994       CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos64\n");
995       rc = COL_ERROR_IOINIT;
996     }
997 #endif
998   init_io_intf_finished++;
999   return rc;
1000 }
1001 
1002 /*------------------------------------------------------------- open */
1003 int
open(const char * path,int oflag,...)1004 open (const char *path, int oflag, ...)
1005 {
1006   int *guard;
1007   int fd;
1008   void *packet;
1009   IOTrace_packet *iopkt;
1010   mode_t mode;
1011   va_list ap;
1012   size_t sz;
1013   unsigned pktSize;
1014 
1015   va_start (ap, oflag);
1016   mode = va_arg (ap, mode_t);
1017   va_end (ap);
1018 
1019   if (NULL_PTR (open))
1020     init_io_intf ();
1021 
1022   if (CHCK_REENTRANCE (guard) || path == NULL)
1023     return CALL_REAL (open)(path, oflag, mode);
1024   PUSH_REENTRANCE (guard);
1025   hrtime_t reqt = gethrtime ();
1026   fd = CALL_REAL (open)(path, oflag, mode);
1027   if (RECHCK_REENTRANCE (guard))
1028     {
1029       POP_REENTRANCE (guard);
1030       return fd;
1031     }
1032   hrtime_t grnt = gethrtime ();
1033   sz = collector_strlen (path);
1034   pktSize = sizeof (IOTrace_packet) + sz;
1035   pktSize = collector_align_pktsize (pktSize);
1036   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1037   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1038   if (packet != NULL)
1039     {
1040       iopkt = (IOTrace_packet *) packet;
1041       collector_memset (iopkt, 0, pktSize);
1042       iopkt->comm.tsize = pktSize;
1043       iopkt->comm.tstamp = grnt;
1044       iopkt->requested = reqt;
1045       if (fd != -1)
1046 	iopkt->iotype = OPEN_TRACE;
1047       else
1048 	iopkt->iotype = OPEN_TRACE_ERROR;
1049       iopkt->fd = fd;
1050       iopkt->fstype = collector_fstype (path);
1051       collector_strncpy (&(iopkt->fname), path, sz);
1052       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1053       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1054       collector_interface->freeCSize (io_heap, packet, pktSize);
1055     }
1056   else
1057     {
1058       Tprintf (0, "iotrace: ERROR: open cannot allocate memory\n");
1059       return -1;
1060     }
1061   POP_REENTRANCE (guard);
1062   return fd;
1063 }
1064 
1065 /*------------------------------------------------------------- open64 */
1066 #if ARCH(Intel) && WSIZE(32)
1067 // map interposed symbol versions
1068 static int
1069 __collector_open64_symver (int(real_open64) (const char *, int, ...),
1070 			   const char *path, int oflag, mode_t mode);
1071 
1072 SYMVER_ATTRIBUTE (__collector_open64_2_2, open64@@GLIBC_2.2)
1073 int
__collector_open64_2_2(const char * path,int oflag,...)1074 __collector_open64_2_2 (const char *path, int oflag, ...)
1075 {
1076   mode_t mode;
1077   va_list ap;
1078   va_start (ap, oflag);
1079   mode = va_arg (ap, mode_t);
1080   va_end (ap);
1081   TprintfT (DBG_LTT,
1082 	    "iotrace: __collector_open64_2_2@%p(path=%s, oflag=0%o, mode=0%o\n",
1083 	    CALL_REAL (open64_2_2), path ? path : "NULL", oflag, mode);
1084   if (NULL_PTR (open64))
1085     init_io_intf ();
1086   return __collector_open64_symver (CALL_REAL (open64_2_2), path, oflag, mode);
1087 }
1088 
1089 SYMVER_ATTRIBUTE (__collector_open64_2_1, open64@GLIBC_2.1)
1090 int
__collector_open64_2_1(const char * path,int oflag,...)1091 __collector_open64_2_1 (const char *path, int oflag, ...)
1092 {
1093   mode_t mode;
1094   va_list ap;
1095   va_start (ap, oflag);
1096   mode = va_arg (ap, mode_t);
1097   va_end (ap);
1098   TprintfT (DBG_LTT,
1099 	    "iotrace: __collector_open64_2_1@%p(path=%s, oflag=0%o, mode=0%o\n",
1100 	    CALL_REAL (open64_2_1), path ? path : "NULL", oflag, mode);
1101   if (NULL_PTR (open64))
1102     init_io_intf ();
1103   return __collector_open64_symver (CALL_REAL (open64_2_1), path, oflag, mode);
1104 }
1105 
1106 #endif /* ARCH(Intel) && WSIZE(32) */
1107 #if WSIZE(32)
1108 #if ARCH(Intel) && WSIZE(32)
1109 
1110 static int
__collector_open64_symver(int (real_open64)(const char *,int,...),const char * path,int oflag,mode_t mode)1111 __collector_open64_symver (int(real_open64) (const char *, int, ...),
1112 			   const char *path, int oflag, mode_t mode)
1113 {
1114   int *guard;
1115   int fd;
1116   void *packet;
1117   IOTrace_packet *iopkt;
1118   size_t sz;
1119   unsigned pktSize;
1120   if (NULL_PTR (open64))
1121     init_io_intf ();
1122   if (CHCK_REENTRANCE (guard) || path == NULL)
1123     return (real_open64) (path, oflag, mode);
1124   PUSH_REENTRANCE (guard);
1125   hrtime_t reqt = gethrtime ();
1126   fd = real_open64 (path, oflag, mode);
1127 #else /* ^ARCH(Intel) && WSIZE(32) */
1128 
1129 int
1130 open64 (const char *path, int oflag, ...)
1131 {
1132   int *guard;
1133   int fd;
1134   void *packet;
1135   IOTrace_packet *iopkt;
1136   mode_t mode;
1137   va_list ap;
1138   size_t sz;
1139   unsigned pktSize;
1140 
1141   va_start (ap, oflag);
1142   mode = va_arg (ap, mode_t);
1143   va_end (ap);
1144   if (NULL_PTR (open64))
1145     init_io_intf ();
1146   if (CHCK_REENTRANCE (guard) || path == NULL)
1147     return CALL_REAL (open64)(path, oflag, mode);
1148   PUSH_REENTRANCE (guard);
1149   hrtime_t reqt = gethrtime ();
1150   fd = CALL_REAL (open64)(path, oflag, mode);
1151 #endif /* ^ARCH(Intel) && WSIZE(32) */
1152 
1153   if (RECHCK_REENTRANCE (guard) || path == NULL)
1154     {
1155       POP_REENTRANCE (guard);
1156       return fd;
1157     }
1158   hrtime_t grnt = gethrtime ();
1159   sz = collector_strlen (path);
1160   pktSize = sizeof (IOTrace_packet) + sz;
1161   pktSize = collector_align_pktsize (pktSize);
1162   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1163   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1164   if (packet != NULL)
1165     {
1166       iopkt = (IOTrace_packet *) packet;
1167       collector_memset (iopkt, 0, pktSize);
1168       iopkt->comm.tsize = pktSize;
1169       iopkt->comm.tstamp = grnt;
1170       iopkt->requested = reqt;
1171       if (fd != -1)
1172 	iopkt->iotype = OPEN_TRACE;
1173       else
1174 	iopkt->iotype = OPEN_TRACE_ERROR;
1175       iopkt->fd = fd;
1176       iopkt->fstype = collector_fstype (path);
1177       collector_strncpy (&(iopkt->fname), path, sz);
1178       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1179       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1180       collector_interface->freeCSize (io_heap, packet, pktSize);
1181     }
1182   else
1183     {
1184       Tprintf (0, "iotrace: ERROR: open64 cannot allocate memory\n");
1185       return -1;
1186     }
1187   POP_REENTRANCE (guard);
1188   return fd;
1189 }
1190 #endif
1191 
1192 #define F_ERROR_ARG     0
1193 #define F_INT_ARG       1
1194 #define F_LONG_ARG      2
1195 #define F_VOID_ARG      3
1196 
1197 /*
1198  * The following macro is not defined in the
1199  * older versions of Linux.
1200  * #define F_DUPFD_CLOEXEC	1030
1201  *
1202  * Instead use the command that is defined below
1203  * until we start compiling mpmt on the newer
1204  * versions of Linux.
1205  */
1206 #define TMP_F_DUPFD_CLOEXEC 1030
1207 
1208 /*------------------------------------------------------------- fcntl */
1209 int
1210 fcntl (int fildes, int cmd, ...)
1211 {
1212   int *guard;
1213   int fd = 0;
1214   IOTrace_packet iopkt;
1215   long long_arg = 0;
1216   int int_arg = 0;
1217   int which_arg = F_ERROR_ARG;
1218   va_list ap;
1219   switch (cmd)
1220     {
1221     case F_DUPFD:
1222     case TMP_F_DUPFD_CLOEXEC:
1223     case F_SETFD:
1224     case F_SETFL:
1225     case F_SETOWN:
1226     case F_SETSIG:
1227     case F_SETLEASE:
1228     case F_NOTIFY:
1229     case F_SETLK:
1230     case F_SETLKW:
1231     case F_GETLK:
1232       va_start (ap, cmd);
1233       long_arg = va_arg (ap, long);
1234       va_end (ap);
1235       which_arg = F_LONG_ARG;
1236       break;
1237     case F_GETFD:
1238     case F_GETFL:
1239     case F_GETOWN:
1240     case F_GETLEASE:
1241     case F_GETSIG:
1242       which_arg = F_VOID_ARG;
1243       break;
1244     }
1245   if (NULL_PTR (fcntl))
1246     init_io_intf ();
1247   if (CHCK_REENTRANCE (guard))
1248     {
1249       switch (which_arg)
1250 	{
1251 	case F_INT_ARG:
1252 	  return CALL_REAL (fcntl)(fildes, cmd, int_arg);
1253 	case F_LONG_ARG:
1254 	  return CALL_REAL (fcntl)(fildes, cmd, long_arg);
1255 	case F_VOID_ARG:
1256 	  return CALL_REAL (fcntl)(fildes, cmd);
1257 	case F_ERROR_ARG:
1258 	  Tprintf (0, "iotrace: ERROR: Unsupported fcntl command\n");
1259 	  return -1;
1260 	}
1261       return -1;
1262     }
1263   if (cmd != F_DUPFD && cmd != TMP_F_DUPFD_CLOEXEC)
1264     {
1265       switch (which_arg)
1266 	{
1267 	case F_INT_ARG:
1268 	  return CALL_REAL (fcntl)(fildes, cmd, int_arg);
1269 	case F_LONG_ARG:
1270 	  return CALL_REAL (fcntl)(fildes, cmd, long_arg);
1271 	case F_VOID_ARG:
1272 	  return CALL_REAL (fcntl)(fildes, cmd);
1273 	case F_ERROR_ARG:
1274 	  Tprintf (0, "iotrace: ERROR: Unsupported fcntl command\n");
1275 	  return -1;
1276 	}
1277       return -1;
1278     }
1279   PUSH_REENTRANCE (guard);
1280   hrtime_t reqt = gethrtime ();
1281   switch (cmd)
1282     {
1283     case F_DUPFD:
1284     case TMP_F_DUPFD_CLOEXEC:
1285       fd = CALL_REAL (fcntl)(fildes, cmd, long_arg);
1286       break;
1287     }
1288   if (RECHCK_REENTRANCE (guard))
1289     {
1290       POP_REENTRANCE (guard);
1291       return fd;
1292     }
1293   hrtime_t grnt = gethrtime ();
1294   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1295   iopkt.comm.tsize = sizeof (IOTrace_packet);
1296   iopkt.comm.tstamp = grnt;
1297   iopkt.requested = reqt;
1298   if (fd != -1)
1299     iopkt.iotype = OPEN_TRACE;
1300   else
1301     iopkt.iotype = OPEN_TRACE_ERROR;
1302   iopkt.fd = fd;
1303   iopkt.ofd = fildes;
1304   iopkt.fstype = UNKNOWNFS_TYPE;
1305   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1306   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1307   POP_REENTRANCE (guard);
1308   return fd;
1309 }
1310 
1311 /*------------------------------------------------------------- openat */
1312 int
1313 openat (int fildes, const char *path, int oflag, ...)
1314 {
1315   int *guard;
1316   int fd;
1317   void *packet;
1318   IOTrace_packet *iopkt;
1319   mode_t mode;
1320   va_list ap;
1321   size_t sz;
1322   unsigned pktSize;
1323 
1324   va_start (ap, oflag);
1325   mode = va_arg (ap, mode_t);
1326   va_end (ap);
1327   if (NULL_PTR (openat))
1328     init_io_intf ();
1329   if (CHCK_REENTRANCE (guard) || path == NULL)
1330     return CALL_REAL (openat)(fildes, path, oflag, mode);
1331   PUSH_REENTRANCE (guard);
1332   hrtime_t reqt = gethrtime ();
1333   fd = CALL_REAL (openat)(fildes, path, oflag, mode);
1334   if (RECHCK_REENTRANCE (guard))
1335     {
1336       POP_REENTRANCE (guard);
1337       return fd;
1338     }
1339   hrtime_t grnt = gethrtime ();
1340   sz = collector_strlen (path);
1341   pktSize = sizeof (IOTrace_packet) + sz;
1342   pktSize = collector_align_pktsize (pktSize);
1343   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1344   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1345   if (packet != NULL)
1346     {
1347       iopkt = (IOTrace_packet *) packet;
1348       collector_memset (iopkt, 0, pktSize);
1349       iopkt->comm.tsize = pktSize;
1350       iopkt->comm.tstamp = grnt;
1351       iopkt->requested = reqt;
1352       if (fd != -1)
1353 	iopkt->iotype = OPEN_TRACE;
1354       else
1355 	iopkt->iotype = OPEN_TRACE_ERROR;
1356       iopkt->fd = fd;
1357       iopkt->fstype = collector_fstype (path);
1358       collector_strncpy (&(iopkt->fname), path, sz);
1359       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1360       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1361       collector_interface->freeCSize (io_heap, packet, pktSize);
1362     }
1363   else
1364     {
1365       Tprintf (0, "iotrace: ERROR: openat cannot allocate memory\n");
1366       return -1;
1367     }
1368   POP_REENTRANCE (guard);
1369   return fd;
1370 }
1371 
1372 /*------------------------------------------------------------- creat */
1373 int
1374 creat (const char *path, mode_t mode)
1375 {
1376   int *guard;
1377   int fd;
1378   void *packet;
1379   IOTrace_packet *iopkt;
1380   size_t sz;
1381   unsigned pktSize;
1382   if (NULL_PTR (creat))
1383     init_io_intf ();
1384   if (CHCK_REENTRANCE (guard) || path == NULL)
1385     return CALL_REAL (creat)(path, mode);
1386   PUSH_REENTRANCE (guard);
1387   hrtime_t reqt = gethrtime ();
1388   fd = CALL_REAL (creat)(path, mode);
1389   if (RECHCK_REENTRANCE (guard))
1390     {
1391       POP_REENTRANCE (guard);
1392       return fd;
1393     }
1394   hrtime_t grnt = gethrtime ();
1395   sz = collector_strlen (path);
1396   pktSize = sizeof (IOTrace_packet) + sz;
1397   pktSize = collector_align_pktsize (pktSize);
1398   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1399   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1400   if (packet != NULL)
1401     {
1402       iopkt = (IOTrace_packet *) packet;
1403       collector_memset (iopkt, 0, pktSize);
1404       iopkt->comm.tsize = pktSize;
1405       iopkt->comm.tstamp = grnt;
1406       iopkt->requested = reqt;
1407       if (fd != -1)
1408 	iopkt->iotype = OPEN_TRACE;
1409       else
1410 	iopkt->iotype = OPEN_TRACE_ERROR;
1411       iopkt->fd = fd;
1412       iopkt->fstype = collector_fstype (path);
1413       collector_strncpy (&(iopkt->fname), path, sz);
1414       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1415       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1416       collector_interface->freeCSize (io_heap, packet, pktSize);
1417     }
1418   else
1419     {
1420       Tprintf (0, "iotrace: ERROR: creat cannot allocate memory\n");
1421       return -1;
1422     }
1423   POP_REENTRANCE (guard);
1424   return fd;
1425 }
1426 
1427 /*------------------------------------------------------------- creat64 */
1428 #if WSIZE(32)
1429 int
1430 creat64 (const char *path, mode_t mode)
1431 {
1432   int *guard;
1433   int fd;
1434   void *packet;
1435   IOTrace_packet *iopkt;
1436   size_t sz;
1437   unsigned pktSize;
1438 
1439   if (NULL_PTR (creat64))
1440     init_io_intf ();
1441   if (CHCK_REENTRANCE (guard) || path == NULL)
1442     return CALL_REAL (creat64)(path, mode);
1443   PUSH_REENTRANCE (guard);
1444   hrtime_t reqt = gethrtime ();
1445   fd = CALL_REAL (creat64)(path, mode);
1446   if (RECHCK_REENTRANCE (guard))
1447     {
1448       POP_REENTRANCE (guard);
1449       return fd;
1450     }
1451   hrtime_t grnt = gethrtime ();
1452   sz = collector_strlen (path);
1453   pktSize = sizeof (IOTrace_packet) + sz;
1454   pktSize = collector_align_pktsize (pktSize);
1455   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1456   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1457   if (packet != NULL)
1458     {
1459       iopkt = (IOTrace_packet *) packet;
1460       collector_memset (iopkt, 0, pktSize);
1461       iopkt->comm.tsize = pktSize;
1462       iopkt->comm.tstamp = grnt;
1463       iopkt->requested = reqt;
1464       if (fd != -1)
1465 	iopkt->iotype = OPEN_TRACE;
1466       else
1467 	iopkt->iotype = OPEN_TRACE_ERROR;
1468       iopkt->fd = fd;
1469       iopkt->fstype = collector_fstype (path);
1470       collector_strncpy (&(iopkt->fname), path, sz);
1471       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1472       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1473       collector_interface->freeCSize (io_heap, packet, pktSize);
1474     }
1475   else
1476     {
1477       Tprintf (0, "iotrace: ERROR: creat64 cannot allocate memory\n");
1478       return -1;
1479     }
1480   POP_REENTRANCE (guard);
1481   return fd;
1482 }
1483 #endif
1484 
1485 /*------------------------------------------------------------- mkstemp */
1486 int
1487 mkstemp (char *template)
1488 {
1489   int *guard;
1490   int fd;
1491   void *packet;
1492   IOTrace_packet *iopkt;
1493   size_t sz;
1494   unsigned pktSize;
1495   if (NULL_PTR (mkstemp))
1496     init_io_intf ();
1497   if (CHCK_REENTRANCE (guard) || template == NULL)
1498     return CALL_REAL (mkstemp)(template);
1499   PUSH_REENTRANCE (guard);
1500   hrtime_t reqt = gethrtime ();
1501   fd = CALL_REAL (mkstemp)(template);
1502   if (RECHCK_REENTRANCE (guard))
1503     {
1504       POP_REENTRANCE (guard);
1505       return fd;
1506     }
1507   hrtime_t grnt = gethrtime ();
1508   sz = collector_strlen (template);
1509   pktSize = sizeof (IOTrace_packet) + sz;
1510   pktSize = collector_align_pktsize (pktSize);
1511   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1512   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1513   if (packet != NULL)
1514     {
1515       iopkt = (IOTrace_packet *) packet;
1516       collector_memset (iopkt, 0, pktSize);
1517       iopkt->comm.tsize = pktSize;
1518       iopkt->comm.tstamp = grnt;
1519       iopkt->requested = reqt;
1520       if (fd != -1)
1521 	iopkt->iotype = OPEN_TRACE;
1522       else
1523 	iopkt->iotype = OPEN_TRACE_ERROR;
1524       iopkt->fd = fd;
1525       iopkt->fstype = collector_fstype (template);
1526       collector_strncpy (&(iopkt->fname), template, sz);
1527       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1528       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1529       collector_interface->freeCSize (io_heap, packet, pktSize);
1530     }
1531   else
1532     {
1533       Tprintf (0, "iotrace: ERROR: mkstemp cannot allocate memory\n");
1534       return -1;
1535     }
1536   POP_REENTRANCE (guard);
1537   return fd;
1538 }
1539 
1540 /*------------------------------------------------------------- mkstemps */
1541 int
1542 mkstemps (char *template, int slen)
1543 {
1544   int *guard;
1545   int fd;
1546   void *packet;
1547   IOTrace_packet *iopkt;
1548   size_t sz;
1549   unsigned pktSize;
1550   if (NULL_PTR (mkstemps))
1551     init_io_intf ();
1552   if (CHCK_REENTRANCE (guard) || template == NULL)
1553     return CALL_REAL (mkstemps)(template, slen);
1554   PUSH_REENTRANCE (guard);
1555   hrtime_t reqt = gethrtime ();
1556   fd = CALL_REAL (mkstemps)(template, slen);
1557   if (RECHCK_REENTRANCE (guard))
1558     {
1559       POP_REENTRANCE (guard);
1560       return fd;
1561     }
1562   hrtime_t grnt = gethrtime ();
1563   sz = collector_strlen (template);
1564   pktSize = sizeof (IOTrace_packet) + sz;
1565   pktSize = collector_align_pktsize (pktSize);
1566   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1567   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1568   if (packet != NULL)
1569     {
1570       iopkt = (IOTrace_packet *) packet;
1571       collector_memset (iopkt, 0, pktSize);
1572       iopkt->comm.tsize = pktSize;
1573       iopkt->comm.tstamp = grnt;
1574       iopkt->requested = reqt;
1575       if (fd != -1)
1576 	iopkt->iotype = OPEN_TRACE;
1577       else
1578 	iopkt->iotype = OPEN_TRACE_ERROR;
1579       iopkt->fd = fd;
1580       iopkt->fstype = collector_fstype (template);
1581       collector_strncpy (&(iopkt->fname), template, sz);
1582       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1583       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1584       collector_interface->freeCSize (io_heap, packet, pktSize);
1585     }
1586   else
1587     {
1588       Tprintf (0, "iotrace: ERROR: mkstemps cannot allocate memory\n");
1589       return -1;
1590     }
1591   POP_REENTRANCE (guard);
1592   return fd;
1593 }
1594 
1595 /*------------------------------------------------------------- close */
1596 int
1597 close (int fildes)
1598 {
1599   int *guard;
1600   int stat;
1601   IOTrace_packet iopkt;
1602   if (NULL_PTR (close))
1603     init_io_intf ();
1604   if (CHCK_REENTRANCE (guard))
1605     return CALL_REAL (close)(fildes);
1606   PUSH_REENTRANCE (guard);
1607   hrtime_t reqt = gethrtime ();
1608   stat = CALL_REAL (close)(fildes);
1609   if (RECHCK_REENTRANCE (guard))
1610     {
1611       POP_REENTRANCE (guard);
1612       return stat;
1613     }
1614   hrtime_t grnt = gethrtime ();
1615   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1616   iopkt.comm.tsize = sizeof (IOTrace_packet);
1617   iopkt.comm.tstamp = grnt;
1618   iopkt.requested = reqt;
1619   if (stat == 0)
1620     iopkt.iotype = CLOSE_TRACE;
1621   else
1622     iopkt.iotype = CLOSE_TRACE_ERROR;
1623   iopkt.fd = fildes;
1624   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1625   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1626   POP_REENTRANCE (guard);
1627   return stat;
1628 }
1629 
1630 /*------------------------------------------------------------- fopen */
1631 // map interposed symbol versions
1632 #if ARCH(Intel) && WSIZE(32)
1633 
1634 static FILE*
1635 __collector_fopen_symver (FILE*(real_fopen) (), const char *filename, const char *mode);
1636 
1637 SYMVER_ATTRIBUTE (__collector_fopen_2_1, fopen@@GLIBC_2.1)
1638 FILE*
1639 __collector_fopen_2_1 (const char *filename, const char *mode)
1640 {
1641   if (NULL_PTR (fopen))
1642     init_io_intf ();
1643   TprintfT (DBG_LTT, "iotrace: __collector_fopen_2_1@%p\n", CALL_REAL (fopen_2_1));
1644   return __collector_fopen_symver (CALL_REAL (fopen_2_1), filename, mode);
1645 }
1646 
1647 SYMVER_ATTRIBUTE (__collector_fopen_2_0, fopen@GLIBC_2.0)
1648 FILE*
1649 __collector_fopen_2_0 (const char *filename, const char *mode)
1650 {
1651   if (NULL_PTR (fopen))
1652     init_io_intf ();
1653   TprintfT (DBG_LTT, "iotrace: __collector_fopen_2_0@%p\n", CALL_REAL (fopen_2_0));
1654   return __collector_fopen_symver (CALL_REAL (fopen_2_0), filename, mode);
1655 }
1656 
1657 #endif
1658 
1659 #if ARCH(Intel) && WSIZE(32)
1660 
1661 static FILE*
1662 __collector_fopen_symver (FILE*(real_fopen) (), const char *filename, const char *mode)
1663 {
1664 #else
1665 
1666 FILE*
1667 fopen (const char *filename, const char *mode)
1668 {
1669 #endif
1670   int *guard;
1671   FILE *fp = NULL;
1672   void *packet;
1673   IOTrace_packet *iopkt;
1674   size_t sz;
1675   unsigned pktSize;
1676   if (NULL_PTR (fopen))
1677     init_io_intf ();
1678   if (CHCK_REENTRANCE (guard) || filename == NULL)
1679     {
1680 #if ARCH(Intel) && WSIZE(32)
1681       return (real_fopen) (filename, mode);
1682 #else
1683       return CALL_REAL (fopen)(filename, mode);
1684 #endif
1685     }
1686   PUSH_REENTRANCE (guard);
1687   hrtime_t reqt = gethrtime ();
1688 
1689 #if ARCH(Intel) && WSIZE(32)
1690   fp = (real_fopen) (filename, mode);
1691 #else
1692   fp = CALL_REAL (fopen)(filename, mode);
1693 #endif
1694   if (RECHCK_REENTRANCE (guard))
1695     {
1696       POP_REENTRANCE (guard);
1697       return fp;
1698     }
1699   hrtime_t grnt = gethrtime ();
1700   sz = collector_strlen (filename);
1701   pktSize = sizeof (IOTrace_packet) + sz;
1702   pktSize = collector_align_pktsize (pktSize);
1703   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1704   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1705   if (packet != NULL)
1706     {
1707       iopkt = (IOTrace_packet *) packet;
1708       collector_memset (iopkt, 0, pktSize);
1709       iopkt->comm.tsize = pktSize;
1710       iopkt->comm.tstamp = grnt;
1711       iopkt->requested = reqt;
1712       if (fp != NULL)
1713 	{
1714 	  iopkt->iotype = OPEN_TRACE;
1715 	  iopkt->fd = fileno (fp);
1716 	}
1717       else
1718 	{
1719 	  iopkt->iotype = OPEN_TRACE_ERROR;
1720 	  iopkt->fd = -1;
1721 	}
1722       iopkt->fstype = collector_fstype (filename);
1723       collector_strncpy (&(iopkt->fname), filename, sz);
1724 
1725 #if ARCH(Intel) && WSIZE(32)
1726       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
1727 #else
1728       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1729 #endif
1730       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1731       collector_interface->freeCSize (io_heap, packet, pktSize);
1732     }
1733   else
1734     {
1735       Tprintf (0, "iotrace: ERROR: fopen cannot allocate memory\n");
1736       return NULL;
1737     }
1738   POP_REENTRANCE (guard);
1739   return fp;
1740 }
1741 
1742 /*------------------------------------------------------------- fclose */
1743 // map interposed symbol versions
1744 #if ARCH(Intel) && WSIZE(32)
1745 
1746 static int
1747 __collector_fclose_symver (int(real_fclose) (), FILE *stream);
1748 
1749 SYMVER_ATTRIBUTE (__collector_fclose_2_1, fclose@@GLIBC_2.1)
1750 int
1751 __collector_fclose_2_1 (FILE *stream)
1752 {
1753   if (NULL_PTR (fclose))
1754     init_io_intf ();
1755   TprintfT (DBG_LTT, "iotrace: __collector_fclose_2_1@%p\n", CALL_REAL (fclose_2_1));
1756   return __collector_fclose_symver (CALL_REAL (fclose_2_1), stream);
1757 }
1758 
1759 SYMVER_ATTRIBUTE (__collector_fclose_2_0, fclose@GLIBC_2.0)
1760 int
1761 __collector_fclose_2_0 (FILE *stream)
1762 {
1763   if (NULL_PTR (fclose))
1764     init_io_intf ();
1765   TprintfT (DBG_LTT, "iotrace: __collector_fclose_2_0@%p\n", CALL_REAL (fclose_2_0));
1766   return __collector_fclose_symver (CALL_REAL (fclose_2_0), stream);
1767 }
1768 
1769 #endif
1770 
1771 #if ARCH(Intel) && WSIZE(32)
1772 
1773 static int
1774 __collector_fclose_symver (int(real_fclose) (), FILE *stream)
1775 {
1776 #else
1777 
1778 int
1779 fclose (FILE *stream)
1780 {
1781 #endif
1782   int *guard;
1783   int stat;
1784   IOTrace_packet iopkt;
1785   if (NULL_PTR (fclose))
1786     init_io_intf ();
1787   if (CHCK_REENTRANCE (guard) || stream == NULL)
1788     {
1789 #if ARCH(Intel) && WSIZE(32)
1790       return (real_fclose) (stream);
1791 #else
1792       return CALL_REAL (fclose)(stream);
1793 #endif
1794     }
1795   PUSH_REENTRANCE (guard);
1796   hrtime_t reqt = gethrtime ();
1797 #if ARCH(Intel) && WSIZE(32)
1798   stat = (real_fclose) (stream);
1799 #else
1800   stat = CALL_REAL (fclose)(stream);
1801 #endif
1802   if (RECHCK_REENTRANCE (guard))
1803     {
1804       POP_REENTRANCE (guard);
1805       return stat;
1806     }
1807   hrtime_t grnt = gethrtime ();
1808   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1809   iopkt.comm.tsize = sizeof (IOTrace_packet);
1810   iopkt.comm.tstamp = grnt;
1811   iopkt.requested = reqt;
1812   if (stat == 0)
1813     iopkt.iotype = CLOSE_TRACE;
1814   else
1815     iopkt.iotype = CLOSE_TRACE_ERROR;
1816   iopkt.fd = fileno (stream);
1817 
1818 #if ARCH(Intel) && WSIZE(32)
1819   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
1820 #else
1821   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1822 #endif
1823   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1824   POP_REENTRANCE (guard);
1825   return stat;
1826 }
1827 
1828 /*------------------------------------------------------------- fflush */
1829 int
1830 fflush (FILE *stream)
1831 {
1832   int *guard;
1833   int stat;
1834   IOTrace_packet iopkt;
1835   if (NULL_PTR (fflush))
1836     init_io_intf ();
1837   if (CHCK_REENTRANCE (guard))
1838     return CALL_REAL (fflush)(stream);
1839   PUSH_REENTRANCE (guard);
1840   hrtime_t reqt = gethrtime ();
1841   stat = CALL_REAL (fflush)(stream);
1842   if (RECHCK_REENTRANCE (guard))
1843     {
1844       POP_REENTRANCE (guard);
1845       return stat;
1846     }
1847   hrtime_t grnt = gethrtime ();
1848   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1849   iopkt.comm.tsize = sizeof (IOTrace_packet);
1850   iopkt.comm.tstamp = grnt;
1851   iopkt.requested = reqt;
1852   if (stat == 0)
1853     iopkt.iotype = OTHERIO_TRACE;
1854   else
1855     iopkt.iotype = OTHERIO_TRACE_ERROR;
1856   if (stream != NULL)
1857     iopkt.fd = fileno (stream);
1858   else
1859     iopkt.fd = -1;
1860   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1861   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1862   POP_REENTRANCE (guard);
1863   return stat;
1864 }
1865 
1866 /*------------------------------------------------------------- fdopen */
1867 // map interposed symbol versions
1868 #if ARCH(Intel) && WSIZE(32)
1869 
1870 static FILE*
1871 __collector_fdopen_symver (FILE*(real_fdopen) (), int fildes, const char *mode);
1872 
1873 SYMVER_ATTRIBUTE (__collector_fdopen_2_1, fdopen@@GLIBC_2.1)
1874 FILE*
1875 __collector_fdopen_2_1 (int fildes, const char *mode)
1876 {
1877   if (NULL_PTR (fdopen))
1878     init_io_intf ();
1879   TprintfT (DBG_LTT, "iotrace: __collector_fdopen_2_1@%p\n", CALL_REAL (fdopen_2_1));
1880   return __collector_fdopen_symver (CALL_REAL (fdopen_2_1), fildes, mode);
1881 }
1882 
1883 SYMVER_ATTRIBUTE (__collector_fdopen_2_0, fdopen@GLIBC_2.0)
1884 FILE*
1885 __collector_fdopen_2_0 (int fildes, const char *mode)
1886 {
1887   if (NULL_PTR (fdopen))
1888     init_io_intf ();
1889   TprintfT (DBG_LTT, "iotrace: __collector_fdopen_2_0@%p\n", CALL_REAL (fdopen_2_0));
1890   return __collector_fdopen_symver (CALL_REAL (fdopen_2_0), fildes, mode);
1891 }
1892 
1893 #endif
1894 
1895 #if ARCH(Intel) && WSIZE(32)
1896 static FILE*
1897 __collector_fdopen_symver (FILE*(real_fdopen) (), int fildes, const char *mode)
1898 {
1899 #else
1900 FILE*
1901 fdopen (int fildes, const char *mode)
1902 {
1903 #endif
1904   int *guard;
1905   FILE *fp = NULL;
1906   IOTrace_packet iopkt;
1907   if (NULL_PTR (fdopen))
1908     init_io_intf ();
1909   if (CHCK_REENTRANCE (guard))
1910     {
1911 #if ARCH(Intel) && WSIZE(32)
1912       return (real_fdopen) (fildes, mode);
1913 #else
1914       return CALL_REAL (fdopen)(fildes, mode);
1915 #endif
1916     }
1917   PUSH_REENTRANCE (guard);
1918   hrtime_t reqt = gethrtime ();
1919 #if ARCH(Intel) && WSIZE(32)
1920   fp = (real_fdopen) (fildes, mode);
1921 #else
1922   fp = CALL_REAL (fdopen)(fildes, mode);
1923 #endif
1924   if (RECHCK_REENTRANCE (guard))
1925     {
1926       POP_REENTRANCE (guard);
1927       return fp;
1928     }
1929   hrtime_t grnt = gethrtime ();
1930   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1931   iopkt.comm.tsize = sizeof (IOTrace_packet);
1932   iopkt.comm.tstamp = grnt;
1933   iopkt.requested = reqt;
1934   if (fp != NULL)
1935     iopkt.iotype = OPEN_TRACE;
1936   else
1937     iopkt.iotype = OPEN_TRACE_ERROR;
1938   iopkt.fd = fildes;
1939   iopkt.fstype = UNKNOWNFS_TYPE;
1940 #if ARCH(Intel) && WSIZE(32)
1941   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
1942 #else
1943   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1944 #endif
1945   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1946   POP_REENTRANCE (guard);
1947   return fp;
1948 }
1949 
1950 /*------------------------------------------------------------- dup */
1951 int
1952 dup (int fildes)
1953 {
1954   int *guard;
1955   int fd;
1956   IOTrace_packet iopkt;
1957   if (NULL_PTR (dup))
1958     init_io_intf ();
1959   if (CHCK_REENTRANCE (guard))
1960     return CALL_REAL (dup)(fildes);
1961   PUSH_REENTRANCE (guard);
1962   hrtime_t reqt = gethrtime ();
1963   fd = CALL_REAL (dup)(fildes);
1964   if (RECHCK_REENTRANCE (guard))
1965     {
1966       POP_REENTRANCE (guard);
1967       return fd;
1968     }
1969   hrtime_t grnt = gethrtime ();
1970   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1971   iopkt.comm.tsize = sizeof (IOTrace_packet);
1972   iopkt.comm.tstamp = grnt;
1973   iopkt.requested = reqt;
1974   if (fd != -1)
1975     iopkt.iotype = OPEN_TRACE;
1976   else
1977     iopkt.iotype = OPEN_TRACE_ERROR;
1978 
1979   iopkt.fd = fd;
1980   iopkt.ofd = fildes;
1981   iopkt.fstype = UNKNOWNFS_TYPE;
1982   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1983   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1984   POP_REENTRANCE (guard);
1985   return fd;
1986 }
1987 
1988 /*------------------------------------------------------------- dup2 */
1989 int
1990 dup2 (int fildes, int fildes2)
1991 {
1992   int *guard;
1993   int fd;
1994   IOTrace_packet iopkt;
1995   if (NULL_PTR (dup2))
1996     init_io_intf ();
1997   if (CHCK_REENTRANCE (guard))
1998     return CALL_REAL (dup2)(fildes, fildes2);
1999   PUSH_REENTRANCE (guard);
2000   hrtime_t reqt = gethrtime ();
2001   fd = CALL_REAL (dup2)(fildes, fildes2);
2002   if (RECHCK_REENTRANCE (guard))
2003     {
2004       POP_REENTRANCE (guard);
2005       return fd;
2006     }
2007   hrtime_t grnt = gethrtime ();
2008   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2009   iopkt.comm.tsize = sizeof (IOTrace_packet);
2010   iopkt.comm.tstamp = grnt;
2011   iopkt.requested = reqt;
2012   if (fd != -1)
2013     iopkt.iotype = OPEN_TRACE;
2014   else
2015     iopkt.iotype = OPEN_TRACE_ERROR;
2016   iopkt.fd = fd;
2017   iopkt.ofd = fildes;
2018   iopkt.fstype = UNKNOWNFS_TYPE;
2019   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2020   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2021   POP_REENTRANCE (guard);
2022   return fd;
2023 }
2024 
2025 /*------------------------------------------------------------- pipe */
2026 int
2027 pipe (int fildes[2])
2028 {
2029   int *guard;
2030   int ret;
2031   IOTrace_packet iopkt;
2032   if (NULL_PTR (pipe))
2033     init_io_intf ();
2034   if (CHCK_REENTRANCE (guard))
2035     return CALL_REAL (pipe)(fildes);
2036   PUSH_REENTRANCE (guard);
2037   hrtime_t reqt = gethrtime ();
2038   ret = CALL_REAL (pipe)(fildes);
2039   if (RECHCK_REENTRANCE (guard))
2040     {
2041       POP_REENTRANCE (guard);
2042       return ret;
2043     }
2044   hrtime_t grnt = gethrtime ();
2045   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2046   iopkt.comm.tsize = sizeof (IOTrace_packet);
2047   iopkt.comm.tstamp = grnt;
2048   iopkt.requested = reqt;
2049   if (ret != -1)
2050     iopkt.iotype = OPEN_TRACE;
2051   else
2052     iopkt.iotype = OPEN_TRACE_ERROR;
2053   iopkt.fd = fildes[0];
2054   iopkt.fstype = UNKNOWNFS_TYPE;
2055   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2056   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2057   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2058   iopkt.comm.tsize = sizeof (IOTrace_packet);
2059   iopkt.comm.tstamp = grnt;
2060   iopkt.requested = reqt;
2061   if (ret != -1)
2062     iopkt.iotype = OPEN_TRACE;
2063   else
2064     iopkt.iotype = OPEN_TRACE_ERROR;
2065   iopkt.fd = fildes[1];
2066   iopkt.fstype = UNKNOWNFS_TYPE;
2067   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2068   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2069   POP_REENTRANCE (guard);
2070   return ret;
2071 }
2072 
2073 /*------------------------------------------------------------- socket */
2074 int
2075 socket (int domain, int type, int protocol)
2076 {
2077   int *guard;
2078   int fd;
2079   IOTrace_packet iopkt;
2080   if (NULL_PTR (socket))
2081     init_io_intf ();
2082   if (CHCK_REENTRANCE (guard))
2083     return CALL_REAL (socket)(domain, type, protocol);
2084   PUSH_REENTRANCE (guard);
2085   hrtime_t reqt = gethrtime ();
2086   fd = CALL_REAL (socket)(domain, type, protocol);
2087   if (RECHCK_REENTRANCE (guard))
2088     {
2089       POP_REENTRANCE (guard);
2090       return fd;
2091     }
2092   hrtime_t grnt = gethrtime ();
2093   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2094   iopkt.comm.tsize = sizeof (IOTrace_packet);
2095   iopkt.comm.tstamp = grnt;
2096   iopkt.requested = reqt;
2097   if (fd != -1)
2098     iopkt.iotype = OPEN_TRACE;
2099   else
2100     iopkt.iotype = OPEN_TRACE_ERROR;
2101   iopkt.fd = fd;
2102   iopkt.fstype = UNKNOWNFS_TYPE;
2103   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2104   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2105   POP_REENTRANCE (guard);
2106   return fd;
2107 }
2108 
2109 /*------------------------------------------------------------- read */
2110 ssize_t
2111 read (int fildes, void *buf, size_t nbyte)
2112 {
2113   int *guard;
2114   ssize_t ret;
2115   IOTrace_packet iopkt;
2116   if (NULL_PTR (read))
2117     init_io_intf ();
2118   if (CHCK_REENTRANCE (guard))
2119     return CALL_REAL (read)(fildes, buf, nbyte);
2120   PUSH_REENTRANCE (guard);
2121   hrtime_t reqt = gethrtime ();
2122   ret = CALL_REAL (read)(fildes, buf, nbyte);
2123   if (RECHCK_REENTRANCE (guard))
2124     {
2125       POP_REENTRANCE (guard);
2126       return ret;
2127     }
2128   hrtime_t grnt = gethrtime ();
2129   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2130   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2131   iopkt.comm.tstamp = grnt;
2132   iopkt.requested = reqt;
2133   if (ret >= 0)
2134     iopkt.iotype = READ_TRACE;
2135   else
2136     iopkt.iotype = READ_TRACE_ERROR;
2137   iopkt.fd = fildes;
2138   iopkt.nbyte = ret;
2139   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2140   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2141   POP_REENTRANCE (guard);
2142   return ret;
2143 }
2144 
2145 /*------------------------------------------------------------- write */
2146 ssize_t
2147 write (int fildes, const void *buf, size_t nbyte)
2148 {
2149   int *guard;
2150   ssize_t ret;
2151   IOTrace_packet iopkt;
2152   if (NULL_PTR (write))
2153     init_io_intf ();
2154   if (CHCK_REENTRANCE (guard))
2155     return CALL_REAL (write)(fildes, buf, nbyte);
2156   PUSH_REENTRANCE (guard);
2157   hrtime_t reqt = gethrtime ();
2158   ret = CALL_REAL (write)(fildes, buf, nbyte);
2159   if (RECHCK_REENTRANCE (guard))
2160     {
2161       POP_REENTRANCE (guard);
2162       return ret;
2163     }
2164   hrtime_t grnt = gethrtime ();
2165   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2166   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2167   iopkt.comm.tstamp = grnt;
2168   iopkt.requested = reqt;
2169   if (ret >= 0)
2170     iopkt.iotype = WRITE_TRACE;
2171   else
2172     iopkt.iotype = WRITE_TRACE_ERROR;
2173   iopkt.fd = fildes;
2174   iopkt.nbyte = ret;
2175   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2176   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2177   POP_REENTRANCE (guard);
2178   return ret;
2179 }
2180 
2181 /*------------------------------------------------------------- readv */
2182 ssize_t
2183 readv (int fildes, const struct iovec *iov, int iovcnt)
2184 {
2185   int *guard;
2186   ssize_t ret;
2187   IOTrace_packet iopkt;
2188   if (NULL_PTR (readv))
2189     init_io_intf ();
2190   if (CHCK_REENTRANCE (guard))
2191     return CALL_REAL (readv)(fildes, iov, iovcnt);
2192   PUSH_REENTRANCE (guard);
2193   hrtime_t reqt = gethrtime ();
2194   ret = CALL_REAL (readv)(fildes, iov, iovcnt);
2195   if (RECHCK_REENTRANCE (guard))
2196     {
2197       POP_REENTRANCE (guard);
2198       return ret;
2199     }
2200   hrtime_t grnt = gethrtime ();
2201   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2202   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2203   iopkt.comm.tstamp = grnt;
2204   iopkt.requested = reqt;
2205   if (ret >= 0)
2206     iopkt.iotype = READ_TRACE;
2207   else
2208     iopkt.iotype = READ_TRACE_ERROR;
2209   iopkt.fd = fildes;
2210   iopkt.nbyte = ret;
2211   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2212   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2213   POP_REENTRANCE (guard);
2214   return ret;
2215 }
2216 
2217 /*------------------------------------------------------------- writev */
2218 ssize_t
2219 writev (int fildes, const struct iovec *iov, int iovcnt)
2220 {
2221   int *guard;
2222   ssize_t ret;
2223   IOTrace_packet iopkt;
2224   if (NULL_PTR (writev))
2225     init_io_intf ();
2226   if (CHCK_REENTRANCE (guard))
2227     return CALL_REAL (writev)(fildes, iov, iovcnt);
2228   PUSH_REENTRANCE (guard);
2229   hrtime_t reqt = gethrtime ();
2230   ret = CALL_REAL (writev)(fildes, iov, iovcnt);
2231   if (RECHCK_REENTRANCE (guard))
2232     {
2233       POP_REENTRANCE (guard);
2234       return ret;
2235     }
2236   hrtime_t grnt = gethrtime ();
2237   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2238   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2239   iopkt.comm.tstamp = grnt;
2240   iopkt.requested = reqt;
2241   if (ret >= 0)
2242     iopkt.iotype = WRITE_TRACE;
2243   else
2244     iopkt.iotype = WRITE_TRACE_ERROR;
2245   iopkt.fd = fildes;
2246   iopkt.nbyte = ret;
2247   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2248   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2249   POP_REENTRANCE (guard);
2250   return ret;
2251 }
2252 
2253 /*------------------------------------------------------------- fread */
2254 size_t
2255 fread (void *ptr, size_t size, size_t nitems, FILE *stream)
2256 {
2257   int *guard;
2258   size_t ret;
2259   IOTrace_packet iopkt;
2260   if (NULL_PTR (fread))
2261     init_io_intf ();
2262   if (CHCK_REENTRANCE (guard) || stream == NULL)
2263     return CALL_REAL (fread)(ptr, size, nitems, stream);
2264   PUSH_REENTRANCE (guard);
2265   hrtime_t reqt = gethrtime ();
2266   ret = CALL_REAL (fread)(ptr, size, nitems, stream);
2267   if (RECHCK_REENTRANCE (guard))
2268     {
2269       POP_REENTRANCE (guard);
2270       return ret;
2271     }
2272   hrtime_t grnt = gethrtime ();
2273   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2274   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2275   iopkt.comm.tstamp = grnt;
2276   iopkt.requested = reqt;
2277   if (ferror (stream) == 0)
2278     {
2279       iopkt.iotype = READ_TRACE;
2280       iopkt.nbyte = ret * size;
2281     }
2282   else
2283     {
2284       iopkt.iotype = READ_TRACE_ERROR;
2285       iopkt.nbyte = 0;
2286     }
2287   iopkt.fd = fileno (stream);
2288   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2289   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2290   POP_REENTRANCE (guard);
2291   return ret;
2292 }
2293 
2294 /*------------------------------------------------------------- fwrite */
2295 size_t
2296 fwrite (const void *ptr, size_t size, size_t nitems, FILE *stream)
2297 {
2298   int *guard;
2299   size_t ret;
2300   IOTrace_packet iopkt;
2301   if (NULL_PTR (fwrite))
2302     init_io_intf ();
2303   if (CHCK_REENTRANCE (guard) || stream == NULL)
2304     return CALL_REAL (fwrite)(ptr, size, nitems, stream);
2305   PUSH_REENTRANCE (guard);
2306   hrtime_t reqt = gethrtime ();
2307   ret = CALL_REAL (fwrite)(ptr, size, nitems, stream);
2308   if (RECHCK_REENTRANCE (guard))
2309     {
2310       POP_REENTRANCE (guard);
2311       return ret;
2312     }
2313   hrtime_t grnt = gethrtime ();
2314   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2315   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2316   iopkt.comm.tstamp = grnt;
2317   iopkt.requested = reqt;
2318   if (ferror (stream) == 0)
2319     {
2320       iopkt.iotype = WRITE_TRACE;
2321       iopkt.nbyte = ret * size;
2322     }
2323   else
2324     {
2325       iopkt.iotype = WRITE_TRACE_ERROR;
2326       iopkt.nbyte = 0;
2327     }
2328   iopkt.fd = fileno (stream);
2329   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2330   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2331   POP_REENTRANCE (guard);
2332   return ret;
2333 }
2334 
2335 /*------------------------------------------------------------- pread */
2336 #if ARCH(Intel) && WSIZE(32)
2337 // map interposed symbol versions
2338 static int
2339 __collector_pread_symver (int(real_pread) (), int fildes, void *buf, size_t nbyte, off_t offset);
2340 
2341 SYMVER_ATTRIBUTE (__collector_pread_2_2, pread@@GLIBC_2.2)
2342 int
2343 __collector_pread_2_2 (int fildes, void *buf, size_t nbyte, off_t offset)
2344 {
2345   TprintfT (DBG_LTT, "iotrace: __collector_pread_2_2@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
2346 	    CALL_REAL (pread_2_2), fildes, buf, (long long) nbyte, (long long) offset);
2347   if (NULL_PTR (pread))
2348     init_io_intf ();
2349   return __collector_pread_symver (CALL_REAL (pread_2_2), fildes, buf, nbyte, offset);
2350 }
2351 
2352 SYMVER_ATTRIBUTE (__collector_pread_2_1, pread@GLIBC_2.1)
2353 int
2354 __collector_pread_2_1 (int fildes, void *buf, size_t nbyte, off_t offset)
2355 {
2356   TprintfT (DBG_LTT, "iotrace: __collector_pread_2_1@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
2357 	    CALL_REAL (pread_2_1), fildes, buf, (long long) nbyte, (long long) offset);
2358   if (NULL_PTR (pread))
2359     init_io_intf ();
2360   return __collector_pread_symver (CALL_REAL (pread_2_1), fildes, buf, nbyte, offset);
2361 }
2362 
2363 static int
2364 __collector_pread_symver (int(real_pread) (), int fildes, void *buf, size_t nbyte, off_t offset)
2365 {
2366 #else /* ^ARCH(Intel) && WSIZE(32) */
2367 
2368 ssize_t
2369 pread (int fildes, void *buf, size_t nbyte, off_t offset)
2370 {
2371 #endif
2372   int *guard;
2373   ssize_t ret;
2374   IOTrace_packet iopkt;
2375   if (NULL_PTR (pread))
2376     init_io_intf ();
2377   if (CHCK_REENTRANCE (guard))
2378     {
2379 #if ARCH(Intel) && WSIZE(32)
2380       return (real_pread) (fildes, buf, nbyte, offset);
2381 #else
2382       return CALL_REAL (pread)(fildes, buf, nbyte, offset);
2383 #endif
2384     }
2385   PUSH_REENTRANCE (guard);
2386   hrtime_t reqt = gethrtime ();
2387 #if ARCH(Intel) && WSIZE(32)
2388   ret = (real_pread) (fildes, buf, nbyte, offset);
2389 #else
2390   ret = CALL_REAL (pread)(fildes, buf, nbyte, offset);
2391 #endif
2392   if (RECHCK_REENTRANCE (guard))
2393     {
2394       POP_REENTRANCE (guard);
2395       return ret;
2396     }
2397   hrtime_t grnt = gethrtime ();
2398   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2399   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2400   iopkt.comm.tstamp = grnt;
2401   iopkt.requested = reqt;
2402   if (ret >= 0)
2403     iopkt.iotype = READ_TRACE;
2404   else
2405     iopkt.iotype = READ_TRACE_ERROR;
2406   iopkt.fd = fildes;
2407   iopkt.nbyte = ret;
2408   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2409   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2410   POP_REENTRANCE (guard);
2411   return ret;
2412 }
2413 
2414 /*------------------------------------------------------------- pwrite */
2415 #if ARCH(Intel) && WSIZE(32)
2416 // map interposed symbol versions
2417 static int
2418 __collector_pwrite_symver (int(real_pwrite) (), int fildes, const void *buf, size_t nbyte, off_t offset);
2419 
2420 SYMVER_ATTRIBUTE (__collector_pwrite_2_2, pwrite@@GLIBC_2.2)
2421 int
2422 __collector_pwrite_2_2 (int fildes, const void *buf, size_t nbyte, off_t offset)
2423 {
2424   TprintfT (DBG_LTT, "iotrace: __collector_pwrite_2_2@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
2425 	    CALL_REAL (pwrite_2_2), fildes, buf, (long long) nbyte, (long long) offset);
2426   if (NULL_PTR (pwrite))
2427     init_io_intf ();
2428   return __collector_pwrite_symver (CALL_REAL (pwrite_2_2), fildes, buf, nbyte, offset);
2429 }
2430 
2431 SYMVER_ATTRIBUTE (__collector_pwrite_2_1, pwrite@GLIBC_2.1)
2432 int
2433 __collector_pwrite_2_1 (int fildes, const void *buf, size_t nbyte, off_t offset)
2434 {
2435   TprintfT (DBG_LTT, "iotrace: __collector_pwrite_2_1@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
2436 	    CALL_REAL (pwrite_2_1), fildes, buf, (long long) nbyte, (long long) offset);
2437   if (NULL_PTR (pwrite))
2438     init_io_intf ();
2439   return __collector_pwrite_symver (CALL_REAL (pwrite_2_1), fildes, buf, nbyte, offset);
2440 }
2441 
2442 static int
2443 __collector_pwrite_symver (int(real_pwrite) (), int fildes, const void *buf, size_t nbyte, off_t offset)
2444 {
2445 #else /* ^ARCH(Intel) && WSIZE(32) */
2446 
2447 ssize_t
2448 pwrite (int fildes, const void *buf, size_t nbyte, off_t offset)
2449 {
2450 #endif /* ^ARCH(Intel) && WSIZE(32) */
2451   int *guard;
2452   ssize_t ret;
2453   IOTrace_packet iopkt;
2454   if (NULL_PTR (pwrite))
2455     init_io_intf ();
2456   if (CHCK_REENTRANCE (guard))
2457     {
2458 #if ARCH(Intel) && WSIZE(32)
2459       return (real_pwrite) (fildes, buf, nbyte, offset);
2460 #else
2461       return CALL_REAL (pwrite)(fildes, buf, nbyte, offset);
2462 #endif
2463     }
2464   PUSH_REENTRANCE (guard);
2465   hrtime_t reqt = gethrtime ();
2466 #if ARCH(Intel) && WSIZE(32)
2467   ret = (real_pwrite) (fildes, buf, nbyte, offset);
2468 #else
2469   ret = CALL_REAL (pwrite)(fildes, buf, nbyte, offset);
2470 #endif
2471   if (RECHCK_REENTRANCE (guard))
2472     {
2473       POP_REENTRANCE (guard);
2474       return ret;
2475     }
2476   hrtime_t grnt = gethrtime ();
2477   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2478   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2479   iopkt.comm.tstamp = grnt;
2480   iopkt.requested = reqt;
2481   if (ret >= 0)
2482     iopkt.iotype = WRITE_TRACE;
2483   else
2484     iopkt.iotype = WRITE_TRACE_ERROR;
2485   iopkt.fd = fildes;
2486   iopkt.nbyte = ret;
2487   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2488   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2489   POP_REENTRANCE (guard);
2490   return ret;
2491 }
2492 
2493 /*------------------------------------------------------------- pwrite64 */
2494 #if ARCH(Intel) && WSIZE(32)
2495 // map interposed symbol versions
2496 static int
2497 __collector_pwrite64_symver (int(real_pwrite64) (), int fildes, const void *buf, size_t nbyte, off64_t offset);
2498 
2499 SYMVER_ATTRIBUTE (__collector_pwrite64_2_2, pwrite64@@GLIBC_2.2)
2500 int
2501 __collector_pwrite64_2_2 (int fildes, const void *buf, size_t nbyte, off64_t offset)
2502 {
2503   TprintfT (DBG_LTT, "iotrace: __collector_pwrite64_2_2@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
2504 	    CALL_REAL (pwrite64_2_2), fildes, buf, (long long) nbyte, (long long) offset);
2505   if (NULL_PTR (pwrite64))
2506     init_io_intf ();
2507   return __collector_pwrite64_symver (CALL_REAL (pwrite64_2_2), fildes, buf, nbyte, offset);
2508 }
2509 
2510 SYMVER_ATTRIBUTE (__collector_pwrite64_2_1, pwrite64@GLIBC_2.1)
2511 int
2512 __collector_pwrite64_2_1 (int fildes, const void *buf, size_t nbyte, off64_t offset)
2513 {
2514   TprintfT (DBG_LTT, "iotrace: __collector_pwrite64_2_1@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
2515 	    CALL_REAL (pwrite64_2_1), fildes, buf, (long long) nbyte, (long long) offset);
2516   if (NULL_PTR (pwrite64))
2517     init_io_intf ();
2518   return __collector_pwrite64_symver (CALL_REAL (pwrite64_2_1), fildes, buf, nbyte, offset);
2519 }
2520 
2521 static int
2522 __collector_pwrite64_symver (int(real_pwrite64) (), int fildes, const void *buf, size_t nbyte, off64_t offset)
2523 {
2524 #else /* ^ARCH(Intel) && WSIZE(32) */
2525 
2526 ssize_t
2527 pwrite64 (int fildes, const void *buf, size_t nbyte, off64_t offset)
2528 {
2529 #endif /* ^ARCH(Intel) && WSIZE(32) */
2530   int *guard;
2531   ssize_t ret;
2532   IOTrace_packet iopkt;
2533   if (NULL_PTR (pwrite64))
2534     init_io_intf ();
2535   if (CHCK_REENTRANCE (guard))
2536     {
2537 #if ARCH(Intel) && WSIZE(32)
2538       return (real_pwrite64) (fildes, buf, nbyte, offset);
2539 #else
2540       return CALL_REAL (pwrite64)(fildes, buf, nbyte, offset);
2541 #endif
2542     }
2543   PUSH_REENTRANCE (guard);
2544   hrtime_t reqt = gethrtime ();
2545 #if ARCH(Intel) && WSIZE(32)
2546   ret = (real_pwrite64) (fildes, buf, nbyte, offset);
2547 #else
2548   ret = CALL_REAL (pwrite64)(fildes, buf, nbyte, offset);
2549 #endif
2550   if (RECHCK_REENTRANCE (guard))
2551     {
2552       POP_REENTRANCE (guard);
2553       return ret;
2554     }
2555   hrtime_t grnt = gethrtime ();
2556   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2557   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2558   iopkt.comm.tstamp = grnt;
2559   iopkt.requested = reqt;
2560   if (ret >= 0)
2561     iopkt.iotype = WRITE_TRACE;
2562   else
2563     iopkt.iotype = WRITE_TRACE_ERROR;
2564   iopkt.fd = fildes;
2565   iopkt.nbyte = ret;
2566   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2567   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2568   POP_REENTRANCE (guard);
2569   return ret;
2570 }
2571 
2572 /*------------------------------------------------------------- fgets */
2573 char*
2574 fgets (char *s, int n, FILE *stream)
2575 {
2576   int *guard;
2577   char *ptr;
2578   IOTrace_packet iopkt;
2579   if (NULL_PTR (fgets))
2580     init_io_intf ();
2581   if (CHCK_REENTRANCE (guard) || stream == NULL)
2582     return CALL_REAL (fgets)(s, n, stream);
2583   PUSH_REENTRANCE (guard);
2584   hrtime_t reqt = gethrtime ();
2585   ptr = CALL_REAL (fgets)(s, n, stream);
2586   if (RECHCK_REENTRANCE (guard))
2587     {
2588       POP_REENTRANCE (guard);
2589       return ptr;
2590     }
2591   int error = errno;
2592   hrtime_t grnt = gethrtime ();
2593   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2594   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2595   iopkt.comm.tstamp = grnt;
2596   iopkt.requested = reqt;
2597   if (ptr != NULL)
2598     {
2599       iopkt.iotype = READ_TRACE;
2600       iopkt.nbyte = collector_strlen (ptr);
2601     }
2602   else if (ptr == NULL && error != EAGAIN && error != EBADF && error != EINTR &&
2603 	   error != EIO && error != EOVERFLOW && error != ENOMEM && error != ENXIO)
2604     {
2605       iopkt.iotype = READ_TRACE;
2606       iopkt.nbyte = 0;
2607     }
2608   else
2609     iopkt.iotype = READ_TRACE_ERROR;
2610   iopkt.fd = fileno (stream);
2611   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2612   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2613   POP_REENTRANCE (guard);
2614   return ptr;
2615 }
2616 
2617 /*------------------------------------------------------------- fputs */
2618 int
2619 fputs (const char *s, FILE *stream)
2620 {
2621   int *guard;
2622   int ret;
2623   IOTrace_packet iopkt;
2624   if (NULL_PTR (fputs))
2625     init_io_intf ();
2626   if (CHCK_REENTRANCE (guard) || stream == NULL)
2627     return CALL_REAL (fputs)(s, stream);
2628   PUSH_REENTRANCE (guard);
2629   hrtime_t reqt = gethrtime ();
2630   ret = CALL_REAL (fputs)(s, stream);
2631   if (RECHCK_REENTRANCE (guard))
2632     {
2633       POP_REENTRANCE (guard);
2634       return ret;
2635     }
2636   hrtime_t grnt = gethrtime ();
2637   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2638   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2639   iopkt.comm.tstamp = grnt;
2640   iopkt.requested = reqt;
2641   if (ret != EOF)
2642     {
2643       iopkt.iotype = WRITE_TRACE;
2644       iopkt.nbyte = ret;
2645     }
2646   else
2647     {
2648       iopkt.iotype = WRITE_TRACE_ERROR;
2649       iopkt.nbyte = 0;
2650     }
2651   iopkt.fd = fileno (stream);
2652   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2653   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2654   POP_REENTRANCE (guard);
2655   return ret;
2656 }
2657 
2658 /*------------------------------------------------------------- fputc */
2659 int
2660 fputc (int c, FILE *stream)
2661 {
2662   int *guard;
2663   int ret;
2664   IOTrace_packet iopkt;
2665   if (NULL_PTR (fputc))
2666     init_io_intf ();
2667   if (CHCK_REENTRANCE (guard) || stream == NULL)
2668     return CALL_REAL (fputc)(c, stream);
2669   PUSH_REENTRANCE (guard);
2670   hrtime_t reqt = gethrtime ();
2671   ret = CALL_REAL (fputc)(c, stream);
2672   if (RECHCK_REENTRANCE (guard))
2673     {
2674       POP_REENTRANCE (guard);
2675       return ret;
2676     }
2677   hrtime_t grnt = gethrtime ();
2678   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2679   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2680   iopkt.comm.tstamp = grnt;
2681   iopkt.requested = reqt;
2682   if (ret != EOF)
2683     {
2684       iopkt.iotype = WRITE_TRACE;
2685       iopkt.nbyte = ret;
2686     }
2687   else
2688     {
2689       iopkt.iotype = WRITE_TRACE_ERROR;
2690       iopkt.nbyte = 0;
2691     }
2692   iopkt.fd = fileno (stream);
2693   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2694   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2695   POP_REENTRANCE (guard);
2696   return ret;
2697 }
2698 
2699 /*------------------------------------------------------------- fprintf */
2700 int
2701 fprintf (FILE *stream, const char *format, ...)
2702 {
2703   int *guard;
2704   int ret;
2705   IOTrace_packet iopkt;
2706   va_list ap;
2707   va_start (ap, format);
2708   if (NULL_PTR (fprintf))
2709     init_io_intf ();
2710   if (NULL_PTR (vfprintf))
2711     init_io_intf ();
2712   if (CHCK_REENTRANCE (guard) || stream == NULL)
2713     return CALL_REAL (vfprintf)(stream, format, ap);
2714   PUSH_REENTRANCE (guard);
2715   hrtime_t reqt = gethrtime ();
2716   ret = CALL_REAL (vfprintf)(stream, format, ap);
2717   if (RECHCK_REENTRANCE (guard))
2718     {
2719       POP_REENTRANCE (guard);
2720       return ret;
2721     }
2722   hrtime_t grnt = gethrtime ();
2723   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2724   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2725   iopkt.comm.tstamp = grnt;
2726   iopkt.requested = reqt;
2727   if (ret >= 0)
2728     iopkt.iotype = WRITE_TRACE;
2729   else
2730     iopkt.iotype = WRITE_TRACE_ERROR;
2731   iopkt.fd = fileno (stream);
2732   iopkt.nbyte = ret;
2733   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2734   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2735   POP_REENTRANCE (guard);
2736   return ret;
2737 }
2738 
2739 /*------------------------------------------------------------- vfprintf */
2740 int
2741 vfprintf (FILE *stream, const char *format, va_list ap)
2742 {
2743   int *guard;
2744   int ret;
2745   IOTrace_packet iopkt;
2746   if (NULL_PTR (vfprintf))
2747     init_io_intf ();
2748   if (CHCK_REENTRANCE (guard) || stream == NULL)
2749     return CALL_REAL (vfprintf)(stream, format, ap);
2750   PUSH_REENTRANCE (guard);
2751   hrtime_t reqt = gethrtime ();
2752   ret = CALL_REAL (vfprintf)(stream, format, ap);
2753   if (RECHCK_REENTRANCE (guard))
2754     {
2755       POP_REENTRANCE (guard);
2756       return ret;
2757     }
2758   hrtime_t grnt = gethrtime ();
2759   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2760   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2761   iopkt.comm.tstamp = grnt;
2762   iopkt.requested = reqt;
2763   if (ret >= 0)
2764     iopkt.iotype = WRITE_TRACE;
2765   else
2766     iopkt.iotype = WRITE_TRACE_ERROR;
2767   iopkt.fd = fileno (stream);
2768   iopkt.nbyte = ret;
2769   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2770   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2771   POP_REENTRANCE (guard);
2772   return ret;
2773 }
2774 
2775 /*------------------------------------------------------------- lseek */
2776 off_t
2777 lseek (int fildes, off_t offset, int whence)
2778 {
2779   int *guard;
2780   off_t ret;
2781   IOTrace_packet iopkt;
2782   if (NULL_PTR (lseek))
2783     init_io_intf ();
2784   if (CHCK_REENTRANCE (guard))
2785     return CALL_REAL (lseek)(fildes, offset, whence);
2786   PUSH_REENTRANCE (guard);
2787   hrtime_t reqt = gethrtime ();
2788   ret = CALL_REAL (lseek)(fildes, offset, whence);
2789   if (RECHCK_REENTRANCE (guard))
2790     {
2791       POP_REENTRANCE (guard);
2792       return ret;
2793     }
2794   hrtime_t grnt = gethrtime ();
2795   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2796   iopkt.comm.tsize = sizeof (IOTrace_packet);
2797   iopkt.comm.tstamp = grnt;
2798   iopkt.requested = reqt;
2799   if (ret != -1)
2800     iopkt.iotype = OTHERIO_TRACE;
2801   else
2802     iopkt.iotype = OTHERIO_TRACE_ERROR;
2803   iopkt.fd = fildes;
2804   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2805   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2806   POP_REENTRANCE (guard);
2807   return ret;
2808 }
2809 
2810 /*------------------------------------------------------------- llseek */
2811 offset_t
2812 llseek (int fildes, offset_t offset, int whence)
2813 {
2814   int *guard;
2815   offset_t ret;
2816   IOTrace_packet iopkt;
2817   if (NULL_PTR (llseek))
2818     init_io_intf ();
2819   if (CHCK_REENTRANCE (guard))
2820     return CALL_REAL (llseek)(fildes, offset, whence);
2821   PUSH_REENTRANCE (guard);
2822   hrtime_t reqt = gethrtime ();
2823   ret = CALL_REAL (llseek)(fildes, offset, whence);
2824   if (RECHCK_REENTRANCE (guard))
2825     {
2826       POP_REENTRANCE (guard);
2827       return ret;
2828     }
2829   hrtime_t grnt = gethrtime ();
2830   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2831   iopkt.comm.tsize = sizeof (IOTrace_packet);
2832   iopkt.comm.tstamp = grnt;
2833   iopkt.requested = reqt;
2834   if (ret != -1)
2835     iopkt.iotype = OTHERIO_TRACE;
2836   else
2837     iopkt.iotype = OTHERIO_TRACE_ERROR;
2838   iopkt.fd = fildes;
2839   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2840   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2841   POP_REENTRANCE (guard);
2842   return ret;
2843 }
2844 
2845 /*------------------------------------------------------------- chmod */
2846 int
2847 chmod (const char *path, mode_t mode)
2848 {
2849   int *guard;
2850   int ret;
2851   void *packet;
2852   IOTrace_packet *iopkt;
2853   size_t sz;
2854   unsigned pktSize;
2855   if (NULL_PTR (chmod))
2856     init_io_intf ();
2857   if (CHCK_REENTRANCE (guard) || path == NULL)
2858     return CALL_REAL (chmod)(path, mode);
2859   PUSH_REENTRANCE (guard);
2860   hrtime_t reqt = gethrtime ();
2861   ret = CALL_REAL (chmod)(path, mode);
2862   if (RECHCK_REENTRANCE (guard))
2863     {
2864       POP_REENTRANCE (guard);
2865       return ret;
2866     }
2867   hrtime_t grnt = gethrtime ();
2868   sz = collector_strlen (path);
2869   pktSize = sizeof (IOTrace_packet) + sz;
2870   pktSize = collector_align_pktsize (pktSize);
2871   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
2872   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
2873   if (packet != NULL)
2874     {
2875       iopkt = (IOTrace_packet *) packet;
2876       collector_memset (iopkt, 0, pktSize);
2877       iopkt->comm.tsize = pktSize;
2878       iopkt->comm.tstamp = grnt;
2879       iopkt->requested = reqt;
2880       if (ret != -1)
2881 	iopkt->iotype = OTHERIO_TRACE;
2882       else
2883 	iopkt->iotype = OTHERIO_TRACE_ERROR;
2884       collector_strncpy (&(iopkt->fname), path, sz);
2885       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2886       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
2887       collector_interface->freeCSize (io_heap, packet, pktSize);
2888     }
2889   else
2890     {
2891       Tprintf (0, "iotrace: ERROR: chmod cannot allocate memory\n");
2892       return 0;
2893     }
2894   POP_REENTRANCE (guard);
2895   return ret;
2896 }
2897 
2898 /*------------------------------------------------------------- access */
2899 int
2900 access (const char *path, int amode)
2901 {
2902   int *guard;
2903   int ret;
2904   void *packet;
2905   IOTrace_packet *iopkt;
2906   size_t sz;
2907   unsigned pktSize;
2908   if (NULL_PTR (access))
2909     init_io_intf ();
2910   if (CHCK_REENTRANCE (guard) || path == NULL)
2911     return CALL_REAL (access)(path, amode);
2912   PUSH_REENTRANCE (guard);
2913   hrtime_t reqt = gethrtime ();
2914   ret = CALL_REAL (access)(path, amode);
2915   if (RECHCK_REENTRANCE (guard))
2916     {
2917       POP_REENTRANCE (guard);
2918       return ret;
2919     }
2920   hrtime_t grnt = gethrtime ();
2921   sz = collector_strlen (path);
2922   pktSize = sizeof (IOTrace_packet) + sz;
2923   pktSize = collector_align_pktsize (pktSize);
2924   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
2925   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
2926   if (packet != NULL)
2927     {
2928       iopkt = (IOTrace_packet *) packet;
2929       collector_memset (iopkt, 0, pktSize);
2930       iopkt->comm.tsize = pktSize;
2931       iopkt->comm.tstamp = grnt;
2932       iopkt->requested = reqt;
2933       if (ret != -1)
2934 	iopkt->iotype = OTHERIO_TRACE;
2935       else
2936 	iopkt->iotype = OTHERIO_TRACE_ERROR;
2937       collector_strncpy (&(iopkt->fname), path, sz);
2938       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2939       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
2940       collector_interface->freeCSize (io_heap, packet, pktSize);
2941     }
2942   else
2943     {
2944       Tprintf (0, "iotrace: ERROR: access cannot allocate memory\n");
2945       return 0;
2946     }
2947   POP_REENTRANCE (guard);
2948   return ret;
2949 }
2950 
2951 /*------------------------------------------------------------- rename */
2952 int
2953 rename (const char *old, const char *new)
2954 {
2955   int *guard;
2956   int ret;
2957   void *packet;
2958   IOTrace_packet *iopkt;
2959   size_t sz;
2960   unsigned pktSize;
2961   if (NULL_PTR (rename))
2962     init_io_intf ();
2963   if (CHCK_REENTRANCE (guard) || new == NULL)
2964     return CALL_REAL (rename)(old, new);
2965   PUSH_REENTRANCE (guard);
2966   hrtime_t reqt = gethrtime ();
2967   ret = CALL_REAL (rename)(old, new);
2968   if (RECHCK_REENTRANCE (guard))
2969     {
2970       POP_REENTRANCE (guard);
2971       return ret;
2972     }
2973   hrtime_t grnt = gethrtime ();
2974   sz = collector_strlen (new);
2975   pktSize = sizeof (IOTrace_packet) + sz;
2976   pktSize = collector_align_pktsize (pktSize);
2977   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
2978   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
2979   if (packet != NULL)
2980     {
2981       iopkt = (IOTrace_packet *) packet;
2982       collector_memset (iopkt, 0, pktSize);
2983       iopkt->comm.tsize = pktSize;
2984       iopkt->comm.tstamp = grnt;
2985       iopkt->requested = reqt;
2986       if (ret != -1)
2987 	iopkt->iotype = OTHERIO_TRACE;
2988       else
2989 	iopkt->iotype = OTHERIO_TRACE_ERROR;
2990       collector_strncpy (&(iopkt->fname), new, sz);
2991       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2992       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
2993       collector_interface->freeCSize (io_heap, packet, pktSize);
2994     }
2995   else
2996     {
2997       Tprintf (0, "iotrace: ERROR: rename cannot allocate memory\n");
2998       return 0;
2999     }
3000   POP_REENTRANCE (guard);
3001   return ret;
3002 }
3003 
3004 /*------------------------------------------------------------- mkdir */
3005 int
3006 mkdir (const char *path, mode_t mode)
3007 {
3008   int *guard;
3009   int ret;
3010   void *packet;
3011   IOTrace_packet *iopkt;
3012   size_t sz;
3013   unsigned pktSize;
3014   if (NULL_PTR (mkdir))
3015     init_io_intf ();
3016   if (CHCK_REENTRANCE (guard) || path == NULL)
3017     return CALL_REAL (mkdir)(path, mode);
3018   PUSH_REENTRANCE (guard);
3019   hrtime_t reqt = gethrtime ();
3020   ret = CALL_REAL (mkdir)(path, mode);
3021   if (RECHCK_REENTRANCE (guard))
3022     {
3023       POP_REENTRANCE (guard);
3024       return ret;
3025     }
3026   hrtime_t grnt = gethrtime ();
3027   sz = collector_strlen (path);
3028   pktSize = sizeof (IOTrace_packet) + sz;
3029   pktSize = collector_align_pktsize (pktSize);
3030   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
3031   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
3032   if (packet != NULL)
3033     {
3034       iopkt = (IOTrace_packet *) packet;
3035       collector_memset (iopkt, 0, pktSize);
3036       iopkt->comm.tsize = pktSize;
3037       iopkt->comm.tstamp = grnt;
3038       iopkt->requested = reqt;
3039       if (ret != -1)
3040 	iopkt->iotype = OTHERIO_TRACE;
3041       else
3042 	iopkt->iotype = OTHERIO_TRACE_ERROR;
3043       collector_strncpy (&(iopkt->fname), path, sz);
3044       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3045       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
3046       collector_interface->freeCSize (io_heap, packet, pktSize);
3047     }
3048   else
3049     {
3050       Tprintf (0, "iotrace: ERROR: mkdir cannot allocate memory\n");
3051       return 0;
3052     }
3053   POP_REENTRANCE (guard);
3054   return ret;
3055 }
3056 
3057 /*------------------------------------------------------------- getdents */
3058 int
3059 getdents (int fildes, struct dirent *buf, size_t nbyte)
3060 {
3061   int *guard;
3062   int ret;
3063   IOTrace_packet iopkt;
3064   if (NULL_PTR (getdents))
3065     init_io_intf ();
3066   if (CHCK_REENTRANCE (guard))
3067     return CALL_REAL (getdents)(fildes, buf, nbyte);
3068   PUSH_REENTRANCE (guard);
3069   hrtime_t reqt = gethrtime ();
3070   ret = CALL_REAL (getdents)(fildes, buf, nbyte);
3071   if (RECHCK_REENTRANCE (guard))
3072     {
3073       POP_REENTRANCE (guard);
3074       return ret;
3075     }
3076   hrtime_t grnt = gethrtime ();
3077   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3078   iopkt.comm.tsize = sizeof (IOTrace_packet);
3079   iopkt.comm.tstamp = grnt;
3080   iopkt.requested = reqt;
3081   if (ret != -1)
3082     iopkt.iotype = OTHERIO_TRACE;
3083   else
3084     iopkt.iotype = OTHERIO_TRACE_ERROR;
3085   iopkt.fd = fildes;
3086   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3087   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3088   POP_REENTRANCE (guard);
3089   return ret;
3090 }
3091 
3092 /*------------------------------------------------------------- unlink */
3093 int
3094 unlink (const char *path)
3095 {
3096   int *guard;
3097   int ret;
3098   void *packet;
3099   IOTrace_packet *iopkt;
3100   size_t sz;
3101   unsigned pktSize;
3102   if (NULL_PTR (unlink))
3103     init_io_intf ();
3104   if (CHCK_REENTRANCE (guard) || path == NULL)
3105     return CALL_REAL (unlink)(path);
3106   PUSH_REENTRANCE (guard);
3107   hrtime_t reqt = gethrtime ();
3108   ret = CALL_REAL (unlink)(path);
3109   if (RECHCK_REENTRANCE (guard))
3110     {
3111       POP_REENTRANCE (guard);
3112       return ret;
3113     }
3114   hrtime_t grnt = gethrtime ();
3115   sz = collector_strlen (path);
3116   pktSize = sizeof (IOTrace_packet) + sz;
3117   pktSize = collector_align_pktsize (pktSize);
3118   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
3119   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
3120   if (packet != NULL)
3121     {
3122       iopkt = (IOTrace_packet *) packet;
3123       collector_memset (iopkt, 0, pktSize);
3124       iopkt->comm.tsize = pktSize;
3125       iopkt->comm.tstamp = grnt;
3126       iopkt->requested = reqt;
3127       if (ret != -1)
3128 	iopkt->iotype = OTHERIO_TRACE;
3129       else
3130 	iopkt->iotype = OTHERIO_TRACE_ERROR;
3131       collector_strncpy (&(iopkt->fname), path, sz);
3132       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3133       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
3134       collector_interface->freeCSize (io_heap, packet, pktSize);
3135     }
3136   else
3137     {
3138       Tprintf (0, "iotrace: ERROR: unlink cannot allocate memory\n");
3139       return 0;
3140     }
3141   POP_REENTRANCE (guard);
3142   return ret;
3143 }
3144 
3145 /*------------------------------------------------------------- fseek */
3146 int
3147 fseek (FILE *stream, long offset, int whence)
3148 {
3149   int *guard;
3150   int ret;
3151   IOTrace_packet iopkt;
3152   if (NULL_PTR (fseek))
3153     init_io_intf ();
3154   if (CHCK_REENTRANCE (guard) || stream == NULL)
3155     return CALL_REAL (fseek)(stream, offset, whence);
3156   PUSH_REENTRANCE (guard);
3157   hrtime_t reqt = gethrtime ();
3158   ret = CALL_REAL (fseek)(stream, offset, whence);
3159   if (RECHCK_REENTRANCE (guard))
3160     {
3161       POP_REENTRANCE (guard);
3162       return ret;
3163     }
3164   hrtime_t grnt = gethrtime ();
3165   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3166   iopkt.comm.tsize = sizeof (IOTrace_packet);
3167   iopkt.comm.tstamp = grnt;
3168   iopkt.requested = reqt;
3169   if (ret != -1)
3170     iopkt.iotype = OTHERIO_TRACE;
3171   else
3172     iopkt.iotype = OTHERIO_TRACE_ERROR;
3173   iopkt.fd = fileno (stream);
3174   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3175   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3176   POP_REENTRANCE (guard);
3177   return ret;
3178 }
3179 
3180 /*------------------------------------------------------------- rewind */
3181 void
3182 rewind (FILE *stream)
3183 {
3184   int *guard;
3185   IOTrace_packet iopkt;
3186   if (NULL_PTR (rewind))
3187     init_io_intf ();
3188   if (CHCK_REENTRANCE (guard) || stream == NULL)
3189     {
3190       CALL_REAL (rewind)(stream);
3191       return;
3192     }
3193   PUSH_REENTRANCE (guard);
3194   hrtime_t reqt = gethrtime ();
3195   CALL_REAL (rewind)(stream);
3196   if (RECHCK_REENTRANCE (guard))
3197     {
3198       POP_REENTRANCE (guard);
3199       return;
3200     }
3201   hrtime_t grnt = gethrtime ();
3202   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3203   iopkt.comm.tsize = sizeof (IOTrace_packet);
3204   iopkt.comm.tstamp = grnt;
3205   iopkt.requested = reqt;
3206   iopkt.iotype = OTHERIO_TRACE;
3207   iopkt.fd = fileno (stream);
3208   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3209   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3210   POP_REENTRANCE (guard);
3211 }
3212 
3213 /*------------------------------------------------------------- ftell */
3214 long
3215 ftell (FILE *stream)
3216 {
3217   int *guard;
3218   long ret;
3219   IOTrace_packet iopkt;
3220   if (NULL_PTR (ftell))
3221     init_io_intf ();
3222   if (CHCK_REENTRANCE (guard) || stream == NULL)
3223     return CALL_REAL (ftell)(stream);
3224   PUSH_REENTRANCE (guard);
3225   hrtime_t reqt = gethrtime ();
3226   ret = CALL_REAL (ftell)(stream);
3227   if (RECHCK_REENTRANCE (guard))
3228     {
3229       POP_REENTRANCE (guard);
3230       return ret;
3231     }
3232   hrtime_t grnt = gethrtime ();
3233   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3234   iopkt.comm.tsize = sizeof (IOTrace_packet);
3235   iopkt.comm.tstamp = grnt;
3236   iopkt.requested = reqt;
3237   if (ret != -1)
3238     iopkt.iotype = OTHERIO_TRACE;
3239   else
3240     iopkt.iotype = OTHERIO_TRACE_ERROR;
3241   iopkt.fd = fileno (stream);
3242   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3243   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3244   POP_REENTRANCE (guard);
3245   return ret;
3246 }
3247 
3248 /*------------------------------------------------------------- fgetpos */
3249 // map interposed symbol versions
3250 #if ARCH(Intel) && WSIZE(32)
3251 static int
3252 __collector_fgetpos_symver (int(real_fgetpos) (), FILE *stream, fpos_t *pos);
3253 
3254 SYMVER_ATTRIBUTE (__collector_fgetpos_2_2, fgetpos@@GLIBC_2.2)
3255 int
3256 __collector_fgetpos_2_2 (FILE *stream, fpos_t *pos)
3257 {
3258   if (NULL_PTR (fgetpos))
3259     init_io_intf ();
3260   TprintfT (DBG_LTT, "iotrace: __collector_fgetpos_2_2@%p\n", CALL_REAL (fgetpos_2_2));
3261   return __collector_fgetpos_symver (CALL_REAL (fgetpos_2_2), stream, pos);
3262 }
3263 
3264 SYMVER_ATTRIBUTE (__collector_fgetpos_2_0, fgetpos@GLIBC_2.0)
3265 int
3266 __collector_fgetpos_2_0 (FILE *stream, fpos_t *pos)
3267 {
3268   if (NULL_PTR (fgetpos))
3269     init_io_intf ();
3270   TprintfT (DBG_LTT, "iotrace: __collector_fgetpos_2_0@%p\n", CALL_REAL (fgetpos_2_0));
3271   return __collector_fgetpos_symver (CALL_REAL (fgetpos_2_0), stream, pos);
3272 }
3273 #endif
3274 
3275 #if ARCH(Intel) && WSIZE(32)
3276 
3277 static int
3278 __collector_fgetpos_symver (int(real_fgetpos) (), FILE *stream, fpos_t *pos)
3279 {
3280 #else
3281 int
3282 fgetpos (FILE *stream, fpos_t *pos)
3283 {
3284 #endif
3285   int *guard;
3286   int ret;
3287   IOTrace_packet iopkt;
3288   if (NULL_PTR (fgetpos))
3289     init_io_intf ();
3290   if (CHCK_REENTRANCE (guard) || stream == NULL)
3291     {
3292 #if ARCH(Intel) && WSIZE(32)
3293       return (real_fgetpos) (stream, pos);
3294 #else
3295       return CALL_REAL (fgetpos)(stream, pos);
3296 #endif
3297     }
3298   PUSH_REENTRANCE (guard);
3299   hrtime_t reqt = gethrtime ();
3300 #if ARCH(Intel) && WSIZE(32)
3301   ret = (real_fgetpos) (stream, pos);
3302 #else
3303   ret = CALL_REAL (fgetpos)(stream, pos);
3304 #endif
3305   if (RECHCK_REENTRANCE (guard))
3306     {
3307       POP_REENTRANCE (guard);
3308       return ret;
3309     }
3310   hrtime_t grnt = gethrtime ();
3311   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3312   iopkt.comm.tsize = sizeof (IOTrace_packet);
3313   iopkt.comm.tstamp = grnt;
3314   iopkt.requested = reqt;
3315   if (ret == 0)
3316     iopkt.iotype = OTHERIO_TRACE;
3317   else
3318     iopkt.iotype = OTHERIO_TRACE_ERROR;
3319   iopkt.fd = fileno (stream);
3320 
3321 #if ARCH(Intel) && WSIZE(32)
3322   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
3323 #else
3324   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3325 #endif
3326   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3327   POP_REENTRANCE (guard);
3328   return ret;
3329 }
3330 
3331 #if WSIZE(32)
3332 /*------------------------------------------------------------- fgetpos64 */
3333 #if ARCH(Intel)
3334 // map interposed symbol versions
3335 
3336 static int
3337 __collector_fgetpos64_symver (int(real_fgetpos64) (), FILE *stream, fpos64_t *pos);
3338 
3339 SYMVER_ATTRIBUTE (__collector_fgetpos64_2_2, fgetpos64@@GLIBC_2.2)
3340 int
3341 __collector_fgetpos64_2_2 (FILE *stream, fpos64_t *pos)
3342 {
3343   TprintfT (DBG_LTT, "iotrace: __collector_fgetpos64_2_2@%p(stream=%p, pos=%p)\n",
3344 	    CALL_REAL (fgetpos64_2_2), stream, pos);
3345   if (NULL_PTR (fgetpos64))
3346     init_io_intf ();
3347   return __collector_fgetpos64_symver (CALL_REAL (fgetpos64_2_2), stream, pos);
3348 }
3349 
3350 SYMVER_ATTRIBUTE (__collector_fgetpos64_2_1, fgetpos64@GLIBC_2.1)
3351 int
3352 __collector_fgetpos64_2_1 (FILE *stream, fpos64_t *pos)
3353 {
3354   TprintfT (DBG_LTT, "iotrace: __collector_fgetpos64_2_1@%p(stream=%p, pos=%p)\n",
3355 	    CALL_REAL (fgetpos64_2_1), stream, pos);
3356   if (NULL_PTR (fgetpos64))
3357     init_io_intf ();
3358   return __collector_fgetpos64_symver (CALL_REAL (fgetpos64_2_1), stream, pos);
3359 }
3360 
3361 static int
3362 __collector_fgetpos64_symver (int(real_fgetpos64) (), FILE *stream, fpos64_t *pos)
3363 {
3364 #else
3365 int
3366 fgetpos64 (FILE *stream, fpos64_t *pos)
3367 {
3368 #endif
3369   int *guard;
3370   int ret;
3371   IOTrace_packet iopkt;
3372   if (NULL_PTR (fgetpos64))
3373     init_io_intf ();
3374   if (CHCK_REENTRANCE (guard) || stream == NULL)
3375     {
3376 #if ARCH(Intel)
3377       return (real_fgetpos64) (stream, pos);
3378 #else
3379       return CALL_REAL (fgetpos64)(stream, pos);
3380 #endif
3381     }
3382   PUSH_REENTRANCE (guard);
3383   hrtime_t reqt = gethrtime ();
3384 #if ARCH(Intel)
3385   ret = (real_fgetpos64) (stream, pos);
3386 #else
3387   ret = CALL_REAL (fgetpos64)(stream, pos);
3388 #endif
3389   if (RECHCK_REENTRANCE (guard))
3390     {
3391       POP_REENTRANCE (guard);
3392       return ret;
3393     }
3394   hrtime_t grnt = gethrtime ();
3395   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3396   iopkt.comm.tsize = sizeof (IOTrace_packet);
3397   iopkt.comm.tstamp = grnt;
3398   iopkt.requested = reqt;
3399   if (ret == 0)
3400     iopkt.iotype = OTHERIO_TRACE;
3401   else
3402     iopkt.iotype = OTHERIO_TRACE_ERROR;
3403   iopkt.fd = fileno (stream);
3404 #if ARCH(Intel)
3405   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
3406 #else
3407   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3408 #endif
3409   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3410   POP_REENTRANCE (guard);
3411   return ret;
3412 }
3413 #endif
3414 
3415 /*------------------------------------------------------------- fsetpos */
3416 // map interposed symbol versions
3417 #if ARCH(Intel) && WSIZE(32)
3418 static int
3419 __collector_fsetpos_symver (int(real_fsetpos) (), FILE *stream, const fpos_t *pos);
3420 
3421 SYMVER_ATTRIBUTE (__collector_fsetpos_2_2, fsetpos@@GLIBC_2.2)
3422 int
3423 __collector_fsetpos_2_2 (FILE *stream, const fpos_t *pos)
3424 {
3425   if (NULL_PTR (fsetpos))
3426     init_io_intf ();
3427   TprintfT (DBG_LTT, "iotrace: __collector_fsetpos_2_2@%p\n", CALL_REAL (fsetpos_2_2));
3428   return __collector_fsetpos_symver (CALL_REAL (fsetpos_2_2), stream, pos);
3429 }
3430 
3431 SYMVER_ATTRIBUTE (__collector_fsetpos_2_0, fsetpos@GLIBC_2.0)
3432 int
3433 __collector_fsetpos_2_0 (FILE *stream, const fpos_t *pos)
3434 {
3435   if (NULL_PTR (fsetpos))
3436     init_io_intf ();
3437   TprintfT (DBG_LTT, "iotrace: __collector_fsetpos_2_0@%p\n", CALL_REAL (fsetpos_2_0));
3438   return __collector_fsetpos_symver (CALL_REAL (fsetpos_2_0), stream, pos);
3439 }
3440 #endif
3441 
3442 #if ARCH(Intel) && WSIZE(32)
3443 
3444 static int
3445 __collector_fsetpos_symver (int(real_fsetpos) (), FILE *stream, const fpos_t *pos)
3446 {
3447 #else
3448 int
3449 fsetpos (FILE *stream, const fpos_t *pos)
3450 {
3451 #endif
3452   int *guard;
3453   int ret;
3454   IOTrace_packet iopkt;
3455   if (NULL_PTR (fsetpos))
3456     init_io_intf ();
3457   if (CHCK_REENTRANCE (guard) || stream == NULL)
3458     {
3459 #if ARCH(Intel) && WSIZE(32)
3460       return (real_fsetpos) (stream, pos);
3461 #else
3462       return CALL_REAL (fsetpos)(stream, pos);
3463 #endif
3464     }
3465   PUSH_REENTRANCE (guard);
3466   hrtime_t reqt = gethrtime ();
3467 #if ARCH(Intel) && WSIZE(32)
3468   ret = (real_fsetpos) (stream, pos);
3469 #else
3470   ret = CALL_REAL (fsetpos)(stream, pos);
3471 #endif
3472   if (RECHCK_REENTRANCE (guard))
3473     {
3474       POP_REENTRANCE (guard);
3475       return ret;
3476     }
3477   hrtime_t grnt = gethrtime ();
3478   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3479   iopkt.comm.tsize = sizeof (IOTrace_packet);
3480   iopkt.comm.tstamp = grnt;
3481   iopkt.requested = reqt;
3482   if (ret == 0)
3483     iopkt.iotype = OTHERIO_TRACE;
3484   else
3485     iopkt.iotype = OTHERIO_TRACE_ERROR;
3486   iopkt.fd = fileno (stream);
3487 #if ARCH(Intel) && WSIZE(32)
3488   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
3489 #else
3490   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3491 #endif
3492   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3493   POP_REENTRANCE (guard);
3494   return ret;
3495 }
3496 
3497 #if WSIZE(32)
3498 /*------------------------------------------------------------- fsetpos64 */
3499 #if ARCH(Intel)
3500 // map interposed symbol versions
3501 static int
3502 __collector_fsetpos64_symver (int(real_fsetpos64) (), FILE *stream, const fpos64_t *pos);
3503 
3504 SYMVER_ATTRIBUTE (__collector_fsetpos64_2_2, fsetpos64@@GLIBC_2.2)
3505 int
3506 __collector_fsetpos64_2_2 (FILE *stream, const fpos64_t *pos)
3507 {
3508   TprintfT (DBG_LTT, "iotrace: __collector_fsetpos64_2_2@%p(stream=%p, pos=%p)\n",
3509 	    CALL_REAL (fsetpos64_2_2), stream, pos);
3510   if (NULL_PTR (fsetpos64))
3511     init_io_intf ();
3512   return __collector_fsetpos64_symver (CALL_REAL (fsetpos64_2_2), stream, pos);
3513 }
3514 
3515 SYMVER_ATTRIBUTE (__collector_fsetpos64_2_1, fsetpos64@GLIBC_2.1)
3516 int
3517 __collector_fsetpos64_2_1 (FILE *stream, const fpos64_t *pos)
3518 {
3519   TprintfT (DBG_LTT, "iotrace: __collector_fsetpos64_2_1@%p(stream=%p, pos=%p)\n",
3520 	    CALL_REAL (fsetpos64_2_1), stream, pos);
3521   if (NULL_PTR (fsetpos64))
3522     init_io_intf ();
3523   return __collector_fsetpos64_symver (CALL_REAL (fsetpos64_2_1), stream, pos);
3524 }
3525 
3526 static int
3527 __collector_fsetpos64_symver (int(real_fsetpos64) (), FILE *stream, const fpos64_t *pos)
3528 {
3529 #else
3530 int
3531 fsetpos64 (FILE *stream, const fpos64_t *pos)
3532 {
3533 #endif
3534   int *guard;
3535   int ret;
3536   IOTrace_packet iopkt;
3537   if (NULL_PTR (fsetpos64))
3538     init_io_intf ();
3539   if (CHCK_REENTRANCE (guard) || stream == NULL)
3540     {
3541 #if ARCH(Intel) && WSIZE(32)
3542       return (real_fsetpos64) (stream, pos);
3543 #else
3544       return CALL_REAL (fsetpos64)(stream, pos);
3545 #endif
3546     }
3547   PUSH_REENTRANCE (guard);
3548   hrtime_t reqt = gethrtime ();
3549 #if ARCH(Intel) && WSIZE(32)
3550   ret = (real_fsetpos64) (stream, pos);
3551 #else
3552   ret = CALL_REAL (fsetpos64)(stream, pos);
3553 #endif
3554   if (RECHCK_REENTRANCE (guard))
3555     {
3556       POP_REENTRANCE (guard);
3557       return ret;
3558     }
3559   hrtime_t grnt = gethrtime ();
3560   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3561   iopkt.comm.tsize = sizeof (IOTrace_packet);
3562   iopkt.comm.tstamp = grnt;
3563   iopkt.requested = reqt;
3564   if (ret == 0)
3565     iopkt.iotype = OTHERIO_TRACE;
3566   else
3567     iopkt.iotype = OTHERIO_TRACE_ERROR;
3568   iopkt.fd = fileno (stream);
3569 #if ARCH(Intel)
3570   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
3571 #else
3572   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3573 #endif
3574   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3575   POP_REENTRANCE (guard);
3576   return ret;
3577 }
3578 #endif
3579 
3580 /*------------------------------------------------------------- fsync */
3581 int
3582 fsync (int fildes)
3583 {
3584   int *guard;
3585   int ret;
3586   IOTrace_packet iopkt;
3587   if (NULL_PTR (fsync))
3588     init_io_intf ();
3589   if (CHCK_REENTRANCE (guard))
3590     return CALL_REAL (fsync)(fildes);
3591   PUSH_REENTRANCE (guard);
3592   hrtime_t reqt = gethrtime ();
3593   ret = CALL_REAL (fsync)(fildes);
3594   if (RECHCK_REENTRANCE (guard))
3595     {
3596       POP_REENTRANCE (guard);
3597       return ret;
3598     }
3599   hrtime_t grnt = gethrtime ();
3600   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3601   iopkt.comm.tsize = sizeof (IOTrace_packet);
3602   iopkt.comm.tstamp = grnt;
3603   iopkt.requested = reqt;
3604   if (ret == 0)
3605     iopkt.iotype = OTHERIO_TRACE;
3606   else
3607     iopkt.iotype = OTHERIO_TRACE_ERROR;
3608   iopkt.fd = fildes;
3609   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3610   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3611   POP_REENTRANCE (guard);
3612   return ret;
3613 }
3614 
3615 /*------------------------------------------------------------- readdir */
3616 struct dirent*
3617 readdir (DIR *dirp)
3618 {
3619   int *guard;
3620   struct dirent *ptr;
3621   IOTrace_packet iopkt;
3622   if (NULL_PTR (readdir))
3623     init_io_intf ();
3624   if (CHCK_REENTRANCE (guard))
3625     return CALL_REAL (readdir)(dirp);
3626   PUSH_REENTRANCE (guard);
3627   hrtime_t reqt = gethrtime ();
3628   ptr = CALL_REAL (readdir)(dirp);
3629   if (RECHCK_REENTRANCE (guard))
3630     {
3631       POP_REENTRANCE (guard);
3632       return ptr;
3633     }
3634   hrtime_t grnt = gethrtime ();
3635   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
3636   iopkt.comm.tsize = sizeof ( IOTrace_packet);
3637   iopkt.comm.tstamp = grnt;
3638   iopkt.requested = reqt;
3639   if (ptr != NULL)
3640     iopkt.iotype = OTHERIO_TRACE;
3641   else
3642     iopkt.iotype = OTHERIO_TRACE_ERROR;
3643   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3644   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3645   POP_REENTRANCE (guard);
3646   return ptr;
3647 }
3648 
3649 /*------------------------------------------------------------- flock */
3650 int
3651 flock (int fd, int operation)
3652 {
3653   int *guard;
3654   int ret;
3655   IOTrace_packet iopkt;
3656   if (NULL_PTR (flock))
3657     init_io_intf ();
3658   if (CHCK_REENTRANCE (guard))
3659     return CALL_REAL (flock)(fd, operation);
3660   PUSH_REENTRANCE (guard);
3661   hrtime_t reqt = gethrtime ();
3662   ret = CALL_REAL (flock)(fd, operation);
3663   if (RECHCK_REENTRANCE (guard))
3664     {
3665       POP_REENTRANCE (guard);
3666       return ret;
3667     }
3668   hrtime_t grnt = gethrtime ();
3669   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3670   iopkt.comm.tsize = sizeof (IOTrace_packet);
3671   iopkt.comm.tstamp = grnt;
3672   iopkt.requested = reqt;
3673   if (ret == 0)
3674     iopkt.iotype = OTHERIO_TRACE;
3675   else
3676     iopkt.iotype = OTHERIO_TRACE_ERROR;
3677   iopkt.fd = fd;
3678   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3679   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3680   POP_REENTRANCE (guard);
3681   return ret;
3682 }
3683 
3684 /*------------------------------------------------------------- lockf */
3685 int
3686 lockf (int fildes, int function, off_t size)
3687 {
3688   int *guard;
3689   int ret;
3690   IOTrace_packet iopkt;
3691   if (NULL_PTR (lockf))
3692     init_io_intf ();
3693   if (CHCK_REENTRANCE (guard))
3694     return CALL_REAL (lockf)(fildes, function, size);
3695   PUSH_REENTRANCE (guard);
3696   hrtime_t reqt = gethrtime ();
3697   ret = CALL_REAL (lockf)(fildes, function, size);
3698   if (RECHCK_REENTRANCE (guard))
3699     {
3700       POP_REENTRANCE (guard);
3701       return ret;
3702     }
3703   hrtime_t grnt = gethrtime ();
3704   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3705   iopkt.comm.tsize = sizeof (IOTrace_packet);
3706   iopkt.comm.tstamp = grnt;
3707   iopkt.requested = reqt;
3708   if (ret == 0)
3709     iopkt.iotype = OTHERIO_TRACE;
3710   else
3711     iopkt.iotype = OTHERIO_TRACE_ERROR;
3712   iopkt.fd = fildes;
3713   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3714   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3715   POP_REENTRANCE (guard);
3716   return ret;
3717 }
3718