diff options
-rw-r--r-- | include/klee/KDAlloc/allocator.h | 53 | ||||
-rw-r--r-- | include/klee/KDAlloc/mapping.h | 12 | ||||
-rw-r--r-- | include/klee/KDAlloc/suballocators/loh.h | 4 |
3 files changed, 34 insertions, 35 deletions
diff --git a/include/klee/KDAlloc/allocator.h b/include/klee/KDAlloc/allocator.h index d848e94c..d7b1e0e2 100644 --- a/include/klee/KDAlloc/allocator.h +++ b/include/klee/KDAlloc/allocator.h @@ -192,35 +192,36 @@ public: : AllocatorFactory(Mapping{address, size}, quarantineSize) {} AllocatorFactory(Mapping &&mapping, std::uint32_t const quarantineSize) { - assert(mapping && "Invalid mapping"); - assert(mapping.getSize() > - Allocator::Control::meta.size() * 4096 + 3 * 4096 && - "Mapping is *far* to small"); - - control = new Allocator::Control(std::move(mapping)); - auto const binSize = - static_cast<std::size_t>(1) - << (std::numeric_limits<std::size_t>::digits - 1 - - countLeadingZeroes(control->mapping.getSize() / - (Allocator::Control::meta.size() + 1))); - char *const base = static_cast<char *>(control->mapping.getBaseAddress()); - std::size_t totalSize = 0; - for (std::size_t i = 0; i < Allocator::Control::meta.size(); ++i) { - control->sizedBins[i].initialize( - base + totalSize, binSize, Allocator::Control::meta[i], + if (mapping) { + assert(mapping.getSize() > + Allocator::Control::meta.size() * 4096 + 3 * 4096 && + "Mapping is *far* too small"); + + control = new Allocator::Control(std::move(mapping)); + auto const binSize = + static_cast<std::size_t>(1) + << (std::numeric_limits<std::size_t>::digits - 1 - + countLeadingZeroes(control->mapping.getSize() / + (Allocator::Control::meta.size() + 1))); + char *const base = static_cast<char *>(control->mapping.getBaseAddress()); + std::size_t totalSize = 0; + for (std::size_t i = 0; i < Allocator::Control::meta.size(); ++i) { + control->sizedBins[i].initialize( + base + totalSize, binSize, Allocator::Control::meta[i], + quarantineSize == unlimitedQuarantine, + quarantineSize == unlimitedQuarantine ? 0 : quarantineSize); + + totalSize += binSize; + assert(totalSize <= control->mapping.getSize() && "Mapping too small"); + } + + auto largeObjectBinSize = control->mapping.getSize() - totalSize; + assert(largeObjectBinSize > 0); + control->largeObjectBin.initialize( + base + totalSize, largeObjectBinSize, quarantineSize == unlimitedQuarantine, quarantineSize == unlimitedQuarantine ? 0 : quarantineSize); - - totalSize += binSize; - assert(totalSize <= control->mapping.getSize() && "Mapping too small"); } - - auto largeObjectBinSize = control->mapping.getSize() - totalSize; - assert(largeObjectBinSize > 0); - control->largeObjectBin.initialize( - base + totalSize, largeObjectBinSize, - quarantineSize == unlimitedQuarantine, - quarantineSize == unlimitedQuarantine ? 0 : quarantineSize); } explicit operator bool() const noexcept { return !control.isNull(); } diff --git a/include/klee/KDAlloc/mapping.h b/include/klee/KDAlloc/mapping.h index f566a211..c66e2f4b 100644 --- a/include/klee/KDAlloc/mapping.h +++ b/include/klee/KDAlloc/mapping.h @@ -54,6 +54,10 @@ class Mapping { auto mappedAddress = ::mmap(reinterpret_cast<void *>(baseAddress), size, PROT_READ | PROT_WRITE, flags, -1, 0); + if (mappedAddress == MAP_FAILED) { + this->baseAddress = MAP_FAILED; + return false; + } if (baseAddress != 0 && baseAddress != reinterpret_cast<std::uintptr_t>(mappedAddress)) { [[maybe_unused]] int rc = ::munmap(mappedAddress, size); @@ -61,10 +65,6 @@ class Mapping { this->baseAddress = MAP_FAILED; return false; } - if (mappedAddress == MAP_FAILED) { - this->baseAddress = MAP_FAILED; - return false; - } this->baseAddress = mappedAddress; #if defined(__linux__) @@ -98,10 +98,6 @@ public: Mapping(std::uintptr_t baseAddress, std::size_t size) noexcept : size(size) { try_map(baseAddress); - assert(*this && "failed to allocate mapping"); - if (!*this) { - std::abort(); - } } Mapping(Mapping const &) = delete; diff --git a/include/klee/KDAlloc/suballocators/loh.h b/include/klee/KDAlloc/suballocators/loh.h index 62386182..4b99942b 100644 --- a/include/klee/KDAlloc/suballocators/loh.h +++ b/include/klee/KDAlloc/suballocators/loh.h @@ -193,7 +193,9 @@ public: LargeObjectAllocator(LargeObjectAllocator &&rhs) noexcept : data(std::exchange(rhs.data, nullptr)) { - assert(data->referenceCount > 0); + if (data) { + assert(data->referenceCount > 0); + } } LargeObjectAllocator &operator=(LargeObjectAllocator &&rhs) noexcept { |