1 //===-- mem_map.cpp ---------------------------------------------*- 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 //===----------------------------------------------------------------------===//
15 bool MemMapDefault::mapImpl(uptr Addr
, uptr Size
, const char *Name
,
18 ::scudo::map(reinterpret_cast<void *>(Addr
), Size
, Name
, Flags
, &Data
);
19 if (MappedAddr
== nullptr)
21 Base
= reinterpret_cast<uptr
>(MappedAddr
);
27 void MemMapDefault::unmapImpl(uptr Addr
, uptr Size
) {
28 if (Size
== Capacity
) {
29 Base
= MappedBase
= Capacity
= 0;
33 MappedBase
= MappedBase
== 0 ? Base
: Max(MappedBase
, Base
);
38 ::scudo::unmap(reinterpret_cast<void *>(Addr
), Size
, UNMAP_ALL
, &Data
);
41 bool MemMapDefault::remapImpl(uptr Addr
, uptr Size
, const char *Name
,
44 ::scudo::map(reinterpret_cast<void *>(Addr
), Size
, Name
, Flags
, &Data
);
45 const uptr RemappedAddr
= reinterpret_cast<uptr
>(RemappedPtr
);
46 MappedBase
= MappedBase
== 0 ? RemappedAddr
: Min(MappedBase
, RemappedAddr
);
47 return RemappedAddr
== Addr
;
50 void MemMapDefault::releaseAndZeroPagesToOSImpl(uptr From
, uptr Size
) {
51 DCHECK_NE(MappedBase
, 0U);
52 DCHECK_GE(From
, MappedBase
);
53 return ::scudo::releasePagesToOS(MappedBase
, From
- MappedBase
, Size
, &Data
);
56 void MemMapDefault::setMemoryPermissionImpl(uptr Addr
, uptr Size
, uptr Flags
) {
57 return ::scudo::setMemoryPermission(Addr
, Size
, Flags
);
60 void ReservedMemoryDefault::releaseImpl() {
61 ::scudo::unmap(reinterpret_cast<void *>(Base
), Capacity
, UNMAP_ALL
, &Data
);
64 bool ReservedMemoryDefault::createImpl(uptr Addr
, uptr Size
, const char *Name
,
66 void *Reserved
= ::scudo::map(reinterpret_cast<void *>(Addr
), Size
, Name
,
67 Flags
| MAP_NOACCESS
, &Data
);
68 if (Reserved
== nullptr)
71 Base
= reinterpret_cast<uptr
>(Reserved
);
77 ReservedMemoryDefault::MemMapT
ReservedMemoryDefault::dispatchImpl(uptr Addr
,
79 ReservedMemoryDefault::MemMapT
NewMap(Addr
, Size
);
80 NewMap
.setMapPlatformData(Data
);