17 May 2006

windows equivalent

In almost all flavours of unix (those which run glibc i think all flavours i know of use glibc.however there might be some which dont!) there is a unique feature (if i can call that as that). There is something called LD_PRELOAD. By using this, you can write your own version of a system library (say for example fopen, fclose etc) and make your programs use it instead of the normal glibc calls, by loading this library using the LD_PRELOAD.
The question is, are there any windows equivalents for this ? Do drop in a line or a comment if you know of one. Conversley, do you have any idea how the bounds checkers in windows work ? That might give me some ideas too.
K.Shyam

Posted by Shyam Krishnaswamy at 12:05 PM

5 Comments

  1. Blogger Shree Kumar posted at Wednesday, May 17, 2006 at 7:27:00 PM GMT+5:30  
    Nope, no Windows equivalent for LD_PRELOAD.

    The key difference is that, in Windows, you can see that a specific symbol is imported from a specific DLL. Try dumpbin /imports to see a list of which symbol is imported from which library. *NIX OSes have concepts of symbols, but there is no way to figure out who provides them. Whoever first satisfies a symbol wins... That's why LD_PRELOAD works !

    A related technique in Windows is called "DLL Thunking" but is fairly involved. Try a Google search ;-) You might bump on an old DDJ article...
  2. Blogger K.Shyam posted at Thursday, May 18, 2006 at 4:30:00 PM GMT+5:30  
    shree: i knew windows sucked but i never knew it sucked this much :-) i was trying to write up a memory manager when i fell into this block !
    K.Shyam
  3. Blogger Suraj posted at Thursday, May 18, 2006 at 4:30:00 PM GMT+5:30  
    A minor technical nit-pick: The LD_PRELOAD feature has nothing to do with using glibc. It has to do with 'ld' (which finds libraries (from LD_LIBRARY_PATH, /etc/ld.so.cache, etc.,.) resolves symbols and maps the correct functions.

    btw, one set of examples for famous unix systems that doesn't using GNU libc: *BSDs :) Remember? Both GNU and *BSD started evolving at almost the same time (with different goals, of course) :)
  4. Blogger Shree Kumar posted at Thursday, May 18, 2006 at 6:06:00 PM GMT+5:30  
    Suraj : Nit-pick on top of nit-pick - I don't remember Solaris (supports LD_PRELOAD) using /etc/ld.so.cache :-)

    Shyam : As long as you don't try to debug some memory related issue using your memory manager, you should be fine. But if memory debugging is your goal, you will find good tools. If they don't work for you, then write your own and let us all know :-)
  5. Blogger K.Shyam posted at Friday, May 19, 2006 at 10:22:00 AM GMT+5:30  
    suraj : ya i am aware of that thing called BSD :-)
    shree : solaris now supports gnu ld. so as long as the ld used is gnu's there should not be a problem.
    as i have said in my next post, the intent was not to write a memory debugger.so sorry about that shree :-) in any case even if i need one, valgrind for x86 is always there.

Post a Comment

« Home