summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/debugger/debugger.cpp161
-rw-r--r--src/core/debugger/gdbstub.cpp151
-rw-r--r--src/core/debugger/gdbstub.h1
-rw-r--r--src/core/hle/kernel/init/init_slab_setup.cpp1
-rw-r--r--src/core/hle/kernel/k_page_table.cpp3
-rw-r--r--src/core/hle/kernel/k_page_table.h3
-rw-r--r--src/core/hle/kernel/k_process.cpp1
-rw-r--r--src/core/hle/kernel/svc.cpp26
-rw-r--r--src/core/hle/kernel/svc_wrap.h8
-rw-r--r--src/core/hle/result.h76
-rw-r--r--src/core/hle/service/am/applets/applet_error.cpp1
-rw-r--r--src/core/hle/service/am/applets/applet_general_backend.cpp2
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp5
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp5
-rw-r--r--src/core/hle/service/nvflinger/buffer_queue_core.cpp6
-rw-r--r--src/core/hle/service/nvflinger/buffer_queue_core.h5
-rw-r--r--src/core/hle/service/nvflinger/buffer_queue_producer.cpp14
-rw-r--r--src/core/hle/service/nvflinger/buffer_queue_producer.h3
-rw-r--r--src/core/hle/service/service.cpp1
-rw-r--r--src/core/hle/service/time/time_zone_manager.cpp1
-rw-r--r--src/core/memory.cpp65
-rw-r--r--src/core/memory.h34
22 files changed, 478 insertions, 95 deletions
diff --git a/src/core/debugger/debugger.cpp b/src/core/debugger/debugger.cpp
index 339f971e6..1a8e02e6a 100644
--- a/src/core/debugger/debugger.cpp
+++ b/src/core/debugger/debugger.cpp
@@ -27,12 +27,21 @@ static void AsyncReceiveInto(Readable& r, Buffer& buffer, Callback&& c) {
const u8* buffer_start = reinterpret_cast<const u8*>(&buffer);
std::span<const u8> received_data{buffer_start, buffer_start + bytes_read};
c(received_data);
+ AsyncReceiveInto(r, buffer, c);
}
-
- AsyncReceiveInto(r, buffer, c);
});
}
+template <typename Callback>
+static void AsyncAccept(boost::asio::ip::tcp::acceptor& acceptor, Callback&& c) {
+ acceptor.async_accept([&, c](const boost::system::error_code& error, auto&& peer_socket) {
+ if (!error.failed()) {
+ c(peer_socket);
+ AsyncAccept(acceptor, c);
+ }
+ });
+}
+
template <typename Readable, typename Buffer>
static std::span<const u8> ReceiveInto(Readable& r, Buffer& buffer) {
static_assert(std::is_trivial_v<Buffer>);
@@ -59,9 +68,7 @@ namespace Core {
class DebuggerImpl : public DebuggerBackend {
public:
- explicit DebuggerImpl(Core::System& system_, u16 port)
- : system{system_}, signal_pipe{io_context}, client_socket{io_context} {
- frontend = std::make_unique<GDBStub>(*this, system);
+ explicit DebuggerImpl(Core::System& system_, u16 port) : system{system_} {
InitializeServer(port);
}
@@ -70,39 +77,42 @@ public:
}
bool SignalDebugger(SignalInfo signal_info) {
- {
- std::scoped_lock lk{connection_lock};
+ std::scoped_lock lk{connection_lock};
- if (stopped) {
- // Do not notify the debugger about another event.
- // It should be ignored.
- return false;
- }
-
- // Set up the state.
- stopped = true;
- info = signal_info;
+ if (stopped || !state) {
+ // Do not notify the debugger about another event.
+ // It should be ignored.
+ return false;
}
+ // Set up the state.
+ stopped = true;
+ state->info = signal_info;
+
// Write a single byte into the pipe to wake up the debug interface.
- boost::asio::write(signal_pipe, boost::asio::buffer(&stopped, sizeof(stopped)));
+ boost::asio::write(state->signal_pipe, boost::asio::buffer(&stopped, sizeof(stopped)));
+
return true;
}
+ // These functions are callbacks from the frontend, and the lock will be held.
+ // There is no need to relock it.
+
std::span<const u8> ReadFromClient() override {
- return ReceiveInto(client_socket, client_data);
+ return ReceiveInto(state->client_socket, state->client_data);
}
void WriteToClient(std::span<const u8> data) override {
- boost::asio::write(client_socket, boost::asio::buffer(data.data(), data.size_bytes()));
+ boost::asio::write(state->client_socket,
+ boost::asio::buffer(data.data(), data.size_bytes()));
}
void SetActiveThread(Kernel::KThread* thread) override {
- active_thread = thread;
+ state->active_thread = thread;
}
Kernel::KThread* GetActiveThread() override {
- return active_thread;
+ return state->active_thread;
}
private:
@@ -113,65 +123,78 @@ private:
// Run the connection thread.
connection_thread = std::jthread([&, port](std::stop_token stop_token) {
+ Common::SetCurrentThreadName("Debugger");
+
try {
// Initialize the listening socket and accept a new client.
tcp::endpoint endpoint{boost::asio::ip::address_v4::any(), port};
tcp::acceptor acceptor{io_context, endpoint};
- acceptor.async_accept(client_socket, [](const auto&) {});
- io_context.run_one();
- io_context.restart();
+ AsyncAccept(acceptor, [&](auto&& peer) { AcceptConnection(std::move(peer)); });
- if (stop_token.stop_requested()) {
- return;
+ while (!stop_token.stop_requested() && io_context.run()) {
}
-
- ThreadLoop(stop_token);
} catch (const std::exception& ex) {
LOG_CRITICAL(Debug_GDBStub, "Stopping server: {}", ex.what());
}
});
}
- void ShutdownServer() {
- connection_thread.request_stop();
- io_context.stop();
- connection_thread.join();
- }
+ void AcceptConnection(boost::asio::ip::tcp::socket&& peer) {
+ LOG_INFO(Debug_GDBStub, "Accepting new peer connection");
- void ThreadLoop(std::stop_token stop_token) {
- Common::SetCurrentThreadName("Debugger");
+ std::scoped_lock lk{connection_lock};
+
+ // Ensure everything is stopped.
+ PauseEmulation();
+
+ // Set up the new frontend.
+ frontend = std::make_unique<GDBStub>(*this, system);
+
+ // Set the new state. This will tear down any existing state.
+ state = ConnectionState{
+ .client_socket{std::move(peer)},
+ .signal_pipe{io_context},
+ .info{},
+ .active_thread{},
+ .client_data{},
+ .pipe_data{},
+ };
// Set up the client signals for new data.
- AsyncReceiveInto(signal_pipe, pipe_data, [&](auto d) { PipeData(d); });
- AsyncReceiveInto(client_socket, client_data, [&](auto d) { ClientData(d); });
+ AsyncReceiveInto(state->signal_pipe, state->pipe_data, [&](auto d) { PipeData(d); });
+ AsyncReceiveInto(state->client_socket, state->client_data, [&](auto d) { ClientData(d); });
// Set the active thread.
UpdateActiveThread();
// Set up the frontend.
frontend->Connected();
+ }
- // Main event loop.
- while (!stop_token.stop_requested() && io_context.run()) {
- }
+ void ShutdownServer() {
+ connection_thread.request_stop();
+ io_context.stop();
+ connection_thread.join();
}
void PipeData(std::span<const u8> data) {
- switch (info.type) {
+ std::scoped_lock lk{connection_lock};
+
+ switch (state->info.type) {
case SignalType::Stopped:
case SignalType::Watchpoint:
// Stop emulation.
PauseEmulation();
// Notify the client.
- active_thread = info.thread;
+ state->active_thread = state->info.thread;
UpdateActiveThread();
- if (info.type == SignalType::Watchpoint) {
- frontend->Watchpoint(active_thread, *info.watchpoint);
+ if (state->info.type == SignalType::Watchpoint) {
+ frontend->Watchpoint(state->active_thread, *state->info.watchpoint);
} else {
- frontend->Stopped(active_thread);
+ frontend->Stopped(state->active_thread);
}
break;
@@ -179,8 +202,8 @@ private:
frontend->ShuttingDown();
// Wait for emulation to shut down gracefully now.
- signal_pipe.close();
- client_socket.shutdown(boost::asio::socket_base::shutdown_both);
+ state->signal_pipe.close();
+ state->client_socket.shutdown(boost::asio::socket_base::shutdown_both);
LOG_INFO(Debug_GDBStub, "Shut down server");
break;
@@ -188,17 +211,16 @@ private:
}
void ClientData(std::span<const u8> data) {
+ std::scoped_lock lk{connection_lock};
+
const auto actions{frontend->ClientData(data)};
for (const auto action : actions) {
switch (action) {
case DebuggerAction::Interrupt: {
- {
- std::scoped_lock lk{connection_lock};
- stopped = true;
- }
+ stopped = true;
PauseEmulation();
UpdateActiveThread();
- frontend->Stopped(active_thread);
+ frontend->Stopped(state->active_thread);
break;
}
case DebuggerAction::Continue:
@@ -206,15 +228,15 @@ private:
break;
case DebuggerAction::StepThreadUnlocked:
MarkResumed([&] {
- active_thread->SetStepState(Kernel::StepState::StepPending);
- active_thread->Resume(Kernel::SuspendType::Debug);
- ResumeEmulation(active_thread);
+ state->active_thread->SetStepState(Kernel::StepState::StepPending);
+ state->active_thread->Resume(Kernel::SuspendType::Debug);
+ ResumeEmulation(state->active_thread);
});
break;
case DebuggerAction::StepThreadLocked: {
MarkResumed([&] {
- active_thread->SetStepState(Kernel::StepState::StepPending);
- active_thread->Resume(Kernel::SuspendType::Debug);
+ state->active_thread->SetStepState(Kernel::StepState::StepPending);
+ state->active_thread->Resume(Kernel::SuspendType::Debug);
});
break;
}
@@ -254,15 +276,14 @@ private:
template <typename Callback>
void MarkResumed(Callback&& cb) {
Kernel::KScopedSchedulerLock sl{system.Kernel()};
- std::scoped_lock cl{connection_lock};
stopped = false;
cb();
}
void UpdateActiveThread() {
const auto& threads{ThreadList()};
- if (std::find(threads.begin(), threads.end(), active_thread) == threads.end()) {
- active_thread = threads[0];
+ if (std::find(threads.begin(), threads.end(), state->active_thread) == threads.end()) {
+ state->active_thread = threads[0];
}
}
@@ -274,18 +295,22 @@ private:
System& system;
std::unique_ptr<DebuggerFrontend> frontend;
+ boost::asio::io_context io_context;
std::jthread connection_thread;
std::mutex connection_lock;
- boost::asio::io_context io_context;
- boost::process::async_pipe signal_pipe;
- boost::asio::ip::tcp::socket client_socket;
- SignalInfo info;
- Kernel::KThread* active_thread;
- bool pipe_data;
- bool stopped;
+ struct ConnectionState {
+ boost::asio::ip::tcp::socket client_socket;
+ boost::process::async_pipe signal_pipe;
+
+ SignalInfo info;
+ Kernel::KThread* active_thread;
+ std::array<u8, 4096> client_data;
+ bool pipe_data;
+ };
- std::array<u8, 4096> client_data;
+ std::optional<ConnectionState> state{};
+ bool stopped{};
};
Debugger::Debugger(Core::System& system, u16 port) {
diff --git a/src/core/debugger/gdbstub.cpp b/src/core/debugger/gdbstub.cpp
index 884229c77..a64a9ac64 100644
--- a/src/core/debugger/gdbstub.cpp
+++ b/src/core/debugger/gdbstub.cpp
@@ -606,6 +606,8 @@ void GDBStub::HandleQuery(std::string_view command) {
} else if (command.starts_with("StartNoAckMode")) {
no_ack = true;
SendReply(GDB_STUB_REPLY_OK);
+ } else if (command.starts_with("Rcmd,")) {
+ HandleRcmd(Common::HexStringToVector(command.substr(5), false));
} else {
SendReply(GDB_STUB_REPLY_EMPTY);
}
@@ -645,6 +647,155 @@ void GDBStub::HandleVCont(std::string_view command, std::vector<DebuggerAction>&
}
}
+constexpr std::array<std::pair<const char*, Kernel::Svc::MemoryState>, 22> MemoryStateNames{{
+ {"----- Free -----", Kernel::Svc::MemoryState::Free},
+ {"Io ", Kernel::Svc::MemoryState::Io},
+ {"Static ", Kernel::Svc::MemoryState::Static},
+ {"Code ", Kernel::Svc::MemoryState::Code},
+ {"CodeData ", Kernel::Svc::MemoryState::CodeData},
+ {"Normal ", Kernel::Svc::MemoryState::Normal},
+ {"Shared ", Kernel::Svc::MemoryState::Shared},
+ {"AliasCode ", Kernel::Svc::MemoryState::AliasCode},
+ {"AliasCodeData ", Kernel::Svc::MemoryState::AliasCodeData},
+ {"Ipc ", Kernel::Svc::MemoryState::Ipc},
+ {"Stack ", Kernel::Svc::MemoryState::Stack},
+ {"ThreadLocal ", Kernel::Svc::MemoryState::ThreadLocal},
+ {"Transfered ", Kernel::Svc::MemoryState::Transfered},
+ {"SharedTransfered", Kernel::Svc::MemoryState::SharedTransfered},
+ {"SharedCode ", Kernel::Svc::MemoryState::SharedCode},
+ {"Inaccessible ", Kernel::Svc::MemoryState::Inaccessible},
+ {"NonSecureIpc ", Kernel::Svc::MemoryState::NonSecureIpc},
+ {"NonDeviceIpc ", Kernel::Svc::MemoryState::NonDeviceIpc},
+ {"Kernel ", Kernel::Svc::MemoryState::Kernel},
+ {"GeneratedCode ", Kernel::Svc::MemoryState::GeneratedCode},
+ {"CodeOut ", Kernel::Svc::MemoryState::CodeOut},
+ {"Coverage ", Kernel::Svc::MemoryState::Coverage},
+}};
+
+static constexpr const char* GetMemoryStateName(Kernel::Svc::MemoryState state) {
+ for (size_t i = 0; i < MemoryStateNames.size(); i++) {
+ if (std::get<1>(MemoryStateNames[i]) == state) {
+ return std::get<0>(MemoryStateNames[i]);
+ }
+ }
+ return "Unknown ";
+}
+
+static constexpr const char* GetMemoryPermissionString(const Kernel::Svc::MemoryInfo& info) {
+ if (info.state == Kernel::Svc::MemoryState::Free) {
+ return " ";
+ }
+
+ switch (info.permission) {
+ case Kernel::Svc::MemoryPermission::ReadExecute:
+ return "r-x";
+ case Kernel::Svc::MemoryPermission::Read:
+ return "r--";
+ case Kernel::Svc::MemoryPermission::ReadWrite:
+ return "rw-";
+ default:
+ return "---";
+ }
+}
+
+static VAddr GetModuleEnd(Kernel::KPageTable& page_table, VAddr base) {
+ Kernel::Svc::MemoryInfo mem_info;
+ VAddr cur_addr{base};
+
+ // Expect: r-x Code (.text)
+ mem_info = page_table.QueryInfo(cur_addr).GetSvcMemoryInfo();
+ cur_addr = mem_info.base_address + mem_info.size;
+ if (mem_info.state != Kernel::Svc::MemoryState::Code ||
+ mem_info.permission != Kernel::Svc::MemoryPermission::ReadExecute) {
+ return cur_addr - 1;
+ }
+
+ // Expect: r-- Code (.rodata)
+ mem_info = page_table.QueryInfo(cur_addr).GetSvcMemoryInfo();
+ cur_addr = mem_info.base_address + mem_info.size;
+ if (mem_info.state != Kernel::Svc::MemoryState::Code ||
+ mem_info.permission != Kernel::Svc::MemoryPermission::Read) {
+ return cur_addr - 1;
+ }
+
+ // Expect: rw- CodeData (.data)
+ mem_info = page_table.QueryInfo(cur_addr).GetSvcMemoryInfo();
+ cur_addr = mem_info.base_address + mem_info.size;
+ return cur_addr - 1;
+}
+
+void GDBStub::HandleRcmd(const std::vector<u8>& command) {
+ std::string_view command_str{reinterpret_cast<const char*>(&command[0]), command.size()};
+ std::string reply;
+
+ auto* process = system.CurrentProcess();
+ auto& page_table = process->PageTable();
+
+ if (command_str == "get info") {
+ Loader::AppLoader::Modules modules;
+ system.GetAppLoader().ReadNSOModules(modules);
+
+ reply = fmt::format("Process: {:#x} ({})\n"
+ "Program Id: {:#018x}\n",
+ process->GetProcessID(), process->GetName(), process->GetProgramID());
+ reply +=
+ fmt::format("Layout:\n"
+ " Alias: {:#012x} - {:#012x}\n"
+ " Heap: {:#012x} - {:#012x}\n"
+ " Aslr: {:#012x} - {:#012x}\n"
+ " Stack: {:#012x} - {:#012x}\n"
+ "Modules:\n",
+ page_table.GetAliasRegionStart(), page_table.GetAliasRegionEnd(),
+ page_table.GetHeapRegionStart(), page_table.GetHeapRegionEnd(),
+ page_table.GetAliasCodeRegionStart(), page_table.GetAliasCodeRegionEnd(),
+ page_table.GetStackRegionStart(), page_table.GetStackRegionEnd());
+
+ for (const auto& [vaddr, name] : modules) {
+ reply += fmt::format(" {:#012x} - {:#012x} {}\n", vaddr,
+ GetModuleEnd(page_table, vaddr), name);
+ }
+ } else if (command_str == "get mappings") {
+ reply = "Mappings:\n";
+ VAddr cur_addr = 0;
+
+ while (true) {
+ using MemoryAttribute = Kernel::Svc::MemoryAttribute;
+
+ auto mem_info = page_table.QueryInfo(cur_addr).GetSvcMemoryInfo();
+
+ if (mem_info.state != Kernel::Svc::MemoryState::Inaccessible ||
+ mem_info.base_address + mem_info.size - 1 != std::numeric_limits<u64>::max()) {
+ const char* state = GetMemoryStateName(mem_info.state);
+ const char* perm = GetMemoryPermissionString(mem_info);
+
+ const char l = True(mem_info.attribute & MemoryAttribute::Locked) ? 'L' : '-';
+ const char i = True(mem_info.attribute & MemoryAttribute::IpcLocked) ? 'I' : '-';
+ const char d = True(mem_info.attribute & MemoryAttribute::DeviceShared) ? 'D' : '-';
+ const char u = True(mem_info.attribute & MemoryAttribute::Uncached) ? 'U' : '-';
+
+ reply +=
+ fmt::format(" {:#012x} - {:#012x} {} {} {}{}{}{} [{}, {}]\n",
+ mem_info.base_address, mem_info.base_address + mem_info.size - 1,
+ perm, state, l, i, d, u, mem_info.ipc_count, mem_info.device_count);
+ }
+
+ const uintptr_t next_address = mem_info.base_address + mem_info.size;
+ if (next_address <= cur_addr) {
+ break;
+ }
+
+ cur_addr = next_address;
+ }
+ } else if (command_str == "help") {
+ reply = "Commands:\n get info\n get mappings\n";
+ } else {
+ reply = "Unknown command.\nCommands:\n get info\n get mappings\n";
+ }
+
+ std::span<const u8> reply_span{reinterpret_cast<u8*>(&reply.front()), reply.size()};
+ SendReply(Common::HexToString(reply_span, false));
+}
+
Kernel::KThread* GDBStub::GetThreadByID(u64 thread_id) {
const auto& threads{system.GlobalSchedulerContext().GetThreadList()};
for (auto* thread : threads) {
diff --git a/src/core/debugger/gdbstub.h b/src/core/debugger/gdbstub.h
index 0b0f56e4b..368197920 100644
--- a/src/core/debugger/gdbstub.h
+++ b/src/core/debugger/gdbstub.h
@@ -32,6 +32,7 @@ private:
void ExecuteCommand(std::string_view packet, std::vector<DebuggerAction>& actions);
void HandleVCont(std::string_view command, std::vector<DebuggerAction>& actions);
void HandleQuery(std::string_view command);
+ void HandleRcmd(const std::vector<u8>& command);
void HandleBreakpointInsert(std::string_view command);
void HandleBreakpointRemove(std::string_view command);
std::vector<char>::const_iterator CommandEnd() const;
diff --git a/src/core/hle/kernel/init/init_slab_setup.cpp b/src/core/hle/kernel/init/init_slab_setup.cpp
index bda098511..7b363eb1e 100644
--- a/src/core/hle/kernel/init/init_slab_setup.cpp
+++ b/src/core/hle/kernel/init/init_slab_setup.cpp
@@ -243,6 +243,7 @@ void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) {
// If we somehow get an invalid type, abort.
default:
ASSERT_MSG(false, "Unknown slab type: {}", slab_types[i]);
+ break;
}
// If we've hit the end of a gap, free it.
diff --git a/src/core/hle/kernel/k_page_table.cpp b/src/core/hle/kernel/k_page_table.cpp
index 5387bf5fe..612fc76fa 100644
--- a/src/core/hle/kernel/k_page_table.cpp
+++ b/src/core/hle/kernel/k_page_table.cpp
@@ -2301,6 +2301,7 @@ Result KPageTable::SetProcessMemoryPermission(VAddr addr, size_t size,
break;
default:
ASSERT(false);
+ break;
}
}
@@ -2803,6 +2804,7 @@ Result KPageTable::Operate(VAddr addr, size_t num_pages, const KPageGroup& page_
break;
default:
ASSERT(false);
+ break;
}
addr += size;
@@ -2838,6 +2840,7 @@ Result KPageTable::Operate(VAddr addr, size_t num_pages, KMemoryPermission perm,
break;
default:
ASSERT(false);
+ break;
}
R_SUCCEED();
}
diff --git a/src/core/hle/kernel/k_page_table.h b/src/core/hle/kernel/k_page_table.h
index 950850291..f1ca785d7 100644
--- a/src/core/hle/kernel/k_page_table.h
+++ b/src/core/hle/kernel/k_page_table.h
@@ -320,6 +320,9 @@ public:
constexpr VAddr GetAliasCodeRegionStart() const {
return m_alias_code_region_start;
}
+ constexpr VAddr GetAliasCodeRegionEnd() const {
+ return m_alias_code_region_end;
+ }
constexpr VAddr GetAliasCodeRegionSize() const {
return m_alias_code_region_end - m_alias_code_region_start;
}
diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp
index 55a9c5fae..d1dc62401 100644
--- a/src/core/hle/kernel/k_process.cpp
+++ b/src/core/hle/kernel/k_process.cpp
@@ -395,6 +395,7 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std:
default:
ASSERT(false);
+ break;
}
// Create TLS region
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 9962ad171..e520cab47 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -2701,14 +2701,24 @@ static Result GetThreadList(Core::System& system, u32* out_num_threads, VAddr ou
return ResultSuccess;
}
-static Result FlushProcessDataCache32([[maybe_unused]] Core::System& system,
- [[maybe_unused]] Handle handle, [[maybe_unused]] u32 address,
- [[maybe_unused]] u32 size) {
- // Note(Blinkhawk): For emulation purposes of the data cache this is mostly a no-op,
- // as all emulation is done in the same cache level in host architecture, thus data cache
- // does not need flushing.
- LOG_DEBUG(Kernel_SVC, "called");
- return ResultSuccess;
+static Result FlushProcessDataCache32(Core::System& system, Handle process_handle, u64 address,
+ u64 size) {
+ // Validate address/size.
+ R_UNLESS(size > 0, ResultInvalidSize);
+ R_UNLESS(address == static_cast<uintptr_t>(address), ResultInvalidCurrentMemory);
+ R_UNLESS(size == static_cast<size_t>(size), ResultInvalidCurrentMemory);
+
+ // Get the process from its handle.
+ KScopedAutoObject process =
+ system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KProcess>(process_handle);
+ R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
+
+ // Verify the region is within range.
+ auto& page_table = process->PageTable();
+ R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory);
+
+ // Perform the operation.
+ R_RETURN(system.Memory().FlushDataCache(*process, address, size));
}
namespace {
diff --git a/src/core/hle/kernel/svc_wrap.h b/src/core/hle/kernel/svc_wrap.h
index 272c54cf7..3730937fe 100644
--- a/src/core/hle/kernel/svc_wrap.h
+++ b/src/core/hle/kernel/svc_wrap.h
@@ -722,4 +722,12 @@ void SvcWrap32(Core::System& system) {
FuncReturn(system, retval);
}
+// Used by Invalidate/Store/FlushProcessDataCache32
+template <Result func(Core::System&, Handle, u64, u64)>
+void SvcWrap32(Core::System& system) {
+ const u64 address = (Param(system, 3) << 32) | Param(system, 2);
+ const u64 size = (Param(system, 4) << 32) | Param(system, 1);
+ FuncReturn32(system, func(system, Param32(system, 0), address, size).raw);
+}
+
} // namespace Kernel
diff --git a/src/core/hle/result.h b/src/core/hle/result.h
index 56c990728..240f06689 100644
--- a/src/core/hle/result.h
+++ b/src/core/hle/result.h
@@ -28,30 +28,49 @@ enum class ErrorModule : u32 {
Loader = 9,
CMIF = 10,
HIPC = 11,
+ TMA = 12,
+ DMNT = 13,
+ GDS = 14,
PM = 15,
NS = 16,
+ BSDSockets = 17,
HTC = 18,
+ TSC = 19,
NCMContent = 20,
SM = 21,
RO = 22,
+ GC = 23,
SDMMC = 24,
OVLN = 25,
SPL = 26,
+ Socket = 27,
+ HTCLOW = 29,
+ DDSF = 30,
+ HTCFS = 31,
+ Async = 32,
+ Util = 33,
+ TIPC = 35,
+ ANIF = 37,
ETHC = 100,
I2C = 101,
GPIO = 102,
UART = 103,
+ CPAD = 104,
Settings = 105,
+ FTM = 106,
WLAN = 107,
XCD = 108,
+ TMP451 = 109,
NIFM = 110,
Hwopus = 111,
+ LSM6DS3 = 112,
Bluetooth = 113,
VI = 114,
NFP = 115,
Time = 116,
FGM = 117,
OE = 118,
+ BH1730FVC = 119,
PCIe = 120,
Friends = 121,
BCAT = 122,
@@ -65,7 +84,7 @@ enum class ErrorModule : u32 {
AHID = 130,
Qlaunch = 132,
PCV = 133,
- OMM = 134,
+ USBPD = 134,
BPC = 135,
PSM = 136,
NIM = 137,
@@ -75,18 +94,22 @@ enum class ErrorModule : u32 {
NSD = 141,
PCTL = 142,
BTM = 143,
+ LA = 144,
ETicket = 145,
NGC = 146,
ERPT = 147,
APM = 148,
+ CEC = 149,
Profiler = 150,
ErrorUpload = 151,
+ LIDBE = 152,
Audio = 153,
NPNS = 154,
NPNSHTTPSTREAM = 155,
ARP = 157,
SWKBD = 158,
BOOT = 159,
+ NetDiag = 160,
NFCMifare = 161,
UserlandAssert = 162,
Fatal = 163,
@@ -94,17 +117,68 @@ enum class ErrorModule : u32 {
SPSM = 165,
BGTC = 167,
UserlandCrash = 168,
+ SASBUS = 169,
+ PI = 170,
+ AudioCtrl = 172,
+ LBL = 173,
+ JIT = 175,
+ HDCP = 176,
+ OMM = 177,
+ PDM = 178,
+ OLSC = 179,
SREPO = 180,
Dauth = 181,
+ STDFU = 182,
+ DBG = 183,
+ DHCPS = 186,
+ SPI = 187,
+ AVM = 188,
+ PWM = 189,
+ RTC = 191,
+ Regulator = 192,
+ LED = 193,
+ SIO = 195,
+ PCM = 196,
+ CLKRST = 197,
+ POWCTL = 198,
+ AudioOld = 201,
HID = 202,
LDN = 203,
+ CS = 204,
Irsensor = 205,
Capture = 206,
Manu = 208,
ATK = 209,
+ WEB = 210,
+ LCS = 211,
GRC = 212,
+ Repair = 213,
+ Album = 214,
+ RID = 215,
Migration = 216,
MigrationLdcServ = 217,
+ HIDBUS = 218,
+ ENS = 219,
+ WebSocket = 223,
+ DCDMTP = 227,
+ PGL = 228,
+ Notification = 229,
+ INS = 230,
+ LP2P = 231,
+ RCD = 232,
+ LCM40607 = 233,
+ PRC = 235,
+ TMAHTC = 237,
+ ECTX = 238,
+ MNPP = 239,
+ HSHL = 240,
+ CAPMTP = 242,
+ DP2HDMI = 244,
+ Cradle = 245,
+ SProfile = 246,
+ NDRM = 250,
+ TSPM = 499,
+ DevMenu = 500,
GeneralWebApplet = 800,
WifiWebAuthApplet = 809,
WhitelistedApplet = 810,
diff --git a/src/core/hle/service/am/applets/applet_error.cpp b/src/core/hle/service/am/applets/applet_error.cpp
index fcf34bf7e..bae0d99a6 100644
--- a/src/core/hle/service/am/applets/applet_error.cpp
+++ b/src/core/hle/service/am/applets/applet_error.cpp
@@ -144,6 +144,7 @@ void Error::Initialize() {
break;
default:
UNIMPLEMENTED_MSG("Unimplemented LibAppletError mode={:02X}!", mode);
+ break;
}
}
diff --git a/src/core/hle/service/am/applets/applet_general_backend.cpp b/src/core/hle/service/am/applets/applet_general_backend.cpp
index c34ef08b3..e50acdaf6 100644
--- a/src/core/hle/service/am/applets/applet_general_backend.cpp
+++ b/src/core/hle/service/am/applets/applet_general_backend.cpp
@@ -129,6 +129,7 @@ void Auth::Execute() {
}
default:
unimplemented_log();
+ break;
}
}
@@ -192,6 +193,7 @@ void PhotoViewer::Execute() {
break;
default:
UNIMPLEMENTED_MSG("Unimplemented PhotoViewer applet mode={:02X}!", mode);
+ break;
}
}
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp
index ced57dfe6..b97813fbc 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp
@@ -300,11 +300,10 @@ Kernel::KEvent* nvhost_ctrl_gpu::QueryEvent(u32 event_id) {
return error_notifier_event;
case 2:
return unknown_event;
- default: {
+ default:
LOG_CRITICAL(Service_NVDRV, "Unknown Ctrl GPU Event {}", event_id);
+ return nullptr;
}
- }
- return nullptr;
}
} // namespace Service::Nvidia::Devices
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
index 45a759fa8..e123564c6 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
@@ -364,11 +364,10 @@ Kernel::KEvent* nvhost_gpu::QueryEvent(u32 event_id) {
return sm_exception_breakpoint_pause_report_event;
case 3:
return error_notifier_event;
- default: {
+ default:
LOG_CRITICAL(Service_NVDRV, "Unknown Ctrl GPU Event {}", event_id);
+ return nullptr;
}
- }
- return nullptr;
}
} // namespace Service::Nvidia::Devices
diff --git a/src/core/hle/service/nvflinger/buffer_queue_core.cpp b/src/core/hle/service/nvflinger/buffer_queue_core.cpp
index ea4a14ea4..3d1338e66 100644
--- a/src/core/hle/service/nvflinger/buffer_queue_core.cpp
+++ b/src/core/hle/service/nvflinger/buffer_queue_core.cpp
@@ -23,15 +23,17 @@ void BufferQueueCore::NotifyShutdown() {
}
void BufferQueueCore::SignalDequeueCondition() {
+ dequeue_possible.store(true);
dequeue_condition.notify_all();
}
-bool BufferQueueCore::WaitForDequeueCondition() {
+bool BufferQueueCore::WaitForDequeueCondition(std::unique_lock<std::mutex>& lk) {
if (is_shutting_down) {
return false;
}
- dequeue_condition.wait(mutex);
+ dequeue_condition.wait(lk, [&] { return dequeue_possible.load(); });
+ dequeue_possible.store(false);
return true;
}
diff --git a/src/core/hle/service/nvflinger/buffer_queue_core.h b/src/core/hle/service/nvflinger/buffer_queue_core.h
index ca6baefaf..85b3bc4c1 100644
--- a/src/core/hle/service/nvflinger/buffer_queue_core.h
+++ b/src/core/hle/service/nvflinger/buffer_queue_core.h
@@ -38,7 +38,7 @@ public:
private:
void SignalDequeueCondition();
- bool WaitForDequeueCondition();
+ bool WaitForDequeueCondition(std::unique_lock<std::mutex>& lk);
s32 GetMinUndequeuedBufferCountLocked(bool async) const;
s32 GetMinMaxBufferCountLocked(bool async) const;
@@ -60,7 +60,8 @@ private:
BufferQueueDefs::SlotsType slots{};
std::vector<BufferItem> queue;
s32 override_max_buffer_count{};
- mutable std::condition_variable_any dequeue_condition;
+ std::condition_variable dequeue_condition;
+ std::atomic<bool> dequeue_possible{};
const bool use_async_buffer{}; // This is always disabled on HOS
bool dequeue_buffer_cannot_block{};
PixelFormat default_buffer_format{PixelFormat::Rgba8888};
diff --git a/src/core/hle/service/nvflinger/buffer_queue_producer.cpp b/src/core/hle/service/nvflinger/buffer_queue_producer.cpp
index 41ba44b21..e601b5da1 100644
--- a/src/core/hle/service/nvflinger/buffer_queue_producer.cpp
+++ b/src/core/hle/service/nvflinger/buffer_queue_producer.cpp
@@ -121,8 +121,8 @@ Status BufferQueueProducer::SetBufferCount(s32 buffer_count) {
return Status::NoError;
}
-Status BufferQueueProducer::WaitForFreeSlotThenRelock(bool async, s32* found,
- Status* return_flags) const {
+Status BufferQueueProducer::WaitForFreeSlotThenRelock(bool async, s32* found, Status* return_flags,
+ std::unique_lock<std::mutex>& lk) const {
bool try_again = true;
while (try_again) {
@@ -214,7 +214,7 @@ Status BufferQueueProducer::WaitForFreeSlotThenRelock(bool async, s32* found,
return Status::WouldBlock;
}
- if (!core->WaitForDequeueCondition()) {
+ if (!core->WaitForDequeueCondition(lk)) {
// We are no longer running
return Status::NoError;
}
@@ -237,7 +237,7 @@ Status BufferQueueProducer::DequeueBuffer(s32* out_slot, Fence* out_fence, bool
Status return_flags = Status::NoError;
bool attached_by_consumer = false;
{
- std::scoped_lock lock{core->mutex};
+ std::unique_lock lock{core->mutex};
core->WaitWhileAllocatingLocked();
if (format == PixelFormat::NoFormat) {
@@ -248,7 +248,7 @@ Status BufferQueueProducer::DequeueBuffer(s32* out_slot, Fence* out_fence, bool
usage |= core->consumer_usage_bit;
s32 found{};
- Status status = WaitForFreeSlotThenRelock(async, &found, &return_flags);
+ Status status = WaitForFreeSlotThenRelock(async, &found, &return_flags, lock);
if (status != Status::NoError) {
return status;
}
@@ -400,13 +400,13 @@ Status BufferQueueProducer::AttachBuffer(s32* out_slot,
return Status::BadValue;
}
- std::scoped_lock lock{core->mutex};
+ std::unique_lock lock{core->mutex};
core->WaitWhileAllocatingLocked();
Status return_flags = Status::NoError;
s32 found{};
- const auto status = WaitForFreeSlotThenRelock(false, &found, &return_flags);
+ const auto status = WaitForFreeSlotThenRelock(false, &found, &return_flags, lock);
if (status != Status::NoError) {
return status;
}
diff --git a/src/core/hle/service/nvflinger/buffer_queue_producer.h b/src/core/hle/service/nvflinger/buffer_queue_producer.h
index 7526bf8ec..1d380480f 100644
--- a/src/core/hle/service/nvflinger/buffer_queue_producer.h
+++ b/src/core/hle/service/nvflinger/buffer_queue_producer.h
@@ -70,7 +70,8 @@ public:
private:
BufferQueueProducer(const BufferQueueProducer&) = delete;
- Status WaitForFreeSlotThenRelock(bool async, s32* found, Status* return_flags) const;
+ Status WaitForFreeSlotThenRelock(bool async, s32* found, Status* return_flags,
+ std::unique_lock<std::mutex>& lk) const;
Kernel::KEvent* buffer_wait_event{};
Service::KernelHelpers::ServiceContext& service_context;
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index 5ab41c0c4..0de67f1e1 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -228,6 +228,7 @@ Result ServiceFrameworkBase::HandleSyncRequest(Kernel::KServerSession& session,
}
UNIMPLEMENTED_MSG("command_type={}", ctx.GetCommandType());
+ break;
}
// If emulation was shutdown, we are closing service threads, do not write the response back to
diff --git a/src/core/hle/service/time/time_zone_manager.cpp b/src/core/hle/service/time/time_zone_manager.cpp
index 2aa675df9..f9ada7c93 100644
--- a/src/core/hle/service/time/time_zone_manager.cpp
+++ b/src/core/hle/service/time/time_zone_manager.cpp
@@ -280,6 +280,7 @@ static constexpr int TransitionTime(int year, Rule rule, int offset) {
}
default:
ASSERT(false);
+ break;
}
return value + rule.transition_time + offset;
}
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 3ca80c8ff..3141122f1 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -6,6 +6,7 @@
#include "common/assert.h"
#include "common/atomic_ops.h"
+#include "common/cache_management.h"
#include "common/common_types.h"
#include "common/logging/log.h"
#include "common/page_table.h"
@@ -329,6 +330,55 @@ struct Memory::Impl {
});
}
+ template <typename Callback>
+ Result PerformCacheOperation(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size,
+ Callback&& cb) {
+ class InvalidMemoryException : public std::exception {};
+
+ try {
+ WalkBlock(
+ process, dest_addr, size,
+ [&](const std::size_t block_size, const VAddr current_vaddr) {
+ LOG_ERROR(HW_Memory, "Unmapped cache maintenance @ {:#018X}", current_vaddr);
+ throw InvalidMemoryException();
+ },
+ [&](const std::size_t block_size, u8* const host_ptr) { cb(block_size, host_ptr); },
+ [&](const VAddr current_vaddr, const std::size_t block_size, u8* const host_ptr) {
+ system.GPU().FlushRegion(current_vaddr, block_size);
+ cb(block_size, host_ptr);
+ },
+ [](const std::size_t block_size) {});
+ } catch (InvalidMemoryException&) {
+ return Kernel::ResultInvalidCurrentMemory;
+ }
+
+ return ResultSuccess;
+ }
+
+ Result InvalidateDataCache(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size) {
+ auto perform = [&](const std::size_t block_size, u8* const host_ptr) {
+ // Do nothing; this operation (dc ivac) cannot be supported
+ // from EL0
+ };
+ return PerformCacheOperation(process, dest_addr, size, perform);
+ }
+
+ Result StoreDataCache(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size) {
+ auto perform = [&](const std::size_t block_size, u8* const host_ptr) {
+ // dc cvac: Store to point of coherency
+ Common::DataCacheLineCleanByVAToPoC(host_ptr, block_size);
+ };
+ return PerformCacheOperation(process, dest_addr, size, perform);
+ }
+
+ Result FlushDataCache(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size) {
+ auto perform = [&](const std::size_t block_size, u8* const host_ptr) {
+ // dc civac: Store to point of coherency, and invalidate from cache
+ Common::DataCacheLineCleanAndInvalidateByVAToPoC(host_ptr, block_size);
+ };
+ return PerformCacheOperation(process, dest_addr, size, perform);
+ }
+
void MarkRegionDebug(VAddr vaddr, u64 size, bool debug) {
if (vaddr == 0) {
return;
@@ -786,6 +836,21 @@ void Memory::ZeroBlock(const Kernel::KProcess& process, VAddr dest_addr, const s
impl->ZeroBlock(process, dest_addr, size);
}
+Result Memory::InvalidateDataCache(const Kernel::KProcess& process, VAddr dest_addr,
+ const std::size_t size) {
+ return impl->InvalidateDataCache(process, dest_addr, size);
+}
+
+Result Memory::StoreDataCache(const Kernel::KProcess& process, VAddr dest_addr,
+ const std::size_t size) {
+ return impl->StoreDataCache(process, dest_addr, size);
+}
+
+Result Memory::FlushDataCache(const Kernel::KProcess& process, VAddr dest_addr,
+ const std::size_t size) {
+ return impl->FlushDataCache(process, dest_addr, size);
+}
+
void Memory::RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached) {
impl->RasterizerMarkRegionCached(vaddr, size, cached);
}
diff --git a/src/core/memory.h b/src/core/memory.h
index 81eac448b..31fe699d8 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -7,6 +7,7 @@
#include <memory>
#include <string>
#include "common/common_types.h"
+#include "core/hle/result.h"
namespace Common {
struct PageTable;
@@ -450,6 +451,39 @@ public:
void ZeroBlock(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size);
/**
+ * Invalidates a range of bytes within the current process' address space at the specified
+ * virtual address.
+ *
+ * @param process The process that will have data invalidated within its address space.
+ * @param dest_addr The destination virtual address to invalidate the data from.
+ * @param size The size of the range to invalidate, in bytes.
+ *
+ */
+ Result InvalidateDataCache(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size);
+
+ /**
+ * Stores a range of bytes within the current process' address space at the specified
+ * virtual address.
+ *
+ * @param process The process that will have data stored within its address space.
+ * @param dest_addr The destination virtual address to store the data from.
+ * @param size The size of the range to store, in bytes.
+ *
+ */
+ Result StoreDataCache(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size);
+
+ /**
+ * Flushes a range of bytes within the current process' address space at the specified
+ * virtual address.
+ *
+ * @param process The process that will have data flushed within its address space.
+ * @param dest_addr The destination virtual address to flush the data from.
+ * @param size The size of the range to flush, in bytes.
+ *
+ */
+ Result FlushDataCache(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size);
+
+ /**
* Marks each page within the specified address range as cached or uncached.
*
* @param vaddr The virtual address indicating the start of the address range.