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

Side by Side Diff: test/mac/mach_multiprocess.cc

Issue 1405273002: Mach port scopers should use get() instead of type conversion operators (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: More is_valid() Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « handler/mac/exception_handler_server.cc ('k') | tools/mac/catch_exception_tool.cc » ('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 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 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,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 // Set up the parent port and register it with the bootstrap server before 92 // Set up the parent port and register it with the bootstrap server before
93 // forking, so that it’s guaranteed to be there when the child attempts to 93 // forking, so that it’s guaranteed to be there when the child attempts to
94 // look it up. 94 // look it up.
95 info_->service_name = "com.googlecode.crashpad.test.mach_multiprocess."; 95 info_->service_name = "com.googlecode.crashpad.test.mach_multiprocess.";
96 for (int index = 0; index < 16; ++index) { 96 for (int index = 0; index < 16; ++index) {
97 info_->service_name.append(1, base::RandInt('A', 'Z')); 97 info_->service_name.append(1, base::RandInt('A', 'Z'));
98 } 98 }
99 99
100 info_->local_port = BootstrapCheckIn(info_->service_name); 100 info_->local_port = BootstrapCheckIn(info_->service_name);
101 ASSERT_NE(kMachPortNull, info_->local_port); 101 ASSERT_TRUE(info_->local_port.is_valid());
102 } 102 }
103 103
104 mach_port_t MachMultiprocess::LocalPort() const { 104 mach_port_t MachMultiprocess::LocalPort() const {
105 EXPECT_NE(kMachPortNull, info_->local_port); 105 EXPECT_TRUE(info_->local_port.is_valid());
106 return info_->local_port; 106 return info_->local_port.get();
107 } 107 }
108 108
109 mach_port_t MachMultiprocess::RemotePort() const { 109 mach_port_t MachMultiprocess::RemotePort() const {
110 EXPECT_NE(kMachPortNull, info_->remote_port); 110 EXPECT_TRUE(info_->remote_port.is_valid());
111 return info_->remote_port; 111 return info_->remote_port.get();
112 } 112 }
113 113
114 task_t MachMultiprocess::ChildTask() const { 114 task_t MachMultiprocess::ChildTask() const {
115 EXPECT_NE(TASK_NULL, info_->child_task); 115 EXPECT_TRUE(info_->child_task.is_valid());
116 return info_->child_task; 116 return info_->child_task.get();
117 } 117 }
118 118
119 void MachMultiprocess::MultiprocessParent() { 119 void MachMultiprocess::MultiprocessParent() {
120 ReceiveHelloMessage message = {}; 120 ReceiveHelloMessage message = {};
121 121
122 kern_return_t kr = mach_msg(&message.header, 122 kern_return_t kr = mach_msg(&message.header,
123 MACH_RCV_MSG | kMachMessageReceiveAuditTrailer, 123 MACH_RCV_MSG | kMachMessageReceiveAuditTrailer,
124 0, 124 0,
125 sizeof(message), 125 sizeof(message),
126 info_->local_port, 126 info_->local_port.get(),
127 MACH_MSG_TIMEOUT_NONE, 127 MACH_MSG_TIMEOUT_NONE,
128 MACH_PORT_NULL); 128 MACH_PORT_NULL);
129 ASSERT_EQ(MACH_MSG_SUCCESS, kr) << MachErrorMessage(kr, "mach_msg"); 129 ASSERT_EQ(MACH_MSG_SUCCESS, kr) << MachErrorMessage(kr, "mach_msg");
130 130
131 // Comb through the entire message, checking every field against its expected 131 // Comb through the entire message, checking every field against its expected
132 // value. 132 // value.
133 EXPECT_EQ(MACH_MSGH_BITS(MACH_MSG_TYPE_MOVE_SEND, MACH_MSG_TYPE_MOVE_SEND) | 133 EXPECT_EQ(MACH_MSGH_BITS(MACH_MSG_TYPE_MOVE_SEND, MACH_MSG_TYPE_MOVE_SEND) |
134 MACH_MSGH_BITS_COMPLEX, 134 MACH_MSGH_BITS_COMPLEX,
135 message.header.msgh_bits); 135 message.header.msgh_bits);
136 ASSERT_EQ(sizeof(SendHelloMessage), message.header.msgh_size); 136 ASSERT_EQ(sizeof(SendHelloMessage), message.header.msgh_size);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 EXPECT_EQ(audit_info.ai_auid, audit_auid); 191 EXPECT_EQ(audit_info.ai_auid, audit_auid);
192 EXPECT_EQ(audit_info.ai_asid, audit_asid); 192 EXPECT_EQ(audit_info.ai_asid, audit_asid);
193 193
194 // Retrieve the remote port from the message header, and the child’s task port 194 // Retrieve the remote port from the message header, and the child’s task port
195 // from the message body. 195 // from the message body.
196 info_->remote_port.reset(message.header.msgh_remote_port); 196 info_->remote_port.reset(message.header.msgh_remote_port);
197 info_->child_task.reset(message.port_descriptor.name); 197 info_->child_task.reset(message.port_descriptor.name);
198 198
199 // Verify that the child’s task port is what it purports to be. 199 // Verify that the child’s task port is what it purports to be.
200 int mach_pid; 200 int mach_pid;
201 kr = pid_for_task(info_->child_task, &mach_pid); 201 kr = pid_for_task(info_->child_task.get(), &mach_pid);
202 ASSERT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "pid_for_task"); 202 ASSERT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "pid_for_task");
203 ASSERT_EQ(ChildPID(), mach_pid); 203 ASSERT_EQ(ChildPID(), mach_pid);
204 204
205 MachMultiprocessParent(); 205 MachMultiprocessParent();
206 206
207 info_->remote_port.reset(); 207 info_->remote_port.reset();
208 info_->local_port.reset(); 208 info_->local_port.reset();
209 } 209 }
210 210
211 void MachMultiprocess::MultiprocessChild() { 211 void MachMultiprocess::MultiprocessChild() {
(...skipping 10 matching lines...) Expand all
222 ASSERT_NE(kMachPortNull, info_->remote_port); 222 ASSERT_NE(kMachPortNull, info_->remote_port);
223 223
224 // The “hello” message will provide the parent with its remote port, a send 224 // The “hello” message will provide the parent with its remote port, a send
225 // right to the child task’s local port receive right. It will also carry a 225 // right to the child task’s local port receive right. It will also carry a
226 // send right to the child task’s task port. 226 // send right to the child task’s task port.
227 SendHelloMessage message = {}; 227 SendHelloMessage message = {};
228 message.header.msgh_bits = 228 message.header.msgh_bits =
229 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND) | 229 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND) |
230 MACH_MSGH_BITS_COMPLEX; 230 MACH_MSGH_BITS_COMPLEX;
231 message.header.msgh_size = sizeof(message); 231 message.header.msgh_size = sizeof(message);
232 message.header.msgh_remote_port = info_->remote_port; 232 message.header.msgh_remote_port = info_->remote_port.get();
233 message.header.msgh_local_port = info_->local_port; 233 message.header.msgh_local_port = info_->local_port.get();
234 message.body.msgh_descriptor_count = 1; 234 message.body.msgh_descriptor_count = 1;
235 message.port_descriptor.name = mach_task_self(); 235 message.port_descriptor.name = mach_task_self();
236 message.port_descriptor.disposition = MACH_MSG_TYPE_COPY_SEND; 236 message.port_descriptor.disposition = MACH_MSG_TYPE_COPY_SEND;
237 message.port_descriptor.type = MACH_MSG_PORT_DESCRIPTOR; 237 message.port_descriptor.type = MACH_MSG_PORT_DESCRIPTOR;
238 238
239 kern_return_t kr = mach_msg(&message.header, 239 kern_return_t kr = mach_msg(&message.header,
240 MACH_SEND_MSG, 240 MACH_SEND_MSG,
241 message.header.msgh_size, 241 message.header.msgh_size,
242 0, 242 0,
243 MACH_PORT_NULL, 243 MACH_PORT_NULL,
(...skipping 18 matching lines...) Expand all
262 if (testing::Test::HasFailure()) { 262 if (testing::Test::HasFailure()) {
263 // Trigger the ScopedForbidReturn destructor. 263 // Trigger the ScopedForbidReturn destructor.
264 return; 264 return;
265 } 265 }
266 266
267 forbid_return.Disarm(); 267 forbid_return.Disarm();
268 } 268 }
269 269
270 } // namespace test 270 } // namespace test
271 } // namespace crashpad 271 } // namespace crashpad
OLDNEW
« no previous file with comments | « handler/mac/exception_handler_server.cc ('k') | tools/mac/catch_exception_tool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698