[DAG] TransformFPLoadStorePair - early out if we're not loading a simple type
[llvm-project.git] / compiler-rt / lib / scudo / standalone / mem_map.cpp
blob115cc34e70600b6dbbbbd812fcf727e075a5ac24
1 //===-- mem_map.cpp ---------------------------------------------*- 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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "mem_map.h"
11 #include "common.h"
13 namespace scudo {
15 bool MemMapDefault::mapImpl(uptr Addr, uptr Size, const char *Name,
16 uptr Flags) {
17 void *MappedAddr =
18 ::scudo::map(reinterpret_cast<void *>(Addr), Size, Name, Flags, &Data);
19 if (MappedAddr == nullptr)
20 return false;
21 Base = reinterpret_cast<uptr>(MappedAddr);
22 MappedBase = Base;
23 Capacity = Size;
24 return true;
27 void MemMapDefault::unmapImpl(uptr Addr, uptr Size) {
28 if (Size == Capacity) {
29 Base = MappedBase = Capacity = 0;
30 } else {
31 if (Base == Addr) {
32 Base = Addr + Size;
33 MappedBase = MappedBase == 0 ? Base : Max(MappedBase, Base);
35 Capacity -= Size;
38 ::scudo::unmap(reinterpret_cast<void *>(Addr), Size, UNMAP_ALL, &Data);
41 bool MemMapDefault::remapImpl(uptr Addr, uptr Size, const char *Name,
42 uptr Flags) {
43 void *RemappedPtr =
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,
65 uptr Flags) {
66 void *Reserved = ::scudo::map(reinterpret_cast<void *>(Addr), Size, Name,
67 Flags | MAP_NOACCESS, &Data);
68 if (Reserved == nullptr)
69 return false;
71 Base = reinterpret_cast<uptr>(Reserved);
72 Capacity = Size;
74 return true;
77 ReservedMemoryDefault::MemMapT ReservedMemoryDefault::dispatchImpl(uptr Addr,
78 uptr Size) {
79 ReservedMemoryDefault::MemMapT NewMap(Addr, Size);
80 NewMap.setMapPlatformData(Data);
81 return NewMap;
84 } // namespace scudo