1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 15:55:08 +00:00
serenity/Userland/DevTools/UserspaceEmulator/RangeAllocator.h
Daniel Bertalan 4e1898df99 UserspaceEmulator: Exclude special ranges from RangeAllocator
If we do not mark these ranges as reserved, RangeAllocator might later
give us addresses that overlap these, which then causes an assertion
failure in the SoftMMU.  This behavior led to recurring CI failures, and
sometimes made programs as simple as `/bin/true` fail.

Fixes "Crash 1" reported in #9104
2021-12-28 19:28:13 +02:00

38 lines
847 B
C++

/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "Range.h"
#include <AK/Vector.h>
namespace UserspaceEmulator {
class RangeAllocator {
public:
RangeAllocator();
void initialize_with_range(VirtualAddress, size_t);
Optional<Range> allocate_anywhere(size_t, size_t alignment = PAGE_SIZE);
Optional<Range> allocate_specific(VirtualAddress, size_t);
Optional<Range> allocate_randomized(size_t, size_t alignment);
void deallocate(const Range&);
void reserve_user_range(VirtualAddress, size_t);
void dump() const;
bool contains(const Range& range) const { return m_total_range.contains(range); }
private:
void carve_at_index(int, const Range&);
Vector<Range> m_available_ranges;
Range m_total_range;
};
}