[GHC] #7612: Automatically start the haskell runtime in DllMain on windows -shared

GHC cvs-ghc at haskell.org
Mon Jan 21 09:35:18 CET 2013


#7612: Automatically start the haskell runtime in DllMain on windows -shared
----------------------------+-----------------------------------------------
Reporter:  schyler          |          Owner:                  
    Type:  feature request  |         Status:  new             
Priority:  normal           |      Component:  Compiler        
 Version:  7.6.1            |       Keywords:                  
      Os:  Windows          |   Architecture:  Unknown/Multiple
 Failure:  None/Unknown     |      Blockedby:                  
Blocking:                   |        Related:                  
----------------------------+-----------------------------------------------
 On Windows DllMain is called when a dll is loaded into a process via
 LoadLibrary (or even when it's loaded as a regular dependency).

 Currently a stub, such as this, is required to be linked with all haskell
 dll compilations on windows that plan to have their functions called from
 non-haskell origins;

 {{{
 #include <windows.h>
 #include <Rts.h>

 EXTFUN(__stginit_Adder);

 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_Adder);
       return TRUE;
   }
   return TRUE;
 }
 }}}
 see outdated documentation, but still mostly applicable:
 http://www.haskell.org/ghc/docs/5.04/html/users_guide/win32-dlls-
 foreign.html

 I personally think this is a tad silly and could be easily improved.
 Ideally, DllMain should automatically detect if the runtime is running,
 and if not, automatically start it up so that the dll's ordinals can all
 be called freely. This could be a stub automatically added by ghc when the
 windows -shared is used.

 An extension to this would be to add a pragma/flag to allow people to
 execute code inside DllMain (dllMain, a pragma, maybe?) after the runtime
 has started. One extremely easy way to do this would be to assume main as
 being :: Int -> IO Int where the first bound argument is the attach reason
 when windows -shared is used.

 This would GREATLY improve how easy it is to call haskell dll's from other
 languages, even .net origins, etc.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7612>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the ghc-tickets mailing list