1 //===-- mem_map.h -----------------------------------------------*- C++ -*-===//
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-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef SCUDO_MEM_MAP_H_
10 #define SCUDO_MEM_MAP_H_
12 #include "mem_map_base.h"
15 #include "internal_defs.h"
17 // TODO: This is only used for `MapPlatformData`. Remove these includes when we
18 // have all three platform specific `MemMap` and `ReservedMemory`
24 #include "mem_map_fuchsia.h"
28 // This will be deprecated when every allocator has been supported by each
29 // platform's `MemMap` implementation.
30 class MemMapDefault final : public MemMapBase<MemMapDefault> {
32 constexpr MemMapDefault() = default;
33 MemMapDefault(uptr Base, uptr Capacity) : Base(Base), Capacity(Capacity) {}
35 // Impls for base functions.
36 bool mapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
37 void unmapImpl(uptr Addr, uptr Size);
38 bool remapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
39 void setMemoryPermissionImpl(uptr Addr, uptr Size, uptr Flags);
40 void releasePagesToOSImpl(uptr From, uptr Size) {
41 return releaseAndZeroPagesToOSImpl(From, Size);
43 void releaseAndZeroPagesToOSImpl(uptr From, uptr Size);
44 uptr getBaseImpl() { return Base; }
45 uptr getCapacityImpl() { return Capacity; }
47 void setMapPlatformData(MapPlatformData &NewData) { Data = NewData; }
53 MapPlatformData Data = {};
56 // This will be deprecated when every allocator has been supported by each
57 // platform's `MemMap` implementation.
58 class ReservedMemoryDefault final
59 : public ReservedMemory<ReservedMemoryDefault, MemMapDefault> {
61 constexpr ReservedMemoryDefault() = default;
63 bool createImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
65 MemMapT dispatchImpl(uptr Addr, uptr Size);
66 uptr getBaseImpl() { return Base; }
67 uptr getCapacityImpl() { return Capacity; }
72 MapPlatformData Data = {};
76 using ReservedMemoryT = ReservedMemoryDefault;
77 using MemMapT = ReservedMemoryT::MemMapT;
79 using ReservedMemoryT = ReservedMemoryDefault;
80 using MemMapT = ReservedMemoryT::MemMapT;
82 using ReservedMemoryT = ReservedMemoryDefault;
83 using MemMapT = ReservedMemoryT::MemMapT;
86 "Unsupported platform, please implement the ReservedMemory for your platform!"
91 #endif // SCUDO_MEM_MAP_H_