diff options
author | Chia-hung Duan <chiahungduan@google.com> | 2023-04-07 04:56:40 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-04-07 04:56:40 +0000 |
commit | 4781aa4b8f4d779cf0654fdad7c0a1458d96ba00 (patch) | |
tree | fe36f97e91fcb41a34ff3b1ae0298a5ccffe7606 | |
parent | 9ddc1a45b1c408b1db9ad79029f1d2bf3f61e557 (diff) | |
parent | 086d2c65a56d00c78ac4c0cda1c8cfbaf75ae288 (diff) | |
download | scudo-4781aa4b8f4d779cf0654fdad7c0a1458d96ba00.tar.gz |
Revert "[scudo] Switch to use MemMap in tests" am: 602204b456 am: edab38adb3 am: 85c4ac04fa am: 086d2c65a5
Original change: https://android-review.googlesource.com/c/platform/external/scudo/+/2528022
Change-Id: Iebd02f4956cba7df44c6be83b613f883ebc19a51
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | standalone/tests/combined_test.cpp | 10 | ||||
-rw-r--r-- | standalone/tests/common_test.cpp | 23 | ||||
-rw-r--r-- | standalone/tests/map_test.cpp | 73 | ||||
-rw-r--r-- | standalone/tests/memtag_test.cpp | 18 |
4 files changed, 52 insertions, 72 deletions
diff --git a/standalone/tests/combined_test.cpp b/standalone/tests/combined_test.cpp index 7bf580e3770..550fdd3dd76 100644 --- a/standalone/tests/combined_test.cpp +++ b/standalone/tests/combined_test.cpp @@ -12,7 +12,6 @@ #include "allocator_config.h" #include "chunk.h" #include "combined.h" -#include "mem_map.h" #include <condition_variable> #include <memory> @@ -496,12 +495,11 @@ SCUDO_TYPED_TEST(ScudoCombinedTest, ThreadedCombined) { // process's signal handlers (GWP-ASan used to do this). TEST(ScudoCombinedDeathTest, SKIP_ON_FUCHSIA(testSEGV)) { const scudo::uptr Size = 4 * scudo::getPageSizeCached(); - scudo::ReservedMemoryT ReservedMemory; - ASSERT_TRUE(ReservedMemory.create(/*Addr=*/0U, Size, "testSEGV")); - void *P = reinterpret_cast<void *>(ReservedMemory.getBase()); - ASSERT_NE(P, nullptr); + scudo::MapPlatformData Data = {}; + void *P = scudo::map(nullptr, Size, "testSEGV", MAP_NOACCESS, &Data); + EXPECT_NE(P, nullptr); EXPECT_DEATH(memset(P, 0xaa, Size), ""); - ReservedMemory.release(); + scudo::unmap(P, Size, UNMAP_ALL, &Data); } struct DeathSizeClassConfig { diff --git a/standalone/tests/common_test.cpp b/standalone/tests/common_test.cpp index f7392787315..a9794f03fd7 100644 --- a/standalone/tests/common_test.cpp +++ b/standalone/tests/common_test.cpp @@ -10,7 +10,6 @@ #include "tests/scudo_unit_test.h" #include "common.h" -#include "mem_map.h" #include <algorithm> #include <fstream> @@ -35,39 +34,39 @@ TEST(ScudoCommonTest, SKIP_ON_FUCHSIA(ResidentMemorySize)) { const uptr Size = 1ull << 30; const uptr Threshold = Size >> 3; - MemMapT MemMap; - ASSERT_TRUE(MemMap.map(/*Addr=*/0U, Size, "ResidentMemorySize")); - void *P = reinterpret_cast<void *>(MemMap.getBase()); + MapPlatformData Data = {}; + void *P = map(nullptr, Size, "ResidentMemorySize", 0, &Data); + ASSERT_NE(nullptr, P); EXPECT_LT(getResidentMemorySize(), OnStart + Threshold); memset(P, 1, Size); EXPECT_GT(getResidentMemorySize(), OnStart + Size - Threshold); - MemMap.releasePagesToOS(MemMap.getBase(), Size); + releasePagesToOS((uptr)P, 0, Size, &Data); EXPECT_LT(getResidentMemorySize(), OnStart + Threshold); memset(P, 1, Size); EXPECT_GT(getResidentMemorySize(), OnStart + Size - Threshold); - MemMap.unmap(MemMap.getBase(), Size); + unmap(P, Size, 0, &Data); } TEST(ScudoCommonTest, Zeros) { const uptr Size = 1ull << 20; - MemMapT MemMap; - ASSERT_TRUE(MemMap.map(/*Addr=*/0U, Size, "Zeros")); - uptr *P = reinterpret_cast<uptr *>(MemMap.getBase()); - const ptrdiff_t N = Size / sizeof(uptr); + MapPlatformData Data = {}; + uptr *P = reinterpret_cast<uptr *>(map(nullptr, Size, "Zeros", 0, &Data)); + const ptrdiff_t N = Size / sizeof(*P); + ASSERT_NE(nullptr, P); EXPECT_EQ(std::count(P, P + N, 0), N); memset(P, 1, Size); EXPECT_EQ(std::count(P, P + N, 0), 0); - MemMap.releasePagesToOS(MemMap.getBase(), Size); + releasePagesToOS((uptr)P, 0, Size, &Data); EXPECT_EQ(std::count(P, P + N, 0), N); - MemMap.unmap(MemMap.getBase(), Size); + unmap(P, Size, 0, &Data); } #if 0 diff --git a/standalone/tests/map_test.cpp b/standalone/tests/map_test.cpp index 06a56f84803..ff05258db58 100644 --- a/standalone/tests/map_test.cpp +++ b/standalone/tests/map_test.cpp @@ -9,7 +9,6 @@ #include "tests/scudo_unit_test.h" #include "common.h" -#include "mem_map.h" #include <string.h> #include <unistd.h> @@ -23,15 +22,11 @@ TEST(ScudoMapTest, PageSize) { TEST(ScudoMapDeathTest, MapNoAccessUnmap) { const scudo::uptr Size = 4 * scudo::getPageSizeCached(); - scudo::ReservedMemoryT ReservedMemory; - - ASSERT_TRUE(ReservedMemory.create(/*Addr=*/0U, Size, MappingName)); - EXPECT_NE(ReservedMemory.getBase(), 0U); - EXPECT_DEATH( - memset(reinterpret_cast<void *>(ReservedMemory.getBase()), 0xaa, Size), - ""); - - ReservedMemory.release(); + scudo::MapPlatformData Data = {}; + void *P = scudo::map(nullptr, Size, MappingName, MAP_NOACCESS, &Data); + EXPECT_NE(P, nullptr); + EXPECT_DEATH(memset(P, 0xaa, Size), ""); + scudo::unmap(P, Size, UNMAP_ALL, &Data); } TEST(ScudoMapDeathTest, MapUnmap) { @@ -41,13 +36,11 @@ TEST(ScudoMapDeathTest, MapUnmap) { // Repeat few time to avoid missing crash if it's mmaped by unrelated // code. for (int i = 0; i < 10; ++i) { - scudo::MemMapT MemMap; - MemMap.map(/*Addr=*/0U, Size, MappingName); - scudo::uptr P = MemMap.getBase(); - if (P == 0U) + void *P = scudo::map(nullptr, Size, MappingName, 0, nullptr); + if (!P) continue; - MemMap.unmap(MemMap.getBase(), Size); - memset(reinterpret_cast<void *>(P), 0xbb, Size); + scudo::unmap(P, Size, 0, nullptr); + memset(P, 0xbb, Size); } }, ""); @@ -56,36 +49,30 @@ TEST(ScudoMapDeathTest, MapUnmap) { TEST(ScudoMapDeathTest, MapWithGuardUnmap) { const scudo::uptr PageSize = scudo::getPageSizeCached(); const scudo::uptr Size = 4 * PageSize; - scudo::ReservedMemoryT ReservedMemory; - ASSERT_TRUE( - ReservedMemory.create(/*Addr=*/0U, Size + 2 * PageSize, MappingName)); - ASSERT_NE(ReservedMemory.getBase(), 0U); - - scudo::MemMapT MemMap = - ReservedMemory.dispatch(ReservedMemory.getBase(), Size + 2 * PageSize); - ASSERT_TRUE(MemMap.isAllocated()); - scudo::uptr Q = MemMap.getBase() + PageSize; - ASSERT_TRUE(MemMap.remap(Q, Size, MappingName)); - memset(reinterpret_cast<void *>(Q), 0xaa, Size); - EXPECT_DEATH(memset(reinterpret_cast<void *>(Q), 0xaa, Size + 1), ""); - MemMap.unmap(MemMap.getBase(), MemMap.getCapacity()); + scudo::MapPlatformData Data = {}; + void *P = scudo::map(nullptr, Size + 2 * PageSize, MappingName, MAP_NOACCESS, + &Data); + EXPECT_NE(P, nullptr); + void *Q = + reinterpret_cast<void *>(reinterpret_cast<scudo::uptr>(P) + PageSize); + EXPECT_EQ(scudo::map(Q, Size, MappingName, 0, &Data), Q); + memset(Q, 0xaa, Size); + EXPECT_DEATH(memset(Q, 0xaa, Size + 1), ""); + scudo::unmap(P, Size + 2 * PageSize, UNMAP_ALL, &Data); } TEST(ScudoMapTest, MapGrowUnmap) { const scudo::uptr PageSize = scudo::getPageSizeCached(); const scudo::uptr Size = 4 * PageSize; - scudo::ReservedMemoryT ReservedMemory; - ReservedMemory.create(/*Addr=*/0U, Size, MappingName); - ASSERT_TRUE(ReservedMemory.isCreated()); - - scudo::MemMapT MemMap = - ReservedMemory.dispatch(ReservedMemory.getBase(), Size); - ASSERT_TRUE(MemMap.isAllocated()); - scudo::uptr Q = MemMap.getBase() + PageSize; - ASSERT_TRUE(MemMap.remap(Q, PageSize, MappingName)); - memset(reinterpret_cast<void *>(Q), 0xaa, PageSize); - Q += PageSize; - ASSERT_TRUE(MemMap.remap(Q, PageSize, MappingName)); - memset(reinterpret_cast<void *>(Q), 0xbb, PageSize); - MemMap.unmap(MemMap.getBase(), MemMap.getCapacity()); + scudo::MapPlatformData Data = {}; + void *P = scudo::map(nullptr, Size, MappingName, MAP_NOACCESS, &Data); + EXPECT_NE(P, nullptr); + void *Q = + reinterpret_cast<void *>(reinterpret_cast<scudo::uptr>(P) + PageSize); + EXPECT_EQ(scudo::map(Q, PageSize, MappingName, 0, &Data), Q); + memset(Q, 0xaa, PageSize); + Q = reinterpret_cast<void *>(reinterpret_cast<scudo::uptr>(Q) + PageSize); + EXPECT_EQ(scudo::map(Q, PageSize, MappingName, 0, &Data), Q); + memset(Q, 0xbb, PageSize); + scudo::unmap(P, Size, UNMAP_ALL, &Data); } diff --git a/standalone/tests/memtag_test.cpp b/standalone/tests/memtag_test.cpp index 369e3c1eb64..8a40eda3a57 100644 --- a/standalone/tests/memtag_test.cpp +++ b/standalone/tests/memtag_test.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "common.h" -#include "mem_map.h" #include "memtag.h" #include "platform.h" #include "tests/scudo_unit_test.h" @@ -46,23 +45,20 @@ protected: GTEST_SKIP() << "Memory tagging is not supported"; BufferSize = getPageSizeCached(); - scudo::MemMapT MemMap; - ASSERT_TRUE(MemMap.map(/*Addr=*/0U, BufferSize, "MemtagTest", MAP_MEMTAG)); - Addr = MemMap.getBase(); - Buffer = reinterpret_cast<u8 *>(Addr); + Buffer = reinterpret_cast<u8 *>( + map(nullptr, BufferSize, "MemtagTest", MAP_MEMTAG, &Data)); + Addr = reinterpret_cast<uptr>(Buffer); EXPECT_TRUE(isAligned(Addr, archMemoryTagGranuleSize())); EXPECT_EQ(Addr, untagPointer(Addr)); } void TearDown() override { - if (Buffer) { - ASSERT_TRUE(MemMap.isAllocated()); - MemMap.unmap(MemMap.getBase(), MemMap.getCapacity()); - } + if (Buffer) + unmap(Buffer, BufferSize, 0, &Data); } uptr BufferSize = 0; - scudo::MemMapT MemMap; + MapPlatformData Data = {}; u8 *Buffer = nullptr; uptr Addr = 0; }; @@ -183,7 +179,7 @@ TEST_F(MemtagTest, StoreTags) { EXPECT_EQ(LoadPtr, loadTag(LoadPtr)); // Reset tags without using StoreTags. - MemMap.releasePagesToOS(Addr, BufferSize); + releasePagesToOS(Addr, 0, BufferSize, &Data); } } |