citra-emu
/
citra-canary
Archived
1
0
Fork 0

Kernel: make config_mem and MapSharedPages members of KernelSystem

This commit is contained in:
Weiyi Wang 2018-10-25 10:51:00 -04:00
parent 95790218f2
commit 773ec47629
8 changed files with 37 additions and 21 deletions

View File

@ -9,9 +9,7 @@
namespace ConfigMem { namespace ConfigMem {
ConfigMemDef config_mem; Handler::Handler() {
void Init() {
std::memset(&config_mem, 0, sizeof(config_mem)); std::memset(&config_mem, 0, sizeof(config_mem));
// Values extracted from firmware 11.2.0-35E // Values extracted from firmware 11.2.0-35E
@ -28,4 +26,8 @@ void Init() {
config_mem.firm_ctr_sdk_ver = 0x0000F297; config_mem.firm_ctr_sdk_ver = 0x0000F297;
} }
ConfigMemDef& Handler::GetConfigMem() {
return config_mem;
}
} // namespace ConfigMem } // namespace ConfigMem

View File

@ -49,8 +49,13 @@ struct ConfigMemDef {
static_assert(sizeof(ConfigMemDef) == Memory::CONFIG_MEMORY_SIZE, static_assert(sizeof(ConfigMemDef) == Memory::CONFIG_MEMORY_SIZE,
"Config Memory structure size is wrong"); "Config Memory structure size is wrong");
extern ConfigMemDef config_mem; class Handler {
public:
Handler();
ConfigMemDef& GetConfigMem();
void Init(); private:
ConfigMemDef config_mem;
};
} // namespace ConfigMem } // namespace ConfigMem

View File

@ -16,9 +16,7 @@ namespace Kernel {
/// Initialize the kernel /// Initialize the kernel
KernelSystem::KernelSystem(u32 system_mode) { KernelSystem::KernelSystem(u32 system_mode) {
ConfigMem::Init(); MemoryInit(system_mode);
Kernel::MemoryInit(system_mode);
resource_limits = std::make_unique<ResourceLimitList>(*this); resource_limits = std::make_unique<ResourceLimitList>(*this);
thread_manager = std::make_unique<ThreadManager>(); thread_manager = std::make_unique<ThreadManager>();

View File

@ -12,6 +12,10 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/result.h" #include "core/hle/result.h"
namespace ConfigMem {
class Handler;
}
namespace Kernel { namespace Kernel {
class AddressArbiter; class AddressArbiter;
@ -30,6 +34,7 @@ class ResourceLimitList;
class SharedMemory; class SharedMemory;
class ThreadManager; class ThreadManager;
class TimerManager; class TimerManager;
class VMManager;
enum class ResetType { enum class ResetType {
OneShot, OneShot,
@ -195,7 +200,11 @@ public:
TimerManager& GetTimerManager(); TimerManager& GetTimerManager();
const TimerManager& GetTimerManager() const; const TimerManager& GetTimerManager() const;
void MapSharedPages(VMManager& address_space);
private: private:
void MemoryInit(u32 mem_type);
std::unique_ptr<ResourceLimitList> resource_limits; std::unique_ptr<ResourceLimitList> resource_limits;
std::atomic<u32> next_object_id{0}; std::atomic<u32> next_object_id{0};
@ -210,6 +219,8 @@ private:
std::unique_ptr<ThreadManager> thread_manager; std::unique_ptr<ThreadManager> thread_manager;
std::unique_ptr<TimerManager> timer_manager; std::unique_ptr<TimerManager> timer_manager;
std::unique_ptr<ConfigMem::Handler> config_mem_handler;
}; };
} // namespace Kernel } // namespace Kernel

View File

@ -41,7 +41,7 @@ static const u32 memory_region_sizes[8][3] = {
{0x0B200000, 0x02E00000, 0x02000000}, // 7 {0x0B200000, 0x02E00000, 0x02000000}, // 7
}; };
void MemoryInit(u32 mem_type) { void KernelSystem::MemoryInit(u32 mem_type) {
// TODO(yuriks): On the n3DS, all o3DS configurations (<=5) are forced to 6 instead. // TODO(yuriks): On the n3DS, all o3DS configurations (<=5) are forced to 6 instead.
ASSERT_MSG(mem_type <= 5, "New 3DS memory configuration aren't supported yet!"); ASSERT_MSG(mem_type <= 5, "New 3DS memory configuration aren't supported yet!");
ASSERT(mem_type != 1); ASSERT(mem_type != 1);
@ -64,7 +64,8 @@ void MemoryInit(u32 mem_type) {
// We must've allocated the entire FCRAM by the end // We must've allocated the entire FCRAM by the end
ASSERT(base == Memory::FCRAM_SIZE); ASSERT(base == Memory::FCRAM_SIZE);
using ConfigMem::config_mem; config_mem_handler = std::make_unique<ConfigMem::Handler>();
auto& config_mem = config_mem_handler->GetConfigMem();
config_mem.app_mem_type = mem_type; config_mem.app_mem_type = mem_type;
// app_mem_malloc does not always match the configured size for memory_region[0]: in case the // app_mem_malloc does not always match the configured size for memory_region[0]: in case the
// n3DS type override is in effect it reports the size the game expects, not the real one. // n3DS type override is in effect it reports the size the game expects, not the real one.
@ -152,10 +153,11 @@ void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mappin
mapping.read_only ? VMAPermission::Read : VMAPermission::ReadWrite); mapping.read_only ? VMAPermission::Read : VMAPermission::ReadWrite);
} }
void MapSharedPages(VMManager& address_space) { void KernelSystem::MapSharedPages(VMManager& address_space) {
auto cfg_mem_vma = address_space auto cfg_mem_vma =
address_space
.MapBackingMemory(Memory::CONFIG_MEMORY_VADDR, .MapBackingMemory(Memory::CONFIG_MEMORY_VADDR,
reinterpret_cast<u8*>(&ConfigMem::config_mem), reinterpret_cast<u8*>(&config_mem_handler->GetConfigMem()),
Memory::CONFIG_MEMORY_SIZE, MemoryState::Shared) Memory::CONFIG_MEMORY_SIZE, MemoryState::Shared)
.Unwrap(); .Unwrap();
address_space.Reprotect(cfg_mem_vma, VMAPermission::Read); address_space.Reprotect(cfg_mem_vma, VMAPermission::Read);

View File

@ -20,12 +20,10 @@ struct MemoryRegionInfo {
std::shared_ptr<std::vector<u8>> linear_heap_memory; std::shared_ptr<std::vector<u8>> linear_heap_memory;
}; };
void MemoryInit(u32 mem_type);
void MemoryShutdown(); void MemoryShutdown();
MemoryRegionInfo* GetMemoryRegion(MemoryRegion region); MemoryRegionInfo* GetMemoryRegion(MemoryRegion region);
void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping); void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping);
void MapSharedPages(VMManager& address_space);
extern MemoryRegionInfo memory_regions[3]; extern MemoryRegionInfo memory_regions[3];
} // namespace Kernel } // namespace Kernel

View File

@ -143,7 +143,7 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) {
memory_region->used += stack_size; memory_region->used += stack_size;
// Map special address mappings // Map special address mappings
MapSharedPages(vm_manager); kernel.MapSharedPages(vm_manager);
for (const auto& mapping : address_mappings) { for (const auto& mapping : address_mappings) {
HandleSpecialMapping(vm_manager, mapping); HandleSpecialMapping(vm_manager, mapping);
} }

View File

@ -25,7 +25,7 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") { SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") {
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0)); auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
Kernel::MapSharedPages(process->vm_manager); kernel.MapSharedPages(process->vm_manager);
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true); CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true);
CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true); CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true);
} }
@ -47,7 +47,7 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
SECTION("Unmapping a VAddr should make it invalid") { SECTION("Unmapping a VAddr should make it invalid") {
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0)); auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
Kernel::MapSharedPages(process->vm_manager); kernel.MapSharedPages(process->vm_manager);
process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE); process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE);
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false); CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false);
} }