Portability fixes

Dear Mono developers,

I have written my own hobby operating system (homemade kernel and libc) and successfully ported Mono 3.4.0 to it [1]. You have done a fairly good job making the code portable to new operating systems, though I did run into a number of minor issues that I had to patch around. This change set fixes a number of portability problems and minor issues that occur when porting to new standards-compliant operating systems. I'm happy to notice that some of my issues have already been independently fixed in git master (and are thus not included in this pull request).

These patches were originally developed against the 3.4.0 release, I have attempted to forward port them to git master. You will likely wish to carefully review them as a few of the patches are crude and a better solution would be desirable. Feel free to chery-pick the useful commits and adapt them to your needs.

I have included more detailed commentary in each commit message. 

Cheers,
Jonas

[1] https://users-cs.au.dk/sortie/sortix/screenshots/sortix-mono-mcs-hello-world.png