OLD | NEW |
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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 // Wait for the child process to be ready. It needs to have all of its | 354 // Wait for the child process to be ready. It needs to have all of its |
355 // threads set up before proceeding if in kSetOutOfProcess mode. | 355 // threads set up before proceeding if in kSetOutOfProcess mode. |
356 char c; | 356 char c; |
357 CheckedReadFile(ReadPipeHandle(), &c, 1); | 357 CheckedReadFile(ReadPipeHandle(), &c, 1); |
358 EXPECT_EQ('\0', c); | 358 EXPECT_EQ('\0', c); |
359 | 359 |
360 mach_port_t local_port = LocalPort(); | 360 mach_port_t local_port = LocalPort(); |
361 | 361 |
362 // Get an ExceptionPorts object for the task and each of its threads. | 362 // Get an ExceptionPorts object for the task and each of its threads. |
363 ExceptionPorts task_ports(ExceptionPorts::kTargetTypeTask, ChildTask()); | 363 ExceptionPorts task_ports(ExceptionPorts::kTargetTypeTask, ChildTask()); |
364 EXPECT_EQ("task", task_ports.TargetTypeName()); | 364 EXPECT_STREQ("task", task_ports.TargetTypeName()); |
365 | 365 |
366 // Hopefully the threads returned by task_threads() are in order, with the | 366 // Hopefully the threads returned by task_threads() are in order, with the |
367 // main thread first and the other thread second. This is currently always | 367 // main thread first and the other thread second. This is currently always |
368 // the case, although nothing guarantees that it will remain so. | 368 // the case, although nothing guarantees that it will remain so. |
369 thread_act_array_t threads; | 369 thread_act_array_t threads; |
370 mach_msg_type_number_t thread_count = 0; | 370 mach_msg_type_number_t thread_count = 0; |
371 kern_return_t kr = task_threads(ChildTask(), &threads, &thread_count); | 371 kern_return_t kr = task_threads(ChildTask(), &threads, &thread_count); |
372 ASSERT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "task_threads"); | 372 ASSERT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "task_threads"); |
373 | 373 |
374 ScopedForbidReturn threads_need_owners; | 374 ScopedForbidReturn threads_need_owners; |
375 ASSERT_EQ(2u, thread_count); | 375 ASSERT_EQ(2u, thread_count); |
376 base::mac::ScopedMachSendRight main_thread(threads[0]); | 376 base::mac::ScopedMachSendRight main_thread(threads[0]); |
377 base::mac::ScopedMachSendRight other_thread(threads[1]); | 377 base::mac::ScopedMachSendRight other_thread(threads[1]); |
378 threads_need_owners.Disarm(); | 378 threads_need_owners.Disarm(); |
379 | 379 |
380 ExceptionPorts main_thread_ports(ExceptionPorts::kTargetTypeThread, | 380 ExceptionPorts main_thread_ports(ExceptionPorts::kTargetTypeThread, |
381 main_thread); | 381 main_thread); |
382 ExceptionPorts other_thread_ports(ExceptionPorts::kTargetTypeThread, | 382 ExceptionPorts other_thread_ports(ExceptionPorts::kTargetTypeThread, |
383 other_thread); | 383 other_thread); |
384 EXPECT_EQ("thread", main_thread_ports.TargetTypeName()); | 384 EXPECT_STREQ("thread", main_thread_ports.TargetTypeName()); |
385 EXPECT_EQ("thread", other_thread_ports.TargetTypeName()); | 385 EXPECT_STREQ("thread", other_thread_ports.TargetTypeName()); |
386 | 386 |
387 if (set_type_ == kSetOutOfProcess) { | 387 if (set_type_ == kSetOutOfProcess) { |
388 // Test ExceptionPorts::SetExceptionPorts() being called from | 388 // Test ExceptionPorts::SetExceptionPorts() being called from |
389 // out-of-process. | 389 // out-of-process. |
390 // | 390 // |
391 // local_port is only a receive right, but a send right is needed for | 391 // local_port is only a receive right, but a send right is needed for |
392 // ExceptionPorts::SetExceptionPort(). Make a send right, which can be | 392 // ExceptionPorts::SetExceptionPort(). Make a send right, which can be |
393 // deallocated once the calls to ExceptionPorts::SetExceptionPort() are | 393 // deallocated once the calls to ExceptionPorts::SetExceptionPort() are |
394 // done. | 394 // done. |
395 kr = mach_port_insert_right( | 395 kr = mach_port_insert_right( |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 // ExceptionPorts isn’t expected to work as non-root. Just do a quick test to | 580 // ExceptionPorts isn’t expected to work as non-root. Just do a quick test to |
581 // make sure that TargetTypeName() returns the right string, and that the | 581 // make sure that TargetTypeName() returns the right string, and that the |
582 // underlying host_get_exception_ports() function appears to be called by | 582 // underlying host_get_exception_ports() function appears to be called by |
583 // looking for a KERN_INVALID_ARGUMENT return value. Or, on the off chance | 583 // looking for a KERN_INVALID_ARGUMENT return value. Or, on the off chance |
584 // that the test is being run as root, just look for KERN_SUCCESS. | 584 // that the test is being run as root, just look for KERN_SUCCESS. |
585 // host_set_exception_ports() is not tested, because if the test were running | 585 // host_set_exception_ports() is not tested, because if the test were running |
586 // as root and the call succeeded, it would have global effects. | 586 // as root and the call succeeded, it would have global effects. |
587 | 587 |
588 base::mac::ScopedMachSendRight host(mach_host_self()); | 588 base::mac::ScopedMachSendRight host(mach_host_self()); |
589 ExceptionPorts explicit_host_ports(ExceptionPorts::kTargetTypeHost, host); | 589 ExceptionPorts explicit_host_ports(ExceptionPorts::kTargetTypeHost, host); |
590 EXPECT_EQ("host", explicit_host_ports.TargetTypeName()); | 590 EXPECT_STREQ("host", explicit_host_ports.TargetTypeName()); |
591 | 591 |
592 std::vector<ExceptionPorts::ExceptionHandler> handlers; | 592 std::vector<ExceptionPorts::ExceptionHandler> handlers; |
593 bool rv = explicit_host_ports.GetExceptionPorts( | 593 bool rv = explicit_host_ports.GetExceptionPorts( |
594 ExcMaskAll() | EXC_MASK_CRASH, &handlers); | 594 ExcMaskAll() | EXC_MASK_CRASH, &handlers); |
595 if (geteuid() == 0) { | 595 if (geteuid() == 0) { |
596 EXPECT_TRUE(rv); | 596 EXPECT_TRUE(rv); |
597 } else { | 597 } else { |
598 EXPECT_FALSE(rv); | 598 EXPECT_FALSE(rv); |
599 } | 599 } |
600 | 600 |
601 ExceptionPorts implicit_host_ports(ExceptionPorts::kTargetTypeHost, | 601 ExceptionPorts implicit_host_ports(ExceptionPorts::kTargetTypeHost, |
602 HOST_NULL); | 602 HOST_NULL); |
603 EXPECT_EQ("host", implicit_host_ports.TargetTypeName()); | 603 EXPECT_STREQ("host", implicit_host_ports.TargetTypeName()); |
604 | 604 |
605 rv = implicit_host_ports.GetExceptionPorts( | 605 rv = implicit_host_ports.GetExceptionPorts( |
606 ExcMaskAll() | EXC_MASK_CRASH, &handlers); | 606 ExcMaskAll() | EXC_MASK_CRASH, &handlers); |
607 if (geteuid() == 0) { | 607 if (geteuid() == 0) { |
608 EXPECT_TRUE(rv); | 608 EXPECT_TRUE(rv); |
609 } else { | 609 } else { |
610 EXPECT_FALSE(rv); | 610 EXPECT_FALSE(rv); |
611 } | 611 } |
612 } | 612 } |
613 | 613 |
614 } // namespace | 614 } // namespace |
615 } // namespace test | 615 } // namespace test |
616 } // namespace crashpad | 616 } // namespace crashpad |
OLD | NEW |