[compiler-rt] 89cc530 - Revert "[scudo] Switch to use MemMap in tests"
Chia-hung Duan via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 5 17:07:30 PDT 2023
Author: Chia-hung Duan
Date: 2023-04-06T00:06:34Z
New Revision: 89cc5304969ded574550e0ad113f59f3d4f50303
URL: https://github.com/llvm/llvm-project/commit/89cc5304969ded574550e0ad113f59f3d4f50303
DIFF: https://github.com/llvm/llvm-project/commit/89cc5304969ded574550e0ad113f59f3d4f50303.diff
LOG: Revert "[scudo] Switch to use MemMap in tests"
This reverts commit 4151477021170d8937f8fc820187d5934eb93c7d.
Added:
Modified:
compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
compiler-rt/lib/scudo/standalone/tests/common_test.cpp
compiler-rt/lib/scudo/standalone/tests/map_test.cpp
compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
index 7bf580e37706a..550fdd3dd7606 100644
--- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
+++ b/compiler-rt/lib/scudo/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/compiler-rt/lib/scudo/standalone/tests/common_test.cpp b/compiler-rt/lib/scudo/standalone/tests/common_test.cpp
index f7392787315e5..a9794f03fd7a5 100644
--- a/compiler-rt/lib/scudo/standalone/tests/common_test.cpp
+++ b/compiler-rt/lib/scudo/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 ptr
diff _t N = Size / sizeof(uptr);
+ MapPlatformData Data = {};
+ uptr *P = reinterpret_cast<uptr *>(map(nullptr, Size, "Zeros", 0, &Data));
+ const ptr
diff _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/compiler-rt/lib/scudo/standalone/tests/map_test.cpp b/compiler-rt/lib/scudo/standalone/tests/map_test.cpp
index 06a56f848030e..ff05258db58d1 100644
--- a/compiler-rt/lib/scudo/standalone/tests/map_test.cpp
+++ b/compiler-rt/lib/scudo/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/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp b/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp
index 369e3c1eb6499..8a40eda3a571a 100644
--- a/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp
+++ b/compiler-rt/lib/scudo/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 @@ class MemtagTest : public Test {
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);
}
}
More information about the llvm-commits
mailing list