merged freebsd changes from @ptomulik,
this PR goes after freebsd PR.