]>
Commit | Line | Data |
---|---|---|
fd67aa11 | 1 | /* Copyright (C) 2021-2024 Free Software Foundation, Inc. |
bb368aad VM |
2 | Contributed by Oracle. |
3 | ||
4 | This file is part of GNU Binutils. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 3, or (at your option) | |
9 | any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, 51 Franklin Street - Fifth Floor, Boston, | |
19 | MA 02110-1301, USA. */ | |
20 | ||
21 | /* | |
22 | * IO events | |
23 | */ | |
24 | #include "config.h" | |
25 | #include <dlfcn.h> | |
26 | #include <errno.h> | |
27 | #include <stdarg.h> | |
53beac2e | 28 | #include <stddef.h> |
bb368aad VM |
29 | #include <stdlib.h> |
30 | ||
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> | |
36 | ||
37 | #include "gp-defs.h" | |
fe39ffdc | 38 | #include "collector.h" |
bb368aad | 39 | #include "gp-experiment.h" |
bb368aad VM |
40 | #include "tsd.h" |
41 | ||
bb368aad VM |
42 | |
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; | |
55 | ||
56 | typedef long long offset_t; | |
57 | ||
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 (); | |
64 | ||
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) */ | |
73 | }; | |
74 | ||
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; | |
80 | ||
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))--) | |
bb368aad VM |
85 | #define gethrtime collector_interface->getHiResTime |
86 | ||
bb368aad VM |
87 | |
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; | |
bb368aad | 135 | static int (*__real_open64)(const char *path, int oflag, ...) = NULL; |
66f76c54 | 136 | static int (*__real_open64_2_2)(const char *path, int oflag, ...) = NULL; |
bb368aad VM |
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; | |
66f76c54 VM |
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; | |
bb368aad | 142 | static FILE *(*__real_fopen_2_1)(const char *filename, const char *mode) = NULL; |
66f76c54 VM |
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; | |
bb368aad | 146 | static int (*__real_fclose_2_1)(FILE *stream) = NULL; |
66f76c54 VM |
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; | |
bb368aad | 150 | static FILE *(*__real_fdopen_2_1)(int fildes, const char *mode) = NULL; |
66f76c54 VM |
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; | |
bb368aad | 154 | static int (*__real_fgetpos_2_2)(FILE *stream, fpos_t *pos) = NULL; |
66f76c54 VM |
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; | |
bb368aad | 158 | static int (*__real_fsetpos_2_2)(FILE *stream, const fpos_t *pos) = NULL; |
66f76c54 | 159 | static int (*__real_fsetpos_2_0)(FILE *stream, const fpos_t *pos) = NULL; |
bb368aad VM |
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; | |
66f76c54 VM |
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; | |
bb368aad | 165 | static int (*__real_fgetpos64_2_1)(FILE *stream, fpos64_t *pos) = NULL; |
66f76c54 VM |
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; | |
bb368aad | 169 | static int (*__real_fsetpos64_2_1)(FILE *stream, const fpos64_t *pos) = NULL; |
66f76c54 | 170 | static ssize_t (*__real_pwrite64_2_2)(int fildes, const void *buf, size_t nbyte, off64_t offset) = NULL; |
bb368aad VM |
171 | |
172 | static int | |
173 | collector_align_pktsize (int sz) | |
174 | { | |
175 | int pktSize = sz; | |
176 | if (sz <= 0) | |
177 | return sz; | |
178 | if ((sz % 8) != 0) | |
179 | { | |
180 | pktSize = (sz / 8) + 1; | |
181 | pktSize *= 8; | |
182 | } | |
183 | return pktSize; | |
184 | } | |
185 | ||
186 | static void | |
187 | collector_memset (void *s, int c, size_t n) | |
188 | { | |
189 | unsigned char *s1 = s; | |
190 | while (n--) | |
191 | *s1++ = (unsigned char) c; | |
192 | } | |
193 | ||
194 | static size_t | |
195 | collector_strlen (const char *s) | |
196 | { | |
197 | if (s == NULL) | |
198 | return 0; | |
199 | int len = -1; | |
200 | while (s[++len] != '\0') | |
201 | ; | |
202 | return len; | |
203 | } | |
204 | ||
205 | static size_t | |
206 | collector_strncpy (char *dst, const char *src, size_t dstsize) | |
207 | { | |
208 | size_t i; | |
209 | for (i = 0; i < dstsize; i++) | |
210 | { | |
211 | dst[i] = src[i]; | |
212 | if (src[i] == '\0') | |
213 | break; | |
214 | } | |
215 | return i; | |
216 | } | |
217 | ||
218 | static char * | |
219 | collector_strchr (const char *s, int c) | |
220 | { | |
221 | do | |
222 | { | |
223 | if (*s == (char) c) | |
224 | return ((char *) s); | |
225 | } | |
226 | while (*s++); | |
227 | return (NULL); | |
228 | } | |
229 | ||
230 | static FileSystem_type | |
231 | collector_fstype (const char *path) | |
232 | { | |
233 | return UNKNOWNFS_TYPE; | |
234 | } | |
235 | ||
236 | void | |
237 | __collector_module_init (CollectorInterface *_collector_interface) | |
238 | { | |
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; | |
249 | } | |
250 | ||
251 | static int | |
252 | open_experiment (const char *exp) | |
253 | { | |
254 | if (collector_interface == NULL) | |
255 | { | |
256 | Tprintf (0, "iotrace: collector_interface is null.\n"); | |
257 | return COL_ERROR_IOINIT; | |
258 | } | |
259 | if (io_hndl == COLLECTOR_MODULE_ERR) | |
260 | { | |
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; | |
265 | } | |
266 | TprintfT (0, "iotrace: open_experiment %s\n", exp); | |
267 | if (NULL_PTR (fopen)) | |
268 | init_io_intf (); | |
269 | if (io_heap == NULL) | |
270 | { | |
271 | io_heap = collector_interface->newHeap (); | |
272 | if (io_heap == NULL) | |
273 | { | |
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; | |
278 | } | |
279 | } | |
280 | ||
281 | const char *params = collector_interface->getParams (); | |
282 | while (params) | |
283 | { | |
284 | if ((params[0] == 'i') && (params[1] == ':')) | |
285 | { | |
286 | params += 2; | |
287 | break; | |
288 | } | |
289 | params = collector_strchr (params, ';'); | |
290 | if (params) | |
291 | params++; | |
292 | } | |
293 | if (params == NULL) /* IO data collection not specified */ | |
294 | return COL_ERROR_IOINIT; | |
295 | ||
296 | io_key = collector_interface->createKey (sizeof ( int), NULL, NULL); | |
297 | if (io_key == (unsigned) - 1) | |
298 | { | |
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; | |
303 | } | |
304 | ||
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 */ | |
bb368aad VM |
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", | |
53beac2e VM |
311 | (int) offsetof (IOTrace_packet, comm.lwp_id), |
312 | fld_sizeof (IOTrace_packet, comm.lwp_id) == 4 ? "INT32" : "INT64"); | |
bb368aad | 313 | collector_interface->writeLog (" <field name=\"THRID\" uname=\"Thread number\" offset=\"%d\" type=\"%s\"/>\n", |
53beac2e VM |
314 | (int) offsetof (IOTrace_packet, comm.thr_id), |
315 | fld_sizeof (IOTrace_packet, comm.thr_id) == 4 ? "INT32" : "INT64"); | |
bb368aad | 316 | collector_interface->writeLog (" <field name=\"CPUID\" uname=\"CPU id\" offset=\"%d\" type=\"%s\"/>\n", |
53beac2e VM |
317 | (int) offsetof (IOTrace_packet, comm.cpu_id), |
318 | fld_sizeof (IOTrace_packet, comm.cpu_id) == 4 ? "INT32" : "INT64"); | |
bb368aad | 319 | collector_interface->writeLog (" <field name=\"TSTAMP\" uname=\"High resolution timestamp\" offset=\"%d\" type=\"%s\"/>\n", |
53beac2e VM |
320 | (int) offsetof (IOTrace_packet, comm.tstamp), |
321 | fld_sizeof (IOTrace_packet, comm.tstamp) == 4 ? "INT32" : "INT64"); | |
bb368aad | 322 | collector_interface->writeLog (" <field name=\"FRINFO\" offset=\"%d\" type=\"%s\"/>\n", |
53beac2e VM |
323 | (int) offsetof (IOTrace_packet, comm.frinfo), |
324 | fld_sizeof (IOTrace_packet, comm.frinfo) == 4 ? "INT32" : "INT64"); | |
bb368aad | 325 | collector_interface->writeLog (" <field name=\"IOTYPE\" uname=\"IO trace function type\" offset=\"%d\" type=\"%s\"/>\n", |
53beac2e VM |
326 | (int) offsetof (IOTrace_packet, iotype), |
327 | fld_sizeof (IOTrace_packet, iotype) == 4 ? "INT32" : "INT64"); | |
bb368aad | 328 | collector_interface->writeLog (" <field name=\"IOFD\" uname=\"File descriptor\" offset=\"%d\" type=\"%s\"/>\n", |
53beac2e VM |
329 | (int) offsetof (IOTrace_packet, fd), |
330 | fld_sizeof (IOTrace_packet, fd) == 4 ? "INT32" : "INT64"); | |
bb368aad | 331 | collector_interface->writeLog (" <field name=\"IONBYTE\" uname=\"Number of bytes\" offset=\"%d\" type=\"%s\"/>\n", |
53beac2e VM |
332 | (int) offsetof (IOTrace_packet, nbyte), |
333 | fld_sizeof (IOTrace_packet, nbyte) == 4 ? "INT32" : "INT64"); | |
bb368aad | 334 | collector_interface->writeLog (" <field name=\"IORQST\" uname=\"Time of IO requested\" offset=\"%d\" type=\"%s\"/>\n", |
53beac2e VM |
335 | (int) offsetof (IOTrace_packet, requested), |
336 | fld_sizeof (IOTrace_packet, requested) == 4 ? "INT32" : "INT64"); | |
bb368aad | 337 | collector_interface->writeLog (" <field name=\"IOOFD\" uname=\"Original file descriptor\" offset=\"%d\" type=\"%s\"/>\n", |
53beac2e VM |
338 | (int) offsetof (IOTrace_packet, ofd), |
339 | fld_sizeof (IOTrace_packet, ofd) == 4 ? "INT32" : "INT64"); | |
bb368aad | 340 | collector_interface->writeLog (" <field name=\"IOFSTYPE\" uname=\"File system type\" offset=\"%d\" type=\"%s\"/>\n", |
53beac2e VM |
341 | (int) offsetof (IOTrace_packet, fstype), |
342 | fld_sizeof (IOTrace_packet, fstype) == 4 ? "INT32" : "INT64"); | |
bb368aad | 343 | collector_interface->writeLog (" <field name=\"IOFNAME\" uname=\"File name\" offset=\"%d\" type=\"%s\"/>\n", |
53beac2e | 344 | (int) offsetof (IOTrace_packet, fname), "STRING"); |
bb368aad VM |
345 | collector_interface->writeLog (" </profpckt>\n"); |
346 | collector_interface->writeLog ("</profile>\n"); | |
347 | return COL_ERROR_NONE; | |
348 | } | |
349 | ||
350 | static int | |
351 | start_data_collection (void) | |
352 | { | |
353 | io_mode = 1; | |
354 | Tprintf (0, "iotrace: start_data_collection\n"); | |
355 | return 0; | |
356 | } | |
357 | ||
358 | static int | |
359 | stop_data_collection (void) | |
360 | { | |
361 | io_mode = 0; | |
362 | Tprintf (0, "iotrace: stop_data_collection\n"); | |
363 | return 0; | |
364 | } | |
365 | ||
366 | static int | |
367 | close_experiment (void) | |
368 | { | |
369 | io_mode = 0; | |
370 | io_key = COLLECTOR_TSD_INVALID_KEY; | |
371 | if (io_heap != NULL) | |
372 | { | |
373 | collector_interface->deleteHeap (io_heap); | |
374 | io_heap = NULL; | |
375 | } | |
376 | Tprintf (0, "iotrace: close_experiment\n"); | |
377 | return 0; | |
378 | } | |
379 | ||
380 | static int | |
381 | detach_experiment (void) | |
382 | { | |
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) | |
387 | { | |
388 | collector_interface->deleteHeap (io_heap); | |
389 | io_heap = NULL; | |
390 | } | |
391 | Tprintf (0, "iotrace: detach_experiment\n"); | |
392 | return 0; | |
393 | } | |
394 | ||
66f76c54 VM |
395 | static int |
396 | init_fopen (void *dlflag) | |
397 | { | |
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; | |
413 | } | |
414 | ||
bb368aad VM |
415 | static int |
416 | init_io_intf () | |
417 | { | |
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) | |
425 | { | |
426 | /* pull the plug if recursion occurs... */ | |
427 | abort (); | |
428 | } | |
429 | ||
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 (); | |
436 | ||
bb368aad | 437 | dlflag = RTLD_NEXT; |
66f76c54 VM |
438 | if (init_fopen (dlflag) == 0) |
439 | { | |
440 | if (init_fopen (RTLD_DEFAULT)) | |
441 | dlflag = RTLD_DEFAULT; | |
bb368aad VM |
442 | else |
443 | { | |
444 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen\n"); | |
445 | rc = COL_ERROR_IOINIT; | |
446 | } | |
447 | } | |
448 | ||
66f76c54 VM |
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"); | |
bb368aad | 463 | |
35fab451 VM |
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"); | |
478 | ||
66f76c54 VM |
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) | |
bb368aad | 485 | { |
66f76c54 | 486 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread\n"); |
bb368aad VM |
487 | rc = COL_ERROR_IOINIT; |
488 | } | |
489 | ||
66f76c54 VM |
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) | |
bb368aad | 496 | { |
66f76c54 | 497 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite\n"); |
bb368aad VM |
498 | rc = COL_ERROR_IOINIT; |
499 | } | |
500 | ||
bb368aad | 501 | |
66f76c54 VM |
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"); | |
507 | ||
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"); | |
bb368aad VM |
522 | if (__real_fclose == NULL) |
523 | { | |
524 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose\n"); | |
525 | rc = COL_ERROR_IOINIT; | |
526 | } | |
527 | ||
66f76c54 VM |
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"); | |
bb368aad VM |
542 | if (__real_fdopen == NULL) |
543 | { | |
544 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen\n"); | |
545 | rc = COL_ERROR_IOINIT; | |
546 | } | |
547 | ||
66f76c54 VM |
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"); | |
bb368aad VM |
562 | if (__real_fgetpos == NULL) |
563 | { | |
564 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos\n"); | |
565 | rc = COL_ERROR_IOINIT; | |
566 | } | |
567 | ||
66f76c54 VM |
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"); | |
bb368aad VM |
582 | if (__real_fsetpos == NULL) |
583 | { | |
584 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos\n"); | |
585 | rc = COL_ERROR_IOINIT; | |
586 | } | |
bb368aad VM |
587 | |
588 | __real_open = (int (*)(const char*, int, ...))dlsym (dlflag, "open"); | |
589 | if (__real_open == NULL) | |
590 | { | |
591 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open\n"); | |
592 | rc = COL_ERROR_IOINIT; | |
593 | } | |
594 | ||
66f76c54 VM |
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"); | |
bb368aad VM |
600 | |
601 | __real_fcntl = (int (*)(int, int, ...))dlsym (dlflag, "fcntl"); | |
602 | if (__real_fcntl == NULL) | |
603 | { | |
604 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fcntl\n"); | |
605 | rc = COL_ERROR_IOINIT; | |
606 | } | |
607 | ||
608 | __real_openat = (int (*)(int, const char*, int, ...))dlsym (dlflag, "openat"); | |
609 | if (__real_openat == NULL) | |
610 | { | |
611 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT openat\n"); | |
612 | rc = COL_ERROR_IOINIT; | |
613 | } | |
614 | ||
615 | __real_close = (int (*)(int))dlsym (dlflag, "close"); | |
616 | if (__real_close == NULL) | |
617 | { | |
618 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT close\n"); | |
619 | rc = COL_ERROR_IOINIT; | |
620 | } | |
621 | ||
622 | __real_dup = (int (*)(int))dlsym (dlflag, "dup"); | |
623 | if (__real_dup == NULL) | |
624 | { | |
625 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT dup\n"); | |
626 | rc = COL_ERROR_IOINIT; | |
627 | } | |
628 | ||
629 | __real_dup2 = (int (*)(int, int))dlsym (dlflag, "dup2"); | |
630 | if (__real_dup2 == NULL) | |
631 | { | |
632 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT dup2\n"); | |
633 | rc = COL_ERROR_IOINIT; | |
634 | } | |
635 | ||
636 | __real_pipe = (int (*)(int[]))dlsym (dlflag, "pipe"); | |
637 | if (__real_pipe == NULL) | |
638 | { | |
639 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pipe\n"); | |
640 | rc = COL_ERROR_IOINIT; | |
641 | } | |
642 | ||
643 | __real_socket = (int (*)(int, int, int))dlsym (dlflag, "socket"); | |
644 | if (__real_socket == NULL) | |
645 | { | |
646 | __real_socket = (int (*)(int, int, int))dlsym (RTLD_NEXT, "socket"); | |
647 | if (__real_socket == NULL) | |
648 | { | |
649 | #if 0 | |
650 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT socket\n"); | |
651 | rc = COL_ERROR_IOINIT; | |
652 | #endif | |
653 | } | |
654 | } | |
655 | ||
656 | __real_mkstemp = (int (*)(char*))dlsym (dlflag, "mkstemp"); | |
657 | if (__real_mkstemp == NULL) | |
658 | { | |
659 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT mkstemp\n"); | |
660 | rc = COL_ERROR_IOINIT; | |
661 | } | |
662 | ||
663 | __real_mkstemps = (int (*)(char*, int))dlsym (dlflag, "mkstemps"); | |
664 | if (__real_mkstemps == NULL) | |
665 | { | |
666 | #if 0 | |
667 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT mkstemps\n"); | |
668 | rc = COL_ERROR_IOINIT; | |
669 | #endif | |
670 | } | |
671 | ||
672 | __real_creat = (int (*)(const char*, mode_t))dlsym (dlflag, "creat"); | |
673 | if (__real_creat == NULL) | |
674 | { | |
675 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT creat\n"); | |
676 | rc = COL_ERROR_IOINIT; | |
677 | } | |
678 | ||
bb368aad VM |
679 | __real_creat64 = (int (*)(const char*, mode_t))dlsym (dlflag, "creat64"); |
680 | if (__real_creat64 == NULL) | |
681 | { | |
682 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT creat64\n"); | |
683 | rc = COL_ERROR_IOINIT; | |
684 | } | |
bb368aad VM |
685 | |
686 | __real_read = (ssize_t (*)(int, void*, size_t))dlsym (dlflag, "read"); | |
687 | if (__real_read == NULL) | |
688 | { | |
689 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT read\n"); | |
690 | rc = COL_ERROR_IOINIT; | |
691 | } | |
692 | ||
693 | __real_write = (ssize_t (*)(int, const void*, size_t))dlsym (dlflag, "write"); | |
694 | if (__real_write == NULL) | |
695 | { | |
696 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT write\n"); | |
697 | rc = COL_ERROR_IOINIT; | |
698 | } | |
699 | ||
700 | __real_readv = (ssize_t (*)(int, const struct iovec*, int))dlsym (dlflag, "readv"); | |
701 | if (__real_readv == NULL) | |
702 | { | |
703 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT readv\n"); | |
704 | rc = COL_ERROR_IOINIT; | |
705 | } | |
706 | ||
707 | __real_writev = (ssize_t (*)(int, const struct iovec*, int))dlsym (dlflag, "writev"); | |
708 | if (__real_writev == NULL) | |
709 | { | |
710 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT writev\n"); | |
711 | rc = COL_ERROR_IOINIT; | |
712 | } | |
713 | ||
714 | __real_fread = (size_t (*)(void*, size_t, size_t, FILE*))dlsym (dlflag, "fread"); | |
715 | if (__real_fread == NULL) | |
716 | { | |
717 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fread\n"); | |
718 | rc = COL_ERROR_IOINIT; | |
719 | } | |
720 | ||
721 | __real_fwrite = (size_t (*)(const void*, size_t, size_t, FILE*))dlsym (dlflag, "fwrite"); | |
722 | if (__real_fwrite == NULL) | |
723 | { | |
724 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fwrite\n"); | |
725 | rc = COL_ERROR_IOINIT; | |
726 | } | |
727 | ||
728 | __real_pread = (ssize_t (*)(int, void*, size_t, off_t))dlsym (dlflag, "pread"); | |
729 | if (__real_pread == NULL) | |
730 | { | |
731 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread\n"); | |
732 | rc = COL_ERROR_IOINIT; | |
733 | } | |
734 | ||
735 | __real_pwrite = (ssize_t (*)(int, const void*, size_t, off_t))dlsym (dlflag, "pwrite"); | |
736 | if (__real_pwrite == NULL) | |
737 | { | |
738 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite\n"); | |
739 | rc = COL_ERROR_IOINIT; | |
740 | } | |
741 | ||
742 | __real_pwrite64 = (ssize_t (*)(int, const void*, size_t, off64_t))dlsym (dlflag, "pwrite64"); | |
743 | if (__real_pwrite64 == NULL) | |
744 | { | |
745 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite64\n"); | |
746 | rc = COL_ERROR_IOINIT; | |
747 | } | |
748 | ||
749 | __real_fgets = (char* (*)(char*, int, FILE*))dlsym (dlflag, "fgets"); | |
750 | if (__real_fgets == NULL) | |
751 | { | |
752 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgets\n"); | |
753 | rc = COL_ERROR_IOINIT; | |
754 | } | |
755 | ||
756 | __real_fputs = (int (*)(const char*, FILE*))dlsym (dlflag, "fputs"); | |
757 | if (__real_fputs == NULL) | |
758 | { | |
759 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fputs\n"); | |
760 | rc = COL_ERROR_IOINIT; | |
761 | } | |
762 | ||
763 | __real_fputc = (int (*)(int, FILE*))dlsym (dlflag, "fputc"); | |
764 | if (__real_fputc == NULL) | |
765 | { | |
766 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fputc\n"); | |
767 | rc = COL_ERROR_IOINIT; | |
768 | } | |
769 | ||
770 | __real_vfprintf = (int (*)(FILE*, const char*, va_list))dlsym (dlflag, "vfprintf"); | |
771 | if (__real_vfprintf == NULL) | |
772 | { | |
773 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT vfprintf\n"); | |
774 | rc = COL_ERROR_IOINIT; | |
775 | } | |
776 | ||
777 | ||
778 | __real_lseek = (off_t (*)(int, off_t, int))dlsym (dlflag, "lseek"); | |
779 | if (__real_lseek == NULL) | |
780 | { | |
781 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT lseek\n"); | |
782 | rc = COL_ERROR_IOINIT; | |
783 | } | |
784 | ||
785 | __real_llseek = (offset_t (*)(int, offset_t, int))dlsym (dlflag, "llseek"); | |
786 | if (__real_llseek == NULL) | |
787 | { | |
788 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT llseek\n"); | |
789 | rc = COL_ERROR_IOINIT; | |
790 | } | |
791 | ||
792 | __real_chmod = (int (*)(const char*, mode_t))dlsym (dlflag, "chmod"); | |
793 | if (__real_chmod == NULL) | |
794 | { | |
795 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT chmod\n"); | |
796 | rc = COL_ERROR_IOINIT; | |
797 | } | |
798 | ||
799 | __real_access = (int (*)(const char*, int))dlsym (dlflag, "access"); | |
800 | if (__real_access == NULL) | |
801 | { | |
802 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT access\n"); | |
803 | rc = COL_ERROR_IOINIT; | |
804 | } | |
805 | ||
806 | __real_rename = (int (*)(const char*, const char*))dlsym (dlflag, "rename"); | |
807 | if (__real_rename == NULL) | |
808 | { | |
809 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT rename\n"); | |
810 | rc = COL_ERROR_IOINIT; | |
811 | } | |
812 | ||
813 | __real_mkdir = (int (*)(const char*, mode_t))dlsym (dlflag, "mkdir"); | |
814 | if (__real_mkdir == NULL) | |
815 | { | |
816 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT mkdir\n"); | |
817 | rc = COL_ERROR_IOINIT; | |
818 | } | |
819 | ||
820 | __real_getdents = (int (*)(int, struct dirent*, size_t))dlsym (dlflag, "getdents"); | |
821 | if (__real_getdents == NULL) | |
822 | { | |
823 | #if 0 | |
824 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT getdents\n"); | |
825 | rc = COL_ERROR_IOINIT; | |
826 | #endif | |
827 | } | |
828 | ||
829 | __real_unlink = (int (*)(const char*))dlsym (dlflag, "unlink"); | |
830 | if (__real_unlink == NULL) | |
831 | { | |
832 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT unlink\n"); | |
833 | rc = COL_ERROR_IOINIT; | |
834 | } | |
835 | ||
836 | __real_fseek = (int (*)(FILE*, long, int))dlsym (dlflag, "fseek"); | |
837 | if (__real_fseek == NULL) | |
838 | { | |
839 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fseek\n"); | |
840 | rc = COL_ERROR_IOINIT; | |
841 | } | |
842 | ||
843 | __real_rewind = (void (*)(FILE*))dlsym (dlflag, "rewind"); | |
844 | if (__real_rewind == NULL) | |
845 | { | |
846 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT rewind\n"); | |
847 | rc = COL_ERROR_IOINIT; | |
848 | } | |
849 | ||
850 | __real_ftell = (long (*)(FILE*))dlsym (dlflag, "ftell"); | |
851 | if (__real_ftell == NULL) | |
852 | { | |
853 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT ftell\n"); | |
854 | rc = COL_ERROR_IOINIT; | |
855 | } | |
856 | ||
857 | __real_fsync = (int (*)(int))dlsym (dlflag, "fsync"); | |
858 | if (__real_fsync == NULL) | |
859 | { | |
860 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsync\n"); | |
861 | rc = COL_ERROR_IOINIT; | |
862 | } | |
863 | ||
864 | __real_readdir = (struct dirent * (*)(DIR*))dlsym (dlflag, "readdir"); | |
865 | if (__real_readdir == NULL) | |
866 | { | |
867 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT readdir\n"); | |
868 | rc = COL_ERROR_IOINIT; | |
869 | } | |
870 | ||
871 | __real_flock = (int (*)(int, int))dlsym (dlflag, "flock"); | |
872 | if (__real_flock == NULL) | |
873 | { | |
874 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT flock\n"); | |
875 | rc = COL_ERROR_IOINIT; | |
876 | } | |
877 | ||
878 | __real_lockf = (int (*)(int, int, off_t))dlsym (dlflag, "lockf"); | |
879 | if (__real_lockf == NULL) | |
880 | { | |
881 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT lockf\n"); | |
882 | rc = COL_ERROR_IOINIT; | |
883 | } | |
884 | ||
885 | __real_fflush = (int (*)(FILE*))dlsym (dlflag, "fflush"); | |
886 | if (__real_fflush == NULL) | |
887 | { | |
888 | CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fflush\n"); | |
889 | rc = COL_ERROR_IOINIT; | |
890 | } | |
891 | ||
bb368aad VM |
892 | init_io_intf_finished++; |
893 | return rc; | |
894 | } | |
895 | ||
fe39ffdc VM |
896 | static void |
897 | write_io_packet (int fd, ssize_t ret, hrtime_t reqt, int iotype) | |
898 | { | |
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); | |
910 | } | |
911 | ||
bb368aad VM |
912 | /*------------------------------------------------------------- open */ |
913 | int | |
914 | open (const char *path, int oflag, ...) | |
915 | { | |
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; | |
924 | ||
925 | va_start (ap, oflag); | |
926 | mode = va_arg (ap, mode_t); | |
927 | va_end (ap); | |
928 | ||
929 | if (NULL_PTR (open)) | |
930 | init_io_intf (); | |
931 | ||
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)) | |
938 | { | |
939 | POP_REENTRANCE (guard); | |
940 | return fd; | |
941 | } | |
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) | |
949 | { | |
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); | |
965 | } | |
966 | else | |
967 | { | |
968 | Tprintf (0, "iotrace: ERROR: open cannot allocate memory\n"); | |
969 | return -1; | |
970 | } | |
971 | POP_REENTRANCE (guard); | |
972 | return fd; | |
973 | } | |
974 | ||
975 | /*------------------------------------------------------------- open64 */ | |
bb368aad | 976 | static int |
66f76c54 VM |
977 | gprofng_open64 (int(real_open64) (const char *, int, ...), |
978 | const char *path, int oflag, mode_t mode) | |
bb368aad VM |
979 | { |
980 | int *guard; | |
981 | int fd; | |
982 | void *packet; | |
983 | IOTrace_packet *iopkt; | |
984 | size_t sz; | |
985 | unsigned pktSize; | |
bb368aad | 986 | if (CHCK_REENTRANCE (guard) || path == NULL) |
66f76c54 | 987 | return real_open64 (path, oflag, mode); |
bb368aad VM |
988 | PUSH_REENTRANCE (guard); |
989 | hrtime_t reqt = gethrtime (); | |
990 | fd = real_open64 (path, oflag, mode); | |
bb368aad VM |
991 | if (RECHCK_REENTRANCE (guard) || path == NULL) |
992 | { | |
993 | POP_REENTRANCE (guard); | |
994 | return fd; | |
995 | } | |
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) | |
1003 | { | |
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); | |
66f76c54 VM |
1016 | iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, |
1017 | iopkt->comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); | |
bb368aad VM |
1018 | collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt); |
1019 | collector_interface->freeCSize (io_heap, packet, pktSize); | |
1020 | } | |
1021 | else | |
1022 | { | |
1023 | Tprintf (0, "iotrace: ERROR: open64 cannot allocate memory\n"); | |
1024 | return -1; | |
1025 | } | |
1026 | POP_REENTRANCE (guard); | |
1027 | return fd; | |
1028 | } | |
66f76c54 | 1029 | |
35fab451 | 1030 | #define DCL_OPEN64(dcl_f) \ |
66f76c54 VM |
1031 | int dcl_f (const char *path, int oflag, ...) \ |
1032 | { \ | |
35fab451 | 1033 | if (__real_open64 == NULL) \ |
66f76c54 VM |
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); \ | |
35fab451 | 1040 | return gprofng_open64 (__real_open64, path, oflag, mode); \ |
66f76c54 VM |
1041 | } |
1042 | ||
1043 | DCL_FUNC_VER (DCL_OPEN64, open64_2_2, open64@GLIBC_2.2) | |
b5c37946 | 1044 | #if !defined(__USE_LARGEFILE64) |
35fab451 | 1045 | DCL_OPEN64 (open64) |
b5c37946 | 1046 | #endif |
bb368aad VM |
1047 | |
1048 | #define F_ERROR_ARG 0 | |
1049 | #define F_INT_ARG 1 | |
1050 | #define F_LONG_ARG 2 | |
1051 | #define F_VOID_ARG 3 | |
1052 | ||
1053 | /* | |
1054 | * The following macro is not defined in the | |
1055 | * older versions of Linux. | |
1056 | * #define F_DUPFD_CLOEXEC 1030 | |
1057 | * | |
1058 | * Instead use the command that is defined below | |
1059 | * until we start compiling mpmt on the newer | |
1060 | * versions of Linux. | |
1061 | */ | |
1062 | #define TMP_F_DUPFD_CLOEXEC 1030 | |
1063 | ||
1064 | /*------------------------------------------------------------- fcntl */ | |
1065 | int | |
1066 | fcntl (int fildes, int cmd, ...) | |
1067 | { | |
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) | |
1076 | { | |
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; | |
1100 | } | |
1101 | if (NULL_PTR (fcntl)) | |
1102 | init_io_intf (); | |
1103 | if (CHCK_REENTRANCE (guard)) | |
1104 | { | |
1105 | switch (which_arg) | |
1106 | { | |
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; | |
1116 | } | |
1117 | return -1; | |
1118 | } | |
1119 | if (cmd != F_DUPFD && cmd != TMP_F_DUPFD_CLOEXEC) | |
1120 | { | |
1121 | switch (which_arg) | |
1122 | { | |
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; | |
1132 | } | |
1133 | return -1; | |
1134 | } | |
1135 | PUSH_REENTRANCE (guard); | |
1136 | hrtime_t reqt = gethrtime (); | |
1137 | switch (cmd) | |
1138 | { | |
1139 | case F_DUPFD: | |
1140 | case TMP_F_DUPFD_CLOEXEC: | |
1141 | fd = CALL_REAL (fcntl)(fildes, cmd, long_arg); | |
1142 | break; | |
1143 | } | |
1144 | if (RECHCK_REENTRANCE (guard)) | |
1145 | { | |
1146 | POP_REENTRANCE (guard); | |
1147 | return fd; | |
1148 | } | |
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; | |
1165 | } | |
1166 | ||
1167 | /*------------------------------------------------------------- openat */ | |
1168 | int | |
1169 | openat (int fildes, const char *path, int oflag, ...) | |
1170 | { | |
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; | |
1179 | ||
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)) | |
1191 | { | |
1192 | POP_REENTRANCE (guard); | |
1193 | return fd; | |
1194 | } | |
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) | |
1202 | { | |
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); | |
1218 | } | |
1219 | else | |
1220 | { | |
1221 | Tprintf (0, "iotrace: ERROR: openat cannot allocate memory\n"); | |
1222 | return -1; | |
1223 | } | |
1224 | POP_REENTRANCE (guard); | |
1225 | return fd; | |
1226 | } | |
1227 | ||
1228 | /*------------------------------------------------------------- creat */ | |
1229 | int | |
1230 | creat (const char *path, mode_t mode) | |
1231 | { | |
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)) | |
1246 | { | |
1247 | POP_REENTRANCE (guard); | |
1248 | return fd; | |
1249 | } | |
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) | |
1257 | { | |
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); | |
1273 | } | |
1274 | else | |
1275 | { | |
1276 | Tprintf (0, "iotrace: ERROR: creat cannot allocate memory\n"); | |
1277 | return -1; | |
1278 | } | |
1279 | POP_REENTRANCE (guard); | |
1280 | return fd; | |
1281 | } | |
1282 | ||
1283 | /*------------------------------------------------------------- creat64 */ | |
f6f19a39 | 1284 | #if WSIZE(32) && !defined(__USE_LARGEFILE64) |
bb368aad VM |
1285 | int |
1286 | creat64 (const char *path, mode_t mode) | |
1287 | { | |
1288 | int *guard; | |
1289 | int fd; | |
1290 | void *packet; | |
1291 | IOTrace_packet *iopkt; | |
1292 | size_t sz; | |
1293 | unsigned pktSize; | |
1294 | ||
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)) | |
1303 | { | |
1304 | POP_REENTRANCE (guard); | |
1305 | return fd; | |
1306 | } | |
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) | |
1314 | { | |
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); | |
1330 | } | |
1331 | else | |
1332 | { | |
1333 | Tprintf (0, "iotrace: ERROR: creat64 cannot allocate memory\n"); | |
1334 | return -1; | |
1335 | } | |
1336 | POP_REENTRANCE (guard); | |
1337 | return fd; | |
1338 | } | |
1339 | #endif | |
1340 | ||
1341 | /*------------------------------------------------------------- mkstemp */ | |
1342 | int | |
1343 | mkstemp (char *template) | |
1344 | { | |
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) || template == NULL) | |
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)) | |
1359 | { | |
1360 | POP_REENTRANCE (guard); | |
1361 | return fd; | |
1362 | } | |
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) | |
1370 | { | |
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); | |
1386 | } | |
1387 | else | |
1388 | { | |
1389 | Tprintf (0, "iotrace: ERROR: mkstemp cannot allocate memory\n"); | |
1390 | return -1; | |
1391 | } | |
1392 | POP_REENTRANCE (guard); | |
1393 | return fd; | |
1394 | } | |
1395 | ||
1396 | /*------------------------------------------------------------- mkstemps */ | |
1397 | int | |
1398 | mkstemps (char *template, int slen) | |
1399 | { | |
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) || template == NULL) | |
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)) | |
1414 | { | |
1415 | POP_REENTRANCE (guard); | |
1416 | return fd; | |
1417 | } | |
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) | |
1425 | { | |
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); | |
1441 | } | |
1442 | else | |
1443 | { | |
1444 | Tprintf (0, "iotrace: ERROR: mkstemps cannot allocate memory\n"); | |
1445 | return -1; | |
1446 | } | |
1447 | POP_REENTRANCE (guard); | |
1448 | return fd; | |
1449 | } | |
1450 | ||
1451 | /*------------------------------------------------------------- close */ | |
1452 | int | |
1453 | close (int fildes) | |
1454 | { | |
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)) | |
1466 | { | |
1467 | POP_REENTRANCE (guard); | |
1468 | return stat; | |
1469 | } | |
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; | |
1484 | } | |
1485 | ||
1486 | /*------------------------------------------------------------- fopen */ | |
bb368aad | 1487 | static FILE* |
66f76c54 | 1488 | gprofng_fopen (FILE*(real_fopen) (), const char *filename, const char *mode) |
bb368aad | 1489 | { |
bb368aad VM |
1490 | int *guard; |
1491 | FILE *fp = NULL; | |
1492 | void *packet; | |
1493 | IOTrace_packet *iopkt; | |
1494 | size_t sz; | |
1495 | unsigned pktSize; | |
bb368aad | 1496 | if (CHCK_REENTRANCE (guard) || filename == NULL) |
66f76c54 | 1497 | return real_fopen (filename, mode); |
bb368aad VM |
1498 | PUSH_REENTRANCE (guard); |
1499 | hrtime_t reqt = gethrtime (); | |
1500 | ||
66f76c54 | 1501 | fp = real_fopen (filename, mode); |
bb368aad VM |
1502 | if (RECHCK_REENTRANCE (guard)) |
1503 | { | |
1504 | POP_REENTRANCE (guard); | |
1505 | return fp; | |
1506 | } | |
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) | |
1514 | { | |
1515 | iopkt = (IOTrace_packet *) packet; | |
1516 | collector_memset (iopkt, 0, pktSize); | |
1517 | iopkt->comm.tsize = pktSize; | |
1518 | iopkt->comm.tstamp = grnt; | |
1519 | iopkt->requested = reqt; | |
1520 | if (fp != NULL) | |
1521 | { | |
1522 | iopkt->iotype = OPEN_TRACE; | |
1523 | iopkt->fd = fileno (fp); | |
1524 | } | |
1525 | else | |
1526 | { | |
1527 | iopkt->iotype = OPEN_TRACE_ERROR; | |
1528 | iopkt->fd = -1; | |
1529 | } | |
1530 | iopkt->fstype = collector_fstype (filename); | |
1531 | collector_strncpy (&(iopkt->fname), filename, sz); | |
66f76c54 VM |
1532 | iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, |
1533 | iopkt->comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); | |
bb368aad VM |
1534 | collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt); |
1535 | collector_interface->freeCSize (io_heap, packet, pktSize); | |
1536 | } | |
1537 | else | |
1538 | { | |
1539 | Tprintf (0, "iotrace: ERROR: fopen cannot allocate memory\n"); | |
1540 | return NULL; | |
1541 | } | |
1542 | POP_REENTRANCE (guard); | |
1543 | return fp; | |
1544 | } | |
1545 | ||
35fab451 | 1546 | #define DCL_FOPEN(dcl_f) \ |
66f76c54 VM |
1547 | FILE *dcl_f (const char *filename, const char *mode) \ |
1548 | { \ | |
35fab451 | 1549 | if (__real_fopen == NULL) \ |
66f76c54 | 1550 | init_io_intf (); \ |
35fab451 | 1551 | return gprofng_fopen (__real_fopen, filename, mode); \ |
66f76c54 | 1552 | } |
bb368aad | 1553 | |
66f76c54 VM |
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) | |
35fab451 | 1558 | DCL_FOPEN (fopen) |
bb368aad | 1559 | |
66f76c54 | 1560 | /*------------------------------------------------------------- fclose */ |
bb368aad | 1561 | static int |
66f76c54 | 1562 | gprofng_fclose (int(real_fclose) (), FILE *stream) |
bb368aad | 1563 | { |
bb368aad VM |
1564 | int *guard; |
1565 | int stat; | |
1566 | IOTrace_packet iopkt; | |
bb368aad | 1567 | if (CHCK_REENTRANCE (guard) || stream == NULL) |
66f76c54 | 1568 | return real_fclose (stream); |
bb368aad VM |
1569 | PUSH_REENTRANCE (guard); |
1570 | hrtime_t reqt = gethrtime (); | |
66f76c54 | 1571 | stat = real_fclose (stream); |
bb368aad VM |
1572 | if (RECHCK_REENTRANCE (guard)) |
1573 | { | |
1574 | POP_REENTRANCE (guard); | |
1575 | return stat; | |
1576 | } | |
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); | |
66f76c54 VM |
1587 | iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, |
1588 | iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); | |
bb368aad VM |
1589 | collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); |
1590 | POP_REENTRANCE (guard); | |
1591 | return stat; | |
1592 | } | |
1593 | ||
35fab451 | 1594 | #define DCL_FCLOSE(dcl_f) \ |
66f76c54 VM |
1595 | int dcl_f (FILE *stream) \ |
1596 | { \ | |
35fab451 | 1597 | if (__real_fclose == NULL) \ |
66f76c54 | 1598 | init_io_intf (); \ |
35fab451 | 1599 | return gprofng_fclose (__real_fclose, stream); \ |
66f76c54 VM |
1600 | } |
1601 | ||
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) | |
35fab451 | 1606 | DCL_FCLOSE (fclose) |
66f76c54 | 1607 | |
bb368aad VM |
1608 | /*------------------------------------------------------------- fflush */ |
1609 | int | |
1610 | fflush (FILE *stream) | |
1611 | { | |
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)) | |
1623 | { | |
1624 | POP_REENTRANCE (guard); | |
1625 | return stat; | |
1626 | } | |
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; | |
1644 | } | |
1645 | ||
1646 | /*------------------------------------------------------------- fdopen */ | |
bb368aad | 1647 | static FILE* |
66f76c54 | 1648 | gprofng_fdopen (FILE*(real_fdopen) (), int fildes, const char *mode) |
bb368aad | 1649 | { |
bb368aad VM |
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)) | |
66f76c54 | 1656 | return real_fdopen (fildes, mode); |
bb368aad VM |
1657 | PUSH_REENTRANCE (guard); |
1658 | hrtime_t reqt = gethrtime (); | |
66f76c54 | 1659 | fp = real_fdopen (fildes, mode); |
bb368aad VM |
1660 | if (RECHCK_REENTRANCE (guard)) |
1661 | { | |
1662 | POP_REENTRANCE (guard); | |
1663 | return fp; | |
1664 | } | |
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; | |
66f76c54 VM |
1676 | iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, |
1677 | iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); | |
bb368aad VM |
1678 | collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); |
1679 | POP_REENTRANCE (guard); | |
1680 | return fp; | |
1681 | } | |
1682 | ||
35fab451 | 1683 | #define DCL_FDOPEN(dcl_f) \ |
66f76c54 VM |
1684 | FILE *dcl_f (int fildes, const char *mode) \ |
1685 | { \ | |
35fab451 | 1686 | if (__real_fdopen == NULL) \ |
66f76c54 | 1687 | init_io_intf (); \ |
35fab451 | 1688 | return gprofng_fdopen (__real_fdopen, fildes, mode); \ |
66f76c54 VM |
1689 | } |
1690 | ||
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) | |
35fab451 | 1695 | DCL_FDOPEN (fdopen) |
66f76c54 | 1696 | |
bb368aad VM |
1697 | /*------------------------------------------------------------- dup */ |
1698 | int | |
1699 | dup (int fildes) | |
1700 | { | |
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)) | |
1712 | { | |
1713 | POP_REENTRANCE (guard); | |
1714 | return fd; | |
1715 | } | |
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; | |
1725 | ||
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; | |
1733 | } | |
1734 | ||
1735 | /*------------------------------------------------------------- dup2 */ | |
1736 | int | |
1737 | dup2 (int fildes, int fildes2) | |
1738 | { | |
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)) | |
1750 | { | |
1751 | POP_REENTRANCE (guard); | |
1752 | return fd; | |
1753 | } | |
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; | |
1770 | } | |
1771 | ||
1772 | /*------------------------------------------------------------- pipe */ | |
1773 | int | |
1774 | pipe (int fildes[2]) | |
1775 | { | |
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)) | |
1787 | { | |
1788 | POP_REENTRANCE (guard); | |
1789 | return ret; | |
1790 | } | |
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; | |
1818 | } | |
1819 | ||
1820 | /*------------------------------------------------------------- socket */ | |
1821 | int | |
1822 | socket (int domain, int type, int protocol) | |
1823 | { | |
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)) | |
1835 | { | |
1836 | POP_REENTRANCE (guard); | |
1837 | return fd; | |
1838 | } | |
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; | |
1854 | } | |
1855 | ||
1856 | /*------------------------------------------------------------- read */ | |
1857 | ssize_t | |
1858 | read (int fildes, void *buf, size_t nbyte) | |
1859 | { | |
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)) | |
1871 | { | |
1872 | POP_REENTRANCE (guard); | |
1873 | return ret; | |
1874 | } | |
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; | |
1890 | } | |
1891 | ||
1892 | /*------------------------------------------------------------- write */ | |
1893 | ssize_t | |
1894 | write (int fildes, const void *buf, size_t nbyte) | |
1895 | { | |
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)) | |
1907 | { | |
1908 | POP_REENTRANCE (guard); | |
1909 | return ret; | |
1910 | } | |
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; | |
1926 | } | |
1927 | ||
1928 | /*------------------------------------------------------------- readv */ | |
1929 | ssize_t | |
1930 | readv (int fildes, const struct iovec *iov, int iovcnt) | |
1931 | { | |
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)) | |
1943 | { | |
1944 | POP_REENTRANCE (guard); | |
1945 | return ret; | |
1946 | } | |
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; | |
1962 | } | |
1963 | ||
1964 | /*------------------------------------------------------------- writev */ | |
1965 | ssize_t | |
1966 | writev (int fildes, const struct iovec *iov, int iovcnt) | |
1967 | { | |
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)) | |
1979 | { | |
1980 | POP_REENTRANCE (guard); | |
1981 | return ret; | |
1982 | } | |
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; | |
1998 | } | |
1999 | ||
2000 | /*------------------------------------------------------------- fread */ | |
2001 | size_t | |
2002 | fread (void *ptr, size_t size, size_t nitems, FILE *stream) | |
2003 | { | |
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)) | |
2015 | { | |
2016 | POP_REENTRANCE (guard); | |
2017 | return ret; | |
2018 | } | |
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) | |
2025 | { | |
2026 | iopkt.iotype = READ_TRACE; | |
2027 | iopkt.nbyte = ret * size; | |
2028 | } | |
2029 | else | |
2030 | { | |
2031 | iopkt.iotype = READ_TRACE_ERROR; | |
2032 | iopkt.nbyte = 0; | |
2033 | } | |
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; | |
2039 | } | |
2040 | ||
2041 | /*------------------------------------------------------------- fwrite */ | |
2042 | size_t | |
2043 | fwrite (const void *ptr, size_t size, size_t nitems, FILE *stream) | |
2044 | { | |
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)) | |
2056 | { | |
2057 | POP_REENTRANCE (guard); | |
2058 | return ret; | |
2059 | } | |
2060 | hrtime_t grnt = gethrtime (); | |
2061 | collector_memset (&iopkt, 0, sizeof ( IOTrace_packet)); | |
2062 | iopkt.comm.tsize = sizeof ( IOTrace_packet); | |
2063 | iopkt.comm.tstamp = grnt; | |
2064 | iopkt.requested = reqt; | |
2065 | if (ferror (stream) == 0) | |
2066 | { | |
2067 | iopkt.iotype = WRITE_TRACE; | |
2068 | iopkt.nbyte = ret * size; | |
2069 | } | |
2070 | else | |
2071 | { | |
2072 | iopkt.iotype = WRITE_TRACE_ERROR; | |
2073 | iopkt.nbyte = 0; | |
2074 | } | |
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; | |
2080 | } | |
2081 | ||
2082 | /*------------------------------------------------------------- pread */ | |
66f76c54 VM |
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) | |
bb368aad | 2086 | { |
bb368aad VM |
2087 | int *guard; |
2088 | ssize_t ret; | |
2089 | IOTrace_packet iopkt; | |
bb368aad | 2090 | if (CHCK_REENTRANCE (guard)) |
66f76c54 | 2091 | return real_pread (fildes, buf, nbyte, offset); |
bb368aad VM |
2092 | PUSH_REENTRANCE (guard); |
2093 | hrtime_t reqt = gethrtime (); | |
66f76c54 | 2094 | ret = real_pread (fildes, buf, nbyte, offset); |
bb368aad VM |
2095 | if (RECHCK_REENTRANCE (guard)) |
2096 | { | |
2097 | POP_REENTRANCE (guard); | |
2098 | return ret; | |
2099 | } | |
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; | |
66f76c54 VM |
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); | |
bb368aad VM |
2114 | POP_REENTRANCE (guard); |
2115 | return ret; | |
2116 | } | |
2117 | ||
35fab451 | 2118 | #define DCL_PREAD(dcl_f) \ |
66f76c54 VM |
2119 | ssize_t dcl_f (int fildes, void *buf, size_t nbyte, off_t offset) \ |
2120 | { \ | |
35fab451 | 2121 | if (__real_pread == NULL) \ |
66f76c54 | 2122 | init_io_intf (); \ |
35fab451 | 2123 | return gprofng_pread (__real_pread, fildes, buf, nbyte, offset); \ |
66f76c54 VM |
2124 | } |
2125 | ||
2126 | DCL_FUNC_VER (DCL_PREAD, pread_2_2, pread@GLIBC_2.2) | |
35fab451 | 2127 | DCL_PREAD (pread) |
66f76c54 | 2128 | |
bb368aad | 2129 | /*------------------------------------------------------------- pwrite */ |
fe39ffdc | 2130 | |
66f76c54 | 2131 | #if !defined(__MUSL_LIBC) |
bb368aad | 2132 | // map interposed symbol versions |
bb368aad | 2133 | |
9c48ba47 | 2134 | SYMVER_ATTRIBUTE (__collector_pwrite_2_2, pwrite@GLIBC_2.2) |
bb368aad VM |
2135 | int |
2136 | __collector_pwrite_2_2 (int fildes, const void *buf, size_t nbyte, off_t offset) | |
2137 | { | |
fe39ffdc VM |
2138 | int *guard; |
2139 | if (NULL_PTR (pwrite_2_2)) | |
bb368aad | 2140 | init_io_intf (); |
fe39ffdc VM |
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)) | |
2147 | { | |
2148 | POP_REENTRANCE (guard); | |
2149 | return ret; | |
2150 | } | |
2151 | write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR); | |
2152 | POP_REENTRANCE (guard); | |
2153 | return ret; | |
bb368aad VM |
2154 | } |
2155 | ||
f6f19a39 | 2156 | #endif |
bb368aad VM |
2157 | ssize_t |
2158 | pwrite (int fildes, const void *buf, size_t nbyte, off_t offset) | |
2159 | { | |
bb368aad | 2160 | int *guard; |
bb368aad VM |
2161 | if (NULL_PTR (pwrite)) |
2162 | init_io_intf (); | |
2163 | if (CHCK_REENTRANCE (guard)) | |
fe39ffdc | 2164 | return CALL_REAL (pwrite)(fildes, buf, nbyte, offset); |
bb368aad VM |
2165 | PUSH_REENTRANCE (guard); |
2166 | hrtime_t reqt = gethrtime (); | |
fe39ffdc | 2167 | ssize_t ret = CALL_REAL (pwrite)(fildes, buf, nbyte, offset); |
bb368aad VM |
2168 | if (RECHCK_REENTRANCE (guard)) |
2169 | { | |
2170 | POP_REENTRANCE (guard); | |
2171 | return ret; | |
2172 | } | |
fe39ffdc | 2173 | write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR); |
bb368aad VM |
2174 | POP_REENTRANCE (guard); |
2175 | return ret; | |
2176 | } | |
2177 | ||
2178 | /*------------------------------------------------------------- pwrite64 */ | |
66f76c54 | 2179 | #if WSIZE(32) && !defined(__USE_FILE_OFFSET64) |
f6f19a39 | 2180 | #if !defined(__MUSL_LIBC) |
bb368aad | 2181 | // map interposed symbol versions |
bb368aad | 2182 | |
9c48ba47 | 2183 | SYMVER_ATTRIBUTE (__collector_pwrite64_2_2, pwrite64@GLIBC_2.2) |
fe39ffdc | 2184 | ssize_t |
bb368aad VM |
2185 | __collector_pwrite64_2_2 (int fildes, const void *buf, size_t nbyte, off64_t offset) |
2186 | { | |
fe39ffdc VM |
2187 | int *guard; |
2188 | if (NULL_PTR (pwrite64_2_2)) | |
bb368aad | 2189 | init_io_intf (); |
fe39ffdc VM |
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)) | |
2196 | { | |
2197 | POP_REENTRANCE (guard); | |
2198 | return ret; | |
2199 | } | |
2200 | write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR); | |
2201 | POP_REENTRANCE (guard); | |
2202 | return ret; | |
bb368aad | 2203 | } |
f6f19a39 | 2204 | #endif |
bb368aad VM |
2205 | |
2206 | ssize_t | |
2207 | pwrite64 (int fildes, const void *buf, size_t nbyte, off64_t offset) | |
2208 | { | |
bb368aad | 2209 | int *guard; |
bb368aad VM |
2210 | if (NULL_PTR (pwrite64)) |
2211 | init_io_intf (); | |
2212 | if (CHCK_REENTRANCE (guard)) | |
fe39ffdc | 2213 | return CALL_REAL (pwrite64)(fildes, buf, nbyte, offset); |
bb368aad VM |
2214 | PUSH_REENTRANCE (guard); |
2215 | hrtime_t reqt = gethrtime (); | |
fe39ffdc | 2216 | ssize_t ret = CALL_REAL (pwrite64)(fildes, buf, nbyte, offset); |
bb368aad VM |
2217 | if (RECHCK_REENTRANCE (guard)) |
2218 | { | |
2219 | POP_REENTRANCE (guard); | |
2220 | return ret; | |
2221 | } | |
fe39ffdc | 2222 | write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR); |
bb368aad VM |
2223 | POP_REENTRANCE (guard); |
2224 | return ret; | |
2225 | } | |
fe39ffdc | 2226 | #endif |
f6f19a39 | 2227 | |
bb368aad VM |
2228 | /*------------------------------------------------------------- fgets */ |
2229 | char* | |
2230 | fgets (char *s, int n, FILE *stream) | |
2231 | { | |
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)) | |
2243 | { | |
2244 | POP_REENTRANCE (guard); | |
2245 | return ptr; | |
2246 | } | |
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) | |
2254 | { | |
2255 | iopkt.iotype = READ_TRACE; | |
2256 | iopkt.nbyte = collector_strlen (ptr); | |
2257 | } | |
2258 | else if (ptr == NULL && error != EAGAIN && error != EBADF && error != EINTR && | |
2259 | error != EIO && error != EOVERFLOW && error != ENOMEM && error != ENXIO) | |
2260 | { | |
2261 | iopkt.iotype = READ_TRACE; | |
2262 | iopkt.nbyte = 0; | |
2263 | } | |
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; | |
2271 | } | |
2272 | ||
2273 | /*------------------------------------------------------------- fputs */ | |
2274 | int | |
2275 | fputs (const char *s, FILE *stream) | |
2276 | { | |
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)) | |
2288 | { | |
2289 | POP_REENTRANCE (guard); | |
2290 | return ret; | |
2291 | } | |
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) | |
2298 | { | |
2299 | iopkt.iotype = WRITE_TRACE; | |
2300 | iopkt.nbyte = ret; | |
2301 | } | |
2302 | else | |
2303 | { | |
2304 | iopkt.iotype = WRITE_TRACE_ERROR; | |
2305 | iopkt.nbyte = 0; | |
2306 | } | |
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; | |
2312 | } | |
2313 | ||
2314 | /*------------------------------------------------------------- fputc */ | |
2315 | int | |
2316 | fputc (int c, FILE *stream) | |
2317 | { | |
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)) | |
2329 | { | |
2330 | POP_REENTRANCE (guard); | |
2331 | return ret; | |
2332 | } | |
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) | |
2339 | { | |
2340 | iopkt.iotype = WRITE_TRACE; | |
2341 | iopkt.nbyte = ret; | |
2342 | } | |
2343 | else | |
2344 | { | |
2345 | iopkt.iotype = WRITE_TRACE_ERROR; | |
2346 | iopkt.nbyte = 0; | |
2347 | } | |
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; | |
2353 | } | |
2354 | ||
2355 | /*------------------------------------------------------------- fprintf */ | |
2356 | int | |
2357 | fprintf (FILE *stream, const char *format, ...) | |
2358 | { | |
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) | |
309b9a1a VM |
2369 | { |
2370 | ret = CALL_REAL (vfprintf)(stream, format, ap); | |
2371 | va_end (ap); | |
2372 | return ret; | |
2373 | } | |
bb368aad VM |
2374 | PUSH_REENTRANCE (guard); |
2375 | hrtime_t reqt = gethrtime (); | |
2376 | ret = CALL_REAL (vfprintf)(stream, format, ap); | |
309b9a1a | 2377 | va_end (ap); |
bb368aad VM |
2378 | if (RECHCK_REENTRANCE (guard)) |
2379 | { | |
2380 | POP_REENTRANCE (guard); | |
2381 | return ret; | |
2382 | } | |
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; | |
2398 | } | |
2399 | ||
2400 | /*------------------------------------------------------------- vfprintf */ | |
2401 | int | |
2402 | vfprintf (FILE *stream, const char *format, va_list ap) | |
2403 | { | |
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)) | |
2415 | { | |
2416 | POP_REENTRANCE (guard); | |
2417 | return ret; | |
2418 | } | |
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; | |
2434 | } | |
2435 | ||
2436 | /*------------------------------------------------------------- lseek */ | |
2437 | off_t | |
2438 | lseek (int fildes, off_t offset, int whence) | |
2439 | { | |
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)) | |
2451 | { | |
2452 | POP_REENTRANCE (guard); | |
2453 | return ret; | |
2454 | } | |
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; | |
2469 | } | |
2470 | ||
2471 | /*------------------------------------------------------------- llseek */ | |
2472 | offset_t | |
2473 | llseek (int fildes, offset_t offset, int whence) | |
2474 | { | |
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)) | |
2486 | { | |
2487 | POP_REENTRANCE (guard); | |
2488 | return ret; | |
2489 | } | |
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; | |
2504 | } | |
2505 | ||
2506 | /*------------------------------------------------------------- chmod */ | |
2507 | int | |
2508 | chmod (const char *path, mode_t mode) | |
2509 | { | |
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)) | |
2524 | { | |
2525 | POP_REENTRANCE (guard); | |
2526 | return ret; | |
2527 | } | |
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) | |
2535 | { | |
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); | |
2549 | } | |
2550 | else | |
2551 | { | |
2552 | Tprintf (0, "iotrace: ERROR: chmod cannot allocate memory\n"); | |
2553 | return 0; | |
2554 | } | |
2555 | POP_REENTRANCE (guard); | |
2556 | return ret; | |
2557 | } | |
2558 | ||
2559 | /*------------------------------------------------------------- access */ | |
2560 | int | |
2561 | access (const char *path, int amode) | |
2562 | { | |
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)) | |
2577 | { | |
2578 | POP_REENTRANCE (guard); | |
2579 | return ret; | |
2580 | } | |
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) | |
2588 | { | |
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); | |
2602 | } | |
2603 | else | |
2604 | { | |
2605 | Tprintf (0, "iotrace: ERROR: access cannot allocate memory\n"); | |
2606 | return 0; | |
2607 | } | |
2608 | POP_REENTRANCE (guard); | |
2609 | return ret; | |
2610 | } | |
2611 | ||
2612 | /*------------------------------------------------------------- rename */ | |
2613 | int | |
2614 | rename (const char *old, const char *new) | |
2615 | { | |
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)) | |
2630 | { | |
2631 | POP_REENTRANCE (guard); | |
2632 | return ret; | |
2633 | } | |
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) | |
2641 | { | |
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); | |
2655 | } | |
2656 | else | |
2657 | { | |
2658 | Tprintf (0, "iotrace: ERROR: rename cannot allocate memory\n"); | |
2659 | return 0; | |
2660 | } | |
2661 | POP_REENTRANCE (guard); | |
2662 | return ret; | |
2663 | } | |
2664 | ||
2665 | /*------------------------------------------------------------- mkdir */ | |
2666 | int | |
2667 | mkdir (const char *path, mode_t mode) | |
2668 | { | |
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)) | |
2683 | { | |
2684 | POP_REENTRANCE (guard); | |
2685 | return ret; | |
2686 | } | |
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) | |
2694 | { | |
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); | |
2708 | } | |
2709 | else | |
2710 | { | |
2711 | Tprintf (0, "iotrace: ERROR: mkdir cannot allocate memory\n"); | |
2712 | return 0; | |
2713 | } | |
2714 | POP_REENTRANCE (guard); | |
2715 | return ret; | |
2716 | } | |
2717 | ||
2718 | /*------------------------------------------------------------- getdents */ | |
2719 | int | |
2720 | getdents (int fildes, struct dirent *buf, size_t nbyte) | |
2721 | { | |
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)) | |
2733 | { | |
2734 | POP_REENTRANCE (guard); | |
2735 | return ret; | |
2736 | } | |
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; | |
2751 | } | |
2752 | ||
2753 | /*------------------------------------------------------------- unlink */ | |
2754 | int | |
2755 | unlink (const char *path) | |
2756 | { | |
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)) | |
2771 | { | |
2772 | POP_REENTRANCE (guard); | |
2773 | return ret; | |
2774 | } | |
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) | |
2782 | { | |
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); | |
2796 | } | |
2797 | else | |
2798 | { | |
2799 | Tprintf (0, "iotrace: ERROR: unlink cannot allocate memory\n"); | |
2800 | return 0; | |
2801 | } | |
2802 | POP_REENTRANCE (guard); | |
2803 | return ret; | |
2804 | } | |
2805 | ||
2806 | /*------------------------------------------------------------- fseek */ | |
2807 | int | |
2808 | fseek (FILE *stream, long offset, int whence) | |
2809 | { | |
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)) | |
2821 | { | |
2822 | POP_REENTRANCE (guard); | |
2823 | return ret; | |
2824 | } | |
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; | |
2839 | } | |
2840 | ||
2841 | /*------------------------------------------------------------- rewind */ | |
2842 | void | |
2843 | rewind (FILE *stream) | |
2844 | { | |
2845 | int *guard; | |
2846 | IOTrace_packet iopkt; | |
2847 | if (NULL_PTR (rewind)) | |
2848 | init_io_intf (); | |
2849 | if (CHCK_REENTRANCE (guard) || stream == NULL) | |
2850 | { | |
2851 | CALL_REAL (rewind)(stream); | |
2852 | return; | |
2853 | } | |
2854 | PUSH_REENTRANCE (guard); | |
2855 | hrtime_t reqt = gethrtime (); | |
2856 | CALL_REAL (rewind)(stream); | |
2857 | if (RECHCK_REENTRANCE (guard)) | |
2858 | { | |
2859 | POP_REENTRANCE (guard); | |
2860 | return; | |
2861 | } | |
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); | |
2872 | } | |
2873 | ||
2874 | /*------------------------------------------------------------- ftell */ | |
2875 | long | |
2876 | ftell (FILE *stream) | |
2877 | { | |
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)) | |
2889 | { | |
2890 | POP_REENTRANCE (guard); | |
2891 | return ret; | |
2892 | } | |
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; | |
2907 | } | |
2908 | ||
2909 | /*------------------------------------------------------------- fgetpos */ | |
bb368aad | 2910 | static int |
66f76c54 VM |
2911 | gprofng_fgetpos (int(real_fgetpos) (FILE *stream, fpos_t *pos), |
2912 | FILE *stream, fpos_t *pos) | |
bb368aad | 2913 | { |
bb368aad VM |
2914 | int *guard; |
2915 | int ret; | |
2916 | IOTrace_packet iopkt; | |
bb368aad | 2917 | if (CHCK_REENTRANCE (guard) || stream == NULL) |
66f76c54 | 2918 | return real_fgetpos (stream, pos); |
bb368aad VM |
2919 | PUSH_REENTRANCE (guard); |
2920 | hrtime_t reqt = gethrtime (); | |
66f76c54 | 2921 | ret = real_fgetpos (stream, pos); |
bb368aad VM |
2922 | if (RECHCK_REENTRANCE (guard)) |
2923 | { | |
2924 | POP_REENTRANCE (guard); | |
2925 | return ret; | |
2926 | } | |
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); | |
66f76c54 VM |
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); | |
bb368aad VM |
2940 | POP_REENTRANCE (guard); |
2941 | return ret; | |
2942 | } | |
2943 | ||
35fab451 | 2944 | #define DCL_FGETPOS(dcl_f) \ |
66f76c54 VM |
2945 | int dcl_f (FILE *stream, fpos_t *pos) \ |
2946 | { \ | |
35fab451 | 2947 | if (__real_fgetpos == NULL) \ |
66f76c54 | 2948 | init_io_intf (); \ |
35fab451 | 2949 | return gprofng_fgetpos (__real_fgetpos, stream, pos); \ |
66f76c54 | 2950 | } |
bb368aad | 2951 | |
66f76c54 VM |
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) | |
35fab451 | 2956 | DCL_FGETPOS (fgetpos) |
bb368aad | 2957 | |
66f76c54 | 2958 | /*------------------------------------------------------------- fgetpos64 */ |
bb368aad | 2959 | static int |
66f76c54 | 2960 | gprofng_fgetpos64 (int(real_fgetpos64) (), FILE *stream, fpos64_t *pos) |
bb368aad | 2961 | { |
bb368aad VM |
2962 | int *guard; |
2963 | int ret; | |
2964 | IOTrace_packet iopkt; | |
bb368aad | 2965 | if (CHCK_REENTRANCE (guard) || stream == NULL) |
66f76c54 | 2966 | return real_fgetpos64 (stream, pos); |
bb368aad VM |
2967 | PUSH_REENTRANCE (guard); |
2968 | hrtime_t reqt = gethrtime (); | |
66f76c54 | 2969 | ret = real_fgetpos64 (stream, pos); |
bb368aad VM |
2970 | if (RECHCK_REENTRANCE (guard)) |
2971 | { | |
2972 | POP_REENTRANCE (guard); | |
2973 | return ret; | |
2974 | } | |
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); | |
66f76c54 VM |
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); | |
bb368aad VM |
2988 | POP_REENTRANCE (guard); |
2989 | return ret; | |
2990 | } | |
bb368aad | 2991 | |
35fab451 | 2992 | #define DCL_FGETPOS64(dcl_f) \ |
66f76c54 VM |
2993 | int dcl_f (FILE *stream, fpos64_t *pos) \ |
2994 | { \ | |
35fab451 | 2995 | if (__real_fgetpos64 == NULL) \ |
66f76c54 | 2996 | init_io_intf (); \ |
35fab451 | 2997 | return gprofng_fgetpos64 (__real_fgetpos64, stream, pos); \ |
66f76c54 | 2998 | } |
bb368aad | 2999 | |
66f76c54 VM |
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) | |
b5c37946 | 3004 | #if !defined(__USE_LARGEFILE64) |
35fab451 | 3005 | DCL_FGETPOS64 (fgetpos64) |
b5c37946 | 3006 | #endif |
66f76c54 | 3007 | /*------------------------------------------------------------- fsetpos */ |
bb368aad | 3008 | static int |
66f76c54 VM |
3009 | gprofng_fsetpos (int(real_fsetpos) (FILE *, const fpos_t *), |
3010 | FILE *stream, const fpos_t *pos) | |
bb368aad | 3011 | { |
bb368aad VM |
3012 | int *guard; |
3013 | int ret; | |
3014 | IOTrace_packet iopkt; | |
bb368aad | 3015 | if (CHCK_REENTRANCE (guard) || stream == NULL) |
66f76c54 | 3016 | return real_fsetpos (stream, pos); |
bb368aad VM |
3017 | PUSH_REENTRANCE (guard); |
3018 | hrtime_t reqt = gethrtime (); | |
66f76c54 | 3019 | ret = real_fsetpos (stream, pos); |
bb368aad VM |
3020 | if (RECHCK_REENTRANCE (guard)) |
3021 | { | |
3022 | POP_REENTRANCE (guard); | |
3023 | return ret; | |
3024 | } | |
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); | |
66f76c54 VM |
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); | |
bb368aad VM |
3038 | POP_REENTRANCE (guard); |
3039 | return ret; | |
3040 | } | |
3041 | ||
35fab451 | 3042 | #define DCL_FSETPOS(dcl_f) \ |
66f76c54 VM |
3043 | int dcl_f (FILE *stream, const fpos_t *pos) \ |
3044 | { \ | |
35fab451 | 3045 | if (__real_fsetpos == NULL) \ |
66f76c54 | 3046 | init_io_intf (); \ |
35fab451 | 3047 | return gprofng_fsetpos (__real_fsetpos, stream, pos); \ |
66f76c54 | 3048 | } |
bb368aad | 3049 | |
66f76c54 VM |
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) | |
35fab451 | 3054 | DCL_FSETPOS (fsetpos) |
bb368aad | 3055 | |
66f76c54 | 3056 | /*------------------------------------------------------------- fsetpos64 */ |
bb368aad | 3057 | static int |
66f76c54 VM |
3058 | gprofng_fsetpos64 (int(real_fsetpos64) (FILE *, const fpos64_t *), |
3059 | FILE *stream, const fpos64_t *pos) | |
bb368aad | 3060 | { |
bb368aad VM |
3061 | int *guard; |
3062 | int ret; | |
3063 | IOTrace_packet iopkt; | |
bb368aad | 3064 | if (CHCK_REENTRANCE (guard) || stream == NULL) |
66f76c54 | 3065 | return real_fsetpos64 (stream, pos); |
bb368aad VM |
3066 | PUSH_REENTRANCE (guard); |
3067 | hrtime_t reqt = gethrtime (); | |
66f76c54 | 3068 | ret = real_fsetpos64 (stream, pos); |
bb368aad VM |
3069 | if (RECHCK_REENTRANCE (guard)) |
3070 | { | |
3071 | POP_REENTRANCE (guard); | |
3072 | return ret; | |
3073 | } | |
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); | |
66f76c54 VM |
3084 | iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, |
3085 | iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); | |
bb368aad VM |
3086 | collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); |
3087 | POP_REENTRANCE (guard); | |
3088 | return ret; | |
3089 | } | |
66f76c54 | 3090 | |
35fab451 | 3091 | #define DCL_FSETPOS64(dcl_f) \ |
66f76c54 VM |
3092 | int dcl_f (FILE *stream, const fpos64_t *pos) \ |
3093 | { \ | |
35fab451 | 3094 | if (__real_fsetpos64 == NULL) \ |
66f76c54 | 3095 | init_io_intf (); \ |
35fab451 | 3096 | return gprofng_fsetpos64 (__real_fsetpos64, stream, pos); \ |
66f76c54 VM |
3097 | } |
3098 | ||
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) | |
b5c37946 | 3103 | #if !defined(__USE_LARGEFILE64) |
35fab451 | 3104 | DCL_FSETPOS64 (fsetpos64) |
b5c37946 | 3105 | #endif |
bb368aad VM |
3106 | /*------------------------------------------------------------- fsync */ |
3107 | int | |
3108 | fsync (int fildes) | |
3109 | { | |
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)) | |
3121 | { | |
3122 | POP_REENTRANCE (guard); | |
3123 | return ret; | |
3124 | } | |
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; | |
3139 | } | |
3140 | ||
3141 | /*------------------------------------------------------------- readdir */ | |
3142 | struct dirent* | |
3143 | readdir (DIR *dirp) | |
3144 | { | |
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)) | |
3156 | { | |
3157 | POP_REENTRANCE (guard); | |
3158 | return ptr; | |
3159 | } | |
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; | |
3173 | } | |
3174 | ||
3175 | /*------------------------------------------------------------- flock */ | |
3176 | int | |
3177 | flock (int fd, int operation) | |
3178 | { | |
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)) | |
3190 | { | |
3191 | POP_REENTRANCE (guard); | |
3192 | return ret; | |
3193 | } | |
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; | |
3208 | } | |
3209 | ||
3210 | /*------------------------------------------------------------- lockf */ | |
3211 | int | |
3212 | lockf (int fildes, int function, off_t size) | |
3213 | { | |
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)) | |
3225 | { | |
3226 | POP_REENTRANCE (guard); | |
3227 | return ret; | |
3228 | } | |
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; | |
3243 | } |