]> Git Repo - binutils.git/blob - gprofng/libcollector/iotrace.c
Automatic date update in version.in
[binutils.git] / gprofng / libcollector / iotrace.c
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.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
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
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
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
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 *
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
244 collector_fstype (const char *path)
245 {
246   return UNKNOWNFS_TYPE;
247 }
248
249 void
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
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
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
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
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
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
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 static void
1003 write_io_packet (int fd, ssize_t ret, hrtime_t reqt, int iotype)
1004 {
1005   IOTrace_packet iopkt;
1006   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
1007   iopkt.comm.tsize = sizeof (IOTrace_packet);
1008   iopkt.comm.tstamp = gethrtime ();
1009   iopkt.requested = reqt;
1010   iopkt.iotype = iotype;
1011   iopkt.fd = fd;
1012   iopkt.nbyte = ret;
1013   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl,
1014                         iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1015   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1016 }
1017
1018 /*------------------------------------------------------------- open */
1019 int
1020 open (const char *path, int oflag, ...)
1021 {
1022   int *guard;
1023   int fd;
1024   void *packet;
1025   IOTrace_packet *iopkt;
1026   mode_t mode;
1027   va_list ap;
1028   size_t sz;
1029   unsigned pktSize;
1030
1031   va_start (ap, oflag);
1032   mode = va_arg (ap, mode_t);
1033   va_end (ap);
1034
1035   if (NULL_PTR (open))
1036     init_io_intf ();
1037
1038   if (CHCK_REENTRANCE (guard) || path == NULL)
1039     return CALL_REAL (open)(path, oflag, mode);
1040   PUSH_REENTRANCE (guard);
1041   hrtime_t reqt = gethrtime ();
1042   fd = CALL_REAL (open)(path, oflag, mode);
1043   if (RECHCK_REENTRANCE (guard))
1044     {
1045       POP_REENTRANCE (guard);
1046       return fd;
1047     }
1048   hrtime_t grnt = gethrtime ();
1049   sz = collector_strlen (path);
1050   pktSize = sizeof (IOTrace_packet) + sz;
1051   pktSize = collector_align_pktsize (pktSize);
1052   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1053   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1054   if (packet != NULL)
1055     {
1056       iopkt = (IOTrace_packet *) packet;
1057       collector_memset (iopkt, 0, pktSize);
1058       iopkt->comm.tsize = pktSize;
1059       iopkt->comm.tstamp = grnt;
1060       iopkt->requested = reqt;
1061       if (fd != -1)
1062         iopkt->iotype = OPEN_TRACE;
1063       else
1064         iopkt->iotype = OPEN_TRACE_ERROR;
1065       iopkt->fd = fd;
1066       iopkt->fstype = collector_fstype (path);
1067       collector_strncpy (&(iopkt->fname), path, sz);
1068       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1069       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1070       collector_interface->freeCSize (io_heap, packet, pktSize);
1071     }
1072   else
1073     {
1074       Tprintf (0, "iotrace: ERROR: open cannot allocate memory\n");
1075       return -1;
1076     }
1077   POP_REENTRANCE (guard);
1078   return fd;
1079 }
1080
1081 /*------------------------------------------------------------- open64 */
1082 #if ARCH(Intel) && WSIZE(32)
1083 // map interposed symbol versions
1084 static int
1085 __collector_open64_symver (int(real_open64) (const char *, int, ...),
1086                            const char *path, int oflag, mode_t mode);
1087
1088 SYMVER_ATTRIBUTE (__collector_open64_2_2, open64@GLIBC_2.2)
1089 int
1090 __collector_open64_2_2 (const char *path, int oflag, ...)
1091 {
1092   mode_t mode;
1093   va_list ap;
1094   va_start (ap, oflag);
1095   mode = va_arg (ap, mode_t);
1096   va_end (ap);
1097   TprintfT (DBG_LTT,
1098             "iotrace: __collector_open64_2_2@%p(path=%s, oflag=0%o, mode=0%o\n",
1099             CALL_REAL (open64_2_2), path ? path : "NULL", oflag, mode);
1100   if (NULL_PTR (open64))
1101     init_io_intf ();
1102   return __collector_open64_symver (CALL_REAL (open64_2_2), path, oflag, mode);
1103 }
1104
1105 SYMVER_ATTRIBUTE (__collector_open64_2_1, open64@GLIBC_2.1)
1106 int
1107 __collector_open64_2_1 (const char *path, int oflag, ...)
1108 {
1109   mode_t mode;
1110   va_list ap;
1111   va_start (ap, oflag);
1112   mode = va_arg (ap, mode_t);
1113   va_end (ap);
1114   TprintfT (DBG_LTT,
1115             "iotrace: __collector_open64_2_1@%p(path=%s, oflag=0%o, mode=0%o\n",
1116             CALL_REAL (open64_2_1), path ? path : "NULL", oflag, mode);
1117   if (NULL_PTR (open64))
1118     init_io_intf ();
1119   return __collector_open64_symver (CALL_REAL (open64_2_1), path, oflag, mode);
1120 }
1121
1122 #endif /* ARCH(Intel) && WSIZE(32) */
1123 #if WSIZE(32)
1124 #if ARCH(Intel) && WSIZE(32)
1125
1126 static int
1127 __collector_open64_symver (int(real_open64) (const char *, int, ...),
1128                            const char *path, int oflag, mode_t mode)
1129 {
1130   int *guard;
1131   int fd;
1132   void *packet;
1133   IOTrace_packet *iopkt;
1134   size_t sz;
1135   unsigned pktSize;
1136   if (NULL_PTR (open64))
1137     init_io_intf ();
1138   if (CHCK_REENTRANCE (guard) || path == NULL)
1139     return (real_open64) (path, oflag, mode);
1140   PUSH_REENTRANCE (guard);
1141   hrtime_t reqt = gethrtime ();
1142   fd = real_open64 (path, oflag, mode);
1143 #else /* ^ARCH(Intel) && WSIZE(32) */
1144
1145 int
1146 open64 (const char *path, int oflag, ...)
1147 {
1148   int *guard;
1149   int fd;
1150   void *packet;
1151   IOTrace_packet *iopkt;
1152   mode_t mode;
1153   va_list ap;
1154   size_t sz;
1155   unsigned pktSize;
1156
1157   va_start (ap, oflag);
1158   mode = va_arg (ap, mode_t);
1159   va_end (ap);
1160   if (NULL_PTR (open64))
1161     init_io_intf ();
1162   if (CHCK_REENTRANCE (guard) || path == NULL)
1163     return CALL_REAL (open64)(path, oflag, mode);
1164   PUSH_REENTRANCE (guard);
1165   hrtime_t reqt = gethrtime ();
1166   fd = CALL_REAL (open64)(path, oflag, mode);
1167 #endif /* ^ARCH(Intel) && WSIZE(32) */
1168
1169   if (RECHCK_REENTRANCE (guard) || path == NULL)
1170     {
1171       POP_REENTRANCE (guard);
1172       return fd;
1173     }
1174   hrtime_t grnt = gethrtime ();
1175   sz = collector_strlen (path);
1176   pktSize = sizeof (IOTrace_packet) + sz;
1177   pktSize = collector_align_pktsize (pktSize);
1178   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1179   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1180   if (packet != NULL)
1181     {
1182       iopkt = (IOTrace_packet *) packet;
1183       collector_memset (iopkt, 0, pktSize);
1184       iopkt->comm.tsize = pktSize;
1185       iopkt->comm.tstamp = grnt;
1186       iopkt->requested = reqt;
1187       if (fd != -1)
1188         iopkt->iotype = OPEN_TRACE;
1189       else
1190         iopkt->iotype = OPEN_TRACE_ERROR;
1191       iopkt->fd = fd;
1192       iopkt->fstype = collector_fstype (path);
1193       collector_strncpy (&(iopkt->fname), path, sz);
1194       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1195       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1196       collector_interface->freeCSize (io_heap, packet, pktSize);
1197     }
1198   else
1199     {
1200       Tprintf (0, "iotrace: ERROR: open64 cannot allocate memory\n");
1201       return -1;
1202     }
1203   POP_REENTRANCE (guard);
1204   return fd;
1205 }
1206 #endif
1207
1208 #define F_ERROR_ARG     0
1209 #define F_INT_ARG       1
1210 #define F_LONG_ARG      2
1211 #define F_VOID_ARG      3
1212
1213 /*
1214  * The following macro is not defined in the
1215  * older versions of Linux.
1216  * #define F_DUPFD_CLOEXEC      1030
1217  *
1218  * Instead use the command that is defined below
1219  * until we start compiling mpmt on the newer
1220  * versions of Linux.
1221  */
1222 #define TMP_F_DUPFD_CLOEXEC 1030
1223
1224 /*------------------------------------------------------------- fcntl */
1225 int
1226 fcntl (int fildes, int cmd, ...)
1227 {
1228   int *guard;
1229   int fd = 0;
1230   IOTrace_packet iopkt;
1231   long long_arg = 0;
1232   int int_arg = 0;
1233   int which_arg = F_ERROR_ARG;
1234   va_list ap;
1235   switch (cmd)
1236     {
1237     case F_DUPFD:
1238     case TMP_F_DUPFD_CLOEXEC:
1239     case F_SETFD:
1240     case F_SETFL:
1241     case F_SETOWN:
1242     case F_SETSIG:
1243     case F_SETLEASE:
1244     case F_NOTIFY:
1245     case F_SETLK:
1246     case F_SETLKW:
1247     case F_GETLK:
1248       va_start (ap, cmd);
1249       long_arg = va_arg (ap, long);
1250       va_end (ap);
1251       which_arg = F_LONG_ARG;
1252       break;
1253     case F_GETFD:
1254     case F_GETFL:
1255     case F_GETOWN:
1256     case F_GETLEASE:
1257     case F_GETSIG:
1258       which_arg = F_VOID_ARG;
1259       break;
1260     }
1261   if (NULL_PTR (fcntl))
1262     init_io_intf ();
1263   if (CHCK_REENTRANCE (guard))
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   if (cmd != F_DUPFD && cmd != TMP_F_DUPFD_CLOEXEC)
1280     {
1281       switch (which_arg)
1282         {
1283         case F_INT_ARG:
1284           return CALL_REAL (fcntl)(fildes, cmd, int_arg);
1285         case F_LONG_ARG:
1286           return CALL_REAL (fcntl)(fildes, cmd, long_arg);
1287         case F_VOID_ARG:
1288           return CALL_REAL (fcntl)(fildes, cmd);
1289         case F_ERROR_ARG:
1290           Tprintf (0, "iotrace: ERROR: Unsupported fcntl command\n");
1291           return -1;
1292         }
1293       return -1;
1294     }
1295   PUSH_REENTRANCE (guard);
1296   hrtime_t reqt = gethrtime ();
1297   switch (cmd)
1298     {
1299     case F_DUPFD:
1300     case TMP_F_DUPFD_CLOEXEC:
1301       fd = CALL_REAL (fcntl)(fildes, cmd, long_arg);
1302       break;
1303     }
1304   if (RECHCK_REENTRANCE (guard))
1305     {
1306       POP_REENTRANCE (guard);
1307       return fd;
1308     }
1309   hrtime_t grnt = gethrtime ();
1310   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1311   iopkt.comm.tsize = sizeof (IOTrace_packet);
1312   iopkt.comm.tstamp = grnt;
1313   iopkt.requested = reqt;
1314   if (fd != -1)
1315     iopkt.iotype = OPEN_TRACE;
1316   else
1317     iopkt.iotype = OPEN_TRACE_ERROR;
1318   iopkt.fd = fd;
1319   iopkt.ofd = fildes;
1320   iopkt.fstype = UNKNOWNFS_TYPE;
1321   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1322   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1323   POP_REENTRANCE (guard);
1324   return fd;
1325 }
1326
1327 /*------------------------------------------------------------- openat */
1328 int
1329 openat (int fildes, const char *path, int oflag, ...)
1330 {
1331   int *guard;
1332   int fd;
1333   void *packet;
1334   IOTrace_packet *iopkt;
1335   mode_t mode;
1336   va_list ap;
1337   size_t sz;
1338   unsigned pktSize;
1339
1340   va_start (ap, oflag);
1341   mode = va_arg (ap, mode_t);
1342   va_end (ap);
1343   if (NULL_PTR (openat))
1344     init_io_intf ();
1345   if (CHCK_REENTRANCE (guard) || path == NULL)
1346     return CALL_REAL (openat)(fildes, path, oflag, mode);
1347   PUSH_REENTRANCE (guard);
1348   hrtime_t reqt = gethrtime ();
1349   fd = CALL_REAL (openat)(fildes, path, oflag, mode);
1350   if (RECHCK_REENTRANCE (guard))
1351     {
1352       POP_REENTRANCE (guard);
1353       return fd;
1354     }
1355   hrtime_t grnt = gethrtime ();
1356   sz = collector_strlen (path);
1357   pktSize = sizeof (IOTrace_packet) + sz;
1358   pktSize = collector_align_pktsize (pktSize);
1359   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1360   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1361   if (packet != NULL)
1362     {
1363       iopkt = (IOTrace_packet *) packet;
1364       collector_memset (iopkt, 0, pktSize);
1365       iopkt->comm.tsize = pktSize;
1366       iopkt->comm.tstamp = grnt;
1367       iopkt->requested = reqt;
1368       if (fd != -1)
1369         iopkt->iotype = OPEN_TRACE;
1370       else
1371         iopkt->iotype = OPEN_TRACE_ERROR;
1372       iopkt->fd = fd;
1373       iopkt->fstype = collector_fstype (path);
1374       collector_strncpy (&(iopkt->fname), path, sz);
1375       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1376       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1377       collector_interface->freeCSize (io_heap, packet, pktSize);
1378     }
1379   else
1380     {
1381       Tprintf (0, "iotrace: ERROR: openat cannot allocate memory\n");
1382       return -1;
1383     }
1384   POP_REENTRANCE (guard);
1385   return fd;
1386 }
1387
1388 /*------------------------------------------------------------- creat */
1389 int
1390 creat (const char *path, mode_t mode)
1391 {
1392   int *guard;
1393   int fd;
1394   void *packet;
1395   IOTrace_packet *iopkt;
1396   size_t sz;
1397   unsigned pktSize;
1398   if (NULL_PTR (creat))
1399     init_io_intf ();
1400   if (CHCK_REENTRANCE (guard) || path == NULL)
1401     return CALL_REAL (creat)(path, mode);
1402   PUSH_REENTRANCE (guard);
1403   hrtime_t reqt = gethrtime ();
1404   fd = CALL_REAL (creat)(path, mode);
1405   if (RECHCK_REENTRANCE (guard))
1406     {
1407       POP_REENTRANCE (guard);
1408       return fd;
1409     }
1410   hrtime_t grnt = gethrtime ();
1411   sz = collector_strlen (path);
1412   pktSize = sizeof (IOTrace_packet) + sz;
1413   pktSize = collector_align_pktsize (pktSize);
1414   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1415   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1416   if (packet != NULL)
1417     {
1418       iopkt = (IOTrace_packet *) packet;
1419       collector_memset (iopkt, 0, pktSize);
1420       iopkt->comm.tsize = pktSize;
1421       iopkt->comm.tstamp = grnt;
1422       iopkt->requested = reqt;
1423       if (fd != -1)
1424         iopkt->iotype = OPEN_TRACE;
1425       else
1426         iopkt->iotype = OPEN_TRACE_ERROR;
1427       iopkt->fd = fd;
1428       iopkt->fstype = collector_fstype (path);
1429       collector_strncpy (&(iopkt->fname), path, sz);
1430       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1431       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1432       collector_interface->freeCSize (io_heap, packet, pktSize);
1433     }
1434   else
1435     {
1436       Tprintf (0, "iotrace: ERROR: creat cannot allocate memory\n");
1437       return -1;
1438     }
1439   POP_REENTRANCE (guard);
1440   return fd;
1441 }
1442
1443 /*------------------------------------------------------------- creat64 */
1444 #if WSIZE(32)
1445 int
1446 creat64 (const char *path, mode_t mode)
1447 {
1448   int *guard;
1449   int fd;
1450   void *packet;
1451   IOTrace_packet *iopkt;
1452   size_t sz;
1453   unsigned pktSize;
1454
1455   if (NULL_PTR (creat64))
1456     init_io_intf ();
1457   if (CHCK_REENTRANCE (guard) || path == NULL)
1458     return CALL_REAL (creat64)(path, mode);
1459   PUSH_REENTRANCE (guard);
1460   hrtime_t reqt = gethrtime ();
1461   fd = CALL_REAL (creat64)(path, mode);
1462   if (RECHCK_REENTRANCE (guard))
1463     {
1464       POP_REENTRANCE (guard);
1465       return fd;
1466     }
1467   hrtime_t grnt = gethrtime ();
1468   sz = collector_strlen (path);
1469   pktSize = sizeof (IOTrace_packet) + sz;
1470   pktSize = collector_align_pktsize (pktSize);
1471   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1472   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1473   if (packet != NULL)
1474     {
1475       iopkt = (IOTrace_packet *) packet;
1476       collector_memset (iopkt, 0, pktSize);
1477       iopkt->comm.tsize = pktSize;
1478       iopkt->comm.tstamp = grnt;
1479       iopkt->requested = reqt;
1480       if (fd != -1)
1481         iopkt->iotype = OPEN_TRACE;
1482       else
1483         iopkt->iotype = OPEN_TRACE_ERROR;
1484       iopkt->fd = fd;
1485       iopkt->fstype = collector_fstype (path);
1486       collector_strncpy (&(iopkt->fname), path, sz);
1487       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1488       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1489       collector_interface->freeCSize (io_heap, packet, pktSize);
1490     }
1491   else
1492     {
1493       Tprintf (0, "iotrace: ERROR: creat64 cannot allocate memory\n");
1494       return -1;
1495     }
1496   POP_REENTRANCE (guard);
1497   return fd;
1498 }
1499 #endif
1500
1501 /*------------------------------------------------------------- mkstemp */
1502 int
1503 mkstemp (char *template)
1504 {
1505   int *guard;
1506   int fd;
1507   void *packet;
1508   IOTrace_packet *iopkt;
1509   size_t sz;
1510   unsigned pktSize;
1511   if (NULL_PTR (mkstemp))
1512     init_io_intf ();
1513   if (CHCK_REENTRANCE (guard) || template == NULL)
1514     return CALL_REAL (mkstemp)(template);
1515   PUSH_REENTRANCE (guard);
1516   hrtime_t reqt = gethrtime ();
1517   fd = CALL_REAL (mkstemp)(template);
1518   if (RECHCK_REENTRANCE (guard))
1519     {
1520       POP_REENTRANCE (guard);
1521       return fd;
1522     }
1523   hrtime_t grnt = gethrtime ();
1524   sz = collector_strlen (template);
1525   pktSize = sizeof (IOTrace_packet) + sz;
1526   pktSize = collector_align_pktsize (pktSize);
1527   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1528   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1529   if (packet != NULL)
1530     {
1531       iopkt = (IOTrace_packet *) packet;
1532       collector_memset (iopkt, 0, pktSize);
1533       iopkt->comm.tsize = pktSize;
1534       iopkt->comm.tstamp = grnt;
1535       iopkt->requested = reqt;
1536       if (fd != -1)
1537         iopkt->iotype = OPEN_TRACE;
1538       else
1539         iopkt->iotype = OPEN_TRACE_ERROR;
1540       iopkt->fd = fd;
1541       iopkt->fstype = collector_fstype (template);
1542       collector_strncpy (&(iopkt->fname), template, sz);
1543       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1544       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1545       collector_interface->freeCSize (io_heap, packet, pktSize);
1546     }
1547   else
1548     {
1549       Tprintf (0, "iotrace: ERROR: mkstemp cannot allocate memory\n");
1550       return -1;
1551     }
1552   POP_REENTRANCE (guard);
1553   return fd;
1554 }
1555
1556 /*------------------------------------------------------------- mkstemps */
1557 int
1558 mkstemps (char *template, int slen)
1559 {
1560   int *guard;
1561   int fd;
1562   void *packet;
1563   IOTrace_packet *iopkt;
1564   size_t sz;
1565   unsigned pktSize;
1566   if (NULL_PTR (mkstemps))
1567     init_io_intf ();
1568   if (CHCK_REENTRANCE (guard) || template == NULL)
1569     return CALL_REAL (mkstemps)(template, slen);
1570   PUSH_REENTRANCE (guard);
1571   hrtime_t reqt = gethrtime ();
1572   fd = CALL_REAL (mkstemps)(template, slen);
1573   if (RECHCK_REENTRANCE (guard))
1574     {
1575       POP_REENTRANCE (guard);
1576       return fd;
1577     }
1578   hrtime_t grnt = gethrtime ();
1579   sz = collector_strlen (template);
1580   pktSize = sizeof (IOTrace_packet) + sz;
1581   pktSize = collector_align_pktsize (pktSize);
1582   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1583   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1584   if (packet != NULL)
1585     {
1586       iopkt = (IOTrace_packet *) packet;
1587       collector_memset (iopkt, 0, pktSize);
1588       iopkt->comm.tsize = pktSize;
1589       iopkt->comm.tstamp = grnt;
1590       iopkt->requested = reqt;
1591       if (fd != -1)
1592         iopkt->iotype = OPEN_TRACE;
1593       else
1594         iopkt->iotype = OPEN_TRACE_ERROR;
1595       iopkt->fd = fd;
1596       iopkt->fstype = collector_fstype (template);
1597       collector_strncpy (&(iopkt->fname), template, sz);
1598       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1599       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1600       collector_interface->freeCSize (io_heap, packet, pktSize);
1601     }
1602   else
1603     {
1604       Tprintf (0, "iotrace: ERROR: mkstemps cannot allocate memory\n");
1605       return -1;
1606     }
1607   POP_REENTRANCE (guard);
1608   return fd;
1609 }
1610
1611 /*------------------------------------------------------------- close */
1612 int
1613 close (int fildes)
1614 {
1615   int *guard;
1616   int stat;
1617   IOTrace_packet iopkt;
1618   if (NULL_PTR (close))
1619     init_io_intf ();
1620   if (CHCK_REENTRANCE (guard))
1621     return CALL_REAL (close)(fildes);
1622   PUSH_REENTRANCE (guard);
1623   hrtime_t reqt = gethrtime ();
1624   stat = CALL_REAL (close)(fildes);
1625   if (RECHCK_REENTRANCE (guard))
1626     {
1627       POP_REENTRANCE (guard);
1628       return stat;
1629     }
1630   hrtime_t grnt = gethrtime ();
1631   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1632   iopkt.comm.tsize = sizeof (IOTrace_packet);
1633   iopkt.comm.tstamp = grnt;
1634   iopkt.requested = reqt;
1635   if (stat == 0)
1636     iopkt.iotype = CLOSE_TRACE;
1637   else
1638     iopkt.iotype = CLOSE_TRACE_ERROR;
1639   iopkt.fd = fildes;
1640   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1641   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1642   POP_REENTRANCE (guard);
1643   return stat;
1644 }
1645
1646 /*------------------------------------------------------------- fopen */
1647 // map interposed symbol versions
1648 #if ARCH(Intel) && WSIZE(32)
1649
1650 static FILE*
1651 __collector_fopen_symver (FILE*(real_fopen) (), const char *filename, const char *mode);
1652
1653 SYMVER_ATTRIBUTE (__collector_fopen_2_1, fopen@GLIBC_2.1)
1654 FILE*
1655 __collector_fopen_2_1 (const char *filename, const char *mode)
1656 {
1657   if (NULL_PTR (fopen))
1658     init_io_intf ();
1659   TprintfT (DBG_LTT, "iotrace: __collector_fopen_2_1@%p\n", CALL_REAL (fopen_2_1));
1660   return __collector_fopen_symver (CALL_REAL (fopen_2_1), filename, mode);
1661 }
1662
1663 SYMVER_ATTRIBUTE (__collector_fopen_2_0, fopen@GLIBC_2.0)
1664 FILE*
1665 __collector_fopen_2_0 (const char *filename, const char *mode)
1666 {
1667   if (NULL_PTR (fopen))
1668     init_io_intf ();
1669   TprintfT (DBG_LTT, "iotrace: __collector_fopen_2_0@%p\n", CALL_REAL (fopen_2_0));
1670   return __collector_fopen_symver (CALL_REAL (fopen_2_0), filename, mode);
1671 }
1672
1673 #endif
1674
1675 #if ARCH(Intel) && WSIZE(32)
1676
1677 static FILE*
1678 __collector_fopen_symver (FILE*(real_fopen) (), const char *filename, const char *mode)
1679 {
1680 #else
1681
1682 FILE*
1683 fopen (const char *filename, const char *mode)
1684 {
1685 #endif
1686   int *guard;
1687   FILE *fp = NULL;
1688   void *packet;
1689   IOTrace_packet *iopkt;
1690   size_t sz;
1691   unsigned pktSize;
1692   if (NULL_PTR (fopen))
1693     init_io_intf ();
1694   if (CHCK_REENTRANCE (guard) || filename == NULL)
1695     {
1696 #if ARCH(Intel) && WSIZE(32)
1697       return (real_fopen) (filename, mode);
1698 #else
1699       return CALL_REAL (fopen)(filename, mode);
1700 #endif
1701     }
1702   PUSH_REENTRANCE (guard);
1703   hrtime_t reqt = gethrtime ();
1704
1705 #if ARCH(Intel) && WSIZE(32)
1706   fp = (real_fopen) (filename, mode);
1707 #else
1708   fp = CALL_REAL (fopen)(filename, mode);
1709 #endif
1710   if (RECHCK_REENTRANCE (guard))
1711     {
1712       POP_REENTRANCE (guard);
1713       return fp;
1714     }
1715   hrtime_t grnt = gethrtime ();
1716   sz = collector_strlen (filename);
1717   pktSize = sizeof (IOTrace_packet) + sz;
1718   pktSize = collector_align_pktsize (pktSize);
1719   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1720   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1721   if (packet != NULL)
1722     {
1723       iopkt = (IOTrace_packet *) packet;
1724       collector_memset (iopkt, 0, pktSize);
1725       iopkt->comm.tsize = pktSize;
1726       iopkt->comm.tstamp = grnt;
1727       iopkt->requested = reqt;
1728       if (fp != NULL)
1729         {
1730           iopkt->iotype = OPEN_TRACE;
1731           iopkt->fd = fileno (fp);
1732         }
1733       else
1734         {
1735           iopkt->iotype = OPEN_TRACE_ERROR;
1736           iopkt->fd = -1;
1737         }
1738       iopkt->fstype = collector_fstype (filename);
1739       collector_strncpy (&(iopkt->fname), filename, sz);
1740
1741 #if ARCH(Intel) && WSIZE(32)
1742       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
1743 #else
1744       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1745 #endif
1746       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1747       collector_interface->freeCSize (io_heap, packet, pktSize);
1748     }
1749   else
1750     {
1751       Tprintf (0, "iotrace: ERROR: fopen cannot allocate memory\n");
1752       return NULL;
1753     }
1754   POP_REENTRANCE (guard);
1755   return fp;
1756 }
1757
1758 /*------------------------------------------------------------- fclose */
1759 // map interposed symbol versions
1760 #if ARCH(Intel) && WSIZE(32)
1761
1762 static int
1763 __collector_fclose_symver (int(real_fclose) (), FILE *stream);
1764
1765 SYMVER_ATTRIBUTE (__collector_fclose_2_1, fclose@GLIBC_2.1)
1766 int
1767 __collector_fclose_2_1 (FILE *stream)
1768 {
1769   if (NULL_PTR (fclose))
1770     init_io_intf ();
1771   TprintfT (DBG_LTT, "iotrace: __collector_fclose_2_1@%p\n", CALL_REAL (fclose_2_1));
1772   return __collector_fclose_symver (CALL_REAL (fclose_2_1), stream);
1773 }
1774
1775 SYMVER_ATTRIBUTE (__collector_fclose_2_0, fclose@GLIBC_2.0)
1776 int
1777 __collector_fclose_2_0 (FILE *stream)
1778 {
1779   if (NULL_PTR (fclose))
1780     init_io_intf ();
1781   TprintfT (DBG_LTT, "iotrace: __collector_fclose_2_0@%p\n", CALL_REAL (fclose_2_0));
1782   return __collector_fclose_symver (CALL_REAL (fclose_2_0), stream);
1783 }
1784
1785 #endif
1786
1787 #if ARCH(Intel) && WSIZE(32)
1788
1789 static int
1790 __collector_fclose_symver (int(real_fclose) (), FILE *stream)
1791 {
1792 #else
1793
1794 int
1795 fclose (FILE *stream)
1796 {
1797 #endif
1798   int *guard;
1799   int stat;
1800   IOTrace_packet iopkt;
1801   if (NULL_PTR (fclose))
1802     init_io_intf ();
1803   if (CHCK_REENTRANCE (guard) || stream == NULL)
1804     {
1805 #if ARCH(Intel) && WSIZE(32)
1806       return (real_fclose) (stream);
1807 #else
1808       return CALL_REAL (fclose)(stream);
1809 #endif
1810     }
1811   PUSH_REENTRANCE (guard);
1812   hrtime_t reqt = gethrtime ();
1813 #if ARCH(Intel) && WSIZE(32)
1814   stat = (real_fclose) (stream);
1815 #else
1816   stat = CALL_REAL (fclose)(stream);
1817 #endif
1818   if (RECHCK_REENTRANCE (guard))
1819     {
1820       POP_REENTRANCE (guard);
1821       return stat;
1822     }
1823   hrtime_t grnt = gethrtime ();
1824   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1825   iopkt.comm.tsize = sizeof (IOTrace_packet);
1826   iopkt.comm.tstamp = grnt;
1827   iopkt.requested = reqt;
1828   if (stat == 0)
1829     iopkt.iotype = CLOSE_TRACE;
1830   else
1831     iopkt.iotype = CLOSE_TRACE_ERROR;
1832   iopkt.fd = fileno (stream);
1833
1834 #if ARCH(Intel) && WSIZE(32)
1835   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
1836 #else
1837   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1838 #endif
1839   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1840   POP_REENTRANCE (guard);
1841   return stat;
1842 }
1843
1844 /*------------------------------------------------------------- fflush */
1845 int
1846 fflush (FILE *stream)
1847 {
1848   int *guard;
1849   int stat;
1850   IOTrace_packet iopkt;
1851   if (NULL_PTR (fflush))
1852     init_io_intf ();
1853   if (CHCK_REENTRANCE (guard))
1854     return CALL_REAL (fflush)(stream);
1855   PUSH_REENTRANCE (guard);
1856   hrtime_t reqt = gethrtime ();
1857   stat = CALL_REAL (fflush)(stream);
1858   if (RECHCK_REENTRANCE (guard))
1859     {
1860       POP_REENTRANCE (guard);
1861       return stat;
1862     }
1863   hrtime_t grnt = gethrtime ();
1864   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1865   iopkt.comm.tsize = sizeof (IOTrace_packet);
1866   iopkt.comm.tstamp = grnt;
1867   iopkt.requested = reqt;
1868   if (stat == 0)
1869     iopkt.iotype = OTHERIO_TRACE;
1870   else
1871     iopkt.iotype = OTHERIO_TRACE_ERROR;
1872   if (stream != NULL)
1873     iopkt.fd = fileno (stream);
1874   else
1875     iopkt.fd = -1;
1876   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1877   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1878   POP_REENTRANCE (guard);
1879   return stat;
1880 }
1881
1882 /*------------------------------------------------------------- fdopen */
1883 // map interposed symbol versions
1884 #if ARCH(Intel) && WSIZE(32)
1885
1886 static FILE*
1887 __collector_fdopen_symver (FILE*(real_fdopen) (), int fildes, const char *mode);
1888
1889 SYMVER_ATTRIBUTE (__collector_fdopen_2_1, fdopen@GLIBC_2.1)
1890 FILE*
1891 __collector_fdopen_2_1 (int fildes, const char *mode)
1892 {
1893   if (NULL_PTR (fdopen))
1894     init_io_intf ();
1895   TprintfT (DBG_LTT, "iotrace: __collector_fdopen_2_1@%p\n", CALL_REAL (fdopen_2_1));
1896   return __collector_fdopen_symver (CALL_REAL (fdopen_2_1), fildes, mode);
1897 }
1898
1899 SYMVER_ATTRIBUTE (__collector_fdopen_2_0, fdopen@GLIBC_2.0)
1900 FILE*
1901 __collector_fdopen_2_0 (int fildes, const char *mode)
1902 {
1903   if (NULL_PTR (fdopen))
1904     init_io_intf ();
1905   TprintfT (DBG_LTT, "iotrace: __collector_fdopen_2_0@%p\n", CALL_REAL (fdopen_2_0));
1906   return __collector_fdopen_symver (CALL_REAL (fdopen_2_0), fildes, mode);
1907 }
1908
1909 #endif
1910
1911 #if ARCH(Intel) && WSIZE(32)
1912 static FILE*
1913 __collector_fdopen_symver (FILE*(real_fdopen) (), int fildes, const char *mode)
1914 {
1915 #else
1916 FILE*
1917 fdopen (int fildes, const char *mode)
1918 {
1919 #endif
1920   int *guard;
1921   FILE *fp = NULL;
1922   IOTrace_packet iopkt;
1923   if (NULL_PTR (fdopen))
1924     init_io_intf ();
1925   if (CHCK_REENTRANCE (guard))
1926     {
1927 #if ARCH(Intel) && WSIZE(32)
1928       return (real_fdopen) (fildes, mode);
1929 #else
1930       return CALL_REAL (fdopen)(fildes, mode);
1931 #endif
1932     }
1933   PUSH_REENTRANCE (guard);
1934   hrtime_t reqt = gethrtime ();
1935 #if ARCH(Intel) && WSIZE(32)
1936   fp = (real_fdopen) (fildes, mode);
1937 #else
1938   fp = CALL_REAL (fdopen)(fildes, mode);
1939 #endif
1940   if (RECHCK_REENTRANCE (guard))
1941     {
1942       POP_REENTRANCE (guard);
1943       return fp;
1944     }
1945   hrtime_t grnt = gethrtime ();
1946   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1947   iopkt.comm.tsize = sizeof (IOTrace_packet);
1948   iopkt.comm.tstamp = grnt;
1949   iopkt.requested = reqt;
1950   if (fp != NULL)
1951     iopkt.iotype = OPEN_TRACE;
1952   else
1953     iopkt.iotype = OPEN_TRACE_ERROR;
1954   iopkt.fd = fildes;
1955   iopkt.fstype = UNKNOWNFS_TYPE;
1956 #if ARCH(Intel) && WSIZE(32)
1957   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
1958 #else
1959   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1960 #endif
1961   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1962   POP_REENTRANCE (guard);
1963   return fp;
1964 }
1965
1966 /*------------------------------------------------------------- dup */
1967 int
1968 dup (int fildes)
1969 {
1970   int *guard;
1971   int fd;
1972   IOTrace_packet iopkt;
1973   if (NULL_PTR (dup))
1974     init_io_intf ();
1975   if (CHCK_REENTRANCE (guard))
1976     return CALL_REAL (dup)(fildes);
1977   PUSH_REENTRANCE (guard);
1978   hrtime_t reqt = gethrtime ();
1979   fd = CALL_REAL (dup)(fildes);
1980   if (RECHCK_REENTRANCE (guard))
1981     {
1982       POP_REENTRANCE (guard);
1983       return fd;
1984     }
1985   hrtime_t grnt = gethrtime ();
1986   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1987   iopkt.comm.tsize = sizeof (IOTrace_packet);
1988   iopkt.comm.tstamp = grnt;
1989   iopkt.requested = reqt;
1990   if (fd != -1)
1991     iopkt.iotype = OPEN_TRACE;
1992   else
1993     iopkt.iotype = OPEN_TRACE_ERROR;
1994
1995   iopkt.fd = fd;
1996   iopkt.ofd = fildes;
1997   iopkt.fstype = UNKNOWNFS_TYPE;
1998   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1999   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2000   POP_REENTRANCE (guard);
2001   return fd;
2002 }
2003
2004 /*------------------------------------------------------------- dup2 */
2005 int
2006 dup2 (int fildes, int fildes2)
2007 {
2008   int *guard;
2009   int fd;
2010   IOTrace_packet iopkt;
2011   if (NULL_PTR (dup2))
2012     init_io_intf ();
2013   if (CHCK_REENTRANCE (guard))
2014     return CALL_REAL (dup2)(fildes, fildes2);
2015   PUSH_REENTRANCE (guard);
2016   hrtime_t reqt = gethrtime ();
2017   fd = CALL_REAL (dup2)(fildes, fildes2);
2018   if (RECHCK_REENTRANCE (guard))
2019     {
2020       POP_REENTRANCE (guard);
2021       return fd;
2022     }
2023   hrtime_t grnt = gethrtime ();
2024   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2025   iopkt.comm.tsize = sizeof (IOTrace_packet);
2026   iopkt.comm.tstamp = grnt;
2027   iopkt.requested = reqt;
2028   if (fd != -1)
2029     iopkt.iotype = OPEN_TRACE;
2030   else
2031     iopkt.iotype = OPEN_TRACE_ERROR;
2032   iopkt.fd = fd;
2033   iopkt.ofd = fildes;
2034   iopkt.fstype = UNKNOWNFS_TYPE;
2035   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2036   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2037   POP_REENTRANCE (guard);
2038   return fd;
2039 }
2040
2041 /*------------------------------------------------------------- pipe */
2042 int
2043 pipe (int fildes[2])
2044 {
2045   int *guard;
2046   int ret;
2047   IOTrace_packet iopkt;
2048   if (NULL_PTR (pipe))
2049     init_io_intf ();
2050   if (CHCK_REENTRANCE (guard))
2051     return CALL_REAL (pipe)(fildes);
2052   PUSH_REENTRANCE (guard);
2053   hrtime_t reqt = gethrtime ();
2054   ret = CALL_REAL (pipe)(fildes);
2055   if (RECHCK_REENTRANCE (guard))
2056     {
2057       POP_REENTRANCE (guard);
2058       return ret;
2059     }
2060   hrtime_t grnt = gethrtime ();
2061   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2062   iopkt.comm.tsize = sizeof (IOTrace_packet);
2063   iopkt.comm.tstamp = grnt;
2064   iopkt.requested = reqt;
2065   if (ret != -1)
2066     iopkt.iotype = OPEN_TRACE;
2067   else
2068     iopkt.iotype = OPEN_TRACE_ERROR;
2069   iopkt.fd = fildes[0];
2070   iopkt.fstype = UNKNOWNFS_TYPE;
2071   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2072   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2073   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2074   iopkt.comm.tsize = sizeof (IOTrace_packet);
2075   iopkt.comm.tstamp = grnt;
2076   iopkt.requested = reqt;
2077   if (ret != -1)
2078     iopkt.iotype = OPEN_TRACE;
2079   else
2080     iopkt.iotype = OPEN_TRACE_ERROR;
2081   iopkt.fd = fildes[1];
2082   iopkt.fstype = UNKNOWNFS_TYPE;
2083   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2084   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2085   POP_REENTRANCE (guard);
2086   return ret;
2087 }
2088
2089 /*------------------------------------------------------------- socket */
2090 int
2091 socket (int domain, int type, int protocol)
2092 {
2093   int *guard;
2094   int fd;
2095   IOTrace_packet iopkt;
2096   if (NULL_PTR (socket))
2097     init_io_intf ();
2098   if (CHCK_REENTRANCE (guard))
2099     return CALL_REAL (socket)(domain, type, protocol);
2100   PUSH_REENTRANCE (guard);
2101   hrtime_t reqt = gethrtime ();
2102   fd = CALL_REAL (socket)(domain, type, protocol);
2103   if (RECHCK_REENTRANCE (guard))
2104     {
2105       POP_REENTRANCE (guard);
2106       return fd;
2107     }
2108   hrtime_t grnt = gethrtime ();
2109   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2110   iopkt.comm.tsize = sizeof (IOTrace_packet);
2111   iopkt.comm.tstamp = grnt;
2112   iopkt.requested = reqt;
2113   if (fd != -1)
2114     iopkt.iotype = OPEN_TRACE;
2115   else
2116     iopkt.iotype = OPEN_TRACE_ERROR;
2117   iopkt.fd = fd;
2118   iopkt.fstype = UNKNOWNFS_TYPE;
2119   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2120   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2121   POP_REENTRANCE (guard);
2122   return fd;
2123 }
2124
2125 /*------------------------------------------------------------- read */
2126 ssize_t
2127 read (int fildes, void *buf, size_t nbyte)
2128 {
2129   int *guard;
2130   ssize_t ret;
2131   IOTrace_packet iopkt;
2132   if (NULL_PTR (read))
2133     init_io_intf ();
2134   if (CHCK_REENTRANCE (guard))
2135     return CALL_REAL (read)(fildes, buf, nbyte);
2136   PUSH_REENTRANCE (guard);
2137   hrtime_t reqt = gethrtime ();
2138   ret = CALL_REAL (read)(fildes, buf, nbyte);
2139   if (RECHCK_REENTRANCE (guard))
2140     {
2141       POP_REENTRANCE (guard);
2142       return ret;
2143     }
2144   hrtime_t grnt = gethrtime ();
2145   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2146   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2147   iopkt.comm.tstamp = grnt;
2148   iopkt.requested = reqt;
2149   if (ret >= 0)
2150     iopkt.iotype = READ_TRACE;
2151   else
2152     iopkt.iotype = READ_TRACE_ERROR;
2153   iopkt.fd = fildes;
2154   iopkt.nbyte = ret;
2155   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2156   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2157   POP_REENTRANCE (guard);
2158   return ret;
2159 }
2160
2161 /*------------------------------------------------------------- write */
2162 ssize_t
2163 write (int fildes, const void *buf, size_t nbyte)
2164 {
2165   int *guard;
2166   ssize_t ret;
2167   IOTrace_packet iopkt;
2168   if (NULL_PTR (write))
2169     init_io_intf ();
2170   if (CHCK_REENTRANCE (guard))
2171     return CALL_REAL (write)(fildes, buf, nbyte);
2172   PUSH_REENTRANCE (guard);
2173   hrtime_t reqt = gethrtime ();
2174   ret = CALL_REAL (write)(fildes, buf, nbyte);
2175   if (RECHCK_REENTRANCE (guard))
2176     {
2177       POP_REENTRANCE (guard);
2178       return ret;
2179     }
2180   hrtime_t grnt = gethrtime ();
2181   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2182   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2183   iopkt.comm.tstamp = grnt;
2184   iopkt.requested = reqt;
2185   if (ret >= 0)
2186     iopkt.iotype = WRITE_TRACE;
2187   else
2188     iopkt.iotype = WRITE_TRACE_ERROR;
2189   iopkt.fd = fildes;
2190   iopkt.nbyte = ret;
2191   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2192   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2193   POP_REENTRANCE (guard);
2194   return ret;
2195 }
2196
2197 /*------------------------------------------------------------- readv */
2198 ssize_t
2199 readv (int fildes, const struct iovec *iov, int iovcnt)
2200 {
2201   int *guard;
2202   ssize_t ret;
2203   IOTrace_packet iopkt;
2204   if (NULL_PTR (readv))
2205     init_io_intf ();
2206   if (CHCK_REENTRANCE (guard))
2207     return CALL_REAL (readv)(fildes, iov, iovcnt);
2208   PUSH_REENTRANCE (guard);
2209   hrtime_t reqt = gethrtime ();
2210   ret = CALL_REAL (readv)(fildes, iov, iovcnt);
2211   if (RECHCK_REENTRANCE (guard))
2212     {
2213       POP_REENTRANCE (guard);
2214       return ret;
2215     }
2216   hrtime_t grnt = gethrtime ();
2217   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2218   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2219   iopkt.comm.tstamp = grnt;
2220   iopkt.requested = reqt;
2221   if (ret >= 0)
2222     iopkt.iotype = READ_TRACE;
2223   else
2224     iopkt.iotype = READ_TRACE_ERROR;
2225   iopkt.fd = fildes;
2226   iopkt.nbyte = ret;
2227   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2228   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2229   POP_REENTRANCE (guard);
2230   return ret;
2231 }
2232
2233 /*------------------------------------------------------------- writev */
2234 ssize_t
2235 writev (int fildes, const struct iovec *iov, int iovcnt)
2236 {
2237   int *guard;
2238   ssize_t ret;
2239   IOTrace_packet iopkt;
2240   if (NULL_PTR (writev))
2241     init_io_intf ();
2242   if (CHCK_REENTRANCE (guard))
2243     return CALL_REAL (writev)(fildes, iov, iovcnt);
2244   PUSH_REENTRANCE (guard);
2245   hrtime_t reqt = gethrtime ();
2246   ret = CALL_REAL (writev)(fildes, iov, iovcnt);
2247   if (RECHCK_REENTRANCE (guard))
2248     {
2249       POP_REENTRANCE (guard);
2250       return ret;
2251     }
2252   hrtime_t grnt = gethrtime ();
2253   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2254   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2255   iopkt.comm.tstamp = grnt;
2256   iopkt.requested = reqt;
2257   if (ret >= 0)
2258     iopkt.iotype = WRITE_TRACE;
2259   else
2260     iopkt.iotype = WRITE_TRACE_ERROR;
2261   iopkt.fd = fildes;
2262   iopkt.nbyte = ret;
2263   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2264   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2265   POP_REENTRANCE (guard);
2266   return ret;
2267 }
2268
2269 /*------------------------------------------------------------- fread */
2270 size_t
2271 fread (void *ptr, size_t size, size_t nitems, FILE *stream)
2272 {
2273   int *guard;
2274   size_t ret;
2275   IOTrace_packet iopkt;
2276   if (NULL_PTR (fread))
2277     init_io_intf ();
2278   if (CHCK_REENTRANCE (guard) || stream == NULL)
2279     return CALL_REAL (fread)(ptr, size, nitems, stream);
2280   PUSH_REENTRANCE (guard);
2281   hrtime_t reqt = gethrtime ();
2282   ret = CALL_REAL (fread)(ptr, size, nitems, stream);
2283   if (RECHCK_REENTRANCE (guard))
2284     {
2285       POP_REENTRANCE (guard);
2286       return ret;
2287     }
2288   hrtime_t grnt = gethrtime ();
2289   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2290   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2291   iopkt.comm.tstamp = grnt;
2292   iopkt.requested = reqt;
2293   if (ferror (stream) == 0)
2294     {
2295       iopkt.iotype = READ_TRACE;
2296       iopkt.nbyte = ret * size;
2297     }
2298   else
2299     {
2300       iopkt.iotype = READ_TRACE_ERROR;
2301       iopkt.nbyte = 0;
2302     }
2303   iopkt.fd = fileno (stream);
2304   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2305   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2306   POP_REENTRANCE (guard);
2307   return ret;
2308 }
2309
2310 /*------------------------------------------------------------- fwrite */
2311 size_t
2312 fwrite (const void *ptr, size_t size, size_t nitems, FILE *stream)
2313 {
2314   int *guard;
2315   size_t ret;
2316   IOTrace_packet iopkt;
2317   if (NULL_PTR (fwrite))
2318     init_io_intf ();
2319   if (CHCK_REENTRANCE (guard) || stream == NULL)
2320     return CALL_REAL (fwrite)(ptr, size, nitems, stream);
2321   PUSH_REENTRANCE (guard);
2322   hrtime_t reqt = gethrtime ();
2323   ret = CALL_REAL (fwrite)(ptr, size, nitems, stream);
2324   if (RECHCK_REENTRANCE (guard))
2325     {
2326       POP_REENTRANCE (guard);
2327       return ret;
2328     }
2329   hrtime_t grnt = gethrtime ();
2330   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2331   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2332   iopkt.comm.tstamp = grnt;
2333   iopkt.requested = reqt;
2334   if (ferror (stream) == 0)
2335     {
2336       iopkt.iotype = WRITE_TRACE;
2337       iopkt.nbyte = ret * size;
2338     }
2339   else
2340     {
2341       iopkt.iotype = WRITE_TRACE_ERROR;
2342       iopkt.nbyte = 0;
2343     }
2344   iopkt.fd = fileno (stream);
2345   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2346   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2347   POP_REENTRANCE (guard);
2348   return ret;
2349 }
2350
2351 /*------------------------------------------------------------- pread */
2352 #if ARCH(Intel) && WSIZE(32)
2353 // map interposed symbol versions
2354 static int
2355 __collector_pread_symver (int(real_pread) (), int fildes, void *buf, size_t nbyte, off_t offset);
2356
2357 SYMVER_ATTRIBUTE (__collector_pread_2_2, pread@GLIBC_2.2)
2358 int
2359 __collector_pread_2_2 (int fildes, void *buf, size_t nbyte, off_t offset)
2360 {
2361   TprintfT (DBG_LTT, "iotrace: __collector_pread_2_2@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
2362             CALL_REAL (pread_2_2), fildes, buf, (long long) nbyte, (long long) offset);
2363   if (NULL_PTR (pread))
2364     init_io_intf ();
2365   return __collector_pread_symver (CALL_REAL (pread_2_2), fildes, buf, nbyte, offset);
2366 }
2367
2368 SYMVER_ATTRIBUTE (__collector_pread_2_1, pread@GLIBC_2.1)
2369 int
2370 __collector_pread_2_1 (int fildes, void *buf, size_t nbyte, off_t offset)
2371 {
2372   TprintfT (DBG_LTT, "iotrace: __collector_pread_2_1@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
2373             CALL_REAL (pread_2_1), fildes, buf, (long long) nbyte, (long long) offset);
2374   if (NULL_PTR (pread))
2375     init_io_intf ();
2376   return __collector_pread_symver (CALL_REAL (pread_2_1), fildes, buf, nbyte, offset);
2377 }
2378
2379 static int
2380 __collector_pread_symver (int(real_pread) (), int fildes, void *buf, size_t nbyte, off_t offset)
2381 {
2382 #else /* ^ARCH(Intel) && WSIZE(32) */
2383
2384 ssize_t
2385 pread (int fildes, void *buf, size_t nbyte, off_t offset)
2386 {
2387 #endif
2388   int *guard;
2389   ssize_t ret;
2390   IOTrace_packet iopkt;
2391   if (NULL_PTR (pread))
2392     init_io_intf ();
2393   if (CHCK_REENTRANCE (guard))
2394     {
2395 #if ARCH(Intel) && WSIZE(32)
2396       return (real_pread) (fildes, buf, nbyte, offset);
2397 #else
2398       return CALL_REAL (pread)(fildes, buf, nbyte, offset);
2399 #endif
2400     }
2401   PUSH_REENTRANCE (guard);
2402   hrtime_t reqt = gethrtime ();
2403 #if ARCH(Intel) && WSIZE(32)
2404   ret = (real_pread) (fildes, buf, nbyte, offset);
2405 #else
2406   ret = CALL_REAL (pread)(fildes, buf, nbyte, offset);
2407 #endif
2408   if (RECHCK_REENTRANCE (guard))
2409     {
2410       POP_REENTRANCE (guard);
2411       return ret;
2412     }
2413   hrtime_t grnt = gethrtime ();
2414   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2415   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2416   iopkt.comm.tstamp = grnt;
2417   iopkt.requested = reqt;
2418   if (ret >= 0)
2419     iopkt.iotype = READ_TRACE;
2420   else
2421     iopkt.iotype = READ_TRACE_ERROR;
2422   iopkt.fd = fildes;
2423   iopkt.nbyte = ret;
2424   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2425   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2426   POP_REENTRANCE (guard);
2427   return ret;
2428 }
2429
2430 /*------------------------------------------------------------- pwrite */
2431
2432 #if !defined(__MUSL_LIBC) && ARCH(Intel) && WSIZE(32)
2433 // map interposed symbol versions
2434
2435 SYMVER_ATTRIBUTE (__collector_pwrite_2_2, pwrite@GLIBC_2.2)
2436 int
2437 __collector_pwrite_2_2 (int fildes, const void *buf, size_t nbyte, off_t offset)
2438 {
2439   int *guard;
2440   if (NULL_PTR (pwrite_2_2))
2441     init_io_intf ();
2442   if (CHCK_REENTRANCE (guard))
2443     return CALL_REAL (pwrite_2_2)(fildes, buf, nbyte, offset);
2444   PUSH_REENTRANCE (guard);
2445   hrtime_t reqt = gethrtime ();
2446   ssize_t ret = CALL_REAL (pwrite_2_2)(fildes, buf, nbyte, offset);
2447   if (RECHCK_REENTRANCE (guard))
2448     {
2449       POP_REENTRANCE (guard);
2450       return ret;
2451     }
2452   write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2453   POP_REENTRANCE (guard);
2454   return ret;
2455 }
2456
2457 SYMVER_ATTRIBUTE (__collector_pwrite_2_1, pwrite@GLIBC_2.1)
2458 int
2459 __collector_pwrite_2_1 (int fildes, const void *buf, size_t nbyte, off_t offset)
2460 {
2461   int *guard;
2462   if (NULL_PTR (pwrite_2_1))
2463     init_io_intf ();
2464   if (CHCK_REENTRANCE (guard))
2465     return CALL_REAL (pwrite_2_1)(fildes, buf, nbyte, offset);
2466   PUSH_REENTRANCE (guard);
2467   hrtime_t reqt = gethrtime ();
2468   ssize_t ret = CALL_REAL (pwrite_2_1)(fildes, buf, nbyte, offset);
2469   if (RECHCK_REENTRANCE (guard))
2470     {
2471       POP_REENTRANCE (guard);
2472       return ret;
2473     }
2474   write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2475   POP_REENTRANCE (guard);
2476   return ret;
2477 }
2478
2479 #else
2480 ssize_t
2481 pwrite (int fildes, const void *buf, size_t nbyte, off_t offset)
2482 {
2483   int *guard;
2484   if (NULL_PTR (pwrite))
2485     init_io_intf ();
2486   if (CHCK_REENTRANCE (guard))
2487     return CALL_REAL (pwrite)(fildes, buf, nbyte, offset);
2488   PUSH_REENTRANCE (guard);
2489   hrtime_t reqt = gethrtime ();
2490   ssize_t ret = CALL_REAL (pwrite)(fildes, buf, nbyte, offset);
2491   if (RECHCK_REENTRANCE (guard))
2492     {
2493       POP_REENTRANCE (guard);
2494       return ret;
2495     }
2496   write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2497   POP_REENTRANCE (guard);
2498   return ret;
2499 }
2500 #endif
2501
2502 /*------------------------------------------------------------- pwrite64 */
2503 #if WSIZE(32)
2504 #if !defined(__MUSL_LIBC) && ARCH(Intel)
2505 // map interposed symbol versions
2506
2507 SYMVER_ATTRIBUTE (__collector_pwrite64_2_2, pwrite64@GLIBC_2.2)
2508 ssize_t
2509 __collector_pwrite64_2_2 (int fildes, const void *buf, size_t nbyte, off64_t offset)
2510 {
2511   int *guard;
2512   if (NULL_PTR (pwrite64_2_2))
2513     init_io_intf ();
2514   if (CHCK_REENTRANCE (guard))
2515     return CALL_REAL (pwrite64_2_2)(fildes, buf, nbyte, offset);
2516   PUSH_REENTRANCE (guard);
2517   hrtime_t reqt = gethrtime ();
2518   ssize_t ret = CALL_REAL (pwrite64_2_2)(fildes, buf, nbyte, offset);
2519   if (RECHCK_REENTRANCE (guard))
2520     {
2521       POP_REENTRANCE (guard);
2522       return ret;
2523     }
2524   write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2525   POP_REENTRANCE (guard);
2526   return ret;
2527 }
2528
2529 SYMVER_ATTRIBUTE (__collector_pwrite64_2_1, pwrite64@GLIBC_2.1)
2530 int
2531 __collector_pwrite64_2_1 (int fildes, const void *buf, size_t nbyte, off64_t offset)
2532 {
2533   int *guard;
2534   if (NULL_PTR (pwrite64_2_1))
2535     init_io_intf ();
2536   if (CHCK_REENTRANCE (guard))
2537     return CALL_REAL (pwrite64_2_1)(fildes, buf, nbyte, offset);
2538   PUSH_REENTRANCE (guard);
2539   hrtime_t reqt = gethrtime ();
2540   ssize_t ret = CALL_REAL (pwrite64_2_1)(fildes, buf, nbyte, offset);
2541   if (RECHCK_REENTRANCE (guard))
2542     {
2543       POP_REENTRANCE (guard);
2544       return ret;
2545     }
2546   write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2547   POP_REENTRANCE (guard);
2548   return ret;
2549 }
2550
2551 #else
2552 ssize_t
2553 pwrite64 (int fildes, const void *buf, size_t nbyte, off64_t offset)
2554 {
2555   int *guard;
2556   if (NULL_PTR (pwrite64))
2557     init_io_intf ();
2558   if (CHCK_REENTRANCE (guard))
2559     return CALL_REAL (pwrite64)(fildes, buf, nbyte, offset);
2560   PUSH_REENTRANCE (guard);
2561   hrtime_t reqt = gethrtime ();
2562   ssize_t ret = CALL_REAL (pwrite64)(fildes, buf, nbyte, offset);
2563   if (RECHCK_REENTRANCE (guard))
2564     {
2565       POP_REENTRANCE (guard);
2566       return ret;
2567     }
2568   write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2569   POP_REENTRANCE (guard);
2570   return ret;
2571 }
2572 #endif
2573 #endif /* SIZE(32) */
2574
2575 /*------------------------------------------------------------- fgets */
2576 char*
2577 fgets (char *s, int n, FILE *stream)
2578 {
2579   int *guard;
2580   char *ptr;
2581   IOTrace_packet iopkt;
2582   if (NULL_PTR (fgets))
2583     init_io_intf ();
2584   if (CHCK_REENTRANCE (guard) || stream == NULL)
2585     return CALL_REAL (fgets)(s, n, stream);
2586   PUSH_REENTRANCE (guard);
2587   hrtime_t reqt = gethrtime ();
2588   ptr = CALL_REAL (fgets)(s, n, stream);
2589   if (RECHCK_REENTRANCE (guard))
2590     {
2591       POP_REENTRANCE (guard);
2592       return ptr;
2593     }
2594   int error = errno;
2595   hrtime_t grnt = gethrtime ();
2596   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2597   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2598   iopkt.comm.tstamp = grnt;
2599   iopkt.requested = reqt;
2600   if (ptr != NULL)
2601     {
2602       iopkt.iotype = READ_TRACE;
2603       iopkt.nbyte = collector_strlen (ptr);
2604     }
2605   else if (ptr == NULL && error != EAGAIN && error != EBADF && error != EINTR &&
2606            error != EIO && error != EOVERFLOW && error != ENOMEM && error != ENXIO)
2607     {
2608       iopkt.iotype = READ_TRACE;
2609       iopkt.nbyte = 0;
2610     }
2611   else
2612     iopkt.iotype = READ_TRACE_ERROR;
2613   iopkt.fd = fileno (stream);
2614   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2615   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2616   POP_REENTRANCE (guard);
2617   return ptr;
2618 }
2619
2620 /*------------------------------------------------------------- fputs */
2621 int
2622 fputs (const char *s, FILE *stream)
2623 {
2624   int *guard;
2625   int ret;
2626   IOTrace_packet iopkt;
2627   if (NULL_PTR (fputs))
2628     init_io_intf ();
2629   if (CHCK_REENTRANCE (guard) || stream == NULL)
2630     return CALL_REAL (fputs)(s, stream);
2631   PUSH_REENTRANCE (guard);
2632   hrtime_t reqt = gethrtime ();
2633   ret = CALL_REAL (fputs)(s, stream);
2634   if (RECHCK_REENTRANCE (guard))
2635     {
2636       POP_REENTRANCE (guard);
2637       return ret;
2638     }
2639   hrtime_t grnt = gethrtime ();
2640   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2641   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2642   iopkt.comm.tstamp = grnt;
2643   iopkt.requested = reqt;
2644   if (ret != EOF)
2645     {
2646       iopkt.iotype = WRITE_TRACE;
2647       iopkt.nbyte = ret;
2648     }
2649   else
2650     {
2651       iopkt.iotype = WRITE_TRACE_ERROR;
2652       iopkt.nbyte = 0;
2653     }
2654   iopkt.fd = fileno (stream);
2655   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2656   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2657   POP_REENTRANCE (guard);
2658   return ret;
2659 }
2660
2661 /*------------------------------------------------------------- fputc */
2662 int
2663 fputc (int c, FILE *stream)
2664 {
2665   int *guard;
2666   int ret;
2667   IOTrace_packet iopkt;
2668   if (NULL_PTR (fputc))
2669     init_io_intf ();
2670   if (CHCK_REENTRANCE (guard) || stream == NULL)
2671     return CALL_REAL (fputc)(c, stream);
2672   PUSH_REENTRANCE (guard);
2673   hrtime_t reqt = gethrtime ();
2674   ret = CALL_REAL (fputc)(c, stream);
2675   if (RECHCK_REENTRANCE (guard))
2676     {
2677       POP_REENTRANCE (guard);
2678       return ret;
2679     }
2680   hrtime_t grnt = gethrtime ();
2681   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2682   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2683   iopkt.comm.tstamp = grnt;
2684   iopkt.requested = reqt;
2685   if (ret != EOF)
2686     {
2687       iopkt.iotype = WRITE_TRACE;
2688       iopkt.nbyte = ret;
2689     }
2690   else
2691     {
2692       iopkt.iotype = WRITE_TRACE_ERROR;
2693       iopkt.nbyte = 0;
2694     }
2695   iopkt.fd = fileno (stream);
2696   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2697   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2698   POP_REENTRANCE (guard);
2699   return ret;
2700 }
2701
2702 /*------------------------------------------------------------- fprintf */
2703 int
2704 fprintf (FILE *stream, const char *format, ...)
2705 {
2706   int *guard;
2707   int ret;
2708   IOTrace_packet iopkt;
2709   va_list ap;
2710   va_start (ap, format);
2711   if (NULL_PTR (fprintf))
2712     init_io_intf ();
2713   if (NULL_PTR (vfprintf))
2714     init_io_intf ();
2715   if (CHCK_REENTRANCE (guard) || stream == NULL)
2716     return CALL_REAL (vfprintf)(stream, format, ap);
2717   PUSH_REENTRANCE (guard);
2718   hrtime_t reqt = gethrtime ();
2719   ret = CALL_REAL (vfprintf)(stream, format, ap);
2720   if (RECHCK_REENTRANCE (guard))
2721     {
2722       POP_REENTRANCE (guard);
2723       return ret;
2724     }
2725   hrtime_t grnt = gethrtime ();
2726   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2727   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2728   iopkt.comm.tstamp = grnt;
2729   iopkt.requested = reqt;
2730   if (ret >= 0)
2731     iopkt.iotype = WRITE_TRACE;
2732   else
2733     iopkt.iotype = WRITE_TRACE_ERROR;
2734   iopkt.fd = fileno (stream);
2735   iopkt.nbyte = ret;
2736   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2737   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2738   POP_REENTRANCE (guard);
2739   return ret;
2740 }
2741
2742 /*------------------------------------------------------------- vfprintf */
2743 int
2744 vfprintf (FILE *stream, const char *format, va_list ap)
2745 {
2746   int *guard;
2747   int ret;
2748   IOTrace_packet iopkt;
2749   if (NULL_PTR (vfprintf))
2750     init_io_intf ();
2751   if (CHCK_REENTRANCE (guard) || stream == NULL)
2752     return CALL_REAL (vfprintf)(stream, format, ap);
2753   PUSH_REENTRANCE (guard);
2754   hrtime_t reqt = gethrtime ();
2755   ret = CALL_REAL (vfprintf)(stream, format, ap);
2756   if (RECHCK_REENTRANCE (guard))
2757     {
2758       POP_REENTRANCE (guard);
2759       return ret;
2760     }
2761   hrtime_t grnt = gethrtime ();
2762   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2763   iopkt.comm.tsize = sizeof ( IOTrace_packet);
2764   iopkt.comm.tstamp = grnt;
2765   iopkt.requested = reqt;
2766   if (ret >= 0)
2767     iopkt.iotype = WRITE_TRACE;
2768   else
2769     iopkt.iotype = WRITE_TRACE_ERROR;
2770   iopkt.fd = fileno (stream);
2771   iopkt.nbyte = ret;
2772   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2773   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2774   POP_REENTRANCE (guard);
2775   return ret;
2776 }
2777
2778 /*------------------------------------------------------------- lseek */
2779 off_t
2780 lseek (int fildes, off_t offset, int whence)
2781 {
2782   int *guard;
2783   off_t ret;
2784   IOTrace_packet iopkt;
2785   if (NULL_PTR (lseek))
2786     init_io_intf ();
2787   if (CHCK_REENTRANCE (guard))
2788     return CALL_REAL (lseek)(fildes, offset, whence);
2789   PUSH_REENTRANCE (guard);
2790   hrtime_t reqt = gethrtime ();
2791   ret = CALL_REAL (lseek)(fildes, offset, whence);
2792   if (RECHCK_REENTRANCE (guard))
2793     {
2794       POP_REENTRANCE (guard);
2795       return ret;
2796     }
2797   hrtime_t grnt = gethrtime ();
2798   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2799   iopkt.comm.tsize = sizeof (IOTrace_packet);
2800   iopkt.comm.tstamp = grnt;
2801   iopkt.requested = reqt;
2802   if (ret != -1)
2803     iopkt.iotype = OTHERIO_TRACE;
2804   else
2805     iopkt.iotype = OTHERIO_TRACE_ERROR;
2806   iopkt.fd = fildes;
2807   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2808   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2809   POP_REENTRANCE (guard);
2810   return ret;
2811 }
2812
2813 /*------------------------------------------------------------- llseek */
2814 offset_t
2815 llseek (int fildes, offset_t offset, int whence)
2816 {
2817   int *guard;
2818   offset_t ret;
2819   IOTrace_packet iopkt;
2820   if (NULL_PTR (llseek))
2821     init_io_intf ();
2822   if (CHCK_REENTRANCE (guard))
2823     return CALL_REAL (llseek)(fildes, offset, whence);
2824   PUSH_REENTRANCE (guard);
2825   hrtime_t reqt = gethrtime ();
2826   ret = CALL_REAL (llseek)(fildes, offset, whence);
2827   if (RECHCK_REENTRANCE (guard))
2828     {
2829       POP_REENTRANCE (guard);
2830       return ret;
2831     }
2832   hrtime_t grnt = gethrtime ();
2833   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2834   iopkt.comm.tsize = sizeof (IOTrace_packet);
2835   iopkt.comm.tstamp = grnt;
2836   iopkt.requested = reqt;
2837   if (ret != -1)
2838     iopkt.iotype = OTHERIO_TRACE;
2839   else
2840     iopkt.iotype = OTHERIO_TRACE_ERROR;
2841   iopkt.fd = fildes;
2842   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2843   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2844   POP_REENTRANCE (guard);
2845   return ret;
2846 }
2847
2848 /*------------------------------------------------------------- chmod */
2849 int
2850 chmod (const char *path, mode_t mode)
2851 {
2852   int *guard;
2853   int ret;
2854   void *packet;
2855   IOTrace_packet *iopkt;
2856   size_t sz;
2857   unsigned pktSize;
2858   if (NULL_PTR (chmod))
2859     init_io_intf ();
2860   if (CHCK_REENTRANCE (guard) || path == NULL)
2861     return CALL_REAL (chmod)(path, mode);
2862   PUSH_REENTRANCE (guard);
2863   hrtime_t reqt = gethrtime ();
2864   ret = CALL_REAL (chmod)(path, mode);
2865   if (RECHCK_REENTRANCE (guard))
2866     {
2867       POP_REENTRANCE (guard);
2868       return ret;
2869     }
2870   hrtime_t grnt = gethrtime ();
2871   sz = collector_strlen (path);
2872   pktSize = sizeof (IOTrace_packet) + sz;
2873   pktSize = collector_align_pktsize (pktSize);
2874   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
2875   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
2876   if (packet != NULL)
2877     {
2878       iopkt = (IOTrace_packet *) packet;
2879       collector_memset (iopkt, 0, pktSize);
2880       iopkt->comm.tsize = pktSize;
2881       iopkt->comm.tstamp = grnt;
2882       iopkt->requested = reqt;
2883       if (ret != -1)
2884         iopkt->iotype = OTHERIO_TRACE;
2885       else
2886         iopkt->iotype = OTHERIO_TRACE_ERROR;
2887       collector_strncpy (&(iopkt->fname), path, sz);
2888       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2889       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
2890       collector_interface->freeCSize (io_heap, packet, pktSize);
2891     }
2892   else
2893     {
2894       Tprintf (0, "iotrace: ERROR: chmod cannot allocate memory\n");
2895       return 0;
2896     }
2897   POP_REENTRANCE (guard);
2898   return ret;
2899 }
2900
2901 /*------------------------------------------------------------- access */
2902 int
2903 access (const char *path, int amode)
2904 {
2905   int *guard;
2906   int ret;
2907   void *packet;
2908   IOTrace_packet *iopkt;
2909   size_t sz;
2910   unsigned pktSize;
2911   if (NULL_PTR (access))
2912     init_io_intf ();
2913   if (CHCK_REENTRANCE (guard) || path == NULL)
2914     return CALL_REAL (access)(path, amode);
2915   PUSH_REENTRANCE (guard);
2916   hrtime_t reqt = gethrtime ();
2917   ret = CALL_REAL (access)(path, amode);
2918   if (RECHCK_REENTRANCE (guard))
2919     {
2920       POP_REENTRANCE (guard);
2921       return ret;
2922     }
2923   hrtime_t grnt = gethrtime ();
2924   sz = collector_strlen (path);
2925   pktSize = sizeof (IOTrace_packet) + sz;
2926   pktSize = collector_align_pktsize (pktSize);
2927   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
2928   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
2929   if (packet != NULL)
2930     {
2931       iopkt = (IOTrace_packet *) packet;
2932       collector_memset (iopkt, 0, pktSize);
2933       iopkt->comm.tsize = pktSize;
2934       iopkt->comm.tstamp = grnt;
2935       iopkt->requested = reqt;
2936       if (ret != -1)
2937         iopkt->iotype = OTHERIO_TRACE;
2938       else
2939         iopkt->iotype = OTHERIO_TRACE_ERROR;
2940       collector_strncpy (&(iopkt->fname), path, sz);
2941       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2942       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
2943       collector_interface->freeCSize (io_heap, packet, pktSize);
2944     }
2945   else
2946     {
2947       Tprintf (0, "iotrace: ERROR: access cannot allocate memory\n");
2948       return 0;
2949     }
2950   POP_REENTRANCE (guard);
2951   return ret;
2952 }
2953
2954 /*------------------------------------------------------------- rename */
2955 int
2956 rename (const char *old, const char *new)
2957 {
2958   int *guard;
2959   int ret;
2960   void *packet;
2961   IOTrace_packet *iopkt;
2962   size_t sz;
2963   unsigned pktSize;
2964   if (NULL_PTR (rename))
2965     init_io_intf ();
2966   if (CHCK_REENTRANCE (guard) || new == NULL)
2967     return CALL_REAL (rename)(old, new);
2968   PUSH_REENTRANCE (guard);
2969   hrtime_t reqt = gethrtime ();
2970   ret = CALL_REAL (rename)(old, new);
2971   if (RECHCK_REENTRANCE (guard))
2972     {
2973       POP_REENTRANCE (guard);
2974       return ret;
2975     }
2976   hrtime_t grnt = gethrtime ();
2977   sz = collector_strlen (new);
2978   pktSize = sizeof (IOTrace_packet) + sz;
2979   pktSize = collector_align_pktsize (pktSize);
2980   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
2981   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
2982   if (packet != NULL)
2983     {
2984       iopkt = (IOTrace_packet *) packet;
2985       collector_memset (iopkt, 0, pktSize);
2986       iopkt->comm.tsize = pktSize;
2987       iopkt->comm.tstamp = grnt;
2988       iopkt->requested = reqt;
2989       if (ret != -1)
2990         iopkt->iotype = OTHERIO_TRACE;
2991       else
2992         iopkt->iotype = OTHERIO_TRACE_ERROR;
2993       collector_strncpy (&(iopkt->fname), new, sz);
2994       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2995       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
2996       collector_interface->freeCSize (io_heap, packet, pktSize);
2997     }
2998   else
2999     {
3000       Tprintf (0, "iotrace: ERROR: rename cannot allocate memory\n");
3001       return 0;
3002     }
3003   POP_REENTRANCE (guard);
3004   return ret;
3005 }
3006
3007 /*------------------------------------------------------------- mkdir */
3008 int
3009 mkdir (const char *path, mode_t mode)
3010 {
3011   int *guard;
3012   int ret;
3013   void *packet;
3014   IOTrace_packet *iopkt;
3015   size_t sz;
3016   unsigned pktSize;
3017   if (NULL_PTR (mkdir))
3018     init_io_intf ();
3019   if (CHCK_REENTRANCE (guard) || path == NULL)
3020     return CALL_REAL (mkdir)(path, mode);
3021   PUSH_REENTRANCE (guard);
3022   hrtime_t reqt = gethrtime ();
3023   ret = CALL_REAL (mkdir)(path, mode);
3024   if (RECHCK_REENTRANCE (guard))
3025     {
3026       POP_REENTRANCE (guard);
3027       return ret;
3028     }
3029   hrtime_t grnt = gethrtime ();
3030   sz = collector_strlen (path);
3031   pktSize = sizeof (IOTrace_packet) + sz;
3032   pktSize = collector_align_pktsize (pktSize);
3033   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
3034   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
3035   if (packet != NULL)
3036     {
3037       iopkt = (IOTrace_packet *) packet;
3038       collector_memset (iopkt, 0, pktSize);
3039       iopkt->comm.tsize = pktSize;
3040       iopkt->comm.tstamp = grnt;
3041       iopkt->requested = reqt;
3042       if (ret != -1)
3043         iopkt->iotype = OTHERIO_TRACE;
3044       else
3045         iopkt->iotype = OTHERIO_TRACE_ERROR;
3046       collector_strncpy (&(iopkt->fname), path, sz);
3047       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3048       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
3049       collector_interface->freeCSize (io_heap, packet, pktSize);
3050     }
3051   else
3052     {
3053       Tprintf (0, "iotrace: ERROR: mkdir cannot allocate memory\n");
3054       return 0;
3055     }
3056   POP_REENTRANCE (guard);
3057   return ret;
3058 }
3059
3060 /*------------------------------------------------------------- getdents */
3061 int
3062 getdents (int fildes, struct dirent *buf, size_t nbyte)
3063 {
3064   int *guard;
3065   int ret;
3066   IOTrace_packet iopkt;
3067   if (NULL_PTR (getdents))
3068     init_io_intf ();
3069   if (CHCK_REENTRANCE (guard))
3070     return CALL_REAL (getdents)(fildes, buf, nbyte);
3071   PUSH_REENTRANCE (guard);
3072   hrtime_t reqt = gethrtime ();
3073   ret = CALL_REAL (getdents)(fildes, buf, nbyte);
3074   if (RECHCK_REENTRANCE (guard))
3075     {
3076       POP_REENTRANCE (guard);
3077       return ret;
3078     }
3079   hrtime_t grnt = gethrtime ();
3080   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3081   iopkt.comm.tsize = sizeof (IOTrace_packet);
3082   iopkt.comm.tstamp = grnt;
3083   iopkt.requested = reqt;
3084   if (ret != -1)
3085     iopkt.iotype = OTHERIO_TRACE;
3086   else
3087     iopkt.iotype = OTHERIO_TRACE_ERROR;
3088   iopkt.fd = fildes;
3089   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3090   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3091   POP_REENTRANCE (guard);
3092   return ret;
3093 }
3094
3095 /*------------------------------------------------------------- unlink */
3096 int
3097 unlink (const char *path)
3098 {
3099   int *guard;
3100   int ret;
3101   void *packet;
3102   IOTrace_packet *iopkt;
3103   size_t sz;
3104   unsigned pktSize;
3105   if (NULL_PTR (unlink))
3106     init_io_intf ();
3107   if (CHCK_REENTRANCE (guard) || path == NULL)
3108     return CALL_REAL (unlink)(path);
3109   PUSH_REENTRANCE (guard);
3110   hrtime_t reqt = gethrtime ();
3111   ret = CALL_REAL (unlink)(path);
3112   if (RECHCK_REENTRANCE (guard))
3113     {
3114       POP_REENTRANCE (guard);
3115       return ret;
3116     }
3117   hrtime_t grnt = gethrtime ();
3118   sz = collector_strlen (path);
3119   pktSize = sizeof (IOTrace_packet) + sz;
3120   pktSize = collector_align_pktsize (pktSize);
3121   Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
3122   packet = collector_interface->allocCSize (io_heap, pktSize, 1);
3123   if (packet != NULL)
3124     {
3125       iopkt = (IOTrace_packet *) packet;
3126       collector_memset (iopkt, 0, pktSize);
3127       iopkt->comm.tsize = pktSize;
3128       iopkt->comm.tstamp = grnt;
3129       iopkt->requested = reqt;
3130       if (ret != -1)
3131         iopkt->iotype = OTHERIO_TRACE;
3132       else
3133         iopkt->iotype = OTHERIO_TRACE_ERROR;
3134       collector_strncpy (&(iopkt->fname), path, sz);
3135       iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3136       collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
3137       collector_interface->freeCSize (io_heap, packet, pktSize);
3138     }
3139   else
3140     {
3141       Tprintf (0, "iotrace: ERROR: unlink cannot allocate memory\n");
3142       return 0;
3143     }
3144   POP_REENTRANCE (guard);
3145   return ret;
3146 }
3147
3148 /*------------------------------------------------------------- fseek */
3149 int
3150 fseek (FILE *stream, long offset, int whence)
3151 {
3152   int *guard;
3153   int ret;
3154   IOTrace_packet iopkt;
3155   if (NULL_PTR (fseek))
3156     init_io_intf ();
3157   if (CHCK_REENTRANCE (guard) || stream == NULL)
3158     return CALL_REAL (fseek)(stream, offset, whence);
3159   PUSH_REENTRANCE (guard);
3160   hrtime_t reqt = gethrtime ();
3161   ret = CALL_REAL (fseek)(stream, offset, whence);
3162   if (RECHCK_REENTRANCE (guard))
3163     {
3164       POP_REENTRANCE (guard);
3165       return ret;
3166     }
3167   hrtime_t grnt = gethrtime ();
3168   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3169   iopkt.comm.tsize = sizeof (IOTrace_packet);
3170   iopkt.comm.tstamp = grnt;
3171   iopkt.requested = reqt;
3172   if (ret != -1)
3173     iopkt.iotype = OTHERIO_TRACE;
3174   else
3175     iopkt.iotype = OTHERIO_TRACE_ERROR;
3176   iopkt.fd = fileno (stream);
3177   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3178   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3179   POP_REENTRANCE (guard);
3180   return ret;
3181 }
3182
3183 /*------------------------------------------------------------- rewind */
3184 void
3185 rewind (FILE *stream)
3186 {
3187   int *guard;
3188   IOTrace_packet iopkt;
3189   if (NULL_PTR (rewind))
3190     init_io_intf ();
3191   if (CHCK_REENTRANCE (guard) || stream == NULL)
3192     {
3193       CALL_REAL (rewind)(stream);
3194       return;
3195     }
3196   PUSH_REENTRANCE (guard);
3197   hrtime_t reqt = gethrtime ();
3198   CALL_REAL (rewind)(stream);
3199   if (RECHCK_REENTRANCE (guard))
3200     {
3201       POP_REENTRANCE (guard);
3202       return;
3203     }
3204   hrtime_t grnt = gethrtime ();
3205   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3206   iopkt.comm.tsize = sizeof (IOTrace_packet);
3207   iopkt.comm.tstamp = grnt;
3208   iopkt.requested = reqt;
3209   iopkt.iotype = OTHERIO_TRACE;
3210   iopkt.fd = fileno (stream);
3211   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3212   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3213   POP_REENTRANCE (guard);
3214 }
3215
3216 /*------------------------------------------------------------- ftell */
3217 long
3218 ftell (FILE *stream)
3219 {
3220   int *guard;
3221   long ret;
3222   IOTrace_packet iopkt;
3223   if (NULL_PTR (ftell))
3224     init_io_intf ();
3225   if (CHCK_REENTRANCE (guard) || stream == NULL)
3226     return CALL_REAL (ftell)(stream);
3227   PUSH_REENTRANCE (guard);
3228   hrtime_t reqt = gethrtime ();
3229   ret = CALL_REAL (ftell)(stream);
3230   if (RECHCK_REENTRANCE (guard))
3231     {
3232       POP_REENTRANCE (guard);
3233       return ret;
3234     }
3235   hrtime_t grnt = gethrtime ();
3236   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3237   iopkt.comm.tsize = sizeof (IOTrace_packet);
3238   iopkt.comm.tstamp = grnt;
3239   iopkt.requested = reqt;
3240   if (ret != -1)
3241     iopkt.iotype = OTHERIO_TRACE;
3242   else
3243     iopkt.iotype = OTHERIO_TRACE_ERROR;
3244   iopkt.fd = fileno (stream);
3245   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3246   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3247   POP_REENTRANCE (guard);
3248   return ret;
3249 }
3250
3251 /*------------------------------------------------------------- fgetpos */
3252 // map interposed symbol versions
3253 #if ARCH(Intel) && WSIZE(32)
3254 static int
3255 __collector_fgetpos_symver (int(real_fgetpos) (), FILE *stream, fpos_t *pos);
3256
3257 SYMVER_ATTRIBUTE (__collector_fgetpos_2_2, fgetpos@GLIBC_2.2)
3258 int
3259 __collector_fgetpos_2_2 (FILE *stream, fpos_t *pos)
3260 {
3261   if (NULL_PTR (fgetpos))
3262     init_io_intf ();
3263   TprintfT (DBG_LTT, "iotrace: __collector_fgetpos_2_2@%p\n", CALL_REAL (fgetpos_2_2));
3264   return __collector_fgetpos_symver (CALL_REAL (fgetpos_2_2), stream, pos);
3265 }
3266
3267 SYMVER_ATTRIBUTE (__collector_fgetpos_2_0, fgetpos@GLIBC_2.0)
3268 int
3269 __collector_fgetpos_2_0 (FILE *stream, fpos_t *pos)
3270 {
3271   if (NULL_PTR (fgetpos))
3272     init_io_intf ();
3273   TprintfT (DBG_LTT, "iotrace: __collector_fgetpos_2_0@%p\n", CALL_REAL (fgetpos_2_0));
3274   return __collector_fgetpos_symver (CALL_REAL (fgetpos_2_0), stream, pos);
3275 }
3276 #endif
3277
3278 #if ARCH(Intel) && WSIZE(32)
3279
3280 static int
3281 __collector_fgetpos_symver (int(real_fgetpos) (), FILE *stream, fpos_t *pos)
3282 {
3283 #else
3284 int
3285 fgetpos (FILE *stream, fpos_t *pos)
3286 {
3287 #endif
3288   int *guard;
3289   int ret;
3290   IOTrace_packet iopkt;
3291   if (NULL_PTR (fgetpos))
3292     init_io_intf ();
3293   if (CHCK_REENTRANCE (guard) || stream == NULL)
3294     {
3295 #if ARCH(Intel) && WSIZE(32)
3296       return (real_fgetpos) (stream, pos);
3297 #else
3298       return CALL_REAL (fgetpos)(stream, pos);
3299 #endif
3300     }
3301   PUSH_REENTRANCE (guard);
3302   hrtime_t reqt = gethrtime ();
3303 #if ARCH(Intel) && WSIZE(32)
3304   ret = (real_fgetpos) (stream, pos);
3305 #else
3306   ret = CALL_REAL (fgetpos)(stream, pos);
3307 #endif
3308   if (RECHCK_REENTRANCE (guard))
3309     {
3310       POP_REENTRANCE (guard);
3311       return ret;
3312     }
3313   hrtime_t grnt = gethrtime ();
3314   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3315   iopkt.comm.tsize = sizeof (IOTrace_packet);
3316   iopkt.comm.tstamp = grnt;
3317   iopkt.requested = reqt;
3318   if (ret == 0)
3319     iopkt.iotype = OTHERIO_TRACE;
3320   else
3321     iopkt.iotype = OTHERIO_TRACE_ERROR;
3322   iopkt.fd = fileno (stream);
3323
3324 #if ARCH(Intel) && WSIZE(32)
3325   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
3326 #else
3327   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3328 #endif
3329   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3330   POP_REENTRANCE (guard);
3331   return ret;
3332 }
3333
3334 #if WSIZE(32)
3335 /*------------------------------------------------------------- fgetpos64 */
3336 #if ARCH(Intel)
3337 // map interposed symbol versions
3338
3339 static int
3340 __collector_fgetpos64_symver (int(real_fgetpos64) (), FILE *stream, fpos64_t *pos);
3341
3342 SYMVER_ATTRIBUTE (__collector_fgetpos64_2_2, fgetpos64@GLIBC_2.2)
3343 int
3344 __collector_fgetpos64_2_2 (FILE *stream, fpos64_t *pos)
3345 {
3346   TprintfT (DBG_LTT, "iotrace: __collector_fgetpos64_2_2@%p(stream=%p, pos=%p)\n",
3347             CALL_REAL (fgetpos64_2_2), stream, pos);
3348   if (NULL_PTR (fgetpos64))
3349     init_io_intf ();
3350   return __collector_fgetpos64_symver (CALL_REAL (fgetpos64_2_2), stream, pos);
3351 }
3352
3353 SYMVER_ATTRIBUTE (__collector_fgetpos64_2_1, fgetpos64@GLIBC_2.1)
3354 int
3355 __collector_fgetpos64_2_1 (FILE *stream, fpos64_t *pos)
3356 {
3357   TprintfT (DBG_LTT, "iotrace: __collector_fgetpos64_2_1@%p(stream=%p, pos=%p)\n",
3358             CALL_REAL (fgetpos64_2_1), stream, pos);
3359   if (NULL_PTR (fgetpos64))
3360     init_io_intf ();
3361   return __collector_fgetpos64_symver (CALL_REAL (fgetpos64_2_1), stream, pos);
3362 }
3363
3364 static int
3365 __collector_fgetpos64_symver (int(real_fgetpos64) (), FILE *stream, fpos64_t *pos)
3366 {
3367 #else
3368 int
3369 fgetpos64 (FILE *stream, fpos64_t *pos)
3370 {
3371 #endif
3372   int *guard;
3373   int ret;
3374   IOTrace_packet iopkt;
3375   if (NULL_PTR (fgetpos64))
3376     init_io_intf ();
3377   if (CHCK_REENTRANCE (guard) || stream == NULL)
3378     {
3379 #if ARCH(Intel)
3380       return (real_fgetpos64) (stream, pos);
3381 #else
3382       return CALL_REAL (fgetpos64)(stream, pos);
3383 #endif
3384     }
3385   PUSH_REENTRANCE (guard);
3386   hrtime_t reqt = gethrtime ();
3387 #if ARCH(Intel)
3388   ret = (real_fgetpos64) (stream, pos);
3389 #else
3390   ret = CALL_REAL (fgetpos64)(stream, pos);
3391 #endif
3392   if (RECHCK_REENTRANCE (guard))
3393     {
3394       POP_REENTRANCE (guard);
3395       return ret;
3396     }
3397   hrtime_t grnt = gethrtime ();
3398   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3399   iopkt.comm.tsize = sizeof (IOTrace_packet);
3400   iopkt.comm.tstamp = grnt;
3401   iopkt.requested = reqt;
3402   if (ret == 0)
3403     iopkt.iotype = OTHERIO_TRACE;
3404   else
3405     iopkt.iotype = OTHERIO_TRACE_ERROR;
3406   iopkt.fd = fileno (stream);
3407 #if ARCH(Intel)
3408   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
3409 #else
3410   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3411 #endif
3412   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3413   POP_REENTRANCE (guard);
3414   return ret;
3415 }
3416 #endif
3417
3418 /*------------------------------------------------------------- fsetpos */
3419 // map interposed symbol versions
3420 #if ARCH(Intel) && WSIZE(32)
3421 static int
3422 __collector_fsetpos_symver (int(real_fsetpos) (), FILE *stream, const fpos_t *pos);
3423
3424 SYMVER_ATTRIBUTE (__collector_fsetpos_2_2, fsetpos@GLIBC_2.2)
3425 int
3426 __collector_fsetpos_2_2 (FILE *stream, const fpos_t *pos)
3427 {
3428   if (NULL_PTR (fsetpos))
3429     init_io_intf ();
3430   TprintfT (DBG_LTT, "iotrace: __collector_fsetpos_2_2@%p\n", CALL_REAL (fsetpos_2_2));
3431   return __collector_fsetpos_symver (CALL_REAL (fsetpos_2_2), stream, pos);
3432 }
3433
3434 SYMVER_ATTRIBUTE (__collector_fsetpos_2_0, fsetpos@GLIBC_2.0)
3435 int
3436 __collector_fsetpos_2_0 (FILE *stream, const fpos_t *pos)
3437 {
3438   if (NULL_PTR (fsetpos))
3439     init_io_intf ();
3440   TprintfT (DBG_LTT, "iotrace: __collector_fsetpos_2_0@%p\n", CALL_REAL (fsetpos_2_0));
3441   return __collector_fsetpos_symver (CALL_REAL (fsetpos_2_0), stream, pos);
3442 }
3443 #endif
3444
3445 #if ARCH(Intel) && WSIZE(32)
3446
3447 static int
3448 __collector_fsetpos_symver (int(real_fsetpos) (), FILE *stream, const fpos_t *pos)
3449 {
3450 #else
3451 int
3452 fsetpos (FILE *stream, const fpos_t *pos)
3453 {
3454 #endif
3455   int *guard;
3456   int ret;
3457   IOTrace_packet iopkt;
3458   if (NULL_PTR (fsetpos))
3459     init_io_intf ();
3460   if (CHCK_REENTRANCE (guard) || stream == NULL)
3461     {
3462 #if ARCH(Intel) && WSIZE(32)
3463       return (real_fsetpos) (stream, pos);
3464 #else
3465       return CALL_REAL (fsetpos)(stream, pos);
3466 #endif
3467     }
3468   PUSH_REENTRANCE (guard);
3469   hrtime_t reqt = gethrtime ();
3470 #if ARCH(Intel) && WSIZE(32)
3471   ret = (real_fsetpos) (stream, pos);
3472 #else
3473   ret = CALL_REAL (fsetpos)(stream, pos);
3474 #endif
3475   if (RECHCK_REENTRANCE (guard))
3476     {
3477       POP_REENTRANCE (guard);
3478       return ret;
3479     }
3480   hrtime_t grnt = gethrtime ();
3481   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3482   iopkt.comm.tsize = sizeof (IOTrace_packet);
3483   iopkt.comm.tstamp = grnt;
3484   iopkt.requested = reqt;
3485   if (ret == 0)
3486     iopkt.iotype = OTHERIO_TRACE;
3487   else
3488     iopkt.iotype = OTHERIO_TRACE_ERROR;
3489   iopkt.fd = fileno (stream);
3490 #if ARCH(Intel) && WSIZE(32)
3491   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
3492 #else
3493   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3494 #endif
3495   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3496   POP_REENTRANCE (guard);
3497   return ret;
3498 }
3499
3500 #if WSIZE(32)
3501 /*------------------------------------------------------------- fsetpos64 */
3502 #if ARCH(Intel)
3503 // map interposed symbol versions
3504 static int
3505 __collector_fsetpos64_symver (int(real_fsetpos64) (), FILE *stream, const fpos64_t *pos);
3506
3507 SYMVER_ATTRIBUTE (__collector_fsetpos64_2_2, fsetpos64@GLIBC_2.2)
3508 int
3509 __collector_fsetpos64_2_2 (FILE *stream, const fpos64_t *pos)
3510 {
3511   TprintfT (DBG_LTT, "iotrace: __collector_fsetpos64_2_2@%p(stream=%p, pos=%p)\n",
3512             CALL_REAL (fsetpos64_2_2), stream, pos);
3513   if (NULL_PTR (fsetpos64))
3514     init_io_intf ();
3515   return __collector_fsetpos64_symver (CALL_REAL (fsetpos64_2_2), stream, pos);
3516 }
3517
3518 SYMVER_ATTRIBUTE (__collector_fsetpos64_2_1, fsetpos64@GLIBC_2.1)
3519 int
3520 __collector_fsetpos64_2_1 (FILE *stream, const fpos64_t *pos)
3521 {
3522   TprintfT (DBG_LTT, "iotrace: __collector_fsetpos64_2_1@%p(stream=%p, pos=%p)\n",
3523             CALL_REAL (fsetpos64_2_1), stream, pos);
3524   if (NULL_PTR (fsetpos64))
3525     init_io_intf ();
3526   return __collector_fsetpos64_symver (CALL_REAL (fsetpos64_2_1), stream, pos);
3527 }
3528
3529 static int
3530 __collector_fsetpos64_symver (int(real_fsetpos64) (), FILE *stream, const fpos64_t *pos)
3531 {
3532 #else
3533 int
3534 fsetpos64 (FILE *stream, const fpos64_t *pos)
3535 {
3536 #endif
3537   int *guard;
3538   int ret;
3539   IOTrace_packet iopkt;
3540   if (NULL_PTR (fsetpos64))
3541     init_io_intf ();
3542   if (CHCK_REENTRANCE (guard) || stream == NULL)
3543     {
3544 #if ARCH(Intel) && WSIZE(32)
3545       return (real_fsetpos64) (stream, pos);
3546 #else
3547       return CALL_REAL (fsetpos64)(stream, pos);
3548 #endif
3549     }
3550   PUSH_REENTRANCE (guard);
3551   hrtime_t reqt = gethrtime ();
3552 #if ARCH(Intel) && WSIZE(32)
3553   ret = (real_fsetpos64) (stream, pos);
3554 #else
3555   ret = CALL_REAL (fsetpos64)(stream, pos);
3556 #endif
3557   if (RECHCK_REENTRANCE (guard))
3558     {
3559       POP_REENTRANCE (guard);
3560       return ret;
3561     }
3562   hrtime_t grnt = gethrtime ();
3563   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3564   iopkt.comm.tsize = sizeof (IOTrace_packet);
3565   iopkt.comm.tstamp = grnt;
3566   iopkt.requested = reqt;
3567   if (ret == 0)
3568     iopkt.iotype = OTHERIO_TRACE;
3569   else
3570     iopkt.iotype = OTHERIO_TRACE_ERROR;
3571   iopkt.fd = fileno (stream);
3572 #if ARCH(Intel)
3573   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
3574 #else
3575   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3576 #endif
3577   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3578   POP_REENTRANCE (guard);
3579   return ret;
3580 }
3581 #endif
3582
3583 /*------------------------------------------------------------- fsync */
3584 int
3585 fsync (int fildes)
3586 {
3587   int *guard;
3588   int ret;
3589   IOTrace_packet iopkt;
3590   if (NULL_PTR (fsync))
3591     init_io_intf ();
3592   if (CHCK_REENTRANCE (guard))
3593     return CALL_REAL (fsync)(fildes);
3594   PUSH_REENTRANCE (guard);
3595   hrtime_t reqt = gethrtime ();
3596   ret = CALL_REAL (fsync)(fildes);
3597   if (RECHCK_REENTRANCE (guard))
3598     {
3599       POP_REENTRANCE (guard);
3600       return ret;
3601     }
3602   hrtime_t grnt = gethrtime ();
3603   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3604   iopkt.comm.tsize = sizeof (IOTrace_packet);
3605   iopkt.comm.tstamp = grnt;
3606   iopkt.requested = reqt;
3607   if (ret == 0)
3608     iopkt.iotype = OTHERIO_TRACE;
3609   else
3610     iopkt.iotype = OTHERIO_TRACE_ERROR;
3611   iopkt.fd = fildes;
3612   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3613   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3614   POP_REENTRANCE (guard);
3615   return ret;
3616 }
3617
3618 /*------------------------------------------------------------- readdir */
3619 struct dirent*
3620 readdir (DIR *dirp)
3621 {
3622   int *guard;
3623   struct dirent *ptr;
3624   IOTrace_packet iopkt;
3625   if (NULL_PTR (readdir))
3626     init_io_intf ();
3627   if (CHCK_REENTRANCE (guard))
3628     return CALL_REAL (readdir)(dirp);
3629   PUSH_REENTRANCE (guard);
3630   hrtime_t reqt = gethrtime ();
3631   ptr = CALL_REAL (readdir)(dirp);
3632   if (RECHCK_REENTRANCE (guard))
3633     {
3634       POP_REENTRANCE (guard);
3635       return ptr;
3636     }
3637   hrtime_t grnt = gethrtime ();
3638   collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
3639   iopkt.comm.tsize = sizeof ( IOTrace_packet);
3640   iopkt.comm.tstamp = grnt;
3641   iopkt.requested = reqt;
3642   if (ptr != NULL)
3643     iopkt.iotype = OTHERIO_TRACE;
3644   else
3645     iopkt.iotype = OTHERIO_TRACE_ERROR;
3646   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3647   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3648   POP_REENTRANCE (guard);
3649   return ptr;
3650 }
3651
3652 /*------------------------------------------------------------- flock */
3653 int
3654 flock (int fd, int operation)
3655 {
3656   int *guard;
3657   int ret;
3658   IOTrace_packet iopkt;
3659   if (NULL_PTR (flock))
3660     init_io_intf ();
3661   if (CHCK_REENTRANCE (guard))
3662     return CALL_REAL (flock)(fd, operation);
3663   PUSH_REENTRANCE (guard);
3664   hrtime_t reqt = gethrtime ();
3665   ret = CALL_REAL (flock)(fd, operation);
3666   if (RECHCK_REENTRANCE (guard))
3667     {
3668       POP_REENTRANCE (guard);
3669       return ret;
3670     }
3671   hrtime_t grnt = gethrtime ();
3672   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3673   iopkt.comm.tsize = sizeof (IOTrace_packet);
3674   iopkt.comm.tstamp = grnt;
3675   iopkt.requested = reqt;
3676   if (ret == 0)
3677     iopkt.iotype = OTHERIO_TRACE;
3678   else
3679     iopkt.iotype = OTHERIO_TRACE_ERROR;
3680   iopkt.fd = fd;
3681   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3682   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3683   POP_REENTRANCE (guard);
3684   return ret;
3685 }
3686
3687 /*------------------------------------------------------------- lockf */
3688 int
3689 lockf (int fildes, int function, off_t size)
3690 {
3691   int *guard;
3692   int ret;
3693   IOTrace_packet iopkt;
3694   if (NULL_PTR (lockf))
3695     init_io_intf ();
3696   if (CHCK_REENTRANCE (guard))
3697     return CALL_REAL (lockf)(fildes, function, size);
3698   PUSH_REENTRANCE (guard);
3699   hrtime_t reqt = gethrtime ();
3700   ret = CALL_REAL (lockf)(fildes, function, size);
3701   if (RECHCK_REENTRANCE (guard))
3702     {
3703       POP_REENTRANCE (guard);
3704       return ret;
3705     }
3706   hrtime_t grnt = gethrtime ();
3707   collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3708   iopkt.comm.tsize = sizeof (IOTrace_packet);
3709   iopkt.comm.tstamp = grnt;
3710   iopkt.requested = reqt;
3711   if (ret == 0)
3712     iopkt.iotype = OTHERIO_TRACE;
3713   else
3714     iopkt.iotype = OTHERIO_TRACE_ERROR;
3715   iopkt.fd = fildes;
3716   iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3717   collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3718   POP_REENTRANCE (guard);
3719   return ret;
3720 }
This page took 0.225373 seconds and 4 git commands to generate.