1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:38:11 +00:00

UserspaceEmulator: Add support for shared buffers (shbuf)

We track these separately from regular mmap() regions, as they have
slightly different behaviors.
This commit is contained in:
Andreas Kling 2020-07-15 17:32:46 +02:00
parent 0ce4d3e942
commit 2da44dba44
7 changed files with 312 additions and 13 deletions

View file

@ -25,6 +25,7 @@
*/
#include "SoftMMU.h"
#include "SharedBufferRegion.h"
#include <AK/ByteBuffer.h>
namespace UserspaceEmulator {
@ -45,11 +46,15 @@ void SoftMMU::add_region(NonnullOwnPtr<Region> region)
{
ASSERT(!find_region({ 0x20, region->base() }));
// FIXME: More sanity checks pls
if (region->is_shared_buffer())
m_shbuf_regions.set(static_cast<SharedBufferRegion*>(region.ptr())->shbuf_id(), region.ptr());
m_regions.append(move(region));
}
void SoftMMU::remove_region(Region& region)
{
if (region.is_shared_buffer())
m_shbuf_regions.remove(static_cast<SharedBufferRegion&>(region).shbuf_id());
m_regions.remove_first_matching([&](auto& entry) { return entry.ptr() == &region; });
}
@ -144,4 +149,9 @@ ByteBuffer SoftMMU::copy_buffer_from_vm(const FlatPtr source, size_t size)
return buffer;
}
SharedBufferRegion* SoftMMU::shbuf_region(int shbuf_id)
{
return (SharedBufferRegion*)m_shbuf_regions.get(shbuf_id).value_or(nullptr);
}
}