xref: /freebsd/contrib/llvm-project/compiler-rt/lib/scudo/standalone/mem_map_linux.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1*5f757f3fSDimitry Andric //===-- mem_map_linux.h -----------------------------------------*- C++ -*-===//
2*5f757f3fSDimitry Andric //
3*5f757f3fSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*5f757f3fSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*5f757f3fSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*5f757f3fSDimitry Andric //
7*5f757f3fSDimitry Andric //===----------------------------------------------------------------------===//
8*5f757f3fSDimitry Andric 
9*5f757f3fSDimitry Andric #ifndef SCUDO_MEM_MAP_LINUX_H_
10*5f757f3fSDimitry Andric #define SCUDO_MEM_MAP_LINUX_H_
11*5f757f3fSDimitry Andric 
12*5f757f3fSDimitry Andric #include "platform.h"
13*5f757f3fSDimitry Andric 
14*5f757f3fSDimitry Andric #if SCUDO_LINUX
15*5f757f3fSDimitry Andric 
16*5f757f3fSDimitry Andric #include "common.h"
17*5f757f3fSDimitry Andric #include "mem_map_base.h"
18*5f757f3fSDimitry Andric 
19*5f757f3fSDimitry Andric namespace scudo {
20*5f757f3fSDimitry Andric 
21*5f757f3fSDimitry Andric class MemMapLinux final : public MemMapBase<MemMapLinux> {
22*5f757f3fSDimitry Andric public:
23*5f757f3fSDimitry Andric   constexpr MemMapLinux() = default;
24*5f757f3fSDimitry Andric   MemMapLinux(uptr Base, uptr Capacity)
25*5f757f3fSDimitry Andric       : MapBase(Base), MapCapacity(Capacity) {}
26*5f757f3fSDimitry Andric 
27*5f757f3fSDimitry Andric   // Impls for base functions.
28*5f757f3fSDimitry Andric   bool mapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags = 0);
29*5f757f3fSDimitry Andric   void unmapImpl(uptr Addr, uptr Size);
30*5f757f3fSDimitry Andric   bool remapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags = 0);
31*5f757f3fSDimitry Andric   void setMemoryPermissionImpl(uptr Addr, uptr Size, uptr Flags);
32*5f757f3fSDimitry Andric   void releasePagesToOSImpl(uptr From, uptr Size) {
33*5f757f3fSDimitry Andric     return releaseAndZeroPagesToOSImpl(From, Size);
34*5f757f3fSDimitry Andric   }
35*5f757f3fSDimitry Andric   void releaseAndZeroPagesToOSImpl(uptr From, uptr Size);
36*5f757f3fSDimitry Andric   uptr getBaseImpl() { return MapBase; }
37*5f757f3fSDimitry Andric   uptr getCapacityImpl() { return MapCapacity; }
38*5f757f3fSDimitry Andric 
39*5f757f3fSDimitry Andric private:
40*5f757f3fSDimitry Andric   uptr MapBase = 0;
41*5f757f3fSDimitry Andric   uptr MapCapacity = 0;
42*5f757f3fSDimitry Andric };
43*5f757f3fSDimitry Andric 
44*5f757f3fSDimitry Andric // This will be deprecated when every allocator has been supported by each
45*5f757f3fSDimitry Andric // platform's `MemMap` implementation.
46*5f757f3fSDimitry Andric class ReservedMemoryLinux final
47*5f757f3fSDimitry Andric     : public ReservedMemory<ReservedMemoryLinux, MemMapLinux> {
48*5f757f3fSDimitry Andric public:
49*5f757f3fSDimitry Andric   // The following two are the Impls for function in `MemMapBase`.
50*5f757f3fSDimitry Andric   uptr getBaseImpl() { return MapBase; }
51*5f757f3fSDimitry Andric   uptr getCapacityImpl() { return MapCapacity; }
52*5f757f3fSDimitry Andric 
53*5f757f3fSDimitry Andric   // These threes are specific to `ReservedMemory`.
54*5f757f3fSDimitry Andric   bool createImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
55*5f757f3fSDimitry Andric   void releaseImpl();
56*5f757f3fSDimitry Andric   MemMapT dispatchImpl(uptr Addr, uptr Size);
57*5f757f3fSDimitry Andric 
58*5f757f3fSDimitry Andric private:
59*5f757f3fSDimitry Andric   uptr MapBase = 0;
60*5f757f3fSDimitry Andric   uptr MapCapacity = 0;
61*5f757f3fSDimitry Andric };
62*5f757f3fSDimitry Andric 
63*5f757f3fSDimitry Andric } // namespace scudo
64*5f757f3fSDimitry Andric 
65*5f757f3fSDimitry Andric #endif // SCUDO_LINUX
66*5f757f3fSDimitry Andric 
67*5f757f3fSDimitry Andric #endif // SCUDO_MEM_MAP_LINUX_H_
68