[fpc-devel] Manual reload of a DLL snapshot (with relocations) causes multiple AV

Sven Barth pascaldragon at googlemail.com
Fri Jan 6 18:16:43 CET 2012

On 06.01.2012 15:07, Gennadiy Poryev wrote:
> First, I'd like to know why calling of DLL entry point anew does not
> re-initialize _all_ RTL internals regardless of what was remembered
> prior to taking the snapshot. Is it just assuming good behavior of
> system loader that carefully zeroes data segment while I don't?

The point is: why should a DLL that is used normally take special care 
of this? The normal lifetime of a DLL is
* DLL is loaded by LoadLibrary
* Windows calls DLL entrypoint with PROCESS_ATTACH
* DLL is used
* DLL is unloaded by FreeLibrary
* Windows calls DLL entrypoint with PROCESS_DETACH
* DLL is gone from memory

If now the process loads that DLL again after a PROCESS_DETACH it runs 
the complete PROCESS_ATTACH again.

I have to admit though that I don't know either why the "StackLength", 
"StackBottom" parts work...

Thinking about this a bit... it might be that there is still the TLS 
value set to a value <> Nil. Thus the RTL will reference the old values 
which are no longer valid. I'd suggest you to take a look at 
%fpcdir%/rtl/win/systhrd.inc and there SysRelocateThreadVar. It's just a 
guess though.


More information about the fpc-devel mailing list