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

Side by Side Diff: util/mach/exc_server_variants_test.cc

Issue 755313004: Pass Mach message trailers to server handler functions (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Use REQUESTED_TRAILER_SIZE() Created 6 years 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 | « util/mach/exc_server_variants.cc ('k') | util/mach/exception_ports_test.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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // of the structures from both exc.h and mach_exc.h here in this file, and 75 // of the structures from both exc.h and mach_exc.h here in this file, and
76 // provide the initialization and verification code as methods in true 76 // provide the initialization and verification code as methods in true
77 // object-oriented fashion. 77 // object-oriented fashion.
78 78
79 struct __attribute__((packed, aligned(4))) ExceptionRaiseRequest { 79 struct __attribute__((packed, aligned(4))) ExceptionRaiseRequest {
80 ExceptionRaiseRequest() { 80 ExceptionRaiseRequest() {
81 memset(this, 0xa5, sizeof(*this)); 81 memset(this, 0xa5, sizeof(*this));
82 Head.msgh_bits = 82 Head.msgh_bits =
83 MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, MACH_MSG_TYPE_PORT_SEND) | 83 MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, MACH_MSG_TYPE_PORT_SEND) |
84 MACH_MSGH_BITS_COMPLEX; 84 MACH_MSGH_BITS_COMPLEX;
85 Head.msgh_size = sizeof(*this); 85 Head.msgh_size = sizeof(*this) - sizeof(trailer);
86 Head.msgh_remote_port = kClientRemotePort; 86 Head.msgh_remote_port = kClientRemotePort;
87 Head.msgh_local_port = kServerLocalPort; 87 Head.msgh_local_port = kServerLocalPort;
88 Head.msgh_id = 2401; 88 Head.msgh_id = 2401;
89 msgh_body.msgh_descriptor_count = 2; 89 msgh_body.msgh_descriptor_count = 2;
90 InitializeMachMsgPortDescriptor(&thread, kExceptionThreadPort); 90 InitializeMachMsgPortDescriptor(&thread, kExceptionThreadPort);
91 InitializeMachMsgPortDescriptor(&task, kExceptionTaskPort); 91 InitializeMachMsgPortDescriptor(&task, kExceptionTaskPort);
92 NDR = NDR_record; 92 NDR = NDR_record;
93 exception = kExceptionType; 93 exception = kExceptionType;
94 codeCnt = 2; 94 codeCnt = 2;
95 code[0] = kTestExceptonCodes[0]; 95 code[0] = kTestExceptonCodes[0];
96 code[1] = kTestExceptonCodes[1]; 96 code[1] = kTestExceptonCodes[1];
97 } 97 }
98 98
99 mach_msg_header_t Head; 99 mach_msg_header_t Head;
100 mach_msg_body_t msgh_body; 100 mach_msg_body_t msgh_body;
101 mach_msg_port_descriptor_t thread; 101 mach_msg_port_descriptor_t thread;
102 mach_msg_port_descriptor_t task; 102 mach_msg_port_descriptor_t task;
103 NDR_record_t NDR; 103 NDR_record_t NDR;
104 exception_type_t exception; 104 exception_type_t exception;
105 mach_msg_type_number_t codeCnt; 105 mach_msg_type_number_t codeCnt;
106 integer_t code[2]; 106 integer_t code[2];
107 mach_msg_trailer_t trailer;
107 }; 108 };
108 109
109 struct __attribute__((packed, aligned(4))) ExceptionRaiseReply { 110 struct __attribute__((packed, aligned(4))) ExceptionRaiseReply {
110 ExceptionRaiseReply() { 111 ExceptionRaiseReply() {
111 memset(this, 0x5a, sizeof(*this)); 112 memset(this, 0x5a, sizeof(*this));
112 RetCode = KERN_FAILURE; 113 RetCode = KERN_FAILURE;
113 } 114 }
114 115
115 // Verify accepts a |behavior| parameter because the same message format and 116 // Verify accepts a |behavior| parameter because the same message format and
116 // verification function is used for ExceptionRaiseReply and 117 // verification function is used for ExceptionRaiseReply and
(...skipping 25 matching lines...) Expand all
142 mach_msg_header_t Head; 143 mach_msg_header_t Head;
143 NDR_record_t NDR; 144 NDR_record_t NDR;
144 kern_return_t RetCode; 145 kern_return_t RetCode;
145 }; 146 };
146 147
147 struct __attribute__((packed, aligned(4))) ExceptionRaiseStateRequest { 148 struct __attribute__((packed, aligned(4))) ExceptionRaiseStateRequest {
148 ExceptionRaiseStateRequest() { 149 ExceptionRaiseStateRequest() {
149 memset(this, 0xa5, sizeof(*this)); 150 memset(this, 0xa5, sizeof(*this));
150 Head.msgh_bits = 151 Head.msgh_bits =
151 MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, MACH_MSG_TYPE_PORT_SEND); 152 MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, MACH_MSG_TYPE_PORT_SEND);
152 Head.msgh_size = sizeof(*this); 153 Head.msgh_size = sizeof(*this) - sizeof(trailer);
153 Head.msgh_remote_port = kClientRemotePort; 154 Head.msgh_remote_port = kClientRemotePort;
154 Head.msgh_local_port = kServerLocalPort; 155 Head.msgh_local_port = kServerLocalPort;
155 Head.msgh_id = 2402; 156 Head.msgh_id = 2402;
156 NDR = NDR_record; 157 NDR = NDR_record;
157 exception = kExceptionType; 158 exception = kExceptionType;
158 codeCnt = 2; 159 codeCnt = 2;
159 code[0] = kTestExceptonCodes[0]; 160 code[0] = kTestExceptonCodes[0];
160 code[1] = kTestExceptonCodes[1]; 161 code[1] = kTestExceptonCodes[1];
161 flavor = kThreadStateFlavor; 162 flavor = kThreadStateFlavor;
162 old_stateCnt = kThreadStateFlavorCount; 163 old_stateCnt = kThreadStateFlavorCount;
163 164
164 // Adjust the message size for the data that it’s actually carrying, which 165 // Adjust the message size for the data that it’s actually carrying, which
165 // may be smaller than the maximum that it can carry. 166 // may be smaller than the maximum that it can carry.
166 Head.msgh_size += sizeof(old_state[0]) * old_stateCnt - sizeof(old_state); 167 Head.msgh_size += sizeof(old_state[0]) * old_stateCnt - sizeof(old_state);
167 } 168 }
168 169
170 // Because the message size has been adjusted, the trailer may not appear in
171 // its home member variable. This computes the actual address of the trailer.
172 const mach_msg_trailer_t* Trailer() const {
Robert Sesek 2014/12/01 20:51:39 Why not use the function defined in mach_message_u
173 return reinterpret_cast<mach_msg_trailer_t*>(
174 reinterpret_cast<uintptr_t>(this) + Head.msgh_size);
175 }
176
169 mach_msg_header_t Head; 177 mach_msg_header_t Head;
170 NDR_record_t NDR; 178 NDR_record_t NDR;
171 exception_type_t exception; 179 exception_type_t exception;
172 mach_msg_type_number_t codeCnt; 180 mach_msg_type_number_t codeCnt;
173 integer_t code[2]; 181 integer_t code[2];
174 int flavor; 182 int flavor;
175 mach_msg_type_number_t old_stateCnt; 183 mach_msg_type_number_t old_stateCnt;
176 natural_t old_state[THREAD_STATE_MAX]; 184 natural_t old_state[THREAD_STATE_MAX];
185 mach_msg_trailer_t trailer;
177 }; 186 };
178 187
179 struct __attribute__((packed, aligned(4))) ExceptionRaiseStateReply { 188 struct __attribute__((packed, aligned(4))) ExceptionRaiseStateReply {
180 ExceptionRaiseStateReply() { 189 ExceptionRaiseStateReply() {
181 memset(this, 0x5a, sizeof(*this)); 190 memset(this, 0x5a, sizeof(*this));
182 RetCode = KERN_FAILURE; 191 RetCode = KERN_FAILURE;
183 } 192 }
184 193
185 // Verify accepts a |behavior| parameter because the same message format and 194 // Verify accepts a |behavior| parameter because the same message format and
186 // verification function is used for ExceptionRaiseStateReply, 195 // verification function is used for ExceptionRaiseStateReply,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 mach_msg_type_number_t new_stateCnt; 234 mach_msg_type_number_t new_stateCnt;
226 natural_t new_state[THREAD_STATE_MAX]; 235 natural_t new_state[THREAD_STATE_MAX];
227 }; 236 };
228 237
229 struct __attribute__((packed, aligned(4))) ExceptionRaiseStateIdentityRequest { 238 struct __attribute__((packed, aligned(4))) ExceptionRaiseStateIdentityRequest {
230 ExceptionRaiseStateIdentityRequest() { 239 ExceptionRaiseStateIdentityRequest() {
231 memset(this, 0xa5, sizeof(*this)); 240 memset(this, 0xa5, sizeof(*this));
232 Head.msgh_bits = 241 Head.msgh_bits =
233 MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, MACH_MSG_TYPE_PORT_SEND) | 242 MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, MACH_MSG_TYPE_PORT_SEND) |
234 MACH_MSGH_BITS_COMPLEX; 243 MACH_MSGH_BITS_COMPLEX;
235 Head.msgh_size = sizeof(*this); 244 Head.msgh_size = sizeof(*this) - sizeof(trailer);
236 Head.msgh_remote_port = kClientRemotePort; 245 Head.msgh_remote_port = kClientRemotePort;
237 Head.msgh_local_port = kServerLocalPort; 246 Head.msgh_local_port = kServerLocalPort;
238 Head.msgh_id = 2403; 247 Head.msgh_id = 2403;
239 msgh_body.msgh_descriptor_count = 2; 248 msgh_body.msgh_descriptor_count = 2;
240 InitializeMachMsgPortDescriptor(&thread, kExceptionThreadPort); 249 InitializeMachMsgPortDescriptor(&thread, kExceptionThreadPort);
241 InitializeMachMsgPortDescriptor(&task, kExceptionTaskPort); 250 InitializeMachMsgPortDescriptor(&task, kExceptionTaskPort);
242 NDR = NDR_record; 251 NDR = NDR_record;
243 exception = kExceptionType; 252 exception = kExceptionType;
244 codeCnt = 2; 253 codeCnt = 2;
245 code[0] = kTestExceptonCodes[0]; 254 code[0] = kTestExceptonCodes[0];
246 code[1] = kTestExceptonCodes[1]; 255 code[1] = kTestExceptonCodes[1];
247 flavor = kThreadStateFlavor; 256 flavor = kThreadStateFlavor;
248 old_stateCnt = kThreadStateFlavorCount; 257 old_stateCnt = kThreadStateFlavorCount;
249 258
250 // Adjust the message size for the data that it’s actually carrying, which 259 // Adjust the message size for the data that it’s actually carrying, which
251 // may be smaller than the maximum that it can carry. 260 // may be smaller than the maximum that it can carry.
252 Head.msgh_size += sizeof(old_state[0]) * old_stateCnt - sizeof(old_state); 261 Head.msgh_size += sizeof(old_state[0]) * old_stateCnt - sizeof(old_state);
253 } 262 }
254 263
264 // Because the message size has been adjusted, the trailer may not appear in
265 // its home member variable. This computes the actual address of the trailer.
266 const mach_msg_trailer_t* Trailer() const {
267 return reinterpret_cast<mach_msg_trailer_t*>(
268 reinterpret_cast<uintptr_t>(this) + Head.msgh_size);
269 }
270
255 mach_msg_header_t Head; 271 mach_msg_header_t Head;
256 mach_msg_body_t msgh_body; 272 mach_msg_body_t msgh_body;
257 mach_msg_port_descriptor_t thread; 273 mach_msg_port_descriptor_t thread;
258 mach_msg_port_descriptor_t task; 274 mach_msg_port_descriptor_t task;
259 NDR_record_t NDR; 275 NDR_record_t NDR;
260 exception_type_t exception; 276 exception_type_t exception;
261 mach_msg_type_number_t codeCnt; 277 mach_msg_type_number_t codeCnt;
262 integer_t code[2]; 278 integer_t code[2];
263 int flavor; 279 int flavor;
264 mach_msg_type_number_t old_stateCnt; 280 mach_msg_type_number_t old_stateCnt;
265 natural_t old_state[THREAD_STATE_MAX]; 281 natural_t old_state[THREAD_STATE_MAX];
282 mach_msg_trailer_t trailer;
266 }; 283 };
267 284
268 // The reply messages for exception_raise_state and 285 // The reply messages for exception_raise_state and
269 // exception_raise_state_identity are identical. 286 // exception_raise_state_identity are identical.
270 using ExceptionRaiseStateIdentityReply = ExceptionRaiseStateReply; 287 using ExceptionRaiseStateIdentityReply = ExceptionRaiseStateReply;
271 288
272 struct __attribute__((packed, aligned(4))) MachExceptionRaiseRequest { 289 struct __attribute__((packed, aligned(4))) MachExceptionRaiseRequest {
273 MachExceptionRaiseRequest() { 290 MachExceptionRaiseRequest() {
274 memset(this, 0xa5, sizeof(*this)); 291 memset(this, 0xa5, sizeof(*this));
275 Head.msgh_bits = 292 Head.msgh_bits =
276 MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, MACH_MSG_TYPE_PORT_SEND) | 293 MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, MACH_MSG_TYPE_PORT_SEND) |
277 MACH_MSGH_BITS_COMPLEX; 294 MACH_MSGH_BITS_COMPLEX;
278 Head.msgh_size = sizeof(*this); 295 Head.msgh_size = sizeof(*this) - sizeof(trailer);
279 Head.msgh_remote_port = kClientRemotePort; 296 Head.msgh_remote_port = kClientRemotePort;
280 Head.msgh_local_port = kServerLocalPort; 297 Head.msgh_local_port = kServerLocalPort;
281 Head.msgh_id = 2405; 298 Head.msgh_id = 2405;
282 msgh_body.msgh_descriptor_count = 2; 299 msgh_body.msgh_descriptor_count = 2;
283 InitializeMachMsgPortDescriptor(&thread, kExceptionThreadPort); 300 InitializeMachMsgPortDescriptor(&thread, kExceptionThreadPort);
284 InitializeMachMsgPortDescriptor(&task, kExceptionTaskPort); 301 InitializeMachMsgPortDescriptor(&task, kExceptionTaskPort);
285 NDR = NDR_record; 302 NDR = NDR_record;
286 exception = kExceptionType; 303 exception = kExceptionType;
287 codeCnt = 2; 304 codeCnt = 2;
288 code[0] = kTestMachExceptionCodes[0]; 305 code[0] = kTestMachExceptionCodes[0];
289 code[1] = kTestMachExceptionCodes[1]; 306 code[1] = kTestMachExceptionCodes[1];
290 } 307 }
291 308
292 mach_msg_header_t Head; 309 mach_msg_header_t Head;
293 mach_msg_body_t msgh_body; 310 mach_msg_body_t msgh_body;
294 mach_msg_port_descriptor_t thread; 311 mach_msg_port_descriptor_t thread;
295 mach_msg_port_descriptor_t task; 312 mach_msg_port_descriptor_t task;
296 NDR_record_t NDR; 313 NDR_record_t NDR;
297 exception_type_t exception; 314 exception_type_t exception;
298 mach_msg_type_number_t codeCnt; 315 mach_msg_type_number_t codeCnt;
299 int64_t code[2]; 316 int64_t code[2];
317 mach_msg_trailer_t trailer;
300 }; 318 };
301 319
302 // The reply messages for exception_raise and mach_exception_raise are 320 // The reply messages for exception_raise and mach_exception_raise are
303 // identical. 321 // identical.
304 using MachExceptionRaiseReply = ExceptionRaiseReply; 322 using MachExceptionRaiseReply = ExceptionRaiseReply;
305 323
306 struct __attribute__((packed, aligned(4))) MachExceptionRaiseStateRequest { 324 struct __attribute__((packed, aligned(4))) MachExceptionRaiseStateRequest {
307 MachExceptionRaiseStateRequest() { 325 MachExceptionRaiseStateRequest() {
308 memset(this, 0xa5, sizeof(*this)); 326 memset(this, 0xa5, sizeof(*this));
309 Head.msgh_bits = 327 Head.msgh_bits =
310 MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, MACH_MSG_TYPE_PORT_SEND); 328 MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, MACH_MSG_TYPE_PORT_SEND);
311 Head.msgh_size = sizeof(*this); 329 Head.msgh_size = sizeof(*this) - sizeof(trailer);
312 Head.msgh_remote_port = kClientRemotePort; 330 Head.msgh_remote_port = kClientRemotePort;
313 Head.msgh_local_port = kServerLocalPort; 331 Head.msgh_local_port = kServerLocalPort;
314 Head.msgh_id = 2406; 332 Head.msgh_id = 2406;
315 NDR = NDR_record; 333 NDR = NDR_record;
316 exception = kExceptionType; 334 exception = kExceptionType;
317 codeCnt = 2; 335 codeCnt = 2;
318 code[0] = kTestMachExceptionCodes[0]; 336 code[0] = kTestMachExceptionCodes[0];
319 code[1] = kTestMachExceptionCodes[1]; 337 code[1] = kTestMachExceptionCodes[1];
320 flavor = kThreadStateFlavor; 338 flavor = kThreadStateFlavor;
321 old_stateCnt = kThreadStateFlavorCount; 339 old_stateCnt = kThreadStateFlavorCount;
322 340
323 // Adjust the message size for the data that it’s actually carrying, which 341 // Adjust the message size for the data that it’s actually carrying, which
324 // may be smaller than the maximum that it can carry. 342 // may be smaller than the maximum that it can carry.
325 Head.msgh_size += sizeof(old_state[0]) * old_stateCnt - sizeof(old_state); 343 Head.msgh_size += sizeof(old_state[0]) * old_stateCnt - sizeof(old_state);
326 } 344 }
327 345
346 // Because the message size has been adjusted, the trailer may not appear in
347 // its home member variable. This computes the actual address of the trailer.
348 const mach_msg_trailer_t* Trailer() const {
349 return reinterpret_cast<mach_msg_trailer_t*>(
350 reinterpret_cast<uintptr_t>(this) + Head.msgh_size);
351 }
352
328 mach_msg_header_t Head; 353 mach_msg_header_t Head;
329 NDR_record_t NDR; 354 NDR_record_t NDR;
330 exception_type_t exception; 355 exception_type_t exception;
331 mach_msg_type_number_t codeCnt; 356 mach_msg_type_number_t codeCnt;
332 int64_t code[2]; 357 int64_t code[2];
333 int flavor; 358 int flavor;
334 mach_msg_type_number_t old_stateCnt; 359 mach_msg_type_number_t old_stateCnt;
335 natural_t old_state[THREAD_STATE_MAX]; 360 natural_t old_state[THREAD_STATE_MAX];
361 mach_msg_trailer_t trailer;
336 }; 362 };
337 363
338 // The reply messages for exception_raise_state and mach_exception_raise_state 364 // The reply messages for exception_raise_state and mach_exception_raise_state
339 // are identical. 365 // are identical.
340 using MachExceptionRaiseStateReply = ExceptionRaiseStateReply; 366 using MachExceptionRaiseStateReply = ExceptionRaiseStateReply;
341 367
342 struct __attribute__((packed, 368 struct __attribute__((packed,
343 aligned(4))) MachExceptionRaiseStateIdentityRequest { 369 aligned(4))) MachExceptionRaiseStateIdentityRequest {
344 MachExceptionRaiseStateIdentityRequest() { 370 MachExceptionRaiseStateIdentityRequest() {
345 memset(this, 0xa5, sizeof(*this)); 371 memset(this, 0xa5, sizeof(*this));
346 Head.msgh_bits = 372 Head.msgh_bits =
347 MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, MACH_MSG_TYPE_PORT_SEND) | 373 MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, MACH_MSG_TYPE_PORT_SEND) |
348 MACH_MSGH_BITS_COMPLEX; 374 MACH_MSGH_BITS_COMPLEX;
349 Head.msgh_size = sizeof(*this); 375 Head.msgh_size = sizeof(*this) - sizeof(trailer);
350 Head.msgh_remote_port = kClientRemotePort; 376 Head.msgh_remote_port = kClientRemotePort;
351 Head.msgh_local_port = kServerLocalPort; 377 Head.msgh_local_port = kServerLocalPort;
352 Head.msgh_id = 2407; 378 Head.msgh_id = 2407;
353 msgh_body.msgh_descriptor_count = 2; 379 msgh_body.msgh_descriptor_count = 2;
354 InitializeMachMsgPortDescriptor(&thread, kExceptionThreadPort); 380 InitializeMachMsgPortDescriptor(&thread, kExceptionThreadPort);
355 InitializeMachMsgPortDescriptor(&task, kExceptionTaskPort); 381 InitializeMachMsgPortDescriptor(&task, kExceptionTaskPort);
356 NDR = NDR_record; 382 NDR = NDR_record;
357 exception = kExceptionType; 383 exception = kExceptionType;
358 codeCnt = 2; 384 codeCnt = 2;
359 code[0] = kTestMachExceptionCodes[0]; 385 code[0] = kTestMachExceptionCodes[0];
360 code[1] = kTestMachExceptionCodes[1]; 386 code[1] = kTestMachExceptionCodes[1];
361 flavor = kThreadStateFlavor; 387 flavor = kThreadStateFlavor;
362 old_stateCnt = kThreadStateFlavorCount; 388 old_stateCnt = kThreadStateFlavorCount;
363 389
364 // Adjust the message size for the data that it’s actually carrying, which 390 // Adjust the message size for the data that it’s actually carrying, which
365 // may be smaller than the maximum that it can carry. 391 // may be smaller than the maximum that it can carry.
366 Head.msgh_size += sizeof(old_state[0]) * old_stateCnt - sizeof(old_state); 392 Head.msgh_size += sizeof(old_state[0]) * old_stateCnt - sizeof(old_state);
367 } 393 }
368 394
395 // Because the message size has been adjusted, the trailer may not appear in
396 // its home member variable. This computes the actual address of the trailer.
397 const mach_msg_trailer_t* Trailer() const {
398 return reinterpret_cast<mach_msg_trailer_t*>(
399 reinterpret_cast<uintptr_t>(this) + Head.msgh_size);
400 }
401
369 mach_msg_header_t Head; 402 mach_msg_header_t Head;
370 mach_msg_body_t msgh_body; 403 mach_msg_body_t msgh_body;
371 mach_msg_port_descriptor_t thread; 404 mach_msg_port_descriptor_t thread;
372 mach_msg_port_descriptor_t task; 405 mach_msg_port_descriptor_t task;
373 NDR_record_t NDR; 406 NDR_record_t NDR;
374 exception_type_t exception; 407 exception_type_t exception;
375 mach_msg_type_number_t codeCnt; 408 mach_msg_type_number_t codeCnt;
376 int64_t code[2]; 409 int64_t code[2];
377 int flavor; 410 int flavor;
378 mach_msg_type_number_t old_stateCnt; 411 mach_msg_type_number_t old_stateCnt;
379 natural_t old_state[THREAD_STATE_MAX]; 412 natural_t old_state[THREAD_STATE_MAX];
413 mach_msg_trailer_t trailer;
380 }; 414 };
381 415
382 // The reply messages for exception_raise_state_identity and 416 // The reply messages for exception_raise_state_identity and
383 // mach_exception_raise_state_identity are identical. 417 // mach_exception_raise_state_identity are identical.
384 using MachExceptionRaiseStateIdentityReply = ExceptionRaiseStateIdentityReply; 418 using MachExceptionRaiseStateIdentityReply = ExceptionRaiseStateIdentityReply;
385 419
386 // InvalidRequest and BadIDErrorReply are used to test that 420 // InvalidRequest and BadIDErrorReply are used to test that
387 // UniversalMachExcServer deals appropriately with messages that it does not 421 // UniversalMachExcServer deals appropriately with messages that it does not
388 // understand: messages with an unknown Head.msgh_id. 422 // understand: messages with an unknown Head.msgh_id.
389 423
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 thread_t thread, 476 thread_t thread,
443 task_t task, 477 task_t task,
444 exception_type_t exception, 478 exception_type_t exception,
445 const mach_exception_data_type_t* code, 479 const mach_exception_data_type_t* code,
446 mach_msg_type_number_t code_count, 480 mach_msg_type_number_t code_count,
447 thread_state_flavor_t* flavor, 481 thread_state_flavor_t* flavor,
448 const natural_t* old_state, 482 const natural_t* old_state,
449 mach_msg_type_number_t old_state_count, 483 mach_msg_type_number_t old_state_count,
450 thread_state_t new_state, 484 thread_state_t new_state,
451 mach_msg_type_number_t* new_state_count, 485 mach_msg_type_number_t* new_state_count,
486 const mach_msg_trailer_t* trailer,
452 bool* destroy_complex_request) override { 487 bool* destroy_complex_request) override {
453 *destroy_complex_request = true; 488 *destroy_complex_request = true;
454 const ConstExceptionCodes exception_codes = {code, code_count}; 489 const ConstExceptionCodes exception_codes = {code, code_count};
455 const ConstThreadState old_thread_state = {old_state, &old_state_count}; 490 const ConstThreadState old_thread_state = {old_state, &old_state_count};
456 ThreadState new_thread_state = {new_state, new_state_count}; 491 ThreadState new_thread_state = {new_state, new_state_count};
457 return MockCatchMachException(behavior, 492 return MockCatchMachException(behavior,
458 exception_port, 493 exception_port,
459 thread, 494 thread,
460 task, 495 task,
461 exception, 496 exception,
462 &exception_codes, 497 &exception_codes,
463 flavor, 498 flavor,
464 &old_thread_state, 499 &old_thread_state,
465 &new_thread_state); 500 &new_thread_state,
501 trailer);
466 } 502 }
467 503
468 MOCK_METHOD9(MockCatchMachException, 504 MOCK_METHOD10(MockCatchMachException,
469 kern_return_t(exception_behavior_t behavior, 505 kern_return_t(exception_behavior_t behavior,
470 exception_handler_t exception_port, 506 exception_handler_t exception_port,
471 thread_t thread, 507 thread_t thread,
472 task_t task, 508 task_t task,
473 exception_type_t exception, 509 exception_type_t exception,
474 const ConstExceptionCodes* exception_codes, 510 const ConstExceptionCodes* exception_codes,
475 thread_state_flavor_t* flavor, 511 thread_state_flavor_t* flavor,
476 const ConstThreadState* old_thread_state, 512 const ConstThreadState* old_thread_state,
477 ThreadState* new_thread_state)); 513 ThreadState* new_thread_state,
514 const mach_msg_trailer_t* trailer));
478 }; 515 };
479 516
480 // Matcher for ConstExceptionCodes, testing that it carries 2 codes matching 517 // Matcher for ConstExceptionCodes, testing that it carries 2 codes matching
481 // code_0 and code_1. 518 // code_0 and code_1.
482 MATCHER_P2(AreExceptionCodes, code_0, code_1, "") { 519 MATCHER_P2(AreExceptionCodes, code_0, code_1, "") {
483 if (!arg) { 520 if (!arg) {
484 return false; 521 return false;
485 } 522 }
486 523
487 if (arg->code_count == 2 && arg->code[0] == code_0 && 524 if (arg->code_count == 2 && arg->code[0] == code_0 &&
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 578
542 ~ScopedDefaultValue() { DefaultValue<T>::Clear(); } 579 ~ScopedDefaultValue() { DefaultValue<T>::Clear(); }
543 }; 580 };
544 581
545 TEST(ExcServerVariants, MockExceptionRaise) { 582 TEST(ExcServerVariants, MockExceptionRaise) {
546 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); 583 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
547 584
548 MockUniversalMachExcServer server; 585 MockUniversalMachExcServer server;
549 586
550 ExceptionRaiseRequest request; 587 ExceptionRaiseRequest request;
551 EXPECT_LE(sizeof(request), server.MachMessageServerRequestSize()); 588 EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize());
552 589
553 ExceptionRaiseReply reply; 590 ExceptionRaiseReply reply;
554 EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize()); 591 EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
555 592
556 const exception_behavior_t kExceptionBehavior = EXCEPTION_DEFAULT; 593 const exception_behavior_t kExceptionBehavior = EXCEPTION_DEFAULT;
557 594
558 EXPECT_CALL(server, 595 EXPECT_CALL(server,
559 MockCatchMachException(kExceptionBehavior, 596 MockCatchMachException(kExceptionBehavior,
560 kServerLocalPort, 597 kServerLocalPort,
561 kExceptionThreadPort, 598 kExceptionThreadPort,
562 kExceptionTaskPort, 599 kExceptionTaskPort,
563 kExceptionType, 600 kExceptionType,
564 AreExceptionCodes(kTestExceptonCodes[0], 601 AreExceptionCodes(kTestExceptonCodes[0],
565 kTestExceptonCodes[1]), 602 kTestExceptonCodes[1]),
566 Pointee(Eq(THREAD_STATE_NONE)), 603 Pointee(Eq(THREAD_STATE_NONE)),
567 IsThreadStateCount(0u), 604 IsThreadStateCount(0u),
568 IsThreadStateCount(0u))) 605 IsThreadStateCount(0u),
606 Eq(&request.trailer)))
569 .WillOnce(Return(KERN_SUCCESS)) 607 .WillOnce(Return(KERN_SUCCESS))
570 .RetiresOnSaturation(); 608 .RetiresOnSaturation();
571 609
572 bool destroy_complex_request = false; 610 bool destroy_complex_request = false;
573 EXPECT_TRUE(server.MachMessageServerFunction( 611 EXPECT_TRUE(server.MachMessageServerFunction(
574 reinterpret_cast<mach_msg_header_t*>(&request), 612 reinterpret_cast<mach_msg_header_t*>(&request),
575 reinterpret_cast<mach_msg_header_t*>(&reply), 613 reinterpret_cast<mach_msg_header_t*>(&reply),
576 &destroy_complex_request)); 614 &destroy_complex_request));
577 EXPECT_TRUE(destroy_complex_request); 615 EXPECT_TRUE(destroy_complex_request);
578 616
579 reply.Verify(kExceptionBehavior); 617 reply.Verify(kExceptionBehavior);
580 } 618 }
581 619
582 TEST(ExcServerVariants, MockExceptionRaiseState) { 620 TEST(ExcServerVariants, MockExceptionRaiseState) {
583 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); 621 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
584 622
585 MockUniversalMachExcServer server; 623 MockUniversalMachExcServer server;
586 624
587 ExceptionRaiseStateRequest request; 625 ExceptionRaiseStateRequest request;
588 EXPECT_LE(sizeof(request), server.MachMessageServerRequestSize()); 626 EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize());
589 627
590 ExceptionRaiseStateReply reply; 628 ExceptionRaiseStateReply reply;
591 EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize()); 629 EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
592 630
593 const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE; 631 const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE;
594 632
595 EXPECT_CALL( 633 EXPECT_CALL(
596 server, 634 server,
597 MockCatchMachException( 635 MockCatchMachException(
598 kExceptionBehavior, 636 kExceptionBehavior,
599 kServerLocalPort, 637 kServerLocalPort,
600 THREAD_NULL, 638 THREAD_NULL,
601 TASK_NULL, 639 TASK_NULL,
602 kExceptionType, 640 kExceptionType,
603 AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]), 641 AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]),
604 Pointee(Eq(kThreadStateFlavor)), 642 Pointee(Eq(kThreadStateFlavor)),
605 IsThreadStateCount(kThreadStateFlavorCount), 643 IsThreadStateCount(kThreadStateFlavorCount),
606 IsThreadStateCount(arraysize(reply.new_state)))) 644 IsThreadStateCount(arraysize(reply.new_state)),
645 Eq(request.Trailer())))
607 .WillOnce(Return(KERN_SUCCESS)) 646 .WillOnce(Return(KERN_SUCCESS))
608 .RetiresOnSaturation(); 647 .RetiresOnSaturation();
609 648
610 bool destroy_complex_request = false; 649 bool destroy_complex_request = false;
611 EXPECT_TRUE(server.MachMessageServerFunction( 650 EXPECT_TRUE(server.MachMessageServerFunction(
612 reinterpret_cast<mach_msg_header_t*>(&request), 651 reinterpret_cast<mach_msg_header_t*>(&request),
613 reinterpret_cast<mach_msg_header_t*>(&reply), 652 reinterpret_cast<mach_msg_header_t*>(&reply),
614 &destroy_complex_request)); 653 &destroy_complex_request));
615 654
616 // The request wasn’t complex, so nothing got a chance to change the value of 655 // The request wasn’t complex, so nothing got a chance to change the value of
617 // this variable. 656 // this variable.
618 EXPECT_FALSE(destroy_complex_request); 657 EXPECT_FALSE(destroy_complex_request);
619 658
620 reply.Verify(kExceptionBehavior); 659 reply.Verify(kExceptionBehavior);
621 } 660 }
622 661
623 TEST(ExcServerVariants, MockExceptionRaiseStateIdentity) { 662 TEST(ExcServerVariants, MockExceptionRaiseStateIdentity) {
624 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); 663 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
625 664
626 MockUniversalMachExcServer server; 665 MockUniversalMachExcServer server;
627 666
628 ExceptionRaiseStateIdentityRequest request; 667 ExceptionRaiseStateIdentityRequest request;
629 EXPECT_LE(sizeof(request), server.MachMessageServerRequestSize()); 668 EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize());
630 669
631 ExceptionRaiseStateIdentityReply reply; 670 ExceptionRaiseStateIdentityReply reply;
632 EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize()); 671 EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
633 672
634 const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE_IDENTITY; 673 const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE_IDENTITY;
635 674
636 EXPECT_CALL( 675 EXPECT_CALL(
637 server, 676 server,
638 MockCatchMachException( 677 MockCatchMachException(
639 kExceptionBehavior, 678 kExceptionBehavior,
640 kServerLocalPort, 679 kServerLocalPort,
641 kExceptionThreadPort, 680 kExceptionThreadPort,
642 kExceptionTaskPort, 681 kExceptionTaskPort,
643 kExceptionType, 682 kExceptionType,
644 AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]), 683 AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]),
645 Pointee(Eq(kThreadStateFlavor)), 684 Pointee(Eq(kThreadStateFlavor)),
646 IsThreadStateCount(kThreadStateFlavorCount), 685 IsThreadStateCount(kThreadStateFlavorCount),
647 IsThreadStateCount(arraysize(reply.new_state)))) 686 IsThreadStateCount(arraysize(reply.new_state)),
687 Eq(request.Trailer())))
648 .WillOnce(Return(KERN_SUCCESS)) 688 .WillOnce(Return(KERN_SUCCESS))
649 .RetiresOnSaturation(); 689 .RetiresOnSaturation();
650 690
651 bool destroy_complex_request = false; 691 bool destroy_complex_request = false;
652 EXPECT_TRUE(server.MachMessageServerFunction( 692 EXPECT_TRUE(server.MachMessageServerFunction(
653 reinterpret_cast<mach_msg_header_t*>(&request), 693 reinterpret_cast<mach_msg_header_t*>(&request),
654 reinterpret_cast<mach_msg_header_t*>(&reply), 694 reinterpret_cast<mach_msg_header_t*>(&reply),
655 &destroy_complex_request)); 695 &destroy_complex_request));
656 EXPECT_TRUE(destroy_complex_request); 696 EXPECT_TRUE(destroy_complex_request);
657 697
658 reply.Verify(kExceptionBehavior); 698 reply.Verify(kExceptionBehavior);
659 } 699 }
660 700
661 TEST(ExcServerVariants, MockMachExceptionRaise) { 701 TEST(ExcServerVariants, MockMachExceptionRaise) {
662 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); 702 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
663 703
664 MockUniversalMachExcServer server; 704 MockUniversalMachExcServer server;
665 705
666 MachExceptionRaiseRequest request; 706 MachExceptionRaiseRequest request;
667 EXPECT_LE(sizeof(request), server.MachMessageServerRequestSize()); 707 EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize());
668 708
669 MachExceptionRaiseReply reply; 709 MachExceptionRaiseReply reply;
670 EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize()); 710 EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
671 711
672 const exception_behavior_t kExceptionBehavior = 712 const exception_behavior_t kExceptionBehavior =
673 EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES; 713 EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES;
674 714
675 EXPECT_CALL( 715 EXPECT_CALL(
676 server, 716 server,
677 MockCatchMachException(kExceptionBehavior, 717 MockCatchMachException(kExceptionBehavior,
678 kServerLocalPort, 718 kServerLocalPort,
679 kExceptionThreadPort, 719 kExceptionThreadPort,
680 kExceptionTaskPort, 720 kExceptionTaskPort,
681 kExceptionType, 721 kExceptionType,
682 AreExceptionCodes(kTestMachExceptionCodes[0], 722 AreExceptionCodes(kTestMachExceptionCodes[0],
683 kTestMachExceptionCodes[1]), 723 kTestMachExceptionCodes[1]),
684 Pointee(Eq(THREAD_STATE_NONE)), 724 Pointee(Eq(THREAD_STATE_NONE)),
685 IsThreadStateCount(0u), 725 IsThreadStateCount(0u),
686 IsThreadStateCount(0u))) 726 IsThreadStateCount(0u),
727 Eq(&request.trailer)))
687 .WillOnce(Return(KERN_SUCCESS)) 728 .WillOnce(Return(KERN_SUCCESS))
688 .RetiresOnSaturation(); 729 .RetiresOnSaturation();
689 730
690 bool destroy_complex_request = false; 731 bool destroy_complex_request = false;
691 EXPECT_TRUE(server.MachMessageServerFunction( 732 EXPECT_TRUE(server.MachMessageServerFunction(
692 reinterpret_cast<mach_msg_header_t*>(&request), 733 reinterpret_cast<mach_msg_header_t*>(&request),
693 reinterpret_cast<mach_msg_header_t*>(&reply), 734 reinterpret_cast<mach_msg_header_t*>(&reply),
694 &destroy_complex_request)); 735 &destroy_complex_request));
695 EXPECT_TRUE(destroy_complex_request); 736 EXPECT_TRUE(destroy_complex_request);
696 737
697 reply.Verify(kExceptionBehavior); 738 reply.Verify(kExceptionBehavior);
698 } 739 }
699 740
700 TEST(ExcServerVariants, MockMachExceptionRaiseState) { 741 TEST(ExcServerVariants, MockMachExceptionRaiseState) {
701 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); 742 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
702 743
703 MockUniversalMachExcServer server; 744 MockUniversalMachExcServer server;
704 745
705 MachExceptionRaiseStateRequest request; 746 MachExceptionRaiseStateRequest request;
706 EXPECT_LE(sizeof(request), server.MachMessageServerRequestSize()); 747 EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize());
707 748
708 MachExceptionRaiseStateReply reply; 749 MachExceptionRaiseStateReply reply;
709 EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize()); 750 EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
710 751
711 const exception_behavior_t kExceptionBehavior = 752 const exception_behavior_t kExceptionBehavior =
712 EXCEPTION_STATE | MACH_EXCEPTION_CODES; 753 EXCEPTION_STATE | MACH_EXCEPTION_CODES;
713 754
714 EXPECT_CALL( 755 EXPECT_CALL(
715 server, 756 server,
716 MockCatchMachException(kExceptionBehavior, 757 MockCatchMachException(kExceptionBehavior,
717 kServerLocalPort, 758 kServerLocalPort,
718 THREAD_NULL, 759 THREAD_NULL,
719 TASK_NULL, 760 TASK_NULL,
720 kExceptionType, 761 kExceptionType,
721 AreExceptionCodes(kTestMachExceptionCodes[0], 762 AreExceptionCodes(kTestMachExceptionCodes[0],
722 kTestMachExceptionCodes[1]), 763 kTestMachExceptionCodes[1]),
723 Pointee(Eq(kThreadStateFlavor)), 764 Pointee(Eq(kThreadStateFlavor)),
724 IsThreadStateCount(kThreadStateFlavorCount), 765 IsThreadStateCount(kThreadStateFlavorCount),
725 IsThreadStateCount(arraysize(reply.new_state)))) 766 IsThreadStateCount(arraysize(reply.new_state)),
767 Eq(request.Trailer())))
726 .WillOnce(Return(KERN_SUCCESS)) 768 .WillOnce(Return(KERN_SUCCESS))
727 .RetiresOnSaturation(); 769 .RetiresOnSaturation();
728 770
729 bool destroy_complex_request = false; 771 bool destroy_complex_request = false;
730 EXPECT_TRUE(server.MachMessageServerFunction( 772 EXPECT_TRUE(server.MachMessageServerFunction(
731 reinterpret_cast<mach_msg_header_t*>(&request), 773 reinterpret_cast<mach_msg_header_t*>(&request),
732 reinterpret_cast<mach_msg_header_t*>(&reply), 774 reinterpret_cast<mach_msg_header_t*>(&reply),
733 &destroy_complex_request)); 775 &destroy_complex_request));
734 776
735 // The request wasn’t complex, so nothing got a chance to change the value of 777 // The request wasn’t complex, so nothing got a chance to change the value of
736 // this variable. 778 // this variable.
737 EXPECT_FALSE(destroy_complex_request); 779 EXPECT_FALSE(destroy_complex_request);
738 780
739 reply.Verify(kExceptionBehavior); 781 reply.Verify(kExceptionBehavior);
740 } 782 }
741 783
742 TEST(ExcServerVariants, MockMachExceptionRaiseStateIdentity) { 784 TEST(ExcServerVariants, MockMachExceptionRaiseStateIdentity) {
743 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); 785 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
744 786
745 MockUniversalMachExcServer server; 787 MockUniversalMachExcServer server;
746 788
747 MachExceptionRaiseStateIdentityRequest request; 789 MachExceptionRaiseStateIdentityRequest request;
748 EXPECT_LE(sizeof(request), server.MachMessageServerRequestSize()); 790 EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize());
749 791
750 MachExceptionRaiseStateIdentityReply reply; 792 MachExceptionRaiseStateIdentityReply reply;
751 EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize()); 793 EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
752 794
753 const exception_behavior_t kExceptionBehavior = 795 const exception_behavior_t kExceptionBehavior =
754 EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES; 796 EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES;
755 797
756 EXPECT_CALL( 798 EXPECT_CALL(
757 server, 799 server,
758 MockCatchMachException(kExceptionBehavior, 800 MockCatchMachException(kExceptionBehavior,
759 kServerLocalPort, 801 kServerLocalPort,
760 kExceptionThreadPort, 802 kExceptionThreadPort,
761 kExceptionTaskPort, 803 kExceptionTaskPort,
762 kExceptionType, 804 kExceptionType,
763 AreExceptionCodes(kTestMachExceptionCodes[0], 805 AreExceptionCodes(kTestMachExceptionCodes[0],
764 kTestMachExceptionCodes[1]), 806 kTestMachExceptionCodes[1]),
765 Pointee(Eq(kThreadStateFlavor)), 807 Pointee(Eq(kThreadStateFlavor)),
766 IsThreadStateCount(kThreadStateFlavorCount), 808 IsThreadStateCount(kThreadStateFlavorCount),
767 IsThreadStateCount(arraysize(reply.new_state)))) 809 IsThreadStateCount(arraysize(reply.new_state)),
810 Eq(request.Trailer())))
768 .WillOnce(Return(KERN_SUCCESS)) 811 .WillOnce(Return(KERN_SUCCESS))
769 .RetiresOnSaturation(); 812 .RetiresOnSaturation();
770 813
771 bool destroy_complex_request = false; 814 bool destroy_complex_request = false;
772 EXPECT_TRUE(server.MachMessageServerFunction( 815 EXPECT_TRUE(server.MachMessageServerFunction(
773 reinterpret_cast<mach_msg_header_t*>(&request), 816 reinterpret_cast<mach_msg_header_t*>(&request),
774 reinterpret_cast<mach_msg_header_t*>(&reply), 817 reinterpret_cast<mach_msg_header_t*>(&reply),
775 &destroy_complex_request)); 818 &destroy_complex_request));
776 EXPECT_TRUE(destroy_complex_request); 819 EXPECT_TRUE(destroy_complex_request);
777 820
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 thread_t thread, 907 thread_t thread,
865 task_t task, 908 task_t task,
866 exception_type_t exception, 909 exception_type_t exception,
867 const mach_exception_data_type_t* code, 910 const mach_exception_data_type_t* code,
868 mach_msg_type_number_t code_count, 911 mach_msg_type_number_t code_count,
869 thread_state_flavor_t* flavor, 912 thread_state_flavor_t* flavor,
870 const natural_t* old_state, 913 const natural_t* old_state,
871 mach_msg_type_number_t old_state_count, 914 mach_msg_type_number_t old_state_count,
872 thread_state_t new_state, 915 thread_state_t new_state,
873 mach_msg_type_number_t* new_state_count, 916 mach_msg_type_number_t* new_state_count,
917 const mach_msg_trailer_t* trailer,
874 bool* destroy_complex_request) override { 918 bool* destroy_complex_request) override {
875 *destroy_complex_request = true; 919 *destroy_complex_request = true;
876 920
877 EXPECT_FALSE(handled_); 921 EXPECT_FALSE(handled_);
878 handled_ = true; 922 handled_ = true;
879 923
880 EXPECT_EQ(behavior_, behavior); 924 EXPECT_EQ(behavior_, behavior);
881 925
882 EXPECT_EQ(LocalPort(), exception_port); 926 EXPECT_EQ(LocalPort(), exception_port);
883 927
(...skipping 26 matching lines...) Expand all
910 *new_state_count); 954 *new_state_count);
911 EXPECT_NE(nullptr, new_state); 955 EXPECT_NE(nullptr, new_state);
912 } else { 956 } else {
913 EXPECT_EQ(THREAD_STATE_NONE, *flavor); 957 EXPECT_EQ(THREAD_STATE_NONE, *flavor);
914 EXPECT_EQ(0u, old_state_count); 958 EXPECT_EQ(0u, old_state_count);
915 EXPECT_EQ(nullptr, old_state); 959 EXPECT_EQ(nullptr, old_state);
916 EXPECT_EQ(0u, *new_state_count); 960 EXPECT_EQ(0u, *new_state_count);
917 EXPECT_EQ(nullptr, new_state); 961 EXPECT_EQ(nullptr, new_state);
918 } 962 }
919 963
964 EXPECT_EQ(implicit_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0),
965 trailer->msgh_trailer_type);
966 EXPECT_EQ(REQUESTED_TRAILER_SIZE(kMachMessageOptions),
967 trailer->msgh_trailer_size);
968
920 return ExcServerSuccessfulReturnValue(behavior, false); 969 return ExcServerSuccessfulReturnValue(behavior, false);
921 } 970 }
922 971
923 private: 972 private:
924 // MachMultiprocess: 973 // MachMultiprocess:
925 974
926 void MachMultiprocessParent() override { 975 void MachMultiprocessParent() override {
927 kern_return_t kr = 976 kern_return_t kr =
928 MachMessageServer::Run(this, 977 MachMessageServer::Run(this,
929 LocalPort(), 978 LocalPort(),
930 MACH_MSG_OPTION_NONE, 979 kMachMessageOptions,
931 MachMessageServer::kOneShot, 980 MachMessageServer::kOneShot,
932 MachMessageServer::kBlocking, 981 MachMessageServer::kBlocking,
933 MachMessageServer::kReceiveLargeError, 982 MachMessageServer::kReceiveLargeError,
934 0); 983 0);
935 EXPECT_EQ(KERN_SUCCESS, kr) 984 EXPECT_EQ(KERN_SUCCESS, kr)
936 << MachErrorMessage(kr, "MachMessageServer::Run"); 985 << MachErrorMessage(kr, "MachMessageServer::Run");
937 986
938 EXPECT_TRUE(handled_); 987 EXPECT_TRUE(handled_);
939 } 988 }
940 989
941 void MachMultiprocessChild() override { 990 void MachMultiprocessChild() override {
942 // Set the parent as the exception handler for EXC_CRASH. 991 // Set the parent as the exception handler for EXC_CRASH.
943 kern_return_t kr = task_set_exception_ports( 992 kern_return_t kr = task_set_exception_ports(
944 mach_task_self(), EXC_MASK_CRASH, RemotePort(), behavior_, flavor_); 993 mach_task_self(), EXC_MASK_CRASH, RemotePort(), behavior_, flavor_);
945 ASSERT_EQ(KERN_SUCCESS, kr) 994 ASSERT_EQ(KERN_SUCCESS, kr)
946 << MachErrorMessage(kr, "task_set_exception_ports"); 995 << MachErrorMessage(kr, "task_set_exception_ports");
947 996
948 // Now crash. 997 // Now crash.
949 __builtin_trap(); 998 __builtin_trap();
950 } 999 }
951 1000
952 exception_behavior_t behavior_; 1001 exception_behavior_t behavior_;
953 thread_state_flavor_t flavor_; 1002 thread_state_flavor_t flavor_;
954 mach_msg_type_number_t state_count_; 1003 mach_msg_type_number_t state_count_;
955 bool handled_; 1004 bool handled_;
956 1005
1006 static const mach_msg_option_t kMachMessageOptions =
1007 MACH_RCV_TRAILER_TYPE(MACH_MSG_TRAILER_FORMAT_0);
1008
957 DISALLOW_COPY_AND_ASSIGN(TestExcServerVariants); 1009 DISALLOW_COPY_AND_ASSIGN(TestExcServerVariants);
958 }; 1010 };
959 1011
960 TEST(ExcServerVariants, ExceptionRaise) { 1012 TEST(ExcServerVariants, ExceptionRaise) {
961 TestExcServerVariants test_exc_server_variants( 1013 TestExcServerVariants test_exc_server_variants(
962 EXCEPTION_DEFAULT, THREAD_STATE_NONE, 0); 1014 EXCEPTION_DEFAULT, THREAD_STATE_NONE, 0);
963 test_exc_server_variants.Run(); 1015 test_exc_server_variants.Run();
964 } 1016 }
965 1017
966 TEST(ExcServerVariants, ExceptionRaiseState) { 1018 TEST(ExcServerVariants, ExceptionRaiseState) {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 1204
1153 EXPECT_EQ(test_data.kr, 1205 EXPECT_EQ(test_data.kr,
1154 ExcServerSuccessfulReturnValue(test_data.behavior, 1206 ExcServerSuccessfulReturnValue(test_data.behavior,
1155 test_data.set_thread_state)); 1207 test_data.set_thread_state));
1156 } 1208 }
1157 } 1209 }
1158 1210
1159 } // namespace 1211 } // namespace
1160 } // namespace test 1212 } // namespace test
1161 } // namespace crashpad 1213 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/mach/exc_server_variants.cc ('k') | util/mach/exception_ports_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698