Kernel: Move userspace virtual address range base to 0x10000

Now that the shared bottom 2 MiB virtual address mappings are gone
userspace can use lower virtual addresses.
This commit is contained in:
Idan Horowitz 2021-12-19 19:36:42 +02:00 committed by Brian Gianforcaro
parent fccd0432a1
commit 5f4a67434c
7 changed files with 18 additions and 4 deletions

12
Kernel/API/MemoryLayout.h Normal file
View file

@ -0,0 +1,12 @@
/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
#include <Kernel/Sections.h>
constexpr FlatPtr userspace_range_base = USER_RANGE_BASE;

View file

@ -333,6 +333,7 @@ UNMAP_AFTER_INIT void APIC::setup_ap_boot_environment()
// * aps_to_enable u32 values for ap_cpu_init_stacks
// * aps_to_enable u32 values for ap_cpu_init_processor_info_array
constexpr u64 apic_startup_region_base = 0x8000;
VERIFY(apic_startup_region_base + apic_ap_start_size < USER_RANGE_BASE);
auto apic_startup_region = create_identity_mapped_region(PhysicalAddress(apic_startup_region_base), Memory::page_round_up(apic_ap_start_size + (2 * aps_to_enable * sizeof(u32))));
memcpy(apic_startup_region->vaddr().as_ptr(), reinterpret_cast<const void*>(apic_ap_start), apic_ap_start_size);

View file

@ -44,7 +44,7 @@ UNMAP_AFTER_INIT NonnullRefPtr<PageDirectory> PageDirectory::must_create_kernel_
ErrorOr<NonnullRefPtr<PageDirectory>> PageDirectory::try_create_for_userspace(VirtualRangeAllocator const* parent_range_allocator)
{
constexpr FlatPtr userspace_range_base = 0x00800000;
constexpr FlatPtr userspace_range_base = USER_RANGE_BASE;
FlatPtr const userspace_range_ceiling = USER_RANGE_CEILING;
auto directory = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) PageDirectory));

View file

@ -179,7 +179,7 @@ bool Region::map_individual_page_impl(size_t page_index)
VERIFY(m_page_directory->get_lock().is_locked_by_current_processor());
auto page_vaddr = vaddr_from_page_index(page_index);
bool user_allowed = page_vaddr.get() >= 0x00800000 && is_user_address(page_vaddr);
bool user_allowed = page_vaddr.get() >= USER_RANGE_BASE && is_user_address(page_vaddr);
if (is_mmap() && !user_allowed) {
PANIC("About to map mmap'ed page at a kernel address");
}

View file

@ -89,7 +89,7 @@ public:
void set_mmap(bool mmap) { m_mmap = mmap; }
[[nodiscard]] bool is_user() const { return !is_kernel(); }
[[nodiscard]] bool is_kernel() const { return vaddr().get() < 0x00800000 || vaddr().get() >= kernel_mapping_base; }
[[nodiscard]] bool is_kernel() const { return vaddr().get() < USER_RANGE_BASE || vaddr().get() >= kernel_mapping_base; }
PageFaultResponse handle_fault(PageFault const&);

View file

@ -21,4 +21,5 @@
#define KERNEL_QUICKMAP_PD (KERNEL_PT1024_BASE + 0x7000)
#define KERNEL_QUICKMAP_PER_CPU_BASE (KERNEL_PT1024_BASE + 0x8000)
#define USER_RANGE_BASE 0x10000
#define USER_RANGE_CEILING (kernel_mapping_base - 0x2000000)

View file

@ -14,6 +14,7 @@
#include <AK/Format.h>
#include <AK/LexicalPath.h>
#include <AK/StringUtils.h>
#include <Kernel/API/MemoryLayout.h>
#include <LibCore/File.h>
#include <LibCore/MappedFile.h>
#include <LibELF/AuxiliaryVector.h>
@ -51,7 +52,6 @@ Emulator::Emulator(String const& executable_path, Vector<StringView> const& argu
{
m_malloc_tracer = make<MallocTracer>(*this);
static constexpr FlatPtr userspace_range_base = 0x00800000;
static constexpr FlatPtr userspace_range_ceiling = 0xbe000000;
#ifdef UE_ASLR
static constexpr FlatPtr page_mask = 0xfffff000u;