1
0
Fork 0

Kernel: move memory_regions into Kernel instance

This commit is contained in:
Weiyi Wang 2018-10-25 21:07:15 -04:00
parent 263290d48c
commit ece96807c4
7 changed files with 21 additions and 28 deletions

View File

@ -24,9 +24,7 @@ KernelSystem::KernelSystem(u32 system_mode) {
}
/// Shutdown the kernel
KernelSystem::~KernelSystem() {
Kernel::MemoryShutdown();
}
KernelSystem::~KernelSystem() = default;
ResourceLimitList& KernelSystem::ResourceLimit() {
return *resource_limits;

View File

@ -4,12 +4,14 @@
#pragma once
#include <array>
#include <atomic>
#include <memory>
#include <string>
#include <vector>
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include "common/common_types.h"
#include "core/hle/kernel/memory.h"
#include "core/hle/result.h"
namespace ConfigMem {
@ -209,6 +211,10 @@ public:
SharedPage::Handler& GetSharedPageHandler();
const SharedPage::Handler& GetSharedPageHandler() const;
MemoryRegionInfo* GetMemoryRegion(MemoryRegion region);
std::array<MemoryRegionInfo, 3> memory_regions;
private:
void MemoryInit(u32 mem_type);

View File

@ -14,6 +14,7 @@
#include "core/core.h"
#include "core/hle/kernel/config_mem.h"
#include "core/hle/kernel/memory.h"
#include "core/hle/kernel/process.h"
#include "core/hle/kernel/shared_page.h"
#include "core/hle/kernel/vm_manager.h"
#include "core/hle/result.h"
@ -24,8 +25,6 @@
namespace Kernel {
MemoryRegionInfo memory_regions[3];
/// Size of the APPLICATION, SYSTEM and BASE memory regions (respectively) for each system
/// memory configuration type.
static const u32 memory_region_sizes[8][3] = {
@ -77,16 +76,7 @@ void KernelSystem::MemoryInit(u32 mem_type) {
shared_page_handler = std::make_unique<SharedPage::Handler>();
}
void MemoryShutdown() {
for (auto& region : memory_regions) {
region.base = 0;
region.size = 0;
region.used = 0;
region.linear_heap_memory = nullptr;
}
}
MemoryRegionInfo* GetMemoryRegion(MemoryRegion region) {
MemoryRegionInfo* KernelSystem::GetMemoryRegion(MemoryRegion region) {
switch (region) {
case MemoryRegion::APPLICATION:
return &memory_regions[0];

View File

@ -5,11 +5,12 @@
#pragma once
#include <memory>
#include <vector>
#include "common/common_types.h"
#include "core/hle/kernel/process.h"
namespace Kernel {
struct AddressMapping;
class VMManager;
struct MemoryRegionInfo {
@ -20,10 +21,6 @@ struct MemoryRegionInfo {
std::shared_ptr<std::vector<u8>> linear_heap_memory;
};
void MemoryShutdown();
MemoryRegionInfo* GetMemoryRegion(MemoryRegion region);
void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping);
extern MemoryRegionInfo memory_regions[3];
} // namespace Kernel

View File

@ -115,7 +115,7 @@ void Process::ParseKernelCaps(const u32* kernel_caps, std::size_t len) {
}
void Process::Run(s32 main_thread_priority, u32 stack_size) {
memory_region = GetMemoryRegion(flags.memory_region);
memory_region = kernel.GetMemoryRegion(flags.memory_region);
auto MapSegment = [&](CodeSet::Segment& segment, VMAPermission permissions,
MemoryState memory_state) {

View File

@ -1233,22 +1233,24 @@ static ResultCode AcceptSession(Handle* out_server_session, Handle server_port_h
static ResultCode GetSystemInfo(s64* out, u32 type, s32 param) {
LOG_TRACE(Kernel_SVC, "called type={} param={}", type, param);
KernelSystem& kernel = Core::System::GetInstance().Kernel();
switch ((SystemInfoType)type) {
case SystemInfoType::REGION_MEMORY_USAGE:
switch ((SystemInfoMemUsageRegion)param) {
case SystemInfoMemUsageRegion::ALL:
*out = GetMemoryRegion(MemoryRegion::APPLICATION)->used +
GetMemoryRegion(MemoryRegion::SYSTEM)->used +
GetMemoryRegion(MemoryRegion::BASE)->used;
*out = kernel.GetMemoryRegion(MemoryRegion::APPLICATION)->used +
kernel.GetMemoryRegion(MemoryRegion::SYSTEM)->used +
kernel.GetMemoryRegion(MemoryRegion::BASE)->used;
break;
case SystemInfoMemUsageRegion::APPLICATION:
*out = GetMemoryRegion(MemoryRegion::APPLICATION)->used;
*out = kernel.GetMemoryRegion(MemoryRegion::APPLICATION)->used;
break;
case SystemInfoMemUsageRegion::SYSTEM:
*out = GetMemoryRegion(MemoryRegion::SYSTEM)->used;
*out = kernel.GetMemoryRegion(MemoryRegion::SYSTEM)->used;
break;
case SystemInfoMemUsageRegion::BASE:
*out = GetMemoryRegion(MemoryRegion::BASE)->used;
*out = kernel.GetMemoryRegion(MemoryRegion::BASE)->used;
break;
default:
LOG_ERROR(Kernel_SVC, "unknown GetSystemInfo type=0 region: param={}", param);

View File

@ -305,7 +305,7 @@ u8* GetPhysicalPointer(PAddr address) {
target_pointer = Core::DSP().GetDspMemory().data() + offset_into_region;
break;
case FCRAM_PADDR:
for (const auto& region : Kernel::memory_regions) {
for (const auto& region : Core::System::GetInstance().Kernel().memory_regions) {
if (offset_into_region >= region.base &&
offset_into_region < region.base + region.size) {
target_pointer =