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

Unified Diff: test/win/child_launcher.cc

Issue 1352323002: win: Make reading NT_IMAGE_HEADERS work cross-bitness (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@cleanup-crashpad-info
Patch Set: . Created 5 years, 3 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: test/win/child_launcher.cc
diff --git a/test/win/child_launcher.cc b/test/win/child_launcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..153db9f086a4c45b6fc9b7bb4291a140230f1186
--- /dev/null
+++ b/test/win/child_launcher.cc
@@ -0,0 +1,71 @@
+// Copyright 2015 The Crashpad Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "test/win/child_launcher.h"
+
+#include "gtest/gtest.h"
+
+namespace crashpad {
+
+ChildLauncher::ChildLauncher(const std::wstring& executable,
+ const std::wstring& command_line)
+ : executable_(executable),
+ command_line_(command_line),
+ process_handle_(),
+ main_thread_handle_(),
+ stdout_read_handle_() {
+}
+
+ChildLauncher::~ChildLauncher() {
+ EXPECT_EQ(WAIT_OBJECT_0,
+ WaitForSingleObject(process_handle_.get(), INFINITE));
+}
+
+void ChildLauncher::Start() {
+ // Create a pipe for the stdout of the child.
+ SECURITY_ATTRIBUTES security_attributes = {0};
+ security_attributes.nLength = sizeof(SECURITY_ATTRIBUTES);
+ security_attributes.bInheritHandle = true;
+ HANDLE stdout_read;
+ HANDLE stdout_write;
+ ASSERT_TRUE(CreatePipe(&stdout_read, &stdout_write, &security_attributes, 0));
+ stdout_read_handle_.reset(stdout_read);
Mark Mentovai 2015/09/19 03:02:47 ASSERT_FALSE(stdout_read_handle_) first to ensure
scottmg 2015/09/19 04:24:41 Done.
+ ScopedFileHANDLE write_handle(stdout_write);
+ ASSERT_TRUE(
+ SetHandleInformation(stdout_read_handle_.get(), HANDLE_FLAG_INHERIT, 0));
+
+ STARTUPINFO startup_info = {0};
+ startup_info.cb = sizeof(startup_info);
+ startup_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
+ startup_info.hStdOutput = write_handle.get();
+ startup_info.hStdError = GetStdHandle(STD_ERROR_HANDLE);
+ startup_info.dwFlags = STARTF_USESTDHANDLES;
+ PROCESS_INFORMATION process_information;
+ std::wstring command_line = executable_ + L" " + command_line_;
Mark Mentovai 2015/09/19 03:02:47 Some sort of escaping (CRT-compatible, I guess) sh
scottmg 2015/09/19 04:24:41 Done.
+ ASSERT_TRUE(CreateProcess(executable_.c_str(),
+ &command_line[0],
+ nullptr,
+ nullptr,
+ true,
+ 0,
+ nullptr,
+ nullptr,
+ &startup_info,
+ &process_information));
+ // Take ownership of the two process handles returned.
+ main_thread_handle_.reset(process_information.hThread);
+ process_handle_.reset(process_information.hProcess);
+}
+
+} // namespace crashpad

Powered by Google App Engine
This is Rietveld 408576698