mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +00:00
UserspaceEmulator: Use ring 3 segment selectors
We were using ring 0 selectors everywhere (the bottom 3 bits of a selector determines the ring.) This doesn't really make any practical difference since UE doesn't run code in other rings anyway, but let's have correct-looking segment selectors. :^)
This commit is contained in:
parent
2f1712cc29
commit
d55fb7b5e2
5 changed files with 25 additions and 25 deletions
|
@ -267,11 +267,11 @@ Vector<FlatPtr> Emulator::raw_backtrace()
|
|||
|
||||
u32 frame_ptr = m_cpu.ebp().value();
|
||||
while (frame_ptr) {
|
||||
u32 ret_ptr = m_mmu.read32({ 0x20, frame_ptr + 4 }).value();
|
||||
u32 ret_ptr = m_mmu.read32({ 0x23, frame_ptr + 4 }).value();
|
||||
if (!ret_ptr)
|
||||
break;
|
||||
backtrace.append(ret_ptr);
|
||||
frame_ptr = m_mmu.read32({ 0x20, frame_ptr }).value();
|
||||
frame_ptr = m_mmu.read32({ 0x23, frame_ptr }).value();
|
||||
}
|
||||
return backtrace;
|
||||
}
|
||||
|
@ -984,7 +984,7 @@ int Emulator::virt$pipe(FlatPtr vm_pipefd, int flags)
|
|||
|
||||
u32 Emulator::virt$munmap(FlatPtr address, u32 size)
|
||||
{
|
||||
auto* region = mmu().find_region({ 0x20, address });
|
||||
auto* region = mmu().find_region({ 0x23, address });
|
||||
ASSERT(region);
|
||||
if (region->size() != round_up_to_power_of_two(size, PAGE_SIZE))
|
||||
TODO();
|
||||
|
|
|
@ -60,7 +60,7 @@ void MallocTracer::target_did_malloc(Badge<SoftCPU>, FlatPtr address, size_t siz
|
|||
{
|
||||
if (m_emulator.is_in_loader_code())
|
||||
return;
|
||||
auto* region = m_emulator.mmu().find_region({ 0x20, address });
|
||||
auto* region = m_emulator.mmu().find_region({ 0x23, address });
|
||||
ASSERT(region);
|
||||
ASSERT(region->is_mmap());
|
||||
auto& mmap_region = static_cast<MmapRegion&>(*region);
|
||||
|
@ -143,7 +143,7 @@ void MallocTracer::target_did_realloc(Badge<SoftCPU>, FlatPtr address, size_t si
|
|||
{
|
||||
if (m_emulator.is_in_loader_code())
|
||||
return;
|
||||
auto* region = m_emulator.mmu().find_region({ 0x20, address });
|
||||
auto* region = m_emulator.mmu().find_region({ 0x23, address });
|
||||
ASSERT(region);
|
||||
ASSERT(region->is_mmap());
|
||||
auto& mmap_region = static_cast<MmapRegion&>(*region);
|
||||
|
@ -309,7 +309,7 @@ bool MallocTracer::is_reachable(const Mallocation& mallocation) const
|
|||
return IterationDecision::Continue;
|
||||
size_t pointers_in_mallocation = other_mallocation.size / sizeof(u32);
|
||||
for (size_t i = 0; i < pointers_in_mallocation; ++i) {
|
||||
auto value = m_emulator.mmu().read32({ 0x20, other_mallocation.address + i * sizeof(u32) });
|
||||
auto value = m_emulator.mmu().read32({ 0x23, other_mallocation.address + i * sizeof(u32) });
|
||||
if (value.value() == mallocation.address && !value.is_uninitialized()) {
|
||||
#ifdef REACHABLE_DEBUG
|
||||
reportln("mallocation {:p} is reachable from other mallocation {:p}", mallocation.address, other_mallocation.address);
|
||||
|
|
|
@ -97,11 +97,11 @@ SoftCPU::SoftCPU(Emulator& emulator)
|
|||
memset(m_gpr, 0, sizeof(m_gpr));
|
||||
memset(m_gpr_shadow, 1, sizeof(m_gpr_shadow));
|
||||
|
||||
m_segment[(int)X86::SegmentRegister::CS] = 0x18;
|
||||
m_segment[(int)X86::SegmentRegister::DS] = 0x20;
|
||||
m_segment[(int)X86::SegmentRegister::ES] = 0x20;
|
||||
m_segment[(int)X86::SegmentRegister::SS] = 0x20;
|
||||
m_segment[(int)X86::SegmentRegister::GS] = 0x28;
|
||||
m_segment[(int)X86::SegmentRegister::CS] = 0x1b;
|
||||
m_segment[(int)X86::SegmentRegister::DS] = 0x23;
|
||||
m_segment[(int)X86::SegmentRegister::ES] = 0x23;
|
||||
m_segment[(int)X86::SegmentRegister::SS] = 0x23;
|
||||
m_segment[(int)X86::SegmentRegister::GS] = 0x2b;
|
||||
}
|
||||
|
||||
void SoftCPU::dump() const
|
||||
|
@ -147,7 +147,7 @@ void SoftCPU::update_code_cache()
|
|||
|
||||
ValueWithShadow<u8> SoftCPU::read_memory8(X86::LogicalAddress address)
|
||||
{
|
||||
ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
|
||||
ASSERT(address.selector() == 0x1b || address.selector() == 0x23 || address.selector() == 0x2b);
|
||||
auto value = m_emulator.mmu().read8(address);
|
||||
#ifdef MEMORY_DEBUG
|
||||
outln("\033[36;1mread_memory8: @{:04x}:{:08x} -> {:02x} ({:02x})\033[0m", address.selector(), address.offset(), value, value.shadow());
|
||||
|
@ -157,7 +157,7 @@ ValueWithShadow<u8> SoftCPU::read_memory8(X86::LogicalAddress address)
|
|||
|
||||
ValueWithShadow<u16> SoftCPU::read_memory16(X86::LogicalAddress address)
|
||||
{
|
||||
ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
|
||||
ASSERT(address.selector() == 0x1b || address.selector() == 0x23 || address.selector() == 0x2b);
|
||||
auto value = m_emulator.mmu().read16(address);
|
||||
#ifdef MEMORY_DEBUG
|
||||
outln("\033[36;1mread_memory16: @{:04x}:{:08x} -> {:04x} ({:04x})\033[0m", address.selector(), address.offset(), value, value.shadow());
|
||||
|
@ -167,7 +167,7 @@ ValueWithShadow<u16> SoftCPU::read_memory16(X86::LogicalAddress address)
|
|||
|
||||
ValueWithShadow<u32> SoftCPU::read_memory32(X86::LogicalAddress address)
|
||||
{
|
||||
ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
|
||||
ASSERT(address.selector() == 0x1b || address.selector() == 0x23 || address.selector() == 0x2b);
|
||||
auto value = m_emulator.mmu().read32(address);
|
||||
#ifdef MEMORY_DEBUG
|
||||
outln("\033[36;1mread_memory32: @{:04x}:{:08x} -> {:08x} ({:08x})\033[0m", address.selector(), address.offset(), value, value.shadow());
|
||||
|
@ -177,7 +177,7 @@ ValueWithShadow<u32> SoftCPU::read_memory32(X86::LogicalAddress address)
|
|||
|
||||
ValueWithShadow<u64> SoftCPU::read_memory64(X86::LogicalAddress address)
|
||||
{
|
||||
ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
|
||||
ASSERT(address.selector() == 0x1b || address.selector() == 0x23 || address.selector() == 0x2b);
|
||||
auto value = m_emulator.mmu().read64(address);
|
||||
#ifdef MEMORY_DEBUG
|
||||
outln("\033[36;1mread_memory64: @{:04x}:{:08x} -> {:016x} ({:016x})\033[0m", address.selector(), address.offset(), value, value.shadow());
|
||||
|
@ -187,7 +187,7 @@ ValueWithShadow<u64> SoftCPU::read_memory64(X86::LogicalAddress address)
|
|||
|
||||
void SoftCPU::write_memory8(X86::LogicalAddress address, ValueWithShadow<u8> value)
|
||||
{
|
||||
ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
|
||||
ASSERT(address.selector() == 0x23 || address.selector() == 0x2b);
|
||||
#ifdef MEMORY_DEBUG
|
||||
outln("\033[36;1mwrite_memory8: @{:04x}:{:08x} <- {:02x} ({:02x})\033[0m", address.selector(), address.offset(), value, value.shadow());
|
||||
#endif
|
||||
|
@ -196,7 +196,7 @@ void SoftCPU::write_memory8(X86::LogicalAddress address, ValueWithShadow<u8> val
|
|||
|
||||
void SoftCPU::write_memory16(X86::LogicalAddress address, ValueWithShadow<u16> value)
|
||||
{
|
||||
ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
|
||||
ASSERT(address.selector() == 0x23 || address.selector() == 0x2b);
|
||||
#ifdef MEMORY_DEBUG
|
||||
outln("\033[36;1mwrite_memory16: @{:04x}:{:08x} <- {:04x} ({:04x})\033[0m", address.selector(), address.offset(), value, value.shadow());
|
||||
#endif
|
||||
|
@ -205,7 +205,7 @@ void SoftCPU::write_memory16(X86::LogicalAddress address, ValueWithShadow<u16> v
|
|||
|
||||
void SoftCPU::write_memory32(X86::LogicalAddress address, ValueWithShadow<u32> value)
|
||||
{
|
||||
ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
|
||||
ASSERT(address.selector() == 0x23 || address.selector() == 0x2b);
|
||||
#ifdef MEMORY_DEBUG
|
||||
outln("\033[36;1mwrite_memory32: @{:04x}:{:08x} <- {:08x} ({:08x})\033[0m", address.selector(), address.offset(), value, value.shadow());
|
||||
#endif
|
||||
|
@ -214,7 +214,7 @@ void SoftCPU::write_memory32(X86::LogicalAddress address, ValueWithShadow<u32> v
|
|||
|
||||
void SoftCPU::write_memory64(X86::LogicalAddress address, ValueWithShadow<u64> value)
|
||||
{
|
||||
ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
|
||||
ASSERT(address.selector() == 0x23 || address.selector() == 0x2b);
|
||||
#ifdef MEMORY_DEBUG
|
||||
outln("\033[36;1mwrite_memory64: @{:04x}:{:08x} <- {:016x} ({:016x})\033[0m", address.selector(), address.offset(), value, value.shadow());
|
||||
#endif
|
||||
|
@ -226,7 +226,7 @@ void SoftCPU::push_string(const StringView& string)
|
|||
size_t space_to_allocate = round_up_to_power_of_two(string.length() + 1, 16);
|
||||
set_esp({ esp().value() - space_to_allocate, esp().shadow() });
|
||||
m_emulator.mmu().copy_to_vm(esp().value(), string.characters_without_null_termination(), string.length());
|
||||
m_emulator.mmu().write8({ 0x20, esp().value() + string.length() }, shadow_wrap_as_initialized((u8)'\0'));
|
||||
m_emulator.mmu().write8({ 0x23, esp().value() + string.length() }, shadow_wrap_as_initialized((u8)'\0'));
|
||||
}
|
||||
|
||||
void SoftCPU::push_buffer(const u8* data, size_t size)
|
||||
|
|
|
@ -41,7 +41,7 @@ SoftMMU::SoftMMU(Emulator& emulator)
|
|||
|
||||
void SoftMMU::add_region(NonnullOwnPtr<Region> region)
|
||||
{
|
||||
ASSERT(!find_region({ 0x20, region->base() }));
|
||||
ASSERT(!find_region({ 0x23, region->base() }));
|
||||
|
||||
// FIXME: More sanity checks pls
|
||||
if (region->is_shared_buffer())
|
||||
|
@ -114,7 +114,7 @@ ValueWithShadow<u32> SoftMMU::read32(X86::LogicalAddress address)
|
|||
{
|
||||
auto* region = find_region(address);
|
||||
if (!region) {
|
||||
reportln("SoftMMU::read32: No region for @ {:p}", address.offset());
|
||||
reportln("SoftMMU::read32: No region for @ {:04x}:{:p}", address.selector(), address.offset());
|
||||
m_emulator.dump_backtrace();
|
||||
TODO();
|
||||
}
|
||||
|
@ -221,14 +221,14 @@ void SoftMMU::copy_to_vm(FlatPtr destination, const void* source, size_t size)
|
|||
{
|
||||
// FIXME: We should have a way to preserve the shadow data here as well.
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
write8({ 0x20, destination + i }, shadow_wrap_as_initialized(((const u8*)source)[i]));
|
||||
write8({ 0x23, destination + i }, shadow_wrap_as_initialized(((const u8*)source)[i]));
|
||||
}
|
||||
|
||||
void SoftMMU::copy_from_vm(void* destination, const FlatPtr source, size_t size)
|
||||
{
|
||||
// FIXME: We should have a way to preserve the shadow data here as well.
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
((u8*)destination)[i] = read8({ 0x20, source + i }).value();
|
||||
((u8*)destination)[i] = read8({ 0x23, source + i }).value();
|
||||
}
|
||||
|
||||
ByteBuffer SoftMMU::copy_buffer_from_vm(const FlatPtr source, size_t size)
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
|
||||
ALWAYS_INLINE Region* find_region(X86::LogicalAddress address)
|
||||
{
|
||||
if (address.selector() == 0x28)
|
||||
if (address.selector() == 0x2b)
|
||||
return m_tls_region.ptr();
|
||||
|
||||
size_t page_index = (address.offset() & ~(PAGE_SIZE - 1)) / PAGE_SIZE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue