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"
25 #include "mem_map_linux.h"
29 // This will be deprecated when every allocator has been supported by each
30 // platform's `MemMap` implementation.
31 class MemMapDefault final
: public MemMapBase
<MemMapDefault
> {
33 constexpr MemMapDefault() = default;
34 MemMapDefault(uptr Base
, uptr Capacity
) : Base(Base
), Capacity(Capacity
) {}
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
);
44 void releaseAndZeroPagesToOSImpl(uptr From
, uptr Size
);
45 uptr
getBaseImpl() { return Base
; }
46 uptr
getCapacityImpl() { return Capacity
; }
48 void setMapPlatformData(MapPlatformData
&NewData
) { Data
= NewData
; }
54 MapPlatformData Data
= {};
57 // This will be deprecated when every allocator has been supported by each
58 // platform's `MemMap` implementation.
59 class ReservedMemoryDefault final
60 : public ReservedMemory
<ReservedMemoryDefault
, MemMapDefault
> {
62 constexpr ReservedMemoryDefault() = default;
64 bool createImpl(uptr Addr
, uptr Size
, const char *Name
, uptr Flags
);
66 MemMapT
dispatchImpl(uptr Addr
, uptr Size
);
67 uptr
getBaseImpl() { return Base
; }
68 uptr
getCapacityImpl() { return Capacity
; }
73 MapPlatformData Data
= {};
77 using ReservedMemoryT
= ReservedMemoryLinux
;
78 using MemMapT
= ReservedMemoryT::MemMapT
;
80 using ReservedMemoryT
= ReservedMemoryFuchsia
;
81 using MemMapT
= ReservedMemoryT::MemMapT
;
83 using ReservedMemoryT
= ReservedMemoryDefault
;
84 using MemMapT
= ReservedMemoryT::MemMapT
;
87 "Unsupported platform, please implement the ReservedMemory for your platform!"
92 #endif // SCUDO_MEM_MAP_H_