Pierre le Riche 21 Posted Friday at 07:40 PM (edited) Hi, For performance reasons I am caching a map of the address space in the stack tracing code inside FastMM_FullDebugMode.dll. This map goes stale whenever a library is loaded or unloaded, and I've been dealing with this rather crudely: by handling the ensuing access violations in a try...except block. These access violations can be quite annoying when running the application under the debugger, so I would like to make them less likely. Invalidating the map whenever a library is loaded or unloaded would be an improvement. I've therefore been looking at ways to be notified when a library is loaded or unloaded, but the only solution I have found is patching the LoadLibrary and FreeLibrary calls in kernel32.dll in-memory to insert a hook. Is there a better strategy? The mechanism doesn't have to be 100% accurate, so if there's a proxy for LoadLibrary and FreeLibrary that is less invasive I would rather go for that. Thanks, Pierre Edited Friday at 07:41 PM by Pierre le Riche Share this post Link to post
Anders Melander 2030 Posted yesterday at 12:45 AM LdrRegisterDllNotification (Vista+) LdrInitShimEngineDynamic (undocumented, XP+ AFAIK) 2 Share this post Link to post
Pierre le Riche 21 Posted 15 hours ago Thanks Anders, I think I'll go with the LdrRegisterDllNotification option. The Vista+ restriction shouldn't be a big deal, since I only need to deal with the exceptions under a debugger and I can't imagine too many developers are still using Windows XP. I see there's a note "[This function may be changed or removed from Windows without further notice.]" in the documentation, so I'll implement it in such a way that it doesn't crash if it it is not available. Best regards, Pierre Share this post Link to post