diff --git a/libcxx/include/__mbstate_t.h b/libcxx/include/__mbstate_t.h
index 2b9e719b1f2e..044c10a58c04 100644
--- a/libcxx/include/__mbstate_t.h
+++ b/libcxx/include/__mbstate_t.h
@@ -42,7 +42,10 @@
 #elif __has_include(<bits/types/mbstate_t.h>)
 #   include <bits/types/mbstate_t.h> // works on most Unixes
 #elif __has_include(<sys/_types/_mbstate_t.h>)
-#   include <sys/_types/_mbstate_t.h> // works on Darwin
+#  if __has_include(<machine/_types.h>)
+#    include <machine/_types.h>
+#  endif
+#  include <sys/_types/_mbstate_t.h> // works on Darwin
 #elif !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) && __has_include_next(<wchar.h>)
 #   include_next <wchar.h> // fall back to the C standard provider of mbstate_t
 #elif __has_include_next(<uchar.h>)
