[MLton] A few patches we had to apply to port from version 20030716 to 20051202 and for the MinGW port

Matthew Fluet fluet at tti-c.org
Thu Mar 29 18:48:01 PST 2007


>> - bug-fix-solaris7.patch
>>
>> This patch is needed to build the MLton runtime when the gcc compiler 
>> is designed to produce code for Solaris 7 because the headers do not 
>> provide the definition for MAP_ANON IPv6.
> 
> Also, I don't think it's a good idea to use 'char dummy' as the contents 
> of sockaddr_in6. A real IPv6 structure is much larger, leading to a 
> potential overrun. Also, it is guaranteed that sizeof(sockaddr_storage) 
>  >= sizeof(sockaddr_*). Is sockaddr_in really the largest? sockaddr_in6 
> is usually bigger. Are these structures missing from headers or missing 
> from the system's support?

I should note that the Basis Library doesn't actually provide any IPv6 
functionality; any reference to sockaddr_in6 in the Basis Library 
implementation (either the C-side or the ML-side) is purely in the 
interest of future expansion.

Nonetheless, it is the case that the ML-side of the Basis Library 
allocates a Word8Array.array with length sizeof(sockaddr_storage) (see 
runtime/basis/Net/Socket/Socket-consts.c and 
basis-library/net/socket.sml) to be initialized with socket address 
information.  So, a potential overrun is a real concern.  Indeed, I see 
the following:

amd64-linux:
sizeof(struct sockaddr_storage) = 128
sizeof(struct sockaddr_in) = 16
sizeof(struct sockaddr_in6) = 28
sizeof(struct sockaddr_un) = 110

x86-darwin:
sizeof(struct sockaddr_storage) = 128
sizeof(struct sockaddr_in) = 16
sizeof(struct sockaddr_in6) = 28
sizeof(struct sockaddr_un) = 106

x86-cygwin:
sizeof(struct sockaddr_storage) = 128
sizeof(struct sockaddr_in) = 16
sizeof(struct sockaddr_un) = 110

So, using unix sockets on a platform with
#define sockaddr_storage sockaddr_in
will most likely cause problems.

I've checked in a revision that replaces the above with
struct sockaddr_storage {
   union {
     struct sockaddr_in sa_in;
     struct sockaddr_un sa_un;
   } sa;
}

>>  - bug-fix-nethostdb-mingw.patch
>>
>>  This patch fixes the NetHostDB functions getByAddress(), getByName() 
>> and getHostName()  which fail to work properly if the WinSock2 DLL has 
>> not been initialized before we call them.
> I see that other parts of the basis are doing this as well. Therefore, I 
> see no harm in putting these calls into those methods.
> 
> However, on another note, shouldn't we be calling this ONCE from the 
> main method? I seem to recall it used to work this way? What happened?

The initialization occurs only once; the MLton_initSockets function (see 
runtime/platform/mingw.c) includes a static variable that ensures that 
WSAStartup is only called once.





More information about the MLton mailing list