Move rustrt::last_os_error into core

Rewrote the last pull request (#4859) to not require on llvm for core.

Also fixes #2269.