Kernel: Assert in RangeAllocator that sizes are multiple of PAGE_SIZE

This commit is contained in:
Andreas Kling 2021-01-27 19:45:53 +01:00
parent f6c6047e49
commit 76a69be217

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -71,6 +71,8 @@ void RangeAllocator::dump() const
Vector<Range, 2> Range::carve(const Range& taken) Vector<Range, 2> Range::carve(const Range& taken)
{ {
ASSERT((taken.size() % PAGE_SIZE) == 0);
Vector<Range, 2> parts; Vector<Range, 2> parts;
if (taken == *this) if (taken == *this)
return {}; return {};
@ -108,6 +110,8 @@ Range RangeAllocator::allocate_anywhere(size_t size, size_t alignment)
if (!size) if (!size)
return {}; return {};
ASSERT((size % PAGE_SIZE) == 0);
#ifdef VM_GUARD_PAGES #ifdef VM_GUARD_PAGES
// NOTE: We pad VM allocations with a guard page on each side. // NOTE: We pad VM allocations with a guard page on each side.
size_t effective_size = size + PAGE_SIZE * 2; size_t effective_size = size + PAGE_SIZE * 2;
@ -149,6 +153,8 @@ Range RangeAllocator::allocate_specific(VirtualAddress base, size_t size)
if (!size) if (!size)
return {}; return {};
ASSERT((size % PAGE_SIZE) == 0);
Range allocated_range(base, size); Range allocated_range(base, size);
ScopedSpinLock lock(m_lock); ScopedSpinLock lock(m_lock);
for (size_t i = 0; i < m_available_ranges.size(); ++i) { for (size_t i = 0; i < m_available_ranges.size(); ++i) {
@ -177,6 +183,7 @@ void RangeAllocator::deallocate(Range range)
ScopedSpinLock lock(m_lock); ScopedSpinLock lock(m_lock);
ASSERT(m_total_range.contains(range)); ASSERT(m_total_range.contains(range));
ASSERT(range.size()); ASSERT(range.size());
ASSERT((range.size() % PAGE_SIZE) == 0);
ASSERT(range.base() < range.end()); ASSERT(range.base() < range.end());
if constexpr (VRA_DEBUG) { if constexpr (VRA_DEBUG) {