123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717 |
- /* Copyright (C) 2021 Free Software Foundation, Inc.
- Contributed by Oracle.
- This file is part of GNU Binutils.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, 51 Franklin Street - Fifth Floor, Boston,
- MA 02110-1301, USA. */
- /*
- * IO events
- */
- #include "config.h"
- #include <dlfcn.h>
- #include <errno.h>
- #include <stdarg.h>
- #include <stdlib.h>
- // create() and others are defined in fcntl.h.
- // Our 'create' should not have the __nonnull attribute
- #undef __nonnull
- #define __nonnull(x)
- #include <fcntl.h>
- #include "gp-defs.h"
- #include "collector_module.h"
- #include "gp-experiment.h"
- #include "data_pckts.h"
- #include "tsd.h"
- /* TprintfT(<level>,...) definitions. Adjust per module as needed */
- #define DBG_LT0 0 // for high-level configuration, unexpected errors/warnings
- #define DBG_LTT 0 // for interposition on GLIBC functions
- #define DBG_LT1 1 // for configuration details, warnings
- #define DBG_LT2 2
- #define DBG_LT3 3
- /* define the packet that will be written out */
- typedef struct IOTrace_packet
- { /* IO tracing packet */
- Common_packet comm;
- IOTrace_type iotype; /* IO type */
- int32_t fd; /* file descriptor */
- Size_type nbyte; /* number of bytes */
- hrtime_t requested; /* time of IO requested */
- int32_t ofd; /* original file descriptor */
- FileSystem_type fstype; /* file system type */
- char fname; /* file name */
- } IOTrace_packet;
- typedef long long offset_t;
- static int open_experiment (const char *);
- static int start_data_collection (void);
- static int stop_data_collection (void);
- static int close_experiment (void);
- static int detach_experiment (void);
- static int init_io_intf ();
- static ModuleInterface module_interface ={
- SP_IOTRACE_FILE, /* description */
- NULL, /* initInterface */
- open_experiment, /* openExperiment */
- start_data_collection, /* startDataCollection */
- stop_data_collection, /* stopDataCollection */
- close_experiment, /* closeExperiment */
- detach_experiment /* detachExperiment (fork child) */
- };
- static CollectorInterface *collector_interface = NULL;
- static struct Heap *io_heap = NULL;
- static int io_mode = 0;
- static CollectorModule io_hndl = COLLECTOR_MODULE_ERR;
- static unsigned io_key = COLLECTOR_TSD_INVALID_KEY;
- #define CHCK_REENTRANCE(x) (!io_mode || ((x) = collector_interface->getKey( io_key )) == NULL || (*(x) != 0))
- #define RECHCK_REENTRANCE(x) (!io_mode || ((x) = collector_interface->getKey( io_key )) == NULL || (*(x) == 0))
- #define PUSH_REENTRANCE(x) ((*(x))++)
- #define POP_REENTRANCE(x) ((*(x))--)
- #define CALL_REAL(x) (__real_##x)
- #define NULL_PTR(x) (__real_##x == NULL)
- #define gethrtime collector_interface->getHiResTime
- #ifdef DEBUG
- #define Tprintf(...) if (collector_interface) collector_interface->writeDebugInfo( 0, __VA_ARGS__ )
- #define TprintfT(...) if (collector_interface) collector_interface->writeDebugInfo( 1, __VA_ARGS__ )
- #else
- #define Tprintf(...)
- #define TprintfT(...)
- #endif
- /* interposition function handles */
- static int (*__real_open)(const char *path, int oflag, ...) = NULL;
- static int (*__real_fcntl)(int fildes, int cmd, ...) = NULL;
- static int (*__real_openat)(int fildes, const char *path, int oflag, ...) = NULL;
- static int (*__real_close)(int fildes) = NULL;
- static FILE *(*__real_fopen)(const char *filename, const char *mode) = NULL;
- static int (*__real_fclose)(FILE *stream) = NULL;
- static int (*__real_dup)(int fildes) = NULL;
- static int (*__real_dup2)(int fildes, int fildes2) = NULL;
- static int (*__real_pipe)(int fildes[2]) = NULL;
- static int (*__real_socket)(int domain, int type, int protocol) = NULL;
- static int (*__real_mkstemp)(char *template) = NULL;
- static int (*__real_mkstemps)(char *template, int slen) = NULL;
- static int (*__real_creat)(const char *path, mode_t mode) = NULL;
- static FILE *(*__real_fdopen)(int fildes, const char *mode) = NULL;
- static ssize_t (*__real_read)(int fildes, void *buf, size_t nbyte) = NULL;
- static ssize_t (*__real_write)(int fildes, const void *buf, size_t nbyte) = NULL;
- static ssize_t (*__real_readv)(int fildes, const struct iovec *iov, int iovcnt) = NULL;
- static ssize_t (*__real_writev)(int fildes, const struct iovec *iov, int iovcnt) = NULL;
- static size_t (*__real_fread)(void *ptr, size_t size, size_t nitems, FILE *stream) = NULL;
- static size_t (*__real_fwrite)(const void *ptr, size_t size, size_t nitems, FILE *stream) = NULL;
- static ssize_t (*__real_pread)(int fildes, void *buf, size_t nbyte, off_t offset) = NULL;
- static ssize_t (*__real_pwrite)(int fildes, const void *buf, size_t nbyte, off_t offset) = NULL;
- static ssize_t (*__real_pwrite64)(int fildes, const void *buf, size_t nbyte, off64_t offset) = NULL;
- static char *(*__real_fgets)(char *s, int n, FILE *stream) = NULL;
- static int (*__real_fputs)(const char *s, FILE *stream) = NULL;
- static int (*__real_fputc)(int c, FILE *stream) = NULL;
- static int (*__real_fprintf)(FILE *stream, const char *format, ...) = NULL;
- static int (*__real_vfprintf)(FILE *stream, const char *format, va_list ap) = NULL;
- static off_t (*__real_lseek)(int fildes, off_t offset, int whence) = NULL;
- static offset_t (*__real_llseek)(int fildes, offset_t offset, int whence) = NULL;
- static int (*__real_chmod)(const char *path, mode_t mode) = NULL;
- static int (*__real_access)(const char *path, int amode) = NULL;
- static int (*__real_rename)(const char *old, const char *new) = NULL;
- static int (*__real_mkdir)(const char *path, mode_t mode) = NULL;
- static int (*__real_getdents)(int fildes, struct dirent *buf, size_t nbyte) = NULL;
- static int (*__real_unlink)(const char *path) = NULL;
- static int (*__real_fseek)(FILE *stream, long offset, int whence) = NULL;
- static void (*__real_rewind)(FILE *stream) = NULL;
- static long (*__real_ftell)(FILE *stream) = NULL;
- static int (*__real_fgetpos)(FILE *stream, fpos_t *pos) = NULL;
- static int (*__real_fsetpos)(FILE *stream, const fpos_t *pos) = NULL;
- static int (*__real_fsync)(int fildes) = NULL;
- static struct dirent *(*__real_readdir)(DIR *dirp) = NULL;
- static int (*__real_flock)(int fd, int operation) = NULL;
- static int (*__real_lockf)(int fildes, int function, off_t size) = NULL;
- static int (*__real_fflush)(FILE *stream) = NULL;
- #if WSIZE(32)
- static int (*__real_open64)(const char *path, int oflag, ...) = NULL;
- static int (*__real_creat64)(const char *path, mode_t mode) = NULL;
- static int (*__real_fgetpos64)(FILE *stream, fpos64_t *pos) = NULL;
- static int (*__real_fsetpos64)(FILE *stream, const fpos64_t *pos) = NULL;
- #if ARCH(Intel)
- static FILE *(*__real_fopen_2_1)(const char *filename, const char *mode) = NULL;
- static int (*__real_fclose_2_1)(FILE *stream) = NULL;
- static FILE *(*__real_fdopen_2_1)(int fildes, const char *mode) = NULL;
- static int (*__real_fgetpos_2_2)(FILE *stream, fpos_t *pos) = NULL;
- static int (*__real_fsetpos_2_2)(FILE *stream, const fpos_t *pos) = NULL;
- static int (*__real_fgetpos64_2_2)(FILE *stream, fpos64_t *pos) = NULL;
- static int (*__real_fsetpos64_2_2)(FILE *stream, const fpos64_t *pos) = NULL;
- static int (*__real_open64_2_2)(const char *path, int oflag, ...) = NULL;
- static ssize_t (*__real_pread_2_2)(int fildes, void *buf, size_t nbyte, off_t offset) = NULL;
- static ssize_t (*__real_pwrite_2_2)(int fildes, const void *buf, size_t nbyte, off_t offset) = NULL;
- static ssize_t (*__real_pwrite64_2_2)(int fildes, const void *buf, size_t nbyte, off64_t offset) = NULL;
- static FILE *(*__real_fopen_2_0)(const char *filename, const char *mode) = NULL;
- static int (*__real_fclose_2_0)(FILE *stream) = NULL;
- static FILE *(*__real_fdopen_2_0)(int fildes, const char *mode) = NULL;
- static int (*__real_fgetpos_2_0)(FILE *stream, fpos_t *pos) = NULL;
- static int (*__real_fsetpos_2_0)(FILE *stream, const fpos_t *pos) = NULL;
- static int (*__real_fgetpos64_2_1)(FILE *stream, fpos64_t *pos) = NULL;
- static int (*__real_fsetpos64_2_1)(FILE *stream, const fpos64_t *pos) = NULL;
- static int (*__real_open64_2_1)(const char *path, int oflag, ...) = NULL;
- static ssize_t (*__real_pread_2_1)(int fildes, void *buf, size_t nbyte, off_t offset) = NULL;
- static ssize_t (*__real_pwrite_2_1)(int fildes, const void *buf, size_t nbyte, off_t offset) = NULL;
- static ssize_t (*__real_pwrite64_2_1)(int fildes, const void *buf, size_t nbyte, off64_t offset) = NULL;
- #endif /* ARCH() */
- #endif /* WSIZE(32) */
- static int
- collector_align_pktsize (int sz)
- {
- int pktSize = sz;
- if (sz <= 0)
- return sz;
- if ((sz % 8) != 0)
- {
- pktSize = (sz / 8) + 1;
- pktSize *= 8;
- }
- return pktSize;
- }
- static void
- collector_memset (void *s, int c, size_t n)
- {
- unsigned char *s1 = s;
- while (n--)
- *s1++ = (unsigned char) c;
- }
- static size_t
- collector_strlen (const char *s)
- {
- if (s == NULL)
- return 0;
- int len = -1;
- while (s[++len] != '\0')
- ;
- return len;
- }
- static size_t
- collector_strncpy (char *dst, const char *src, size_t dstsize)
- {
- size_t i;
- for (i = 0; i < dstsize; i++)
- {
- dst[i] = src[i];
- if (src[i] == '\0')
- break;
- }
- return i;
- }
- static char *
- collector_strchr (const char *s, int c)
- {
- do
- {
- if (*s == (char) c)
- return ((char *) s);
- }
- while (*s++);
- return (NULL);
- }
- static FileSystem_type
- collector_fstype (const char *path)
- {
- return UNKNOWNFS_TYPE;
- }
- void
- __collector_module_init (CollectorInterface *_collector_interface)
- {
- if (_collector_interface == NULL)
- return;
- collector_interface = _collector_interface;
- Tprintf (0, "iotrace: __collector_module_init\n");
- io_hndl = collector_interface->registerModule (&module_interface);
- /* Initialize next module */
- ModuleInitFunc next_init = (ModuleInitFunc) dlsym (RTLD_NEXT, "__collector_module_init");
- if (next_init != NULL)
- next_init (_collector_interface);
- return;
- }
- static int
- open_experiment (const char *exp)
- {
- if (collector_interface == NULL)
- {
- Tprintf (0, "iotrace: collector_interface is null.\n");
- return COL_ERROR_IOINIT;
- }
- if (io_hndl == COLLECTOR_MODULE_ERR)
- {
- Tprintf (0, "iotrace: handle create failed.\n");
- collector_interface->writeLog ("<event kind=\"%s\" id=\"%d\">data handle not created</event>\n",
- SP_JCMD_CERROR, COL_ERROR_IOINIT);
- return COL_ERROR_IOINIT;
- }
- TprintfT (0, "iotrace: open_experiment %s\n", exp);
- if (NULL_PTR (fopen))
- init_io_intf ();
- if (io_heap == NULL)
- {
- io_heap = collector_interface->newHeap ();
- if (io_heap == NULL)
- {
- Tprintf (0, "iotrace: new heap failed.\n");
- collector_interface->writeLog ("<event kind=\"%s\" id=\"%d\">new iotrace heap not created</event>\n",
- SP_JCMD_CERROR, COL_ERROR_IOINIT);
- return COL_ERROR_IOINIT;
- }
- }
- const char *params = collector_interface->getParams ();
- while (params)
- {
- if ((params[0] == 'i') && (params[1] == ':'))
- {
- params += 2;
- break;
- }
- params = collector_strchr (params, ';');
- if (params)
- params++;
- }
- if (params == NULL) /* IO data collection not specified */
- return COL_ERROR_IOINIT;
- io_key = collector_interface->createKey (sizeof ( int), NULL, NULL);
- if (io_key == (unsigned) - 1)
- {
- Tprintf (0, "iotrace: TSD key create failed.\n");
- collector_interface->writeLog ("<event kind=\"%s\" id=\"%d\">TSD key not created</event>\n",
- SP_JCMD_CERROR, COL_ERROR_IOINIT);
- return COL_ERROR_IOINIT;
- }
- collector_interface->writeLog ("<profile name=\"%s\">\n", SP_JCMD_IOTRACE);
- collector_interface->writeLog (" <profdata fname=\"%s\"/>\n",
- module_interface.description);
- /* Record IOTrace_packet description */
- IOTrace_packet *pp = NULL;
- collector_interface->writeLog (" <profpckt kind=\"%d\" uname=\"IO tracing data\">\n", IOTRACE_PCKT);
- collector_interface->writeLog (" <field name=\"LWPID\" uname=\"Lightweight process id\" offset=\"%d\" type=\"%s\"/>\n",
- &pp->comm.lwp_id, sizeof (pp->comm.lwp_id) == 4 ? "INT32" : "INT64");
- collector_interface->writeLog (" <field name=\"THRID\" uname=\"Thread number\" offset=\"%d\" type=\"%s\"/>\n",
- &pp->comm.thr_id, sizeof (pp->comm.thr_id) == 4 ? "INT32" : "INT64");
- collector_interface->writeLog (" <field name=\"CPUID\" uname=\"CPU id\" offset=\"%d\" type=\"%s\"/>\n",
- &pp->comm.cpu_id, sizeof (pp->comm.cpu_id) == 4 ? "INT32" : "INT64");
- collector_interface->writeLog (" <field name=\"TSTAMP\" uname=\"High resolution timestamp\" offset=\"%d\" type=\"%s\"/>\n",
- &pp->comm.tstamp, sizeof (pp->comm.tstamp) == 4 ? "INT32" : "INT64");
- collector_interface->writeLog (" <field name=\"FRINFO\" offset=\"%d\" type=\"%s\"/>\n",
- &pp->comm.frinfo, sizeof (pp->comm.frinfo) == 4 ? "INT32" : "INT64");
- collector_interface->writeLog (" <field name=\"IOTYPE\" uname=\"IO trace function type\" offset=\"%d\" type=\"%s\"/>\n",
- &pp->iotype, sizeof (pp->iotype) == 4 ? "INT32" : "INT64");
- collector_interface->writeLog (" <field name=\"IOFD\" uname=\"File descriptor\" offset=\"%d\" type=\"%s\"/>\n",
- &pp->fd, sizeof (pp->fd) == 4 ? "INT32" : "INT64");
- collector_interface->writeLog (" <field name=\"IONBYTE\" uname=\"Number of bytes\" offset=\"%d\" type=\"%s\"/>\n",
- &pp->nbyte, sizeof (pp->nbyte) == 4 ? "INT32" : "INT64");
- collector_interface->writeLog (" <field name=\"IORQST\" uname=\"Time of IO requested\" offset=\"%d\" type=\"%s\"/>\n",
- &pp->requested, sizeof (pp->requested) == 4 ? "INT32" : "INT64");
- collector_interface->writeLog (" <field name=\"IOOFD\" uname=\"Original file descriptor\" offset=\"%d\" type=\"%s\"/>\n",
- &pp->ofd, sizeof (pp->ofd) == 4 ? "INT32" : "INT64");
- collector_interface->writeLog (" <field name=\"IOFSTYPE\" uname=\"File system type\" offset=\"%d\" type=\"%s\"/>\n",
- &pp->fstype, sizeof (pp->fstype) == 4 ? "INT32" : "INT64");
- collector_interface->writeLog (" <field name=\"IOFNAME\" uname=\"File name\" offset=\"%d\" type=\"%s\"/>\n",
- &pp->fname, "STRING");
- collector_interface->writeLog (" </profpckt>\n");
- collector_interface->writeLog ("</profile>\n");
- return COL_ERROR_NONE;
- }
- static int
- start_data_collection (void)
- {
- io_mode = 1;
- Tprintf (0, "iotrace: start_data_collection\n");
- return 0;
- }
- static int
- stop_data_collection (void)
- {
- io_mode = 0;
- Tprintf (0, "iotrace: stop_data_collection\n");
- return 0;
- }
- static int
- close_experiment (void)
- {
- io_mode = 0;
- io_key = COLLECTOR_TSD_INVALID_KEY;
- if (io_heap != NULL)
- {
- collector_interface->deleteHeap (io_heap);
- io_heap = NULL;
- }
- Tprintf (0, "iotrace: close_experiment\n");
- return 0;
- }
- static int
- detach_experiment (void)
- {
- /* fork child. Clean up state but don't write to experiment */
- io_mode = 0;
- io_key = COLLECTOR_TSD_INVALID_KEY;
- if (io_heap != NULL)
- {
- collector_interface->deleteHeap (io_heap);
- io_heap = NULL;
- }
- Tprintf (0, "iotrace: detach_experiment\n");
- return 0;
- }
- static int
- init_io_intf ()
- {
- void *dlflag;
- int rc = 0;
- /* if we detect recursion/reentrance, SEGV so we can get a stack */
- static int init_io_intf_started;
- static int init_io_intf_finished;
- init_io_intf_started++;
- if (!init_io_intf_finished && init_io_intf_started >= 3)
- {
- /* pull the plug if recursion occurs... */
- abort ();
- }
- /* lookup fprint to print fatal error message */
- void *ptr = dlsym (RTLD_NEXT, "fprintf");
- if (ptr)
- __real_fprintf = (int (*)(FILE*, const char*, ...)) ptr;
- else
- abort ();
- #if ARCH(Intel)
- #if WSIZE(32)
- #define SYS_FOPEN_X_VERSION "GLIBC_2.1"
- #define SYS_FGETPOS_X_VERSION "GLIBC_2.2"
- #define SYS_FGETPOS64_X_VERSION "GLIBC_2.2"
- #define SYS_OPEN64_X_VERSION "GLIBC_2.2"
- #define SYS_PREAD_X_VERSION "GLIBC_2.2"
- #define SYS_PWRITE_X_VERSION "GLIBC_2.2"
- #define SYS_PWRITE64_X_VERSION "GLIBC_2.2"
- #else /* WSIZE(64) */
- #define SYS_FOPEN_X_VERSION "GLIBC_2.2.5"
- #define SYS_FGETPOS_X_VERSION "GLIBC_2.2.5"
- #endif
- #elif ARCH(SPARC)
- #if WSIZE(32)
- #define SYS_FOPEN_X_VERSION "GLIBC_2.1"
- #define SYS_FGETPOS_X_VERSION "GLIBC_2.2"
- #else /* WSIZE(64) */
- #define SYS_FOPEN_X_VERSION "GLIBC_2.2"
- #define SYS_FGETPOS_X_VERSION "GLIBC_2.2"
- #endif
- #elif ARCH(Aarch64)
- #define SYS_FOPEN_X_VERSION "GLIBC_2.17"
- #define SYS_FGETPOS_X_VERSION "GLIBC_2.17"
- #endif /* ARCH() */
- #if WSIZE(32)
- dlflag = RTLD_NEXT;
- __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (dlflag, "fopen", SYS_FOPEN_X_VERSION);
- if (__real_fopen == NULL)
- {
- /* We are probably dlopened after libc,
- * try to search in the previously loaded objects
- */
- __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (RTLD_DEFAULT, "fopen", SYS_FOPEN_X_VERSION);
- if (__real_fopen != NULL)
- {
- Tprintf (0, "iotrace: WARNING: init_io_intf() using RTLD_DEFAULT for Linux io routines\n");
- dlflag = RTLD_DEFAULT;
- }
- else
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen\n");
- rc = COL_ERROR_IOINIT;
- }
- }
- __real_fclose = (int (*)(FILE*))dlvsym (dlflag, "fclose", SYS_FOPEN_X_VERSION);
- if (__real_fclose == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fdopen = (FILE * (*)(int, const char*))dlvsym (dlflag, "fdopen", SYS_FOPEN_X_VERSION);
- if (__real_fdopen == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fgetpos = (int (*)(FILE*, fpos_t*))dlvsym (dlflag, "fgetpos", SYS_FGETPOS_X_VERSION);
- if (__real_fgetpos == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fsetpos = (int (*)(FILE*, const fpos_t*))dlvsym (dlflag, "fsetpos", SYS_FGETPOS_X_VERSION);
- if (__real_fsetpos == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos\n");
- rc = COL_ERROR_IOINIT;
- }
- #if ARCH(Intel)
- __real_fopen_2_1 = __real_fopen;
- __real_fclose_2_1 = __real_fclose;
- __real_fdopen_2_1 = __real_fdopen;
- __real_fgetpos_2_2 = __real_fgetpos;
- __real_fsetpos_2_2 = __real_fsetpos;
- __real_fopen_2_0 = (FILE * (*)(const char*, const char*))dlvsym (dlflag, "fopen", "GLIBC_2.0");
- if (__real_fopen_2_0 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen_2_0\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fclose_2_0 = (int (*)(FILE*))dlvsym (dlflag, "fclose", "GLIBC_2.0");
- if (__real_fclose_2_0 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose_2_0\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fdopen_2_0 = (FILE * (*)(int, const char*))dlvsym (dlflag, "fdopen", "GLIBC_2.0");
- if (__real_fdopen_2_0 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen_2_0\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fgetpos_2_0 = (int (*)(FILE*, fpos_t*))dlvsym (dlflag, "fgetpos", "GLIBC_2.0");
- if (__real_fgetpos_2_0 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos_2_0\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fsetpos_2_0 = (int (*)(FILE*, const fpos_t*))dlvsym (dlflag, "fsetpos", "GLIBC_2.0");
- if (__real_fsetpos_2_0 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos_2_0\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fgetpos64_2_1 = (int (*)(FILE*, fpos64_t*))dlvsym (dlflag, "fgetpos64", "GLIBC_2.1");
- if (__real_fgetpos64_2_1 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos64_2_1\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fsetpos64_2_1 = (int (*)(FILE*, const fpos64_t*))dlvsym (dlflag, "fsetpos64", "GLIBC_2.1");
- if (__real_fsetpos64_2_1 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos64_2_1\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_open64_2_1 = (int (*)(const char*, int, ...))dlvsym (dlflag, "open64", "GLIBC_2.1");
- if (__real_open64_2_1 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open64_2_1\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_pread_2_1 = (int (*)(int fildes, void *buf, size_t nbyte, off_t offset))dlvsym (dlflag, "pread", "GLIBC_2.1");
- if (__real_pread_2_1 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread_2_1\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_pwrite_2_1 = (int (*)(int fildes, const void *buf, size_t nbyte, off_t offset))dlvsym (dlflag, "pwrite", "GLIBC_2.1");
- if (__real_pwrite_2_1 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite_2_1\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_pwrite64_2_1 = (int (*)(int fildes, const void *buf, size_t nbyte, off64_t offset))dlvsym (dlflag, "pwrite64", "GLIBC_2.1");
- if (__real_pwrite64_2_1 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite64_2_1\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fgetpos64_2_2 = (int (*)(FILE*, fpos64_t*))dlvsym (dlflag, "fgetpos64", SYS_FGETPOS64_X_VERSION);
- if (__real_fgetpos64_2_2 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos64_2_2\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fsetpos64_2_2 = (int (*)(FILE*, const fpos64_t*))dlvsym (dlflag, "fsetpos64", SYS_FGETPOS64_X_VERSION);
- if (__real_fsetpos64_2_2 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos64_2_2\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_open64_2_2 = (int (*)(const char*, int, ...))dlvsym (dlflag, "open64", SYS_OPEN64_X_VERSION);
- if (__real_open64_2_2 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open64_2_2\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_pread_2_2 = (int (*)(int fildes, void *buf, size_t nbyte, off_t offset))dlvsym (dlflag, "pread", SYS_PREAD_X_VERSION);
- if (__real_pread_2_2 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread_2_2\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_pwrite_2_2 = (int (*)(int fildes, const void *buf, size_t nbyte, off_t offset))dlvsym (dlflag, "pwrite", SYS_PWRITE_X_VERSION);
- if (__real_pwrite_2_2 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite_2_2\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_pwrite64_2_2 = (int (*)(int fildes, const void *buf, size_t nbyte, off64_t offset))dlvsym (dlflag, "pwrite64", SYS_PWRITE64_X_VERSION);
- if (__real_pwrite64_2_2 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite64_2_2\n");
- rc = COL_ERROR_IOINIT;
- }
- #endif
- #else /* WSIZE(64) */
- dlflag = RTLD_NEXT;
- __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (dlflag, "fopen", SYS_FOPEN_X_VERSION);
- if (__real_fopen == NULL)
- {
- /* We are probably dlopened after libc,
- * try to search in the previously loaded objects
- */
- __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (RTLD_DEFAULT, "fopen", SYS_FOPEN_X_VERSION);
- if (__real_fopen != NULL)
- {
- Tprintf (0, "iotrace: WARNING: init_io_intf() using RTLD_DEFAULT for Linux io routines\n");
- dlflag = RTLD_DEFAULT;
- }
- else
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen\n");
- rc = COL_ERROR_IOINIT;
- }
- }
- __real_fclose = (int (*)(FILE*))dlvsym (dlflag, "fclose", SYS_FOPEN_X_VERSION);
- if (__real_fclose == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fdopen = (FILE * (*)(int, const char*))dlvsym (dlflag, "fdopen", SYS_FOPEN_X_VERSION);
- if (__real_fdopen == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fgetpos = (int (*)(FILE*, fpos_t*))dlvsym (dlflag, "fgetpos", SYS_FGETPOS_X_VERSION);
- if (__real_fgetpos == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fsetpos = (int (*)(FILE*, const fpos_t*))dlvsym (dlflag, "fsetpos", SYS_FGETPOS_X_VERSION);
- if (__real_fsetpos == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos\n");
- rc = COL_ERROR_IOINIT;
- }
- #endif /* WSIZE(32) */
- __real_open = (int (*)(const char*, int, ...))dlsym (dlflag, "open");
- if (__real_open == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open\n");
- rc = COL_ERROR_IOINIT;
- }
- #if WSIZE(32)
- __real_open64 = (int (*)(const char*, int, ...))dlsym (dlflag, "open64");
- if (__real_open64 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open64\n");
- rc = COL_ERROR_IOINIT;
- }
- #endif
- __real_fcntl = (int (*)(int, int, ...))dlsym (dlflag, "fcntl");
- if (__real_fcntl == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fcntl\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_openat = (int (*)(int, const char*, int, ...))dlsym (dlflag, "openat");
- if (__real_openat == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT openat\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_close = (int (*)(int))dlsym (dlflag, "close");
- if (__real_close == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT close\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_dup = (int (*)(int))dlsym (dlflag, "dup");
- if (__real_dup == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT dup\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_dup2 = (int (*)(int, int))dlsym (dlflag, "dup2");
- if (__real_dup2 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT dup2\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_pipe = (int (*)(int[]))dlsym (dlflag, "pipe");
- if (__real_pipe == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pipe\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_socket = (int (*)(int, int, int))dlsym (dlflag, "socket");
- if (__real_socket == NULL)
- {
- __real_socket = (int (*)(int, int, int))dlsym (RTLD_NEXT, "socket");
- if (__real_socket == NULL)
- {
- #if 0
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT socket\n");
- rc = COL_ERROR_IOINIT;
- #endif
- }
- }
- __real_mkstemp = (int (*)(char*))dlsym (dlflag, "mkstemp");
- if (__real_mkstemp == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT mkstemp\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_mkstemps = (int (*)(char*, int))dlsym (dlflag, "mkstemps");
- if (__real_mkstemps == NULL)
- {
- #if 0
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT mkstemps\n");
- rc = COL_ERROR_IOINIT;
- #endif
- }
- __real_creat = (int (*)(const char*, mode_t))dlsym (dlflag, "creat");
- if (__real_creat == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT creat\n");
- rc = COL_ERROR_IOINIT;
- }
- #if WSIZE(32)
- __real_creat64 = (int (*)(const char*, mode_t))dlsym (dlflag, "creat64");
- if (__real_creat64 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT creat64\n");
- rc = COL_ERROR_IOINIT;
- }
- #endif
- __real_read = (ssize_t (*)(int, void*, size_t))dlsym (dlflag, "read");
- if (__real_read == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT read\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_write = (ssize_t (*)(int, const void*, size_t))dlsym (dlflag, "write");
- if (__real_write == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT write\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_readv = (ssize_t (*)(int, const struct iovec*, int))dlsym (dlflag, "readv");
- if (__real_readv == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT readv\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_writev = (ssize_t (*)(int, const struct iovec*, int))dlsym (dlflag, "writev");
- if (__real_writev == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT writev\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fread = (size_t (*)(void*, size_t, size_t, FILE*))dlsym (dlflag, "fread");
- if (__real_fread == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fread\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fwrite = (size_t (*)(const void*, size_t, size_t, FILE*))dlsym (dlflag, "fwrite");
- if (__real_fwrite == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fwrite\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_pread = (ssize_t (*)(int, void*, size_t, off_t))dlsym (dlflag, "pread");
- if (__real_pread == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_pwrite = (ssize_t (*)(int, const void*, size_t, off_t))dlsym (dlflag, "pwrite");
- if (__real_pwrite == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_pwrite64 = (ssize_t (*)(int, const void*, size_t, off64_t))dlsym (dlflag, "pwrite64");
- if (__real_pwrite64 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite64\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fgets = (char* (*)(char*, int, FILE*))dlsym (dlflag, "fgets");
- if (__real_fgets == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgets\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fputs = (int (*)(const char*, FILE*))dlsym (dlflag, "fputs");
- if (__real_fputs == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fputs\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fputc = (int (*)(int, FILE*))dlsym (dlflag, "fputc");
- if (__real_fputc == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fputc\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_vfprintf = (int (*)(FILE*, const char*, va_list))dlsym (dlflag, "vfprintf");
- if (__real_vfprintf == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT vfprintf\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_lseek = (off_t (*)(int, off_t, int))dlsym (dlflag, "lseek");
- if (__real_lseek == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT lseek\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_llseek = (offset_t (*)(int, offset_t, int))dlsym (dlflag, "llseek");
- if (__real_llseek == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT llseek\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_chmod = (int (*)(const char*, mode_t))dlsym (dlflag, "chmod");
- if (__real_chmod == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT chmod\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_access = (int (*)(const char*, int))dlsym (dlflag, "access");
- if (__real_access == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT access\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_rename = (int (*)(const char*, const char*))dlsym (dlflag, "rename");
- if (__real_rename == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT rename\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_mkdir = (int (*)(const char*, mode_t))dlsym (dlflag, "mkdir");
- if (__real_mkdir == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT mkdir\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_getdents = (int (*)(int, struct dirent*, size_t))dlsym (dlflag, "getdents");
- if (__real_getdents == NULL)
- {
- #if 0
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERXXX_IOINIT getdents\n");
- rc = COL_ERROR_IOINIT;
- #endif
- }
- __real_unlink = (int (*)(const char*))dlsym (dlflag, "unlink");
- if (__real_unlink == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT unlink\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fseek = (int (*)(FILE*, long, int))dlsym (dlflag, "fseek");
- if (__real_fseek == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fseek\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_rewind = (void (*)(FILE*))dlsym (dlflag, "rewind");
- if (__real_rewind == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT rewind\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_ftell = (long (*)(FILE*))dlsym (dlflag, "ftell");
- if (__real_ftell == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT ftell\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fsync = (int (*)(int))dlsym (dlflag, "fsync");
- if (__real_fsync == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsync\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_readdir = (struct dirent * (*)(DIR*))dlsym (dlflag, "readdir");
- if (__real_readdir == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT readdir\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_flock = (int (*)(int, int))dlsym (dlflag, "flock");
- if (__real_flock == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT flock\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_lockf = (int (*)(int, int, off_t))dlsym (dlflag, "lockf");
- if (__real_lockf == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT lockf\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fflush = (int (*)(FILE*))dlsym (dlflag, "fflush");
- if (__real_fflush == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fflush\n");
- rc = COL_ERROR_IOINIT;
- }
- #if WSIZE(32)
- __real_fgetpos64 = (int (*)(FILE*, fpos64_t*))dlsym (dlflag, "fgetpos64");
- if (__real_fgetpos64 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos64\n");
- rc = COL_ERROR_IOINIT;
- }
- __real_fsetpos64 = (int (*)(FILE*, const fpos64_t*))dlsym (dlflag, "fsetpos64");
- if (__real_fsetpos64 == NULL)
- {
- CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos64\n");
- rc = COL_ERROR_IOINIT;
- }
- #endif
- init_io_intf_finished++;
- return rc;
- }
- /*------------------------------------------------------------- open */
- int
- open (const char *path, int oflag, ...)
- {
- int *guard;
- int fd;
- void *packet;
- IOTrace_packet *iopkt;
- mode_t mode;
- va_list ap;
- size_t sz;
- unsigned pktSize;
- va_start (ap, oflag);
- mode = va_arg (ap, mode_t);
- va_end (ap);
- if (NULL_PTR (open))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || path == NULL)
- return CALL_REAL (open)(path, oflag, mode);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- fd = CALL_REAL (open)(path, oflag, mode);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return fd;
- }
- hrtime_t grnt = gethrtime ();
- sz = collector_strlen (path);
- pktSize = sizeof (IOTrace_packet) + sz;
- pktSize = collector_align_pktsize (pktSize);
- Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
- packet = collector_interface->allocCSize (io_heap, pktSize, 1);
- if (packet != NULL)
- {
- iopkt = (IOTrace_packet *) packet;
- collector_memset (iopkt, 0, pktSize);
- iopkt->comm.tsize = pktSize;
- iopkt->comm.tstamp = grnt;
- iopkt->requested = reqt;
- if (fd != -1)
- iopkt->iotype = OPEN_TRACE;
- else
- iopkt->iotype = OPEN_TRACE_ERROR;
- iopkt->fd = fd;
- iopkt->fstype = collector_fstype (path);
- collector_strncpy (&(iopkt->fname), path, sz);
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
- collector_interface->freeCSize (io_heap, packet, pktSize);
- }
- else
- {
- Tprintf (0, "iotrace: ERROR: open cannot allocate memory\n");
- return -1;
- }
- POP_REENTRANCE (guard);
- return fd;
- }
- /*------------------------------------------------------------- open64 */
- #if ARCH(Intel) && WSIZE(32)
- // map interposed symbol versions
- static int
- __collector_open64_symver (int(real_open64) (const char *, int, ...),
- const char *path, int oflag, mode_t mode);
- SYMVER_ATTRIBUTE (__collector_open64_2_2, open64@@GLIBC_2.2)
- int
- __collector_open64_2_2 (const char *path, int oflag, ...)
- {
- mode_t mode;
- va_list ap;
- va_start (ap, oflag);
- mode = va_arg (ap, mode_t);
- va_end (ap);
- TprintfT (DBG_LTT,
- "iotrace: __collector_open64_2_2@%p(path=%s, oflag=0%o, mode=0%o\n",
- CALL_REAL (open64_2_2), path ? path : "NULL", oflag, mode);
- if (NULL_PTR (open64))
- init_io_intf ();
- return __collector_open64_symver (CALL_REAL (open64_2_2), path, oflag, mode);
- }
- SYMVER_ATTRIBUTE (__collector_open64_2_1, open64@GLIBC_2.1)
- int
- __collector_open64_2_1 (const char *path, int oflag, ...)
- {
- mode_t mode;
- va_list ap;
- va_start (ap, oflag);
- mode = va_arg (ap, mode_t);
- va_end (ap);
- TprintfT (DBG_LTT,
- "iotrace: __collector_open64_2_1@%p(path=%s, oflag=0%o, mode=0%o\n",
- CALL_REAL (open64_2_1), path ? path : "NULL", oflag, mode);
- if (NULL_PTR (open64))
- init_io_intf ();
- return __collector_open64_symver (CALL_REAL (open64_2_1), path, oflag, mode);
- }
- #endif /* ARCH(Intel) && WSIZE(32) */
- #if WSIZE(32)
- #if ARCH(Intel) && WSIZE(32)
- static int
- __collector_open64_symver (int(real_open64) (const char *, int, ...),
- const char *path, int oflag, mode_t mode)
- {
- int *guard;
- int fd;
- void *packet;
- IOTrace_packet *iopkt;
- size_t sz;
- unsigned pktSize;
- if (NULL_PTR (open64))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || path == NULL)
- return (real_open64) (path, oflag, mode);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- fd = real_open64 (path, oflag, mode);
- #else /* ^ARCH(Intel) && WSIZE(32) */
- int
- open64 (const char *path, int oflag, ...)
- {
- int *guard;
- int fd;
- void *packet;
- IOTrace_packet *iopkt;
- mode_t mode;
- va_list ap;
- size_t sz;
- unsigned pktSize;
- va_start (ap, oflag);
- mode = va_arg (ap, mode_t);
- va_end (ap);
- if (NULL_PTR (open64))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || path == NULL)
- return CALL_REAL (open64)(path, oflag, mode);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- fd = CALL_REAL (open64)(path, oflag, mode);
- #endif /* ^ARCH(Intel) && WSIZE(32) */
- if (RECHCK_REENTRANCE (guard) || path == NULL)
- {
- POP_REENTRANCE (guard);
- return fd;
- }
- hrtime_t grnt = gethrtime ();
- sz = collector_strlen (path);
- pktSize = sizeof (IOTrace_packet) + sz;
- pktSize = collector_align_pktsize (pktSize);
- Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
- packet = collector_interface->allocCSize (io_heap, pktSize, 1);
- if (packet != NULL)
- {
- iopkt = (IOTrace_packet *) packet;
- collector_memset (iopkt, 0, pktSize);
- iopkt->comm.tsize = pktSize;
- iopkt->comm.tstamp = grnt;
- iopkt->requested = reqt;
- if (fd != -1)
- iopkt->iotype = OPEN_TRACE;
- else
- iopkt->iotype = OPEN_TRACE_ERROR;
- iopkt->fd = fd;
- iopkt->fstype = collector_fstype (path);
- collector_strncpy (&(iopkt->fname), path, sz);
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
- collector_interface->freeCSize (io_heap, packet, pktSize);
- }
- else
- {
- Tprintf (0, "iotrace: ERROR: open64 cannot allocate memory\n");
- return -1;
- }
- POP_REENTRANCE (guard);
- return fd;
- }
- #endif
- #define F_ERROR_ARG 0
- #define F_INT_ARG 1
- #define F_LONG_ARG 2
- #define F_VOID_ARG 3
- /*
- * The following macro is not defined in the
- * older versions of Linux.
- * #define F_DUPFD_CLOEXEC 1030
- *
- * Instead use the command that is defined below
- * until we start compiling mpmt on the newer
- * versions of Linux.
- */
- #define TMP_F_DUPFD_CLOEXEC 1030
- /*------------------------------------------------------------- fcntl */
- int
- fcntl (int fildes, int cmd, ...)
- {
- int *guard;
- int fd = 0;
- IOTrace_packet iopkt;
- long long_arg = 0;
- int int_arg = 0;
- int which_arg = F_ERROR_ARG;
- va_list ap;
- switch (cmd)
- {
- case F_DUPFD:
- case TMP_F_DUPFD_CLOEXEC:
- case F_SETFD:
- case F_SETFL:
- case F_SETOWN:
- case F_SETSIG:
- case F_SETLEASE:
- case F_NOTIFY:
- case F_SETLK:
- case F_SETLKW:
- case F_GETLK:
- va_start (ap, cmd);
- long_arg = va_arg (ap, long);
- va_end (ap);
- which_arg = F_LONG_ARG;
- break;
- case F_GETFD:
- case F_GETFL:
- case F_GETOWN:
- case F_GETLEASE:
- case F_GETSIG:
- which_arg = F_VOID_ARG;
- break;
- }
- if (NULL_PTR (fcntl))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- {
- switch (which_arg)
- {
- case F_INT_ARG:
- return CALL_REAL (fcntl)(fildes, cmd, int_arg);
- case F_LONG_ARG:
- return CALL_REAL (fcntl)(fildes, cmd, long_arg);
- case F_VOID_ARG:
- return CALL_REAL (fcntl)(fildes, cmd);
- case F_ERROR_ARG:
- Tprintf (0, "iotrace: ERROR: Unsupported fcntl command\n");
- return -1;
- }
- return -1;
- }
- if (cmd != F_DUPFD && cmd != TMP_F_DUPFD_CLOEXEC)
- {
- switch (which_arg)
- {
- case F_INT_ARG:
- return CALL_REAL (fcntl)(fildes, cmd, int_arg);
- case F_LONG_ARG:
- return CALL_REAL (fcntl)(fildes, cmd, long_arg);
- case F_VOID_ARG:
- return CALL_REAL (fcntl)(fildes, cmd);
- case F_ERROR_ARG:
- Tprintf (0, "iotrace: ERROR: Unsupported fcntl command\n");
- return -1;
- }
- return -1;
- }
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- switch (cmd)
- {
- case F_DUPFD:
- case TMP_F_DUPFD_CLOEXEC:
- fd = CALL_REAL (fcntl)(fildes, cmd, long_arg);
- break;
- }
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return fd;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (fd != -1)
- iopkt.iotype = OPEN_TRACE;
- else
- iopkt.iotype = OPEN_TRACE_ERROR;
- iopkt.fd = fd;
- iopkt.ofd = fildes;
- iopkt.fstype = UNKNOWNFS_TYPE;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return fd;
- }
- /*------------------------------------------------------------- openat */
- int
- openat (int fildes, const char *path, int oflag, ...)
- {
- int *guard;
- int fd;
- void *packet;
- IOTrace_packet *iopkt;
- mode_t mode;
- va_list ap;
- size_t sz;
- unsigned pktSize;
- va_start (ap, oflag);
- mode = va_arg (ap, mode_t);
- va_end (ap);
- if (NULL_PTR (openat))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || path == NULL)
- return CALL_REAL (openat)(fildes, path, oflag, mode);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- fd = CALL_REAL (openat)(fildes, path, oflag, mode);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return fd;
- }
- hrtime_t grnt = gethrtime ();
- sz = collector_strlen (path);
- pktSize = sizeof (IOTrace_packet) + sz;
- pktSize = collector_align_pktsize (pktSize);
- Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
- packet = collector_interface->allocCSize (io_heap, pktSize, 1);
- if (packet != NULL)
- {
- iopkt = (IOTrace_packet *) packet;
- collector_memset (iopkt, 0, pktSize);
- iopkt->comm.tsize = pktSize;
- iopkt->comm.tstamp = grnt;
- iopkt->requested = reqt;
- if (fd != -1)
- iopkt->iotype = OPEN_TRACE;
- else
- iopkt->iotype = OPEN_TRACE_ERROR;
- iopkt->fd = fd;
- iopkt->fstype = collector_fstype (path);
- collector_strncpy (&(iopkt->fname), path, sz);
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
- collector_interface->freeCSize (io_heap, packet, pktSize);
- }
- else
- {
- Tprintf (0, "iotrace: ERROR: openat cannot allocate memory\n");
- return -1;
- }
- POP_REENTRANCE (guard);
- return fd;
- }
- /*------------------------------------------------------------- creat */
- int
- creat (const char *path, mode_t mode)
- {
- int *guard;
- int fd;
- void *packet;
- IOTrace_packet *iopkt;
- size_t sz;
- unsigned pktSize;
- if (NULL_PTR (creat))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || path == NULL)
- return CALL_REAL (creat)(path, mode);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- fd = CALL_REAL (creat)(path, mode);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return fd;
- }
- hrtime_t grnt = gethrtime ();
- sz = collector_strlen (path);
- pktSize = sizeof (IOTrace_packet) + sz;
- pktSize = collector_align_pktsize (pktSize);
- Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
- packet = collector_interface->allocCSize (io_heap, pktSize, 1);
- if (packet != NULL)
- {
- iopkt = (IOTrace_packet *) packet;
- collector_memset (iopkt, 0, pktSize);
- iopkt->comm.tsize = pktSize;
- iopkt->comm.tstamp = grnt;
- iopkt->requested = reqt;
- if (fd != -1)
- iopkt->iotype = OPEN_TRACE;
- else
- iopkt->iotype = OPEN_TRACE_ERROR;
- iopkt->fd = fd;
- iopkt->fstype = collector_fstype (path);
- collector_strncpy (&(iopkt->fname), path, sz);
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
- collector_interface->freeCSize (io_heap, packet, pktSize);
- }
- else
- {
- Tprintf (0, "iotrace: ERROR: creat cannot allocate memory\n");
- return -1;
- }
- POP_REENTRANCE (guard);
- return fd;
- }
- /*------------------------------------------------------------- creat64 */
- #if WSIZE(32)
- int
- creat64 (const char *path, mode_t mode)
- {
- int *guard;
- int fd;
- void *packet;
- IOTrace_packet *iopkt;
- size_t sz;
- unsigned pktSize;
- if (NULL_PTR (creat64))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || path == NULL)
- return CALL_REAL (creat64)(path, mode);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- fd = CALL_REAL (creat64)(path, mode);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return fd;
- }
- hrtime_t grnt = gethrtime ();
- sz = collector_strlen (path);
- pktSize = sizeof (IOTrace_packet) + sz;
- pktSize = collector_align_pktsize (pktSize);
- Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
- packet = collector_interface->allocCSize (io_heap, pktSize, 1);
- if (packet != NULL)
- {
- iopkt = (IOTrace_packet *) packet;
- collector_memset (iopkt, 0, pktSize);
- iopkt->comm.tsize = pktSize;
- iopkt->comm.tstamp = grnt;
- iopkt->requested = reqt;
- if (fd != -1)
- iopkt->iotype = OPEN_TRACE;
- else
- iopkt->iotype = OPEN_TRACE_ERROR;
- iopkt->fd = fd;
- iopkt->fstype = collector_fstype (path);
- collector_strncpy (&(iopkt->fname), path, sz);
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
- collector_interface->freeCSize (io_heap, packet, pktSize);
- }
- else
- {
- Tprintf (0, "iotrace: ERROR: creat64 cannot allocate memory\n");
- return -1;
- }
- POP_REENTRANCE (guard);
- return fd;
- }
- #endif
- /*------------------------------------------------------------- mkstemp */
- int
- mkstemp (char *template)
- {
- int *guard;
- int fd;
- void *packet;
- IOTrace_packet *iopkt;
- size_t sz;
- unsigned pktSize;
- if (NULL_PTR (mkstemp))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || template == NULL)
- return CALL_REAL (mkstemp)(template);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- fd = CALL_REAL (mkstemp)(template);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return fd;
- }
- hrtime_t grnt = gethrtime ();
- sz = collector_strlen (template);
- pktSize = sizeof (IOTrace_packet) + sz;
- pktSize = collector_align_pktsize (pktSize);
- Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
- packet = collector_interface->allocCSize (io_heap, pktSize, 1);
- if (packet != NULL)
- {
- iopkt = (IOTrace_packet *) packet;
- collector_memset (iopkt, 0, pktSize);
- iopkt->comm.tsize = pktSize;
- iopkt->comm.tstamp = grnt;
- iopkt->requested = reqt;
- if (fd != -1)
- iopkt->iotype = OPEN_TRACE;
- else
- iopkt->iotype = OPEN_TRACE_ERROR;
- iopkt->fd = fd;
- iopkt->fstype = collector_fstype (template);
- collector_strncpy (&(iopkt->fname), template, sz);
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
- collector_interface->freeCSize (io_heap, packet, pktSize);
- }
- else
- {
- Tprintf (0, "iotrace: ERROR: mkstemp cannot allocate memory\n");
- return -1;
- }
- POP_REENTRANCE (guard);
- return fd;
- }
- /*------------------------------------------------------------- mkstemps */
- int
- mkstemps (char *template, int slen)
- {
- int *guard;
- int fd;
- void *packet;
- IOTrace_packet *iopkt;
- size_t sz;
- unsigned pktSize;
- if (NULL_PTR (mkstemps))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || template == NULL)
- return CALL_REAL (mkstemps)(template, slen);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- fd = CALL_REAL (mkstemps)(template, slen);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return fd;
- }
- hrtime_t grnt = gethrtime ();
- sz = collector_strlen (template);
- pktSize = sizeof (IOTrace_packet) + sz;
- pktSize = collector_align_pktsize (pktSize);
- Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
- packet = collector_interface->allocCSize (io_heap, pktSize, 1);
- if (packet != NULL)
- {
- iopkt = (IOTrace_packet *) packet;
- collector_memset (iopkt, 0, pktSize);
- iopkt->comm.tsize = pktSize;
- iopkt->comm.tstamp = grnt;
- iopkt->requested = reqt;
- if (fd != -1)
- iopkt->iotype = OPEN_TRACE;
- else
- iopkt->iotype = OPEN_TRACE_ERROR;
- iopkt->fd = fd;
- iopkt->fstype = collector_fstype (template);
- collector_strncpy (&(iopkt->fname), template, sz);
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
- collector_interface->freeCSize (io_heap, packet, pktSize);
- }
- else
- {
- Tprintf (0, "iotrace: ERROR: mkstemps cannot allocate memory\n");
- return -1;
- }
- POP_REENTRANCE (guard);
- return fd;
- }
- /*------------------------------------------------------------- close */
- int
- close (int fildes)
- {
- int *guard;
- int stat;
- IOTrace_packet iopkt;
- if (NULL_PTR (close))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (close)(fildes);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- stat = CALL_REAL (close)(fildes);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return stat;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (stat == 0)
- iopkt.iotype = CLOSE_TRACE;
- else
- iopkt.iotype = CLOSE_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return stat;
- }
- /*------------------------------------------------------------- fopen */
- // map interposed symbol versions
- #if ARCH(Intel) && WSIZE(32)
- static FILE*
- __collector_fopen_symver (FILE*(real_fopen) (), const char *filename, const char *mode);
- SYMVER_ATTRIBUTE (__collector_fopen_2_1, fopen@@GLIBC_2.1)
- FILE*
- __collector_fopen_2_1 (const char *filename, const char *mode)
- {
- if (NULL_PTR (fopen))
- init_io_intf ();
- TprintfT (DBG_LTT, "iotrace: __collector_fopen_2_1@%p\n", CALL_REAL (fopen_2_1));
- return __collector_fopen_symver (CALL_REAL (fopen_2_1), filename, mode);
- }
- SYMVER_ATTRIBUTE (__collector_fopen_2_0, fopen@GLIBC_2.0)
- FILE*
- __collector_fopen_2_0 (const char *filename, const char *mode)
- {
- if (NULL_PTR (fopen))
- init_io_intf ();
- TprintfT (DBG_LTT, "iotrace: __collector_fopen_2_0@%p\n", CALL_REAL (fopen_2_0));
- return __collector_fopen_symver (CALL_REAL (fopen_2_0), filename, mode);
- }
- #endif
- #if ARCH(Intel) && WSIZE(32)
- static FILE*
- __collector_fopen_symver (FILE*(real_fopen) (), const char *filename, const char *mode)
- {
- #else
- FILE*
- fopen (const char *filename, const char *mode)
- {
- #endif
- int *guard;
- FILE *fp = NULL;
- void *packet;
- IOTrace_packet *iopkt;
- size_t sz;
- unsigned pktSize;
- if (NULL_PTR (fopen))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || filename == NULL)
- {
- #if ARCH(Intel) && WSIZE(32)
- return (real_fopen) (filename, mode);
- #else
- return CALL_REAL (fopen)(filename, mode);
- #endif
- }
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- #if ARCH(Intel) && WSIZE(32)
- fp = (real_fopen) (filename, mode);
- #else
- fp = CALL_REAL (fopen)(filename, mode);
- #endif
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return fp;
- }
- hrtime_t grnt = gethrtime ();
- sz = collector_strlen (filename);
- pktSize = sizeof (IOTrace_packet) + sz;
- pktSize = collector_align_pktsize (pktSize);
- Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
- packet = collector_interface->allocCSize (io_heap, pktSize, 1);
- if (packet != NULL)
- {
- iopkt = (IOTrace_packet *) packet;
- collector_memset (iopkt, 0, pktSize);
- iopkt->comm.tsize = pktSize;
- iopkt->comm.tstamp = grnt;
- iopkt->requested = reqt;
- if (fp != NULL)
- {
- iopkt->iotype = OPEN_TRACE;
- iopkt->fd = fileno (fp);
- }
- else
- {
- iopkt->iotype = OPEN_TRACE_ERROR;
- iopkt->fd = -1;
- }
- iopkt->fstype = collector_fstype (filename);
- collector_strncpy (&(iopkt->fname), filename, sz);
- #if ARCH(Intel) && WSIZE(32)
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
- #else
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- #endif
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
- collector_interface->freeCSize (io_heap, packet, pktSize);
- }
- else
- {
- Tprintf (0, "iotrace: ERROR: fopen cannot allocate memory\n");
- return NULL;
- }
- POP_REENTRANCE (guard);
- return fp;
- }
- /*------------------------------------------------------------- fclose */
- // map interposed symbol versions
- #if ARCH(Intel) && WSIZE(32)
- static int
- __collector_fclose_symver (int(real_fclose) (), FILE *stream);
- SYMVER_ATTRIBUTE (__collector_fclose_2_1, fclose@@GLIBC_2.1)
- int
- __collector_fclose_2_1 (FILE *stream)
- {
- if (NULL_PTR (fclose))
- init_io_intf ();
- TprintfT (DBG_LTT, "iotrace: __collector_fclose_2_1@%p\n", CALL_REAL (fclose_2_1));
- return __collector_fclose_symver (CALL_REAL (fclose_2_1), stream);
- }
- SYMVER_ATTRIBUTE (__collector_fclose_2_0, fclose@GLIBC_2.0)
- int
- __collector_fclose_2_0 (FILE *stream)
- {
- if (NULL_PTR (fclose))
- init_io_intf ();
- TprintfT (DBG_LTT, "iotrace: __collector_fclose_2_0@%p\n", CALL_REAL (fclose_2_0));
- return __collector_fclose_symver (CALL_REAL (fclose_2_0), stream);
- }
- #endif
- #if ARCH(Intel) && WSIZE(32)
- static int
- __collector_fclose_symver (int(real_fclose) (), FILE *stream)
- {
- #else
- int
- fclose (FILE *stream)
- {
- #endif
- int *guard;
- int stat;
- IOTrace_packet iopkt;
- if (NULL_PTR (fclose))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- {
- #if ARCH(Intel) && WSIZE(32)
- return (real_fclose) (stream);
- #else
- return CALL_REAL (fclose)(stream);
- #endif
- }
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- #if ARCH(Intel) && WSIZE(32)
- stat = (real_fclose) (stream);
- #else
- stat = CALL_REAL (fclose)(stream);
- #endif
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return stat;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (stat == 0)
- iopkt.iotype = CLOSE_TRACE;
- else
- iopkt.iotype = CLOSE_TRACE_ERROR;
- iopkt.fd = fileno (stream);
- #if ARCH(Intel) && WSIZE(32)
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
- #else
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- #endif
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return stat;
- }
- /*------------------------------------------------------------- fflush */
- int
- fflush (FILE *stream)
- {
- int *guard;
- int stat;
- IOTrace_packet iopkt;
- if (NULL_PTR (fflush))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (fflush)(stream);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- stat = CALL_REAL (fflush)(stream);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return stat;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (stat == 0)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- if (stream != NULL)
- iopkt.fd = fileno (stream);
- else
- iopkt.fd = -1;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return stat;
- }
- /*------------------------------------------------------------- fdopen */
- // map interposed symbol versions
- #if ARCH(Intel) && WSIZE(32)
- static FILE*
- __collector_fdopen_symver (FILE*(real_fdopen) (), int fildes, const char *mode);
- SYMVER_ATTRIBUTE (__collector_fdopen_2_1, fdopen@@GLIBC_2.1)
- FILE*
- __collector_fdopen_2_1 (int fildes, const char *mode)
- {
- if (NULL_PTR (fdopen))
- init_io_intf ();
- TprintfT (DBG_LTT, "iotrace: __collector_fdopen_2_1@%p\n", CALL_REAL (fdopen_2_1));
- return __collector_fdopen_symver (CALL_REAL (fdopen_2_1), fildes, mode);
- }
- SYMVER_ATTRIBUTE (__collector_fdopen_2_0, fdopen@GLIBC_2.0)
- FILE*
- __collector_fdopen_2_0 (int fildes, const char *mode)
- {
- if (NULL_PTR (fdopen))
- init_io_intf ();
- TprintfT (DBG_LTT, "iotrace: __collector_fdopen_2_0@%p\n", CALL_REAL (fdopen_2_0));
- return __collector_fdopen_symver (CALL_REAL (fdopen_2_0), fildes, mode);
- }
- #endif
- #if ARCH(Intel) && WSIZE(32)
- static FILE*
- __collector_fdopen_symver (FILE*(real_fdopen) (), int fildes, const char *mode)
- {
- #else
- FILE*
- fdopen (int fildes, const char *mode)
- {
- #endif
- int *guard;
- FILE *fp = NULL;
- IOTrace_packet iopkt;
- if (NULL_PTR (fdopen))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- {
- #if ARCH(Intel) && WSIZE(32)
- return (real_fdopen) (fildes, mode);
- #else
- return CALL_REAL (fdopen)(fildes, mode);
- #endif
- }
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- #if ARCH(Intel) && WSIZE(32)
- fp = (real_fdopen) (fildes, mode);
- #else
- fp = CALL_REAL (fdopen)(fildes, mode);
- #endif
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return fp;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (fp != NULL)
- iopkt.iotype = OPEN_TRACE;
- else
- iopkt.iotype = OPEN_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.fstype = UNKNOWNFS_TYPE;
- #if ARCH(Intel) && WSIZE(32)
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
- #else
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- #endif
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return fp;
- }
- /*------------------------------------------------------------- dup */
- int
- dup (int fildes)
- {
- int *guard;
- int fd;
- IOTrace_packet iopkt;
- if (NULL_PTR (dup))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (dup)(fildes);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- fd = CALL_REAL (dup)(fildes);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return fd;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (fd != -1)
- iopkt.iotype = OPEN_TRACE;
- else
- iopkt.iotype = OPEN_TRACE_ERROR;
- iopkt.fd = fd;
- iopkt.ofd = fildes;
- iopkt.fstype = UNKNOWNFS_TYPE;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return fd;
- }
- /*------------------------------------------------------------- dup2 */
- int
- dup2 (int fildes, int fildes2)
- {
- int *guard;
- int fd;
- IOTrace_packet iopkt;
- if (NULL_PTR (dup2))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (dup2)(fildes, fildes2);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- fd = CALL_REAL (dup2)(fildes, fildes2);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return fd;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (fd != -1)
- iopkt.iotype = OPEN_TRACE;
- else
- iopkt.iotype = OPEN_TRACE_ERROR;
- iopkt.fd = fd;
- iopkt.ofd = fildes;
- iopkt.fstype = UNKNOWNFS_TYPE;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return fd;
- }
- /*------------------------------------------------------------- pipe */
- int
- pipe (int fildes[2])
- {
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (pipe))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (pipe)(fildes);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (pipe)(fildes);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret != -1)
- iopkt.iotype = OPEN_TRACE;
- else
- iopkt.iotype = OPEN_TRACE_ERROR;
- iopkt.fd = fildes[0];
- iopkt.fstype = UNKNOWNFS_TYPE;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret != -1)
- iopkt.iotype = OPEN_TRACE;
- else
- iopkt.iotype = OPEN_TRACE_ERROR;
- iopkt.fd = fildes[1];
- iopkt.fstype = UNKNOWNFS_TYPE;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- socket */
- int
- socket (int domain, int type, int protocol)
- {
- int *guard;
- int fd;
- IOTrace_packet iopkt;
- if (NULL_PTR (socket))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (socket)(domain, type, protocol);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- fd = CALL_REAL (socket)(domain, type, protocol);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return fd;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (fd != -1)
- iopkt.iotype = OPEN_TRACE;
- else
- iopkt.iotype = OPEN_TRACE_ERROR;
- iopkt.fd = fd;
- iopkt.fstype = UNKNOWNFS_TYPE;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return fd;
- }
- /*------------------------------------------------------------- read */
- ssize_t
- read (int fildes, void *buf, size_t nbyte)
- {
- int *guard;
- ssize_t ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (read))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (read)(fildes, buf, nbyte);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (read)(fildes, buf, nbyte);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret >= 0)
- iopkt.iotype = READ_TRACE;
- else
- iopkt.iotype = READ_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.nbyte = ret;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- write */
- ssize_t
- write (int fildes, const void *buf, size_t nbyte)
- {
- int *guard;
- ssize_t ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (write))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (write)(fildes, buf, nbyte);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (write)(fildes, buf, nbyte);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret >= 0)
- iopkt.iotype = WRITE_TRACE;
- else
- iopkt.iotype = WRITE_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.nbyte = ret;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- readv */
- ssize_t
- readv (int fildes, const struct iovec *iov, int iovcnt)
- {
- int *guard;
- ssize_t ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (readv))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (readv)(fildes, iov, iovcnt);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (readv)(fildes, iov, iovcnt);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret >= 0)
- iopkt.iotype = READ_TRACE;
- else
- iopkt.iotype = READ_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.nbyte = ret;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- writev */
- ssize_t
- writev (int fildes, const struct iovec *iov, int iovcnt)
- {
- int *guard;
- ssize_t ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (writev))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (writev)(fildes, iov, iovcnt);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (writev)(fildes, iov, iovcnt);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret >= 0)
- iopkt.iotype = WRITE_TRACE;
- else
- iopkt.iotype = WRITE_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.nbyte = ret;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- fread */
- size_t
- fread (void *ptr, size_t size, size_t nitems, FILE *stream)
- {
- int *guard;
- size_t ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (fread))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- return CALL_REAL (fread)(ptr, size, nitems, stream);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (fread)(ptr, size, nitems, stream);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ferror (stream) == 0)
- {
- iopkt.iotype = READ_TRACE;
- iopkt.nbyte = ret * size;
- }
- else
- {
- iopkt.iotype = READ_TRACE_ERROR;
- iopkt.nbyte = 0;
- }
- iopkt.fd = fileno (stream);
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- fwrite */
- size_t
- fwrite (const void *ptr, size_t size, size_t nitems, FILE *stream)
- {
- int *guard;
- size_t ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (fwrite))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- return CALL_REAL (fwrite)(ptr, size, nitems, stream);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (fwrite)(ptr, size, nitems, stream);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ferror (stream) == 0)
- {
- iopkt.iotype = WRITE_TRACE;
- iopkt.nbyte = ret * size;
- }
- else
- {
- iopkt.iotype = WRITE_TRACE_ERROR;
- iopkt.nbyte = 0;
- }
- iopkt.fd = fileno (stream);
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- pread */
- #if ARCH(Intel) && WSIZE(32)
- // map interposed symbol versions
- static int
- __collector_pread_symver (int(real_pread) (), int fildes, void *buf, size_t nbyte, off_t offset);
- SYMVER_ATTRIBUTE (__collector_pread_2_2, pread@@GLIBC_2.2)
- int
- __collector_pread_2_2 (int fildes, void *buf, size_t nbyte, off_t offset)
- {
- TprintfT (DBG_LTT, "iotrace: __collector_pread_2_2@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
- CALL_REAL (pread_2_2), fildes, buf, (long long) nbyte, (long long) offset);
- if (NULL_PTR (pread))
- init_io_intf ();
- return __collector_pread_symver (CALL_REAL (pread_2_2), fildes, buf, nbyte, offset);
- }
- SYMVER_ATTRIBUTE (__collector_pread_2_1, pread@GLIBC_2.1)
- int
- __collector_pread_2_1 (int fildes, void *buf, size_t nbyte, off_t offset)
- {
- TprintfT (DBG_LTT, "iotrace: __collector_pread_2_1@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
- CALL_REAL (pread_2_1), fildes, buf, (long long) nbyte, (long long) offset);
- if (NULL_PTR (pread))
- init_io_intf ();
- return __collector_pread_symver (CALL_REAL (pread_2_1), fildes, buf, nbyte, offset);
- }
- static int
- __collector_pread_symver (int(real_pread) (), int fildes, void *buf, size_t nbyte, off_t offset)
- {
- #else /* ^ARCH(Intel) && WSIZE(32) */
- ssize_t
- pread (int fildes, void *buf, size_t nbyte, off_t offset)
- {
- #endif
- int *guard;
- ssize_t ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (pread))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- {
- #if ARCH(Intel) && WSIZE(32)
- return (real_pread) (fildes, buf, nbyte, offset);
- #else
- return CALL_REAL (pread)(fildes, buf, nbyte, offset);
- #endif
- }
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- #if ARCH(Intel) && WSIZE(32)
- ret = (real_pread) (fildes, buf, nbyte, offset);
- #else
- ret = CALL_REAL (pread)(fildes, buf, nbyte, offset);
- #endif
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret >= 0)
- iopkt.iotype = READ_TRACE;
- else
- iopkt.iotype = READ_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.nbyte = ret;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- pwrite */
- #if ARCH(Intel) && WSIZE(32)
- // map interposed symbol versions
- static int
- __collector_pwrite_symver (int(real_pwrite) (), int fildes, const void *buf, size_t nbyte, off_t offset);
- SYMVER_ATTRIBUTE (__collector_pwrite_2_2, pwrite@@GLIBC_2.2)
- int
- __collector_pwrite_2_2 (int fildes, const void *buf, size_t nbyte, off_t offset)
- {
- TprintfT (DBG_LTT, "iotrace: __collector_pwrite_2_2@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
- CALL_REAL (pwrite_2_2), fildes, buf, (long long) nbyte, (long long) offset);
- if (NULL_PTR (pwrite))
- init_io_intf ();
- return __collector_pwrite_symver (CALL_REAL (pwrite_2_2), fildes, buf, nbyte, offset);
- }
- SYMVER_ATTRIBUTE (__collector_pwrite_2_1, pwrite@GLIBC_2.1)
- int
- __collector_pwrite_2_1 (int fildes, const void *buf, size_t nbyte, off_t offset)
- {
- TprintfT (DBG_LTT, "iotrace: __collector_pwrite_2_1@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
- CALL_REAL (pwrite_2_1), fildes, buf, (long long) nbyte, (long long) offset);
- if (NULL_PTR (pwrite))
- init_io_intf ();
- return __collector_pwrite_symver (CALL_REAL (pwrite_2_1), fildes, buf, nbyte, offset);
- }
- static int
- __collector_pwrite_symver (int(real_pwrite) (), int fildes, const void *buf, size_t nbyte, off_t offset)
- {
- #else /* ^ARCH(Intel) && WSIZE(32) */
- ssize_t
- pwrite (int fildes, const void *buf, size_t nbyte, off_t offset)
- {
- #endif /* ^ARCH(Intel) && WSIZE(32) */
- int *guard;
- ssize_t ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (pwrite))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- {
- #if ARCH(Intel) && WSIZE(32)
- return (real_pwrite) (fildes, buf, nbyte, offset);
- #else
- return CALL_REAL (pwrite)(fildes, buf, nbyte, offset);
- #endif
- }
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- #if ARCH(Intel) && WSIZE(32)
- ret = (real_pwrite) (fildes, buf, nbyte, offset);
- #else
- ret = CALL_REAL (pwrite)(fildes, buf, nbyte, offset);
- #endif
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret >= 0)
- iopkt.iotype = WRITE_TRACE;
- else
- iopkt.iotype = WRITE_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.nbyte = ret;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- pwrite64 */
- #if ARCH(Intel) && WSIZE(32)
- // map interposed symbol versions
- static int
- __collector_pwrite64_symver (int(real_pwrite64) (), int fildes, const void *buf, size_t nbyte, off64_t offset);
- SYMVER_ATTRIBUTE (__collector_pwrite64_2_2, pwrite64@@GLIBC_2.2)
- int
- __collector_pwrite64_2_2 (int fildes, const void *buf, size_t nbyte, off64_t offset)
- {
- TprintfT (DBG_LTT, "iotrace: __collector_pwrite64_2_2@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
- CALL_REAL (pwrite64_2_2), fildes, buf, (long long) nbyte, (long long) offset);
- if (NULL_PTR (pwrite64))
- init_io_intf ();
- return __collector_pwrite64_symver (CALL_REAL (pwrite64_2_2), fildes, buf, nbyte, offset);
- }
- SYMVER_ATTRIBUTE (__collector_pwrite64_2_1, pwrite64@GLIBC_2.1)
- int
- __collector_pwrite64_2_1 (int fildes, const void *buf, size_t nbyte, off64_t offset)
- {
- TprintfT (DBG_LTT, "iotrace: __collector_pwrite64_2_1@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n",
- CALL_REAL (pwrite64_2_1), fildes, buf, (long long) nbyte, (long long) offset);
- if (NULL_PTR (pwrite64))
- init_io_intf ();
- return __collector_pwrite64_symver (CALL_REAL (pwrite64_2_1), fildes, buf, nbyte, offset);
- }
- static int
- __collector_pwrite64_symver (int(real_pwrite64) (), int fildes, const void *buf, size_t nbyte, off64_t offset)
- {
- #else /* ^ARCH(Intel) && WSIZE(32) */
- ssize_t
- pwrite64 (int fildes, const void *buf, size_t nbyte, off64_t offset)
- {
- #endif /* ^ARCH(Intel) && WSIZE(32) */
- int *guard;
- ssize_t ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (pwrite64))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- {
- #if ARCH(Intel) && WSIZE(32)
- return (real_pwrite64) (fildes, buf, nbyte, offset);
- #else
- return CALL_REAL (pwrite64)(fildes, buf, nbyte, offset);
- #endif
- }
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- #if ARCH(Intel) && WSIZE(32)
- ret = (real_pwrite64) (fildes, buf, nbyte, offset);
- #else
- ret = CALL_REAL (pwrite64)(fildes, buf, nbyte, offset);
- #endif
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret >= 0)
- iopkt.iotype = WRITE_TRACE;
- else
- iopkt.iotype = WRITE_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.nbyte = ret;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- fgets */
- char*
- fgets (char *s, int n, FILE *stream)
- {
- int *guard;
- char *ptr;
- IOTrace_packet iopkt;
- if (NULL_PTR (fgets))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- return CALL_REAL (fgets)(s, n, stream);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ptr = CALL_REAL (fgets)(s, n, stream);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ptr;
- }
- int error = errno;
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ptr != NULL)
- {
- iopkt.iotype = READ_TRACE;
- iopkt.nbyte = collector_strlen (ptr);
- }
- else if (ptr == NULL && error != EAGAIN && error != EBADF && error != EINTR &&
- error != EIO && error != EOVERFLOW && error != ENOMEM && error != ENXIO)
- {
- iopkt.iotype = READ_TRACE;
- iopkt.nbyte = 0;
- }
- else
- iopkt.iotype = READ_TRACE_ERROR;
- iopkt.fd = fileno (stream);
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ptr;
- }
- /*------------------------------------------------------------- fputs */
- int
- fputs (const char *s, FILE *stream)
- {
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (fputs))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- return CALL_REAL (fputs)(s, stream);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (fputs)(s, stream);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret != EOF)
- {
- iopkt.iotype = WRITE_TRACE;
- iopkt.nbyte = ret;
- }
- else
- {
- iopkt.iotype = WRITE_TRACE_ERROR;
- iopkt.nbyte = 0;
- }
- iopkt.fd = fileno (stream);
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- fputc */
- int
- fputc (int c, FILE *stream)
- {
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (fputc))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- return CALL_REAL (fputc)(c, stream);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (fputc)(c, stream);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret != EOF)
- {
- iopkt.iotype = WRITE_TRACE;
- iopkt.nbyte = ret;
- }
- else
- {
- iopkt.iotype = WRITE_TRACE_ERROR;
- iopkt.nbyte = 0;
- }
- iopkt.fd = fileno (stream);
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- fprintf */
- int
- fprintf (FILE *stream, const char *format, ...)
- {
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- va_list ap;
- va_start (ap, format);
- if (NULL_PTR (fprintf))
- init_io_intf ();
- if (NULL_PTR (vfprintf))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- return CALL_REAL (vfprintf)(stream, format, ap);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (vfprintf)(stream, format, ap);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret >= 0)
- iopkt.iotype = WRITE_TRACE;
- else
- iopkt.iotype = WRITE_TRACE_ERROR;
- iopkt.fd = fileno (stream);
- iopkt.nbyte = ret;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- vfprintf */
- int
- vfprintf (FILE *stream, const char *format, va_list ap)
- {
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (vfprintf))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- return CALL_REAL (vfprintf)(stream, format, ap);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (vfprintf)(stream, format, ap);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret >= 0)
- iopkt.iotype = WRITE_TRACE;
- else
- iopkt.iotype = WRITE_TRACE_ERROR;
- iopkt.fd = fileno (stream);
- iopkt.nbyte = ret;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- lseek */
- off_t
- lseek (int fildes, off_t offset, int whence)
- {
- int *guard;
- off_t ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (lseek))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (lseek)(fildes, offset, whence);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (lseek)(fildes, offset, whence);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret != -1)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- llseek */
- offset_t
- llseek (int fildes, offset_t offset, int whence)
- {
- int *guard;
- offset_t ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (llseek))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (llseek)(fildes, offset, whence);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (llseek)(fildes, offset, whence);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret != -1)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- chmod */
- int
- chmod (const char *path, mode_t mode)
- {
- int *guard;
- int ret;
- void *packet;
- IOTrace_packet *iopkt;
- size_t sz;
- unsigned pktSize;
- if (NULL_PTR (chmod))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || path == NULL)
- return CALL_REAL (chmod)(path, mode);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (chmod)(path, mode);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- sz = collector_strlen (path);
- pktSize = sizeof (IOTrace_packet) + sz;
- pktSize = collector_align_pktsize (pktSize);
- Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
- packet = collector_interface->allocCSize (io_heap, pktSize, 1);
- if (packet != NULL)
- {
- iopkt = (IOTrace_packet *) packet;
- collector_memset (iopkt, 0, pktSize);
- iopkt->comm.tsize = pktSize;
- iopkt->comm.tstamp = grnt;
- iopkt->requested = reqt;
- if (ret != -1)
- iopkt->iotype = OTHERIO_TRACE;
- else
- iopkt->iotype = OTHERIO_TRACE_ERROR;
- collector_strncpy (&(iopkt->fname), path, sz);
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
- collector_interface->freeCSize (io_heap, packet, pktSize);
- }
- else
- {
- Tprintf (0, "iotrace: ERROR: chmod cannot allocate memory\n");
- return 0;
- }
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- access */
- int
- access (const char *path, int amode)
- {
- int *guard;
- int ret;
- void *packet;
- IOTrace_packet *iopkt;
- size_t sz;
- unsigned pktSize;
- if (NULL_PTR (access))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || path == NULL)
- return CALL_REAL (access)(path, amode);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (access)(path, amode);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- sz = collector_strlen (path);
- pktSize = sizeof (IOTrace_packet) + sz;
- pktSize = collector_align_pktsize (pktSize);
- Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
- packet = collector_interface->allocCSize (io_heap, pktSize, 1);
- if (packet != NULL)
- {
- iopkt = (IOTrace_packet *) packet;
- collector_memset (iopkt, 0, pktSize);
- iopkt->comm.tsize = pktSize;
- iopkt->comm.tstamp = grnt;
- iopkt->requested = reqt;
- if (ret != -1)
- iopkt->iotype = OTHERIO_TRACE;
- else
- iopkt->iotype = OTHERIO_TRACE_ERROR;
- collector_strncpy (&(iopkt->fname), path, sz);
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
- collector_interface->freeCSize (io_heap, packet, pktSize);
- }
- else
- {
- Tprintf (0, "iotrace: ERROR: access cannot allocate memory\n");
- return 0;
- }
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- rename */
- int
- rename (const char *old, const char *new)
- {
- int *guard;
- int ret;
- void *packet;
- IOTrace_packet *iopkt;
- size_t sz;
- unsigned pktSize;
- if (NULL_PTR (rename))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || new == NULL)
- return CALL_REAL (rename)(old, new);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (rename)(old, new);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- sz = collector_strlen (new);
- pktSize = sizeof (IOTrace_packet) + sz;
- pktSize = collector_align_pktsize (pktSize);
- Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
- packet = collector_interface->allocCSize (io_heap, pktSize, 1);
- if (packet != NULL)
- {
- iopkt = (IOTrace_packet *) packet;
- collector_memset (iopkt, 0, pktSize);
- iopkt->comm.tsize = pktSize;
- iopkt->comm.tstamp = grnt;
- iopkt->requested = reqt;
- if (ret != -1)
- iopkt->iotype = OTHERIO_TRACE;
- else
- iopkt->iotype = OTHERIO_TRACE_ERROR;
- collector_strncpy (&(iopkt->fname), new, sz);
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
- collector_interface->freeCSize (io_heap, packet, pktSize);
- }
- else
- {
- Tprintf (0, "iotrace: ERROR: rename cannot allocate memory\n");
- return 0;
- }
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- mkdir */
- int
- mkdir (const char *path, mode_t mode)
- {
- int *guard;
- int ret;
- void *packet;
- IOTrace_packet *iopkt;
- size_t sz;
- unsigned pktSize;
- if (NULL_PTR (mkdir))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || path == NULL)
- return CALL_REAL (mkdir)(path, mode);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (mkdir)(path, mode);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- sz = collector_strlen (path);
- pktSize = sizeof (IOTrace_packet) + sz;
- pktSize = collector_align_pktsize (pktSize);
- Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
- packet = collector_interface->allocCSize (io_heap, pktSize, 1);
- if (packet != NULL)
- {
- iopkt = (IOTrace_packet *) packet;
- collector_memset (iopkt, 0, pktSize);
- iopkt->comm.tsize = pktSize;
- iopkt->comm.tstamp = grnt;
- iopkt->requested = reqt;
- if (ret != -1)
- iopkt->iotype = OTHERIO_TRACE;
- else
- iopkt->iotype = OTHERIO_TRACE_ERROR;
- collector_strncpy (&(iopkt->fname), path, sz);
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
- collector_interface->freeCSize (io_heap, packet, pktSize);
- }
- else
- {
- Tprintf (0, "iotrace: ERROR: mkdir cannot allocate memory\n");
- return 0;
- }
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- getdents */
- int
- getdents (int fildes, struct dirent *buf, size_t nbyte)
- {
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (getdents))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (getdents)(fildes, buf, nbyte);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (getdents)(fildes, buf, nbyte);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret != -1)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- unlink */
- int
- unlink (const char *path)
- {
- int *guard;
- int ret;
- void *packet;
- IOTrace_packet *iopkt;
- size_t sz;
- unsigned pktSize;
- if (NULL_PTR (unlink))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || path == NULL)
- return CALL_REAL (unlink)(path);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (unlink)(path);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- sz = collector_strlen (path);
- pktSize = sizeof (IOTrace_packet) + sz;
- pktSize = collector_align_pktsize (pktSize);
- Tprintf (DBG_LT1, "iotrace allocating %u from io_heap\n", pktSize);
- packet = collector_interface->allocCSize (io_heap, pktSize, 1);
- if (packet != NULL)
- {
- iopkt = (IOTrace_packet *) packet;
- collector_memset (iopkt, 0, pktSize);
- iopkt->comm.tsize = pktSize;
- iopkt->comm.tstamp = grnt;
- iopkt->requested = reqt;
- if (ret != -1)
- iopkt->iotype = OTHERIO_TRACE;
- else
- iopkt->iotype = OTHERIO_TRACE_ERROR;
- collector_strncpy (&(iopkt->fname), path, sz);
- iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt);
- collector_interface->freeCSize (io_heap, packet, pktSize);
- }
- else
- {
- Tprintf (0, "iotrace: ERROR: unlink cannot allocate memory\n");
- return 0;
- }
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- fseek */
- int
- fseek (FILE *stream, long offset, int whence)
- {
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (fseek))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- return CALL_REAL (fseek)(stream, offset, whence);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (fseek)(stream, offset, whence);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret != -1)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- iopkt.fd = fileno (stream);
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- rewind */
- void
- rewind (FILE *stream)
- {
- int *guard;
- IOTrace_packet iopkt;
- if (NULL_PTR (rewind))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- {
- CALL_REAL (rewind)(stream);
- return;
- }
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- CALL_REAL (rewind)(stream);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- iopkt.iotype = OTHERIO_TRACE;
- iopkt.fd = fileno (stream);
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- }
- /*------------------------------------------------------------- ftell */
- long
- ftell (FILE *stream)
- {
- int *guard;
- long ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (ftell))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- return CALL_REAL (ftell)(stream);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (ftell)(stream);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret != -1)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- iopkt.fd = fileno (stream);
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- fgetpos */
- // map interposed symbol versions
- #if ARCH(Intel) && WSIZE(32)
- static int
- __collector_fgetpos_symver (int(real_fgetpos) (), FILE *stream, fpos_t *pos);
- SYMVER_ATTRIBUTE (__collector_fgetpos_2_2, fgetpos@@GLIBC_2.2)
- int
- __collector_fgetpos_2_2 (FILE *stream, fpos_t *pos)
- {
- if (NULL_PTR (fgetpos))
- init_io_intf ();
- TprintfT (DBG_LTT, "iotrace: __collector_fgetpos_2_2@%p\n", CALL_REAL (fgetpos_2_2));
- return __collector_fgetpos_symver (CALL_REAL (fgetpos_2_2), stream, pos);
- }
- SYMVER_ATTRIBUTE (__collector_fgetpos_2_0, fgetpos@GLIBC_2.0)
- int
- __collector_fgetpos_2_0 (FILE *stream, fpos_t *pos)
- {
- if (NULL_PTR (fgetpos))
- init_io_intf ();
- TprintfT (DBG_LTT, "iotrace: __collector_fgetpos_2_0@%p\n", CALL_REAL (fgetpos_2_0));
- return __collector_fgetpos_symver (CALL_REAL (fgetpos_2_0), stream, pos);
- }
- #endif
- #if ARCH(Intel) && WSIZE(32)
- static int
- __collector_fgetpos_symver (int(real_fgetpos) (), FILE *stream, fpos_t *pos)
- {
- #else
- int
- fgetpos (FILE *stream, fpos_t *pos)
- {
- #endif
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (fgetpos))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- {
- #if ARCH(Intel) && WSIZE(32)
- return (real_fgetpos) (stream, pos);
- #else
- return CALL_REAL (fgetpos)(stream, pos);
- #endif
- }
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- #if ARCH(Intel) && WSIZE(32)
- ret = (real_fgetpos) (stream, pos);
- #else
- ret = CALL_REAL (fgetpos)(stream, pos);
- #endif
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret == 0)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- iopkt.fd = fileno (stream);
- #if ARCH(Intel) && WSIZE(32)
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
- #else
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- #endif
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- #if WSIZE(32)
- /*------------------------------------------------------------- fgetpos64 */
- #if ARCH(Intel)
- // map interposed symbol versions
- static int
- __collector_fgetpos64_symver (int(real_fgetpos64) (), FILE *stream, fpos64_t *pos);
- SYMVER_ATTRIBUTE (__collector_fgetpos64_2_2, fgetpos64@@GLIBC_2.2)
- int
- __collector_fgetpos64_2_2 (FILE *stream, fpos64_t *pos)
- {
- TprintfT (DBG_LTT, "iotrace: __collector_fgetpos64_2_2@%p(stream=%p, pos=%p)\n",
- CALL_REAL (fgetpos64_2_2), stream, pos);
- if (NULL_PTR (fgetpos64))
- init_io_intf ();
- return __collector_fgetpos64_symver (CALL_REAL (fgetpos64_2_2), stream, pos);
- }
- SYMVER_ATTRIBUTE (__collector_fgetpos64_2_1, fgetpos64@GLIBC_2.1)
- int
- __collector_fgetpos64_2_1 (FILE *stream, fpos64_t *pos)
- {
- TprintfT (DBG_LTT, "iotrace: __collector_fgetpos64_2_1@%p(stream=%p, pos=%p)\n",
- CALL_REAL (fgetpos64_2_1), stream, pos);
- if (NULL_PTR (fgetpos64))
- init_io_intf ();
- return __collector_fgetpos64_symver (CALL_REAL (fgetpos64_2_1), stream, pos);
- }
- static int
- __collector_fgetpos64_symver (int(real_fgetpos64) (), FILE *stream, fpos64_t *pos)
- {
- #else
- int
- fgetpos64 (FILE *stream, fpos64_t *pos)
- {
- #endif
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (fgetpos64))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- {
- #if ARCH(Intel)
- return (real_fgetpos64) (stream, pos);
- #else
- return CALL_REAL (fgetpos64)(stream, pos);
- #endif
- }
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- #if ARCH(Intel)
- ret = (real_fgetpos64) (stream, pos);
- #else
- ret = CALL_REAL (fgetpos64)(stream, pos);
- #endif
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret == 0)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- iopkt.fd = fileno (stream);
- #if ARCH(Intel)
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
- #else
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- #endif
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- #endif
- /*------------------------------------------------------------- fsetpos */
- // map interposed symbol versions
- #if ARCH(Intel) && WSIZE(32)
- static int
- __collector_fsetpos_symver (int(real_fsetpos) (), FILE *stream, const fpos_t *pos);
- SYMVER_ATTRIBUTE (__collector_fsetpos_2_2, fsetpos@@GLIBC_2.2)
- int
- __collector_fsetpos_2_2 (FILE *stream, const fpos_t *pos)
- {
- if (NULL_PTR (fsetpos))
- init_io_intf ();
- TprintfT (DBG_LTT, "iotrace: __collector_fsetpos_2_2@%p\n", CALL_REAL (fsetpos_2_2));
- return __collector_fsetpos_symver (CALL_REAL (fsetpos_2_2), stream, pos);
- }
- SYMVER_ATTRIBUTE (__collector_fsetpos_2_0, fsetpos@GLIBC_2.0)
- int
- __collector_fsetpos_2_0 (FILE *stream, const fpos_t *pos)
- {
- if (NULL_PTR (fsetpos))
- init_io_intf ();
- TprintfT (DBG_LTT, "iotrace: __collector_fsetpos_2_0@%p\n", CALL_REAL (fsetpos_2_0));
- return __collector_fsetpos_symver (CALL_REAL (fsetpos_2_0), stream, pos);
- }
- #endif
- #if ARCH(Intel) && WSIZE(32)
- static int
- __collector_fsetpos_symver (int(real_fsetpos) (), FILE *stream, const fpos_t *pos)
- {
- #else
- int
- fsetpos (FILE *stream, const fpos_t *pos)
- {
- #endif
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (fsetpos))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- {
- #if ARCH(Intel) && WSIZE(32)
- return (real_fsetpos) (stream, pos);
- #else
- return CALL_REAL (fsetpos)(stream, pos);
- #endif
- }
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- #if ARCH(Intel) && WSIZE(32)
- ret = (real_fsetpos) (stream, pos);
- #else
- ret = CALL_REAL (fsetpos)(stream, pos);
- #endif
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret == 0)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- iopkt.fd = fileno (stream);
- #if ARCH(Intel) && WSIZE(32)
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
- #else
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- #endif
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- #if WSIZE(32)
- /*------------------------------------------------------------- fsetpos64 */
- #if ARCH(Intel)
- // map interposed symbol versions
- static int
- __collector_fsetpos64_symver (int(real_fsetpos64) (), FILE *stream, const fpos64_t *pos);
- SYMVER_ATTRIBUTE (__collector_fsetpos64_2_2, fsetpos64@@GLIBC_2.2)
- int
- __collector_fsetpos64_2_2 (FILE *stream, const fpos64_t *pos)
- {
- TprintfT (DBG_LTT, "iotrace: __collector_fsetpos64_2_2@%p(stream=%p, pos=%p)\n",
- CALL_REAL (fsetpos64_2_2), stream, pos);
- if (NULL_PTR (fsetpos64))
- init_io_intf ();
- return __collector_fsetpos64_symver (CALL_REAL (fsetpos64_2_2), stream, pos);
- }
- SYMVER_ATTRIBUTE (__collector_fsetpos64_2_1, fsetpos64@GLIBC_2.1)
- int
- __collector_fsetpos64_2_1 (FILE *stream, const fpos64_t *pos)
- {
- TprintfT (DBG_LTT, "iotrace: __collector_fsetpos64_2_1@%p(stream=%p, pos=%p)\n",
- CALL_REAL (fsetpos64_2_1), stream, pos);
- if (NULL_PTR (fsetpos64))
- init_io_intf ();
- return __collector_fsetpos64_symver (CALL_REAL (fsetpos64_2_1), stream, pos);
- }
- static int
- __collector_fsetpos64_symver (int(real_fsetpos64) (), FILE *stream, const fpos64_t *pos)
- {
- #else
- int
- fsetpos64 (FILE *stream, const fpos64_t *pos)
- {
- #endif
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (fsetpos64))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard) || stream == NULL)
- {
- #if ARCH(Intel) && WSIZE(32)
- return (real_fsetpos64) (stream, pos);
- #else
- return CALL_REAL (fsetpos64)(stream, pos);
- #endif
- }
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- #if ARCH(Intel) && WSIZE(32)
- ret = (real_fsetpos64) (stream, pos);
- #else
- ret = CALL_REAL (fsetpos64)(stream, pos);
- #endif
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret == 0)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- iopkt.fd = fileno (stream);
- #if ARCH(Intel)
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt);
- #else
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- #endif
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- #endif
- /*------------------------------------------------------------- fsync */
- int
- fsync (int fildes)
- {
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (fsync))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (fsync)(fildes);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (fsync)(fildes);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret == 0)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- readdir */
- struct dirent*
- readdir (DIR *dirp)
- {
- int *guard;
- struct dirent *ptr;
- IOTrace_packet iopkt;
- if (NULL_PTR (readdir))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (readdir)(dirp);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ptr = CALL_REAL (readdir)(dirp);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ptr;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet));
- iopkt.comm.tsize = sizeof ( IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ptr != NULL)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ptr;
- }
- /*------------------------------------------------------------- flock */
- int
- flock (int fd, int operation)
- {
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (flock))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (flock)(fd, operation);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (flock)(fd, operation);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret == 0)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- iopkt.fd = fd;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
- /*------------------------------------------------------------- lockf */
- int
- lockf (int fildes, int function, off_t size)
- {
- int *guard;
- int ret;
- IOTrace_packet iopkt;
- if (NULL_PTR (lockf))
- init_io_intf ();
- if (CHCK_REENTRANCE (guard))
- return CALL_REAL (lockf)(fildes, function, size);
- PUSH_REENTRANCE (guard);
- hrtime_t reqt = gethrtime ();
- ret = CALL_REAL (lockf)(fildes, function, size);
- if (RECHCK_REENTRANCE (guard))
- {
- POP_REENTRANCE (guard);
- return ret;
- }
- hrtime_t grnt = gethrtime ();
- collector_memset (&iopkt, 0, sizeof (IOTrace_packet));
- iopkt.comm.tsize = sizeof (IOTrace_packet);
- iopkt.comm.tstamp = grnt;
- iopkt.requested = reqt;
- if (ret == 0)
- iopkt.iotype = OTHERIO_TRACE;
- else
- iopkt.iotype = OTHERIO_TRACE_ERROR;
- iopkt.fd = fildes;
- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt);
- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt);
- POP_REENTRANCE (guard);
- return ret;
- }
|