1 /* Copyright (C) 2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
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)
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.
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. */
30 // create() and others are defined in fcntl.h.
31 // Our 'create' should not have the __nonnull attribute
37 #include "collector.h"
38 #include "gp-experiment.h"
39 #include "data_pckts.h"
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
49 /* define the packet that will be written out */
50 typedef struct IOTrace_packet
51 { /* IO tracing packet */
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 */
62 typedef long long offset_t;
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 ();
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) */
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;
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))--)
92 #define CALL_REAL(x) (__real_##x)
93 #define NULL_PTR(x) (__real_##x == NULL)
95 #define gethrtime collector_interface->getHiResTime
98 #define Tprintf(...) if (collector_interface) collector_interface->writeDebugInfo( 0, __VA_ARGS__ )
99 #define TprintfT(...) if (collector_interface) collector_interface->writeDebugInfo( 1, __VA_ARGS__ )
102 #define TprintfT(...)
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;
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;
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;
183 #endif /* WSIZE(32) */
186 collector_align_pktsize (int sz)
193 pktSize = (sz / 8) + 1;
200 collector_memset (void *s, int c, size_t n)
202 unsigned char *s1 = s;
204 *s1++ = (unsigned char) c;
208 collector_strlen (const char *s)
213 while (s[++len] != '\0')
219 collector_strncpy (char *dst, const char *src, size_t dstsize)
222 for (i = 0; i < dstsize; i++)
232 collector_strchr (const char *s, int c)
243 static FileSystem_type
244 collector_fstype (const char *path)
246 return UNKNOWNFS_TYPE;
250 __collector_module_init (CollectorInterface *_collector_interface)
252 if (_collector_interface == NULL)
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);
265 open_experiment (const char *exp)
267 if (collector_interface == NULL)
269 Tprintf (0, "iotrace: collector_interface is null.\n");
270 return COL_ERROR_IOINIT;
272 if (io_hndl == COLLECTOR_MODULE_ERR)
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;
279 TprintfT (0, "iotrace: open_experiment %s\n", exp);
280 if (NULL_PTR (fopen))
284 io_heap = collector_interface->newHeap ();
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;
294 const char *params = collector_interface->getParams ();
297 if ((params[0] == 'i') && (params[1] == ':'))
302 params = collector_strchr (params, ';');
306 if (params == NULL) /* IO data collection not specified */
307 return COL_ERROR_IOINIT;
309 io_key = collector_interface->createKey (sizeof ( int), NULL, NULL);
310 if (io_key == (unsigned) - 1)
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;
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;
354 start_data_collection (void)
357 Tprintf (0, "iotrace: start_data_collection\n");
362 stop_data_collection (void)
365 Tprintf (0, "iotrace: stop_data_collection\n");
370 close_experiment (void)
373 io_key = COLLECTOR_TSD_INVALID_KEY;
376 collector_interface->deleteHeap (io_heap);
379 Tprintf (0, "iotrace: close_experiment\n");
384 detach_experiment (void)
386 /* fork child. Clean up state but don't write to experiment */
388 io_key = COLLECTOR_TSD_INVALID_KEY;
391 collector_interface->deleteHeap (io_heap);
394 Tprintf (0, "iotrace: detach_experiment\n");
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)
409 /* pull the plug if recursion occurs... */
413 /* lookup fprint to print fatal error message */
414 void *ptr = dlsym (RTLD_NEXT, "fprintf");
416 __real_fprintf = (int (*)(FILE*, const char*, ...)) ptr;
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"
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"
442 #define SYS_FOPEN_X_VERSION "GLIBC_2.17"
443 #define SYS_FGETPOS_X_VERSION "GLIBC_2.17"
448 __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (dlflag, "fopen", SYS_FOPEN_X_VERSION);
449 if (__real_fopen == NULL)
451 /* We are probably dlopened after libc,
452 * try to search in the previously loaded objects
454 __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (RTLD_DEFAULT, "fopen", SYS_FOPEN_X_VERSION);
455 if (__real_fopen != NULL)
457 Tprintf (0, "iotrace: WARNING: init_io_intf() using RTLD_DEFAULT for Linux io routines\n");
458 dlflag = RTLD_DEFAULT;
462 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen\n");
463 rc = COL_ERROR_IOINIT;
467 __real_fclose = (int (*)(FILE*))dlvsym (dlflag, "fclose", SYS_FOPEN_X_VERSION);
468 if (__real_fclose == NULL)
470 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose\n");
471 rc = COL_ERROR_IOINIT;
474 __real_fdopen = (FILE * (*)(int, const char*))dlvsym (dlflag, "fdopen", SYS_FOPEN_X_VERSION);
475 if (__real_fdopen == NULL)
477 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen\n");
478 rc = COL_ERROR_IOINIT;
481 __real_fgetpos = (int (*)(FILE*, fpos_t*))dlvsym (dlflag, "fgetpos", SYS_FGETPOS_X_VERSION);
482 if (__real_fgetpos == NULL)
484 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos\n");
485 rc = COL_ERROR_IOINIT;
488 __real_fsetpos = (int (*)(FILE*, const fpos_t*))dlvsym (dlflag, "fsetpos", SYS_FGETPOS_X_VERSION);
489 if (__real_fsetpos == NULL)
491 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos\n");
492 rc = COL_ERROR_IOINIT;
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;
503 __real_fopen_2_0 = (FILE * (*)(const char*, const char*))dlvsym (dlflag, "fopen", "GLIBC_2.0");
504 if (__real_fopen_2_0 == NULL)
506 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen_2_0\n");
507 rc = COL_ERROR_IOINIT;
510 __real_fclose_2_0 = (int (*)(FILE*))dlvsym (dlflag, "fclose", "GLIBC_2.0");
511 if (__real_fclose_2_0 == NULL)
513 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose_2_0\n");
514 rc = COL_ERROR_IOINIT;
517 __real_fdopen_2_0 = (FILE * (*)(int, const char*))dlvsym (dlflag, "fdopen", "GLIBC_2.0");
518 if (__real_fdopen_2_0 == NULL)
520 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen_2_0\n");
521 rc = COL_ERROR_IOINIT;
524 __real_fgetpos_2_0 = (int (*)(FILE*, fpos_t*))dlvsym (dlflag, "fgetpos", "GLIBC_2.0");
525 if (__real_fgetpos_2_0 == NULL)
527 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos_2_0\n");
528 rc = COL_ERROR_IOINIT;
531 __real_fsetpos_2_0 = (int (*)(FILE*, const fpos_t*))dlvsym (dlflag, "fsetpos", "GLIBC_2.0");
532 if (__real_fsetpos_2_0 == NULL)
534 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos_2_0\n");
535 rc = COL_ERROR_IOINIT;
538 __real_fgetpos64_2_1 = (int (*)(FILE*, fpos64_t*))dlvsym (dlflag, "fgetpos64", "GLIBC_2.1");
539 if (__real_fgetpos64_2_1 == NULL)
541 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos64_2_1\n");
542 rc = COL_ERROR_IOINIT;
545 __real_fsetpos64_2_1 = (int (*)(FILE*, const fpos64_t*))dlvsym (dlflag, "fsetpos64", "GLIBC_2.1");
546 if (__real_fsetpos64_2_1 == NULL)
548 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos64_2_1\n");
549 rc = COL_ERROR_IOINIT;
552 __real_open64_2_1 = (int (*)(const char*, int, ...))dlvsym (dlflag, "open64", "GLIBC_2.1");
553 if (__real_open64_2_1 == NULL)
555 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open64_2_1\n");
556 rc = COL_ERROR_IOINIT;
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)
562 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread_2_1\n");
563 rc = COL_ERROR_IOINIT;
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)
569 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite_2_1\n");
570 rc = COL_ERROR_IOINIT;
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)
576 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite64_2_1\n");
577 rc = COL_ERROR_IOINIT;
580 __real_fgetpos64_2_2 = (int (*)(FILE*, fpos64_t*))dlvsym (dlflag, "fgetpos64", SYS_FGETPOS64_X_VERSION);
581 if (__real_fgetpos64_2_2 == NULL)
583 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos64_2_2\n");
584 rc = COL_ERROR_IOINIT;
587 __real_fsetpos64_2_2 = (int (*)(FILE*, const fpos64_t*))dlvsym (dlflag, "fsetpos64", SYS_FGETPOS64_X_VERSION);
588 if (__real_fsetpos64_2_2 == NULL)
590 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos64_2_2\n");
591 rc = COL_ERROR_IOINIT;
594 __real_open64_2_2 = (int (*)(const char*, int, ...))dlvsym (dlflag, "open64", SYS_OPEN64_X_VERSION);
595 if (__real_open64_2_2 == NULL)
597 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open64_2_2\n");
598 rc = COL_ERROR_IOINIT;
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)
604 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread_2_2\n");
605 rc = COL_ERROR_IOINIT;
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)
611 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite_2_2\n");
612 rc = COL_ERROR_IOINIT;
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)
618 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite64_2_2\n");
619 rc = COL_ERROR_IOINIT;
624 #else /* WSIZE(64) */
626 __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (dlflag, "fopen", SYS_FOPEN_X_VERSION);
627 if (__real_fopen == NULL)
629 /* We are probably dlopened after libc,
630 * try to search in the previously loaded objects
632 __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (RTLD_DEFAULT, "fopen", SYS_FOPEN_X_VERSION);
633 if (__real_fopen != NULL)
635 Tprintf (0, "iotrace: WARNING: init_io_intf() using RTLD_DEFAULT for Linux io routines\n");
636 dlflag = RTLD_DEFAULT;
640 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen\n");
641 rc = COL_ERROR_IOINIT;
645 __real_fclose = (int (*)(FILE*))dlvsym (dlflag, "fclose", SYS_FOPEN_X_VERSION);
646 if (__real_fclose == NULL)
648 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose\n");
649 rc = COL_ERROR_IOINIT;
652 __real_fdopen = (FILE * (*)(int, const char*))dlvsym (dlflag, "fdopen", SYS_FOPEN_X_VERSION);
653 if (__real_fdopen == NULL)
655 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen\n");
656 rc = COL_ERROR_IOINIT;
659 __real_fgetpos = (int (*)(FILE*, fpos_t*))dlvsym (dlflag, "fgetpos", SYS_FGETPOS_X_VERSION);
660 if (__real_fgetpos == NULL)
662 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos\n");
663 rc = COL_ERROR_IOINIT;
666 __real_fsetpos = (int (*)(FILE*, const fpos_t*))dlvsym (dlflag, "fsetpos", SYS_FGETPOS_X_VERSION);
667 if (__real_fsetpos == NULL)
669 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos\n");
670 rc = COL_ERROR_IOINIT;
672 #endif /* WSIZE(32) */
674 __real_open = (int (*)(const char*, int, ...))dlsym (dlflag, "open");
675 if (__real_open == NULL)
677 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open\n");
678 rc = COL_ERROR_IOINIT;
682 __real_open64 = (int (*)(const char*, int, ...))dlsym (dlflag, "open64");
683 if (__real_open64 == NULL)
685 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open64\n");
686 rc = COL_ERROR_IOINIT;
690 __real_fcntl = (int (*)(int, int, ...))dlsym (dlflag, "fcntl");
691 if (__real_fcntl == NULL)
693 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fcntl\n");
694 rc = COL_ERROR_IOINIT;
697 __real_openat = (int (*)(int, const char*, int, ...))dlsym (dlflag, "openat");
698 if (__real_openat == NULL)
700 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT openat\n");
701 rc = COL_ERROR_IOINIT;
704 __real_close = (int (*)(int))dlsym (dlflag, "close");
705 if (__real_close == NULL)
707 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT close\n");
708 rc = COL_ERROR_IOINIT;
711 __real_dup = (int (*)(int))dlsym (dlflag, "dup");
712 if (__real_dup == NULL)
714 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT dup\n");
715 rc = COL_ERROR_IOINIT;
718 __real_dup2 = (int (*)(int, int))dlsym (dlflag, "dup2");
719 if (__real_dup2 == NULL)
721 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT dup2\n");
722 rc = COL_ERROR_IOINIT;
725 __real_pipe = (int (*)(int[]))dlsym (dlflag, "pipe");
726 if (__real_pipe == NULL)
728 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pipe\n");
729 rc = COL_ERROR_IOINIT;
732 __real_socket = (int (*)(int, int, int))dlsym (dlflag, "socket");
733 if (__real_socket == NULL)
735 __real_socket = (int (*)(int, int, int))dlsym (RTLD_NEXT, "socket");
736 if (__real_socket == NULL)
739 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT socket\n");
740 rc = COL_ERROR_IOINIT;
745 __real_mkstemp = (int (*)(char*))dlsym (dlflag, "mkstemp");
746 if (__real_mkstemp == NULL)
748 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT mkstemp\n");
749 rc = COL_ERROR_IOINIT;
752 __real_mkstemps = (int (*)(char*, int))dlsym (dlflag, "mkstemps");
753 if (__real_mkstemps == NULL)
756 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT mkstemps\n");
757 rc = COL_ERROR_IOINIT;
761 __real_creat = (int (*)(const char*, mode_t))dlsym (dlflag, "creat");
762 if (__real_creat == NULL)
764 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT creat\n");
765 rc = COL_ERROR_IOINIT;
769 __real_creat64 = (int (*)(const char*, mode_t))dlsym (dlflag, "creat64");
770 if (__real_creat64 == NULL)
772 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT creat64\n");
773 rc = COL_ERROR_IOINIT;
777 __real_read = (ssize_t (*)(int, void*, size_t))dlsym (dlflag, "read");
778 if (__real_read == NULL)
780 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT read\n");
781 rc = COL_ERROR_IOINIT;
784 __real_write = (ssize_t (*)(int, const void*, size_t))dlsym (dlflag, "write");
785 if (__real_write == NULL)
787 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT write\n");
788 rc = COL_ERROR_IOINIT;
791 __real_readv = (ssize_t (*)(int, const struct iovec*, int))dlsym (dlflag, "readv");
792 if (__real_readv == NULL)
794 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT readv\n");
795 rc = COL_ERROR_IOINIT;
798 __real_writev = (ssize_t (*)(int, const struct iovec*, int))dlsym (dlflag, "writev");
799 if (__real_writev == NULL)
801 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT writev\n");
802 rc = COL_ERROR_IOINIT;
805 __real_fread = (size_t (*)(void*, size_t, size_t, FILE*))dlsym (dlflag, "fread");
806 if (__real_fread == NULL)
808 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fread\n");
809 rc = COL_ERROR_IOINIT;
812 __real_fwrite = (size_t (*)(const void*, size_t, size_t, FILE*))dlsym (dlflag, "fwrite");
813 if (__real_fwrite == NULL)
815 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fwrite\n");
816 rc = COL_ERROR_IOINIT;
819 __real_pread = (ssize_t (*)(int, void*, size_t, off_t))dlsym (dlflag, "pread");
820 if (__real_pread == NULL)
822 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread\n");
823 rc = COL_ERROR_IOINIT;
826 __real_pwrite = (ssize_t (*)(int, const void*, size_t, off_t))dlsym (dlflag, "pwrite");
827 if (__real_pwrite == NULL)
829 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite\n");
830 rc = COL_ERROR_IOINIT;
833 __real_pwrite64 = (ssize_t (*)(int, const void*, size_t, off64_t))dlsym (dlflag, "pwrite64");
834 if (__real_pwrite64 == NULL)
836 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite64\n");
837 rc = COL_ERROR_IOINIT;
840 __real_fgets = (char* (*)(char*, int, FILE*))dlsym (dlflag, "fgets");
841 if (__real_fgets == NULL)
843 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgets\n");
844 rc = COL_ERROR_IOINIT;
847 __real_fputs = (int (*)(const char*, FILE*))dlsym (dlflag, "fputs");
848 if (__real_fputs == NULL)
850 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fputs\n");
851 rc = COL_ERROR_IOINIT;
854 __real_fputc = (int (*)(int, FILE*))dlsym (dlflag, "fputc");
855 if (__real_fputc == NULL)
857 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fputc\n");
858 rc = COL_ERROR_IOINIT;
861 __real_vfprintf = (int (*)(FILE*, const char*, va_list))dlsym (dlflag, "vfprintf");
862 if (__real_vfprintf == NULL)
864 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT vfprintf\n");
865 rc = COL_ERROR_IOINIT;
869 __real_lseek = (off_t (*)(int, off_t, int))dlsym (dlflag, "lseek");
870 if (__real_lseek == NULL)
872 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT lseek\n");
873 rc = COL_ERROR_IOINIT;
876 __real_llseek = (offset_t (*)(int, offset_t, int))dlsym (dlflag, "llseek");
877 if (__real_llseek == NULL)
879 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT llseek\n");
880 rc = COL_ERROR_IOINIT;
883 __real_chmod = (int (*)(const char*, mode_t))dlsym (dlflag, "chmod");
884 if (__real_chmod == NULL)
886 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT chmod\n");
887 rc = COL_ERROR_IOINIT;
890 __real_access = (int (*)(const char*, int))dlsym (dlflag, "access");
891 if (__real_access == NULL)
893 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT access\n");
894 rc = COL_ERROR_IOINIT;
897 __real_rename = (int (*)(const char*, const char*))dlsym (dlflag, "rename");
898 if (__real_rename == NULL)
900 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT rename\n");
901 rc = COL_ERROR_IOINIT;
904 __real_mkdir = (int (*)(const char*, mode_t))dlsym (dlflag, "mkdir");
905 if (__real_mkdir == NULL)
907 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT mkdir\n");
908 rc = COL_ERROR_IOINIT;
911 __real_getdents = (int (*)(int, struct dirent*, size_t))dlsym (dlflag, "getdents");
912 if (__real_getdents == NULL)
915 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT getdents\n");
916 rc = COL_ERROR_IOINIT;
920 __real_unlink = (int (*)(const char*))dlsym (dlflag, "unlink");
921 if (__real_unlink == NULL)
923 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT unlink\n");
924 rc = COL_ERROR_IOINIT;
927 __real_fseek = (int (*)(FILE*, long, int))dlsym (dlflag, "fseek");
928 if (__real_fseek == NULL)
930 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fseek\n");
931 rc = COL_ERROR_IOINIT;
934 __real_rewind = (void (*)(FILE*))dlsym (dlflag, "rewind");
935 if (__real_rewind == NULL)
937 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT rewind\n");
938 rc = COL_ERROR_IOINIT;
941 __real_ftell = (long (*)(FILE*))dlsym (dlflag, "ftell");
942 if (__real_ftell == NULL)
944 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT ftell\n");
945 rc = COL_ERROR_IOINIT;
948 __real_fsync = (int (*)(int))dlsym (dlflag, "fsync");
949 if (__real_fsync == NULL)
951 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsync\n");
952 rc = COL_ERROR_IOINIT;
955 __real_readdir = (struct dirent * (*)(DIR*))dlsym (dlflag, "readdir");
956 if (__real_readdir == NULL)
958 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT readdir\n");
959 rc = COL_ERROR_IOINIT;
962 __real_flock = (int (*)(int, int))dlsym (dlflag, "flock");
963 if (__real_flock == NULL)
965 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT flock\n");
966 rc = COL_ERROR_IOINIT;
969 __real_lockf = (int (*)(int, int, off_t))dlsym (dlflag, "lockf");
970 if (__real_lockf == NULL)
972 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT lockf\n");
973 rc = COL_ERROR_IOINIT;
976 __real_fflush = (int (*)(FILE*))dlsym (dlflag, "fflush");
977 if (__real_fflush == NULL)
979 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fflush\n");
980 rc = COL_ERROR_IOINIT;
984 __real_fgetpos64 = (int (*)(FILE*, fpos64_t*))dlsym (dlflag, "fgetpos64");
985 if (__real_fgetpos64 == NULL)
987 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos64\n");
988 rc = COL_ERROR_IOINIT;
991 __real_fsetpos64 = (int (*)(FILE*, const fpos64_t*))dlsym (dlflag, "fsetpos64");
992 if (__real_fsetpos64 == NULL)
994 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos64\n");
995 rc = COL_ERROR_IOINIT;
998 init_io_intf_finished++;
1003 write_io_packet (int fd, ssize_t ret, hrtime_t reqt, int iotype)
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;
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);
1018 /*------------------------------------------------------------- open */
1020 open (const char *path, int oflag, ...)
1025 IOTrace_packet *iopkt;
1031 va_start (ap, oflag);
1032 mode = va_arg (ap, mode_t);
1035 if (NULL_PTR (open))
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))
1045 POP_REENTRANCE (guard);
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);
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;
1062 iopkt->iotype = OPEN_TRACE;
1064 iopkt->iotype = OPEN_TRACE_ERROR;
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);
1074 Tprintf (0, "iotrace: ERROR: open cannot allocate memory\n");
1077 POP_REENTRANCE (guard);
1081 /*------------------------------------------------------------- open64 */
1082 #if ARCH(Intel) && WSIZE(32)
1083 // map interposed symbol versions
1085 __collector_open64_symver (int(real_open64) (const char *, int, ...),
1086 const char *path, int oflag, mode_t mode);
1088 SYMVER_ATTRIBUTE (__collector_open64_2_2, open64@GLIBC_2.2)
1090 __collector_open64_2_2 (const char *path, int oflag, ...)
1094 va_start (ap, oflag);
1095 mode = va_arg (ap, mode_t);
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))
1102 return __collector_open64_symver (CALL_REAL (open64_2_2), path, oflag, mode);
1105 SYMVER_ATTRIBUTE (__collector_open64_2_1, open64@GLIBC_2.1)
1107 __collector_open64_2_1 (const char *path, int oflag, ...)
1111 va_start (ap, oflag);
1112 mode = va_arg (ap, mode_t);
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))
1119 return __collector_open64_symver (CALL_REAL (open64_2_1), path, oflag, mode);
1122 #endif /* ARCH(Intel) && WSIZE(32) */
1124 #if ARCH(Intel) && WSIZE(32)
1127 __collector_open64_symver (int(real_open64) (const char *, int, ...),
1128 const char *path, int oflag, mode_t mode)
1133 IOTrace_packet *iopkt;
1136 if (NULL_PTR (open64))
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) */
1146 open64 (const char *path, int oflag, ...)
1151 IOTrace_packet *iopkt;
1157 va_start (ap, oflag);
1158 mode = va_arg (ap, mode_t);
1160 if (NULL_PTR (open64))
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) */
1169 if (RECHCK_REENTRANCE (guard) || path == NULL)
1171 POP_REENTRANCE (guard);
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);
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;
1188 iopkt->iotype = OPEN_TRACE;
1190 iopkt->iotype = OPEN_TRACE_ERROR;
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);
1200 Tprintf (0, "iotrace: ERROR: open64 cannot allocate memory\n");
1203 POP_REENTRANCE (guard);
1208 #define F_ERROR_ARG 0
1210 #define F_LONG_ARG 2
1211 #define F_VOID_ARG 3
1214 * The following macro is not defined in the
1215 * older versions of Linux.
1216 * #define F_DUPFD_CLOEXEC 1030
1218 * Instead use the command that is defined below
1219 * until we start compiling mpmt on the newer
1220 * versions of Linux.
1222 #define TMP_F_DUPFD_CLOEXEC 1030
1224 /*------------------------------------------------------------- fcntl */
1226 fcntl (int fildes, int cmd, ...)
1230 IOTrace_packet iopkt;
1233 int which_arg = F_ERROR_ARG;
1238 case TMP_F_DUPFD_CLOEXEC:
1249 long_arg = va_arg (ap, long);
1251 which_arg = F_LONG_ARG;
1258 which_arg = F_VOID_ARG;
1261 if (NULL_PTR (fcntl))
1263 if (CHCK_REENTRANCE (guard))
1268 return CALL_REAL (fcntl)(fildes, cmd, int_arg);
1270 return CALL_REAL (fcntl)(fildes, cmd, long_arg);
1272 return CALL_REAL (fcntl)(fildes, cmd);
1274 Tprintf (0, "iotrace: ERROR: Unsupported fcntl command\n");
1279 if (cmd != F_DUPFD && cmd != TMP_F_DUPFD_CLOEXEC)
1284 return CALL_REAL (fcntl)(fildes, cmd, int_arg);
1286 return CALL_REAL (fcntl)(fildes, cmd, long_arg);
1288 return CALL_REAL (fcntl)(fildes, cmd);
1290 Tprintf (0, "iotrace: ERROR: Unsupported fcntl command\n");
1295 PUSH_REENTRANCE (guard);
1296 hrtime_t reqt = gethrtime ();
1300 case TMP_F_DUPFD_CLOEXEC:
1301 fd = CALL_REAL (fcntl)(fildes, cmd, long_arg);
1304 if (RECHCK_REENTRANCE (guard))
1306 POP_REENTRANCE (guard);
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;
1315 iopkt.iotype = OPEN_TRACE;
1317 iopkt.iotype = OPEN_TRACE_ERROR;
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);
1327 /*------------------------------------------------------------- openat */
1329 openat (int fildes, const char *path, int oflag, ...)
1334 IOTrace_packet *iopkt;
1340 va_start (ap, oflag);
1341 mode = va_arg (ap, mode_t);
1343 if (NULL_PTR (openat))
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))
1352 POP_REENTRANCE (guard);
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);
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;
1369 iopkt->iotype = OPEN_TRACE;
1371 iopkt->iotype = OPEN_TRACE_ERROR;
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);
1381 Tprintf (0, "iotrace: ERROR: openat cannot allocate memory\n");
1384 POP_REENTRANCE (guard);
1388 /*------------------------------------------------------------- creat */
1390 creat (const char *path, mode_t mode)
1395 IOTrace_packet *iopkt;
1398 if (NULL_PTR (creat))
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))
1407 POP_REENTRANCE (guard);
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);
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;
1424 iopkt->iotype = OPEN_TRACE;
1426 iopkt->iotype = OPEN_TRACE_ERROR;
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);
1436 Tprintf (0, "iotrace: ERROR: creat cannot allocate memory\n");
1439 POP_REENTRANCE (guard);
1443 /*------------------------------------------------------------- creat64 */
1446 creat64 (const char *path, mode_t mode)
1451 IOTrace_packet *iopkt;
1455 if (NULL_PTR (creat64))
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))
1464 POP_REENTRANCE (guard);
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);
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;
1481 iopkt->iotype = OPEN_TRACE;
1483 iopkt->iotype = OPEN_TRACE_ERROR;
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);
1493 Tprintf (0, "iotrace: ERROR: creat64 cannot allocate memory\n");
1496 POP_REENTRANCE (guard);
1501 /*------------------------------------------------------------- mkstemp */
1503 mkstemp (char *template)
1508 IOTrace_packet *iopkt;
1511 if (NULL_PTR (mkstemp))
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))
1520 POP_REENTRANCE (guard);
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);
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;
1537 iopkt->iotype = OPEN_TRACE;
1539 iopkt->iotype = OPEN_TRACE_ERROR;
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);
1549 Tprintf (0, "iotrace: ERROR: mkstemp cannot allocate memory\n");
1552 POP_REENTRANCE (guard);
1556 /*------------------------------------------------------------- mkstemps */
1558 mkstemps (char *template, int slen)
1563 IOTrace_packet *iopkt;
1566 if (NULL_PTR (mkstemps))
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))
1575 POP_REENTRANCE (guard);
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);
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;
1592 iopkt->iotype = OPEN_TRACE;
1594 iopkt->iotype = OPEN_TRACE_ERROR;
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);
1604 Tprintf (0, "iotrace: ERROR: mkstemps cannot allocate memory\n");
1607 POP_REENTRANCE (guard);
1611 /*------------------------------------------------------------- close */
1617 IOTrace_packet iopkt;
1618 if (NULL_PTR (close))
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))
1627 POP_REENTRANCE (guard);
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;
1636 iopkt.iotype = CLOSE_TRACE;
1638 iopkt.iotype = CLOSE_TRACE_ERROR;
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);
1646 /*------------------------------------------------------------- fopen */
1647 // map interposed symbol versions
1648 #if ARCH(Intel) && WSIZE(32)
1651 __collector_fopen_symver (FILE*(real_fopen) (), const char *filename, const char *mode);
1653 SYMVER_ATTRIBUTE (__collector_fopen_2_1, fopen@GLIBC_2.1)
1655 __collector_fopen_2_1 (const char *filename, const char *mode)
1657 if (NULL_PTR (fopen))
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);
1663 SYMVER_ATTRIBUTE (__collector_fopen_2_0, fopen@GLIBC_2.0)
1665 __collector_fopen_2_0 (const char *filename, const char *mode)
1667 if (NULL_PTR (fopen))
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);
1675 #if ARCH(Intel) && WSIZE(32)
1678 __collector_fopen_symver (FILE*(real_fopen) (), const char *filename, const char *mode)
1683 fopen (const char *filename, const char *mode)
1689 IOTrace_packet *iopkt;
1692 if (NULL_PTR (fopen))
1694 if (CHCK_REENTRANCE (guard) || filename == NULL)
1696 #if ARCH(Intel) && WSIZE(32)
1697 return (real_fopen) (filename, mode);
1699 return CALL_REAL (fopen)(filename, mode);
1702 PUSH_REENTRANCE (guard);
1703 hrtime_t reqt = gethrtime ();
1705 #if ARCH(Intel) && WSIZE(32)
1706 fp = (real_fopen) (filename, mode);
1708 fp = CALL_REAL (fopen)(filename, mode);
1710 if (RECHCK_REENTRANCE (guard))
1712 POP_REENTRANCE (guard);
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);
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;
1730 iopkt->iotype = OPEN_TRACE;
1731 iopkt->fd = fileno (fp);
1735 iopkt->iotype = OPEN_TRACE_ERROR;
1738 iopkt->fstype = collector_fstype (filename);
1739 collector_strncpy (&(iopkt->fname), filename, sz);
1741 #if ARCH(Intel) && WSIZE(32)
1742 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
1744 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1746 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1747 collector_interface->freeCSize (io_heap, packet, pktSize);
1751 Tprintf (0, "iotrace: ERROR: fopen cannot allocate memory\n");
1754 POP_REENTRANCE (guard);
1758 /*------------------------------------------------------------- fclose */
1759 // map interposed symbol versions
1760 #if ARCH(Intel) && WSIZE(32)
1763 __collector_fclose_symver (int(real_fclose) (), FILE *stream);
1765 SYMVER_ATTRIBUTE (__collector_fclose_2_1, fclose@GLIBC_2.1)
1767 __collector_fclose_2_1 (FILE *stream)
1769 if (NULL_PTR (fclose))
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);
1775 SYMVER_ATTRIBUTE (__collector_fclose_2_0, fclose@GLIBC_2.0)
1777 __collector_fclose_2_0 (FILE *stream)
1779 if (NULL_PTR (fclose))
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);
1787 #if ARCH(Intel) && WSIZE(32)
1790 __collector_fclose_symver (int(real_fclose) (), FILE *stream)
1795 fclose (FILE *stream)
1800 IOTrace_packet iopkt;
1801 if (NULL_PTR (fclose))
1803 if (CHCK_REENTRANCE (guard) || stream == NULL)
1805 #if ARCH(Intel) && WSIZE(32)
1806 return (real_fclose) (stream);
1808 return CALL_REAL (fclose)(stream);
1811 PUSH_REENTRANCE (guard);
1812 hrtime_t reqt = gethrtime ();
1813 #if ARCH(Intel) && WSIZE(32)
1814 stat = (real_fclose) (stream);
1816 stat = CALL_REAL (fclose)(stream);
1818 if (RECHCK_REENTRANCE (guard))
1820 POP_REENTRANCE (guard);
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;
1829 iopkt.iotype = CLOSE_TRACE;
1831 iopkt.iotype = CLOSE_TRACE_ERROR;
1832 iopkt.fd = fileno (stream);
1834 #if ARCH(Intel) && WSIZE(32)
1835 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
1837 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1839 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1840 POP_REENTRANCE (guard);
1844 /*------------------------------------------------------------- fflush */
1846 fflush (FILE *stream)
1850 IOTrace_packet iopkt;
1851 if (NULL_PTR (fflush))
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))
1860 POP_REENTRANCE (guard);
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;
1869 iopkt.iotype = OTHERIO_TRACE;
1871 iopkt.iotype = OTHERIO_TRACE_ERROR;
1873 iopkt.fd = fileno (stream);
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);
1882 /*------------------------------------------------------------- fdopen */
1883 // map interposed symbol versions
1884 #if ARCH(Intel) && WSIZE(32)
1887 __collector_fdopen_symver (FILE*(real_fdopen) (), int fildes, const char *mode);
1889 SYMVER_ATTRIBUTE (__collector_fdopen_2_1, fdopen@GLIBC_2.1)
1891 __collector_fdopen_2_1 (int fildes, const char *mode)
1893 if (NULL_PTR (fdopen))
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);
1899 SYMVER_ATTRIBUTE (__collector_fdopen_2_0, fdopen@GLIBC_2.0)
1901 __collector_fdopen_2_0 (int fildes, const char *mode)
1903 if (NULL_PTR (fdopen))
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);
1911 #if ARCH(Intel) && WSIZE(32)
1913 __collector_fdopen_symver (FILE*(real_fdopen) (), int fildes, const char *mode)
1917 fdopen (int fildes, const char *mode)
1922 IOTrace_packet iopkt;
1923 if (NULL_PTR (fdopen))
1925 if (CHCK_REENTRANCE (guard))
1927 #if ARCH(Intel) && WSIZE(32)
1928 return (real_fdopen) (fildes, mode);
1930 return CALL_REAL (fdopen)(fildes, mode);
1933 PUSH_REENTRANCE (guard);
1934 hrtime_t reqt = gethrtime ();
1935 #if ARCH(Intel) && WSIZE(32)
1936 fp = (real_fdopen) (fildes, mode);
1938 fp = CALL_REAL (fdopen)(fildes, mode);
1940 if (RECHCK_REENTRANCE (guard))
1942 POP_REENTRANCE (guard);
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;
1951 iopkt.iotype = OPEN_TRACE;
1953 iopkt.iotype = OPEN_TRACE_ERROR;
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);
1959 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1961 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1962 POP_REENTRANCE (guard);
1966 /*------------------------------------------------------------- dup */
1972 IOTrace_packet iopkt;
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))
1982 POP_REENTRANCE (guard);
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;
1991 iopkt.iotype = OPEN_TRACE;
1993 iopkt.iotype = OPEN_TRACE_ERROR;
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);
2004 /*------------------------------------------------------------- dup2 */
2006 dup2 (int fildes, int fildes2)
2010 IOTrace_packet iopkt;
2011 if (NULL_PTR (dup2))
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))
2020 POP_REENTRANCE (guard);
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;
2029 iopkt.iotype = OPEN_TRACE;
2031 iopkt.iotype = OPEN_TRACE_ERROR;
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);
2041 /*------------------------------------------------------------- pipe */
2043 pipe (int fildes[2])
2047 IOTrace_packet iopkt;
2048 if (NULL_PTR (pipe))
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))
2057 POP_REENTRANCE (guard);
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;
2066 iopkt.iotype = OPEN_TRACE;
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;
2078 iopkt.iotype = OPEN_TRACE;
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);
2089 /*------------------------------------------------------------- socket */
2091 socket (int domain, int type, int protocol)
2095 IOTrace_packet iopkt;
2096 if (NULL_PTR (socket))
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))
2105 POP_REENTRANCE (guard);
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;
2114 iopkt.iotype = OPEN_TRACE;
2116 iopkt.iotype = OPEN_TRACE_ERROR;
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);
2125 /*------------------------------------------------------------- read */
2127 read (int fildes, void *buf, size_t nbyte)
2131 IOTrace_packet iopkt;
2132 if (NULL_PTR (read))
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))
2141 POP_REENTRANCE (guard);
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;
2150 iopkt.iotype = READ_TRACE;
2152 iopkt.iotype = READ_TRACE_ERROR;
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);
2161 /*------------------------------------------------------------- write */
2163 write (int fildes, const void *buf, size_t nbyte)
2167 IOTrace_packet iopkt;
2168 if (NULL_PTR (write))
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))
2177 POP_REENTRANCE (guard);
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;
2186 iopkt.iotype = WRITE_TRACE;
2188 iopkt.iotype = WRITE_TRACE_ERROR;
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);
2197 /*------------------------------------------------------------- readv */
2199 readv (int fildes, const struct iovec *iov, int iovcnt)
2203 IOTrace_packet iopkt;
2204 if (NULL_PTR (readv))
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))
2213 POP_REENTRANCE (guard);
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;
2222 iopkt.iotype = READ_TRACE;
2224 iopkt.iotype = READ_TRACE_ERROR;
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);
2233 /*------------------------------------------------------------- writev */
2235 writev (int fildes, const struct iovec *iov, int iovcnt)
2239 IOTrace_packet iopkt;
2240 if (NULL_PTR (writev))
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))
2249 POP_REENTRANCE (guard);
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;
2258 iopkt.iotype = WRITE_TRACE;
2260 iopkt.iotype = WRITE_TRACE_ERROR;
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);
2269 /*------------------------------------------------------------- fread */
2271 fread (void *ptr, size_t size, size_t nitems, FILE *stream)
2275 IOTrace_packet iopkt;
2276 if (NULL_PTR (fread))
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))
2285 POP_REENTRANCE (guard);
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)
2295 iopkt.iotype = READ_TRACE;
2296 iopkt.nbyte = ret * size;
2300 iopkt.iotype = READ_TRACE_ERROR;
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);
2310 /*------------------------------------------------------------- fwrite */
2312 fwrite (const void *ptr, size_t size, size_t nitems, FILE *stream)
2316 IOTrace_packet iopkt;
2317 if (NULL_PTR (fwrite))
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))
2326 POP_REENTRANCE (guard);
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)
2336 iopkt.iotype = WRITE_TRACE;
2337 iopkt.nbyte = ret * size;
2341 iopkt.iotype = WRITE_TRACE_ERROR;
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);
2351 /*------------------------------------------------------------- pread */
2352 #if ARCH(Intel) && WSIZE(32)
2353 // map interposed symbol versions
2355 __collector_pread_symver (int(real_pread) (), int fildes, void *buf, size_t nbyte, off_t offset);
2357 SYMVER_ATTRIBUTE (__collector_pread_2_2, pread@GLIBC_2.2)
2359 __collector_pread_2_2 (int fildes, void *buf, size_t nbyte, off_t offset)
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))
2365 return __collector_pread_symver (CALL_REAL (pread_2_2), fildes, buf, nbyte, offset);
2368 SYMVER_ATTRIBUTE (__collector_pread_2_1, pread@GLIBC_2.1)
2370 __collector_pread_2_1 (int fildes, void *buf, size_t nbyte, off_t offset)
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))
2376 return __collector_pread_symver (CALL_REAL (pread_2_1), fildes, buf, nbyte, offset);
2380 __collector_pread_symver (int(real_pread) (), int fildes, void *buf, size_t nbyte, off_t offset)
2382 #else /* ^ARCH(Intel) && WSIZE(32) */
2385 pread (int fildes, void *buf, size_t nbyte, off_t offset)
2390 IOTrace_packet iopkt;
2391 if (NULL_PTR (pread))
2393 if (CHCK_REENTRANCE (guard))
2395 #if ARCH(Intel) && WSIZE(32)
2396 return (real_pread) (fildes, buf, nbyte, offset);
2398 return CALL_REAL (pread)(fildes, buf, nbyte, offset);
2401 PUSH_REENTRANCE (guard);
2402 hrtime_t reqt = gethrtime ();
2403 #if ARCH(Intel) && WSIZE(32)
2404 ret = (real_pread) (fildes, buf, nbyte, offset);
2406 ret = CALL_REAL (pread)(fildes, buf, nbyte, offset);
2408 if (RECHCK_REENTRANCE (guard))
2410 POP_REENTRANCE (guard);
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;
2419 iopkt.iotype = READ_TRACE;
2421 iopkt.iotype = READ_TRACE_ERROR;
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);
2430 /*------------------------------------------------------------- pwrite */
2432 #if !defined(__MUSL_LIBC) && ARCH(Intel) && WSIZE(32)
2433 // map interposed symbol versions
2435 SYMVER_ATTRIBUTE (__collector_pwrite_2_2, pwrite@GLIBC_2.2)
2437 __collector_pwrite_2_2 (int fildes, const void *buf, size_t nbyte, off_t offset)
2440 if (NULL_PTR (pwrite_2_2))
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))
2449 POP_REENTRANCE (guard);
2452 write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2453 POP_REENTRANCE (guard);
2457 SYMVER_ATTRIBUTE (__collector_pwrite_2_1, pwrite@GLIBC_2.1)
2459 __collector_pwrite_2_1 (int fildes, const void *buf, size_t nbyte, off_t offset)
2462 if (NULL_PTR (pwrite_2_1))
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))
2471 POP_REENTRANCE (guard);
2474 write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2475 POP_REENTRANCE (guard);
2481 pwrite (int fildes, const void *buf, size_t nbyte, off_t offset)
2484 if (NULL_PTR (pwrite))
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))
2493 POP_REENTRANCE (guard);
2496 write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2497 POP_REENTRANCE (guard);
2502 /*------------------------------------------------------------- pwrite64 */
2504 #if !defined(__MUSL_LIBC) && ARCH(Intel)
2505 // map interposed symbol versions
2507 SYMVER_ATTRIBUTE (__collector_pwrite64_2_2, pwrite64@GLIBC_2.2)
2509 __collector_pwrite64_2_2 (int fildes, const void *buf, size_t nbyte, off64_t offset)
2512 if (NULL_PTR (pwrite64_2_2))
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))
2521 POP_REENTRANCE (guard);
2524 write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2525 POP_REENTRANCE (guard);
2529 SYMVER_ATTRIBUTE (__collector_pwrite64_2_1, pwrite64@GLIBC_2.1)
2531 __collector_pwrite64_2_1 (int fildes, const void *buf, size_t nbyte, off64_t offset)
2534 if (NULL_PTR (pwrite64_2_1))
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))
2543 POP_REENTRANCE (guard);
2546 write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2547 POP_REENTRANCE (guard);
2553 pwrite64 (int fildes, const void *buf, size_t nbyte, off64_t offset)
2556 if (NULL_PTR (pwrite64))
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))
2565 POP_REENTRANCE (guard);
2568 write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2569 POP_REENTRANCE (guard);
2573 #endif /* SIZE(32) */
2575 /*------------------------------------------------------------- fgets */
2577 fgets (char *s, int n, FILE *stream)
2581 IOTrace_packet iopkt;
2582 if (NULL_PTR (fgets))
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))
2591 POP_REENTRANCE (guard);
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;
2602 iopkt.iotype = READ_TRACE;
2603 iopkt.nbyte = collector_strlen (ptr);
2605 else if (ptr == NULL && error != EAGAIN && error != EBADF && error != EINTR &&
2606 error != EIO && error != EOVERFLOW && error != ENOMEM && error != ENXIO)
2608 iopkt.iotype = READ_TRACE;
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);
2620 /*------------------------------------------------------------- fputs */
2622 fputs (const char *s, FILE *stream)
2626 IOTrace_packet iopkt;
2627 if (NULL_PTR (fputs))
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))
2636 POP_REENTRANCE (guard);
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;
2646 iopkt.iotype = WRITE_TRACE;
2651 iopkt.iotype = WRITE_TRACE_ERROR;
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);
2661 /*------------------------------------------------------------- fputc */
2663 fputc (int c, FILE *stream)
2667 IOTrace_packet iopkt;
2668 if (NULL_PTR (fputc))
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))
2677 POP_REENTRANCE (guard);
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;
2687 iopkt.iotype = WRITE_TRACE;
2692 iopkt.iotype = WRITE_TRACE_ERROR;
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);
2702 /*------------------------------------------------------------- fprintf */
2704 fprintf (FILE *stream, const char *format, ...)
2708 IOTrace_packet iopkt;
2710 va_start (ap, format);
2711 if (NULL_PTR (fprintf))
2713 if (NULL_PTR (vfprintf))
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))
2722 POP_REENTRANCE (guard);
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;
2731 iopkt.iotype = WRITE_TRACE;
2733 iopkt.iotype = WRITE_TRACE_ERROR;
2734 iopkt.fd = fileno (stream);
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);
2742 /*------------------------------------------------------------- vfprintf */
2744 vfprintf (FILE *stream, const char *format, va_list ap)
2748 IOTrace_packet iopkt;
2749 if (NULL_PTR (vfprintf))
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))
2758 POP_REENTRANCE (guard);
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;
2767 iopkt.iotype = WRITE_TRACE;
2769 iopkt.iotype = WRITE_TRACE_ERROR;
2770 iopkt.fd = fileno (stream);
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);
2778 /*------------------------------------------------------------- lseek */
2780 lseek (int fildes, off_t offset, int whence)
2784 IOTrace_packet iopkt;
2785 if (NULL_PTR (lseek))
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))
2794 POP_REENTRANCE (guard);
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;
2803 iopkt.iotype = OTHERIO_TRACE;
2805 iopkt.iotype = OTHERIO_TRACE_ERROR;
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);
2813 /*------------------------------------------------------------- llseek */
2815 llseek (int fildes, offset_t offset, int whence)
2819 IOTrace_packet iopkt;
2820 if (NULL_PTR (llseek))
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))
2829 POP_REENTRANCE (guard);
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;
2838 iopkt.iotype = OTHERIO_TRACE;
2840 iopkt.iotype = OTHERIO_TRACE_ERROR;
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);
2848 /*------------------------------------------------------------- chmod */
2850 chmod (const char *path, mode_t mode)
2855 IOTrace_packet *iopkt;
2858 if (NULL_PTR (chmod))
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))
2867 POP_REENTRANCE (guard);
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);
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;
2884 iopkt->iotype = OTHERIO_TRACE;
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);
2894 Tprintf (0, "iotrace: ERROR: chmod cannot allocate memory\n");
2897 POP_REENTRANCE (guard);
2901 /*------------------------------------------------------------- access */
2903 access (const char *path, int amode)
2908 IOTrace_packet *iopkt;
2911 if (NULL_PTR (access))
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))
2920 POP_REENTRANCE (guard);
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);
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;
2937 iopkt->iotype = OTHERIO_TRACE;
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);
2947 Tprintf (0, "iotrace: ERROR: access cannot allocate memory\n");
2950 POP_REENTRANCE (guard);
2954 /*------------------------------------------------------------- rename */
2956 rename (const char *old, const char *new)
2961 IOTrace_packet *iopkt;
2964 if (NULL_PTR (rename))
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))
2973 POP_REENTRANCE (guard);
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);
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;
2990 iopkt->iotype = OTHERIO_TRACE;
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);
3000 Tprintf (0, "iotrace: ERROR: rename cannot allocate memory\n");
3003 POP_REENTRANCE (guard);
3007 /*------------------------------------------------------------- mkdir */
3009 mkdir (const char *path, mode_t mode)
3014 IOTrace_packet *iopkt;
3017 if (NULL_PTR (mkdir))
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))
3026 POP_REENTRANCE (guard);
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);
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;
3043 iopkt->iotype = OTHERIO_TRACE;
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);
3053 Tprintf (0, "iotrace: ERROR: mkdir cannot allocate memory\n");
3056 POP_REENTRANCE (guard);
3060 /*------------------------------------------------------------- getdents */
3062 getdents (int fildes, struct dirent *buf, size_t nbyte)
3066 IOTrace_packet iopkt;
3067 if (NULL_PTR (getdents))
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))
3076 POP_REENTRANCE (guard);
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;
3085 iopkt.iotype = OTHERIO_TRACE;
3087 iopkt.iotype = OTHERIO_TRACE_ERROR;
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);
3095 /*------------------------------------------------------------- unlink */
3097 unlink (const char *path)
3102 IOTrace_packet *iopkt;
3105 if (NULL_PTR (unlink))
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))
3114 POP_REENTRANCE (guard);
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);
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;
3131 iopkt->iotype = OTHERIO_TRACE;
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);
3141 Tprintf (0, "iotrace: ERROR: unlink cannot allocate memory\n");
3144 POP_REENTRANCE (guard);
3148 /*------------------------------------------------------------- fseek */
3150 fseek (FILE *stream, long offset, int whence)
3154 IOTrace_packet iopkt;
3155 if (NULL_PTR (fseek))
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))
3164 POP_REENTRANCE (guard);
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;
3173 iopkt.iotype = OTHERIO_TRACE;
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);
3183 /*------------------------------------------------------------- rewind */
3185 rewind (FILE *stream)
3188 IOTrace_packet iopkt;
3189 if (NULL_PTR (rewind))
3191 if (CHCK_REENTRANCE (guard) || stream == NULL)
3193 CALL_REAL (rewind)(stream);
3196 PUSH_REENTRANCE (guard);
3197 hrtime_t reqt = gethrtime ();
3198 CALL_REAL (rewind)(stream);
3199 if (RECHCK_REENTRANCE (guard))
3201 POP_REENTRANCE (guard);
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);
3216 /*------------------------------------------------------------- ftell */
3218 ftell (FILE *stream)
3222 IOTrace_packet iopkt;
3223 if (NULL_PTR (ftell))
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))
3232 POP_REENTRANCE (guard);
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;
3241 iopkt.iotype = OTHERIO_TRACE;
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);
3251 /*------------------------------------------------------------- fgetpos */
3252 // map interposed symbol versions
3253 #if ARCH(Intel) && WSIZE(32)
3255 __collector_fgetpos_symver (int(real_fgetpos) (), FILE *stream, fpos_t *pos);
3257 SYMVER_ATTRIBUTE (__collector_fgetpos_2_2, fgetpos@GLIBC_2.2)
3259 __collector_fgetpos_2_2 (FILE *stream, fpos_t *pos)
3261 if (NULL_PTR (fgetpos))
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);
3267 SYMVER_ATTRIBUTE (__collector_fgetpos_2_0, fgetpos@GLIBC_2.0)
3269 __collector_fgetpos_2_0 (FILE *stream, fpos_t *pos)
3271 if (NULL_PTR (fgetpos))
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);
3278 #if ARCH(Intel) && WSIZE(32)
3281 __collector_fgetpos_symver (int(real_fgetpos) (), FILE *stream, fpos_t *pos)
3285 fgetpos (FILE *stream, fpos_t *pos)
3290 IOTrace_packet iopkt;
3291 if (NULL_PTR (fgetpos))
3293 if (CHCK_REENTRANCE (guard) || stream == NULL)
3295 #if ARCH(Intel) && WSIZE(32)
3296 return (real_fgetpos) (stream, pos);
3298 return CALL_REAL (fgetpos)(stream, pos);
3301 PUSH_REENTRANCE (guard);
3302 hrtime_t reqt = gethrtime ();
3303 #if ARCH(Intel) && WSIZE(32)
3304 ret = (real_fgetpos) (stream, pos);
3306 ret = CALL_REAL (fgetpos)(stream, pos);
3308 if (RECHCK_REENTRANCE (guard))
3310 POP_REENTRANCE (guard);
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;
3319 iopkt.iotype = OTHERIO_TRACE;
3321 iopkt.iotype = OTHERIO_TRACE_ERROR;
3322 iopkt.fd = fileno (stream);
3324 #if ARCH(Intel) && WSIZE(32)
3325 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
3327 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3329 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3330 POP_REENTRANCE (guard);
3335 /*------------------------------------------------------------- fgetpos64 */
3337 // map interposed symbol versions
3340 __collector_fgetpos64_symver (int(real_fgetpos64) (), FILE *stream, fpos64_t *pos);
3342 SYMVER_ATTRIBUTE (__collector_fgetpos64_2_2, fgetpos64@GLIBC_2.2)
3344 __collector_fgetpos64_2_2 (FILE *stream, fpos64_t *pos)
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))
3350 return __collector_fgetpos64_symver (CALL_REAL (fgetpos64_2_2), stream, pos);
3353 SYMVER_ATTRIBUTE (__collector_fgetpos64_2_1, fgetpos64@GLIBC_2.1)
3355 __collector_fgetpos64_2_1 (FILE *stream, fpos64_t *pos)
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))
3361 return __collector_fgetpos64_symver (CALL_REAL (fgetpos64_2_1), stream, pos);
3365 __collector_fgetpos64_symver (int(real_fgetpos64) (), FILE *stream, fpos64_t *pos)
3369 fgetpos64 (FILE *stream, fpos64_t *pos)
3374 IOTrace_packet iopkt;
3375 if (NULL_PTR (fgetpos64))
3377 if (CHCK_REENTRANCE (guard) || stream == NULL)
3380 return (real_fgetpos64) (stream, pos);
3382 return CALL_REAL (fgetpos64)(stream, pos);
3385 PUSH_REENTRANCE (guard);
3386 hrtime_t reqt = gethrtime ();
3388 ret = (real_fgetpos64) (stream, pos);
3390 ret = CALL_REAL (fgetpos64)(stream, pos);
3392 if (RECHCK_REENTRANCE (guard))
3394 POP_REENTRANCE (guard);
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;
3403 iopkt.iotype = OTHERIO_TRACE;
3405 iopkt.iotype = OTHERIO_TRACE_ERROR;
3406 iopkt.fd = fileno (stream);
3408 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
3410 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3412 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3413 POP_REENTRANCE (guard);
3418 /*------------------------------------------------------------- fsetpos */
3419 // map interposed symbol versions
3420 #if ARCH(Intel) && WSIZE(32)
3422 __collector_fsetpos_symver (int(real_fsetpos) (), FILE *stream, const fpos_t *pos);
3424 SYMVER_ATTRIBUTE (__collector_fsetpos_2_2, fsetpos@GLIBC_2.2)
3426 __collector_fsetpos_2_2 (FILE *stream, const fpos_t *pos)
3428 if (NULL_PTR (fsetpos))
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);
3434 SYMVER_ATTRIBUTE (__collector_fsetpos_2_0, fsetpos@GLIBC_2.0)
3436 __collector_fsetpos_2_0 (FILE *stream, const fpos_t *pos)
3438 if (NULL_PTR (fsetpos))
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);
3445 #if ARCH(Intel) && WSIZE(32)
3448 __collector_fsetpos_symver (int(real_fsetpos) (), FILE *stream, const fpos_t *pos)
3452 fsetpos (FILE *stream, const fpos_t *pos)
3457 IOTrace_packet iopkt;
3458 if (NULL_PTR (fsetpos))
3460 if (CHCK_REENTRANCE (guard) || stream == NULL)
3462 #if ARCH(Intel) && WSIZE(32)
3463 return (real_fsetpos) (stream, pos);
3465 return CALL_REAL (fsetpos)(stream, pos);
3468 PUSH_REENTRANCE (guard);
3469 hrtime_t reqt = gethrtime ();
3470 #if ARCH(Intel) && WSIZE(32)
3471 ret = (real_fsetpos) (stream, pos);
3473 ret = CALL_REAL (fsetpos)(stream, pos);
3475 if (RECHCK_REENTRANCE (guard))
3477 POP_REENTRANCE (guard);
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;
3486 iopkt.iotype = OTHERIO_TRACE;
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);
3493 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3495 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3496 POP_REENTRANCE (guard);
3501 /*------------------------------------------------------------- fsetpos64 */
3503 // map interposed symbol versions
3505 __collector_fsetpos64_symver (int(real_fsetpos64) (), FILE *stream, const fpos64_t *pos);
3507 SYMVER_ATTRIBUTE (__collector_fsetpos64_2_2, fsetpos64@GLIBC_2.2)
3509 __collector_fsetpos64_2_2 (FILE *stream, const fpos64_t *pos)
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))
3515 return __collector_fsetpos64_symver (CALL_REAL (fsetpos64_2_2), stream, pos);
3518 SYMVER_ATTRIBUTE (__collector_fsetpos64_2_1, fsetpos64@GLIBC_2.1)
3520 __collector_fsetpos64_2_1 (FILE *stream, const fpos64_t *pos)
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))
3526 return __collector_fsetpos64_symver (CALL_REAL (fsetpos64_2_1), stream, pos);
3530 __collector_fsetpos64_symver (int(real_fsetpos64) (), FILE *stream, const fpos64_t *pos)
3534 fsetpos64 (FILE *stream, const fpos64_t *pos)
3539 IOTrace_packet iopkt;
3540 if (NULL_PTR (fsetpos64))
3542 if (CHCK_REENTRANCE (guard) || stream == NULL)
3544 #if ARCH(Intel) && WSIZE(32)
3545 return (real_fsetpos64) (stream, pos);
3547 return CALL_REAL (fsetpos64)(stream, pos);
3550 PUSH_REENTRANCE (guard);
3551 hrtime_t reqt = gethrtime ();
3552 #if ARCH(Intel) && WSIZE(32)
3553 ret = (real_fsetpos64) (stream, pos);
3555 ret = CALL_REAL (fsetpos64)(stream, pos);
3557 if (RECHCK_REENTRANCE (guard))
3559 POP_REENTRANCE (guard);
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;
3568 iopkt.iotype = OTHERIO_TRACE;
3570 iopkt.iotype = OTHERIO_TRACE_ERROR;
3571 iopkt.fd = fileno (stream);
3573 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
3575 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3577 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3578 POP_REENTRANCE (guard);
3583 /*------------------------------------------------------------- fsync */
3589 IOTrace_packet iopkt;
3590 if (NULL_PTR (fsync))
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))
3599 POP_REENTRANCE (guard);
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;
3608 iopkt.iotype = OTHERIO_TRACE;
3610 iopkt.iotype = OTHERIO_TRACE_ERROR;
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);
3618 /*------------------------------------------------------------- readdir */
3624 IOTrace_packet iopkt;
3625 if (NULL_PTR (readdir))
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))
3634 POP_REENTRANCE (guard);
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;
3643 iopkt.iotype = OTHERIO_TRACE;
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);
3652 /*------------------------------------------------------------- flock */
3654 flock (int fd, int operation)
3658 IOTrace_packet iopkt;
3659 if (NULL_PTR (flock))
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))
3668 POP_REENTRANCE (guard);
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;
3677 iopkt.iotype = OTHERIO_TRACE;
3679 iopkt.iotype = OTHERIO_TRACE_ERROR;
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);
3687 /*------------------------------------------------------------- lockf */
3689 lockf (int fildes, int function, off_t size)
3693 IOTrace_packet iopkt;
3694 if (NULL_PTR (lockf))
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))
3703 POP_REENTRANCE (guard);
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;
3712 iopkt.iotype = OTHERIO_TRACE;
3714 iopkt.iotype = OTHERIO_TRACE_ERROR;
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);