The class is only used in SizeClassAllocator32 in 64-bit mode, but we don't
use that class in 64-bit mode.
Details
Details
- Reviewers
cryptoad - Commits
- rGdab7bdad0492: scudo: Delete unused class ScudoByteMap. NFCI.
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Comment Actions
Unit tests: pass. 62519 tests passed, 0 failed and 844 were skipped.
clang-tidy: pass.
clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.
Build artifacts: clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml
Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.
clang-format: please reformat the code
-template <uptr Level1Size, uptr Level2Size> class TwoLevelByteMap { -public: - void initLinkerInitialized() { - Level1Map = reinterpret_cast<atomic_uptr *>( - map(nullptr, sizeof(atomic_uptr) * Level1Size, "scudo:bytemap")); - } - void init() { - Mutex.init(); - initLinkerInitialized(); - } - - void reset() { - for (uptr I = 0; I < Level1Size; I++) { - u8 *P = get(I); - if (!P) - continue; - unmap(P, Level2Size); - } - memset(Level1Map, 0, sizeof(atomic_uptr) * Level1Size); - } - - void unmapTestOnly() { - reset(); - unmap(reinterpret_cast<void *>(Level1Map), - sizeof(atomic_uptr) * Level1Size); - } - - uptr size() const { return Level1Size * Level2Size; } - - void set(uptr Index, u8 Value) { - DCHECK_LT(Index, Level1Size * Level2Size); - u8 *Level2Map = getOrCreate(Index / Level2Size); - DCHECK_EQ(0U, Level2Map[Index % Level2Size]); - Level2Map[Index % Level2Size] = Value; - } - - u8 operator[](uptr Index) const { - DCHECK_LT(Index, Level1Size * Level2Size); - u8 *Level2Map = get(Index / Level2Size); - if (!Level2Map) - return 0; - return Level2Map[Index % Level2Size]; - } - - void disable() { Mutex.lock(); } - void enable() { Mutex.unlock(); } - -private: - u8 *get(uptr Index) const { - DCHECK_LT(Index, Level1Size); - return reinterpret_cast<u8 *>( - atomic_load(&Level1Map[Index], memory_order_acquire)); - } - - u8 *getOrCreate(uptr Index) { - u8 *Res = get(Index); - if (!Res) { - ScopedLock L(Mutex); - if (!(Res = get(Index))) { - Res = reinterpret_cast<u8 *>(map(nullptr, Level2Size, "scudo:bytemap")); - atomic_store(&Level1Map[Index], reinterpret_cast<uptr>(Res), - memory_order_release); - } - } - return Res; - } - - atomic_uptr *Level1Map; - HybridMutex Mutex; -}; -