GHC 6.4.1 and Win32 DLLs: Bug in shutdownHaskell?
Lennart Augustsson
lennart at augustsson.net
Fri Mar 3 08:02:02 EST 2006
The memory allocated by the runtime system is never freed.
I've submitted a fix fir this.
-- Lennart
Michael Marte wrote:
> Hello *,
>
> before filing a bug report, I want others to comment on my problem.
> Maybe it's my fault, not ghc's.
>
> I wrapped up some Haskell modules in a Win32 DLL.
> Loading the DLL dynamically (with LoadLibrary) works fine. However,
> whether I actually use the library or not, the program (an application
> with MFC GUI) crashes upon termination.
> To find the reason for the crash, I added a new function for unloading
> the DLL using FreeLibrary. FreeLibrary works fine, however the program
> crashes when it returns to the main event loop. Interestingly, when I
> reload the library (FreeLibrary followed by LoadLibrary) the program
> continues working. However, every reload cycle causes the virtual size
> of the process to increase by about 300K and the fourth reload fails
> with the error message "getMBlock: VirtualAlloc failed with: 8" (appears
> in a message window) accompanied by many repetitions of the message
> "Timer proc: wait failed -- error code: 6" (appears on stderr) and
> followed by the message "getMBlocks: misaligned block returned" (again
> in a message window). Then the programm crashes.
>
> Development takes place on Windows XP Professional using MS Visual
> Studio 6.0 SP 5 and ghc 6.4.1. There are no references from the C++ side
> to the Haskell heap. I build the DLL using the command
>
> ghc --mk-dll -optdll--def -optdllFoo.def -o Foo.dll Foo.o Foo_stub.o
> dllMain.c
>
> dllMain.c looks as follows:
>
> #include <windows.h>
> #include <Rts.h>
>
> extern void __stginit_EUzu3820zu85(void);
>
> static char* args[] = { "ghcDll", NULL };
> /* N.B. argv arrays must end with NULL */
> BOOL
> STDCALL
> DllMain(HANDLE hModule, DWORD reason, void* reserved) {
> if (reason == DLL_PROCESS_ATTACH) {
> /* By now, the RTS DLL should have been hoisted in, but we need
> to start it up. */
> startupHaskell(1, args, __stginit_Foo);
> return TRUE;
> } else if (reason == DLL_PROCESS_DETACH) {
> shutdownHaskell();
> }
> return TRUE;
> }
>
> I played around with hs_exit instead of shutdownHaskell, I moved
> initialization and clean-up from DllMain to my library loader, nothing
> helps. Even doing no clean-up whatsoever does not change the behaviour.
>
> Any ideas?
> Michael
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
More information about the Glasgow-haskell-users
mailing list