Fixes required to build hw on freebsd

I've posted these patches on IRC some time ago, but they seem to have been forgotten