[MLton] cygwoes
   
    Mike Thomas
     
    miketh@paradigmgeo.com
       
    Wed, 5 Oct 2005 11:34:58 +1000
    
    
  
Hi Matthew, Stephen and Tom.
I haven't been following this closely but a quick look at your memory
management code suggests that if you try the following function you may
get a better idea of what is causing your problem.
The function just gets the last Windows error and converts that into a
text message.  Usually those messages are extremely helpful.
You can use it in any error situation under Windows.
| SO, it certainly appears that we are passing a VirtualAlloc 
| address to VirtualFree.  Still, I was suspicious of 
| requesting a specific starting address; if I change line 1319 
| of gc.c from
|                          h->start = GC_mmapAnon 
| ((void*)address, h->size); to
|                          h->start = GC_mmapAnon ((void*)NULL, 
| h->size); (i.e., ignoring the scan of the virtual address 
| space), then the VirtualFree failure disappears and the 
| mlton-compile executable terminates normally.
===========================================================
/* example of how to use PrintError () with VirtualFree. */
if ( 0 == VirtualFree ( start, 0, MEM_RELEASE ) ) {
     PrintError ( "VirtualFree" );
}
void PrintError ( LPTSTR lpszFunction ) { 
    TCHAR szBuf[80]; 
    LPVOID lpMsgBuf;
    DWORD dw = GetLastError(); 
    FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER | 
                    FORMAT_MESSAGE_FROM_SYSTEM,
                    NULL,
                    dw,
                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                    (LPTSTR) &lpMsgBuf,
                    0, NULL );
    fprintf ( stderr, 
              "%s failed with error %d: %s", 
              lpszFunction, dw, lpMsgBuf ); 
 
    LocalFree(lpMsgBuf);
    /*ExitProcess(dw); */
}
===========================================================
Cheers
Mike Thomas.