[MLton] Re: cygwoes
Matthew Fluet
fluet@cs.cornell.edu
Tue, 11 Oct 2005 23:02:17 -0400 (EDT)
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--1417689696-1005246318-1129086137=:5095
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
> I did a little more investigating of the Virtual{Alloc,Free} problems over
> the weekend, and I'm mostly convinced that (at least through Cygwin), they
> are not working as advertised by the API. I've got more info at home that
> I'll try to post this evening.
Here is a quick little program that replicates the relevant parts of gc.c
and platform/windows.c that call VirtualAlloc with a non-NULL starting
address. When I run it under Cygwin, I get:
start = 0x60000000 size = 8192
Error: VirtualFree failed with error 87: The parameter is incorrect.
start = 0x60000000 size = 16384
Error: VirtualFree failed with error 87: The parameter is incorrect.
start = 0x18000000 size = 32768
Error: VirtualFree failed with error 487: Attempt to access invalid address.
start = 0x18000000 size = 65536
Error: VirtualFree failed with error 487: Attempt to access invalid address.
start = 0x18000000 size = 131072
Error: VirtualFree failed with error 487: Attempt to access invalid address.
start = 0x18000000 size = 262144
Error: VirtualFree failed with error 487: Attempt to access invalid address.
start = 0x18000000 size = 524288
Error: VirtualFree failed with error 487: Attempt to access invalid address.
start = 0x18000000 size = 1048576
Error: VirtualFree failed with error 487: Attempt to access invalid address.
start = 0x18000000 size = 2097152
Error: VirtualFree failed with error 487: Attempt to access invalid address.
start = 0x18000000 size = 4194304
Error: VirtualFree failed with error 487: Attempt to access invalid address.
start = 0x10000000 size = 8388608
Error: VirtualFree failed with error 487: Attempt to access invalid address.
start = 0x10000000 size = 16777216
Error: VirtualFree failed with error 487: Attempt to access invalid address.
start = 0x10000000 size = 33554432
Error: VirtualFree failed with error 487: Attempt to access invalid address.
start = 0x10000000 size = 67108864
Error: VirtualFree failed with error 487: Attempt to access invalid address.
start = 0x10000000 size = 134217728
Error: VirtualFree failed with error 487: Attempt to access invalid address.
start = 0x08000000 size = 268435456
Error: VirtualFree failed with error 487: Attempt to access invalid address.
Yet, all the program does is immediately VirtualFree the memory returned
by VirtualAlloc. As best I can tell, this behavior is not consistent with
the API. If any of the more Windows savvy programmers can see why this is
the appropriate behavior, we'd like to know. I'm also interested if
anyone could try to compile and run the program as a native Windows
application (i.e., not through Cygwin). I'm curious to see if the same
behavior is also observed there.
If I change the call to VirtualAlloc to take NULL as the starting address,
I get:
start = 0x18b70000 size = 8192
start = 0x18b70000 size = 16384
start = 0x18b70000 size = 32768
start = 0x18b70000 size = 65536
start = 0x18b70000 size = 131072
start = 0x18b70000 size = 262144
start = 0x18b70000 size = 524288
start = 0x18b70000 size = 1048576
start = 0x18b70000 size = 2097152
start = 0x18b70000 size = 4194304
start = 0x18b70000 size = 8388608
start = 0x18b70000 size = 16777216
start = 0x18b70000 size = 33554432
start = 0x18b70000 size = 67108864
start = 0x18b70000 size = 134217728
start = 0x18b70000 size = 268435456
--1417689696-1005246318-1129086137=:5095
Content-Type: TEXT/PLAIN; charset=US-ASCII; name=vm.c
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.62.0510112302170.5095@lion.cs.cornell.edu>
Content-Description:
Content-Disposition: attachment; filename=vm.c
I2luY2x1ZGUgPHN0ZGJvb2wuaD4NCiNpbmNsdWRlIDxzdGRpby5oPg0KI2lu
Y2x1ZGUgPHdpbmRvd3MuaD4NCg0KI2RlZmluZSBERUJVRyAwDQoNCnN0YXRp
YyB2b2lkIFdpbmRvd3NfcHJpbnRFcnJvciAoTFBUU1RSIGxwc3pGdW5jdGlv
bikgew0KICAgIFRDSEFSIHN6QnVmWzgwXTsgDQogICAgTFBWT0lEIGxwTXNn
QnVmOw0KICAgIERXT1JEIGR3ID0gR2V0TGFzdEVycm9yKCk7IA0KDQogICAg
Rm9ybWF0TWVzc2FnZSgNCiAgICAgICAgRk9STUFUX01FU1NBR0VfQUxMT0NB
VEVfQlVGRkVSIHwgDQogICAgICAgIEZPUk1BVF9NRVNTQUdFX0ZST01fU1lT
VEVNLA0KICAgICAgICBOVUxMLA0KICAgICAgIC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