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

Side by Side Diff: test/win/win_child_process.cc

Issue 1422503015: win: Add HandleToInt() and IntToHandle() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Add a comment about the choice of int over unsigned int Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « handler/main.cc ('k') | util/util.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "test/win/win_child_process.h" 15 #include "test/win/win_child_process.h"
16 16
17 #include <windows.h> 17 #include <windows.h>
18 #include <shellapi.h> 18 #include <shellapi.h>
19 19
20 #include <string> 20 #include <string>
21 21
22 #include "base/logging.h" 22 #include "base/logging.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
25 #include "gtest/gtest.h" 25 #include "gtest/gtest.h"
26 #include "util/stdlib/string_number_conversion.h" 26 #include "util/stdlib/string_number_conversion.h"
27 #include "util/string/split_string.h" 27 #include "util/string/split_string.h"
28 #include "util/win/handle.h"
28 #include "test/paths.h" 29 #include "test/paths.h"
29 30
30 namespace crashpad { 31 namespace crashpad {
31 namespace test { 32 namespace test {
32 33
33 namespace { 34 namespace {
34 35
35 const char kIsMultiprocessChild[] = "--is-multiprocess-child"; 36 const char kIsMultiprocessChild[] = "--is-multiprocess-child";
36 struct LocalFreeTraits { 37 struct LocalFreeTraits {
37 static HLOCAL InvalidValue() { return nullptr; } 38 static HLOCAL InvalidValue() { return nullptr; }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 CHECK(GetSwitch(kIsMultiprocessChild, &switch_value)); 146 CHECK(GetSwitch(kIsMultiprocessChild, &switch_value));
146 147
147 // Set up the handles we inherited from the parent. These are inherited from 148 // Set up the handles we inherited from the parent. These are inherited from
148 // the parent and so are open and have the same value as in the parent. The 149 // the parent and so are open and have the same value as in the parent. The
149 // values are passed to the child on the command line. 150 // values are passed to the child on the command line.
150 std::string left, right; 151 std::string left, right;
151 CHECK(SplitString(switch_value, '|', &left, &right)); 152 CHECK(SplitString(switch_value, '|', &left, &right));
152 unsigned int write, read; 153 unsigned int write, read;
153 CHECK(StringToNumber(left, &write)); 154 CHECK(StringToNumber(left, &write));
154 CHECK(StringToNumber(right, &read)); 155 CHECK(StringToNumber(right, &read));
155 pipe_write_.reset(reinterpret_cast<HANDLE>(static_cast<uintptr_t>(write))); 156 pipe_write_.reset(IntToHandle(write));
156 pipe_read_.reset(reinterpret_cast<HANDLE>(static_cast<uintptr_t>(read))); 157 pipe_read_.reset(IntToHandle(read));
157 158
158 // Notify the parent that it's OK to proceed. We only need to wait to get to 159 // Notify the parent that it's OK to proceed. We only need to wait to get to
159 // the process entry point, but this is the easiest place we can notify. 160 // the process entry point, but this is the easiest place we can notify.
160 char c = ' '; 161 char c = ' ';
161 CheckedWriteFile(WritePipeHandle(), &c, sizeof(c)); 162 CheckedWriteFile(WritePipeHandle(), &c, sizeof(c));
162 } 163 }
163 164
164 // static 165 // static
165 bool WinChildProcess::IsChildProcess() { 166 bool WinChildProcess::IsChildProcess() {
166 return GetSwitch(kIsMultiprocessChild, nullptr); 167 return GetSwitch(kIsMultiprocessChild, nullptr);
(...skipping 19 matching lines...) Expand all
186 // Build a command line for the child process that tells it only to run the 187 // Build a command line for the child process that tells it only to run the
187 // current test, and to pass down the values of the pipe handles. 188 // current test, and to pass down the values of the pipe handles.
188 const ::testing::TestInfo* const test_info = 189 const ::testing::TestInfo* const test_info =
189 ::testing::UnitTest::GetInstance()->current_test_info(); 190 ::testing::UnitTest::GetInstance()->current_test_info();
190 std::wstring command_line = 191 std::wstring command_line =
191 Paths::Executable().value() + L" " + 192 Paths::Executable().value() + L" " +
192 base::UTF8ToUTF16(base::StringPrintf("--gtest_filter=%s.%s %s=0x%x|0x%x", 193 base::UTF8ToUTF16(base::StringPrintf("--gtest_filter=%s.%s %s=0x%x|0x%x",
193 test_info->test_case_name(), 194 test_info->test_case_name(),
194 test_info->name(), 195 test_info->name(),
195 kIsMultiprocessChild, 196 kIsMultiprocessChild,
196 write_for_child, 197 HandleToInt(write_for_child.get()),
197 read_for_child.get())); 198 HandleToInt(read_for_child.get())));
198 199
199 // Command-line buffer cannot be constant, per CreateProcess signature. 200 // Command-line buffer cannot be constant, per CreateProcess signature.
200 handles_for_parent->process = LaunchCommandLine(&command_line[0]); 201 handles_for_parent->process = LaunchCommandLine(&command_line[0]);
201 if (!handles_for_parent->process.is_valid()) 202 if (!handles_for_parent->process.is_valid())
202 return scoped_ptr<Handles>(); 203 return scoped_ptr<Handles>();
203 204
204 // Block until the child process has launched. CreateProcess() returns 205 // Block until the child process has launched. CreateProcess() returns
205 // immediately, and test code expects process initialization to have 206 // immediately, and test code expects process initialization to have
206 // completed so it can, for example, read the process memory. 207 // completed so it can, for example, read the process memory.
207 char c; 208 char c;
(...skipping 21 matching lines...) Expand all
229 void WinChildProcess::CloseReadPipe() { 230 void WinChildProcess::CloseReadPipe() {
230 pipe_read_.reset(); 231 pipe_read_.reset();
231 } 232 }
232 233
233 void WinChildProcess::CloseWritePipe() { 234 void WinChildProcess::CloseWritePipe() {
234 pipe_write_.reset(); 235 pipe_write_.reset();
235 } 236 }
236 237
237 } // namespace test 238 } // namespace test
238 } // namespace crashpad 239 } // namespace crashpad
OLDNEW
« no previous file with comments | « handler/main.cc ('k') | util/util.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698