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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 const thread_t kExceptionThreadPort = 0x03030303; | 44 const thread_t kExceptionThreadPort = 0x03030303; |
45 const task_t kExceptionTaskPort = 0x04040404; | 45 const task_t kExceptionTaskPort = 0x04040404; |
46 | 46 |
47 // Other fake exception values. | 47 // Other fake exception values. |
48 const exception_type_t kExceptionType = EXC_BAD_ACCESS; | 48 const exception_type_t kExceptionType = EXC_BAD_ACCESS; |
49 | 49 |
50 // Test using an exception code with the high bit set to ensure that it gets | 50 // Test using an exception code with the high bit set to ensure that it gets |
51 // promoted to the wider mach_exception_data_type_t type as a signed quantity. | 51 // promoted to the wider mach_exception_data_type_t type as a signed quantity. |
52 const exception_data_type_t kTestExceptonCodes[] = { | 52 const exception_data_type_t kTestExceptonCodes[] = { |
53 KERN_PROTECTION_FAILURE, | 53 KERN_PROTECTION_FAILURE, |
54 static_cast<exception_data_type_t>(0xfedcba98), | 54 implicit_cast<exception_data_type_t>(0xfedcba98), |
55 }; | 55 }; |
56 | 56 |
57 const mach_exception_data_type_t kTestMachExceptionCodes[] = { | 57 const mach_exception_data_type_t kTestMachExceptionCodes[] = { |
58 KERN_PROTECTION_FAILURE, | 58 KERN_PROTECTION_FAILURE, |
59 static_cast<mach_exception_data_type_t>(0xfedcba9876543210), | 59 implicit_cast<mach_exception_data_type_t>(0xfedcba9876543210), |
60 }; | 60 }; |
61 | 61 |
62 const thread_state_flavor_t kThreadStateFlavor = MACHINE_THREAD_STATE; | 62 const thread_state_flavor_t kThreadStateFlavor = MACHINE_THREAD_STATE; |
63 const mach_msg_type_number_t kThreadStateFlavorCount = | 63 const mach_msg_type_number_t kThreadStateFlavorCount = |
64 MACHINE_THREAD_STATE_COUNT; | 64 MACHINE_THREAD_STATE_COUNT; |
65 | 65 |
66 void InitializeMachMsgPortDescriptor(mach_msg_port_descriptor_t* descriptor, | 66 void InitializeMachMsgPortDescriptor(mach_msg_port_descriptor_t* descriptor, |
67 mach_port_t port) { | 67 mach_port_t port) { |
68 descriptor->name = port; | 68 descriptor->name = port; |
69 descriptor->disposition = MACH_MSG_TYPE_MOVE_SEND; | 69 descriptor->disposition = MACH_MSG_TYPE_MOVE_SEND; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 void InitializeForTesting() { | 115 void InitializeForTesting() { |
116 memset(this, 0x5a, sizeof(*this)); | 116 memset(this, 0x5a, sizeof(*this)); |
117 RetCode = KERN_FAILURE; | 117 RetCode = KERN_FAILURE; |
118 } | 118 } |
119 | 119 |
120 // Verify accepts a |behavior| parameter because the same message format and | 120 // Verify accepts a |behavior| parameter because the same message format and |
121 // verification function is used for ExceptionRaiseReply and | 121 // verification function is used for ExceptionRaiseReply and |
122 // MachExceptionRaiseReply. Knowing which behavior is expected allows the | 122 // MachExceptionRaiseReply. Knowing which behavior is expected allows the |
123 // message ID to be checked. | 123 // message ID to be checked. |
124 void Verify(exception_behavior_t behavior) { | 124 void Verify(exception_behavior_t behavior) { |
125 EXPECT_EQ(static_cast<mach_msg_bits_t>( | 125 EXPECT_EQ(implicit_cast<mach_msg_bits_t>( |
126 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0)), | 126 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0)), |
127 Head.msgh_bits); | 127 Head.msgh_bits); |
128 EXPECT_EQ(sizeof(*this), Head.msgh_size); | 128 EXPECT_EQ(sizeof(*this), Head.msgh_size); |
129 EXPECT_EQ(kClientRemotePort, Head.msgh_remote_port); | 129 EXPECT_EQ(kClientRemotePort, Head.msgh_remote_port); |
130 EXPECT_EQ(kMachPortNull, Head.msgh_local_port); | 130 EXPECT_EQ(kMachPortNull, Head.msgh_local_port); |
131 switch (behavior) { | 131 switch (behavior) { |
132 case EXCEPTION_DEFAULT: | 132 case EXCEPTION_DEFAULT: |
133 EXPECT_EQ(2501, Head.msgh_id); | 133 EXPECT_EQ(2501, Head.msgh_id); |
134 break; | 134 break; |
135 case EXCEPTION_DEFAULT | kMachExceptionCodes: | 135 case EXCEPTION_DEFAULT | kMachExceptionCodes: |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 memset(this, 0x5a, sizeof(*this)); | 189 memset(this, 0x5a, sizeof(*this)); |
190 RetCode = KERN_FAILURE; | 190 RetCode = KERN_FAILURE; |
191 } | 191 } |
192 | 192 |
193 // Verify accepts a |behavior| parameter because the same message format and | 193 // Verify accepts a |behavior| parameter because the same message format and |
194 // verification function is used for ExceptionRaiseStateReply, | 194 // verification function is used for ExceptionRaiseStateReply, |
195 // ExceptionRaiseStateIdentityReply, MachExceptionRaiseStateReply, and | 195 // ExceptionRaiseStateIdentityReply, MachExceptionRaiseStateReply, and |
196 // MachExceptionRaiseStateIdentityReply. Knowing which behavior is expected | 196 // MachExceptionRaiseStateIdentityReply. Knowing which behavior is expected |
197 // allows the message ID to be checked. | 197 // allows the message ID to be checked. |
198 void Verify(exception_behavior_t behavior) { | 198 void Verify(exception_behavior_t behavior) { |
199 EXPECT_EQ(static_cast<mach_msg_bits_t>( | 199 EXPECT_EQ(implicit_cast<mach_msg_bits_t>( |
200 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0)), | 200 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0)), |
201 Head.msgh_bits); | 201 Head.msgh_bits); |
202 EXPECT_EQ(sizeof(*this), Head.msgh_size); | 202 EXPECT_EQ(sizeof(*this), Head.msgh_size); |
203 EXPECT_EQ(kClientRemotePort, Head.msgh_remote_port); | 203 EXPECT_EQ(kClientRemotePort, Head.msgh_remote_port); |
204 EXPECT_EQ(kMachPortNull, Head.msgh_local_port); | 204 EXPECT_EQ(kMachPortNull, Head.msgh_local_port); |
205 switch (behavior) { | 205 switch (behavior) { |
206 case EXCEPTION_STATE: | 206 case EXCEPTION_STATE: |
207 EXPECT_EQ(2502, Head.msgh_id); | 207 EXPECT_EQ(2502, Head.msgh_id); |
208 break; | 208 break; |
209 case EXCEPTION_STATE_IDENTITY: | 209 case EXCEPTION_STATE_IDENTITY: |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 }; | 402 }; |
403 | 403 |
404 struct __attribute__((packed, aligned(4))) BadIDErrorReply | 404 struct __attribute__((packed, aligned(4))) BadIDErrorReply |
405 : public mig_reply_error_t { | 405 : public mig_reply_error_t { |
406 void InitializeForTesting() { | 406 void InitializeForTesting() { |
407 memset(this, 0x5a, sizeof(*this)); | 407 memset(this, 0x5a, sizeof(*this)); |
408 RetCode = KERN_FAILURE; | 408 RetCode = KERN_FAILURE; |
409 } | 409 } |
410 | 410 |
411 void Verify(mach_msg_id_t id) { | 411 void Verify(mach_msg_id_t id) { |
412 EXPECT_EQ(static_cast<mach_msg_bits_t>( | 412 EXPECT_EQ(implicit_cast<mach_msg_bits_t>( |
413 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0)), | 413 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0)), |
414 Head.msgh_bits); | 414 Head.msgh_bits); |
415 EXPECT_EQ(sizeof(*this), Head.msgh_size); | 415 EXPECT_EQ(sizeof(*this), Head.msgh_size); |
416 EXPECT_EQ(kClientRemotePort, Head.msgh_remote_port); | 416 EXPECT_EQ(kClientRemotePort, Head.msgh_remote_port); |
417 EXPECT_EQ(kMachPortNull, Head.msgh_local_port); | 417 EXPECT_EQ(kMachPortNull, Head.msgh_local_port); |
418 EXPECT_EQ(id + 100, Head.msgh_id); | 418 EXPECT_EQ(id + 100, Head.msgh_id); |
419 EXPECT_EQ(0, memcmp(&NDR, &NDR_record, sizeof(NDR))); | 419 EXPECT_EQ(0, memcmp(&NDR, &NDR_record, sizeof(NDR))); |
420 EXPECT_EQ(MIG_BAD_ID, RetCode); | 420 EXPECT_EQ(MIG_BAD_ID, RetCode); |
421 } | 421 } |
422 }; | 422 }; |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 int signal; | 916 int signal; |
917 ExcCrashRecoverOriginalException(code[0], nullptr, &signal); | 917 ExcCrashRecoverOriginalException(code[0], nullptr, &signal); |
918 SetExpectedChildTermination(kTerminationSignal, signal); | 918 SetExpectedChildTermination(kTerminationSignal, signal); |
919 } | 919 } |
920 | 920 |
921 const bool has_state = ExceptionBehaviorHasState(behavior); | 921 const bool has_state = ExceptionBehaviorHasState(behavior); |
922 if (has_state) { | 922 if (has_state) { |
923 EXPECT_EQ(flavor_, *flavor); | 923 EXPECT_EQ(flavor_, *flavor); |
924 EXPECT_EQ(state_count_, old_state_count); | 924 EXPECT_EQ(state_count_, old_state_count); |
925 EXPECT_NE(nullptr, old_state); | 925 EXPECT_NE(nullptr, old_state); |
926 EXPECT_EQ(static_cast<mach_msg_type_number_t>(THREAD_STATE_MAX), | 926 EXPECT_EQ(implicit_cast<mach_msg_type_number_t>(THREAD_STATE_MAX), |
927 *new_state_count); | 927 *new_state_count); |
928 EXPECT_NE(nullptr, new_state); | 928 EXPECT_NE(nullptr, new_state); |
929 } else { | 929 } else { |
930 EXPECT_EQ(THREAD_STATE_NONE, *flavor); | 930 EXPECT_EQ(THREAD_STATE_NONE, *flavor); |
931 EXPECT_EQ(0u, old_state_count); | 931 EXPECT_EQ(0u, old_state_count); |
932 EXPECT_EQ(nullptr, old_state); | 932 EXPECT_EQ(nullptr, old_state); |
933 EXPECT_EQ(0u, *new_state_count); | 933 EXPECT_EQ(0u, *new_state_count); |
934 EXPECT_EQ(nullptr, new_state); | 934 EXPECT_EQ(nullptr, new_state); |
935 } | 935 } |
936 | 936 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 | 1167 |
1168 EXPECT_EQ(test_data.kr, | 1168 EXPECT_EQ(test_data.kr, |
1169 ExcServerSuccessfulReturnValue(test_data.behavior, | 1169 ExcServerSuccessfulReturnValue(test_data.behavior, |
1170 test_data.set_thread_state)); | 1170 test_data.set_thread_state)); |
1171 } | 1171 } |
1172 } | 1172 } |
1173 | 1173 |
1174 } // namespace | 1174 } // namespace |
1175 } // namespace test | 1175 } // namespace test |
1176 } // namespace crashpad | 1176 } // namespace crashpad |
OLD | NEW |