| 166 | } |
| 167 | |
| 168 | void* mmapAlignedZeroedMemory(size_t alignment, |
| 169 | size_t numBytes, |
| 170 | bool noAccess) { |
| 171 | // to enforce alignment, we try to make sure that the address we return is |
| 172 | // aligned to slab size. |
| 173 | size_t newBytes = numBytes + alignment; |
| 174 | const auto protFlag = noAccess ? PROT_NONE : PROT_READ | PROT_WRITE; |
| 175 | const auto mapFlag = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE; |
| 176 | void* memory = mmap(nullptr, newBytes, protFlag, mapFlag, -1, 0); |
| 177 | if (memory != MAP_FAILED) { |
| 178 | auto alignedMemory = align(alignment, numBytes, memory, newBytes); |
| 179 | XDCHECK_NE(alignedMemory, nullptr); |
| 180 | return alignedMemory; |
| 181 | } |
| 182 | throw std::system_error(errno, std::system_category(), "Cannot mmap"); |
| 183 | } |
| 184 | |
| 185 | void setMaxLockMemory(uint64_t bytes) { |
| 186 | struct rlimit rlim{bytes, bytes}; |
no test coverage detected