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