Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LoadLibrary Reference Counting

From MSDN:

The system maintains a per-process reference count on all loaded modules. Calling LoadLibrary increments the reference count.

Where is that reference count stored?

like image 502
mrduclaw Avatar asked Sep 28 '10 04:09

mrduclaw


People also ask

What is LoadLibrary?

LoadLibrary can be used to load a library module into the address space of the process and return a handle that can be used in GetProcAddress to get the address of a DLL function. LoadLibrary can also be used to load other executable modules.

Which DLL is LoadLibrary?

Kernel32. dll is loaded into every Windows process, and within it is a useful function called LoadLibrary .


1 Answers

The actual windows loader is found in NTDLL.dll's LdrLoadDll function. This function is undocumented, and its internal functionality is subject to change in future versions of windows; only those with access to the windows source code could state for certain what happens behind the scenes.

However, wine's source is available, and you can see where it increments the reference count; it's stored in the LoadCount member of the LDR_MODULE heap structure. Since this doesn't seem to be a wine-internal structure, it's likely that this structure is based off the real, reverse-engineered windows structures, and thus windows probably stores it in the same way. However, since this is undocumented, it is subject to change in any future version of windows, or even with minor windows patches.

like image 180
bdonlan Avatar answered Sep 23 '22 22:09

bdonlan