memory: rename global memory references to application memory
This commit is contained in:
parent
c8963299fa
commit
6eaef51cf2
44 changed files with 185 additions and 226 deletions
|
|
@ -93,7 +93,7 @@ void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) const {
|
|||
stream->AppendBuffer(new_buffer, samples);
|
||||
} else {
|
||||
std::vector<s16> samples(buffer.size / sizeof(s16));
|
||||
system.Memory().ReadBlockUnsafe(buffer.samples, samples.data(), buffer.size);
|
||||
system.ApplicationMemory().ReadBlockUnsafe(buffer.samples, samples.data(), buffer.size);
|
||||
stream->AppendBuffer(new_buffer, samples);
|
||||
}
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) const {
|
|||
void DeviceSession::ReleaseBuffer(const AudioBuffer& buffer) const {
|
||||
if (type == Sink::StreamType::In) {
|
||||
auto samples{stream->ReleaseBuffer(buffer.size / sizeof(s16))};
|
||||
system.Memory().WriteBlockUnsafe(buffer.samples, samples.data(), buffer.size);
|
||||
system.ApplicationMemory().WriteBlockUnsafe(buffer.samples, samples.data(), buffer.size);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
namespace AudioCore::AudioRenderer::ADSP {
|
||||
|
||||
ADSP::ADSP(Core::System& system_, Sink::Sink& sink_)
|
||||
: system{system_}, memory{system.Memory()}, sink{sink_} {}
|
||||
: system{system_}, memory{system.ApplicationMemory()}, sink{sink_} {}
|
||||
|
||||
ADSP::~ADSP() {
|
||||
ClearCommandBuffers();
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace AudioCore::AudioRenderer::ADSP {
|
|||
void CommandListProcessor::Initialize(Core::System& system_, CpuAddr buffer, u64 size,
|
||||
Sink::SinkStream* stream_) {
|
||||
system = &system_;
|
||||
memory = &system->Memory();
|
||||
memory = &system->ApplicationMemory();
|
||||
stream = stream_;
|
||||
header = reinterpret_cast<CommandListHeader*>(buffer);
|
||||
commands = reinterpret_cast<u8*>(buffer + sizeof(CommandListHeader));
|
||||
|
|
|
|||
|
|
@ -127,8 +127,7 @@ Result System::Initialize(const AudioRendererParameterInternal& params,
|
|||
render_device = params.rendering_device;
|
||||
execution_mode = params.execution_mode;
|
||||
|
||||
core.Memory().ZeroBlock(*core.ApplicationProcess(), transfer_memory->GetSourceAddress(),
|
||||
transfer_memory_size);
|
||||
core.ApplicationMemory().ZeroBlock(transfer_memory->GetSourceAddress(), transfer_memory_size);
|
||||
|
||||
// Note: We're not actually using the transfer memory because it's a pain to code for.
|
||||
// Allocate the memory normally instead and hope the game doesn't try to read anything back
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ void ARM_Interface::SymbolicateBacktrace(Core::System& system, std::vector<Backt
|
|||
std::map<std::string, Symbols::Symbols> symbols;
|
||||
for (const auto& module : modules) {
|
||||
symbols.insert_or_assign(
|
||||
module.second, Symbols::GetSymbols(module.first, system.Memory(),
|
||||
module.second, Symbols::GetSymbols(module.first, system.ApplicationMemory(),
|
||||
system.ApplicationProcess()->Is64BitProcess()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ using namespace Common::Literals;
|
|||
class DynarmicCallbacks32 : public Dynarmic::A32::UserCallbacks {
|
||||
public:
|
||||
explicit DynarmicCallbacks32(ARM_Dynarmic_32& parent_)
|
||||
: parent{parent_},
|
||||
memory(parent.system.Memory()), debugger_enabled{parent.system.DebuggerEnabled()},
|
||||
: parent{parent_}, memory(parent.system.ApplicationMemory()),
|
||||
debugger_enabled{parent.system.DebuggerEnabled()},
|
||||
check_memory_access{debugger_enabled ||
|
||||
!Settings::values.cpuopt_ignore_memory_aborts.GetValue()} {}
|
||||
|
||||
|
|
@ -468,7 +468,7 @@ void ARM_Dynarmic_32::PageTableChanged(Common::PageTable& page_table,
|
|||
std::vector<ARM_Interface::BacktraceEntry> ARM_Dynarmic_32::GetBacktrace(Core::System& system,
|
||||
u64 fp, u64 lr, u64 pc) {
|
||||
std::vector<BacktraceEntry> out;
|
||||
auto& memory = system.Memory();
|
||||
auto& memory = system.ApplicationMemory();
|
||||
|
||||
out.push_back({"", 0, pc, 0, ""});
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ using namespace Common::Literals;
|
|||
class DynarmicCallbacks64 : public Dynarmic::A64::UserCallbacks {
|
||||
public:
|
||||
explicit DynarmicCallbacks64(ARM_Dynarmic_64& parent_)
|
||||
: parent{parent_},
|
||||
memory(parent.system.Memory()), debugger_enabled{parent.system.DebuggerEnabled()},
|
||||
: parent{parent_}, memory(parent.system.ApplicationMemory()),
|
||||
debugger_enabled{parent.system.DebuggerEnabled()},
|
||||
check_memory_access{debugger_enabled ||
|
||||
!Settings::values.cpuopt_ignore_memory_aborts.GetValue()} {}
|
||||
|
||||
|
|
@ -529,7 +529,7 @@ void ARM_Dynarmic_64::PageTableChanged(Common::PageTable& page_table,
|
|||
std::vector<ARM_Interface::BacktraceEntry> ARM_Dynarmic_64::GetBacktrace(Core::System& system,
|
||||
u64 fp, u64 lr, u64 pc) {
|
||||
std::vector<BacktraceEntry> out;
|
||||
auto& memory = system.Memory();
|
||||
auto& memory = system.ApplicationMemory();
|
||||
|
||||
out.push_back({"", 0, pc, 0, ""});
|
||||
|
||||
|
|
|
|||
|
|
@ -293,6 +293,7 @@ struct System::Impl {
|
|||
ASSERT(Kernel::KProcess::Initialize(main_process, system, "main",
|
||||
Kernel::KProcess::ProcessType::Userland, resource_limit)
|
||||
.IsSuccess());
|
||||
kernel.MakeApplicationProcess(main_process);
|
||||
const auto [load_result, load_parameters] = app_loader->Load(*main_process, system);
|
||||
if (load_result != Loader::ResultStatus::Success) {
|
||||
LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result);
|
||||
|
|
@ -302,7 +303,6 @@ struct System::Impl {
|
|||
static_cast<u32>(SystemResultStatus::ErrorLoader) + static_cast<u32>(load_result));
|
||||
}
|
||||
AddGlueRegistrationForProcess(*app_loader, *main_process);
|
||||
kernel.MakeApplicationProcess(main_process);
|
||||
kernel.InitializeCores();
|
||||
|
||||
// Initialize cheat engine
|
||||
|
|
@ -681,11 +681,11 @@ const ExclusiveMonitor& System::Monitor() const {
|
|||
return impl->kernel.GetExclusiveMonitor();
|
||||
}
|
||||
|
||||
Memory::Memory& System::Memory() {
|
||||
Memory::Memory& System::ApplicationMemory() {
|
||||
return impl->memory;
|
||||
}
|
||||
|
||||
const Core::Memory::Memory& System::Memory() const {
|
||||
const Core::Memory::Memory& System::ApplicationMemory() const {
|
||||
return impl->memory;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -256,10 +256,10 @@ public:
|
|||
[[nodiscard]] const ExclusiveMonitor& Monitor() const;
|
||||
|
||||
/// Gets a mutable reference to the system memory instance.
|
||||
[[nodiscard]] Core::Memory::Memory& Memory();
|
||||
[[nodiscard]] Core::Memory::Memory& ApplicationMemory();
|
||||
|
||||
/// Gets a constant reference to the system memory instance.
|
||||
[[nodiscard]] const Core::Memory::Memory& Memory() const;
|
||||
[[nodiscard]] const Core::Memory::Memory& ApplicationMemory() const;
|
||||
|
||||
/// Gets a mutable reference to the GPU interface
|
||||
[[nodiscard]] Tegra::GPU& GPU();
|
||||
|
|
|
|||
|
|
@ -261,9 +261,9 @@ void GDBStub::ExecuteCommand(std::string_view packet, std::vector<DebuggerAction
|
|||
const size_t addr{static_cast<size_t>(strtoll(command.data(), nullptr, 16))};
|
||||
const size_t size{static_cast<size_t>(strtoll(command.data() + sep, nullptr, 16))};
|
||||
|
||||
if (system.Memory().IsValidVirtualAddressRange(addr, size)) {
|
||||
if (system.ApplicationMemory().IsValidVirtualAddressRange(addr, size)) {
|
||||
std::vector<u8> mem(size);
|
||||
system.Memory().ReadBlock(addr, mem.data(), size);
|
||||
system.ApplicationMemory().ReadBlock(addr, mem.data(), size);
|
||||
|
||||
SendReply(Common::HexToString(mem));
|
||||
} else {
|
||||
|
|
@ -281,8 +281,8 @@ void GDBStub::ExecuteCommand(std::string_view packet, std::vector<DebuggerAction
|
|||
const auto mem_substr{std::string_view(command).substr(mem_sep)};
|
||||
const auto mem{Common::HexStringToVector(mem_substr, false)};
|
||||
|
||||
if (system.Memory().IsValidVirtualAddressRange(addr, size)) {
|
||||
system.Memory().WriteBlock(addr, mem.data(), size);
|
||||
if (system.ApplicationMemory().IsValidVirtualAddressRange(addr, size)) {
|
||||
system.ApplicationMemory().WriteBlock(addr, mem.data(), size);
|
||||
system.InvalidateCpuInstructionCacheRange(addr, size);
|
||||
SendReply(GDB_STUB_REPLY_OK);
|
||||
} else {
|
||||
|
|
@ -325,7 +325,7 @@ void GDBStub::HandleBreakpointInsert(std::string_view command) {
|
|||
const size_t addr{static_cast<size_t>(strtoll(command.data() + addr_sep, nullptr, 16))};
|
||||
const size_t size{static_cast<size_t>(strtoll(command.data() + size_sep, nullptr, 16))};
|
||||
|
||||
if (!system.Memory().IsValidVirtualAddressRange(addr, size)) {
|
||||
if (!system.ApplicationMemory().IsValidVirtualAddressRange(addr, size)) {
|
||||
SendReply(GDB_STUB_REPLY_ERR);
|
||||
return;
|
||||
}
|
||||
|
|
@ -334,22 +334,22 @@ void GDBStub::HandleBreakpointInsert(std::string_view command) {
|
|||
|
||||
switch (type) {
|
||||
case BreakpointType::Software:
|
||||
replaced_instructions[addr] = system.Memory().Read32(addr);
|
||||
system.Memory().Write32(addr, arch->BreakpointInstruction());
|
||||
replaced_instructions[addr] = system.ApplicationMemory().Read32(addr);
|
||||
system.ApplicationMemory().Write32(addr, arch->BreakpointInstruction());
|
||||
system.InvalidateCpuInstructionCacheRange(addr, sizeof(u32));
|
||||
success = true;
|
||||
break;
|
||||
case BreakpointType::WriteWatch:
|
||||
success = system.ApplicationProcess()->InsertWatchpoint(system, addr, size,
|
||||
success = system.ApplicationProcess()->InsertWatchpoint(addr, size,
|
||||
Kernel::DebugWatchpointType::Write);
|
||||
break;
|
||||
case BreakpointType::ReadWatch:
|
||||
success = system.ApplicationProcess()->InsertWatchpoint(system, addr, size,
|
||||
success = system.ApplicationProcess()->InsertWatchpoint(addr, size,
|
||||
Kernel::DebugWatchpointType::Read);
|
||||
break;
|
||||
case BreakpointType::AccessWatch:
|
||||
success = system.ApplicationProcess()->InsertWatchpoint(
|
||||
system, addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||
addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||
break;
|
||||
case BreakpointType::Hardware:
|
||||
default:
|
||||
|
|
@ -372,7 +372,7 @@ void GDBStub::HandleBreakpointRemove(std::string_view command) {
|
|||
const size_t addr{static_cast<size_t>(strtoll(command.data() + addr_sep, nullptr, 16))};
|
||||
const size_t size{static_cast<size_t>(strtoll(command.data() + size_sep, nullptr, 16))};
|
||||
|
||||
if (!system.Memory().IsValidVirtualAddressRange(addr, size)) {
|
||||
if (!system.ApplicationMemory().IsValidVirtualAddressRange(addr, size)) {
|
||||
SendReply(GDB_STUB_REPLY_ERR);
|
||||
return;
|
||||
}
|
||||
|
|
@ -383,7 +383,7 @@ void GDBStub::HandleBreakpointRemove(std::string_view command) {
|
|||
case BreakpointType::Software: {
|
||||
const auto orig_insn{replaced_instructions.find(addr)};
|
||||
if (orig_insn != replaced_instructions.end()) {
|
||||
system.Memory().Write32(addr, orig_insn->second);
|
||||
system.ApplicationMemory().Write32(addr, orig_insn->second);
|
||||
system.InvalidateCpuInstructionCacheRange(addr, sizeof(u32));
|
||||
replaced_instructions.erase(addr);
|
||||
success = true;
|
||||
|
|
@ -391,16 +391,16 @@ void GDBStub::HandleBreakpointRemove(std::string_view command) {
|
|||
break;
|
||||
}
|
||||
case BreakpointType::WriteWatch:
|
||||
success = system.ApplicationProcess()->RemoveWatchpoint(system, addr, size,
|
||||
success = system.ApplicationProcess()->RemoveWatchpoint(addr, size,
|
||||
Kernel::DebugWatchpointType::Write);
|
||||
break;
|
||||
case BreakpointType::ReadWatch:
|
||||
success = system.ApplicationProcess()->RemoveWatchpoint(system, addr, size,
|
||||
success = system.ApplicationProcess()->RemoveWatchpoint(addr, size,
|
||||
Kernel::DebugWatchpointType::Read);
|
||||
break;
|
||||
case BreakpointType::AccessWatch:
|
||||
success = system.ApplicationProcess()->RemoveWatchpoint(
|
||||
system, addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||
addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||
break;
|
||||
case BreakpointType::Hardware:
|
||||
default:
|
||||
|
|
@ -483,9 +483,9 @@ static std::optional<std::string> GetNameFromThreadType64(Core::Memory::Memory&
|
|||
static std::optional<std::string> GetThreadName(Core::System& system,
|
||||
const Kernel::KThread* thread) {
|
||||
if (system.ApplicationProcess()->Is64BitProcess()) {
|
||||
return GetNameFromThreadType64(system.Memory(), thread);
|
||||
return GetNameFromThreadType64(system.ApplicationMemory(), thread);
|
||||
} else {
|
||||
return GetNameFromThreadType32(system.Memory(), thread);
|
||||
return GetNameFromThreadType32(system.ApplicationMemory(), thread);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ KAddressArbiter::~KAddressArbiter() = default;
|
|||
|
||||
namespace {
|
||||
|
||||
bool ReadFromUser(Core::System& system, s32* out, KProcessAddress address) {
|
||||
*out = system.Memory().Read32(GetInteger(address));
|
||||
bool ReadFromUser(KernelCore& kernel, s32* out, KProcessAddress address) {
|
||||
*out = GetCurrentMemory(kernel).Read32(GetInteger(address));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -209,7 +209,7 @@ Result KAddressArbiter::SignalAndModifyByWaitingCountIfEqual(uint64_t addr, s32
|
|||
if (value != new_value) {
|
||||
succeeded = UpdateIfEqual(m_system, std::addressof(user_value), addr, value, new_value);
|
||||
} else {
|
||||
succeeded = ReadFromUser(m_system, std::addressof(user_value), addr);
|
||||
succeeded = ReadFromUser(m_kernel, std::addressof(user_value), addr);
|
||||
}
|
||||
|
||||
R_UNLESS(succeeded, ResultInvalidCurrentMemory);
|
||||
|
|
@ -252,7 +252,7 @@ Result KAddressArbiter::WaitIfLessThan(uint64_t addr, s32 value, bool decrement,
|
|||
if (decrement) {
|
||||
succeeded = DecrementIfLessThan(m_system, std::addressof(user_value), addr, value);
|
||||
} else {
|
||||
succeeded = ReadFromUser(m_system, std::addressof(user_value), addr);
|
||||
succeeded = ReadFromUser(m_kernel, std::addressof(user_value), addr);
|
||||
}
|
||||
|
||||
if (!succeeded) {
|
||||
|
|
@ -303,7 +303,7 @@ Result KAddressArbiter::WaitIfEqual(uint64_t addr, s32 value, s64 timeout) {
|
|||
|
||||
// Read the value from userspace.
|
||||
s32 user_value{};
|
||||
if (!ReadFromUser(m_system, std::addressof(user_value), addr)) {
|
||||
if (!ReadFromUser(m_kernel, std::addressof(user_value), addr)) {
|
||||
slp.CancelSleep();
|
||||
R_THROW(ResultInvalidCurrentMemory);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ namespace Kernel {
|
|||
|
||||
namespace {
|
||||
|
||||
bool ReadFromUser(Core::System& system, u32* out, KProcessAddress address) {
|
||||
*out = system.Memory().Read32(GetInteger(address));
|
||||
bool ReadFromUser(KernelCore& kernel, u32* out, KProcessAddress address) {
|
||||
*out = GetCurrentMemory(kernel).Read32(GetInteger(address));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteToUser(Core::System& system, KProcessAddress address, const u32* p) {
|
||||
system.Memory().Write32(GetInteger(address), *p);
|
||||
bool WriteToUser(KernelCore& kernel, KProcessAddress address, const u32* p) {
|
||||
GetCurrentMemory(kernel).Write32(GetInteger(address), *p);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ Result KConditionVariable::SignalToAddress(KProcessAddress addr) {
|
|||
|
||||
// Write the value to userspace.
|
||||
Result result{ResultSuccess};
|
||||
if (WriteToUser(m_system, addr, std::addressof(next_value))) [[likely]] {
|
||||
if (WriteToUser(m_kernel, addr, std::addressof(next_value))) [[likely]] {
|
||||
result = ResultSuccess;
|
||||
} else {
|
||||
result = ResultInvalidCurrentMemory;
|
||||
|
|
@ -157,7 +157,7 @@ Result KConditionVariable::WaitForAddress(Handle handle, KProcessAddress addr, u
|
|||
|
||||
// Read the tag from userspace.
|
||||
u32 test_tag{};
|
||||
R_UNLESS(ReadFromUser(m_system, std::addressof(test_tag), addr),
|
||||
R_UNLESS(ReadFromUser(m_kernel, std::addressof(test_tag), addr),
|
||||
ResultInvalidCurrentMemory);
|
||||
|
||||
// If the tag isn't the handle (with wait mask), we're done.
|
||||
|
|
@ -257,7 +257,7 @@ void KConditionVariable::Signal(u64 cv_key, s32 count) {
|
|||
// If we have no waiters, clear the has waiter flag.
|
||||
if (it == m_tree.end() || it->GetConditionVariableKey() != cv_key) {
|
||||
const u32 has_waiter_flag{};
|
||||
WriteToUser(m_system, cv_key, std::addressof(has_waiter_flag));
|
||||
WriteToUser(m_kernel, cv_key, std::addressof(has_waiter_flag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -301,12 +301,12 @@ Result KConditionVariable::Wait(KProcessAddress addr, u64 key, u32 value, s64 ti
|
|||
// Write to the cv key.
|
||||
{
|
||||
const u32 has_waiter_flag = 1;
|
||||
WriteToUser(m_system, key, std::addressof(has_waiter_flag));
|
||||
WriteToUser(m_kernel, key, std::addressof(has_waiter_flag));
|
||||
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||
}
|
||||
|
||||
// Write the value to userspace.
|
||||
if (!WriteToUser(m_system, addr, std::addressof(next_value))) {
|
||||
if (!WriteToUser(m_kernel, addr, std::addressof(next_value))) {
|
||||
slp.CancelSleep();
|
||||
R_THROW(ResultInvalidCurrentMemory);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,7 +108,8 @@ Result KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_type
|
|||
bool enable_das_merge, bool from_back,
|
||||
KMemoryManager::Pool pool, KProcessAddress code_addr,
|
||||
size_t code_size, KSystemResource* system_resource,
|
||||
KResourceLimit* resource_limit) {
|
||||
KResourceLimit* resource_limit,
|
||||
Core::Memory::Memory& memory) {
|
||||
|
||||
const auto GetSpaceStart = [this](KAddressSpaceInfo::Type type) {
|
||||
return KAddressSpaceInfo::GetAddressSpaceStart(m_address_space_width, type);
|
||||
|
|
@ -117,6 +118,9 @@ Result KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_type
|
|||
return KAddressSpaceInfo::GetAddressSpaceSize(m_address_space_width, type);
|
||||
};
|
||||
|
||||
// Set the tracking memory
|
||||
m_memory = std::addressof(memory);
|
||||
|
||||
// Set our width and heap/alias sizes
|
||||
m_address_space_width = GetAddressSpaceWidthFromType(as_type);
|
||||
const KProcessAddress start = 0;
|
||||
|
|
@ -334,10 +338,10 @@ Result KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_type
|
|||
|
||||
void KPageTable::Finalize() {
|
||||
// Finalize memory blocks.
|
||||
m_memory_block_manager.Finalize(
|
||||
m_memory_block_slab_manager, [&](KProcessAddress addr, u64 size) {
|
||||
m_system.Memory().UnmapRegion(*m_page_table_impl, addr, size);
|
||||
});
|
||||
m_memory_block_manager.Finalize(m_memory_block_slab_manager,
|
||||
[&](KProcessAddress addr, u64 size) {
|
||||
m_memory->UnmapRegion(*m_page_table_impl, addr, size);
|
||||
});
|
||||
|
||||
// Release any insecure mapped memory.
|
||||
if (m_mapped_insecure_memory) {
|
||||
|
|
@ -1010,23 +1014,22 @@ Result KPageTable::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
|
|||
clear_size = 0;
|
||||
}
|
||||
|
||||
std::memset(m_system.Memory().GetPointer<void>(GetInteger(start_partial_virt)),
|
||||
fill_val, partial_offset);
|
||||
std::memset(m_memory->GetPointer<void>(GetInteger(start_partial_virt)), fill_val,
|
||||
partial_offset);
|
||||
std::memcpy(
|
||||
m_system.Memory().GetPointer<void>(GetInteger(start_partial_virt) + partial_offset),
|
||||
m_system.Memory().GetPointer<void>(
|
||||
GetInteger(
|
||||
GetHeapVirtualAddress(m_system.Kernel().MemoryLayout(), cur_block_addr)) +
|
||||
partial_offset),
|
||||
m_memory->GetPointer<void>(GetInteger(start_partial_virt) + partial_offset),
|
||||
m_memory->GetPointer<void>(GetInteger(GetHeapVirtualAddress(
|
||||
m_system.Kernel().MemoryLayout(), cur_block_addr)) +
|
||||
partial_offset),
|
||||
copy_size);
|
||||
if (clear_size > 0) {
|
||||
std::memset(m_system.Memory().GetPointer<void>(GetInteger(start_partial_virt) +
|
||||
partial_offset + copy_size),
|
||||
std::memset(m_memory->GetPointer<void>(GetInteger(start_partial_virt) +
|
||||
partial_offset + copy_size),
|
||||
fill_val, clear_size);
|
||||
}
|
||||
} else {
|
||||
std::memset(m_system.Memory().GetPointer<void>(GetInteger(start_partial_virt)),
|
||||
fill_val, PageSize);
|
||||
std::memset(m_memory->GetPointer<void>(GetInteger(start_partial_virt)), fill_val,
|
||||
PageSize);
|
||||
}
|
||||
|
||||
// Map the page.
|
||||
|
|
@ -1099,15 +1102,14 @@ Result KPageTable::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
|
|||
GetHeapVirtualAddress(m_system.Kernel().MemoryLayout(), end_partial_page);
|
||||
if (send) {
|
||||
const size_t copy_size = src_end - mapping_src_end;
|
||||
std::memcpy(m_system.Memory().GetPointer<void>(GetInteger(end_partial_virt)),
|
||||
m_system.Memory().GetPointer<void>(GetInteger(GetHeapVirtualAddress(
|
||||
std::memcpy(m_memory->GetPointer<void>(GetInteger(end_partial_virt)),
|
||||
m_memory->GetPointer<void>(GetInteger(GetHeapVirtualAddress(
|
||||
m_system.Kernel().MemoryLayout(), cur_block_addr))),
|
||||
copy_size);
|
||||
std::memset(
|
||||
m_system.Memory().GetPointer<void>(GetInteger(end_partial_virt) + copy_size),
|
||||
fill_val, PageSize - copy_size);
|
||||
std::memset(m_memory->GetPointer<void>(GetInteger(end_partial_virt) + copy_size),
|
||||
fill_val, PageSize - copy_size);
|
||||
} else {
|
||||
std::memset(m_system.Memory().GetPointer<void>(GetInteger(end_partial_virt)), fill_val,
|
||||
std::memset(m_memory->GetPointer<void>(GetInteger(end_partial_virt)), fill_val,
|
||||
PageSize);
|
||||
}
|
||||
|
||||
|
|
@ -2800,7 +2802,7 @@ Result KPageTable::SetHeapSize(u64* out, size_t size) {
|
|||
|
||||
// Clear all the newly allocated pages.
|
||||
for (size_t cur_page = 0; cur_page < num_pages; ++cur_page) {
|
||||
std::memset(m_system.Memory().GetPointer(m_current_heap_end + (cur_page * PageSize)), 0,
|
||||
std::memset(m_memory->GetPointer(m_current_heap_end + (cur_page * PageSize)), 0,
|
||||
PageSize);
|
||||
}
|
||||
|
||||
|
|
@ -3006,7 +3008,7 @@ Result KPageTable::Operate(KProcessAddress addr, size_t num_pages, const KPageGr
|
|||
const size_t size{node.GetNumPages() * PageSize};
|
||||
|
||||
// Map the pages.
|
||||
m_system.Memory().MapMemoryRegion(*m_page_table_impl, addr, size, node.GetAddress());
|
||||
m_memory->MapMemoryRegion(*m_page_table_impl, addr, size, node.GetAddress());
|
||||
|
||||
addr += size;
|
||||
}
|
||||
|
|
@ -3039,14 +3041,14 @@ Result KPageTable::Operate(KProcessAddress addr, size_t num_pages, KMemoryPermis
|
|||
SCOPE_EXIT({ pages_to_close.CloseAndReset(); });
|
||||
|
||||
this->AddRegionToPages(addr, num_pages, pages_to_close);
|
||||
m_system.Memory().UnmapRegion(*m_page_table_impl, addr, num_pages * PageSize);
|
||||
m_memory->UnmapRegion(*m_page_table_impl, addr, num_pages * PageSize);
|
||||
break;
|
||||
}
|
||||
case OperationType::MapFirst:
|
||||
case OperationType::Map: {
|
||||
ASSERT(map_addr);
|
||||
ASSERT(Common::IsAligned(GetInteger(map_addr), PageSize));
|
||||
m_system.Memory().MapMemoryRegion(*m_page_table_impl, addr, num_pages * PageSize, map_addr);
|
||||
m_memory->MapMemoryRegion(*m_page_table_impl, addr, num_pages * PageSize, map_addr);
|
||||
|
||||
// Open references to pages, if we should.
|
||||
if (IsHeapPhysicalAddress(m_kernel.MemoryLayout(), map_addr)) {
|
||||
|
|
|
|||
|
|
@ -66,7 +66,8 @@ public:
|
|||
Result InitializeForProcess(FileSys::ProgramAddressSpaceType as_type, bool enable_aslr,
|
||||
bool enable_das_merge, bool from_back, KMemoryManager::Pool pool,
|
||||
KProcessAddress code_addr, size_t code_size,
|
||||
KSystemResource* system_resource, KResourceLimit* resource_limit);
|
||||
KSystemResource* system_resource, KResourceLimit* resource_limit,
|
||||
Core::Memory::Memory& memory);
|
||||
|
||||
void Finalize();
|
||||
|
||||
|
|
@ -546,6 +547,7 @@ private:
|
|||
|
||||
Core::System& m_system;
|
||||
KernelCore& m_kernel;
|
||||
Core::Memory::Memory* m_memory{};
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -367,8 +367,8 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std:
|
|||
// Initialize process address space
|
||||
if (const Result result{m_page_table.InitializeForProcess(
|
||||
metadata.GetAddressSpaceType(), false, false, false, KMemoryManager::Pool::Application,
|
||||
0x8000000, code_size, std::addressof(m_kernel.GetAppSystemResource()),
|
||||
m_resource_limit)};
|
||||
0x8000000, code_size, std::addressof(m_kernel.GetAppSystemResource()), m_resource_limit,
|
||||
m_kernel.System().ApplicationMemory())};
|
||||
result.IsError()) {
|
||||
R_RETURN(result);
|
||||
}
|
||||
|
|
@ -592,8 +592,7 @@ Result KProcess::DeleteThreadLocalRegion(KProcessAddress addr) {
|
|||
R_SUCCEED();
|
||||
}
|
||||
|
||||
bool KProcess::InsertWatchpoint(Core::System& system, KProcessAddress addr, u64 size,
|
||||
DebugWatchpointType type) {
|
||||
bool KProcess::InsertWatchpoint(KProcessAddress addr, u64 size, DebugWatchpointType type) {
|
||||
const auto watch{std::find_if(m_watchpoints.begin(), m_watchpoints.end(), [&](const auto& wp) {
|
||||
return wp.type == DebugWatchpointType::None;
|
||||
})};
|
||||
|
|
@ -609,14 +608,13 @@ bool KProcess::InsertWatchpoint(Core::System& system, KProcessAddress addr, u64
|
|||
for (KProcessAddress page = Common::AlignDown(GetInteger(addr), PageSize); page < addr + size;
|
||||
page += PageSize) {
|
||||
m_debug_page_refcounts[page]++;
|
||||
system.Memory().MarkRegionDebug(page, PageSize, true);
|
||||
this->GetMemory().MarkRegionDebug(page, PageSize, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KProcess::RemoveWatchpoint(Core::System& system, KProcessAddress addr, u64 size,
|
||||
DebugWatchpointType type) {
|
||||
bool KProcess::RemoveWatchpoint(KProcessAddress addr, u64 size, DebugWatchpointType type) {
|
||||
const auto watch{std::find_if(m_watchpoints.begin(), m_watchpoints.end(), [&](const auto& wp) {
|
||||
return wp.start_address == addr && wp.end_address == addr + size && wp.type == type;
|
||||
})};
|
||||
|
|
@ -633,7 +631,7 @@ bool KProcess::RemoveWatchpoint(Core::System& system, KProcessAddress addr, u64
|
|||
page += PageSize) {
|
||||
m_debug_page_refcounts[page]--;
|
||||
if (!m_debug_page_refcounts[page]) {
|
||||
system.Memory().MarkRegionDebug(page, PageSize, false);
|
||||
this->GetMemory().MarkRegionDebug(page, PageSize, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -646,8 +644,7 @@ void KProcess::LoadModule(CodeSet code_set, KProcessAddress base_addr) {
|
|||
m_page_table.SetProcessMemoryPermission(segment.addr + base_addr, segment.size, permission);
|
||||
};
|
||||
|
||||
m_kernel.System().Memory().WriteBlock(*this, base_addr, code_set.memory.data(),
|
||||
code_set.memory.size());
|
||||
this->GetMemory().WriteBlock(base_addr, code_set.memory.data(), code_set.memory.size());
|
||||
|
||||
ReprotectSegment(code_set.CodeSegment(), Svc::MemoryPermission::ReadExecute);
|
||||
ReprotectSegment(code_set.RODataSegment(), Svc::MemoryPermission::Read);
|
||||
|
|
@ -706,4 +703,9 @@ Result KProcess::AllocateMainThreadStack(std::size_t stack_size) {
|
|||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Core::Memory::Memory& KProcess::GetMemory() const {
|
||||
// TODO: per-process memory
|
||||
return m_kernel.System().ApplicationMemory();
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -22,8 +22,12 @@
|
|||
#include "core/hle/result.h"
|
||||
|
||||
namespace Core {
|
||||
namespace Memory {
|
||||
class Memory;
|
||||
};
|
||||
|
||||
class System;
|
||||
}
|
||||
} // namespace Core
|
||||
|
||||
namespace FileSys {
|
||||
class ProgramMetadata;
|
||||
|
|
@ -135,6 +139,9 @@ public:
|
|||
return m_handle_table;
|
||||
}
|
||||
|
||||
/// Gets a reference to process's memory.
|
||||
Core::Memory::Memory& GetMemory() const;
|
||||
|
||||
Result SignalToAddress(KProcessAddress address) {
|
||||
return m_condition_var.SignalToAddress(address);
|
||||
}
|
||||
|
|
@ -397,12 +404,10 @@ public:
|
|||
// Debug watchpoint management
|
||||
|
||||
// Attempts to insert a watchpoint into a free slot. Returns false if none are available.
|
||||
bool InsertWatchpoint(Core::System& system, KProcessAddress addr, u64 size,
|
||||
DebugWatchpointType type);
|
||||
bool InsertWatchpoint(KProcessAddress addr, u64 size, DebugWatchpointType type);
|
||||
|
||||
// Attempts to remove the watchpoint specified by the given parameters.
|
||||
bool RemoveWatchpoint(Core::System& system, KProcessAddress addr, u64 size,
|
||||
DebugWatchpointType type);
|
||||
bool RemoveWatchpoint(KProcessAddress addr, u64 size, DebugWatchpointType type);
|
||||
|
||||
const std::array<DebugWatchpoint, Core::Hardware::NUM_WATCHPOINTS>& GetWatchpoints() const {
|
||||
return m_watchpoints;
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ Result KServerSession::SendReply(bool is_hle) {
|
|||
// HLE servers write directly to a pointer to the thread command buffer. Therefore
|
||||
// the reply has already been written in this case.
|
||||
} else {
|
||||
Core::Memory::Memory& memory{m_kernel.System().Memory()};
|
||||
Core::Memory::Memory& memory{client_thread->GetOwnerProcess()->GetMemory()};
|
||||
KThread* server_thread{GetCurrentThreadPointer(m_kernel)};
|
||||
UNIMPLEMENTED_IF(server_thread->GetOwnerProcess() != client_thread->GetOwnerProcess());
|
||||
|
||||
|
|
@ -319,7 +319,7 @@ Result KServerSession::ReceiveRequest(std::shared_ptr<Service::HLERequestContext
|
|||
// bool recv_list_broken = false;
|
||||
|
||||
// Receive the message.
|
||||
Core::Memory::Memory& memory{m_kernel.System().Memory()};
|
||||
Core::Memory::Memory& memory{client_thread->GetOwnerProcess()->GetMemory()};
|
||||
if (out_context != nullptr) {
|
||||
// HLE request.
|
||||
u32* cmd_buf{reinterpret_cast<u32*>(memory.GetPointer(client_message))};
|
||||
|
|
|
|||
|
|
@ -546,7 +546,7 @@ u16 KThread::GetUserDisableCount() const {
|
|||
return {};
|
||||
}
|
||||
|
||||
auto& memory = m_kernel.System().Memory();
|
||||
auto& memory = this->GetOwnerProcess()->GetMemory();
|
||||
return memory.Read16(m_tls_address + offsetof(ThreadLocalRegion, disable_count));
|
||||
}
|
||||
|
||||
|
|
@ -556,7 +556,7 @@ void KThread::SetInterruptFlag() {
|
|||
return;
|
||||
}
|
||||
|
||||
auto& memory = m_kernel.System().Memory();
|
||||
auto& memory = this->GetOwnerProcess()->GetMemory();
|
||||
memory.Write16(m_tls_address + offsetof(ThreadLocalRegion, interrupt_flag), 1);
|
||||
}
|
||||
|
||||
|
|
@ -566,7 +566,7 @@ void KThread::ClearInterruptFlag() {
|
|||
return;
|
||||
}
|
||||
|
||||
auto& memory = m_kernel.System().Memory();
|
||||
auto& memory = this->GetOwnerProcess()->GetMemory();
|
||||
memory.Write16(m_tls_address + offsetof(ThreadLocalRegion, interrupt_flag), 0);
|
||||
}
|
||||
|
||||
|
|
@ -1422,6 +1422,11 @@ s32 GetCurrentCoreId(KernelCore& kernel) {
|
|||
return GetCurrentThread(kernel).GetCurrentCore();
|
||||
}
|
||||
|
||||
Core::Memory::Memory& GetCurrentMemory(KernelCore& kernel) {
|
||||
// TODO: per-process memory
|
||||
return kernel.System().ApplicationMemory();
|
||||
}
|
||||
|
||||
KScopedDisableDispatch::~KScopedDisableDispatch() {
|
||||
// If we are shutting down the kernel, none of this is relevant anymore.
|
||||
if (m_kernel.IsShuttingDown()) {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,9 @@ class Fiber;
|
|||
}
|
||||
|
||||
namespace Core {
|
||||
namespace Memory {
|
||||
class Memory;
|
||||
}
|
||||
class ARM_Interface;
|
||||
class System;
|
||||
} // namespace Core
|
||||
|
|
@ -113,6 +116,7 @@ KThread& GetCurrentThread(KernelCore& kernel);
|
|||
KProcess* GetCurrentProcessPointer(KernelCore& kernel);
|
||||
KProcess& GetCurrentProcess(KernelCore& kernel);
|
||||
s32 GetCurrentCoreId(KernelCore& kernel);
|
||||
Core::Memory::Memory& GetCurrentMemory(KernelCore& kernel);
|
||||
|
||||
class KThread final : public KAutoObjectWithSlabHeapAndContainer<KThread, KWorkerTask>,
|
||||
public boost::intrusive::list_base_hook<>,
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ struct KernelCore::Impl {
|
|||
void InitializeCores() {
|
||||
for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) {
|
||||
cores[core_id]->Initialize((*application_process).Is64BitProcess());
|
||||
system.Memory().SetCurrentPageTable(*application_process, core_id);
|
||||
system.ApplicationMemory().SetCurrentPageTable(*application_process, core_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ struct KernelCore::Impl {
|
|||
|
||||
void InitializePhysicalCores() {
|
||||
exclusive_monitor =
|
||||
Core::MakeExclusiveMonitor(system.Memory(), Core::Hardware::NUM_CPU_CORES);
|
||||
Core::MakeExclusiveMonitor(system.ApplicationMemory(), Core::Hardware::NUM_CPU_CORES);
|
||||
for (u32 i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) {
|
||||
const s32 core{static_cast<s32>(i)};
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue