From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,9a21435408b1ee59 X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2001-08-20 12:17:45 PST Path: archiver1.google.com!newsfeed.google.com!postnews1.google.com!not-for-mail From: kerry@yahoo.com (Kerry Kopp) Newsgroups: comp.unix.tru64 Subject: Re: Library Interposition on Tru64? Date: 20 Aug 2001 12:17:44 -0700 Organization: http://groups.google.com/ Message-ID: <72ee5672.0108201117.1a78e1b6@posting.google.com> References: <72ee5672.0108150029.3999fa91@posting.google.com> <72ee5672.0108151842.5cdac734@posting.google.com> NNTP-Posting-Host: 207.175.94.220 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 998335065 6460 127.0.0.1 (20 Aug 2001 19:17:45 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 20 Aug 2001 19:17:45 GMT Xref: archiver1.google.com comp.unix.tru64:4291 kerry@yahoo.com (Kerry Kopp) wrote in message news:<72ee5672.0108151842.5cdac734@posting.google.com>... > Dan Riley wrote in message news:... > > > > However, I don't see an obvious equivalent to RTLD_NEXT. > > Hmmmm, crud. I've seen some docs about iterating over the various > symbols (on Solaris, of course), so I'll try and figure out if that's > possible. (Although I'm hoping that someone out there knows how to do > it... :) ) Allllrighty, I figured it out, sort of. It's not as auto-magic as RTLD_NEXT, but hey, it works. :) /* * Example of a library interposer on DEC/Tru64: interpose on malloc(). * (Tested on 4.0F, Rev 1229) * Build and use this interposer as following: * 1) compile the shared lib * % cc -o malloc_interposer.so -shared malloc_interposer.c * 2) tell the interposer the nameof the real library that has the function * that we are interposing. For malloc(), this is libc.so. (This is done * as an environment variable so that it can be changed at runtime) * Note: you don't need a full path, as the loader will resolve it for you. * % setenv INTERPOSE_TARGET_LIB libc.so * 3) Tell the loader to look in our library first, then the default libs. * (This is the equivalent to LD_PRELOAD on Solaris) * % setenv _RLD_LIST $cwd/malloc_interposer.so:DEFAULT * 4) Run the app as normal. See the pretty printouts. * 5) Turn off the interposition if needed * % unsetenv _RLD_LIST * * In theory, maybe we should dlclose the shared lib that we are opening, but, * well, this is an example, right? :) * Created from Solaris interposition examples, some research, and a little help * from Dan Riley on Usenet, 8/16/2001, Kerry Kopp kerry@yahoo.com */ #include /* For printf() */ #include /* For dlopen(), dlsym() */ #include /* For getenv() */ /* The environment var that has the real library we want */ #define LIB_PATH_ENV_VAR "INTERPOSE_TARGET_LIB" void *malloc(size_t size) { static void * (*func)(); char * libPath = NULL; void * handle = NULL; libPath = getenv(LIB_PATH_ENV_VAR); if ( !libPath ) { printf("LibPath is null, bailing\n"); return NULL; } handle = dlopen(libPath, RTLD_NOW); if ( !handle ) { printf("Handle is null, bailing.\n"); return NULL; } if(!func) { func = (void *(*)()) dlsym(handle, "malloc"); } printf("malloc(%d) was called\n", size); return(func(size)); }