iotrace.c 112 KB

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