Make base::Pipe windows friendly

For now support only blocking modes. Non-blocking I/O is
too semantically different. In the long run we might even
sunset base::Pipe given its low usage. For now make it build
so that the unittests that use that in blocking mode can
work.

Bug: 174454879
Change-Id: I3f3c553c638638e7991e5b46064081c2a5fba058
diff --git a/src/base/pipe.cc b/src/base/pipe.cc
index c61492f..adc7be3 100644
--- a/src/base/pipe.cc
+++ b/src/base/pipe.cc
@@ -14,13 +14,17 @@
  * limitations under the License.
  */
 
-#include "perfetto/base/build_config.h"
-#if !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
-
 #include "perfetto/ext/base/pipe.h"
 
+#include "perfetto/base/build_config.h"
+
+#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
+#include <io.h>
+#else
+#include <fcntl.h>
 #include <sys/types.h>
 #include <unistd.h>
+#endif
 
 #include "perfetto/base/logging.h"
 
@@ -33,14 +37,18 @@
 
 Pipe Pipe::Create(Flags flags) {
   int fds[2];
+#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
+  PERFETTO_CHECK(_pipe(fds, 256, O_BINARY) == 0);
+#else
   PERFETTO_CHECK(pipe(fds) == 0);
+  PERFETTO_CHECK(fcntl(fds[0], F_SETFD, FD_CLOEXEC) == 0);
+  PERFETTO_CHECK(fcntl(fds[1], F_SETFD, FD_CLOEXEC) == 0);
+#endif
   Pipe p;
   p.rd.reset(fds[0]);
   p.wr.reset(fds[1]);
 
-  PERFETTO_CHECK(fcntl(*p.rd, F_SETFD, FD_CLOEXEC) == 0);
-  PERFETTO_CHECK(fcntl(*p.wr, F_SETFD, FD_CLOEXEC) == 0);
-
+#if !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
   if (flags == kBothNonBlock || flags == kRdNonBlock) {
     int cur_flags = fcntl(*p.rd, F_GETFL, 0);
     PERFETTO_CHECK(cur_flags >= 0);
@@ -52,10 +60,11 @@
     PERFETTO_CHECK(cur_flags >= 0);
     PERFETTO_CHECK(fcntl(*p.wr, F_SETFL, cur_flags | O_NONBLOCK) == 0);
   }
+#else
+  PERFETTO_CHECK(flags == kBothBlock);
+#endif
   return p;
 }
 
 }  // namespace base
 }  // namespace perfetto
-
-#endif  // !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)