Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Unified Diff: util/test/multiprocess_exec_test_child.cc

Issue 808493003: win: port multiprocess_exec_test_child.cc (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: ws Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: util/test/multiprocess_exec_test_child.cc
diff --git a/util/test/multiprocess_exec_test_child.cc b/util/test/multiprocess_exec_test_child.cc
index e1a06122ed1779d9cf1d33b125505053c1e1979c..7e8525c67e5ef95c29a2e43d1eac1f25c390d256 100644
--- a/util/test/multiprocess_exec_test_child.cc
+++ b/util/test/multiprocess_exec_test_child.cc
@@ -17,11 +17,19 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
-#include <unistd.h>
#include <algorithm>
+#include "build/build_config.h"
+
+#if defined(OS_POSIX)
+#include <unistd.h>
+#elif defined(OS_WIN)
+#include <windows.h>
+#endif
+
int main(int argc, char* argv[]) {
+#if defined(OS_POSIX)
// Make sure that there’s nothing open at any FD higher than 3. All FDs other
// than stdin, stdout, and stderr should have been closed prior to or at
// exec().
@@ -47,5 +55,41 @@ int main(int argc, char* argv[]) {
abort();
}
+#elif defined(OS_WIN)
+
+ // Make sure there's nothing open other than stdin, stdout, and stderr.
+ HANDLE handle_stdin = GetStdHandle(STD_INPUT_HANDLE);
+ HANDLE handle_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ HANDLE handle_stderr = GetStdHandle(STD_ERROR_HANDLE);
+ // Handles can theoretically go as high as 2^32-4, but in practice they're
Mark Mentovai 2015/01/08 17:20:20 I thought Windows had an API to do this a little m
Mark Mentovai 2015/01/08 17:20:20 Blank line before the comment, to make it easier t
scottmg 2015/01/08 18:15:53 Sure, I actually used that at first based on https
+ // never that large, so we check only up to 2^16.
+ for (uintptr_t handle_int = 4; handle_int <= 0xffff; handle_int += 4) {
+ HANDLE handle = reinterpret_cast<HANDLE>(handle_int);
+ if (handle == handle_stdin || handle == handle_stdout ||
+ handle == handle_stderr)
+ continue;
Mark Mentovai 2015/01/08 17:20:20 {} me (the condition takes up more than one line,
scottmg 2015/01/08 18:15:53 Removed.
+ if (CloseHandle(handle)) {
Mark Mentovai 2015/01/08 17:20:20 Can CloseHandle() fail for a reason other than an
scottmg 2015/01/08 18:15:53 I don't know of any reason, but there are so many
+ abort();
+ }
+ }
+
+ // Read a byte from stdin, expecting it to be a specific value.
+ char c;
+ DWORD bytes_read;
+ if (!ReadFile(handle_stdin, &c, 1, &bytes_read, nullptr) || bytes_read != 1 ||
+ c != 'z') {
+ abort();
+ }
+
+ // Write a byte to stdout.
+ c = 'Z';
+ DWORD bytes_written;
+ if (!WriteFile(handle_stdout, &c, 1, &bytes_written, nullptr) ||
+ bytes_written != 1) {
+ abort();
+ }
+
+#endif // OS_POSIX
+
return 0;
}
« no previous file with comments | « util/test/multiprocess_exec_test.cc ('k') | util/util.gyp » ('j') | util/util.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698