1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:57:44 +00:00

UserspaceEmulator: Add a fast path for forward REP STOSB

This is used by memset() so we get a lot of mileage out of optimizing
this instruction.

Note that we currently audit every individual byte accessed separately.
This could be greatly improved by adding a range auditing mechanism to
MallocTracer.
This commit is contained in:
Andreas Kling 2020-11-15 17:54:11 +01:00
parent 92e152f11d
commit 102e1d330c
3 changed files with 45 additions and 0 deletions

View file

@ -26,9 +26,11 @@
#include "SoftMMU.h"
#include "Emulator.h"
#include "MmapRegion.h"
#include "Report.h"
#include "SharedBufferRegion.h"
#include <AK/ByteBuffer.h>
#include <AK/Memory.h>
namespace UserspaceEmulator {
@ -244,4 +246,29 @@ SharedBufferRegion* SoftMMU::shbuf_region(int shbuf_id)
return (SharedBufferRegion*)m_shbuf_regions.get(shbuf_id).value_or(nullptr);
}
bool SoftMMU::fast_fill_memory8(X86::LogicalAddress address, size_t size, ValueWithShadow<u8> value)
{
if (!size)
return true;
auto* region = find_region(address);
if (!region)
return false;
if (!region->contains(address.offset() + size - 1))
return false;
if (region->is_mmap() && static_cast<const MmapRegion&>(*region).is_malloc_block()) {
if (auto* tracer = Emulator::the().malloc_tracer()) {
// FIXME: Add a way to audit an entire range of memory instead of looping here!
for (size_t i = 0; i < size; i += sizeof(u8)) {
tracer->audit_write(address.offset() + (i * sizeof(u8)), sizeof(u8));
}
}
}
size_t offset_in_region = address.offset() - region->base();
memset(region->data() + offset_in_region, value.value(), size);
memset(region->shadow_data() + offset_in_region, value.shadow(), size);
return true;
}
}