brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · b92216c Raw
93 lines · c
1//===-- mem_map.h -----------------------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef SCUDO_MEM_MAP_H_10#define SCUDO_MEM_MAP_H_11 12#include "mem_map_base.h"13 14#include "common.h"15#include "internal_defs.h"16 17// TODO: This is only used for `MapPlatformData`. Remove these includes when we18// have all three platform specific `MemMap` and `ReservedMemory`19// implementations.20#include "fuchsia.h"21#include "linux.h"22#include "trusty.h"23 24#include "mem_map_fuchsia.h"25#include "mem_map_linux.h"26 27namespace scudo {28 29// This will be deprecated when every allocator has been supported by each30// platform's `MemMap` implementation.31class MemMapDefault final : public MemMapBase<MemMapDefault> {32public:33  constexpr MemMapDefault() = default;34  MemMapDefault(uptr Base, uptr Capacity) : Base(Base), Capacity(Capacity) {}35 36  // Impls for base functions.37  bool mapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);38  void unmapImpl(uptr Addr, uptr Size);39  bool remapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);40  void setMemoryPermissionImpl(uptr Addr, uptr Size, uptr Flags);41  void releasePagesToOSImpl(uptr From, uptr Size) {42    return releaseAndZeroPagesToOSImpl(From, Size);43  }44  void releaseAndZeroPagesToOSImpl(uptr From, uptr Size);45  uptr getBaseImpl() { return Base; }46  uptr getCapacityImpl() { return Capacity; }47 48  void setMapPlatformData(MapPlatformData &NewData) { Data = NewData; }49 50private:51  uptr Base = 0;52  uptr Capacity = 0;53  uptr MappedBase = 0;54  MapPlatformData Data = {};55};56 57// This will be deprecated when every allocator has been supported by each58// platform's `MemMap` implementation.59class ReservedMemoryDefault final60    : public ReservedMemory<ReservedMemoryDefault, MemMapDefault> {61public:62  constexpr ReservedMemoryDefault() = default;63 64  bool createImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);65  void releaseImpl();66  MemMapT dispatchImpl(uptr Addr, uptr Size);67  uptr getBaseImpl() { return Base; }68  uptr getCapacityImpl() { return Capacity; }69 70private:71  uptr Base = 0;72  uptr Capacity = 0;73  MapPlatformData Data = {};74};75 76#if SCUDO_LINUX77using ReservedMemoryT = ReservedMemoryLinux;78using MemMapT = ReservedMemoryT::MemMapT;79#elif SCUDO_FUCHSIA80using ReservedMemoryT = ReservedMemoryFuchsia;81using MemMapT = ReservedMemoryT::MemMapT;82#elif SCUDO_TRUSTY83using ReservedMemoryT = ReservedMemoryDefault;84using MemMapT = ReservedMemoryT::MemMapT;85#else86#error                                                                         \87    "Unsupported platform, please implement the ReservedMemory for your platform!"88#endif89 90} // namespace scudo91 92#endif // SCUDO_MEM_MAP_H_93