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 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 EXPECT_EQ(nullptr, old_state); | 1025 EXPECT_EQ(nullptr, old_state); |
1026 EXPECT_EQ(0u, *new_state_count); | 1026 EXPECT_EQ(0u, *new_state_count); |
1027 EXPECT_EQ(nullptr, new_state); | 1027 EXPECT_EQ(nullptr, new_state); |
1028 } | 1028 } |
1029 | 1029 |
1030 EXPECT_EQ(implicit_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0), | 1030 EXPECT_EQ(implicit_cast<mach_msg_trailer_type_t>(MACH_MSG_TRAILER_FORMAT_0), |
1031 trailer->msgh_trailer_type); | 1031 trailer->msgh_trailer_type); |
1032 EXPECT_EQ(REQUESTED_TRAILER_SIZE(kMachMessageOptions), | 1032 EXPECT_EQ(REQUESTED_TRAILER_SIZE(kMachMessageOptions), |
1033 trailer->msgh_trailer_size); | 1033 trailer->msgh_trailer_size); |
1034 | 1034 |
| 1035 ExcServerCopyState( |
| 1036 behavior, old_state, old_state_count, new_state, new_state_count); |
| 1037 |
1035 return ExcServerSuccessfulReturnValue(behavior, false); | 1038 return ExcServerSuccessfulReturnValue(behavior, false); |
1036 } | 1039 } |
1037 | 1040 |
1038 private: | 1041 private: |
1039 // MachMultiprocess: | 1042 // MachMultiprocess: |
1040 | 1043 |
1041 void MachMultiprocessParent() override { | 1044 void MachMultiprocessParent() override { |
1042 UniversalMachExcServer universal_mach_exc_server(this); | 1045 UniversalMachExcServer universal_mach_exc_server(this); |
1043 | 1046 |
1044 kern_return_t kr = | 1047 kern_return_t kr = |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 index, | 1271 index, |
1269 test_data.behavior, | 1272 test_data.behavior, |
1270 test_data.set_thread_state ? "true" : "false")); | 1273 test_data.set_thread_state ? "true" : "false")); |
1271 | 1274 |
1272 EXPECT_EQ(test_data.kr, | 1275 EXPECT_EQ(test_data.kr, |
1273 ExcServerSuccessfulReturnValue(test_data.behavior, | 1276 ExcServerSuccessfulReturnValue(test_data.behavior, |
1274 test_data.set_thread_state)); | 1277 test_data.set_thread_state)); |
1275 } | 1278 } |
1276 } | 1279 } |
1277 | 1280 |
| 1281 TEST(ExcServerVariants, ExcServerCopyState) { |
| 1282 const natural_t old_state[] = {1, 2, 3, 4, 5}; |
| 1283 natural_t new_state[10] = {}; |
| 1284 |
| 1285 const mach_msg_type_number_t old_state_count = arraysize(old_state); |
| 1286 mach_msg_type_number_t new_state_count = arraysize(new_state); |
| 1287 |
| 1288 // EXCEPTION_DEFAULT (with or without MACH_EXCEPTION_CODES) is not |
| 1289 // state-carrying. new_state and new_state_count should be untouched. |
| 1290 ExcServerCopyState(EXCEPTION_DEFAULT, |
| 1291 old_state, |
| 1292 old_state_count, |
| 1293 new_state, |
| 1294 &new_state_count); |
| 1295 EXPECT_EQ(arraysize(new_state), new_state_count); |
| 1296 for (size_t i = 0; i < arraysize(new_state); ++i) { |
| 1297 EXPECT_EQ(0u, new_state[i]) << "i " << i; |
| 1298 } |
| 1299 |
| 1300 ExcServerCopyState(MACH_EXCEPTION_CODES | EXCEPTION_DEFAULT, |
| 1301 old_state, |
| 1302 old_state_count, |
| 1303 new_state, |
| 1304 &new_state_count); |
| 1305 EXPECT_EQ(arraysize(new_state), new_state_count); |
| 1306 for (size_t i = 0; i < arraysize(new_state); ++i) { |
| 1307 EXPECT_EQ(0u, new_state[i]) << "i " << i; |
| 1308 } |
| 1309 |
| 1310 // This is a state-carrying exception where old_state_count is small. |
| 1311 mach_msg_type_number_t copy_limit = 2; |
| 1312 ExcServerCopyState( |
| 1313 EXCEPTION_STATE, old_state, copy_limit, new_state, &new_state_count); |
| 1314 EXPECT_EQ(copy_limit, new_state_count); |
| 1315 for (size_t i = 0; i < copy_limit; ++i) { |
| 1316 EXPECT_EQ(old_state[i], new_state[i]) << "i " << i; |
| 1317 } |
| 1318 for (size_t i = copy_limit; i < arraysize(new_state); ++i) { |
| 1319 EXPECT_EQ(0u, new_state[i]) << "i " << i; |
| 1320 } |
| 1321 |
| 1322 // This is a state-carrying exception where new_state_count is small. |
| 1323 copy_limit = 3; |
| 1324 new_state_count = copy_limit; |
| 1325 ExcServerCopyState(EXCEPTION_STATE_IDENTITY, |
| 1326 old_state, |
| 1327 old_state_count, |
| 1328 new_state, |
| 1329 &new_state_count); |
| 1330 EXPECT_EQ(copy_limit, new_state_count); |
| 1331 for (size_t i = 0; i < copy_limit; ++i) { |
| 1332 EXPECT_EQ(old_state[i], new_state[i]) << "i " << i; |
| 1333 } |
| 1334 for (size_t i = copy_limit; i < arraysize(new_state); ++i) { |
| 1335 EXPECT_EQ(0u, new_state[i]) << "i " << i; |
| 1336 } |
| 1337 |
| 1338 // This is a state-carrying exception where all of old_state is copied to |
| 1339 // new_state, which is large enough to receive it and then some. |
| 1340 new_state_count = arraysize(new_state); |
| 1341 ExcServerCopyState(MACH_EXCEPTION_CODES | EXCEPTION_STATE_IDENTITY, |
| 1342 old_state, |
| 1343 old_state_count, |
| 1344 new_state, |
| 1345 &new_state_count); |
| 1346 EXPECT_EQ(old_state_count, new_state_count); |
| 1347 for (size_t i = 0; i < arraysize(old_state); ++i) { |
| 1348 EXPECT_EQ(old_state[i], new_state[i]) << "i " << i; |
| 1349 } |
| 1350 for (size_t i = arraysize(old_state); i < arraysize(new_state); ++i) { |
| 1351 EXPECT_EQ(0u, new_state[i]) << "i " << i; |
| 1352 } |
| 1353 } |
| 1354 |
1278 } // namespace | 1355 } // namespace |
1279 } // namespace test | 1356 } // namespace test |
1280 } // namespace crashpad | 1357 } // namespace crashpad |
OLD | NEW |