This does still contain some FreeBSD-specific bits, but it's a pain to do partial diffs. R=rsc https://golang.org/cl/152138