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

Side by Side Diff: syzygy/agent/asan/page_protection_helpers_unittest.cc

Issue 2508333002: Remove the is_nested bit from the BlockInfo structure. (Closed)
Patch Set: Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2014 Google Inc. All Rights Reserved. 1 // Copyright 2014 Google Inc. 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 uint32_t min_right_redzone_size) { 169 uint32_t min_right_redzone_size) {
170 // Create and initialize the given block. 170 // Create and initialize the given block.
171 BlockLayout layout = {}; 171 BlockLayout layout = {};
172 EXPECT_TRUE(BlockPlanLayout(chunk_size, alignment, size, 172 EXPECT_TRUE(BlockPlanLayout(chunk_size, alignment, size,
173 min_left_redzone_size, min_right_redzone_size, 173 min_left_redzone_size, min_right_redzone_size,
174 &layout)); 174 &layout));
175 void* alloc = 175 void* alloc =
176 ::VirtualAlloc(NULL, layout.block_size, MEM_COMMIT, PAGE_READWRITE); 176 ::VirtualAlloc(NULL, layout.block_size, MEM_COMMIT, PAGE_READWRITE);
177 ASSERT_TRUE(alloc != NULL); 177 ASSERT_TRUE(alloc != NULL);
178 BlockInfo block_info = {}; 178 BlockInfo block_info = {};
179 BlockInitialize(layout, alloc, false, &block_info); 179 BlockInitialize(layout, alloc, &block_info);
180 180
181 // By default the protections should be disabled for a fresh allocation. 181 // By default the protections should be disabled for a fresh allocation.
182 EXPECT_NO_FATAL_FAILURE( 182 EXPECT_NO_FATAL_FAILURE(
183 TestAccessUnderProtection(block_info, kProtectNone)); 183 TestAccessUnderProtection(block_info, kProtectNone));
184 184
185 // Try a full cycle of page protections. This tests all possible 185 // Try a full cycle of page protections. This tests all possible
186 // transitions, including self transitions. 186 // transitions, including self transitions.
187 EXPECT_NO_FATAL_FAILURE(TestProtectNone(block_info)); 187 EXPECT_NO_FATAL_FAILURE(TestProtectNone(block_info));
188 EXPECT_NO_FATAL_FAILURE(TestProtectNone(block_info)); 188 EXPECT_NO_FATAL_FAILURE(TestProtectNone(block_info));
189 EXPECT_NO_FATAL_FAILURE(TestProtectRedzones(block_info)); 189 EXPECT_NO_FATAL_FAILURE(TestProtectRedzones(block_info));
(...skipping 20 matching lines...) Expand all
210 BlockLayout layout = {}; 210 BlockLayout layout = {};
211 BlockPlanLayout(4096, 4096, 4096, 4096, 4096, &layout); 211 BlockPlanLayout(4096, 4096, 4096, 4096, 4096, &layout);
212 212
213 void* alloc = ::VirtualAlloc( 213 void* alloc = ::VirtualAlloc(
214 nullptr, layout.block_size, MEM_COMMIT, PAGE_READWRITE); 214 nullptr, layout.block_size, MEM_COMMIT, PAGE_READWRITE);
215 ASSERT_TRUE(alloc != nullptr); 215 ASSERT_TRUE(alloc != nullptr);
216 ::memset(alloc, 0, layout.block_size); 216 ::memset(alloc, 0, layout.block_size);
217 217
218 // Initialize the block in both memory and the shadow memory. 218 // Initialize the block in both memory and the shadow memory.
219 BlockInfo info = {}; 219 BlockInfo info = {};
220 BlockInitialize(layout, alloc, false, &info); 220 BlockInitialize(layout, alloc, &info);
221 shadow_.PoisonAllocatedBlock(info); 221 shadow_.PoisonAllocatedBlock(info);
222 222
223 // Try recovering in the usual case. 223 // Try recovering in the usual case.
224 BlockInfo info_recovered = {}; 224 BlockInfo info_recovered = {};
225 EXPECT_TRUE(BlockInfoFromMemory(info.header, &info_recovered)); 225 EXPECT_TRUE(BlockInfoFromMemory(info.header, &info_recovered));
226 EXPECT_TRUE(GetBlockInfo(&shadow_, info.body, &info_recovered)); 226 EXPECT_TRUE(GetBlockInfo(&shadow_, info.body, &info_recovered));
227 EXPECT_EQ(0, ::memcmp(&info, &info_recovered, sizeof(info))); 227 EXPECT_EQ(0, ::memcmp(&info, &info_recovered, sizeof(info)));
228 228
229 // Muck up the header and try again. 229 // Muck up the header and try again.
230 info.header->magic++; 230 info.header->magic++;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 TEST_F(PageProtectionHelpersTest, BlockProtectAuto) { 272 TEST_F(PageProtectionHelpersTest, BlockProtectAuto) {
273 BlockLayout layout = {}; 273 BlockLayout layout = {};
274 const uint32_t kPageSize = static_cast<uint32_t>(GetPageSize()); 274 const uint32_t kPageSize = static_cast<uint32_t>(GetPageSize());
275 EXPECT_TRUE(BlockPlanLayout(kPageSize, kPageSize, kPageSize, kPageSize, 275 EXPECT_TRUE(BlockPlanLayout(kPageSize, kPageSize, kPageSize, kPageSize,
276 kPageSize, &layout)); 276 kPageSize, &layout));
277 void* alloc = ::VirtualAlloc(NULL, layout.block_size, MEM_COMMIT, 277 void* alloc = ::VirtualAlloc(NULL, layout.block_size, MEM_COMMIT,
278 PAGE_READWRITE); 278 PAGE_READWRITE);
279 ASSERT_TRUE(alloc != NULL); 279 ASSERT_TRUE(alloc != NULL);
280 280
281 BlockInfo block_info = {}; 281 BlockInfo block_info = {};
282 BlockInitialize(layout, alloc, false, &block_info); 282 BlockInitialize(layout, alloc, &block_info);
283 TestAccessUnderProtection(block_info, kProtectNone); 283 TestAccessUnderProtection(block_info, kProtectNone);
284 284
285 block_info.header->state = ALLOCATED_BLOCK; 285 block_info.header->state = ALLOCATED_BLOCK;
286 BlockProtectAuto(block_info, &shadow_); 286 BlockProtectAuto(block_info, &shadow_);
287 TestAccessUnderProtection(block_info, kProtectRedzones); 287 TestAccessUnderProtection(block_info, kProtectRedzones);
288 BlockProtectNone(block_info, &shadow_); 288 BlockProtectNone(block_info, &shadow_);
289 289
290 block_info.header->state = QUARANTINED_BLOCK; 290 block_info.header->state = QUARANTINED_BLOCK;
291 BlockProtectAuto(block_info, &shadow_); 291 BlockProtectAuto(block_info, &shadow_);
292 TestAccessUnderProtection(block_info, kProtectAll); 292 TestAccessUnderProtection(block_info, kProtectAll);
293 BlockProtectNone(block_info, &shadow_); 293 BlockProtectNone(block_info, &shadow_);
294 294
295 block_info.header->state = QUARANTINED_FLOODED_BLOCK; 295 block_info.header->state = QUARANTINED_FLOODED_BLOCK;
296 BlockProtectAuto(block_info, &shadow_); 296 BlockProtectAuto(block_info, &shadow_);
297 TestAccessUnderProtection(block_info, kProtectAll); 297 TestAccessUnderProtection(block_info, kProtectAll);
298 BlockProtectNone(block_info, &shadow_); 298 BlockProtectNone(block_info, &shadow_);
299 299
300 block_info.header->state = FREED_BLOCK; 300 block_info.header->state = FREED_BLOCK;
301 BlockProtectAuto(block_info, &shadow_); 301 BlockProtectAuto(block_info, &shadow_);
302 TestAccessUnderProtection(block_info, kProtectAll); 302 TestAccessUnderProtection(block_info, kProtectAll);
303 BlockProtectNone(block_info, &shadow_); 303 BlockProtectNone(block_info, &shadow_);
304 304
305 ASSERT_EQ(TRUE, ::VirtualFree(alloc, 0, MEM_RELEASE)); 305 ASSERT_EQ(TRUE, ::VirtualFree(alloc, 0, MEM_RELEASE));
306 } 306 }
307 307
308 } // namespace asan 308 } // namespace asan
309 } // namespace agent 309 } // namespace agent
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698