Path: blob/main/contrib/llvm-project/compiler-rt/lib/scudo/standalone/mem_map.h
35291 views
//===-- mem_map.h -----------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef SCUDO_MEM_MAP_H_9#define SCUDO_MEM_MAP_H_1011#include "mem_map_base.h"1213#include "common.h"14#include "internal_defs.h"1516// TODO: This is only used for `MapPlatformData`. Remove these includes when we17// have all three platform specific `MemMap` and `ReservedMemory`18// implementations.19#include "fuchsia.h"20#include "linux.h"21#include "trusty.h"2223#include "mem_map_fuchsia.h"24#include "mem_map_linux.h"2526namespace scudo {2728// This will be deprecated when every allocator has been supported by each29// platform's `MemMap` implementation.30class MemMapDefault final : public MemMapBase<MemMapDefault> {31public:32constexpr MemMapDefault() = default;33MemMapDefault(uptr Base, uptr Capacity) : Base(Base), Capacity(Capacity) {}3435// Impls for base functions.36bool mapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);37void unmapImpl(uptr Addr, uptr Size);38bool remapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);39void setMemoryPermissionImpl(uptr Addr, uptr Size, uptr Flags);40void releasePagesToOSImpl(uptr From, uptr Size) {41return releaseAndZeroPagesToOSImpl(From, Size);42}43void releaseAndZeroPagesToOSImpl(uptr From, uptr Size);44uptr getBaseImpl() { return Base; }45uptr getCapacityImpl() { return Capacity; }4647void setMapPlatformData(MapPlatformData &NewData) { Data = NewData; }4849private:50uptr Base = 0;51uptr Capacity = 0;52uptr MappedBase = 0;53MapPlatformData Data = {};54};5556// This will be deprecated when every allocator has been supported by each57// platform's `MemMap` implementation.58class ReservedMemoryDefault final59: public ReservedMemory<ReservedMemoryDefault, MemMapDefault> {60public:61constexpr ReservedMemoryDefault() = default;6263bool createImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);64void releaseImpl();65MemMapT dispatchImpl(uptr Addr, uptr Size);66uptr getBaseImpl() { return Base; }67uptr getCapacityImpl() { return Capacity; }6869private:70uptr Base = 0;71uptr Capacity = 0;72MapPlatformData Data = {};73};7475#if SCUDO_LINUX76using ReservedMemoryT = ReservedMemoryLinux;77using MemMapT = ReservedMemoryT::MemMapT;78#elif SCUDO_FUCHSIA79using ReservedMemoryT = ReservedMemoryFuchsia;80using MemMapT = ReservedMemoryT::MemMapT;81#elif SCUDO_TRUSTY82using ReservedMemoryT = ReservedMemoryDefault;83using MemMapT = ReservedMemoryT::MemMapT;84#else85#error \86"Unsupported platform, please implement the ReservedMemory for your platform!"87#endif8889} // namespace scudo9091#endif // SCUDO_MEM_MAP_H_929394