| 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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 442               Head.msgh_bits); | 442               Head.msgh_bits); | 
| 443     EXPECT_EQ(sizeof(*this), Head.msgh_size); | 443     EXPECT_EQ(sizeof(*this), Head.msgh_size); | 
| 444     EXPECT_EQ(kClientRemotePort, Head.msgh_remote_port); | 444     EXPECT_EQ(kClientRemotePort, Head.msgh_remote_port); | 
| 445     EXPECT_EQ(kMachPortNull, Head.msgh_local_port); | 445     EXPECT_EQ(kMachPortNull, Head.msgh_local_port); | 
| 446     EXPECT_EQ(id + 100, Head.msgh_id); | 446     EXPECT_EQ(id + 100, Head.msgh_id); | 
| 447     EXPECT_EQ(0, memcmp(&NDR, &NDR_record, sizeof(NDR))); | 447     EXPECT_EQ(0, memcmp(&NDR, &NDR_record, sizeof(NDR))); | 
| 448     EXPECT_EQ(MIG_BAD_ID, RetCode); | 448     EXPECT_EQ(MIG_BAD_ID, RetCode); | 
| 449   } | 449   } | 
| 450 }; | 450 }; | 
| 451 | 451 | 
| 452 class MockUniversalMachExcServer : public UniversalMachExcServer { | 452 class MockUniversalMachExcServer : public UniversalMachExcServer::Interface { | 
| 453  public: | 453  public: | 
| 454   struct ConstExceptionCodes { | 454   struct ConstExceptionCodes { | 
| 455     const mach_exception_data_type_t* code; | 455     const mach_exception_data_type_t* code; | 
| 456     mach_msg_type_number_t code_count; | 456     mach_msg_type_number_t code_count; | 
| 457   }; | 457   }; | 
| 458   struct ThreadState { | 458   struct ThreadState { | 
| 459     thread_state_t state; | 459     thread_state_t state; | 
| 460     mach_msg_type_number_t* state_count; | 460     mach_msg_type_number_t* state_count; | 
| 461   }; | 461   }; | 
| 462   struct ConstThreadState { | 462   struct ConstThreadState { | 
| 463     const natural_t* state; | 463     const natural_t* state; | 
| 464     mach_msg_type_number_t* state_count; | 464     mach_msg_type_number_t* state_count; | 
| 465   }; | 465   }; | 
| 466 | 466 | 
|  | 467   // UniversalMachExcServer::Interface: | 
|  | 468 | 
| 467   // CatchMachException is the method to mock, but it has 13 parameters, and | 469   // CatchMachException is the method to mock, but it has 13 parameters, and | 
| 468   // gmock can only mock methods with up to 10 parameters. Coalesce some related | 470   // gmock can only mock methods with up to 10 parameters. Coalesce some related | 
| 469   // parameters together into structs, and call a mocked method. | 471   // parameters together into structs, and call a mocked method. | 
| 470   virtual kern_return_t CatchMachException( | 472   virtual kern_return_t CatchMachException( | 
| 471       exception_behavior_t behavior, | 473       exception_behavior_t behavior, | 
| 472       exception_handler_t exception_port, | 474       exception_handler_t exception_port, | 
| 473       thread_t thread, | 475       thread_t thread, | 
| 474       task_t task, | 476       task_t task, | 
| 475       exception_type_t exception, | 477       exception_type_t exception, | 
| 476       const mach_exception_data_type_t* code, | 478       const mach_exception_data_type_t* code, | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 573     DefaultValue<T>::Set(default_value); | 575     DefaultValue<T>::Set(default_value); | 
| 574   } | 576   } | 
| 575 | 577 | 
| 576   ~ScopedDefaultValue() { DefaultValue<T>::Clear(); } | 578   ~ScopedDefaultValue() { DefaultValue<T>::Clear(); } | 
| 577 }; | 579 }; | 
| 578 | 580 | 
| 579 TEST(ExcServerVariants, MockExceptionRaise) { | 581 TEST(ExcServerVariants, MockExceptionRaise) { | 
| 580   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 582   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 
| 581 | 583 | 
| 582   MockUniversalMachExcServer server; | 584   MockUniversalMachExcServer server; | 
|  | 585   UniversalMachExcServer universal_mach_exc_server(&server); | 
| 583 | 586 | 
| 584   ExceptionRaiseRequest request; | 587   ExceptionRaiseRequest request; | 
| 585   EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize()); | 588   EXPECT_LE(request.Head.msgh_size, | 
|  | 589             universal_mach_exc_server.MachMessageServerRequestSize()); | 
| 586 | 590 | 
| 587   ExceptionRaiseReply reply; | 591   ExceptionRaiseReply reply; | 
| 588   EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize()); | 592   EXPECT_LE(sizeof(reply), | 
|  | 593             universal_mach_exc_server.MachMessageServerReplySize()); | 
| 589 | 594 | 
| 590   const exception_behavior_t kExceptionBehavior = EXCEPTION_DEFAULT; | 595   const exception_behavior_t kExceptionBehavior = EXCEPTION_DEFAULT; | 
| 591 | 596 | 
| 592   EXPECT_CALL(server, | 597   EXPECT_CALL(server, | 
| 593               MockCatchMachException(kExceptionBehavior, | 598               MockCatchMachException(kExceptionBehavior, | 
| 594                                      kServerLocalPort, | 599                                      kServerLocalPort, | 
| 595                                      kExceptionThreadPort, | 600                                      kExceptionThreadPort, | 
| 596                                      kExceptionTaskPort, | 601                                      kExceptionTaskPort, | 
| 597                                      kExceptionType, | 602                                      kExceptionType, | 
| 598                                      AreExceptionCodes(kTestExceptonCodes[0], | 603                                      AreExceptionCodes(kTestExceptonCodes[0], | 
| 599                                                        kTestExceptonCodes[1]), | 604                                                        kTestExceptonCodes[1]), | 
| 600                                      Pointee(Eq(THREAD_STATE_NONE)), | 605                                      Pointee(Eq(THREAD_STATE_NONE)), | 
| 601                                      IsThreadStateCount(0u), | 606                                      IsThreadStateCount(0u), | 
| 602                                      IsThreadStateCount(0u), | 607                                      IsThreadStateCount(0u), | 
| 603                                      Eq(&request.trailer))) | 608                                      Eq(&request.trailer))) | 
| 604       .WillOnce(Return(KERN_SUCCESS)) | 609       .WillOnce(Return(KERN_SUCCESS)) | 
| 605       .RetiresOnSaturation(); | 610       .RetiresOnSaturation(); | 
| 606 | 611 | 
| 607   bool destroy_complex_request = false; | 612   bool destroy_complex_request = false; | 
| 608   EXPECT_TRUE(server.MachMessageServerFunction( | 613   EXPECT_TRUE(universal_mach_exc_server.MachMessageServerFunction( | 
| 609       reinterpret_cast<mach_msg_header_t*>(&request), | 614       reinterpret_cast<mach_msg_header_t*>(&request), | 
| 610       reinterpret_cast<mach_msg_header_t*>(&reply), | 615       reinterpret_cast<mach_msg_header_t*>(&reply), | 
| 611       &destroy_complex_request)); | 616       &destroy_complex_request)); | 
| 612   EXPECT_TRUE(destroy_complex_request); | 617   EXPECT_TRUE(destroy_complex_request); | 
| 613 | 618 | 
| 614   reply.Verify(kExceptionBehavior); | 619   reply.Verify(kExceptionBehavior); | 
| 615 } | 620 } | 
| 616 | 621 | 
| 617 TEST(ExcServerVariants, MockExceptionRaiseState) { | 622 TEST(ExcServerVariants, MockExceptionRaiseState) { | 
| 618   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 623   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 
| 619 | 624 | 
| 620   MockUniversalMachExcServer server; | 625   MockUniversalMachExcServer server; | 
|  | 626   UniversalMachExcServer universal_mach_exc_server(&server); | 
| 621 | 627 | 
| 622   ExceptionRaiseStateRequest request; | 628   ExceptionRaiseStateRequest request; | 
| 623   EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize()); | 629   EXPECT_LE(request.Head.msgh_size, | 
|  | 630             universal_mach_exc_server.MachMessageServerRequestSize()); | 
| 624 | 631 | 
| 625   ExceptionRaiseStateReply reply; | 632   ExceptionRaiseStateReply reply; | 
| 626   EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize()); | 633   EXPECT_LE(sizeof(reply), | 
|  | 634             universal_mach_exc_server.MachMessageServerReplySize()); | 
| 627 | 635 | 
| 628   const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE; | 636   const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE; | 
| 629 | 637 | 
| 630   EXPECT_CALL( | 638   EXPECT_CALL( | 
| 631       server, | 639       server, | 
| 632       MockCatchMachException( | 640       MockCatchMachException( | 
| 633           kExceptionBehavior, | 641           kExceptionBehavior, | 
| 634           kServerLocalPort, | 642           kServerLocalPort, | 
| 635           THREAD_NULL, | 643           THREAD_NULL, | 
| 636           TASK_NULL, | 644           TASK_NULL, | 
| 637           kExceptionType, | 645           kExceptionType, | 
| 638           AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]), | 646           AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]), | 
| 639           Pointee(Eq(kThreadStateFlavor)), | 647           Pointee(Eq(kThreadStateFlavor)), | 
| 640           IsThreadStateCount(kThreadStateFlavorCount), | 648           IsThreadStateCount(kThreadStateFlavorCount), | 
| 641           IsThreadStateCount(arraysize(reply.new_state)), | 649           IsThreadStateCount(arraysize(reply.new_state)), | 
| 642           Eq(request.Trailer()))) | 650           Eq(request.Trailer()))) | 
| 643       .WillOnce(Return(KERN_SUCCESS)) | 651       .WillOnce(Return(KERN_SUCCESS)) | 
| 644       .RetiresOnSaturation(); | 652       .RetiresOnSaturation(); | 
| 645 | 653 | 
| 646   bool destroy_complex_request = false; | 654   bool destroy_complex_request = false; | 
| 647   EXPECT_TRUE(server.MachMessageServerFunction( | 655   EXPECT_TRUE(universal_mach_exc_server.MachMessageServerFunction( | 
| 648       reinterpret_cast<mach_msg_header_t*>(&request), | 656       reinterpret_cast<mach_msg_header_t*>(&request), | 
| 649       reinterpret_cast<mach_msg_header_t*>(&reply), | 657       reinterpret_cast<mach_msg_header_t*>(&reply), | 
| 650       &destroy_complex_request)); | 658       &destroy_complex_request)); | 
| 651 | 659 | 
| 652   // The request wasn’t complex, so nothing got a chance to change the value of | 660   // The request wasn’t complex, so nothing got a chance to change the value of | 
| 653   // this variable. | 661   // this variable. | 
| 654   EXPECT_FALSE(destroy_complex_request); | 662   EXPECT_FALSE(destroy_complex_request); | 
| 655 | 663 | 
| 656   reply.Verify(kExceptionBehavior); | 664   reply.Verify(kExceptionBehavior); | 
| 657 } | 665 } | 
| 658 | 666 | 
| 659 TEST(ExcServerVariants, MockExceptionRaiseStateIdentity) { | 667 TEST(ExcServerVariants, MockExceptionRaiseStateIdentity) { | 
| 660   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 668   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 
| 661 | 669 | 
| 662   MockUniversalMachExcServer server; | 670   MockUniversalMachExcServer server; | 
|  | 671   UniversalMachExcServer universal_mach_exc_server(&server); | 
| 663 | 672 | 
| 664   ExceptionRaiseStateIdentityRequest request; | 673   ExceptionRaiseStateIdentityRequest request; | 
| 665   EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize()); | 674   EXPECT_LE(request.Head.msgh_size, | 
|  | 675             universal_mach_exc_server.MachMessageServerRequestSize()); | 
| 666 | 676 | 
| 667   ExceptionRaiseStateIdentityReply reply; | 677   ExceptionRaiseStateIdentityReply reply; | 
| 668   EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize()); | 678   EXPECT_LE(sizeof(reply), | 
|  | 679             universal_mach_exc_server.MachMessageServerReplySize()); | 
| 669 | 680 | 
| 670   const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE_IDENTITY; | 681   const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE_IDENTITY; | 
| 671 | 682 | 
| 672   EXPECT_CALL( | 683   EXPECT_CALL( | 
| 673       server, | 684       server, | 
| 674       MockCatchMachException( | 685       MockCatchMachException( | 
| 675           kExceptionBehavior, | 686           kExceptionBehavior, | 
| 676           kServerLocalPort, | 687           kServerLocalPort, | 
| 677           kExceptionThreadPort, | 688           kExceptionThreadPort, | 
| 678           kExceptionTaskPort, | 689           kExceptionTaskPort, | 
| 679           kExceptionType, | 690           kExceptionType, | 
| 680           AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]), | 691           AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]), | 
| 681           Pointee(Eq(kThreadStateFlavor)), | 692           Pointee(Eq(kThreadStateFlavor)), | 
| 682           IsThreadStateCount(kThreadStateFlavorCount), | 693           IsThreadStateCount(kThreadStateFlavorCount), | 
| 683           IsThreadStateCount(arraysize(reply.new_state)), | 694           IsThreadStateCount(arraysize(reply.new_state)), | 
| 684           Eq(request.Trailer()))) | 695           Eq(request.Trailer()))) | 
| 685       .WillOnce(Return(KERN_SUCCESS)) | 696       .WillOnce(Return(KERN_SUCCESS)) | 
| 686       .RetiresOnSaturation(); | 697       .RetiresOnSaturation(); | 
| 687 | 698 | 
| 688   bool destroy_complex_request = false; | 699   bool destroy_complex_request = false; | 
| 689   EXPECT_TRUE(server.MachMessageServerFunction( | 700   EXPECT_TRUE(universal_mach_exc_server.MachMessageServerFunction( | 
| 690       reinterpret_cast<mach_msg_header_t*>(&request), | 701       reinterpret_cast<mach_msg_header_t*>(&request), | 
| 691       reinterpret_cast<mach_msg_header_t*>(&reply), | 702       reinterpret_cast<mach_msg_header_t*>(&reply), | 
| 692       &destroy_complex_request)); | 703       &destroy_complex_request)); | 
| 693   EXPECT_TRUE(destroy_complex_request); | 704   EXPECT_TRUE(destroy_complex_request); | 
| 694 | 705 | 
| 695   reply.Verify(kExceptionBehavior); | 706   reply.Verify(kExceptionBehavior); | 
| 696 } | 707 } | 
| 697 | 708 | 
| 698 TEST(ExcServerVariants, MockMachExceptionRaise) { | 709 TEST(ExcServerVariants, MockMachExceptionRaise) { | 
| 699   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 710   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 
| 700 | 711 | 
| 701   MockUniversalMachExcServer server; | 712   MockUniversalMachExcServer server; | 
|  | 713   UniversalMachExcServer universal_mach_exc_server(&server); | 
| 702 | 714 | 
| 703   MachExceptionRaiseRequest request; | 715   MachExceptionRaiseRequest request; | 
| 704   EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize()); | 716   EXPECT_LE(request.Head.msgh_size, | 
|  | 717             universal_mach_exc_server.MachMessageServerRequestSize()); | 
| 705 | 718 | 
| 706   MachExceptionRaiseReply reply; | 719   MachExceptionRaiseReply reply; | 
| 707   EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize()); | 720   EXPECT_LE(sizeof(reply), | 
|  | 721             universal_mach_exc_server.MachMessageServerReplySize()); | 
| 708 | 722 | 
| 709   const exception_behavior_t kExceptionBehavior = | 723   const exception_behavior_t kExceptionBehavior = | 
| 710       EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES; | 724       EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES; | 
| 711 | 725 | 
| 712   EXPECT_CALL( | 726   EXPECT_CALL( | 
| 713       server, | 727       server, | 
| 714       MockCatchMachException(kExceptionBehavior, | 728       MockCatchMachException(kExceptionBehavior, | 
| 715                              kServerLocalPort, | 729                              kServerLocalPort, | 
| 716                              kExceptionThreadPort, | 730                              kExceptionThreadPort, | 
| 717                              kExceptionTaskPort, | 731                              kExceptionTaskPort, | 
| 718                              kExceptionType, | 732                              kExceptionType, | 
| 719                              AreExceptionCodes(kTestMachExceptionCodes[0], | 733                              AreExceptionCodes(kTestMachExceptionCodes[0], | 
| 720                                                kTestMachExceptionCodes[1]), | 734                                                kTestMachExceptionCodes[1]), | 
| 721                              Pointee(Eq(THREAD_STATE_NONE)), | 735                              Pointee(Eq(THREAD_STATE_NONE)), | 
| 722                              IsThreadStateCount(0u), | 736                              IsThreadStateCount(0u), | 
| 723                              IsThreadStateCount(0u), | 737                              IsThreadStateCount(0u), | 
| 724                              Eq(&request.trailer))) | 738                              Eq(&request.trailer))) | 
| 725       .WillOnce(Return(KERN_SUCCESS)) | 739       .WillOnce(Return(KERN_SUCCESS)) | 
| 726       .RetiresOnSaturation(); | 740       .RetiresOnSaturation(); | 
| 727 | 741 | 
| 728   bool destroy_complex_request = false; | 742   bool destroy_complex_request = false; | 
| 729   EXPECT_TRUE(server.MachMessageServerFunction( | 743   EXPECT_TRUE(universal_mach_exc_server.MachMessageServerFunction( | 
| 730       reinterpret_cast<mach_msg_header_t*>(&request), | 744       reinterpret_cast<mach_msg_header_t*>(&request), | 
| 731       reinterpret_cast<mach_msg_header_t*>(&reply), | 745       reinterpret_cast<mach_msg_header_t*>(&reply), | 
| 732       &destroy_complex_request)); | 746       &destroy_complex_request)); | 
| 733   EXPECT_TRUE(destroy_complex_request); | 747   EXPECT_TRUE(destroy_complex_request); | 
| 734 | 748 | 
| 735   reply.Verify(kExceptionBehavior); | 749   reply.Verify(kExceptionBehavior); | 
| 736 } | 750 } | 
| 737 | 751 | 
| 738 TEST(ExcServerVariants, MockMachExceptionRaiseState) { | 752 TEST(ExcServerVariants, MockMachExceptionRaiseState) { | 
| 739   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 753   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 
| 740 | 754 | 
| 741   MockUniversalMachExcServer server; | 755   MockUniversalMachExcServer server; | 
|  | 756   UniversalMachExcServer universal_mach_exc_server(&server); | 
| 742 | 757 | 
| 743   MachExceptionRaiseStateRequest request; | 758   MachExceptionRaiseStateRequest request; | 
| 744   EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize()); | 759   EXPECT_LE(request.Head.msgh_size, | 
|  | 760             universal_mach_exc_server.MachMessageServerRequestSize()); | 
| 745 | 761 | 
| 746   MachExceptionRaiseStateReply reply; | 762   MachExceptionRaiseStateReply reply; | 
| 747   EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize()); | 763   EXPECT_LE(sizeof(reply), | 
|  | 764             universal_mach_exc_server.MachMessageServerReplySize()); | 
| 748 | 765 | 
| 749   const exception_behavior_t kExceptionBehavior = | 766   const exception_behavior_t kExceptionBehavior = | 
| 750       EXCEPTION_STATE | MACH_EXCEPTION_CODES; | 767       EXCEPTION_STATE | MACH_EXCEPTION_CODES; | 
| 751 | 768 | 
| 752   EXPECT_CALL( | 769   EXPECT_CALL( | 
| 753       server, | 770       server, | 
| 754       MockCatchMachException(kExceptionBehavior, | 771       MockCatchMachException(kExceptionBehavior, | 
| 755                              kServerLocalPort, | 772                              kServerLocalPort, | 
| 756                              THREAD_NULL, | 773                              THREAD_NULL, | 
| 757                              TASK_NULL, | 774                              TASK_NULL, | 
| 758                              kExceptionType, | 775                              kExceptionType, | 
| 759                              AreExceptionCodes(kTestMachExceptionCodes[0], | 776                              AreExceptionCodes(kTestMachExceptionCodes[0], | 
| 760                                                kTestMachExceptionCodes[1]), | 777                                                kTestMachExceptionCodes[1]), | 
| 761                              Pointee(Eq(kThreadStateFlavor)), | 778                              Pointee(Eq(kThreadStateFlavor)), | 
| 762                              IsThreadStateCount(kThreadStateFlavorCount), | 779                              IsThreadStateCount(kThreadStateFlavorCount), | 
| 763                              IsThreadStateCount(arraysize(reply.new_state)), | 780                              IsThreadStateCount(arraysize(reply.new_state)), | 
| 764                              Eq(request.Trailer()))) | 781                              Eq(request.Trailer()))) | 
| 765       .WillOnce(Return(KERN_SUCCESS)) | 782       .WillOnce(Return(KERN_SUCCESS)) | 
| 766       .RetiresOnSaturation(); | 783       .RetiresOnSaturation(); | 
| 767 | 784 | 
| 768   bool destroy_complex_request = false; | 785   bool destroy_complex_request = false; | 
| 769   EXPECT_TRUE(server.MachMessageServerFunction( | 786   EXPECT_TRUE(universal_mach_exc_server.MachMessageServerFunction( | 
| 770       reinterpret_cast<mach_msg_header_t*>(&request), | 787       reinterpret_cast<mach_msg_header_t*>(&request), | 
| 771       reinterpret_cast<mach_msg_header_t*>(&reply), | 788       reinterpret_cast<mach_msg_header_t*>(&reply), | 
| 772       &destroy_complex_request)); | 789       &destroy_complex_request)); | 
| 773 | 790 | 
| 774   // The request wasn’t complex, so nothing got a chance to change the value of | 791   // The request wasn’t complex, so nothing got a chance to change the value of | 
| 775   // this variable. | 792   // this variable. | 
| 776   EXPECT_FALSE(destroy_complex_request); | 793   EXPECT_FALSE(destroy_complex_request); | 
| 777 | 794 | 
| 778   reply.Verify(kExceptionBehavior); | 795   reply.Verify(kExceptionBehavior); | 
| 779 } | 796 } | 
| 780 | 797 | 
| 781 TEST(ExcServerVariants, MockMachExceptionRaiseStateIdentity) { | 798 TEST(ExcServerVariants, MockMachExceptionRaiseStateIdentity) { | 
| 782   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 799   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 
| 783 | 800 | 
| 784   MockUniversalMachExcServer server; | 801   MockUniversalMachExcServer server; | 
|  | 802   UniversalMachExcServer universal_mach_exc_server(&server); | 
| 785 | 803 | 
| 786   MachExceptionRaiseStateIdentityRequest request; | 804   MachExceptionRaiseStateIdentityRequest request; | 
| 787   EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize()); | 805   EXPECT_LE(request.Head.msgh_size, | 
|  | 806             universal_mach_exc_server.MachMessageServerRequestSize()); | 
| 788 | 807 | 
| 789   MachExceptionRaiseStateIdentityReply reply; | 808   MachExceptionRaiseStateIdentityReply reply; | 
| 790   EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize()); | 809   EXPECT_LE(sizeof(reply), | 
|  | 810             universal_mach_exc_server.MachMessageServerReplySize()); | 
| 791 | 811 | 
| 792   const exception_behavior_t kExceptionBehavior = | 812   const exception_behavior_t kExceptionBehavior = | 
| 793       EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES; | 813       EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES; | 
| 794 | 814 | 
| 795   EXPECT_CALL( | 815   EXPECT_CALL( | 
| 796       server, | 816       server, | 
| 797       MockCatchMachException(kExceptionBehavior, | 817       MockCatchMachException(kExceptionBehavior, | 
| 798                              kServerLocalPort, | 818                              kServerLocalPort, | 
| 799                              kExceptionThreadPort, | 819                              kExceptionThreadPort, | 
| 800                              kExceptionTaskPort, | 820                              kExceptionTaskPort, | 
| 801                              kExceptionType, | 821                              kExceptionType, | 
| 802                              AreExceptionCodes(kTestMachExceptionCodes[0], | 822                              AreExceptionCodes(kTestMachExceptionCodes[0], | 
| 803                                                kTestMachExceptionCodes[1]), | 823                                                kTestMachExceptionCodes[1]), | 
| 804                              Pointee(Eq(kThreadStateFlavor)), | 824                              Pointee(Eq(kThreadStateFlavor)), | 
| 805                              IsThreadStateCount(kThreadStateFlavorCount), | 825                              IsThreadStateCount(kThreadStateFlavorCount), | 
| 806                              IsThreadStateCount(arraysize(reply.new_state)), | 826                              IsThreadStateCount(arraysize(reply.new_state)), | 
| 807                              Eq(request.Trailer()))) | 827                              Eq(request.Trailer()))) | 
| 808       .WillOnce(Return(KERN_SUCCESS)) | 828       .WillOnce(Return(KERN_SUCCESS)) | 
| 809       .RetiresOnSaturation(); | 829       .RetiresOnSaturation(); | 
| 810 | 830 | 
| 811   bool destroy_complex_request = false; | 831   bool destroy_complex_request = false; | 
| 812   EXPECT_TRUE(server.MachMessageServerFunction( | 832   EXPECT_TRUE(universal_mach_exc_server.MachMessageServerFunction( | 
| 813       reinterpret_cast<mach_msg_header_t*>(&request), | 833       reinterpret_cast<mach_msg_header_t*>(&request), | 
| 814       reinterpret_cast<mach_msg_header_t*>(&reply), | 834       reinterpret_cast<mach_msg_header_t*>(&reply), | 
| 815       &destroy_complex_request)); | 835       &destroy_complex_request)); | 
| 816   EXPECT_TRUE(destroy_complex_request); | 836   EXPECT_TRUE(destroy_complex_request); | 
| 817 | 837 | 
| 818   reply.Verify(kExceptionBehavior); | 838   reply.Verify(kExceptionBehavior); | 
| 819 } | 839 } | 
| 820 | 840 | 
| 821 TEST(ExcServerVariants, MockUnknownID) { | 841 TEST(ExcServerVariants, MockUnknownID) { | 
| 822   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 842   ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); | 
| 823 | 843 | 
| 824   MockUniversalMachExcServer server; | 844   MockUniversalMachExcServer server; | 
|  | 845   UniversalMachExcServer universal_mach_exc_server(&server); | 
| 825 | 846 | 
| 826   // Make sure that a message with an unknown ID is handled appropriately. | 847   // Make sure that a message with an unknown ID is handled appropriately. | 
| 827   // UniversalMachExcServer should not dispatch the message to | 848   // UniversalMachExcServer should not dispatch the message to | 
| 828   // MachMessageServerFunction, but should generate a MIG_BAD_ID error reply. | 849   // MachMessageServerFunction, but should generate a MIG_BAD_ID error reply. | 
| 829 | 850 | 
| 830   const mach_msg_id_t unknown_ids[] = { | 851   const mach_msg_id_t unknown_ids[] = { | 
| 831       // Reasonable things to check. | 852       // Reasonable things to check. | 
| 832       -101, | 853       -101, | 
| 833       -100, | 854       -100, | 
| 834       -99, | 855       -99, | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 855       2507, | 876       2507, | 
| 856       2508, | 877       2508, | 
| 857   }; | 878   }; | 
| 858 | 879 | 
| 859   for (size_t index = 0; index < arraysize(unknown_ids); ++index) { | 880   for (size_t index = 0; index < arraysize(unknown_ids); ++index) { | 
| 860     mach_msg_id_t id = unknown_ids[index]; | 881     mach_msg_id_t id = unknown_ids[index]; | 
| 861 | 882 | 
| 862     SCOPED_TRACE(base::StringPrintf("unknown id %d", id)); | 883     SCOPED_TRACE(base::StringPrintf("unknown id %d", id)); | 
| 863 | 884 | 
| 864     InvalidRequest request(id); | 885     InvalidRequest request(id); | 
| 865     EXPECT_LE(sizeof(request), server.MachMessageServerRequestSize()); | 886     EXPECT_LE(sizeof(request), | 
|  | 887               universal_mach_exc_server.MachMessageServerRequestSize()); | 
| 866 | 888 | 
| 867     BadIDErrorReply reply; | 889     BadIDErrorReply reply; | 
| 868     EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize()); | 890     EXPECT_LE(sizeof(reply), | 
|  | 891               universal_mach_exc_server.MachMessageServerReplySize()); | 
| 869 | 892 | 
| 870     bool destroy_complex_request = false; | 893     bool destroy_complex_request = false; | 
| 871     EXPECT_FALSE(server.MachMessageServerFunction( | 894     EXPECT_FALSE(universal_mach_exc_server.MachMessageServerFunction( | 
| 872         reinterpret_cast<mach_msg_header_t*>(&request), | 895         reinterpret_cast<mach_msg_header_t*>(&request), | 
| 873         reinterpret_cast<mach_msg_header_t*>(&reply), | 896         reinterpret_cast<mach_msg_header_t*>(&reply), | 
| 874         &destroy_complex_request)); | 897         &destroy_complex_request)); | 
| 875 | 898 | 
| 876     // The request wasn’t handled, nothing got a chance to change the value of | 899     // The request wasn’t handled, nothing got a chance to change the value of | 
| 877     // this variable. MachMessageServer would destroy the request if it was | 900     // this variable. MachMessageServer would destroy the request if it was | 
| 878     // complex, regardless of what was done to this variable, because the | 901     // complex, regardless of what was done to this variable, because the | 
| 879     // return code was not KERN_SUCCESS or MIG_NO_REPLY. | 902     // return code was not KERN_SUCCESS or MIG_NO_REPLY. | 
| 880     EXPECT_FALSE(destroy_complex_request); | 903     EXPECT_FALSE(destroy_complex_request); | 
| 881 | 904 | 
| 882     reply.Verify(id); | 905     reply.Verify(id); | 
| 883   } | 906   } | 
| 884 } | 907 } | 
| 885 | 908 | 
| 886 class TestExcServerVariants : public UniversalMachExcServer, | 909 class TestExcServerVariants : public MachMultiprocess, | 
| 887                               public MachMultiprocess { | 910                               public UniversalMachExcServer::Interface { | 
| 888  public: | 911  public: | 
| 889   TestExcServerVariants(exception_behavior_t behavior, | 912   TestExcServerVariants(exception_behavior_t behavior, | 
| 890                         thread_state_flavor_t flavor, | 913                         thread_state_flavor_t flavor, | 
| 891                         mach_msg_type_number_t state_count) | 914                         mach_msg_type_number_t state_count) | 
| 892       : UniversalMachExcServer(), | 915       : MachMultiprocess(), | 
| 893         MachMultiprocess(), | 916         UniversalMachExcServer::Interface(), | 
| 894         behavior_(behavior), | 917         behavior_(behavior), | 
| 895         flavor_(flavor), | 918         flavor_(flavor), | 
| 896         state_count_(state_count), | 919         state_count_(state_count), | 
| 897         handled_(false) {} | 920         handled_(false) {} | 
| 898 | 921 | 
| 899   // UniversalMachExcServer: | 922   // UniversalMachExcServer::Interface: | 
| 900 | 923 | 
| 901   virtual kern_return_t CatchMachException( | 924   virtual kern_return_t CatchMachException( | 
| 902       exception_behavior_t behavior, | 925       exception_behavior_t behavior, | 
| 903       exception_handler_t exception_port, | 926       exception_handler_t exception_port, | 
| 904       thread_t thread, | 927       thread_t thread, | 
| 905       task_t task, | 928       task_t task, | 
| 906       exception_type_t exception, | 929       exception_type_t exception, | 
| 907       const mach_exception_data_type_t* code, | 930       const mach_exception_data_type_t* code, | 
| 908       mach_msg_type_number_t code_count, | 931       mach_msg_type_number_t code_count, | 
| 909       thread_state_flavor_t* flavor, | 932       thread_state_flavor_t* flavor, | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 963     EXPECT_EQ(REQUESTED_TRAILER_SIZE(kMachMessageOptions), | 986     EXPECT_EQ(REQUESTED_TRAILER_SIZE(kMachMessageOptions), | 
| 964               trailer->msgh_trailer_size); | 987               trailer->msgh_trailer_size); | 
| 965 | 988 | 
| 966     return ExcServerSuccessfulReturnValue(behavior, false); | 989     return ExcServerSuccessfulReturnValue(behavior, false); | 
| 967   } | 990   } | 
| 968 | 991 | 
| 969  private: | 992  private: | 
| 970   // MachMultiprocess: | 993   // MachMultiprocess: | 
| 971 | 994 | 
| 972   void MachMultiprocessParent() override { | 995   void MachMultiprocessParent() override { | 
|  | 996     UniversalMachExcServer universal_mach_exc_server(this); | 
|  | 997 | 
| 973     kern_return_t kr = | 998     kern_return_t kr = | 
| 974         MachMessageServer::Run(this, | 999         MachMessageServer::Run(&universal_mach_exc_server, | 
| 975                                LocalPort(), | 1000                                LocalPort(), | 
| 976                                kMachMessageOptions, | 1001                                kMachMessageOptions, | 
| 977                                MachMessageServer::kOneShot, | 1002                                MachMessageServer::kOneShot, | 
| 978                                MachMessageServer::kBlocking, | 1003                                MachMessageServer::kBlocking, | 
| 979                                MachMessageServer::kReceiveLargeError, | 1004                                MachMessageServer::kReceiveLargeError, | 
| 980                                0); | 1005                                0); | 
| 981     EXPECT_EQ(KERN_SUCCESS, kr) | 1006     EXPECT_EQ(KERN_SUCCESS, kr) | 
| 982         << MachErrorMessage(kr, "MachMessageServer::Run"); | 1007         << MachErrorMessage(kr, "MachMessageServer::Run"); | 
| 983 | 1008 | 
| 984     EXPECT_TRUE(handled_); | 1009     EXPECT_TRUE(handled_); | 
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1201 | 1226 | 
| 1202     EXPECT_EQ(test_data.kr, | 1227     EXPECT_EQ(test_data.kr, | 
| 1203               ExcServerSuccessfulReturnValue(test_data.behavior, | 1228               ExcServerSuccessfulReturnValue(test_data.behavior, | 
| 1204                                              test_data.set_thread_state)); | 1229                                              test_data.set_thread_state)); | 
| 1205   } | 1230   } | 
| 1206 } | 1231 } | 
| 1207 | 1232 | 
| 1208 }  // namespace | 1233 }  // namespace | 
| 1209 }  // namespace test | 1234 }  // namespace test | 
| 1210 }  // namespace crashpad | 1235 }  // namespace crashpad | 
| OLD | NEW | 
|---|