llvm/compiler-rt/lib/scudo/standalone/size_class_map.h

//===-- size_class_map.h ----------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef SCUDO_SIZE_CLASS_MAP_H_
#define SCUDO_SIZE_CLASS_MAP_H_

#include "chunk.h"
#include "common.h"
#include "string_utils.h"

namespace scudo {

inline uptr scaledLog2(uptr Size, uptr ZeroLog, uptr LogBits) {}

template <typename Config> struct SizeClassMapBase {};

// SizeClassMap maps allocation sizes into size classes and back, in an
// efficient table-free manner.
//
// Class 0 is a special class that doesn't abide by the same rules as other
// classes. The allocator uses it to hold batches.
//
// The other sizes are controlled by the template parameters:
// - MinSizeLog: defines the first class as 2^MinSizeLog bytes.
// - MaxSizeLog: defines the last class as 2^MaxSizeLog bytes.
// - MidSizeLog: classes increase with step 2^MinSizeLog from 2^MinSizeLog to
//               2^MidSizeLog bytes.
// - NumBits: the number of non-zero bits in sizes after 2^MidSizeLog.
//            eg. with NumBits==3 all size classes after 2^MidSizeLog look like
//            0b1xx0..0 (where x is either 0 or 1).
//
// This class also gives a hint to a thread-caching allocator about the amount
// of chunks that can be cached per-thread:
// - MaxNumCachedHint is a hint for the max number of chunks cached per class.
// - 2^MaxBytesCachedLog is the max number of bytes cached per class.
template <typename Config>
class FixedSizeClassMap : public SizeClassMapBase<Config> {};

template <typename Config>
class TableSizeClassMap : public SizeClassMapBase<Config> {};

struct DefaultSizeClassConfig {};

DefaultSizeClassMap;

struct FuchsiaSizeClassConfig {};

FuchsiaSizeClassMap;

struct AndroidSizeClassConfig {};

AndroidSizeClassMap;

#if SCUDO_WORDSIZE == 64U && defined(__clang__)
static_assert;
#endif

struct TrustySizeClassConfig {};

TrustySizeClassMap;

template <typename SCMap> inline void printMap() {}

template <typename SCMap> static UNUSED void validateMap() {}
} // namespace scudo

#endif // SCUDO_SIZE_CLASS_MAP_H_