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