Cherry-pick 0f6ea33044177c470cc77f3b6fe19d6a1cc7ac63 from mfsbsd