OLD | NEW |
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 26 matching lines...) Expand all Loading... |
37 #include "syzygy/agent/asan/unittest_util.h" | 37 #include "syzygy/agent/asan/unittest_util.h" |
38 #include "syzygy/agent/asan/heaps/internal_heap.h" | 38 #include "syzygy/agent/asan/heaps/internal_heap.h" |
39 #include "syzygy/agent/asan/heaps/large_block_heap.h" | 39 #include "syzygy/agent/asan/heaps/large_block_heap.h" |
40 #include "syzygy/agent/asan/heaps/simple_block_heap.h" | 40 #include "syzygy/agent/asan/heaps/simple_block_heap.h" |
41 #include "syzygy/agent/asan/heaps/win_heap.h" | 41 #include "syzygy/agent/asan/heaps/win_heap.h" |
42 #include "syzygy/agent/asan/heaps/zebra_block_heap.h" | 42 #include "syzygy/agent/asan/heaps/zebra_block_heap.h" |
43 #include "syzygy/agent/asan/memory_notifiers/null_memory_notifier.h" | 43 #include "syzygy/agent/asan/memory_notifiers/null_memory_notifier.h" |
44 #include "syzygy/assm/assembler.h" | 44 #include "syzygy/assm/assembler.h" |
45 #include "syzygy/assm/buffer_serializer.h" | 45 #include "syzygy/assm/buffer_serializer.h" |
46 #include "syzygy/common/asan_parameters.h" | 46 #include "syzygy/common/asan_parameters.h" |
| 47 #include "syzygy/testing/laa.h" |
47 | 48 |
48 namespace agent { | 49 namespace agent { |
49 namespace asan { | 50 namespace asan { |
50 namespace heap_managers { | 51 namespace heap_managers { |
51 | 52 |
52 namespace { | 53 namespace { |
53 | 54 |
54 using heaps::ZebraBlockHeap; | 55 using heaps::ZebraBlockHeap; |
55 using testing::IsAccessible; | 56 using testing::IsAccessible; |
56 using testing::IsNotAccessible; | 57 using testing::IsNotAccessible; |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 const size_t kAllocSize = 17; | 606 const size_t kAllocSize = 17; |
606 HeapId heap_id = heap_manager_->CreateHeap(); | 607 HeapId heap_id = heap_manager_->CreateHeap(); |
607 EXPECT_NE(0u, heap_id); | 608 EXPECT_NE(0u, heap_id); |
608 void* alloc = heap_manager_->Allocate(heap_id, kAllocSize); | 609 void* alloc = heap_manager_->Allocate(heap_id, kAllocSize); |
609 EXPECT_NE(static_cast<void*>(nullptr), alloc); | 610 EXPECT_NE(static_cast<void*>(nullptr), alloc); |
610 EXPECT_LE(kAllocSize, heap_manager_->Size(heap_id, alloc)); | 611 EXPECT_LE(kAllocSize, heap_manager_->Size(heap_id, alloc)); |
611 EXPECT_TRUE(heap_manager_->Free(heap_id, alloc)); | 612 EXPECT_TRUE(heap_manager_->Free(heap_id, alloc)); |
612 EXPECT_TRUE(heap_manager_->DestroyHeap(heap_id)); | 613 EXPECT_TRUE(heap_manager_->DestroyHeap(heap_id)); |
613 } | 614 } |
614 | 615 |
| 616 TEST_F(BlockHeapManagerTest, AllocAndFreeLargeBlock) { |
| 617 TEST_ONLY_SUPPORTS_4G(); |
| 618 |
| 619 const size_t kAllocSize = 0x7000001c; |
| 620 HeapId heap_id = heap_manager_->CreateHeap(); |
| 621 EXPECT_NE(0u, heap_id); |
| 622 void* alloc = heap_manager_->Allocate(heap_id, kAllocSize); |
| 623 EXPECT_NE(static_cast<void*>(nullptr), alloc); |
| 624 EXPECT_LE(kAllocSize, heap_manager_->Size(heap_id, alloc)); |
| 625 EXPECT_TRUE(heap_manager_->Free(heap_id, alloc)); |
| 626 EXPECT_TRUE(heap_manager_->DestroyHeap(heap_id)); |
| 627 } |
| 628 |
| 629 TEST_F(BlockHeapManagerTest, AllocLargeBlockFail) { |
| 630 const size_t kAllocSize = 0x80000000; |
| 631 HeapId heap_id = heap_manager_->CreateHeap(); |
| 632 EXPECT_NE(0u, heap_id); |
| 633 void* alloc = heap_manager_->Allocate(heap_id, kAllocSize); |
| 634 EXPECT_EQ(static_cast<void*>(nullptr), alloc); |
| 635 EXPECT_TRUE(heap_manager_->DestroyHeap(heap_id)); |
| 636 } |
| 637 |
615 TEST_F(BlockHeapManagerTest, FreeNullPointer) { | 638 TEST_F(BlockHeapManagerTest, FreeNullPointer) { |
616 HeapId heap_id = heap_manager_->CreateHeap(); | 639 HeapId heap_id = heap_manager_->CreateHeap(); |
617 EXPECT_NE(0u, heap_id); | 640 EXPECT_NE(0u, heap_id); |
618 EXPECT_TRUE(heap_manager_->Free(heap_id, static_cast<void*>(nullptr))); | 641 EXPECT_TRUE(heap_manager_->Free(heap_id, static_cast<void*>(nullptr))); |
619 EXPECT_TRUE(heap_manager_->DestroyHeap(heap_id)); | 642 EXPECT_TRUE(heap_manager_->DestroyHeap(heap_id)); |
620 } | 643 } |
621 | 644 |
622 TEST_F(BlockHeapManagerTest, FreeUnguardedAlloc) { | 645 TEST_F(BlockHeapManagerTest, FreeUnguardedAlloc) { |
623 const size_t kAllocSize = 100; | 646 const size_t kAllocSize = 100; |
624 ::common::AsanParameters params = heap_manager_->parameters(); | 647 ::common::AsanParameters params = heap_manager_->parameters(); |
(...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1897 bi.header->alloc_stack->relative_stack_id()); | 1920 bi.header->alloc_stack->relative_stack_id()); |
1898 | 1921 |
1899 // Clear the heap ID and delete the block, expecting this to succeed. | 1922 // Clear the heap ID and delete the block, expecting this to succeed. |
1900 bi.trailer->heap_id = 0; | 1923 bi.trailer->heap_id = 0; |
1901 EXPECT_TRUE(heap_manager_->Free(wh, alloc)); | 1924 EXPECT_TRUE(heap_manager_->Free(wh, alloc)); |
1902 } | 1925 } |
1903 | 1926 |
1904 } // namespace heap_managers | 1927 } // namespace heap_managers |
1905 } // namespace asan | 1928 } // namespace asan |
1906 } // namespace agent | 1929 } // namespace agent |
OLD | NEW |