Fix random crash on Mavericks 64-bit. Backport slightly modified version of https://github.com/mono/mono/commit/978e4ebbd66b231fa6e4f8b32451b87d447bfcf2 and https://github.com/mono/mono/commit/7c85c560ea935b28c5e8492b1a0f6d5e6fe3c14e