arm: Support pac_key_* register operand for MRS/MSR in Armv8.1-M Mainline
[binutils-gdb.git] / gprofng / libcollector / iotrace.c
blob3deb441d9c7177be1b81c020cf7ab99307860957
1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
2 Contributed by Oracle.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
22 * IO events
24 #include "config.h"
25 #include <dlfcn.h>
26 #include <errno.h>
27 #include <stdarg.h>
28 #include <stddef.h>
29 #include <stdlib.h>
31 // create() and others are defined in fcntl.h.
32 // Our 'create' should not have the __nonnull attribute
33 #undef __nonnull
34 #define __nonnull(x)
35 #include <fcntl.h>
37 #include "gp-defs.h"
38 #include "collector.h"
39 #include "gp-experiment.h"
40 #include "tsd.h"
43 /* define the packet that will be written out */
44 typedef struct IOTrace_packet
45 { /* IO tracing packet */
46 Common_packet comm;
47 IOTrace_type iotype; /* IO type */
48 int32_t fd; /* file descriptor */
49 Size_type nbyte; /* number of bytes */
50 hrtime_t requested; /* time of IO requested */
51 int32_t ofd; /* original file descriptor */
52 FileSystem_type fstype; /* file system type */
53 char fname; /* file name */
54 } IOTrace_packet;
56 typedef long long offset_t;
58 static int open_experiment (const char *);
59 static int start_data_collection (void);
60 static int stop_data_collection (void);
61 static int close_experiment (void);
62 static int detach_experiment (void);
63 static int init_io_intf ();
65 static ModuleInterface module_interface ={
66 SP_IOTRACE_FILE, /* description */
67 NULL, /* initInterface */
68 open_experiment, /* openExperiment */
69 start_data_collection, /* startDataCollection */
70 stop_data_collection, /* stopDataCollection */
71 close_experiment, /* closeExperiment */
72 detach_experiment /* detachExperiment (fork child) */
75 static CollectorInterface *collector_interface = NULL;
76 static struct Heap *io_heap = NULL;
77 static int io_mode = 0;
78 static CollectorModule io_hndl = COLLECTOR_MODULE_ERR;
79 static unsigned io_key = COLLECTOR_TSD_INVALID_KEY;
81 #define CHCK_REENTRANCE(x) (!io_mode || ((x) = collector_interface->getKey( io_key )) == NULL || (*(x) != 0))
82 #define RECHCK_REENTRANCE(x) (!io_mode || ((x) = collector_interface->getKey( io_key )) == NULL || (*(x) == 0))
83 #define PUSH_REENTRANCE(x) ((*(x))++)
84 #define POP_REENTRANCE(x) ((*(x))--)
85 #define gethrtime collector_interface->getHiResTime
88 /* interposition function handles */
89 static int (*__real_open)(const char *path, int oflag, ...) = NULL;
90 static int (*__real_fcntl)(int fildes, int cmd, ...) = NULL;
91 static int (*__real_openat)(int fildes, const char *path, int oflag, ...) = NULL;
92 static int (*__real_close)(int fildes) = NULL;
93 static FILE *(*__real_fopen)(const char *filename, const char *mode) = NULL;
94 static int (*__real_fclose)(FILE *stream) = NULL;
95 static int (*__real_dup)(int fildes) = NULL;
96 static int (*__real_dup2)(int fildes, int fildes2) = NULL;
97 static int (*__real_pipe)(int fildes[2]) = NULL;
98 static int (*__real_socket)(int domain, int type, int protocol) = NULL;
99 static int (*__real_mkstemp)(char *template) = NULL;
100 static int (*__real_mkstemps)(char *template, int slen) = NULL;
101 static int (*__real_creat)(const char *path, mode_t mode) = NULL;
102 static FILE *(*__real_fdopen)(int fildes, const char *mode) = NULL;
103 static ssize_t (*__real_read)(int fildes, void *buf, size_t nbyte) = NULL;
104 static ssize_t (*__real_write)(int fildes, const void *buf, size_t nbyte) = NULL;
105 static ssize_t (*__real_readv)(int fildes, const struct iovec *iov, int iovcnt) = NULL;
106 static ssize_t (*__real_writev)(int fildes, const struct iovec *iov, int iovcnt) = NULL;
107 static size_t (*__real_fread)(void *ptr, size_t size, size_t nitems, FILE *stream) = NULL;
108 static size_t (*__real_fwrite)(const void *ptr, size_t size, size_t nitems, FILE *stream) = NULL;
109 static ssize_t (*__real_pread)(int fildes, void *buf, size_t nbyte, off_t offset) = NULL;
110 static ssize_t (*__real_pwrite)(int fildes, const void *buf, size_t nbyte, off_t offset) = NULL;
111 static ssize_t (*__real_pwrite64)(int fildes, const void *buf, size_t nbyte, off64_t offset) = NULL;
112 static char *(*__real_fgets)(char *s, int n, FILE *stream) = NULL;
113 static int (*__real_fputs)(const char *s, FILE *stream) = NULL;
114 static int (*__real_fputc)(int c, FILE *stream) = NULL;
115 static int (*__real_fprintf)(FILE *stream, const char *format, ...) = NULL;
116 static int (*__real_vfprintf)(FILE *stream, const char *format, va_list ap) = NULL;
117 static off_t (*__real_lseek)(int fildes, off_t offset, int whence) = NULL;
118 static offset_t (*__real_llseek)(int fildes, offset_t offset, int whence) = NULL;
119 static int (*__real_chmod)(const char *path, mode_t mode) = NULL;
120 static int (*__real_access)(const char *path, int amode) = NULL;
121 static int (*__real_rename)(const char *old, const char *new) = NULL;
122 static int (*__real_mkdir)(const char *path, mode_t mode) = NULL;
123 static int (*__real_getdents)(int fildes, struct dirent *buf, size_t nbyte) = NULL;
124 static int (*__real_unlink)(const char *path) = NULL;
125 static int (*__real_fseek)(FILE *stream, long offset, int whence) = NULL;
126 static void (*__real_rewind)(FILE *stream) = NULL;
127 static long (*__real_ftell)(FILE *stream) = NULL;
128 static int (*__real_fgetpos)(FILE *stream, fpos_t *pos) = NULL;
129 static int (*__real_fsetpos)(FILE *stream, const fpos_t *pos) = NULL;
130 static int (*__real_fsync)(int fildes) = NULL;
131 static struct dirent *(*__real_readdir)(DIR *dirp) = NULL;
132 static int (*__real_flock)(int fd, int operation) = NULL;
133 static int (*__real_lockf)(int fildes, int function, off_t size) = NULL;
134 static int (*__real_fflush)(FILE *stream) = NULL;
135 static int (*__real_open64)(const char *path, int oflag, ...) = NULL;
136 static int (*__real_open64_2_2)(const char *path, int oflag, ...) = NULL;
137 static int (*__real_creat64)(const char *path, mode_t mode) = NULL;
138 static int (*__real_fgetpos64)(FILE *stream, fpos64_t *pos) = NULL;
139 static int (*__real_fsetpos64)(FILE *stream, const fpos64_t *pos) = NULL;
140 static FILE *(*__real_fopen_2_17)(const char *filename, const char *mode) = NULL;
141 static FILE *(*__real_fopen_2_2_5)(const char *filename, const char *mode) = NULL;
142 static FILE *(*__real_fopen_2_1)(const char *filename, const char *mode) = NULL;
143 static FILE *(*__real_fopen_2_0)(const char *filename, const char *mode) = NULL;
144 static int (*__real_fclose_2_17)(FILE *stream) = NULL;
145 static int (*__real_fclose_2_2_5)(FILE *stream) = NULL;
146 static int (*__real_fclose_2_1)(FILE *stream) = NULL;
147 static int (*__real_fclose_2_0)(FILE *stream) = NULL;
148 static FILE *(*__real_fdopen_2_17)(int fildes, const char *mode) = NULL;
149 static FILE *(*__real_fdopen_2_2_5)(int fildes, const char *mode) = NULL;
150 static FILE *(*__real_fdopen_2_1)(int fildes, const char *mode) = NULL;
151 static FILE *(*__real_fdopen_2_0)(int fildes, const char *mode) = NULL;
152 static int (*__real_fgetpos_2_17)(FILE *stream, fpos_t *pos) = NULL;
153 static int (*__real_fgetpos_2_2_5)(FILE *stream, fpos_t *pos) = NULL;
154 static int (*__real_fgetpos_2_2)(FILE *stream, fpos_t *pos) = NULL;
155 static int (*__real_fgetpos_2_0)(FILE *stream, fpos_t *pos) = NULL;
156 static int (*__real_fsetpos_2_17)(FILE *stream, const fpos_t *pos) = NULL;
157 static int (*__real_fsetpos_2_2_5)(FILE *stream, const fpos_t *pos) = NULL;
158 static int (*__real_fsetpos_2_2)(FILE *stream, const fpos_t *pos) = NULL;
159 static int (*__real_fsetpos_2_0)(FILE *stream, const fpos_t *pos) = NULL;
160 static ssize_t (*__real_pread_2_2)(int fildes, void *buf, size_t nbyte, off_t offset) = NULL;
161 static ssize_t (*__real_pwrite_2_2)(int fildes, const void *buf, size_t nbyte, off_t offset) = NULL;
162 static int (*__real_fgetpos64_2_17)(FILE *stream, fpos64_t *pos) = NULL;
163 static int (*__real_fgetpos64_2_2_5)(FILE *stream, fpos64_t *pos) = NULL;
164 static int (*__real_fgetpos64_2_2)(FILE *stream, fpos64_t *pos) = NULL;
165 static int (*__real_fgetpos64_2_1)(FILE *stream, fpos64_t *pos) = NULL;
166 static int (*__real_fsetpos64_2_17)(FILE *stream, const fpos64_t *pos) = NULL;
167 static int (*__real_fsetpos64_2_2_5)(FILE *stream, const fpos64_t *pos) = NULL;
168 static int (*__real_fsetpos64_2_2)(FILE *stream, const fpos64_t *pos) = NULL;
169 static int (*__real_fsetpos64_2_1)(FILE *stream, const fpos64_t *pos) = NULL;
170 static ssize_t (*__real_pwrite64_2_2)(int fildes, const void *buf, size_t nbyte, off64_t offset) = NULL;
172 static int
173 collector_align_pktsize (int sz)
175 int pktSize = sz;
176 if (sz <= 0)
177 return sz;
178 if ((sz % 8) != 0)
180 pktSize = (sz / 8) + 1;
181 pktSize *= 8;
183 return pktSize;
186 static void
187 collector_memset (void *s, int c, size_t n)
189 unsigned char *s1 = s;
190 while (n--)
191 *s1++ = (unsigned char) c;
194 static size_t
195 collector_strlen (const char *s)
197 if (s == NULL)
198 return 0;
199 int len = -1;
200 while (s[++len] != '\0')
202 return len;
205 static size_t
206 collector_strncpy (char *dst, const char *src, size_t dstsize)
208 size_t i;
209 for (i = 0; i < dstsize; i++)
211 dst[i] = src[i];
212 if (src[i] == '\0')
213 break;
215 return i;
218 static char *
219 collector_strchr (const char *s, int c)
223 if (*s == (char) c)
224 return ((char *) s);
226 while (*s++);
227 return (NULL);
230 static FileSystem_type
231 collector_fstype (const char *path)
233 return UNKNOWNFS_TYPE;
236 void
237 __collector_module_init (CollectorInterface *_collector_interface)
239 if (_collector_interface == NULL)
240 return;
241 collector_interface = _collector_interface;
242 Tprintf (0, "iotrace: __collector_module_init\n");
243 io_hndl = collector_interface->registerModule (&module_interface);
244 /* Initialize next module */
245 ModuleInitFunc next_init = (ModuleInitFunc) dlsym (RTLD_NEXT, "__collector_module_init");
246 if (next_init != NULL)
247 next_init (_collector_interface);
248 return;
251 static int
252 open_experiment (const char *exp)
254 if (collector_interface == NULL)
256 Tprintf (0, "iotrace: collector_interface is null.\n");
257 return COL_ERROR_IOINIT;
259 if (io_hndl == COLLECTOR_MODULE_ERR)
261 Tprintf (0, "iotrace: handle create failed.\n");
262 collector_interface->writeLog ("<event kind=\"%s\" id=\"%d\">data handle not created</event>\n",
263 SP_JCMD_CERROR, COL_ERROR_IOINIT);
264 return COL_ERROR_IOINIT;
266 TprintfT (0, "iotrace: open_experiment %s\n", exp);
267 if (NULL_PTR (fopen))
268 init_io_intf ();
269 if (io_heap == NULL)
271 io_heap = collector_interface->newHeap ();
272 if (io_heap == NULL)
274 Tprintf (0, "iotrace: new heap failed.\n");
275 collector_interface->writeLog ("<event kind=\"%s\" id=\"%d\">new iotrace heap not created</event>\n",
276 SP_JCMD_CERROR, COL_ERROR_IOINIT);
277 return COL_ERROR_IOINIT;
281 const char *params = collector_interface->getParams ();
282 while (params)
284 if ((params[0] == 'i') && (params[1] == ':'))
286 params += 2;
287 break;
289 params = collector_strchr (params, ';');
290 if (params)
291 params++;
293 if (params == NULL) /* IO data collection not specified */
294 return COL_ERROR_IOINIT;
296 io_key = collector_interface->createKey (sizeof ( int), NULL, NULL);
297 if (io_key == (unsigned) - 1)
299 Tprintf (0, "iotrace: TSD key create failed.\n");
300 collector_interface->writeLog ("<event kind=\"%s\" id=\"%d\">TSD key not created</event>\n",
301 SP_JCMD_CERROR, COL_ERROR_IOINIT);
302 return COL_ERROR_IOINIT;
305 collector_interface->writeLog ("<profile name=\"%s\">\n", SP_JCMD_IOTRACE);
306 collector_interface->writeLog (" <profdata fname=\"%s\"/>\n",
307 module_interface.description);
308 /* Record IOTrace_packet description */
309 collector_interface->writeLog (" <profpckt kind=\"%d\" uname=\"IO tracing data\">\n", IOTRACE_PCKT);
310 collector_interface->writeLog (" <field name=\"LWPID\" uname=\"Lightweight process id\" offset=\"%d\" type=\"%s\"/>\n",
311 (int) offsetof (IOTrace_packet, comm.lwp_id),
312 fld_sizeof (IOTrace_packet, comm.lwp_id) == 4 ? "INT32" : "INT64");
313 collector_interface->writeLog (" <field name=\"THRID\" uname=\"Thread number\" offset=\"%d\" type=\"%s\"/>\n",
314 (int) offsetof (IOTrace_packet, comm.thr_id),
315 fld_sizeof (IOTrace_packet, comm.thr_id) == 4 ? "INT32" : "INT64");
316 collector_interface->writeLog (" <field name=\"CPUID\" uname=\"CPU id\" offset=\"%d\" type=\"%s\"/>\n",
317 (int) offsetof (IOTrace_packet, comm.cpu_id),
318 fld_sizeof (IOTrace_packet, comm.cpu_id) == 4 ? "INT32" : "INT64");
319 collector_interface->writeLog (" <field name=\"TSTAMP\" uname=\"High resolution timestamp\" offset=\"%d\" type=\"%s\"/>\n",
320 (int) offsetof (IOTrace_packet, comm.tstamp),
321 fld_sizeof (IOTrace_packet, comm.tstamp) == 4 ? "INT32" : "INT64");
322 collector_interface->writeLog (" <field name=\"FRINFO\" offset=\"%d\" type=\"%s\"/>\n",
323 (int) offsetof (IOTrace_packet, comm.frinfo),
324 fld_sizeof (IOTrace_packet, comm.frinfo) == 4 ? "INT32" : "INT64");
325 collector_interface->writeLog (" <field name=\"IOTYPE\" uname=\"IO trace function type\" offset=\"%d\" type=\"%s\"/>\n",
326 (int) offsetof (IOTrace_packet, iotype),
327 fld_sizeof (IOTrace_packet, iotype) == 4 ? "INT32" : "INT64");
328 collector_interface->writeLog (" <field name=\"IOFD\" uname=\"File descriptor\" offset=\"%d\" type=\"%s\"/>\n",
329 (int) offsetof (IOTrace_packet, fd),
330 fld_sizeof (IOTrace_packet, fd) == 4 ? "INT32" : "INT64");
331 collector_interface->writeLog (" <field name=\"IONBYTE\" uname=\"Number of bytes\" offset=\"%d\" type=\"%s\"/>\n",
332 (int) offsetof (IOTrace_packet, nbyte),
333 fld_sizeof (IOTrace_packet, nbyte) == 4 ? "INT32" : "INT64");
334 collector_interface->writeLog (" <field name=\"IORQST\" uname=\"Time of IO requested\" offset=\"%d\" type=\"%s\"/>\n",
335 (int) offsetof (IOTrace_packet, requested),
336 fld_sizeof (IOTrace_packet, requested) == 4 ? "INT32" : "INT64");
337 collector_interface->writeLog (" <field name=\"IOOFD\" uname=\"Original file descriptor\" offset=\"%d\" type=\"%s\"/>\n",
338 (int) offsetof (IOTrace_packet, ofd),
339 fld_sizeof (IOTrace_packet, ofd) == 4 ? "INT32" : "INT64");
340 collector_interface->writeLog (" <field name=\"IOFSTYPE\" uname=\"File system type\" offset=\"%d\" type=\"%s\"/>\n",
341 (int) offsetof (IOTrace_packet, fstype),
342 fld_sizeof (IOTrace_packet, fstype) == 4 ? "INT32" : "INT64");
343 collector_interface->writeLog (" <field name=\"IOFNAME\" uname=\"File name\" offset=\"%d\" type=\"%s\"/>\n",
344 (int) offsetof (IOTrace_packet, fname), "STRING");
345 collector_interface->writeLog (" </profpckt>\n");
346 collector_interface->writeLog ("</profile>\n");
347 return COL_ERROR_NONE;
350 static int
351 start_data_collection (void)
353 io_mode = 1;
354 Tprintf (0, "iotrace: start_data_collection\n");
355 return 0;
358 static int
359 stop_data_collection (void)
361 io_mode = 0;
362 Tprintf (0, "iotrace: stop_data_collection\n");
363 return 0;
366 static int
367 close_experiment (void)
369 io_mode = 0;
370 io_key = COLLECTOR_TSD_INVALID_KEY;
371 if (io_heap != NULL)
373 collector_interface->deleteHeap (io_heap);
374 io_heap = NULL;
376 Tprintf (0, "iotrace: close_experiment\n");
377 return 0;
380 static int
381 detach_experiment (void)
383 /* fork child. Clean up state but don't write to experiment */
384 io_mode = 0;
385 io_key = COLLECTOR_TSD_INVALID_KEY;
386 if (io_heap != NULL)
388 collector_interface->deleteHeap (io_heap);
389 io_heap = NULL;
391 Tprintf (0, "iotrace: detach_experiment\n");
392 return 0;
395 static int
396 init_fopen (void *dlflag)
398 __real_fopen_2_17 = dlvsym (dlflag, "fopen", "GLIBC_2.17");
399 __real_fopen_2_2_5 = dlvsym (dlflag, "fopen", "GLIBC_2.2.5");
400 __real_fopen_2_1 = dlvsym (dlflag, "fopen", "GLIBC_2.1");
401 __real_fopen_2_0 = dlvsym (dlflag, "fopen", "GLIBC_2.0");
402 if (__real_fopen_2_17)
403 __real_fopen = __real_fopen_2_17;
404 else if (__real_fopen_2_2_5)
405 __real_fopen = __real_fopen_2_2_5;
406 else if (__real_fopen_2_1)
407 __real_fopen = __real_fopen_2_1;
408 else if (__real_fopen_2_0)
409 __real_fopen = __real_fopen_2_0;
410 else
411 __real_fopen = dlsym (dlflag, "fopen");
412 return __real_fopen ? 1 : 0;
415 static int
416 init_io_intf ()
418 void *dlflag;
419 int rc = 0;
420 /* if we detect recursion/reentrance, SEGV so we can get a stack */
421 static int init_io_intf_started;
422 static int init_io_intf_finished;
423 init_io_intf_started++;
424 if (!init_io_intf_finished && init_io_intf_started >= 3)
426 /* pull the plug if recursion occurs... */
427 abort ();
430 /* lookup fprint to print fatal error message */
431 void *ptr = dlsym (RTLD_NEXT, "fprintf");
432 if (ptr)
433 __real_fprintf = (int (*)(FILE*, const char*, ...)) ptr;
434 else
435 abort ();
437 dlflag = RTLD_NEXT;
438 if (init_fopen (dlflag) == 0)
440 if (init_fopen (RTLD_DEFAULT))
441 dlflag = RTLD_DEFAULT;
442 else
444 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen\n");
445 rc = COL_ERROR_IOINIT;
449 __real_fgetpos64_2_17 = dlvsym (dlflag, "fgetpos64", "GLIBC_2.17");
450 __real_fgetpos64_2_2_5 = dlvsym (dlflag, "fgetpos64", "GLIBC_2.2.5");
451 __real_fgetpos64_2_2 = dlvsym (dlflag, "fgetpos64", "GLIBC_2.2");
452 __real_fgetpos64_2_1 = dlvsym (dlflag, "fgetpos64", "GLIBC_2.1");
453 if (__real_fgetpos64_2_17)
454 __real_fgetpos64 = __real_fgetpos64_2_17;
455 else if (__real_fgetpos64_2_2_5)
456 __real_fgetpos64 = __real_fgetpos64_2_2_5;
457 else if (__real_fgetpos64_2_2)
458 __real_fgetpos64 = __real_fgetpos64_2_2;
459 else if (__real_fgetpos64_2_1)
460 __real_fgetpos64 = __real_fgetpos64_2_1;
461 else
462 __real_fgetpos64 = dlsym (dlflag, "fgetpos64");
464 __real_fsetpos64_2_17 = dlvsym (dlflag, "fsetpos64", "GLIBC_2.17");
465 __real_fsetpos64_2_2_5 = dlvsym (dlflag, "fsetpos64", "GLIBC_2.2.5");
466 __real_fsetpos64_2_2 = dlvsym (dlflag, "fsetpos64", "GLIBC_2.2");
467 __real_fsetpos64_2_1 = dlvsym (dlflag, "fsetpos64", "GLIBC_2.1");
468 if (__real_fsetpos64_2_17)
469 __real_fsetpos64 = __real_fsetpos64_2_17;
470 else if (__real_fsetpos64_2_2_5)
471 __real_fsetpos64 = __real_fsetpos64_2_2_5;
472 else if (__real_fsetpos64_2_2)
473 __real_fsetpos64 = __real_fsetpos64_2_2;
474 else if (__real_fsetpos64_2_1)
475 __real_fsetpos64 = __real_fsetpos64_2_1;
476 else
477 __real_fsetpos64 = dlsym (dlflag, "fsetpos64");
479 __real_pread_2_2 = dlvsym (dlflag, "pread", "GLIBC_2.2");
480 if (__real_pread_2_2)
481 __real_pread = __real_pread_2_2;
482 else
483 __real_pread = dlsym (dlflag, "pread");
484 if (__real_pread == NULL)
486 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread\n");
487 rc = COL_ERROR_IOINIT;
490 __real_pwrite_2_2 = dlvsym (dlflag, "pwrite", "GLIBC_2.2");
491 if (__real_pwrite_2_2)
492 __real_pwrite = __real_pwrite_2_2;
493 else
494 __real_pwrite = dlsym (dlflag, "pwrite");
495 if (__real_pwrite == NULL)
497 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite\n");
498 rc = COL_ERROR_IOINIT;
502 __real_pwrite64_2_2 = dlvsym (dlflag, "pwrite64", "GLIBC_2.2");
503 if (__real_pwrite64_2_2)
504 __real_pwrite64 = __real_pwrite64_2_2;
505 else
506 __real_pwrite64 = dlsym (dlflag, "pwrite64");
508 __real_fclose_2_17 = dlvsym (dlflag, "fclose", "GLIBC_2.17");
509 __real_fclose_2_2_5 = dlvsym (dlflag, "fclose", "GLIBC_2.2.5");
510 __real_fclose_2_1 = dlvsym (dlflag, "fclose", "GLIBC_2.1");
511 __real_fclose_2_0 = dlvsym (dlflag, "fclose", "GLIBC_2.0");
512 if (__real_fclose_2_17)
513 __real_fclose = __real_fclose_2_17;
514 else if (__real_fclose_2_2_5)
515 __real_fclose = __real_fclose_2_2_5;
516 else if (__real_fclose_2_1)
517 __real_fclose = __real_fclose_2_1;
518 else if (__real_fclose_2_0)
519 __real_fclose = __real_fclose_2_0;
520 else
521 __real_fclose = dlsym (dlflag, "fclose");
522 if (__real_fclose == NULL)
524 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose\n");
525 rc = COL_ERROR_IOINIT;
528 __real_fdopen_2_17 = dlvsym (dlflag, "fdopen", "GLIBC_2.17");
529 __real_fdopen_2_2_5 = dlvsym (dlflag, "fdopen", "GLIBC_2.2.5");
530 __real_fdopen_2_1 = dlvsym (dlflag, "fdopen", "GLIBC_2.1");
531 __real_fdopen_2_0 = dlvsym (dlflag, "fdopen", "GLIBC_2.0");
532 if (__real_fdopen_2_17)
533 __real_fdopen = __real_fdopen_2_17;
534 else if (__real_fdopen_2_2_5)
535 __real_fdopen = __real_fdopen_2_2_5;
536 else if (__real_fdopen_2_1)
537 __real_fdopen = __real_fdopen_2_1;
538 else if (__real_fdopen_2_0)
539 __real_fdopen = __real_fdopen_2_0;
540 else
541 __real_fdopen = dlsym (dlflag, "fdopen");
542 if (__real_fdopen == NULL)
544 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen\n");
545 rc = COL_ERROR_IOINIT;
548 __real_fgetpos_2_17 = dlvsym (dlflag, "fgetpos", "GLIBC_2.17");
549 __real_fgetpos_2_2_5 = dlvsym (dlflag, "fgetpos", "GLIBC_2.2.5");
550 __real_fgetpos_2_2 = dlvsym (dlflag, "fgetpos", "GLIBC_2.2");
551 __real_fgetpos_2_0 = dlvsym (dlflag, "fgetpos", "GLIBC_2.0");
552 if (__real_fgetpos_2_17)
553 __real_fgetpos = __real_fgetpos_2_17;
554 else if (__real_fgetpos_2_2_5)
555 __real_fgetpos = __real_fgetpos_2_2_5;
556 else if (__real_fgetpos_2_2)
557 __real_fgetpos = __real_fgetpos_2_2;
558 else if (__real_fgetpos_2_0)
559 __real_fgetpos = __real_fgetpos_2_0;
560 else
561 __real_fgetpos = dlsym (dlflag, "fgetpos");
562 if (__real_fgetpos == NULL)
564 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos\n");
565 rc = COL_ERROR_IOINIT;
568 __real_fsetpos_2_17 = dlvsym (dlflag, "fsetpos", "GLIBC_2.17");
569 __real_fsetpos_2_2_5 = dlvsym (dlflag, "fsetpos", "GLIBC_2.2.5");
570 __real_fsetpos_2_2 = dlvsym (dlflag, "fsetpos", "GLIBC_2.2");
571 __real_fsetpos_2_0 = dlvsym (dlflag, "fsetpos", "GLIBC_2.0");
572 if (__real_fsetpos_2_17)
573 __real_fsetpos = __real_fsetpos_2_17;
574 else if (__real_fsetpos_2_2_5)
575 __real_fsetpos = __real_fsetpos_2_2_5;
576 else if (__real_fsetpos_2_2)
577 __real_fsetpos = __real_fsetpos_2_2;
578 else if (__real_fsetpos_2_0)
579 __real_fsetpos = __real_fsetpos_2_0;
580 else
581 __real_fsetpos = dlsym (dlflag, "fsetpos");
582 if (__real_fsetpos == NULL)
584 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos\n");
585 rc = COL_ERROR_IOINIT;
588 __real_open = (int (*)(const char*, int, ...))dlsym (dlflag, "open");
589 if (__real_open == NULL)
591 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open\n");
592 rc = COL_ERROR_IOINIT;
595 __real_open64_2_2 = dlvsym (dlflag, "open64", "GLIBC_2.2");
596 if (__real_open64_2_2)
597 __real_open64 = __real_open64_2_2;
598 else
599 __real_open64 = dlsym (dlflag, "open64");
601 __real_fcntl = (int (*)(int, int, ...))dlsym (dlflag, "fcntl");
602 if (__real_fcntl == NULL)
604 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fcntl\n");
605 rc = COL_ERROR_IOINIT;
608 __real_openat = (int (*)(int, const char*, int, ...))dlsym (dlflag, "openat");
609 if (__real_openat == NULL)
611 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT openat\n");
612 rc = COL_ERROR_IOINIT;
615 __real_close = (int (*)(int))dlsym (dlflag, "close");
616 if (__real_close == NULL)
618 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT close\n");
619 rc = COL_ERROR_IOINIT;
622 __real_dup = (int (*)(int))dlsym (dlflag, "dup");
623 if (__real_dup == NULL)
625 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT dup\n");
626 rc = COL_ERROR_IOINIT;
629 __real_dup2 = (int (*)(int, int))dlsym (dlflag, "dup2");
630 if (__real_dup2 == NULL)
632 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT dup2\n");
633 rc = COL_ERROR_IOINIT;
636 __real_pipe = (int (*)(int[]))dlsym (dlflag, "pipe");
637 if (__real_pipe == NULL)
639 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pipe\n");
640 rc = COL_ERROR_IOINIT;
643 __real_socket = (int (*)(int, int, int))dlsym (dlflag, "socket");
644 if (__real_socket == NULL)
646 __real_socket = (int (*)(int, int, int))dlsym (RTLD_NEXT, "socket");
647 if (__real_socket == NULL)
649 #if 0
650 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT socket\n");
651 rc = COL_ERROR_IOINIT;
652 #endif
656 __real_mkstemp = (int (*)(char*))dlsym (dlflag, "mkstemp");
657 if (__real_mkstemp == NULL)
659 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT mkstemp\n");
660 rc = COL_ERROR_IOINIT;
663 __real_mkstemps = (int (*)(char*, int))dlsym (dlflag, "mkstemps");
664 if (__real_mkstemps == NULL)
666 #if 0
667 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT mkstemps\n");
668 rc = COL_ERROR_IOINIT;
669 #endif
672 __real_creat = (int (*)(const char*, mode_t))dlsym (dlflag, "creat");
673 if (__real_creat == NULL)
675 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT creat\n");
676 rc = COL_ERROR_IOINIT;
679 __real_creat64 = (int (*)(const char*, mode_t))dlsym (dlflag, "creat64");
680 if (__real_creat64 == NULL)
682 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT creat64\n");
683 rc = COL_ERROR_IOINIT;
686 __real_read = (ssize_t (*)(int, void*, size_t))dlsym (dlflag, "read");
687 if (__real_read == NULL)
689 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT read\n");
690 rc = COL_ERROR_IOINIT;
693 __real_write = (ssize_t (*)(int, const void*, size_t))dlsym (dlflag, "write");
694 if (__real_write == NULL)
696 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT write\n");
697 rc = COL_ERROR_IOINIT;
700 __real_readv = (ssize_t (*)(int, const struct iovec*, int))dlsym (dlflag, "readv");
701 if (__real_readv == NULL)
703 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT readv\n");
704 rc = COL_ERROR_IOINIT;
707 __real_writev = (ssize_t (*)(int, const struct iovec*, int))dlsym (dlflag, "writev");
708 if (__real_writev == NULL)
710 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT writev\n");
711 rc = COL_ERROR_IOINIT;
714 __real_fread = (size_t (*)(void*, size_t, size_t, FILE*))dlsym (dlflag, "fread");
715 if (__real_fread == NULL)
717 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fread\n");
718 rc = COL_ERROR_IOINIT;
721 __real_fwrite = (size_t (*)(const void*, size_t, size_t, FILE*))dlsym (dlflag, "fwrite");
722 if (__real_fwrite == NULL)
724 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fwrite\n");
725 rc = COL_ERROR_IOINIT;
728 __real_pread = (ssize_t (*)(int, void*, size_t, off_t))dlsym (dlflag, "pread");
729 if (__real_pread == NULL)
731 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread\n");
732 rc = COL_ERROR_IOINIT;
735 __real_pwrite = (ssize_t (*)(int, const void*, size_t, off_t))dlsym (dlflag, "pwrite");
736 if (__real_pwrite == NULL)
738 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite\n");
739 rc = COL_ERROR_IOINIT;
742 __real_pwrite64 = (ssize_t (*)(int, const void*, size_t, off64_t))dlsym (dlflag, "pwrite64");
743 if (__real_pwrite64 == NULL)
745 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite64\n");
746 rc = COL_ERROR_IOINIT;
749 __real_fgets = (char* (*)(char*, int, FILE*))dlsym (dlflag, "fgets");
750 if (__real_fgets == NULL)
752 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgets\n");
753 rc = COL_ERROR_IOINIT;
756 __real_fputs = (int (*)(const char*, FILE*))dlsym (dlflag, "fputs");
757 if (__real_fputs == NULL)
759 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fputs\n");
760 rc = COL_ERROR_IOINIT;
763 __real_fputc = (int (*)(int, FILE*))dlsym (dlflag, "fputc");
764 if (__real_fputc == NULL)
766 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fputc\n");
767 rc = COL_ERROR_IOINIT;
770 __real_vfprintf = (int (*)(FILE*, const char*, va_list))dlsym (dlflag, "vfprintf");
771 if (__real_vfprintf == NULL)
773 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT vfprintf\n");
774 rc = COL_ERROR_IOINIT;
778 __real_lseek = (off_t (*)(int, off_t, int))dlsym (dlflag, "lseek");
779 if (__real_lseek == NULL)
781 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT lseek\n");
782 rc = COL_ERROR_IOINIT;
785 __real_llseek = (offset_t (*)(int, offset_t, int))dlsym (dlflag, "llseek");
786 if (__real_llseek == NULL)
788 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT llseek\n");
789 rc = COL_ERROR_IOINIT;
792 __real_chmod = (int (*)(const char*, mode_t))dlsym (dlflag, "chmod");
793 if (__real_chmod == NULL)
795 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT chmod\n");
796 rc = COL_ERROR_IOINIT;
799 __real_access = (int (*)(const char*, int))dlsym (dlflag, "access");
800 if (__real_access == NULL)
802 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT access\n");
803 rc = COL_ERROR_IOINIT;
806 __real_rename = (int (*)(const char*, const char*))dlsym (dlflag, "rename");
807 if (__real_rename == NULL)
809 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT rename\n");
810 rc = COL_ERROR_IOINIT;
813 __real_mkdir = (int (*)(const char*, mode_t))dlsym (dlflag, "mkdir");
814 if (__real_mkdir == NULL)
816 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT mkdir\n");
817 rc = COL_ERROR_IOINIT;
820 __real_getdents = (int (*)(int, struct dirent*, size_t))dlsym (dlflag, "getdents");
821 if (__real_getdents == NULL)
823 #if 0
824 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT getdents\n");
825 rc = COL_ERROR_IOINIT;
826 #endif
829 __real_unlink = (int (*)(const char*))dlsym (dlflag, "unlink");
830 if (__real_unlink == NULL)
832 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT unlink\n");
833 rc = COL_ERROR_IOINIT;
836 __real_fseek = (int (*)(FILE*, long, int))dlsym (dlflag, "fseek");
837 if (__real_fseek == NULL)
839 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fseek\n");
840 rc = COL_ERROR_IOINIT;
843 __real_rewind = (void (*)(FILE*))dlsym (dlflag, "rewind");
844 if (__real_rewind == NULL)
846 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT rewind\n");
847 rc = COL_ERROR_IOINIT;
850 __real_ftell = (long (*)(FILE*))dlsym (dlflag, "ftell");
851 if (__real_ftell == NULL)
853 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT ftell\n");
854 rc = COL_ERROR_IOINIT;
857 __real_fsync = (int (*)(int))dlsym (dlflag, "fsync");
858 if (__real_fsync == NULL)
860 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsync\n");
861 rc = COL_ERROR_IOINIT;
864 __real_readdir = (struct dirent * (*)(DIR*))dlsym (dlflag, "readdir");
865 if (__real_readdir == NULL)
867 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT readdir\n");
868 rc = COL_ERROR_IOINIT;
871 __real_flock = (int (*)(int, int))dlsym (dlflag, "flock");
872 if (__real_flock == NULL)
874 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT flock\n");
875 rc = COL_ERROR_IOINIT;
878 __real_lockf = (int (*)(int, int, off_t))dlsym (dlflag, "lockf");
879 if (__real_lockf == NULL)
881 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT lockf\n");
882 rc = COL_ERROR_IOINIT;
885 __real_fflush = (int (*)(FILE*))dlsym (dlflag, "fflush");
886 if (__real_fflush == NULL)
888 CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fflush\n");
889 rc = COL_ERROR_IOINIT;
892 init_io_intf_finished++;
893 return rc;
896 static void
897 write_io_packet (int fd, ssize_t ret, hrtime_t reqt, int iotype)
899 IOTrace_packet iopkt;
900 collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
901 iopkt.comm.tsize = sizeof (IOTrace_packet);
902 iopkt.comm.tstamp = gethrtime ();
903 iopkt.requested = reqt;
904 iopkt.iotype = iotype;
905 iopkt.fd = fd;
906 iopkt.nbyte = ret;
907 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl,
908 iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
909 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
912 /*------------------------------------------------------------- open */
914 open (const char *path, int oflag, ...)
916 int *guard;
917 int fd;
918 void *packet;
919 IOTrace_packet *iopkt;
920 mode_t mode;
921 va_list ap;
922 size_t sz;
923 unsigned pktSize;
925 va_start (ap, oflag);
926 mode = va_arg (ap, mode_t);
927 va_end (ap);
929 if (NULL_PTR (open))
930 init_io_intf ();
932 if (CHCK_REENTRANCE (guard) || path == NULL)
933 return CALL_REAL (open)(path, oflag, mode);
934 PUSH_REENTRANCE (guard);
935 hrtime_t reqt = gethrtime ();
936 fd = CALL_REAL (open)(path, oflag, mode);
937 if (RECHCK_REENTRANCE (guard))
939 POP_REENTRANCE (guard);
940 return fd;
942 hrtime_t grnt = gethrtime ();
943 sz = collector_strlen (path);
944 pktSize = sizeof (IOTrace_packet) + sz;
945 pktSize = collector_align_pktsize (pktSize);
946 Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
947 packet = collector_interface->allocCSize (io_heap, pktSize, 1);
948 if (packet != NULL)
950 iopkt = (IOTrace_packet *) packet;
951 collector_memset (iopkt, 0, pktSize);
952 iopkt->comm.tsize = pktSize;
953 iopkt->comm.tstamp = grnt;
954 iopkt->requested = reqt;
955 if (fd != -1)
956 iopkt->iotype = OPEN_TRACE;
957 else
958 iopkt->iotype = OPEN_TRACE_ERROR;
959 iopkt->fd = fd;
960 iopkt->fstype = collector_fstype (path);
961 collector_strncpy (&(iopkt->fname), path, sz);
962 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
963 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
964 collector_interface->freeCSize (io_heap, packet, pktSize);
966 else
968 Tprintf (0, "iotrace: ERROR: open cannot allocate memory\n");
969 return -1;
971 POP_REENTRANCE (guard);
972 return fd;
975 /*------------------------------------------------------------- open64 */
976 static int
977 gprofng_open64 (int(real_open64) (const char *, int, ...),
978 const char *path, int oflag, mode_t mode)
980 int *guard;
981 int fd;
982 void *packet;
983 IOTrace_packet *iopkt;
984 size_t sz;
985 unsigned pktSize;
986 if (CHCK_REENTRANCE (guard) || path == NULL)
987 return real_open64 (path, oflag, mode);
988 PUSH_REENTRANCE (guard);
989 hrtime_t reqt = gethrtime ();
990 fd = real_open64 (path, oflag, mode);
991 if (RECHCK_REENTRANCE (guard) || path == NULL)
993 POP_REENTRANCE (guard);
994 return fd;
996 hrtime_t grnt = gethrtime ();
997 sz = collector_strlen (path);
998 pktSize = sizeof (IOTrace_packet) + sz;
999 pktSize = collector_align_pktsize (pktSize);
1000 Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1001 packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1002 if (packet != NULL)
1004 iopkt = (IOTrace_packet *) packet;
1005 collector_memset (iopkt, 0, pktSize);
1006 iopkt->comm.tsize = pktSize;
1007 iopkt->comm.tstamp = grnt;
1008 iopkt->requested = reqt;
1009 if (fd != -1)
1010 iopkt->iotype = OPEN_TRACE;
1011 else
1012 iopkt->iotype = OPEN_TRACE_ERROR;
1013 iopkt->fd = fd;
1014 iopkt->fstype = collector_fstype (path);
1015 collector_strncpy (&(iopkt->fname), path, sz);
1016 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl,
1017 iopkt->comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
1018 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1019 collector_interface->freeCSize (io_heap, packet, pktSize);
1021 else
1023 Tprintf (0, "iotrace: ERROR: open64 cannot allocate memory\n");
1024 return -1;
1026 POP_REENTRANCE (guard);
1027 return fd;
1030 #define DCL_OPEN64(dcl_f) \
1031 int dcl_f (const char *path, int oflag, ...) \
1033 if (__real_open64 == NULL) \
1034 init_io_intf (); \
1035 mode_t mode; \
1036 va_list ap; \
1037 va_start (ap, oflag); \
1038 mode = va_arg (ap, mode_t); \
1039 va_end (ap); \
1040 return gprofng_open64 (__real_open64, path, oflag, mode); \
1043 DCL_FUNC_VER (DCL_OPEN64, open64_2_2, open64@GLIBC_2.2)
1044 #if !defined(__USE_LARGEFILE64)
1045 DCL_OPEN64 (open64)
1046 #endif
1048 #define F_ERROR_ARG 0
1049 #define F_INT_ARG 1
1050 #define F_LONG_ARG 2
1051 #define F_VOID_ARG 3
1054 * The following macro is not defined in the
1055 * older versions of Linux.
1056 * #define F_DUPFD_CLOEXEC 1030
1058 * Instead use the command that is defined below
1059 * until we start compiling mpmt on the newer
1060 * versions of Linux.
1062 #define TMP_F_DUPFD_CLOEXEC 1030
1064 /*------------------------------------------------------------- fcntl */
1066 fcntl (int fildes, int cmd, ...)
1068 int *guard;
1069 int fd = 0;
1070 IOTrace_packet iopkt;
1071 long long_arg = 0;
1072 int int_arg = 0;
1073 int which_arg = F_ERROR_ARG;
1074 va_list ap;
1075 switch (cmd)
1077 case F_DUPFD:
1078 case TMP_F_DUPFD_CLOEXEC:
1079 case F_SETFD:
1080 case F_SETFL:
1081 case F_SETOWN:
1082 case F_SETSIG:
1083 case F_SETLEASE:
1084 case F_NOTIFY:
1085 case F_SETLK:
1086 case F_SETLKW:
1087 case F_GETLK:
1088 va_start (ap, cmd);
1089 long_arg = va_arg (ap, long);
1090 va_end (ap);
1091 which_arg = F_LONG_ARG;
1092 break;
1093 case F_GETFD:
1094 case F_GETFL:
1095 case F_GETOWN:
1096 case F_GETLEASE:
1097 case F_GETSIG:
1098 which_arg = F_VOID_ARG;
1099 break;
1101 if (NULL_PTR (fcntl))
1102 init_io_intf ();
1103 if (CHCK_REENTRANCE (guard))
1105 switch (which_arg)
1107 case F_INT_ARG:
1108 return CALL_REAL (fcntl)(fildes, cmd, int_arg);
1109 case F_LONG_ARG:
1110 return CALL_REAL (fcntl)(fildes, cmd, long_arg);
1111 case F_VOID_ARG:
1112 return CALL_REAL (fcntl)(fildes, cmd);
1113 case F_ERROR_ARG:
1114 Tprintf (0, "iotrace: ERROR: Unsupported fcntl command\n");
1115 return -1;
1117 return -1;
1119 if (cmd != F_DUPFD && cmd != TMP_F_DUPFD_CLOEXEC)
1121 switch (which_arg)
1123 case F_INT_ARG:
1124 return CALL_REAL (fcntl)(fildes, cmd, int_arg);
1125 case F_LONG_ARG:
1126 return CALL_REAL (fcntl)(fildes, cmd, long_arg);
1127 case F_VOID_ARG:
1128 return CALL_REAL (fcntl)(fildes, cmd);
1129 case F_ERROR_ARG:
1130 Tprintf (0, "iotrace: ERROR: Unsupported fcntl command\n");
1131 return -1;
1133 return -1;
1135 PUSH_REENTRANCE (guard);
1136 hrtime_t reqt = gethrtime ();
1137 switch (cmd)
1139 case F_DUPFD:
1140 case TMP_F_DUPFD_CLOEXEC:
1141 fd = CALL_REAL (fcntl)(fildes, cmd, long_arg);
1142 break;
1144 if (RECHCK_REENTRANCE (guard))
1146 POP_REENTRANCE (guard);
1147 return fd;
1149 hrtime_t grnt = gethrtime ();
1150 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1151 iopkt.comm.tsize = sizeof (IOTrace_packet);
1152 iopkt.comm.tstamp = grnt;
1153 iopkt.requested = reqt;
1154 if (fd != -1)
1155 iopkt.iotype = OPEN_TRACE;
1156 else
1157 iopkt.iotype = OPEN_TRACE_ERROR;
1158 iopkt.fd = fd;
1159 iopkt.ofd = fildes;
1160 iopkt.fstype = UNKNOWNFS_TYPE;
1161 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1162 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1163 POP_REENTRANCE (guard);
1164 return fd;
1167 /*------------------------------------------------------------- openat */
1169 openat (int fildes, const char *path, int oflag, ...)
1171 int *guard;
1172 int fd;
1173 void *packet;
1174 IOTrace_packet *iopkt;
1175 mode_t mode;
1176 va_list ap;
1177 size_t sz;
1178 unsigned pktSize;
1180 va_start (ap, oflag);
1181 mode = va_arg (ap, mode_t);
1182 va_end (ap);
1183 if (NULL_PTR (openat))
1184 init_io_intf ();
1185 if (CHCK_REENTRANCE (guard) || path == NULL)
1186 return CALL_REAL (openat)(fildes, path, oflag, mode);
1187 PUSH_REENTRANCE (guard);
1188 hrtime_t reqt = gethrtime ();
1189 fd = CALL_REAL (openat)(fildes, path, oflag, mode);
1190 if (RECHCK_REENTRANCE (guard))
1192 POP_REENTRANCE (guard);
1193 return fd;
1195 hrtime_t grnt = gethrtime ();
1196 sz = collector_strlen (path);
1197 pktSize = sizeof (IOTrace_packet) + sz;
1198 pktSize = collector_align_pktsize (pktSize);
1199 Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1200 packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1201 if (packet != NULL)
1203 iopkt = (IOTrace_packet *) packet;
1204 collector_memset (iopkt, 0, pktSize);
1205 iopkt->comm.tsize = pktSize;
1206 iopkt->comm.tstamp = grnt;
1207 iopkt->requested = reqt;
1208 if (fd != -1)
1209 iopkt->iotype = OPEN_TRACE;
1210 else
1211 iopkt->iotype = OPEN_TRACE_ERROR;
1212 iopkt->fd = fd;
1213 iopkt->fstype = collector_fstype (path);
1214 collector_strncpy (&(iopkt->fname), path, sz);
1215 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1216 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1217 collector_interface->freeCSize (io_heap, packet, pktSize);
1219 else
1221 Tprintf (0, "iotrace: ERROR: openat cannot allocate memory\n");
1222 return -1;
1224 POP_REENTRANCE (guard);
1225 return fd;
1228 /*------------------------------------------------------------- creat */
1230 creat (const char *path, mode_t mode)
1232 int *guard;
1233 int fd;
1234 void *packet;
1235 IOTrace_packet *iopkt;
1236 size_t sz;
1237 unsigned pktSize;
1238 if (NULL_PTR (creat))
1239 init_io_intf ();
1240 if (CHCK_REENTRANCE (guard) || path == NULL)
1241 return CALL_REAL (creat)(path, mode);
1242 PUSH_REENTRANCE (guard);
1243 hrtime_t reqt = gethrtime ();
1244 fd = CALL_REAL (creat)(path, mode);
1245 if (RECHCK_REENTRANCE (guard))
1247 POP_REENTRANCE (guard);
1248 return fd;
1250 hrtime_t grnt = gethrtime ();
1251 sz = collector_strlen (path);
1252 pktSize = sizeof (IOTrace_packet) + sz;
1253 pktSize = collector_align_pktsize (pktSize);
1254 Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1255 packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1256 if (packet != NULL)
1258 iopkt = (IOTrace_packet *) packet;
1259 collector_memset (iopkt, 0, pktSize);
1260 iopkt->comm.tsize = pktSize;
1261 iopkt->comm.tstamp = grnt;
1262 iopkt->requested = reqt;
1263 if (fd != -1)
1264 iopkt->iotype = OPEN_TRACE;
1265 else
1266 iopkt->iotype = OPEN_TRACE_ERROR;
1267 iopkt->fd = fd;
1268 iopkt->fstype = collector_fstype (path);
1269 collector_strncpy (&(iopkt->fname), path, sz);
1270 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1271 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1272 collector_interface->freeCSize (io_heap, packet, pktSize);
1274 else
1276 Tprintf (0, "iotrace: ERROR: creat cannot allocate memory\n");
1277 return -1;
1279 POP_REENTRANCE (guard);
1280 return fd;
1283 /*------------------------------------------------------------- creat64 */
1284 #if WSIZE(32) && !defined(__USE_LARGEFILE64)
1286 creat64 (const char *path, mode_t mode)
1288 int *guard;
1289 int fd;
1290 void *packet;
1291 IOTrace_packet *iopkt;
1292 size_t sz;
1293 unsigned pktSize;
1295 if (NULL_PTR (creat64))
1296 init_io_intf ();
1297 if (CHCK_REENTRANCE (guard) || path == NULL)
1298 return CALL_REAL (creat64)(path, mode);
1299 PUSH_REENTRANCE (guard);
1300 hrtime_t reqt = gethrtime ();
1301 fd = CALL_REAL (creat64)(path, mode);
1302 if (RECHCK_REENTRANCE (guard))
1304 POP_REENTRANCE (guard);
1305 return fd;
1307 hrtime_t grnt = gethrtime ();
1308 sz = collector_strlen (path);
1309 pktSize = sizeof (IOTrace_packet) + sz;
1310 pktSize = collector_align_pktsize (pktSize);
1311 Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1312 packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1313 if (packet != NULL)
1315 iopkt = (IOTrace_packet *) packet;
1316 collector_memset (iopkt, 0, pktSize);
1317 iopkt->comm.tsize = pktSize;
1318 iopkt->comm.tstamp = grnt;
1319 iopkt->requested = reqt;
1320 if (fd != -1)
1321 iopkt->iotype = OPEN_TRACE;
1322 else
1323 iopkt->iotype = OPEN_TRACE_ERROR;
1324 iopkt->fd = fd;
1325 iopkt->fstype = collector_fstype (path);
1326 collector_strncpy (&(iopkt->fname), path, sz);
1327 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1328 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1329 collector_interface->freeCSize (io_heap, packet, pktSize);
1331 else
1333 Tprintf (0, "iotrace: ERROR: creat64 cannot allocate memory\n");
1334 return -1;
1336 POP_REENTRANCE (guard);
1337 return fd;
1339 #endif
1341 /*------------------------------------------------------------- mkstemp */
1343 mkstemp (char *template)
1345 int *guard;
1346 int fd;
1347 void *packet;
1348 IOTrace_packet *iopkt;
1349 size_t sz;
1350 unsigned pktSize;
1351 if (NULL_PTR (mkstemp))
1352 init_io_intf ();
1353 if (CHCK_REENTRANCE (guard))
1354 return CALL_REAL (mkstemp)(template);
1355 PUSH_REENTRANCE (guard);
1356 hrtime_t reqt = gethrtime ();
1357 fd = CALL_REAL (mkstemp)(template);
1358 if (RECHCK_REENTRANCE (guard))
1360 POP_REENTRANCE (guard);
1361 return fd;
1363 hrtime_t grnt = gethrtime ();
1364 sz = collector_strlen (template);
1365 pktSize = sizeof (IOTrace_packet) + sz;
1366 pktSize = collector_align_pktsize (pktSize);
1367 Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1368 packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1369 if (packet != NULL)
1371 iopkt = (IOTrace_packet *) packet;
1372 collector_memset (iopkt, 0, pktSize);
1373 iopkt->comm.tsize = pktSize;
1374 iopkt->comm.tstamp = grnt;
1375 iopkt->requested = reqt;
1376 if (fd != -1)
1377 iopkt->iotype = OPEN_TRACE;
1378 else
1379 iopkt->iotype = OPEN_TRACE_ERROR;
1380 iopkt->fd = fd;
1381 iopkt->fstype = collector_fstype (template);
1382 collector_strncpy (&(iopkt->fname), template, sz);
1383 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1384 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1385 collector_interface->freeCSize (io_heap, packet, pktSize);
1387 else
1389 Tprintf (0, "iotrace: ERROR: mkstemp cannot allocate memory\n");
1390 return -1;
1392 POP_REENTRANCE (guard);
1393 return fd;
1396 /*------------------------------------------------------------- mkstemps */
1398 mkstemps (char *template, int slen)
1400 int *guard;
1401 int fd;
1402 void *packet;
1403 IOTrace_packet *iopkt;
1404 size_t sz;
1405 unsigned pktSize;
1406 if (NULL_PTR (mkstemps))
1407 init_io_intf ();
1408 if (CHCK_REENTRANCE (guard))
1409 return CALL_REAL (mkstemps)(template, slen);
1410 PUSH_REENTRANCE (guard);
1411 hrtime_t reqt = gethrtime ();
1412 fd = CALL_REAL (mkstemps)(template, slen);
1413 if (RECHCK_REENTRANCE (guard))
1415 POP_REENTRANCE (guard);
1416 return fd;
1418 hrtime_t grnt = gethrtime ();
1419 sz = collector_strlen (template);
1420 pktSize = sizeof (IOTrace_packet) + sz;
1421 pktSize = collector_align_pktsize (pktSize);
1422 Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1423 packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1424 if (packet != NULL)
1426 iopkt = (IOTrace_packet *) packet;
1427 collector_memset (iopkt, 0, pktSize);
1428 iopkt->comm.tsize = pktSize;
1429 iopkt->comm.tstamp = grnt;
1430 iopkt->requested = reqt;
1431 if (fd != -1)
1432 iopkt->iotype = OPEN_TRACE;
1433 else
1434 iopkt->iotype = OPEN_TRACE_ERROR;
1435 iopkt->fd = fd;
1436 iopkt->fstype = collector_fstype (template);
1437 collector_strncpy (&(iopkt->fname), template, sz);
1438 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1439 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1440 collector_interface->freeCSize (io_heap, packet, pktSize);
1442 else
1444 Tprintf (0, "iotrace: ERROR: mkstemps cannot allocate memory\n");
1445 return -1;
1447 POP_REENTRANCE (guard);
1448 return fd;
1451 /*------------------------------------------------------------- close */
1453 close (int fildes)
1455 int *guard;
1456 int stat;
1457 IOTrace_packet iopkt;
1458 if (NULL_PTR (close))
1459 init_io_intf ();
1460 if (CHCK_REENTRANCE (guard))
1461 return CALL_REAL (close)(fildes);
1462 PUSH_REENTRANCE (guard);
1463 hrtime_t reqt = gethrtime ();
1464 stat = CALL_REAL (close)(fildes);
1465 if (RECHCK_REENTRANCE (guard))
1467 POP_REENTRANCE (guard);
1468 return stat;
1470 hrtime_t grnt = gethrtime ();
1471 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1472 iopkt.comm.tsize = sizeof (IOTrace_packet);
1473 iopkt.comm.tstamp = grnt;
1474 iopkt.requested = reqt;
1475 if (stat == 0)
1476 iopkt.iotype = CLOSE_TRACE;
1477 else
1478 iopkt.iotype = CLOSE_TRACE_ERROR;
1479 iopkt.fd = fildes;
1480 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1481 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1482 POP_REENTRANCE (guard);
1483 return stat;
1486 /*------------------------------------------------------------- fopen */
1487 static FILE*
1488 gprofng_fopen (FILE*(real_fopen) (const char *, const char *), const char *filename, const char *mode)
1490 int *guard;
1491 FILE *fp = NULL;
1492 void *packet;
1493 IOTrace_packet *iopkt;
1494 size_t sz;
1495 unsigned pktSize;
1496 if (CHCK_REENTRANCE (guard) || filename == NULL)
1497 return real_fopen (filename, mode);
1498 PUSH_REENTRANCE (guard);
1499 hrtime_t reqt = gethrtime ();
1501 fp = real_fopen (filename, mode);
1502 if (RECHCK_REENTRANCE (guard))
1504 POP_REENTRANCE (guard);
1505 return fp;
1507 hrtime_t grnt = gethrtime ();
1508 sz = collector_strlen (filename);
1509 pktSize = sizeof (IOTrace_packet) + sz;
1510 pktSize = collector_align_pktsize (pktSize);
1511 Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
1512 packet = collector_interface->allocCSize (io_heap, pktSize, 1);
1513 if (packet != NULL)
1515 iopkt = (IOTrace_packet *) packet;
1516 collector_memset (iopkt, 0, pktSize);
1517 iopkt->comm.tsize = pktSize;
1518 iopkt->comm.tstamp = grnt;
1519 iopkt->requested = reqt;
1520 if (fp != NULL)
1522 iopkt->iotype = OPEN_TRACE;
1523 iopkt->fd = fileno (fp);
1525 else
1527 iopkt->iotype = OPEN_TRACE_ERROR;
1528 iopkt->fd = -1;
1530 iopkt->fstype = collector_fstype (filename);
1531 collector_strncpy (&(iopkt->fname), filename, sz);
1532 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl,
1533 iopkt->comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
1534 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
1535 collector_interface->freeCSize (io_heap, packet, pktSize);
1537 else
1539 Tprintf (0, "iotrace: ERROR: fopen cannot allocate memory\n");
1540 return NULL;
1542 POP_REENTRANCE (guard);
1543 return fp;
1546 #define DCL_FOPEN(dcl_f) \
1547 FILE *dcl_f (const char *filename, const char *mode) \
1549 if (__real_fopen == NULL) \
1550 init_io_intf (); \
1551 return gprofng_fopen (__real_fopen, filename, mode); \
1554 DCL_FUNC_VER (DCL_FOPEN, fopen_2_17, fopen@GLIBC_2.17)
1555 DCL_FUNC_VER (DCL_FOPEN, fopen_2_2_5, fopen@GLIBC_2.2.5)
1556 DCL_FUNC_VER (DCL_FOPEN, fopen_2_1, fopen@GLIBC_2.1)
1557 DCL_FUNC_VER (DCL_FOPEN, fopen_2_0, fopen@GLIBC_2.0)
1558 DCL_FOPEN (fopen)
1560 /*------------------------------------------------------------- fclose */
1561 static int
1562 gprofng_fclose (int(real_fclose) (FILE *), FILE *stream)
1564 int *guard;
1565 int stat;
1566 IOTrace_packet iopkt;
1567 if (CHCK_REENTRANCE (guard) || stream == NULL)
1568 return real_fclose (stream);
1569 PUSH_REENTRANCE (guard);
1570 hrtime_t reqt = gethrtime ();
1571 stat = real_fclose (stream);
1572 if (RECHCK_REENTRANCE (guard))
1574 POP_REENTRANCE (guard);
1575 return stat;
1577 hrtime_t grnt = gethrtime ();
1578 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1579 iopkt.comm.tsize = sizeof (IOTrace_packet);
1580 iopkt.comm.tstamp = grnt;
1581 iopkt.requested = reqt;
1582 if (stat == 0)
1583 iopkt.iotype = CLOSE_TRACE;
1584 else
1585 iopkt.iotype = CLOSE_TRACE_ERROR;
1586 iopkt.fd = fileno (stream);
1587 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl,
1588 iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
1589 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1590 POP_REENTRANCE (guard);
1591 return stat;
1594 #define DCL_FCLOSE(dcl_f) \
1595 int dcl_f (FILE *stream) \
1597 if (__real_fclose == NULL) \
1598 init_io_intf (); \
1599 return gprofng_fclose (__real_fclose, stream); \
1602 DCL_FUNC_VER (DCL_FCLOSE, fclose_2_17, fclose@GLIBC_2.17)
1603 DCL_FUNC_VER (DCL_FCLOSE, fclose_2_2_5, fclose@GLIBC_2.2.5)
1604 DCL_FUNC_VER (DCL_FCLOSE, fclose_2_1, fclose@GLIBC_2.1)
1605 DCL_FUNC_VER (DCL_FCLOSE, fclose_2_0, fclose@GLIBC_2.0)
1606 DCL_FCLOSE (fclose)
1608 /*------------------------------------------------------------- fflush */
1610 fflush (FILE *stream)
1612 int *guard;
1613 int stat;
1614 IOTrace_packet iopkt;
1615 if (NULL_PTR (fflush))
1616 init_io_intf ();
1617 if (CHCK_REENTRANCE (guard))
1618 return CALL_REAL (fflush)(stream);
1619 PUSH_REENTRANCE (guard);
1620 hrtime_t reqt = gethrtime ();
1621 stat = CALL_REAL (fflush)(stream);
1622 if (RECHCK_REENTRANCE (guard))
1624 POP_REENTRANCE (guard);
1625 return stat;
1627 hrtime_t grnt = gethrtime ();
1628 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1629 iopkt.comm.tsize = sizeof (IOTrace_packet);
1630 iopkt.comm.tstamp = grnt;
1631 iopkt.requested = reqt;
1632 if (stat == 0)
1633 iopkt.iotype = OTHERIO_TRACE;
1634 else
1635 iopkt.iotype = OTHERIO_TRACE_ERROR;
1636 if (stream != NULL)
1637 iopkt.fd = fileno (stream);
1638 else
1639 iopkt.fd = -1;
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;
1646 /*------------------------------------------------------------- fdopen */
1647 static FILE*
1648 gprofng_fdopen (FILE*(real_fdopen) (int, const char *), int fildes, const char *mode)
1650 int *guard;
1651 FILE *fp = NULL;
1652 IOTrace_packet iopkt;
1653 if (NULL_PTR (fdopen))
1654 init_io_intf ();
1655 if (CHCK_REENTRANCE (guard))
1656 return real_fdopen (fildes, mode);
1657 PUSH_REENTRANCE (guard);
1658 hrtime_t reqt = gethrtime ();
1659 fp = real_fdopen (fildes, mode);
1660 if (RECHCK_REENTRANCE (guard))
1662 POP_REENTRANCE (guard);
1663 return fp;
1665 hrtime_t grnt = gethrtime ();
1666 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1667 iopkt.comm.tsize = sizeof (IOTrace_packet);
1668 iopkt.comm.tstamp = grnt;
1669 iopkt.requested = reqt;
1670 if (fp != NULL)
1671 iopkt.iotype = OPEN_TRACE;
1672 else
1673 iopkt.iotype = OPEN_TRACE_ERROR;
1674 iopkt.fd = fildes;
1675 iopkt.fstype = UNKNOWNFS_TYPE;
1676 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl,
1677 iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
1678 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1679 POP_REENTRANCE (guard);
1680 return fp;
1683 #define DCL_FDOPEN(dcl_f) \
1684 FILE *dcl_f (int fildes, const char *mode) \
1686 if (__real_fdopen == NULL) \
1687 init_io_intf (); \
1688 return gprofng_fdopen (__real_fdopen, fildes, mode); \
1691 DCL_FUNC_VER (DCL_FDOPEN, fdopen_2_17, fdopen@GLIBC_2.17)
1692 DCL_FUNC_VER (DCL_FDOPEN, fdopen_2_2_5, fdopen@GLIBC_2.2.5)
1693 DCL_FUNC_VER (DCL_FDOPEN, fdopen_2_1, fdopen@GLIBC_2.1)
1694 DCL_FUNC_VER (DCL_FDOPEN, fdopen_2_0, fdopen@GLIBC_2.0)
1695 DCL_FDOPEN (fdopen)
1697 /*------------------------------------------------------------- dup */
1699 dup (int fildes)
1701 int *guard;
1702 int fd;
1703 IOTrace_packet iopkt;
1704 if (NULL_PTR (dup))
1705 init_io_intf ();
1706 if (CHCK_REENTRANCE (guard))
1707 return CALL_REAL (dup)(fildes);
1708 PUSH_REENTRANCE (guard);
1709 hrtime_t reqt = gethrtime ();
1710 fd = CALL_REAL (dup)(fildes);
1711 if (RECHCK_REENTRANCE (guard))
1713 POP_REENTRANCE (guard);
1714 return fd;
1716 hrtime_t grnt = gethrtime ();
1717 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1718 iopkt.comm.tsize = sizeof (IOTrace_packet);
1719 iopkt.comm.tstamp = grnt;
1720 iopkt.requested = reqt;
1721 if (fd != -1)
1722 iopkt.iotype = OPEN_TRACE;
1723 else
1724 iopkt.iotype = OPEN_TRACE_ERROR;
1726 iopkt.fd = fd;
1727 iopkt.ofd = fildes;
1728 iopkt.fstype = UNKNOWNFS_TYPE;
1729 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1730 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1731 POP_REENTRANCE (guard);
1732 return fd;
1735 /*------------------------------------------------------------- dup2 */
1737 dup2 (int fildes, int fildes2)
1739 int *guard;
1740 int fd;
1741 IOTrace_packet iopkt;
1742 if (NULL_PTR (dup2))
1743 init_io_intf ();
1744 if (CHCK_REENTRANCE (guard))
1745 return CALL_REAL (dup2)(fildes, fildes2);
1746 PUSH_REENTRANCE (guard);
1747 hrtime_t reqt = gethrtime ();
1748 fd = CALL_REAL (dup2)(fildes, fildes2);
1749 if (RECHCK_REENTRANCE (guard))
1751 POP_REENTRANCE (guard);
1752 return fd;
1754 hrtime_t grnt = gethrtime ();
1755 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1756 iopkt.comm.tsize = sizeof (IOTrace_packet);
1757 iopkt.comm.tstamp = grnt;
1758 iopkt.requested = reqt;
1759 if (fd != -1)
1760 iopkt.iotype = OPEN_TRACE;
1761 else
1762 iopkt.iotype = OPEN_TRACE_ERROR;
1763 iopkt.fd = fd;
1764 iopkt.ofd = fildes;
1765 iopkt.fstype = UNKNOWNFS_TYPE;
1766 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1767 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1768 POP_REENTRANCE (guard);
1769 return fd;
1772 /*------------------------------------------------------------- pipe */
1774 pipe (int fildes[2])
1776 int *guard;
1777 int ret;
1778 IOTrace_packet iopkt;
1779 if (NULL_PTR (pipe))
1780 init_io_intf ();
1781 if (CHCK_REENTRANCE (guard))
1782 return CALL_REAL (pipe)(fildes);
1783 PUSH_REENTRANCE (guard);
1784 hrtime_t reqt = gethrtime ();
1785 ret = CALL_REAL (pipe)(fildes);
1786 if (RECHCK_REENTRANCE (guard))
1788 POP_REENTRANCE (guard);
1789 return ret;
1791 hrtime_t grnt = gethrtime ();
1792 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1793 iopkt.comm.tsize = sizeof (IOTrace_packet);
1794 iopkt.comm.tstamp = grnt;
1795 iopkt.requested = reqt;
1796 if (ret != -1)
1797 iopkt.iotype = OPEN_TRACE;
1798 else
1799 iopkt.iotype = OPEN_TRACE_ERROR;
1800 iopkt.fd = fildes[0];
1801 iopkt.fstype = UNKNOWNFS_TYPE;
1802 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1803 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1804 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1805 iopkt.comm.tsize = sizeof (IOTrace_packet);
1806 iopkt.comm.tstamp = grnt;
1807 iopkt.requested = reqt;
1808 if (ret != -1)
1809 iopkt.iotype = OPEN_TRACE;
1810 else
1811 iopkt.iotype = OPEN_TRACE_ERROR;
1812 iopkt.fd = fildes[1];
1813 iopkt.fstype = UNKNOWNFS_TYPE;
1814 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1815 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1816 POP_REENTRANCE (guard);
1817 return ret;
1820 /*------------------------------------------------------------- socket */
1822 socket (int domain, int type, int protocol)
1824 int *guard;
1825 int fd;
1826 IOTrace_packet iopkt;
1827 if (NULL_PTR (socket))
1828 init_io_intf ();
1829 if (CHCK_REENTRANCE (guard))
1830 return CALL_REAL (socket)(domain, type, protocol);
1831 PUSH_REENTRANCE (guard);
1832 hrtime_t reqt = gethrtime ();
1833 fd = CALL_REAL (socket)(domain, type, protocol);
1834 if (RECHCK_REENTRANCE (guard))
1836 POP_REENTRANCE (guard);
1837 return fd;
1839 hrtime_t grnt = gethrtime ();
1840 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
1841 iopkt.comm.tsize = sizeof (IOTrace_packet);
1842 iopkt.comm.tstamp = grnt;
1843 iopkt.requested = reqt;
1844 if (fd != -1)
1845 iopkt.iotype = OPEN_TRACE;
1846 else
1847 iopkt.iotype = OPEN_TRACE_ERROR;
1848 iopkt.fd = fd;
1849 iopkt.fstype = UNKNOWNFS_TYPE;
1850 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1851 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1852 POP_REENTRANCE (guard);
1853 return fd;
1856 /*------------------------------------------------------------- read */
1857 ssize_t
1858 read (int fildes, void *buf, size_t nbyte)
1860 int *guard;
1861 ssize_t ret;
1862 IOTrace_packet iopkt;
1863 if (NULL_PTR (read))
1864 init_io_intf ();
1865 if (CHCK_REENTRANCE (guard))
1866 return CALL_REAL (read)(fildes, buf, nbyte);
1867 PUSH_REENTRANCE (guard);
1868 hrtime_t reqt = gethrtime ();
1869 ret = CALL_REAL (read)(fildes, buf, nbyte);
1870 if (RECHCK_REENTRANCE (guard))
1872 POP_REENTRANCE (guard);
1873 return ret;
1875 hrtime_t grnt = gethrtime ();
1876 collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
1877 iopkt.comm.tsize = sizeof ( IOTrace_packet);
1878 iopkt.comm.tstamp = grnt;
1879 iopkt.requested = reqt;
1880 if (ret >= 0)
1881 iopkt.iotype = READ_TRACE;
1882 else
1883 iopkt.iotype = READ_TRACE_ERROR;
1884 iopkt.fd = fildes;
1885 iopkt.nbyte = ret;
1886 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1887 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1888 POP_REENTRANCE (guard);
1889 return ret;
1892 /*------------------------------------------------------------- write */
1893 ssize_t
1894 write (int fildes, const void *buf, size_t nbyte)
1896 int *guard;
1897 ssize_t ret;
1898 IOTrace_packet iopkt;
1899 if (NULL_PTR (write))
1900 init_io_intf ();
1901 if (CHCK_REENTRANCE (guard))
1902 return CALL_REAL (write)(fildes, buf, nbyte);
1903 PUSH_REENTRANCE (guard);
1904 hrtime_t reqt = gethrtime ();
1905 ret = CALL_REAL (write)(fildes, buf, nbyte);
1906 if (RECHCK_REENTRANCE (guard))
1908 POP_REENTRANCE (guard);
1909 return ret;
1911 hrtime_t grnt = gethrtime ();
1912 collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
1913 iopkt.comm.tsize = sizeof ( IOTrace_packet);
1914 iopkt.comm.tstamp = grnt;
1915 iopkt.requested = reqt;
1916 if (ret >= 0)
1917 iopkt.iotype = WRITE_TRACE;
1918 else
1919 iopkt.iotype = WRITE_TRACE_ERROR;
1920 iopkt.fd = fildes;
1921 iopkt.nbyte = ret;
1922 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1923 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1924 POP_REENTRANCE (guard);
1925 return ret;
1928 /*------------------------------------------------------------- readv */
1929 ssize_t
1930 readv (int fildes, const struct iovec *iov, int iovcnt)
1932 int *guard;
1933 ssize_t ret;
1934 IOTrace_packet iopkt;
1935 if (NULL_PTR (readv))
1936 init_io_intf ();
1937 if (CHCK_REENTRANCE (guard))
1938 return CALL_REAL (readv)(fildes, iov, iovcnt);
1939 PUSH_REENTRANCE (guard);
1940 hrtime_t reqt = gethrtime ();
1941 ret = CALL_REAL (readv)(fildes, iov, iovcnt);
1942 if (RECHCK_REENTRANCE (guard))
1944 POP_REENTRANCE (guard);
1945 return ret;
1947 hrtime_t grnt = gethrtime ();
1948 collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
1949 iopkt.comm.tsize = sizeof ( IOTrace_packet);
1950 iopkt.comm.tstamp = grnt;
1951 iopkt.requested = reqt;
1952 if (ret >= 0)
1953 iopkt.iotype = READ_TRACE;
1954 else
1955 iopkt.iotype = READ_TRACE_ERROR;
1956 iopkt.fd = fildes;
1957 iopkt.nbyte = ret;
1958 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1959 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1960 POP_REENTRANCE (guard);
1961 return ret;
1964 /*------------------------------------------------------------- writev */
1965 ssize_t
1966 writev (int fildes, const struct iovec *iov, int iovcnt)
1968 int *guard;
1969 ssize_t ret;
1970 IOTrace_packet iopkt;
1971 if (NULL_PTR (writev))
1972 init_io_intf ();
1973 if (CHCK_REENTRANCE (guard))
1974 return CALL_REAL (writev)(fildes, iov, iovcnt);
1975 PUSH_REENTRANCE (guard);
1976 hrtime_t reqt = gethrtime ();
1977 ret = CALL_REAL (writev)(fildes, iov, iovcnt);
1978 if (RECHCK_REENTRANCE (guard))
1980 POP_REENTRANCE (guard);
1981 return ret;
1983 hrtime_t grnt = gethrtime ();
1984 collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
1985 iopkt.comm.tsize = sizeof ( IOTrace_packet);
1986 iopkt.comm.tstamp = grnt;
1987 iopkt.requested = reqt;
1988 if (ret >= 0)
1989 iopkt.iotype = WRITE_TRACE;
1990 else
1991 iopkt.iotype = WRITE_TRACE_ERROR;
1992 iopkt.fd = fildes;
1993 iopkt.nbyte = ret;
1994 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
1995 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
1996 POP_REENTRANCE (guard);
1997 return ret;
2000 /*------------------------------------------------------------- fread */
2001 size_t
2002 fread (void *ptr, size_t size, size_t nitems, FILE *stream)
2004 int *guard;
2005 size_t ret;
2006 IOTrace_packet iopkt;
2007 if (NULL_PTR (fread))
2008 init_io_intf ();
2009 if (CHCK_REENTRANCE (guard) || stream == NULL)
2010 return CALL_REAL (fread)(ptr, size, nitems, stream);
2011 PUSH_REENTRANCE (guard);
2012 hrtime_t reqt = gethrtime ();
2013 ret = CALL_REAL (fread)(ptr, size, nitems, stream);
2014 if (RECHCK_REENTRANCE (guard))
2016 POP_REENTRANCE (guard);
2017 return ret;
2019 hrtime_t grnt = gethrtime ();
2020 collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2021 iopkt.comm.tsize = sizeof ( IOTrace_packet);
2022 iopkt.comm.tstamp = grnt;
2023 iopkt.requested = reqt;
2024 if (ferror (stream) == 0)
2026 iopkt.iotype = READ_TRACE;
2027 iopkt.nbyte = ret * size;
2029 else
2031 iopkt.iotype = READ_TRACE_ERROR;
2032 iopkt.nbyte = 0;
2034 iopkt.fd = fileno (stream);
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 ret;
2041 /*------------------------------------------------------------- fwrite */
2042 size_t
2043 fwrite (const void *ptr, size_t size, size_t nitems, FILE *stream)
2045 int *guard;
2046 size_t ret;
2047 IOTrace_packet iopkt;
2048 if (NULL_PTR (fwrite))
2049 init_io_intf ();
2050 if (CHCK_REENTRANCE (guard) || stream == NULL)
2051 return CALL_REAL (fwrite)(ptr, size, nitems, stream);
2052 PUSH_REENTRANCE (guard);
2053 hrtime_t reqt = gethrtime ();
2054 ret = CALL_REAL (fwrite)(ptr, size, nitems, stream);
2055 if (RECHCK_REENTRANCE (guard))
2057 POP_REENTRANCE (guard);
2058 return ret;
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 (ferror (stream) == 0)
2067 iopkt.iotype = WRITE_TRACE;
2068 iopkt.nbyte = ret * size;
2070 else
2072 iopkt.iotype = WRITE_TRACE_ERROR;
2073 iopkt.nbyte = 0;
2075 iopkt.fd = fileno (stream);
2076 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2077 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2078 POP_REENTRANCE (guard);
2079 return ret;
2082 /*------------------------------------------------------------- pread */
2083 static ssize_t
2084 gprofng_pread (ssize_t(real_pread) (int, void *, size_t, off_t),
2085 int fildes, void *buf, size_t nbyte, off_t offset)
2087 int *guard;
2088 ssize_t ret;
2089 IOTrace_packet iopkt;
2090 if (CHCK_REENTRANCE (guard))
2091 return real_pread (fildes, buf, nbyte, offset);
2092 PUSH_REENTRANCE (guard);
2093 hrtime_t reqt = gethrtime ();
2094 ret = real_pread (fildes, buf, nbyte, offset);
2095 if (RECHCK_REENTRANCE (guard))
2097 POP_REENTRANCE (guard);
2098 return ret;
2100 hrtime_t grnt = gethrtime ();
2101 collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2102 iopkt.comm.tsize = sizeof ( IOTrace_packet);
2103 iopkt.comm.tstamp = grnt;
2104 iopkt.requested = reqt;
2105 if (ret >= 0)
2106 iopkt.iotype = READ_TRACE;
2107 else
2108 iopkt.iotype = READ_TRACE_ERROR;
2109 iopkt.fd = fildes;
2110 iopkt.nbyte = ret;
2111 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl,
2112 iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
2113 collector_interface->writeDataRecord (io_hndl, (Common_packet*) &iopkt);
2114 POP_REENTRANCE (guard);
2115 return ret;
2118 #define DCL_PREAD(dcl_f) \
2119 ssize_t dcl_f (int fildes, void *buf, size_t nbyte, off_t offset) \
2121 if (__real_pread == NULL) \
2122 init_io_intf (); \
2123 return gprofng_pread (__real_pread, fildes, buf, nbyte, offset); \
2126 DCL_FUNC_VER (DCL_PREAD, pread_2_2, pread@GLIBC_2.2)
2127 DCL_PREAD (pread)
2129 /*------------------------------------------------------------- pwrite */
2131 #if !defined(__MUSL_LIBC)
2132 // map interposed symbol versions
2134 SYMVER_ATTRIBUTE (__collector_pwrite_2_2, pwrite@GLIBC_2.2)
2136 __collector_pwrite_2_2 (int fildes, const void *buf, size_t nbyte, off_t offset)
2138 int *guard;
2139 if (NULL_PTR (pwrite_2_2))
2140 init_io_intf ();
2141 if (CHCK_REENTRANCE (guard))
2142 return CALL_REAL (pwrite_2_2)(fildes, buf, nbyte, offset);
2143 PUSH_REENTRANCE (guard);
2144 hrtime_t reqt = gethrtime ();
2145 ssize_t ret = CALL_REAL (pwrite_2_2)(fildes, buf, nbyte, offset);
2146 if (RECHCK_REENTRANCE (guard))
2148 POP_REENTRANCE (guard);
2149 return ret;
2151 write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2152 POP_REENTRANCE (guard);
2153 return ret;
2156 #endif
2157 ssize_t
2158 pwrite (int fildes, const void *buf, size_t nbyte, off_t offset)
2160 int *guard;
2161 if (NULL_PTR (pwrite))
2162 init_io_intf ();
2163 if (CHCK_REENTRANCE (guard))
2164 return CALL_REAL (pwrite)(fildes, buf, nbyte, offset);
2165 PUSH_REENTRANCE (guard);
2166 hrtime_t reqt = gethrtime ();
2167 ssize_t ret = CALL_REAL (pwrite)(fildes, buf, nbyte, offset);
2168 if (RECHCK_REENTRANCE (guard))
2170 POP_REENTRANCE (guard);
2171 return ret;
2173 write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2174 POP_REENTRANCE (guard);
2175 return ret;
2178 /*------------------------------------------------------------- pwrite64 */
2179 #if WSIZE(32) && !defined(__USE_FILE_OFFSET64)
2180 #if !defined(__MUSL_LIBC)
2181 // map interposed symbol versions
2183 SYMVER_ATTRIBUTE (__collector_pwrite64_2_2, pwrite64@GLIBC_2.2)
2184 ssize_t
2185 __collector_pwrite64_2_2 (int fildes, const void *buf, size_t nbyte, off64_t offset)
2187 int *guard;
2188 if (NULL_PTR (pwrite64_2_2))
2189 init_io_intf ();
2190 if (CHCK_REENTRANCE (guard))
2191 return CALL_REAL (pwrite64_2_2)(fildes, buf, nbyte, offset);
2192 PUSH_REENTRANCE (guard);
2193 hrtime_t reqt = gethrtime ();
2194 ssize_t ret = CALL_REAL (pwrite64_2_2)(fildes, buf, nbyte, offset);
2195 if (RECHCK_REENTRANCE (guard))
2197 POP_REENTRANCE (guard);
2198 return ret;
2200 write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2201 POP_REENTRANCE (guard);
2202 return ret;
2204 #endif
2206 ssize_t
2207 pwrite64 (int fildes, const void *buf, size_t nbyte, off64_t offset)
2209 int *guard;
2210 if (NULL_PTR (pwrite64))
2211 init_io_intf ();
2212 if (CHCK_REENTRANCE (guard))
2213 return CALL_REAL (pwrite64)(fildes, buf, nbyte, offset);
2214 PUSH_REENTRANCE (guard);
2215 hrtime_t reqt = gethrtime ();
2216 ssize_t ret = CALL_REAL (pwrite64)(fildes, buf, nbyte, offset);
2217 if (RECHCK_REENTRANCE (guard))
2219 POP_REENTRANCE (guard);
2220 return ret;
2222 write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR);
2223 POP_REENTRANCE (guard);
2224 return ret;
2226 #endif
2228 /*------------------------------------------------------------- fgets */
2229 char*
2230 fgets (char *s, int n, FILE *stream)
2232 int *guard;
2233 char *ptr;
2234 IOTrace_packet iopkt;
2235 if (NULL_PTR (fgets))
2236 init_io_intf ();
2237 if (CHCK_REENTRANCE (guard) || stream == NULL)
2238 return CALL_REAL (fgets)(s, n, stream);
2239 PUSH_REENTRANCE (guard);
2240 hrtime_t reqt = gethrtime ();
2241 ptr = CALL_REAL (fgets)(s, n, stream);
2242 if (RECHCK_REENTRANCE (guard))
2244 POP_REENTRANCE (guard);
2245 return ptr;
2247 int error = errno;
2248 hrtime_t grnt = gethrtime ();
2249 collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2250 iopkt.comm.tsize = sizeof ( IOTrace_packet);
2251 iopkt.comm.tstamp = grnt;
2252 iopkt.requested = reqt;
2253 if (ptr != NULL)
2255 iopkt.iotype = READ_TRACE;
2256 iopkt.nbyte = collector_strlen (ptr);
2258 else if (ptr == NULL && error != EAGAIN && error != EBADF && error != EINTR &&
2259 error != EIO && error != EOVERFLOW && error != ENOMEM && error != ENXIO)
2261 iopkt.iotype = READ_TRACE;
2262 iopkt.nbyte = 0;
2264 else
2265 iopkt.iotype = READ_TRACE_ERROR;
2266 iopkt.fd = fileno (stream);
2267 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2268 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2269 POP_REENTRANCE (guard);
2270 return ptr;
2273 /*------------------------------------------------------------- fputs */
2275 fputs (const char *s, FILE *stream)
2277 int *guard;
2278 int ret;
2279 IOTrace_packet iopkt;
2280 if (NULL_PTR (fputs))
2281 init_io_intf ();
2282 if (CHCK_REENTRANCE (guard) || stream == NULL)
2283 return CALL_REAL (fputs)(s, stream);
2284 PUSH_REENTRANCE (guard);
2285 hrtime_t reqt = gethrtime ();
2286 ret = CALL_REAL (fputs)(s, stream);
2287 if (RECHCK_REENTRANCE (guard))
2289 POP_REENTRANCE (guard);
2290 return ret;
2292 hrtime_t grnt = gethrtime ();
2293 collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2294 iopkt.comm.tsize = sizeof ( IOTrace_packet);
2295 iopkt.comm.tstamp = grnt;
2296 iopkt.requested = reqt;
2297 if (ret != EOF)
2299 iopkt.iotype = WRITE_TRACE;
2300 iopkt.nbyte = ret;
2302 else
2304 iopkt.iotype = WRITE_TRACE_ERROR;
2305 iopkt.nbyte = 0;
2307 iopkt.fd = fileno (stream);
2308 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2309 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2310 POP_REENTRANCE (guard);
2311 return ret;
2314 /*------------------------------------------------------------- fputc */
2316 fputc (int c, FILE *stream)
2318 int *guard;
2319 int ret;
2320 IOTrace_packet iopkt;
2321 if (NULL_PTR (fputc))
2322 init_io_intf ();
2323 if (CHCK_REENTRANCE (guard) || stream == NULL)
2324 return CALL_REAL (fputc)(c, stream);
2325 PUSH_REENTRANCE (guard);
2326 hrtime_t reqt = gethrtime ();
2327 ret = CALL_REAL (fputc)(c, stream);
2328 if (RECHCK_REENTRANCE (guard))
2330 POP_REENTRANCE (guard);
2331 return ret;
2333 hrtime_t grnt = gethrtime ();
2334 collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2335 iopkt.comm.tsize = sizeof ( IOTrace_packet);
2336 iopkt.comm.tstamp = grnt;
2337 iopkt.requested = reqt;
2338 if (ret != EOF)
2340 iopkt.iotype = WRITE_TRACE;
2341 iopkt.nbyte = ret;
2343 else
2345 iopkt.iotype = WRITE_TRACE_ERROR;
2346 iopkt.nbyte = 0;
2348 iopkt.fd = fileno (stream);
2349 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2350 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2351 POP_REENTRANCE (guard);
2352 return ret;
2355 /*------------------------------------------------------------- fprintf */
2357 fprintf (FILE *stream, const char *format, ...)
2359 int *guard;
2360 int ret;
2361 IOTrace_packet iopkt;
2362 va_list ap;
2363 va_start (ap, format);
2364 if (NULL_PTR (fprintf))
2365 init_io_intf ();
2366 if (NULL_PTR (vfprintf))
2367 init_io_intf ();
2368 if (CHCK_REENTRANCE (guard) || stream == NULL)
2370 ret = CALL_REAL (vfprintf)(stream, format, ap);
2371 va_end (ap);
2372 return ret;
2374 PUSH_REENTRANCE (guard);
2375 hrtime_t reqt = gethrtime ();
2376 ret = CALL_REAL (vfprintf)(stream, format, ap);
2377 va_end (ap);
2378 if (RECHCK_REENTRANCE (guard))
2380 POP_REENTRANCE (guard);
2381 return ret;
2383 hrtime_t grnt = gethrtime ();
2384 collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2385 iopkt.comm.tsize = sizeof ( IOTrace_packet);
2386 iopkt.comm.tstamp = grnt;
2387 iopkt.requested = reqt;
2388 if (ret >= 0)
2389 iopkt.iotype = WRITE_TRACE;
2390 else
2391 iopkt.iotype = WRITE_TRACE_ERROR;
2392 iopkt.fd = fileno (stream);
2393 iopkt.nbyte = ret;
2394 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2395 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2396 POP_REENTRANCE (guard);
2397 return ret;
2400 /*------------------------------------------------------------- vfprintf */
2402 vfprintf (FILE *stream, const char *format, va_list ap)
2404 int *guard;
2405 int ret;
2406 IOTrace_packet iopkt;
2407 if (NULL_PTR (vfprintf))
2408 init_io_intf ();
2409 if (CHCK_REENTRANCE (guard) || stream == NULL)
2410 return CALL_REAL (vfprintf)(stream, format, ap);
2411 PUSH_REENTRANCE (guard);
2412 hrtime_t reqt = gethrtime ();
2413 ret = CALL_REAL (vfprintf)(stream, format, ap);
2414 if (RECHCK_REENTRANCE (guard))
2416 POP_REENTRANCE (guard);
2417 return ret;
2419 hrtime_t grnt = gethrtime ();
2420 collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
2421 iopkt.comm.tsize = sizeof ( IOTrace_packet);
2422 iopkt.comm.tstamp = grnt;
2423 iopkt.requested = reqt;
2424 if (ret >= 0)
2425 iopkt.iotype = WRITE_TRACE;
2426 else
2427 iopkt.iotype = WRITE_TRACE_ERROR;
2428 iopkt.fd = fileno (stream);
2429 iopkt.nbyte = ret;
2430 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2431 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2432 POP_REENTRANCE (guard);
2433 return ret;
2436 /*------------------------------------------------------------- lseek */
2437 off_t
2438 lseek (int fildes, off_t offset, int whence)
2440 int *guard;
2441 off_t ret;
2442 IOTrace_packet iopkt;
2443 if (NULL_PTR (lseek))
2444 init_io_intf ();
2445 if (CHCK_REENTRANCE (guard))
2446 return CALL_REAL (lseek)(fildes, offset, whence);
2447 PUSH_REENTRANCE (guard);
2448 hrtime_t reqt = gethrtime ();
2449 ret = CALL_REAL (lseek)(fildes, offset, whence);
2450 if (RECHCK_REENTRANCE (guard))
2452 POP_REENTRANCE (guard);
2453 return ret;
2455 hrtime_t grnt = gethrtime ();
2456 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2457 iopkt.comm.tsize = sizeof (IOTrace_packet);
2458 iopkt.comm.tstamp = grnt;
2459 iopkt.requested = reqt;
2460 if (ret != -1)
2461 iopkt.iotype = OTHERIO_TRACE;
2462 else
2463 iopkt.iotype = OTHERIO_TRACE_ERROR;
2464 iopkt.fd = fildes;
2465 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2466 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2467 POP_REENTRANCE (guard);
2468 return ret;
2471 /*------------------------------------------------------------- llseek */
2472 offset_t
2473 llseek (int fildes, offset_t offset, int whence)
2475 int *guard;
2476 offset_t ret;
2477 IOTrace_packet iopkt;
2478 if (NULL_PTR (llseek))
2479 init_io_intf ();
2480 if (CHCK_REENTRANCE (guard))
2481 return CALL_REAL (llseek)(fildes, offset, whence);
2482 PUSH_REENTRANCE (guard);
2483 hrtime_t reqt = gethrtime ();
2484 ret = CALL_REAL (llseek)(fildes, offset, whence);
2485 if (RECHCK_REENTRANCE (guard))
2487 POP_REENTRANCE (guard);
2488 return ret;
2490 hrtime_t grnt = gethrtime ();
2491 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2492 iopkt.comm.tsize = sizeof (IOTrace_packet);
2493 iopkt.comm.tstamp = grnt;
2494 iopkt.requested = reqt;
2495 if (ret != -1)
2496 iopkt.iotype = OTHERIO_TRACE;
2497 else
2498 iopkt.iotype = OTHERIO_TRACE_ERROR;
2499 iopkt.fd = fildes;
2500 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2501 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2502 POP_REENTRANCE (guard);
2503 return ret;
2506 /*------------------------------------------------------------- chmod */
2508 chmod (const char *path, mode_t mode)
2510 int *guard;
2511 int ret;
2512 void *packet;
2513 IOTrace_packet *iopkt;
2514 size_t sz;
2515 unsigned pktSize;
2516 if (NULL_PTR (chmod))
2517 init_io_intf ();
2518 if (CHCK_REENTRANCE (guard) || path == NULL)
2519 return CALL_REAL (chmod)(path, mode);
2520 PUSH_REENTRANCE (guard);
2521 hrtime_t reqt = gethrtime ();
2522 ret = CALL_REAL (chmod)(path, mode);
2523 if (RECHCK_REENTRANCE (guard))
2525 POP_REENTRANCE (guard);
2526 return ret;
2528 hrtime_t grnt = gethrtime ();
2529 sz = collector_strlen (path);
2530 pktSize = sizeof (IOTrace_packet) + sz;
2531 pktSize = collector_align_pktsize (pktSize);
2532 Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
2533 packet = collector_interface->allocCSize (io_heap, pktSize, 1);
2534 if (packet != NULL)
2536 iopkt = (IOTrace_packet *) packet;
2537 collector_memset (iopkt, 0, pktSize);
2538 iopkt->comm.tsize = pktSize;
2539 iopkt->comm.tstamp = grnt;
2540 iopkt->requested = reqt;
2541 if (ret != -1)
2542 iopkt->iotype = OTHERIO_TRACE;
2543 else
2544 iopkt->iotype = OTHERIO_TRACE_ERROR;
2545 collector_strncpy (&(iopkt->fname), path, sz);
2546 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2547 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
2548 collector_interface->freeCSize (io_heap, packet, pktSize);
2550 else
2552 Tprintf (0, "iotrace: ERROR: chmod cannot allocate memory\n");
2553 return 0;
2555 POP_REENTRANCE (guard);
2556 return ret;
2559 /*------------------------------------------------------------- access */
2561 access (const char *path, int amode)
2563 int *guard;
2564 int ret;
2565 void *packet;
2566 IOTrace_packet *iopkt;
2567 size_t sz;
2568 unsigned pktSize;
2569 if (NULL_PTR (access))
2570 init_io_intf ();
2571 if (CHCK_REENTRANCE (guard) || path == NULL)
2572 return CALL_REAL (access)(path, amode);
2573 PUSH_REENTRANCE (guard);
2574 hrtime_t reqt = gethrtime ();
2575 ret = CALL_REAL (access)(path, amode);
2576 if (RECHCK_REENTRANCE (guard))
2578 POP_REENTRANCE (guard);
2579 return ret;
2581 hrtime_t grnt = gethrtime ();
2582 sz = collector_strlen (path);
2583 pktSize = sizeof (IOTrace_packet) + sz;
2584 pktSize = collector_align_pktsize (pktSize);
2585 Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
2586 packet = collector_interface->allocCSize (io_heap, pktSize, 1);
2587 if (packet != NULL)
2589 iopkt = (IOTrace_packet *) packet;
2590 collector_memset (iopkt, 0, pktSize);
2591 iopkt->comm.tsize = pktSize;
2592 iopkt->comm.tstamp = grnt;
2593 iopkt->requested = reqt;
2594 if (ret != -1)
2595 iopkt->iotype = OTHERIO_TRACE;
2596 else
2597 iopkt->iotype = OTHERIO_TRACE_ERROR;
2598 collector_strncpy (&(iopkt->fname), path, sz);
2599 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2600 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
2601 collector_interface->freeCSize (io_heap, packet, pktSize);
2603 else
2605 Tprintf (0, "iotrace: ERROR: access cannot allocate memory\n");
2606 return 0;
2608 POP_REENTRANCE (guard);
2609 return ret;
2612 /*------------------------------------------------------------- rename */
2614 rename (const char *old, const char *new)
2616 int *guard;
2617 int ret;
2618 void *packet;
2619 IOTrace_packet *iopkt;
2620 size_t sz;
2621 unsigned pktSize;
2622 if (NULL_PTR (rename))
2623 init_io_intf ();
2624 if (CHCK_REENTRANCE (guard) || new == NULL)
2625 return CALL_REAL (rename)(old, new);
2626 PUSH_REENTRANCE (guard);
2627 hrtime_t reqt = gethrtime ();
2628 ret = CALL_REAL (rename)(old, new);
2629 if (RECHCK_REENTRANCE (guard))
2631 POP_REENTRANCE (guard);
2632 return ret;
2634 hrtime_t grnt = gethrtime ();
2635 sz = collector_strlen (new);
2636 pktSize = sizeof (IOTrace_packet) + sz;
2637 pktSize = collector_align_pktsize (pktSize);
2638 Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
2639 packet = collector_interface->allocCSize (io_heap, pktSize, 1);
2640 if (packet != NULL)
2642 iopkt = (IOTrace_packet *) packet;
2643 collector_memset (iopkt, 0, pktSize);
2644 iopkt->comm.tsize = pktSize;
2645 iopkt->comm.tstamp = grnt;
2646 iopkt->requested = reqt;
2647 if (ret != -1)
2648 iopkt->iotype = OTHERIO_TRACE;
2649 else
2650 iopkt->iotype = OTHERIO_TRACE_ERROR;
2651 collector_strncpy (&(iopkt->fname), new, sz);
2652 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2653 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
2654 collector_interface->freeCSize (io_heap, packet, pktSize);
2656 else
2658 Tprintf (0, "iotrace: ERROR: rename cannot allocate memory\n");
2659 return 0;
2661 POP_REENTRANCE (guard);
2662 return ret;
2665 /*------------------------------------------------------------- mkdir */
2667 mkdir (const char *path, mode_t mode)
2669 int *guard;
2670 int ret;
2671 void *packet;
2672 IOTrace_packet *iopkt;
2673 size_t sz;
2674 unsigned pktSize;
2675 if (NULL_PTR (mkdir))
2676 init_io_intf ();
2677 if (CHCK_REENTRANCE (guard) || path == NULL)
2678 return CALL_REAL (mkdir)(path, mode);
2679 PUSH_REENTRANCE (guard);
2680 hrtime_t reqt = gethrtime ();
2681 ret = CALL_REAL (mkdir)(path, mode);
2682 if (RECHCK_REENTRANCE (guard))
2684 POP_REENTRANCE (guard);
2685 return ret;
2687 hrtime_t grnt = gethrtime ();
2688 sz = collector_strlen (path);
2689 pktSize = sizeof (IOTrace_packet) + sz;
2690 pktSize = collector_align_pktsize (pktSize);
2691 Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
2692 packet = collector_interface->allocCSize (io_heap, pktSize, 1);
2693 if (packet != NULL)
2695 iopkt = (IOTrace_packet *) packet;
2696 collector_memset (iopkt, 0, pktSize);
2697 iopkt->comm.tsize = pktSize;
2698 iopkt->comm.tstamp = grnt;
2699 iopkt->requested = reqt;
2700 if (ret != -1)
2701 iopkt->iotype = OTHERIO_TRACE;
2702 else
2703 iopkt->iotype = OTHERIO_TRACE_ERROR;
2704 collector_strncpy (&(iopkt->fname), path, sz);
2705 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2706 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
2707 collector_interface->freeCSize (io_heap, packet, pktSize);
2709 else
2711 Tprintf (0, "iotrace: ERROR: mkdir cannot allocate memory\n");
2712 return 0;
2714 POP_REENTRANCE (guard);
2715 return ret;
2718 /*------------------------------------------------------------- getdents */
2720 getdents (int fildes, struct dirent *buf, size_t nbyte)
2722 int *guard;
2723 int ret;
2724 IOTrace_packet iopkt;
2725 if (NULL_PTR (getdents))
2726 init_io_intf ();
2727 if (CHCK_REENTRANCE (guard))
2728 return CALL_REAL (getdents)(fildes, buf, nbyte);
2729 PUSH_REENTRANCE (guard);
2730 hrtime_t reqt = gethrtime ();
2731 ret = CALL_REAL (getdents)(fildes, buf, nbyte);
2732 if (RECHCK_REENTRANCE (guard))
2734 POP_REENTRANCE (guard);
2735 return ret;
2737 hrtime_t grnt = gethrtime ();
2738 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2739 iopkt.comm.tsize = sizeof (IOTrace_packet);
2740 iopkt.comm.tstamp = grnt;
2741 iopkt.requested = reqt;
2742 if (ret != -1)
2743 iopkt.iotype = OTHERIO_TRACE;
2744 else
2745 iopkt.iotype = OTHERIO_TRACE_ERROR;
2746 iopkt.fd = fildes;
2747 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2748 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2749 POP_REENTRANCE (guard);
2750 return ret;
2753 /*------------------------------------------------------------- unlink */
2755 unlink (const char *path)
2757 int *guard;
2758 int ret;
2759 void *packet;
2760 IOTrace_packet *iopkt;
2761 size_t sz;
2762 unsigned pktSize;
2763 if (NULL_PTR (unlink))
2764 init_io_intf ();
2765 if (CHCK_REENTRANCE (guard) || path == NULL)
2766 return CALL_REAL (unlink)(path);
2767 PUSH_REENTRANCE (guard);
2768 hrtime_t reqt = gethrtime ();
2769 ret = CALL_REAL (unlink)(path);
2770 if (RECHCK_REENTRANCE (guard))
2772 POP_REENTRANCE (guard);
2773 return ret;
2775 hrtime_t grnt = gethrtime ();
2776 sz = collector_strlen (path);
2777 pktSize = sizeof (IOTrace_packet) + sz;
2778 pktSize = collector_align_pktsize (pktSize);
2779 Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
2780 packet = collector_interface->allocCSize (io_heap, pktSize, 1);
2781 if (packet != NULL)
2783 iopkt = (IOTrace_packet *) packet;
2784 collector_memset (iopkt, 0, pktSize);
2785 iopkt->comm.tsize = pktSize;
2786 iopkt->comm.tstamp = grnt;
2787 iopkt->requested = reqt;
2788 if (ret != -1)
2789 iopkt->iotype = OTHERIO_TRACE;
2790 else
2791 iopkt->iotype = OTHERIO_TRACE_ERROR;
2792 collector_strncpy (&(iopkt->fname), path, sz);
2793 iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2794 collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
2795 collector_interface->freeCSize (io_heap, packet, pktSize);
2797 else
2799 Tprintf (0, "iotrace: ERROR: unlink cannot allocate memory\n");
2800 return 0;
2802 POP_REENTRANCE (guard);
2803 return ret;
2806 /*------------------------------------------------------------- fseek */
2808 fseek (FILE *stream, long offset, int whence)
2810 int *guard;
2811 int ret;
2812 IOTrace_packet iopkt;
2813 if (NULL_PTR (fseek))
2814 init_io_intf ();
2815 if (CHCK_REENTRANCE (guard) || stream == NULL)
2816 return CALL_REAL (fseek)(stream, offset, whence);
2817 PUSH_REENTRANCE (guard);
2818 hrtime_t reqt = gethrtime ();
2819 ret = CALL_REAL (fseek)(stream, offset, whence);
2820 if (RECHCK_REENTRANCE (guard))
2822 POP_REENTRANCE (guard);
2823 return ret;
2825 hrtime_t grnt = gethrtime ();
2826 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2827 iopkt.comm.tsize = sizeof (IOTrace_packet);
2828 iopkt.comm.tstamp = grnt;
2829 iopkt.requested = reqt;
2830 if (ret != -1)
2831 iopkt.iotype = OTHERIO_TRACE;
2832 else
2833 iopkt.iotype = OTHERIO_TRACE_ERROR;
2834 iopkt.fd = fileno (stream);
2835 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2836 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2837 POP_REENTRANCE (guard);
2838 return ret;
2841 /*------------------------------------------------------------- rewind */
2842 void
2843 rewind (FILE *stream)
2845 int *guard;
2846 IOTrace_packet iopkt;
2847 if (NULL_PTR (rewind))
2848 init_io_intf ();
2849 if (CHCK_REENTRANCE (guard) || stream == NULL)
2851 CALL_REAL (rewind)(stream);
2852 return;
2854 PUSH_REENTRANCE (guard);
2855 hrtime_t reqt = gethrtime ();
2856 CALL_REAL (rewind)(stream);
2857 if (RECHCK_REENTRANCE (guard))
2859 POP_REENTRANCE (guard);
2860 return;
2862 hrtime_t grnt = gethrtime ();
2863 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2864 iopkt.comm.tsize = sizeof (IOTrace_packet);
2865 iopkt.comm.tstamp = grnt;
2866 iopkt.requested = reqt;
2867 iopkt.iotype = OTHERIO_TRACE;
2868 iopkt.fd = fileno (stream);
2869 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2870 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2871 POP_REENTRANCE (guard);
2874 /*------------------------------------------------------------- ftell */
2875 long
2876 ftell (FILE *stream)
2878 int *guard;
2879 long ret;
2880 IOTrace_packet iopkt;
2881 if (NULL_PTR (ftell))
2882 init_io_intf ();
2883 if (CHCK_REENTRANCE (guard) || stream == NULL)
2884 return CALL_REAL (ftell)(stream);
2885 PUSH_REENTRANCE (guard);
2886 hrtime_t reqt = gethrtime ();
2887 ret = CALL_REAL (ftell)(stream);
2888 if (RECHCK_REENTRANCE (guard))
2890 POP_REENTRANCE (guard);
2891 return ret;
2893 hrtime_t grnt = gethrtime ();
2894 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2895 iopkt.comm.tsize = sizeof (IOTrace_packet);
2896 iopkt.comm.tstamp = grnt;
2897 iopkt.requested = reqt;
2898 if (ret != -1)
2899 iopkt.iotype = OTHERIO_TRACE;
2900 else
2901 iopkt.iotype = OTHERIO_TRACE_ERROR;
2902 iopkt.fd = fileno (stream);
2903 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
2904 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
2905 POP_REENTRANCE (guard);
2906 return ret;
2909 /*------------------------------------------------------------- fgetpos */
2910 static int
2911 gprofng_fgetpos (int(real_fgetpos) (FILE *stream, fpos_t *pos),
2912 FILE *stream, fpos_t *pos)
2914 int *guard;
2915 int ret;
2916 IOTrace_packet iopkt;
2917 if (CHCK_REENTRANCE (guard) || stream == NULL)
2918 return real_fgetpos (stream, pos);
2919 PUSH_REENTRANCE (guard);
2920 hrtime_t reqt = gethrtime ();
2921 ret = real_fgetpos (stream, pos);
2922 if (RECHCK_REENTRANCE (guard))
2924 POP_REENTRANCE (guard);
2925 return ret;
2927 hrtime_t grnt = gethrtime ();
2928 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2929 iopkt.comm.tsize = sizeof (IOTrace_packet);
2930 iopkt.comm.tstamp = grnt;
2931 iopkt.requested = reqt;
2932 if (ret == 0)
2933 iopkt.iotype = OTHERIO_TRACE;
2934 else
2935 iopkt.iotype = OTHERIO_TRACE_ERROR;
2936 iopkt.fd = fileno (stream);
2937 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl,
2938 iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
2939 collector_interface->writeDataRecord (io_hndl, (Common_packet*) &iopkt);
2940 POP_REENTRANCE (guard);
2941 return ret;
2944 #define DCL_FGETPOS(dcl_f) \
2945 int dcl_f (FILE *stream, fpos_t *pos) \
2947 if (__real_fgetpos == NULL) \
2948 init_io_intf (); \
2949 return gprofng_fgetpos (__real_fgetpos, stream, pos); \
2952 DCL_FUNC_VER (DCL_FGETPOS, fgetpos_2_17, fgetpos@GLIBC_2.17)
2953 DCL_FUNC_VER (DCL_FGETPOS, fgetpos_2_2_5, fgetpos@GLIBC_2.2.5)
2954 DCL_FUNC_VER (DCL_FGETPOS, fgetpos_2_2, fgetpos@GLIBC_2.2)
2955 DCL_FUNC_VER (DCL_FGETPOS, fgetpos_2_0, fgetpos@GLIBC_2.0)
2956 DCL_FGETPOS (fgetpos)
2958 /*------------------------------------------------------------- fgetpos64 */
2959 static int
2960 gprofng_fgetpos64 (int(real_fgetpos64) (FILE *, fpos64_t *), FILE *stream, fpos64_t *pos)
2962 int *guard;
2963 int ret;
2964 IOTrace_packet iopkt;
2965 if (CHCK_REENTRANCE (guard) || stream == NULL)
2966 return real_fgetpos64 (stream, pos);
2967 PUSH_REENTRANCE (guard);
2968 hrtime_t reqt = gethrtime ();
2969 ret = real_fgetpos64 (stream, pos);
2970 if (RECHCK_REENTRANCE (guard))
2972 POP_REENTRANCE (guard);
2973 return ret;
2975 hrtime_t grnt = gethrtime ();
2976 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
2977 iopkt.comm.tsize = sizeof (IOTrace_packet);
2978 iopkt.comm.tstamp = grnt;
2979 iopkt.requested = reqt;
2980 if (ret == 0)
2981 iopkt.iotype = OTHERIO_TRACE;
2982 else
2983 iopkt.iotype = OTHERIO_TRACE_ERROR;
2984 iopkt.fd = fileno (stream);
2985 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl,
2986 iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
2987 collector_interface->writeDataRecord (io_hndl, (Common_packet*) &iopkt);
2988 POP_REENTRANCE (guard);
2989 return ret;
2992 #define DCL_FGETPOS64(dcl_f) \
2993 int dcl_f (FILE *stream, fpos64_t *pos) \
2995 if (__real_fgetpos64 == NULL) \
2996 init_io_intf (); \
2997 return gprofng_fgetpos64 (__real_fgetpos64, stream, pos); \
3000 DCL_FUNC_VER (DCL_FGETPOS64, fgetpos64_2_17, fgetpos64@GLIBC_2.17)
3001 DCL_FUNC_VER (DCL_FGETPOS64, fgetpos64_2_2_5, fgetpos64@GLIBC_2.2.5)
3002 DCL_FUNC_VER (DCL_FGETPOS64, fgetpos64_2_2, fgetpos64@GLIBC_2.2)
3003 DCL_FUNC_VER (DCL_FGETPOS64, fgetpos64_2_1, fgetpos64@GLIBC_2.1)
3004 #if !defined(__USE_LARGEFILE64)
3005 DCL_FGETPOS64 (fgetpos64)
3006 #endif
3007 /*------------------------------------------------------------- fsetpos */
3008 static int
3009 gprofng_fsetpos (int(real_fsetpos) (FILE *, const fpos_t *),
3010 FILE *stream, const fpos_t *pos)
3012 int *guard;
3013 int ret;
3014 IOTrace_packet iopkt;
3015 if (CHCK_REENTRANCE (guard) || stream == NULL)
3016 return real_fsetpos (stream, pos);
3017 PUSH_REENTRANCE (guard);
3018 hrtime_t reqt = gethrtime ();
3019 ret = real_fsetpos (stream, pos);
3020 if (RECHCK_REENTRANCE (guard))
3022 POP_REENTRANCE (guard);
3023 return ret;
3025 hrtime_t grnt = gethrtime ();
3026 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3027 iopkt.comm.tsize = sizeof (IOTrace_packet);
3028 iopkt.comm.tstamp = grnt;
3029 iopkt.requested = reqt;
3030 if (ret == 0)
3031 iopkt.iotype = OTHERIO_TRACE;
3032 else
3033 iopkt.iotype = OTHERIO_TRACE_ERROR;
3034 iopkt.fd = fileno (stream);
3035 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl,
3036 iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
3037 collector_interface->writeDataRecord (io_hndl, (Common_packet*) &iopkt);
3038 POP_REENTRANCE (guard);
3039 return ret;
3042 #define DCL_FSETPOS(dcl_f) \
3043 int dcl_f (FILE *stream, const fpos_t *pos) \
3045 if (__real_fsetpos == NULL) \
3046 init_io_intf (); \
3047 return gprofng_fsetpos (__real_fsetpos, stream, pos); \
3050 DCL_FUNC_VER (DCL_FSETPOS, fsetpos_2_17, fsetpos@GLIBC_2.17)
3051 DCL_FUNC_VER (DCL_FSETPOS, fsetpos_2_2_5, fsetpos@GLIBC_2.2.5)
3052 DCL_FUNC_VER (DCL_FSETPOS, fsetpos_2_2, fsetpos@GLIBC_2.2)
3053 DCL_FUNC_VER (DCL_FSETPOS, fsetpos_2_0, fsetpos@GLIBC_2.0)
3054 DCL_FSETPOS (fsetpos)
3056 /*------------------------------------------------------------- fsetpos64 */
3057 static int
3058 gprofng_fsetpos64 (int(real_fsetpos64) (FILE *, const fpos64_t *),
3059 FILE *stream, const fpos64_t *pos)
3061 int *guard;
3062 int ret;
3063 IOTrace_packet iopkt;
3064 if (CHCK_REENTRANCE (guard) || stream == NULL)
3065 return real_fsetpos64 (stream, pos);
3066 PUSH_REENTRANCE (guard);
3067 hrtime_t reqt = gethrtime ();
3068 ret = real_fsetpos64 (stream, pos);
3069 if (RECHCK_REENTRANCE (guard))
3071 POP_REENTRANCE (guard);
3072 return ret;
3074 hrtime_t grnt = gethrtime ();
3075 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3076 iopkt.comm.tsize = sizeof (IOTrace_packet);
3077 iopkt.comm.tstamp = grnt;
3078 iopkt.requested = reqt;
3079 if (ret == 0)
3080 iopkt.iotype = OTHERIO_TRACE;
3081 else
3082 iopkt.iotype = OTHERIO_TRACE_ERROR;
3083 iopkt.fd = fileno (stream);
3084 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl,
3085 iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
3086 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3087 POP_REENTRANCE (guard);
3088 return ret;
3091 #define DCL_FSETPOS64(dcl_f) \
3092 int dcl_f (FILE *stream, const fpos64_t *pos) \
3094 if (__real_fsetpos64 == NULL) \
3095 init_io_intf (); \
3096 return gprofng_fsetpos64 (__real_fsetpos64, stream, pos); \
3099 DCL_FUNC_VER (DCL_FSETPOS64, fsetpos64_2_17, fsetpos64@GLIBC_2.17)
3100 DCL_FUNC_VER (DCL_FSETPOS64, fsetpos64_2_2_5, fsetpos64@GLIBC_2.2.5)
3101 DCL_FUNC_VER (DCL_FSETPOS64, fsetpos64_2_2, fsetpos64@GLIBC_2.2)
3102 DCL_FUNC_VER (DCL_FSETPOS64, fsetpos64_2_1, fsetpos64@GLIBC_2.1)
3103 #if !defined(__USE_LARGEFILE64)
3104 DCL_FSETPOS64 (fsetpos64)
3105 #endif
3106 /*------------------------------------------------------------- fsync */
3108 fsync (int fildes)
3110 int *guard;
3111 int ret;
3112 IOTrace_packet iopkt;
3113 if (NULL_PTR (fsync))
3114 init_io_intf ();
3115 if (CHCK_REENTRANCE (guard))
3116 return CALL_REAL (fsync)(fildes);
3117 PUSH_REENTRANCE (guard);
3118 hrtime_t reqt = gethrtime ();
3119 ret = CALL_REAL (fsync)(fildes);
3120 if (RECHCK_REENTRANCE (guard))
3122 POP_REENTRANCE (guard);
3123 return ret;
3125 hrtime_t grnt = gethrtime ();
3126 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3127 iopkt.comm.tsize = sizeof (IOTrace_packet);
3128 iopkt.comm.tstamp = grnt;
3129 iopkt.requested = reqt;
3130 if (ret == 0)
3131 iopkt.iotype = OTHERIO_TRACE;
3132 else
3133 iopkt.iotype = OTHERIO_TRACE_ERROR;
3134 iopkt.fd = fildes;
3135 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3136 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3137 POP_REENTRANCE (guard);
3138 return ret;
3141 /*------------------------------------------------------------- readdir */
3142 struct dirent*
3143 readdir (DIR *dirp)
3145 int *guard;
3146 struct dirent *ptr;
3147 IOTrace_packet iopkt;
3148 if (NULL_PTR (readdir))
3149 init_io_intf ();
3150 if (CHCK_REENTRANCE (guard))
3151 return CALL_REAL (readdir)(dirp);
3152 PUSH_REENTRANCE (guard);
3153 hrtime_t reqt = gethrtime ();
3154 ptr = CALL_REAL (readdir)(dirp);
3155 if (RECHCK_REENTRANCE (guard))
3157 POP_REENTRANCE (guard);
3158 return ptr;
3160 hrtime_t grnt = gethrtime ();
3161 collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
3162 iopkt.comm.tsize = sizeof ( IOTrace_packet);
3163 iopkt.comm.tstamp = grnt;
3164 iopkt.requested = reqt;
3165 if (ptr != NULL)
3166 iopkt.iotype = OTHERIO_TRACE;
3167 else
3168 iopkt.iotype = OTHERIO_TRACE_ERROR;
3169 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3170 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3171 POP_REENTRANCE (guard);
3172 return ptr;
3175 /*------------------------------------------------------------- flock */
3177 flock (int fd, int operation)
3179 int *guard;
3180 int ret;
3181 IOTrace_packet iopkt;
3182 if (NULL_PTR (flock))
3183 init_io_intf ();
3184 if (CHCK_REENTRANCE (guard))
3185 return CALL_REAL (flock)(fd, operation);
3186 PUSH_REENTRANCE (guard);
3187 hrtime_t reqt = gethrtime ();
3188 ret = CALL_REAL (flock)(fd, operation);
3189 if (RECHCK_REENTRANCE (guard))
3191 POP_REENTRANCE (guard);
3192 return ret;
3194 hrtime_t grnt = gethrtime ();
3195 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3196 iopkt.comm.tsize = sizeof (IOTrace_packet);
3197 iopkt.comm.tstamp = grnt;
3198 iopkt.requested = reqt;
3199 if (ret == 0)
3200 iopkt.iotype = OTHERIO_TRACE;
3201 else
3202 iopkt.iotype = OTHERIO_TRACE_ERROR;
3203 iopkt.fd = fd;
3204 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3205 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3206 POP_REENTRANCE (guard);
3207 return ret;
3210 /*------------------------------------------------------------- lockf */
3212 lockf (int fildes, int function, off_t size)
3214 int *guard;
3215 int ret;
3216 IOTrace_packet iopkt;
3217 if (NULL_PTR (lockf))
3218 init_io_intf ();
3219 if (CHCK_REENTRANCE (guard))
3220 return CALL_REAL (lockf)(fildes, function, size);
3221 PUSH_REENTRANCE (guard);
3222 hrtime_t reqt = gethrtime ();
3223 ret = CALL_REAL (lockf)(fildes, function, size);
3224 if (RECHCK_REENTRANCE (guard))
3226 POP_REENTRANCE (guard);
3227 return ret;
3229 hrtime_t grnt = gethrtime ();
3230 collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
3231 iopkt.comm.tsize = sizeof (IOTrace_packet);
3232 iopkt.comm.tstamp = grnt;
3233 iopkt.requested = reqt;
3234 if (ret == 0)
3235 iopkt.iotype = OTHERIO_TRACE;
3236 else
3237 iopkt.iotype = OTHERIO_TRACE_ERROR;
3238 iopkt.fd = fildes;
3239 iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
3240 collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
3241 POP_REENTRANCE (guard);
3242 return ret;