var H: THandle;
begin
Application.Initialize;
H := LoadPackage('vclimg160.bpl');
Application.Run;
UnloadPackage(H);
Application.ProcessMessages;
end.
I build the project with Delphi XE2 update 4 (16.0.4429.46931) running under Windows 7 x64. These are the settings to build the projects:
1. using FastMM 4.991
2. I rebuild the FastMM_FullDebugMode.dll.
3. Build the project with runtime packages
4. Build the project FastMM full debug mode.
I then run the project with delphi debugger (pressing F9). It is not easy to get to the error, you may want to keep pressing the F9 key for about 1 minutes in order to get the error prompt out:
Project SQLAlpha.exe raised exception class $C00000005 with message "access violation at 0x006b68d1: read of address 0x004616db"
The debugger stop at line 277 of FastMM_FullDebugMode.dpr:
Module Load: SQLAlpha.exe. No Debug Info. Base Address: $00400000. Process SQLAlpha.exe (5856)
Module Load: ntdll.dll. No Debug Info. Base Address: $77300000. Process SQLAlpha.exe (5856)
Module Load: KERNEL32.dll. No Debug Info. Base Address: $75980000. Process SQLAlpha.exe (5856)
Module Load: KERNELBASE.dll. No Debug Info. Base Address: $75930000. Process SQLAlpha.exe (5856)
Module Load: rtl160.bpl. Has Debug Info. Base Address: $50030000. Process SQLAlpha.exe (5856)
Module Load: OLEAUT32.dll. No Debug Info. Base Address: $768F0000. Process SQLAlpha.exe (5856)
Module Load: ole32.dll. No Debug Info. Base Address: $74B80000. Process SQLAlpha.exe (5856)
Module Load: msvcrt.dll. No Debug Info. Base Address: $75F40000. Process SQLAlpha.exe (5856)
Module Load: GDI32.dll. No Debug Info. Base Address: $75CE0000. Process SQLAlpha.exe (5856)
Module Load: USER32.dll. No Debug Info. Base Address: $75AF0000. Process SQLAlpha.exe (5856)
Module Load: ADVAPI32.dll. No Debug Info. Base Address: $76170000. Process SQLAlpha.exe (5856)
Module Load: SECHOST.dll. No Debug Info. Base Address: $75AD0000. Process SQLAlpha.exe (5856)
Module Load: RPCRT4.dll. No Debug Info. Base Address: $765B0000. Process SQLAlpha.exe (5856)
Module Load: SspiCli.dll. No Debug Info. Base Address: $749F0000. Process SQLAlpha.exe (5856)
Module Load: CRYPTBASE.dll. No Debug Info. Base Address: $749E0000. Process SQLAlpha.exe (5856)
Module Load: LPK.dll. No Debug Info. Base Address: $76480000. Process SQLAlpha.exe (5856)
Module Load: USP10.dll. No Debug Info. Base Address: $74A50000. Process SQLAlpha.exe (5856)
Module Load: VERSION.dll. No Debug Info. Base Address: $73420000. Process SQLAlpha.exe (5856)
Module Load: MPR.dll. No Debug Info. Base Address: $717F0000. Process SQLAlpha.exe (5856)
Module Load: imagehlp.dll. No Debug Info. Base Address: $76980000. Process SQLAlpha.exe (5856)
Module Load: SHFOLDER.dll. No Debug Info. Base Address: $71FF0000. Process SQLAlpha.exe (5856)
Module Load: SHELL32.dll. No Debug Info. Base Address: $74CE0000. Process SQLAlpha.exe (5856)
Module Load: SHLWAPI.dll. No Debug Info. Base Address: $76270000. Process SQLAlpha.exe (5856)
Module Load: WSOCK32.dll. No Debug Info. Base Address: $732E0000. Process SQLAlpha.exe (5856)
Module Load: WS2_32.dll. No Debug Info. Base Address: $75A90000. Process SQLAlpha.exe (5856)
Module Load: NSI.dll. No Debug Info. Base Address: $76100000. Process SQLAlpha.exe (5856)
Module Load: OLEACC.dll. No Debug Info. Base Address: $6EE90000. Process SQLAlpha.exe (5856)
Module Load: ODBC32.dll. No Debug Info. Base Address: $72630000. Process SQLAlpha.exe (5856)
Module Load: FastMM_FullDebugMode.dll. Has Debug Info. Base Address: $00680000. Process SQLAlpha.exe (5856)
Module Load: vcl160.bpl. Has Debug Info. Base Address: $50300000. Process SQLAlpha.exe (5856)
Module Load: MSIMG32.dll. No Debug Info. Base Address: $6F3D0000. Process SQLAlpha.exe (5856)
Module Load: COMCTL32.dll. No Debug Info. Base Address: $6F0F0000. Process SQLAlpha.exe (5856)
Module Load: COMDLG32.dll. No Debug Info. Base Address: $763F0000. Process SQLAlpha.exe (5856)
Module Load: WINSPOOL.DRV. No Debug Info. Base Address: $71710000. Process SQLAlpha.exe (5856)
Module Load: oledlg.dll. No Debug Info. Base Address: $6F370000. Process SQLAlpha.exe (5856)
Module Load: IMM32.dll. No Debug Info. Base Address: $76110000. Process SQLAlpha.exe (5856)
Module Load: MSCTF.dll. No Debug Info. Base Address: $75C10000. Process SQLAlpha.exe (5856)
Module Load: UNKNOWN_MODULE_31654. No Debug Info. Base Address: $725E0000. Process SQLAlpha.exe (5856)
Module Load: UxTheme.dll. No Debug Info. Base Address: $720C0000. Process SQLAlpha.exe (5856)
Module Load: tiptsf.dll. No Debug Info. Base Address: $71CB0000. Process SQLAlpha.exe (5856)
Module Load: dwmapi.dll. No Debug Info. Base Address: $720A0000. Process SQLAlpha.exe (5856)
Module Load: WTSAPI32.dll. No Debug Info. Base Address: $72FA0000. Process SQLAlpha.exe (5856)
Module Load: WINSTA.dll. No Debug Info. Base Address: $72070000. Process SQLAlpha.exe (5856)
Module Load: vclimg160.bpl. Has Debug Info. Base Address: $00460000. Process SQLAlpha.exe (5856)
Module Load: WINMM.dll. No Debug Info. Base Address: $73270000. Process SQLAlpha.exe (5856)
Module Unload: vclimg160.bpl. Process SQLAlpha.exe (5856)
Module Unload: WINMM.dll. Process SQLAlpha.exe (5856)
Do you have any ideas why the errors raised? Thank you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Exceptions in that code is normal. It is possible for an address to become invalid between the time that the memory map is built and a pointer into a seemingly valid address is dereferenced. You'll see that any access violations there are trapped, and if one occurs then the memory map is rebuilt.
Best regards,
Pierre
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Pierre, this access violation occurs always if main application load and unload dll (compiled with AttemptToUseSharedMM define). After unload dll (FreeLibrary API) access violation occurs on next GetMem's call of main application. My project has this problem only on Delphi XE4 (i have upgraded from Delphi XE).
How can we rebuild memory map manually without exceptions? Such function will be useful after unload dll or bpl for prevention AV in debugger.
If it AV is really need - can you make named Exception class (for example EFastMMError) instead of access violation? We can put this class name in ignore list of debugger exception.
Now i found workaround - access violation does not occur if undefine "RawStackTraces".
May be it's really solution? :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Now i found workaround - access violation does not occur if undefine
"RawStackTraces".
May be it's really solution? :)
The exceptions are unavoidable when using raw stack traces, since it
will inevitably try to access invalid addresses while trying to
construct the stack trace. If you disable raw stack traces then you
will not get the (handled) exceptions, but your stack traces may also
not be as complete.
Best regards,
Pierre
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
this is a old thread but actually I have the same problem with FastMM4991.
If I call LoadLibrary (a brand new created delphi DLL with FastMM and no other code) and directly after that FreeLibrary than the application (EXE) runs a little bit but crashed after a while with an access violation (crash at very different positions in the code, in the most cases while reading dfm resource of mainform). The exception reason is always a call into the function GetStackTrace.
If I don't call FreeLibrary than it's fine.
If I call FreeLibrary but without use RawStackTraces (FastMM4Options.inc) than it seems to be also fine.
I did not exactly understand your explanation for the problem. But it sucks really...
It is possible (and useful) to run all memory allocations inside a DLL without RawStackTraces but for the Main application it is still active?
Best regards
ma2xx
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a simple application:
program SQLAlpha;
uses
FastMM4,
SysUtils,
Vcl.Forms;
var H: THandle;
begin
Application.Initialize;
H := LoadPackage('vclimg160.bpl');
Application.Run;
UnloadPackage(H);
Application.ProcessMessages;
end.
I build the project with Delphi XE2 update 4 (16.0.4429.46931) running under Windows 7 x64. These are the settings to build the projects:
1. using FastMM 4.991
2. I rebuild the FastMM_FullDebugMode.dll.
3. Build the project with runtime packages
4. Build the project FastMM full debug mode.
I then run the project with delphi debugger (pressing F9). It is not easy to get to the error, you may want to keep pressing the F9 key for about 1 minutes in order to get the error prompt out:
Project SQLAlpha.exe raised exception class $C00000005 with message "access violation at 0x006b68d1: read of address 0x004616db"
The debugger stop at line 277 of FastMM_FullDebugMode.dpr:
Line 277: if PByteArray(LCallAddress) = $E8 then
Here is the stacks when exception raised:
FastMM_FullDebugMode.IsValidCallSite(???)
FastMM_FullDebugMode.GetRawStackTrace($7EF9FAEC,9,0)
:00403d3e ; C:\Users\coder\Project\output.d16\earth\Win32\debug\SQLAlpha.exe
rtl.System._ReallocMem(???,???)
:50037af5 @ReallocMem + $45
rtl.System._DynArraySetLength
rtl.System.Classes.TList.SetCapacity(???)
:500418c6 @DynArraySetLength + $A
:75b0946a ; C:\Windows\syswow64\USER32.dll
:75b0d1e5 USER32.EnumWindows + 0x16
vcl.Vcl.Forms.TApplication.DoShowOwnedPopups(???)
:50451eec TApplication.DoShowOwnedPopups + $3C
:7599339a kernel32.BaseThreadInitThunk + 0x12
:77339ed2 ntdll.RtlInitializeExceptionChain + 0x63
:77339ea5 ntdll.RtlInitializeExceptionChain + 0x36
and this is the module messages in Delphi IDE:
Module Load: SQLAlpha.exe. No Debug Info. Base Address: $00400000. Process SQLAlpha.exe (5856)
Module Load: ntdll.dll. No Debug Info. Base Address: $77300000. Process SQLAlpha.exe (5856)
Module Load: KERNEL32.dll. No Debug Info. Base Address: $75980000. Process SQLAlpha.exe (5856)
Module Load: KERNELBASE.dll. No Debug Info. Base Address: $75930000. Process SQLAlpha.exe (5856)
Module Load: rtl160.bpl. Has Debug Info. Base Address: $50030000. Process SQLAlpha.exe (5856)
Module Load: OLEAUT32.dll. No Debug Info. Base Address: $768F0000. Process SQLAlpha.exe (5856)
Module Load: ole32.dll. No Debug Info. Base Address: $74B80000. Process SQLAlpha.exe (5856)
Module Load: msvcrt.dll. No Debug Info. Base Address: $75F40000. Process SQLAlpha.exe (5856)
Module Load: GDI32.dll. No Debug Info. Base Address: $75CE0000. Process SQLAlpha.exe (5856)
Module Load: USER32.dll. No Debug Info. Base Address: $75AF0000. Process SQLAlpha.exe (5856)
Module Load: ADVAPI32.dll. No Debug Info. Base Address: $76170000. Process SQLAlpha.exe (5856)
Module Load: SECHOST.dll. No Debug Info. Base Address: $75AD0000. Process SQLAlpha.exe (5856)
Module Load: RPCRT4.dll. No Debug Info. Base Address: $765B0000. Process SQLAlpha.exe (5856)
Module Load: SspiCli.dll. No Debug Info. Base Address: $749F0000. Process SQLAlpha.exe (5856)
Module Load: CRYPTBASE.dll. No Debug Info. Base Address: $749E0000. Process SQLAlpha.exe (5856)
Module Load: LPK.dll. No Debug Info. Base Address: $76480000. Process SQLAlpha.exe (5856)
Module Load: USP10.dll. No Debug Info. Base Address: $74A50000. Process SQLAlpha.exe (5856)
Module Load: VERSION.dll. No Debug Info. Base Address: $73420000. Process SQLAlpha.exe (5856)
Module Load: MPR.dll. No Debug Info. Base Address: $717F0000. Process SQLAlpha.exe (5856)
Module Load: imagehlp.dll. No Debug Info. Base Address: $76980000. Process SQLAlpha.exe (5856)
Module Load: SHFOLDER.dll. No Debug Info. Base Address: $71FF0000. Process SQLAlpha.exe (5856)
Module Load: SHELL32.dll. No Debug Info. Base Address: $74CE0000. Process SQLAlpha.exe (5856)
Module Load: SHLWAPI.dll. No Debug Info. Base Address: $76270000. Process SQLAlpha.exe (5856)
Module Load: WSOCK32.dll. No Debug Info. Base Address: $732E0000. Process SQLAlpha.exe (5856)
Module Load: WS2_32.dll. No Debug Info. Base Address: $75A90000. Process SQLAlpha.exe (5856)
Module Load: NSI.dll. No Debug Info. Base Address: $76100000. Process SQLAlpha.exe (5856)
Module Load: OLEACC.dll. No Debug Info. Base Address: $6EE90000. Process SQLAlpha.exe (5856)
Module Load: ODBC32.dll. No Debug Info. Base Address: $72630000. Process SQLAlpha.exe (5856)
Module Load: FastMM_FullDebugMode.dll. Has Debug Info. Base Address: $00680000. Process SQLAlpha.exe (5856)
Module Load: vcl160.bpl. Has Debug Info. Base Address: $50300000. Process SQLAlpha.exe (5856)
Module Load: MSIMG32.dll. No Debug Info. Base Address: $6F3D0000. Process SQLAlpha.exe (5856)
Module Load: COMCTL32.dll. No Debug Info. Base Address: $6F0F0000. Process SQLAlpha.exe (5856)
Module Load: COMDLG32.dll. No Debug Info. Base Address: $763F0000. Process SQLAlpha.exe (5856)
Module Load: WINSPOOL.DRV. No Debug Info. Base Address: $71710000. Process SQLAlpha.exe (5856)
Module Load: oledlg.dll. No Debug Info. Base Address: $6F370000. Process SQLAlpha.exe (5856)
Module Load: IMM32.dll. No Debug Info. Base Address: $76110000. Process SQLAlpha.exe (5856)
Module Load: MSCTF.dll. No Debug Info. Base Address: $75C10000. Process SQLAlpha.exe (5856)
Module Load: UNKNOWN_MODULE_31654. No Debug Info. Base Address: $725E0000. Process SQLAlpha.exe (5856)
Module Load: UxTheme.dll. No Debug Info. Base Address: $720C0000. Process SQLAlpha.exe (5856)
Module Load: tiptsf.dll. No Debug Info. Base Address: $71CB0000. Process SQLAlpha.exe (5856)
Module Load: dwmapi.dll. No Debug Info. Base Address: $720A0000. Process SQLAlpha.exe (5856)
Module Load: WTSAPI32.dll. No Debug Info. Base Address: $72FA0000. Process SQLAlpha.exe (5856)
Module Load: WINSTA.dll. No Debug Info. Base Address: $72070000. Process SQLAlpha.exe (5856)
Module Load: vclimg160.bpl. Has Debug Info. Base Address: $00460000. Process SQLAlpha.exe (5856)
Module Load: WINMM.dll. No Debug Info. Base Address: $73270000. Process SQLAlpha.exe (5856)
Module Unload: vclimg160.bpl. Process SQLAlpha.exe (5856)
Module Unload: WINMM.dll. Process SQLAlpha.exe (5856)
Do you have any ideas why the errors raised? Thank you.
Hi,
Exceptions in that code is normal. It is possible for an address to become invalid between the time that the memory map is built and a pointer into a seemingly valid address is dereferenced. You'll see that any access violations there are trapped, and if one occurs then the memory map is rebuilt.
Best regards,
Pierre
Hi,
Pierre, this access violation occurs always if main application load and unload dll (compiled with AttemptToUseSharedMM define). After unload dll (FreeLibrary API) access violation occurs on next GetMem's call of main application. My project has this problem only on Delphi XE4 (i have upgraded from Delphi XE).
How can we rebuild memory map manually without exceptions? Such function will be useful after unload dll or bpl for prevention AV in debugger.
If it AV is really need - can you make named Exception class (for example EFastMMError) instead of access violation? We can put this class name in ignore list of debugger exception.
Now i found workaround - access violation does not occur if undefine "RawStackTraces".
May be it's really solution? :)
Hi,
The exceptions are unavoidable when using raw stack traces, since it
will inevitably try to access invalid addresses while trying to
construct the stack trace. If you disable raw stack traces then you
will not get the (handled) exceptions, but your stack traces may also
not be as complete.
Best regards,
Pierre
Hi Pierre,
this is a old thread but actually I have the same problem with FastMM4991.
If I call LoadLibrary (a brand new created delphi DLL with FastMM and no other code) and directly after that FreeLibrary than the application (EXE) runs a little bit but crashed after a while with an access violation (crash at very different positions in the code, in the most cases while reading dfm resource of mainform). The exception reason is always a call into the function GetStackTrace.
If I don't call FreeLibrary than it's fine.
If I call FreeLibrary but without use RawStackTraces (FastMM4Options.inc) than it seems to be also fine.
I did not exactly understand your explanation for the problem. But it sucks really...
It is possible (and useful) to run all memory allocations inside a DLL without RawStackTraces but for the Main application it is still active?
Best regards
ma2xx