diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-25 15:39:26 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-25 15:39:26 +0100 |
commit | d55fb7b5e205c15a775b22b40d2b1d8006db4cad (patch) | |
tree | 2f7209b6db4c002b895968442459cf24b175ebef /DevTools | |
parent | 2f1712cc2906b6cd40c99eec733c949a6ade6861 (diff) | |
download | serenity-d55fb7b5e205c15a775b22b40d2b1d8006db4cad.zip |
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. :^)
Diffstat (limited to 'DevTools')
-rw-r--r-- | DevTools/UserspaceEmulator/Emulator.cpp | 6 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/MallocTracer.cpp | 6 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/SoftCPU.cpp | 28 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/SoftMMU.cpp | 8 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/SoftMMU.h | 2 |
5 files changed, 25 insertions, 25 deletions
diff --git a/DevTools/UserspaceEmulator/Emulator.cpp b/DevTools/UserspaceEmulator/Emulator.cpp index d09f71a21b..be6f368cab 100644 --- a/DevTools/UserspaceEmulator/Emulator.cpp +++ b/DevTools/UserspaceEmulator/Emulator.cpp @@ -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(); diff --git a/DevTools/UserspaceEmulator/MallocTracer.cpp b/DevTools/UserspaceEmulator/MallocTracer.cpp index 98e9c934c7..9661e615a5 100644 --- a/DevTools/UserspaceEmulator/MallocTracer.cpp +++ b/DevTools/UserspaceEmulator/MallocTracer.cpp @@ -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); diff --git a/DevTools/UserspaceEmulator/SoftCPU.cpp b/DevTools/UserspaceEmulator/SoftCPU.cpp index 280c38b35f..15aaa9eb4a 100644 --- a/DevTools/UserspaceEmulator/SoftCPU.cpp +++ b/DevTools/UserspaceEmulator/SoftCPU.cpp @@ -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) diff --git a/DevTools/UserspaceEmulator/SoftMMU.cpp b/DevTools/UserspaceEmulator/SoftMMU.cpp index 2b4bddd943..04e2242136 100644 --- a/DevTools/UserspaceEmulator/SoftMMU.cpp +++ b/DevTools/UserspaceEmulator/SoftMMU.cpp @@ -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) diff --git a/DevTools/UserspaceEmulator/SoftMMU.h b/DevTools/UserspaceEmulator/SoftMMU.h index c6ac21e415..33351ff57b 100644 --- a/DevTools/UserspaceEmulator/SoftMMU.h +++ b/DevTools/UserspaceEmulator/SoftMMU.h @@ -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; |