mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-06-06 01:13:45 -04:00
remove parent refs pt 1/2
This commit is contained in:
parent
3ade9b002f
commit
3e4d2cb3b2
187 changed files with 2272 additions and 2021 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -7,7 +7,6 @@
|
|||
# Build directory
|
||||
/[Bb]uild*/
|
||||
doc-build/
|
||||
out/
|
||||
AppDir/
|
||||
uruntime
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -39,7 +42,7 @@ Result DeviceSession::Initialize(std::string_view name_, SampleFormat sample_for
|
|||
channel_count = channel_count_;
|
||||
session_id = session_id_;
|
||||
handle = handle_;
|
||||
handle->Open();
|
||||
handle->Open(system.Kernel());
|
||||
applet_resource_user_id = applet_resource_user_id_;
|
||||
|
||||
if (type == Sink::StreamType::In) {
|
||||
|
|
@ -60,7 +63,7 @@ void DeviceSession::Finalize() {
|
|||
}
|
||||
|
||||
if (handle) {
|
||||
handle->Close();
|
||||
handle->Close(system.Kernel());
|
||||
handle = nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ Result System::Stop() {
|
|||
session->SetVolume(0.0f);
|
||||
session->ClearBuffers();
|
||||
if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) {
|
||||
buffer_event->Signal();
|
||||
buffer_event->Signal(system.Kernel());
|
||||
}
|
||||
state = State::Stopped;
|
||||
}
|
||||
|
|
@ -164,7 +164,7 @@ void System::ReleaseBuffers() {
|
|||
|
||||
if (signal) {
|
||||
// Signal if any buffer was released, or if none are registered, we need more.
|
||||
buffer_event->Signal();
|
||||
buffer_event->Signal(system.Kernel());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -181,7 +181,7 @@ bool System::FlushAudioInBuffers() {
|
|||
buffers.FlushBuffers(buffers_released);
|
||||
|
||||
if (buffers_released > 0) {
|
||||
buffer_event->Signal();
|
||||
buffer_event->Signal(system.Kernel());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ Result System::Stop() {
|
|||
session->SetVolume(0.0f);
|
||||
session->ClearBuffers();
|
||||
if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) {
|
||||
buffer_event->Signal();
|
||||
buffer_event->Signal(system.Kernel());
|
||||
}
|
||||
state = State::Stopped;
|
||||
}
|
||||
|
|
@ -162,7 +162,7 @@ void System::ReleaseBuffers() {
|
|||
bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session, false)};
|
||||
if (signal) {
|
||||
// Signal if any buffer was released, or if none are registered, we need more.
|
||||
buffer_event->Signal();
|
||||
buffer_event->Signal(system.Kernel());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +179,7 @@ bool System::FlushAudioOutBuffers() {
|
|||
buffers.FlushBuffers(buffers_released);
|
||||
|
||||
if (buffers_released > 0) {
|
||||
buffer_event->Signal();
|
||||
buffer_event->Signal(system.Kernel());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
|
|
@ -540,7 +540,7 @@ Result System::Update(std::span<const u8> input, std::span<u8> performance, std:
|
|||
return result;
|
||||
}
|
||||
|
||||
adsp_rendered_event->Clear();
|
||||
adsp_rendered_event->Clear(core.Kernel());
|
||||
num_times_updated++;
|
||||
|
||||
const auto end_time{core.CoreTiming().GetGlobalTimeNs().count()};
|
||||
|
|
@ -624,7 +624,7 @@ void System::SendCommandToDsp() {
|
|||
reset_command_buffers = false;
|
||||
command_buffer_size = command_size;
|
||||
if (remaining_command_count == 0) {
|
||||
adsp_rendered_event->Signal();
|
||||
adsp_rendered_event->Signal(core.Kernel());
|
||||
}
|
||||
} else {
|
||||
audio_renderer.ClearRemainCommandCount(session_id);
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
|
|||
|
||||
struct System::Impl {
|
||||
explicit Impl(System& system)
|
||||
: kernel{system}, fs_controller{system}, hid_core{}, cpu_manager{system},
|
||||
: kernel{system}, fs_controller{system}, hid_core{system.Kernel()}, cpu_manager{system},
|
||||
reporter{system}, applet_manager{system}, frontend_applets{system}, profile_manager{} {}
|
||||
|
||||
u64 program_id;
|
||||
|
|
@ -923,7 +923,7 @@ void System::PushGeneralChannelData(std::vector<u8>&& data) {
|
|||
const bool was_empty = impl->general_channel.empty();
|
||||
impl->general_channel.push_back(std::move(data));
|
||||
if (was_empty) {
|
||||
impl->general_channel_event->Signal();
|
||||
impl->general_channel_event->Signal(impl->kernel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -935,7 +935,7 @@ bool System::TryPopGeneralChannel(std::vector<u8>& out_data) {
|
|||
out_data = std::move(impl->general_channel.back());
|
||||
impl->general_channel.pop_back();
|
||||
if (impl->general_channel.empty()) {
|
||||
impl->general_channel_event->Clear();
|
||||
impl->general_channel_event->Clear(impl->kernel);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,10 @@ namespace Core {
|
|||
|
||||
class DebuggerImpl : public DebuggerBackend {
|
||||
public:
|
||||
explicit DebuggerImpl(Core::System& system_, u16 port) : system{system_} {
|
||||
explicit DebuggerImpl(Core::System& system_, u16 port)
|
||||
: system{system_}
|
||||
, debug_process{system_.Kernel()}
|
||||
{
|
||||
InitializeServer(port);
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +124,7 @@ public:
|
|||
}
|
||||
|
||||
void SetActiveThread(Kernel::KThread* thread) override {
|
||||
state->active_thread = thread;
|
||||
state->active_thread = {system.Kernel(), thread};
|
||||
}
|
||||
|
||||
Kernel::KThread* GetActiveThread() override {
|
||||
|
|
@ -168,14 +171,7 @@ private:
|
|||
frontend = std::make_unique<GDBStub>(*this, system, debug_process.GetPointerUnsafe());
|
||||
|
||||
// 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{},
|
||||
};
|
||||
state.emplace(std::move(peer), io_context, system.Kernel());
|
||||
|
||||
// Set up the client signals for new data.
|
||||
AsyncReceiveInto(state->signal_pipe, state->pipe_data, [&](auto d) { PipeData(d); });
|
||||
|
|
@ -204,7 +200,7 @@ private:
|
|||
PauseEmulation();
|
||||
|
||||
// Notify the client.
|
||||
state->active_thread = state->info.thread;
|
||||
state->active_thread = {system.Kernel(), state->info.thread};
|
||||
UpdateActiveThread();
|
||||
|
||||
if (state->info.type == SignalType::Watchpoint) {
|
||||
|
|
@ -258,7 +254,7 @@ private:
|
|||
auto* gdb = static_cast<GDBStub*>(frontend.get());
|
||||
MarkResumed([this, threads = std::move(gdb->resume_threads)] {
|
||||
state->active_thread->SetStepState(Kernel::StepState::StepPending);
|
||||
state->active_thread->Resume(Kernel::SuspendType::Debug);
|
||||
state->active_thread->Resume(system.Kernel(), Kernel::SuspendType::Debug);
|
||||
ResumeThreads(threads, state->active_thread.GetPointerUnsafe());
|
||||
});
|
||||
break;
|
||||
|
|
@ -281,7 +277,7 @@ private:
|
|||
|
||||
// Put all threads to sleep on next scheduler round.
|
||||
for (auto& thread : ThreadList()) {
|
||||
thread.RequestSuspend(Kernel::SuspendType::Debug);
|
||||
thread.RequestSuspend(system.Kernel(), Kernel::SuspendType::Debug);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -296,7 +292,7 @@ private:
|
|||
}
|
||||
|
||||
thread.SetStepState(Kernel::StepState::NotStepping);
|
||||
thread.Resume(Kernel::SuspendType::Debug);
|
||||
thread.Resume(system.Kernel(), Kernel::SuspendType::Debug);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -312,7 +308,7 @@ private:
|
|||
}
|
||||
|
||||
thread->SetStepState(Kernel::StepState::NotStepping);
|
||||
thread->Resume(Kernel::SuspendType::Debug);
|
||||
thread->Resume(system.Kernel(), Kernel::SuspendType::Debug);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -332,7 +328,7 @@ private:
|
|||
return;
|
||||
}
|
||||
}
|
||||
state->active_thread = std::addressof(threads.front());
|
||||
state->active_thread = {system.Kernel(), std::addressof(threads.front())};
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -354,13 +350,20 @@ private:
|
|||
std::mutex connection_lock;
|
||||
|
||||
struct ConnectionState {
|
||||
boost::asio::ip::tcp::socket client_socket;
|
||||
#ifdef USE_BOOST_v1
|
||||
boost::process::v1::async_pipe signal_pipe;
|
||||
using async_pipe = boost::process::v1::async_pipe;
|
||||
#else
|
||||
boost::process::async_pipe signal_pipe;
|
||||
using async_pipe = boost::process::async_pipe;
|
||||
#endif
|
||||
|
||||
ConnectionState(boost::asio::ip::tcp::socket&& client_socket_, async_pipe signal_pipe_, Kernel::KernelCore& kernel)
|
||||
: client_socket{std::move(client_socket_)}
|
||||
, signal_pipe{signal_pipe_}
|
||||
, active_thread{kernel, nullptr}
|
||||
{}
|
||||
|
||||
boost::asio::ip::tcp::socket client_socket;
|
||||
async_pipe signal_pipe;
|
||||
SignalInfo info;
|
||||
Kernel::KScopedAutoObject<Kernel::KThread> active_thread;
|
||||
std::array<u8, 4096> client_data;
|
||||
|
|
|
|||
|
|
@ -323,13 +323,13 @@ void GDBStub::HandleBreakpointInsert(std::string_view command) {
|
|||
success = true;
|
||||
break;
|
||||
case BreakpointType::WriteWatch:
|
||||
success = debug_process->InsertWatchpoint(addr, size, Kernel::DebugWatchpointType::Write);
|
||||
success = debug_process->InsertWatchpoint(system.Kernel(), addr, size, Kernel::DebugWatchpointType::Write);
|
||||
break;
|
||||
case BreakpointType::ReadWatch:
|
||||
success = debug_process->InsertWatchpoint(addr, size, Kernel::DebugWatchpointType::Read);
|
||||
success = debug_process->InsertWatchpoint(system.Kernel(), addr, size, Kernel::DebugWatchpointType::Read);
|
||||
break;
|
||||
case BreakpointType::AccessWatch:
|
||||
success = debug_process->InsertWatchpoint(addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||
success = debug_process->InsertWatchpoint(system.Kernel(), addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||
break;
|
||||
case BreakpointType::Hardware:
|
||||
default:
|
||||
|
|
@ -368,13 +368,13 @@ void GDBStub::HandleBreakpointRemove(std::string_view sv) {
|
|||
break;
|
||||
}
|
||||
case BreakpointType::WriteWatch:
|
||||
success = debug_process->RemoveWatchpoint(addr, size, Kernel::DebugWatchpointType::Write);
|
||||
success = debug_process->RemoveWatchpoint(system.Kernel(), addr, size, Kernel::DebugWatchpointType::Write);
|
||||
break;
|
||||
case BreakpointType::ReadWatch:
|
||||
success = debug_process->RemoveWatchpoint(addr, size, Kernel::DebugWatchpointType::Read);
|
||||
success = debug_process->RemoveWatchpoint(system.Kernel(), addr, size, Kernel::DebugWatchpointType::Read);
|
||||
break;
|
||||
case BreakpointType::AccessWatch:
|
||||
success = debug_process->RemoveWatchpoint(addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||
success = debug_process->RemoveWatchpoint(system.Kernel(), addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||
break;
|
||||
case BreakpointType::Hardware:
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -70,11 +70,11 @@ void GlobalSchedulerContext::UnregisterDummyThreadForWakeup(KThread* thread) noe
|
|||
}
|
||||
}
|
||||
|
||||
void GlobalSchedulerContext::WakeupWaitingDummyThreads() noexcept {
|
||||
void GlobalSchedulerContext::WakeupWaitingDummyThreads(KernelCore& kernel) noexcept {
|
||||
ASSERT(this->IsLocked());
|
||||
if (m_woken_dummy_threads.size() > 0) {
|
||||
for (auto* thread : m_woken_dummy_threads)
|
||||
thread->DummyThreadEndWait();
|
||||
thread->DummyThreadEndWait(kernel);
|
||||
m_woken_dummy_threads.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public:
|
|||
bool IsLocked() const noexcept;
|
||||
void UnregisterDummyThreadForWakeup(KThread* thread) noexcept;
|
||||
void RegisterDummyThreadForWakeup(KThread* thread) noexcept;
|
||||
void WakeupWaitingDummyThreads() noexcept;
|
||||
void WakeupWaitingDummyThreads(KernelCore& kernel) noexcept;
|
||||
|
||||
private:
|
||||
friend class KScopedSchedulerLock;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -281,7 +284,7 @@ void KPageBufferSlabHeap::Initialize(Core::System& system) {
|
|||
|
||||
// Reserve memory from the system resource limit.
|
||||
ASSERT(
|
||||
kernel.GetSystemResourceLimit()->Reserve(LimitableResource::PhysicalMemoryMax, slab_size));
|
||||
kernel.GetSystemResourceLimit()->Reserve(kernel, LimitableResource::PhysicalMemoryMax, slab_size));
|
||||
|
||||
// Allocate memory for the slab.
|
||||
constexpr auto AllocateOption = KMemoryManager::EncodeOption(
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -16,8 +19,9 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
KAddressArbiter::KAddressArbiter(Core::System& system)
|
||||
: m_system{system}, m_kernel{system.Kernel()} {}
|
||||
KAddressArbiter::KAddressArbiter(Core::System& system_)
|
||||
: system{system_}
|
||||
{}
|
||||
KAddressArbiter::~KAddressArbiter() = default;
|
||||
|
||||
namespace {
|
||||
|
|
@ -112,7 +116,7 @@ public:
|
|||
explicit ThreadQueueImplForKAddressArbiter(KernelCore& kernel, KAddressArbiter::ThreadTree* t)
|
||||
: KThreadQueue(kernel), m_tree(t) {}
|
||||
|
||||
void CancelWait(KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
void CancelWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
// If the thread is waiting on an address arbiter, remove it from the tree.
|
||||
if (waiting_thread->IsWaitingForAddressArbiter()) {
|
||||
m_tree->erase(m_tree->iterator_to(*waiting_thread));
|
||||
|
|
@ -120,7 +124,7 @@ public:
|
|||
}
|
||||
|
||||
// Invoke the base cancel wait handler.
|
||||
KThreadQueue::CancelWait(waiting_thread, wait_result, cancel_timer_task);
|
||||
KThreadQueue::CancelWait(kernel, waiting_thread, wait_result, cancel_timer_task);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -133,14 +137,14 @@ Result KAddressArbiter::Signal(uint64_t addr, s32 count) {
|
|||
// Perform signaling.
|
||||
s32 num_waiters{};
|
||||
{
|
||||
KScopedSchedulerLock sl(m_kernel);
|
||||
KScopedSchedulerLock sl(system.Kernel());
|
||||
|
||||
auto it = m_tree.nfind_key({addr, -1});
|
||||
while ((it != m_tree.end()) && (count <= 0 || num_waiters < count) &&
|
||||
(it->GetAddressArbiterKey() == addr)) {
|
||||
// End the thread's wait.
|
||||
KThread* target_thread = std::addressof(*it);
|
||||
target_thread->EndWait(ResultSuccess);
|
||||
target_thread->EndWait(system.Kernel(), ResultSuccess);
|
||||
|
||||
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
||||
target_thread->ClearAddressArbiter();
|
||||
|
|
@ -156,11 +160,11 @@ Result KAddressArbiter::SignalAndIncrementIfEqual(uint64_t addr, s32 value, s32
|
|||
// Perform signaling.
|
||||
s32 num_waiters{};
|
||||
{
|
||||
KScopedSchedulerLock sl(m_kernel);
|
||||
KScopedSchedulerLock sl(system.Kernel());
|
||||
|
||||
// Check the userspace value.
|
||||
s32 user_value{};
|
||||
R_UNLESS(UpdateIfEqual(m_kernel, std::addressof(user_value), addr, value, value + 1),
|
||||
R_UNLESS(UpdateIfEqual(system.Kernel(), std::addressof(user_value), addr, value, value + 1),
|
||||
ResultInvalidCurrentMemory);
|
||||
R_UNLESS(user_value == value, ResultInvalidState);
|
||||
|
||||
|
|
@ -169,7 +173,7 @@ Result KAddressArbiter::SignalAndIncrementIfEqual(uint64_t addr, s32 value, s32
|
|||
(it->GetAddressArbiterKey() == addr)) {
|
||||
// End the thread's wait.
|
||||
KThread* target_thread = std::addressof(*it);
|
||||
target_thread->EndWait(ResultSuccess);
|
||||
target_thread->EndWait(system.Kernel(), ResultSuccess);
|
||||
|
||||
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
||||
target_thread->ClearAddressArbiter();
|
||||
|
|
@ -185,7 +189,7 @@ Result KAddressArbiter::SignalAndModifyByWaitingCountIfEqual(uint64_t addr, s32
|
|||
// Perform signaling.
|
||||
s32 num_waiters{};
|
||||
{
|
||||
KScopedSchedulerLock sl(m_kernel);
|
||||
KScopedSchedulerLock sl(system.Kernel());
|
||||
|
||||
auto it = m_tree.nfind_key({addr, -1});
|
||||
// Determine the updated value.
|
||||
|
|
@ -220,9 +224,9 @@ Result KAddressArbiter::SignalAndModifyByWaitingCountIfEqual(uint64_t addr, s32
|
|||
s32 user_value{};
|
||||
bool succeeded{};
|
||||
if (value != new_value) {
|
||||
succeeded = UpdateIfEqual(m_kernel, std::addressof(user_value), addr, value, new_value);
|
||||
succeeded = UpdateIfEqual(system.Kernel(), std::addressof(user_value), addr, value, new_value);
|
||||
} else {
|
||||
succeeded = ReadFromUser(m_kernel, std::addressof(user_value), addr);
|
||||
succeeded = ReadFromUser(system.Kernel(), std::addressof(user_value), addr);
|
||||
}
|
||||
|
||||
R_UNLESS(succeeded, ResultInvalidCurrentMemory);
|
||||
|
|
@ -232,7 +236,7 @@ Result KAddressArbiter::SignalAndModifyByWaitingCountIfEqual(uint64_t addr, s32
|
|||
(it->GetAddressArbiterKey() == addr)) {
|
||||
// End the thread's wait.
|
||||
KThread* target_thread = std::addressof(*it);
|
||||
target_thread->EndWait(ResultSuccess);
|
||||
target_thread->EndWait(system.Kernel(), ResultSuccess);
|
||||
|
||||
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
||||
target_thread->ClearAddressArbiter();
|
||||
|
|
@ -246,12 +250,12 @@ Result KAddressArbiter::SignalAndModifyByWaitingCountIfEqual(uint64_t addr, s32
|
|||
|
||||
Result KAddressArbiter::WaitIfLessThan(uint64_t addr, s32 value, bool decrement, s64 timeout) {
|
||||
// Prepare to wait.
|
||||
KThread* cur_thread = GetCurrentThreadPointer(m_kernel);
|
||||
KThread* cur_thread = GetCurrentThreadPointer(system.Kernel());
|
||||
KHardwareTimer* timer{};
|
||||
ThreadQueueImplForKAddressArbiter wait_queue(m_kernel, std::addressof(m_tree));
|
||||
ThreadQueueImplForKAddressArbiter wait_queue(system.Kernel(), std::addressof(m_tree));
|
||||
|
||||
{
|
||||
KScopedSchedulerLockAndSleep slp{m_kernel, std::addressof(timer), cur_thread, timeout};
|
||||
KScopedSchedulerLockAndSleep slp{system.Kernel(), std::addressof(timer), cur_thread, timeout};
|
||||
|
||||
// Check that the thread isn't terminating.
|
||||
if (cur_thread->IsTerminationRequested()) {
|
||||
|
|
@ -263,9 +267,9 @@ Result KAddressArbiter::WaitIfLessThan(uint64_t addr, s32 value, bool decrement,
|
|||
s32 user_value{};
|
||||
bool succeeded{};
|
||||
if (decrement) {
|
||||
succeeded = DecrementIfLessThan(m_kernel, std::addressof(user_value), addr, value);
|
||||
succeeded = DecrementIfLessThan(system.Kernel(), std::addressof(user_value), addr, value);
|
||||
} else {
|
||||
succeeded = ReadFromUser(m_kernel, std::addressof(user_value), addr);
|
||||
succeeded = ReadFromUser(system.Kernel(), std::addressof(user_value), addr);
|
||||
}
|
||||
|
||||
if (!succeeded) {
|
||||
|
|
@ -291,7 +295,7 @@ Result KAddressArbiter::WaitIfLessThan(uint64_t addr, s32 value, bool decrement,
|
|||
|
||||
// Wait for the thread to finish.
|
||||
wait_queue.SetHardwareTimer(timer);
|
||||
cur_thread->BeginWait(std::addressof(wait_queue));
|
||||
cur_thread->BeginWait(system.Kernel(), std::addressof(wait_queue));
|
||||
cur_thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::Arbitration);
|
||||
}
|
||||
|
||||
|
|
@ -301,12 +305,12 @@ Result KAddressArbiter::WaitIfLessThan(uint64_t addr, s32 value, bool decrement,
|
|||
|
||||
Result KAddressArbiter::WaitIfEqual(uint64_t addr, s32 value, s64 timeout) {
|
||||
// Prepare to wait.
|
||||
KThread* cur_thread = GetCurrentThreadPointer(m_kernel);
|
||||
KThread* cur_thread = GetCurrentThreadPointer(system.Kernel());
|
||||
KHardwareTimer* timer{};
|
||||
ThreadQueueImplForKAddressArbiter wait_queue(m_kernel, std::addressof(m_tree));
|
||||
ThreadQueueImplForKAddressArbiter wait_queue(system.Kernel(), std::addressof(m_tree));
|
||||
|
||||
{
|
||||
KScopedSchedulerLockAndSleep slp{m_kernel, std::addressof(timer), cur_thread, timeout};
|
||||
KScopedSchedulerLockAndSleep slp{system.Kernel(), std::addressof(timer), cur_thread, timeout};
|
||||
|
||||
// Check that the thread isn't terminating.
|
||||
if (cur_thread->IsTerminationRequested()) {
|
||||
|
|
@ -316,7 +320,7 @@ Result KAddressArbiter::WaitIfEqual(uint64_t addr, s32 value, s64 timeout) {
|
|||
|
||||
// Read the value from userspace.
|
||||
s32 user_value{};
|
||||
if (!ReadFromUser(m_kernel, std::addressof(user_value), addr)) {
|
||||
if (!ReadFromUser(system.Kernel(), std::addressof(user_value), addr)) {
|
||||
slp.CancelSleep();
|
||||
R_THROW(ResultInvalidCurrentMemory);
|
||||
}
|
||||
|
|
@ -339,7 +343,7 @@ Result KAddressArbiter::WaitIfEqual(uint64_t addr, s32 value, s64 timeout) {
|
|||
|
||||
// Wait for the thread to finish.
|
||||
wait_queue.SetHardwareTimer(timer);
|
||||
cur_thread->BeginWait(std::addressof(wait_queue));
|
||||
cur_thread->BeginWait(system.Kernel(), std::addressof(wait_queue));
|
||||
cur_thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::Arbitration);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -60,8 +63,7 @@ private:
|
|||
|
||||
private:
|
||||
ThreadTree m_tree;
|
||||
Core::System& m_system;
|
||||
KernelCore& m_kernel;
|
||||
Core::System& system;
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
|
|
@ -15,8 +15,8 @@ KAutoObject* KAutoObject::Create(KAutoObject* obj) {
|
|||
return obj;
|
||||
}
|
||||
|
||||
void KAutoObject::RegisterWithKernel() {
|
||||
m_kernel.RegisterKernelObject(this);
|
||||
void KAutoObject::RegisterWithKernel(KernelCore& kernel) {
|
||||
kernel.RegisterKernelObject(this);
|
||||
}
|
||||
|
||||
void KAutoObject::UnregisterWithKernel(KernelCore& kernel, KAutoObject* self) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
|
|
@ -87,21 +87,21 @@ private:
|
|||
KERNEL_AUTOOBJECT_TRAITS_IMPL(KAutoObject, KAutoObject, const);
|
||||
|
||||
public:
|
||||
explicit KAutoObject(KernelCore& kernel) : m_kernel(kernel) {
|
||||
explicit KAutoObject(KernelCore& kernel) {
|
||||
m_class_token = GetStaticTypeObj().GetClassToken();
|
||||
RegisterWithKernel();
|
||||
RegisterWithKernel(kernel);
|
||||
}
|
||||
virtual ~KAutoObject() = default;
|
||||
|
||||
static KAutoObject* Create(KAutoObject* ptr);
|
||||
|
||||
// Destroy is responsible for destroying the auto object's resources when ref_count hits zero.
|
||||
virtual void Destroy() {
|
||||
virtual void Destroy(KernelCore& kernel) {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
// Finalize is responsible for cleaning up resource, but does not destroy the object.
|
||||
virtual void Finalize() {}
|
||||
virtual void Finalize(KernelCore& kernel) {}
|
||||
|
||||
virtual KProcess* GetOwner() const {
|
||||
return nullptr;
|
||||
|
|
@ -123,67 +123,50 @@ public:
|
|||
Derived DynamicCast() {
|
||||
static_assert(std::is_pointer_v<Derived>);
|
||||
using DerivedType = std::remove_pointer_t<Derived>;
|
||||
|
||||
if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj())) {
|
||||
return static_cast<Derived>(this);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj()))
|
||||
return Derived(this);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename Derived>
|
||||
const Derived DynamicCast() const {
|
||||
static_assert(std::is_pointer_v<Derived>);
|
||||
using DerivedType = std::remove_pointer_t<Derived>;
|
||||
|
||||
if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj())) {
|
||||
return static_cast<Derived>(this);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj()))
|
||||
return Derived(this);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Open() {
|
||||
bool Open(KernelCore& kernel) {
|
||||
// Atomically increment the reference count, only if it's positive.
|
||||
u32 cur_ref_count = m_ref_count.load(std::memory_order_acquire);
|
||||
do {
|
||||
if (cur_ref_count == 0) {
|
||||
if (cur_ref_count == 0)
|
||||
return false;
|
||||
}
|
||||
ASSERT(cur_ref_count < cur_ref_count + 1);
|
||||
} while (!m_ref_count.compare_exchange_weak(cur_ref_count, cur_ref_count + 1,
|
||||
std::memory_order_relaxed));
|
||||
|
||||
} while (!m_ref_count.compare_exchange_weak(cur_ref_count, cur_ref_count + 1, std::memory_order_relaxed));
|
||||
return true;
|
||||
}
|
||||
|
||||
void Close() {
|
||||
void Close(KernelCore& kernel) {
|
||||
// Atomically decrement the reference count, not allowing it to become negative.
|
||||
u32 cur_ref_count = m_ref_count.load(std::memory_order_acquire);
|
||||
do {
|
||||
if (cur_ref_count == 0) {
|
||||
if (cur_ref_count == 0)
|
||||
return;
|
||||
}
|
||||
ASSERT(cur_ref_count > 0);
|
||||
} while (!m_ref_count.compare_exchange_weak(cur_ref_count, cur_ref_count - 1,
|
||||
std::memory_order_acq_rel));
|
||||
|
||||
} while (!m_ref_count.compare_exchange_weak(cur_ref_count, cur_ref_count - 1, std::memory_order_acq_rel));
|
||||
// If ref count hits 1, destroy the object.
|
||||
if (cur_ref_count == 1) {
|
||||
KernelCore& kernel = m_kernel;
|
||||
this->Destroy();
|
||||
this->Destroy(kernel);
|
||||
KAutoObject::UnregisterWithKernel(kernel, this);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void RegisterWithKernel();
|
||||
void RegisterWithKernel(KernelCore& kernel);
|
||||
static void UnregisterWithKernel(KernelCore& kernel, KAutoObject* self);
|
||||
|
||||
protected:
|
||||
KernelCore& m_kernel;
|
||||
|
||||
private:
|
||||
std::atomic<u32> m_ref_count{};
|
||||
ClassTokenType m_class_token{};
|
||||
};
|
||||
|
|
@ -225,17 +208,22 @@ class KScopedAutoObject {
|
|||
public:
|
||||
YUZU_NON_COPYABLE(KScopedAutoObject);
|
||||
|
||||
constexpr KScopedAutoObject() = default;
|
||||
constexpr KScopedAutoObject(KernelCore& kernel_)
|
||||
: kernel{kernel_}
|
||||
{}
|
||||
|
||||
constexpr KScopedAutoObject(T* o) : m_obj(o) {
|
||||
constexpr KScopedAutoObject(KernelCore& kernel_, T* o)
|
||||
: kernel{kernel_}
|
||||
, m_obj(o)
|
||||
{
|
||||
if (m_obj != nullptr) {
|
||||
m_obj->Open();
|
||||
m_obj->Open(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
~KScopedAutoObject() {
|
||||
if (m_obj != nullptr) {
|
||||
m_obj->Close();
|
||||
m_obj->Close(kernel);
|
||||
}
|
||||
m_obj = nullptr;
|
||||
}
|
||||
|
|
@ -253,7 +241,7 @@ public:
|
|||
if (rhs.m_obj != nullptr) {
|
||||
derived = rhs.m_obj->template DynamicCast<T*>();
|
||||
if (derived == nullptr) {
|
||||
rhs.m_obj->Close();
|
||||
rhs.m_obj->Close(rhs.kernel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -274,8 +262,16 @@ public:
|
|||
return *m_obj;
|
||||
}
|
||||
|
||||
constexpr void SetObject(T* o) {
|
||||
if (m_obj)
|
||||
m_obj->Close(kernel);
|
||||
m_obj = o;
|
||||
if (m_obj)
|
||||
m_obj->Open(kernel);
|
||||
}
|
||||
|
||||
constexpr void Reset(T* o) {
|
||||
KScopedAutoObject(o).Swap(*this);
|
||||
KScopedAutoObject(kernel, o).Swap(*this);
|
||||
}
|
||||
|
||||
constexpr T* GetPointerUnsafe() {
|
||||
|
|
@ -304,6 +300,7 @@ private:
|
|||
friend class KScopedAutoObject;
|
||||
|
||||
private:
|
||||
KernelCore& kernel;
|
||||
T* m_obj{};
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2021 Citra Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -15,7 +18,7 @@ namespace Kernel {
|
|||
KClientPort::KClientPort(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
||||
KClientPort::~KClientPort() = default;
|
||||
|
||||
void KClientPort::Initialize(KPort* parent, s32 max_sessions) {
|
||||
void KClientPort::Initialize(KernelCore& kernel, KPort* parent, s32 max_sessions) {
|
||||
// Set member variables.
|
||||
m_num_sessions = 0;
|
||||
m_peak_sessions = 0;
|
||||
|
|
@ -23,48 +26,48 @@ void KClientPort::Initialize(KPort* parent, s32 max_sessions) {
|
|||
m_max_sessions = max_sessions;
|
||||
}
|
||||
|
||||
void KClientPort::OnSessionFinalized() {
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
void KClientPort::OnSessionFinalized(KernelCore& kernel) {
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
if (const auto prev = m_num_sessions--; prev == m_max_sessions) {
|
||||
this->NotifyAvailable();
|
||||
this->NotifyAvailable(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
void KClientPort::OnServerClosed() {}
|
||||
void KClientPort::OnServerClosed(KernelCore& kernel) {}
|
||||
|
||||
bool KClientPort::IsLight() const {
|
||||
bool KClientPort::IsLight(KernelCore& kernel) const {
|
||||
return this->GetParent()->IsLight();
|
||||
}
|
||||
|
||||
bool KClientPort::IsServerClosed() const {
|
||||
return this->GetParent()->IsServerClosed();
|
||||
bool KClientPort::IsServerClosed(KernelCore& kernel) const {
|
||||
return this->GetParent()->IsServerClosed(kernel);
|
||||
}
|
||||
|
||||
void KClientPort::Destroy() {
|
||||
void KClientPort::Destroy(KernelCore& kernel) {
|
||||
// Note with our parent that we're closed.
|
||||
m_parent->OnClientClosed();
|
||||
m_parent->OnClientClosed(kernel);
|
||||
|
||||
// Close our reference to our parent.
|
||||
m_parent->Close();
|
||||
m_parent->Close(kernel);
|
||||
}
|
||||
|
||||
bool KClientPort::IsSignaled() const {
|
||||
bool KClientPort::IsSignaled(KernelCore& kernel) const {
|
||||
return m_num_sessions.load() < m_max_sessions;
|
||||
}
|
||||
|
||||
Result KClientPort::CreateSession(KClientSession** out) {
|
||||
Result KClientPort::CreateSession(KernelCore& kernel, KClientSession** out) {
|
||||
// Declare the session we're going to allocate.
|
||||
KSession* session{};
|
||||
|
||||
// Reserve a new session from the resource limit.
|
||||
KScopedResourceReservation session_reservation(GetCurrentProcessPointer(m_kernel),
|
||||
KScopedResourceReservation session_reservation(kernel, GetCurrentProcessPointer(kernel),
|
||||
LimitableResource::SessionCountMax);
|
||||
R_UNLESS(session_reservation.Succeeded(), ResultLimitReached);
|
||||
|
||||
// Allocate a session normally.
|
||||
// TODO: Dynamic resource limits
|
||||
session = KSession::Create(m_kernel);
|
||||
session = KSession::Create(kernel);
|
||||
|
||||
// Check that we successfully created a session.
|
||||
R_UNLESS(session != nullptr, ResultOutOfResource);
|
||||
|
|
@ -72,7 +75,7 @@ Result KClientPort::CreateSession(KClientSession** out) {
|
|||
// Update the session counts.
|
||||
{
|
||||
ON_RESULT_FAILURE {
|
||||
session->Close();
|
||||
session->Close(kernel);
|
||||
};
|
||||
|
||||
// Atomically increment the number of sessions.
|
||||
|
|
@ -100,38 +103,37 @@ Result KClientPort::CreateSession(KClientSession** out) {
|
|||
}
|
||||
|
||||
// Initialize the session.
|
||||
session->Initialize(this, m_parent->GetName());
|
||||
session->Initialize(kernel, this, m_parent->GetName());
|
||||
|
||||
// Commit the session reservation.
|
||||
session_reservation.Commit();
|
||||
|
||||
// Register the session.
|
||||
KSession::Register(m_kernel, session);
|
||||
KSession::Register(kernel, session);
|
||||
ON_RESULT_FAILURE {
|
||||
session->GetClientSession().Close();
|
||||
session->GetServerSession().Close();
|
||||
session->GetClientSession().Close(kernel);
|
||||
session->GetServerSession().Close(kernel);
|
||||
};
|
||||
|
||||
// Enqueue the session with our parent.
|
||||
R_TRY(m_parent->EnqueueSession(std::addressof(session->GetServerSession())));
|
||||
R_TRY(m_parent->EnqueueSession(kernel, std::addressof(session->GetServerSession())));
|
||||
|
||||
// We succeeded, so set the output.
|
||||
*out = std::addressof(session->GetClientSession());
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result KClientPort::CreateLightSession(KLightClientSession** out) {
|
||||
Result KClientPort::CreateLightSession(KernelCore& kernel, KLightClientSession** out) {
|
||||
// Declare the session we're going to allocate.
|
||||
KLightSession* session{};
|
||||
|
||||
// Reserve a new session from the resource limit.
|
||||
KScopedResourceReservation session_reservation(GetCurrentProcessPointer(m_kernel),
|
||||
Svc::LimitableResource::SessionCountMax);
|
||||
KScopedResourceReservation session_reservation(kernel, GetCurrentProcessPointer(kernel), Svc::LimitableResource::SessionCountMax);
|
||||
R_UNLESS(session_reservation.Succeeded(), ResultLimitReached);
|
||||
|
||||
// Allocate a session normally.
|
||||
// TODO: Dynamic resource limits
|
||||
session = KLightSession::Create(m_kernel);
|
||||
session = KLightSession::Create(kernel);
|
||||
|
||||
// Check that we successfully created a session.
|
||||
R_UNLESS(session != nullptr, ResultOutOfResource);
|
||||
|
|
@ -139,7 +141,7 @@ Result KClientPort::CreateLightSession(KLightClientSession** out) {
|
|||
// Update the session counts.
|
||||
{
|
||||
ON_RESULT_FAILURE {
|
||||
session->Close();
|
||||
session->Close(kernel);
|
||||
};
|
||||
|
||||
// Atomically increment the number of sessions.
|
||||
|
|
@ -167,20 +169,20 @@ Result KClientPort::CreateLightSession(KLightClientSession** out) {
|
|||
}
|
||||
|
||||
// Initialize the session.
|
||||
session->Initialize(this, m_parent->GetName());
|
||||
session->Initialize(kernel, this, m_parent->GetName());
|
||||
|
||||
// Commit the session reservation.
|
||||
session_reservation.Commit();
|
||||
|
||||
// Register the session.
|
||||
KLightSession::Register(m_kernel, session);
|
||||
KLightSession::Register(kernel, session);
|
||||
ON_RESULT_FAILURE {
|
||||
session->GetClientSession().Close();
|
||||
session->GetServerSession().Close();
|
||||
session->GetClientSession().Close(kernel);
|
||||
session->GetServerSession().Close(kernel);
|
||||
};
|
||||
|
||||
// Enqueue the session with our parent.
|
||||
R_TRY(m_parent->EnqueueSession(std::addressof(session->GetServerSession())));
|
||||
R_TRY(m_parent->EnqueueSession(kernel, std::addressof(session->GetServerSession())));
|
||||
|
||||
// We succeeded, so set the output.
|
||||
*out = std::addressof(session->GetClientSession());
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -23,9 +26,9 @@ public:
|
|||
explicit KClientPort(KernelCore& kernel);
|
||||
~KClientPort() override;
|
||||
|
||||
void Initialize(KPort* parent, s32 max_sessions);
|
||||
void OnSessionFinalized();
|
||||
void OnServerClosed();
|
||||
void Initialize(KernelCore& kernel, KPort* parent, s32 max_sessions);
|
||||
void OnSessionFinalized(KernelCore& kernel);
|
||||
void OnServerClosed(KernelCore& kernel);
|
||||
|
||||
const KPort* GetParent() const {
|
||||
return m_parent;
|
||||
|
|
@ -44,15 +47,15 @@ public:
|
|||
return m_max_sessions;
|
||||
}
|
||||
|
||||
bool IsLight() const;
|
||||
bool IsServerClosed() const;
|
||||
bool IsLight(KernelCore& kernel) const;
|
||||
bool IsServerClosed(KernelCore& kernel) const;
|
||||
|
||||
// Overridden virtual functions.
|
||||
void Destroy() override;
|
||||
bool IsSignaled() const override;
|
||||
void Destroy(KernelCore& kernel) override;
|
||||
bool IsSignaled(KernelCore& kernel) const override;
|
||||
|
||||
Result CreateSession(KClientSession** out);
|
||||
Result CreateLightSession(KLightClientSession** out);
|
||||
Result CreateSession(KernelCore& kernel, KClientSession** out);
|
||||
Result CreateLightSession(KernelCore& kernel, KLightClientSession** out);
|
||||
|
||||
private:
|
||||
std::atomic<s32> m_num_sessions{};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -13,41 +16,41 @@ namespace Kernel {
|
|||
KClientSession::KClientSession(KernelCore& kernel) : KAutoObject{kernel} {}
|
||||
KClientSession::~KClientSession() = default;
|
||||
|
||||
void KClientSession::Destroy() {
|
||||
m_parent->OnClientClosed();
|
||||
m_parent->Close();
|
||||
void KClientSession::Destroy(KernelCore& kernel) {
|
||||
m_parent->OnClientClosed(kernel);
|
||||
m_parent->Close(kernel);
|
||||
}
|
||||
|
||||
void KClientSession::OnServerClosed() {}
|
||||
|
||||
Result KClientSession::SendSyncRequest(uintptr_t address, size_t size) {
|
||||
Result KClientSession::SendSyncRequest(KernelCore& kernel, uintptr_t address, size_t size) {
|
||||
// Create a session request.
|
||||
KSessionRequest* request = KSessionRequest::Create(m_kernel);
|
||||
KSessionRequest* request = KSessionRequest::Create(kernel);
|
||||
R_UNLESS(request != nullptr, ResultOutOfResource);
|
||||
SCOPE_EXIT {
|
||||
request->Close();
|
||||
request->Close(kernel);
|
||||
};
|
||||
|
||||
// Initialize the request.
|
||||
request->Initialize(nullptr, address, size);
|
||||
request->Initialize(kernel, nullptr, address, size);
|
||||
|
||||
// Send the request.
|
||||
R_RETURN(m_parent->OnRequest(request));
|
||||
R_RETURN(m_parent->OnRequest(kernel, request));
|
||||
}
|
||||
|
||||
Result KClientSession::SendAsyncRequest(KEvent* event, uintptr_t address, size_t size) {
|
||||
Result KClientSession::SendAsyncRequest(KernelCore& kernel, KEvent* event, uintptr_t address, size_t size) {
|
||||
// Create a session request.
|
||||
KSessionRequest* request = KSessionRequest::Create(m_kernel);
|
||||
KSessionRequest* request = KSessionRequest::Create(kernel);
|
||||
R_UNLESS(request != nullptr, ResultOutOfResource);
|
||||
SCOPE_EXIT {
|
||||
request->Close();
|
||||
request->Close(kernel);
|
||||
};
|
||||
|
||||
// Initialize the request.
|
||||
request->Initialize(event, address, size);
|
||||
request->Initialize(kernel, event, address, size);
|
||||
|
||||
// Send the request.
|
||||
R_RETURN(m_parent->OnRequest(request));
|
||||
R_RETURN(m_parent->OnRequest(kernel, request));
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -26,14 +29,14 @@ public:
|
|||
m_parent = parent;
|
||||
}
|
||||
|
||||
void Destroy() override;
|
||||
void Destroy(KernelCore& kernel) override;
|
||||
|
||||
KSession* GetParent() const {
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
Result SendSyncRequest(uintptr_t address, size_t size);
|
||||
Result SendAsyncRequest(KEvent* event, uintptr_t address, size_t size);
|
||||
Result SendSyncRequest(KernelCore& kernel, uintptr_t address, size_t size);
|
||||
Result SendAsyncRequest(KernelCore& kernel, KEvent* event, uintptr_t address, size_t size);
|
||||
|
||||
void OnServerClosed();
|
||||
|
||||
|
|
|
|||
|
|
@ -22,16 +22,15 @@ namespace Kernel {
|
|||
KCodeMemory::KCodeMemory(KernelCore& kernel)
|
||||
: KAutoObjectWithSlabHeapAndContainer{kernel}, m_lock(kernel) {}
|
||||
|
||||
Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, KProcessAddress addr,
|
||||
size_t size) {
|
||||
Result KCodeMemory::Initialize(KernelCore& kernel, Core::DeviceMemory& device_memory, KProcessAddress addr, size_t size) {
|
||||
// Set members.
|
||||
m_owner = GetCurrentProcessPointer(m_kernel);
|
||||
m_owner = GetCurrentProcessPointer(kernel);
|
||||
|
||||
// Get the owner page table.
|
||||
auto& page_table = m_owner->GetPageTable();
|
||||
|
||||
// Construct the page group.
|
||||
m_page_group.emplace(m_kernel, page_table.GetBlockInfoManager());
|
||||
m_page_group.emplace(kernel, page_table.GetBlockInfoManager());
|
||||
|
||||
// Lock the memory.
|
||||
R_TRY(page_table.LockForCodeMemory(std::addressof(*m_page_group), addr, size))
|
||||
|
|
@ -42,7 +41,7 @@ Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, KProcessAddres
|
|||
}
|
||||
|
||||
// Set remaining tracking members.
|
||||
m_owner->Open();
|
||||
m_owner->Open(kernel);
|
||||
m_address = addr;
|
||||
m_is_initialized = true;
|
||||
m_is_owner_mapped = false;
|
||||
|
|
@ -52,7 +51,7 @@ Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, KProcessAddres
|
|||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void KCodeMemory::Finalize() {
|
||||
void KCodeMemory::Finalize(KernelCore& kernel) {
|
||||
// Unlock.
|
||||
if (!m_is_mapped && !m_is_owner_mapped) {
|
||||
const size_t size = m_page_group->GetNumPages() * PageSize;
|
||||
|
|
@ -60,14 +59,14 @@ void KCodeMemory::Finalize() {
|
|||
}
|
||||
|
||||
// Close the page group.
|
||||
m_page_group->Close(m_kernel);
|
||||
m_page_group->Close(kernel);
|
||||
m_page_group->Finalize();
|
||||
|
||||
// Close our reference to our owner.
|
||||
m_owner->Close();
|
||||
m_owner->Close(kernel);
|
||||
}
|
||||
|
||||
Result KCodeMemory::Map(KProcessAddress address, size_t size) {
|
||||
Result KCodeMemory::Map(KernelCore& kernel, KProcessAddress address, size_t size) {
|
||||
// Validate the size.
|
||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
|
||||
|
|
@ -78,7 +77,7 @@ Result KCodeMemory::Map(KProcessAddress address, size_t size) {
|
|||
R_UNLESS(!m_is_mapped, ResultInvalidState);
|
||||
|
||||
// Map the memory.
|
||||
R_TRY(GetCurrentProcess(m_kernel).GetPageTable().MapPageGroup(
|
||||
R_TRY(GetCurrentProcess(kernel).GetPageTable().MapPageGroup(
|
||||
address, *m_page_group, KMemoryState::CodeOut, KMemoryPermission::UserReadWrite));
|
||||
|
||||
// Mark ourselves as mapped.
|
||||
|
|
@ -87,7 +86,7 @@ Result KCodeMemory::Map(KProcessAddress address, size_t size) {
|
|||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result KCodeMemory::Unmap(KProcessAddress address, size_t size) {
|
||||
Result KCodeMemory::Unmap(KernelCore& kernel, KProcessAddress address, size_t size) {
|
||||
// Validate the size.
|
||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
|
||||
|
|
@ -95,7 +94,7 @@ Result KCodeMemory::Unmap(KProcessAddress address, size_t size) {
|
|||
KScopedLightLock lk(m_lock);
|
||||
|
||||
// Unmap the memory.
|
||||
R_TRY(GetCurrentProcess(m_kernel).GetPageTable().UnmapPageGroup(address, *m_page_group,
|
||||
R_TRY(GetCurrentProcess(kernel).GetPageTable().UnmapPageGroup(address, *m_page_group,
|
||||
KMemoryState::CodeOut));
|
||||
|
||||
// Mark ourselves as unmapped.
|
||||
|
|
@ -104,7 +103,7 @@ Result KCodeMemory::Unmap(KProcessAddress address, size_t size) {
|
|||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result KCodeMemory::MapToOwner(KProcessAddress address, size_t size, Svc::MemoryPermission perm) {
|
||||
Result KCodeMemory::MapToOwner(KernelCore& kernel, KProcessAddress address, size_t size, Svc::MemoryPermission perm) {
|
||||
// Validate the size.
|
||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
|
||||
|
|
@ -138,7 +137,7 @@ Result KCodeMemory::MapToOwner(KProcessAddress address, size_t size, Svc::Memory
|
|||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result KCodeMemory::UnmapFromOwner(KProcessAddress address, size_t size) {
|
||||
Result KCodeMemory::UnmapFromOwner(KernelCore& kernel, KProcessAddress address, size_t size) {
|
||||
// Validate the size.
|
||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -31,18 +34,18 @@ class KCodeMemory final
|
|||
public:
|
||||
explicit KCodeMemory(KernelCore& kernel);
|
||||
|
||||
Result Initialize(Core::DeviceMemory& device_memory, KProcessAddress address, size_t size);
|
||||
void Finalize() override;
|
||||
Result Initialize(KernelCore& kernel, Core::DeviceMemory& device_memory, KProcessAddress address, size_t size);
|
||||
void Finalize(KernelCore& kernel) override;
|
||||
|
||||
Result Map(KProcessAddress address, size_t size);
|
||||
Result Unmap(KProcessAddress address, size_t size);
|
||||
Result MapToOwner(KProcessAddress address, size_t size, Svc::MemoryPermission perm);
|
||||
Result UnmapFromOwner(KProcessAddress address, size_t size);
|
||||
Result Map(KernelCore& kernel, KProcessAddress address, size_t size);
|
||||
Result Unmap(KernelCore& kernel, KProcessAddress address, size_t size);
|
||||
Result MapToOwner(KernelCore& kernel, KProcessAddress address, size_t size, Svc::MemoryPermission perm);
|
||||
Result UnmapFromOwner(KernelCore& kernel, KProcessAddress address, size_t size);
|
||||
|
||||
bool IsInitialized() const override {
|
||||
return m_is_initialized;
|
||||
}
|
||||
static void PostDestroy(uintptr_t arg) {}
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}
|
||||
|
||||
KProcess* GetOwner() const override {
|
||||
return m_owner;
|
||||
|
|
|
|||
|
|
@ -66,14 +66,15 @@ bool UpdateLockAtomic(KernelCore& kernel, u32* out, KProcessAddress address, u32
|
|||
class ThreadQueueImplForKConditionVariableWaitForAddress final : public KThreadQueue {
|
||||
public:
|
||||
explicit ThreadQueueImplForKConditionVariableWaitForAddress(KernelCore& kernel)
|
||||
: KThreadQueue(kernel) {}
|
||||
: KThreadQueue(kernel)
|
||||
{}
|
||||
|
||||
void CancelWait(KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
virtual void CancelWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
// Remove the thread as a waiter from its owner.
|
||||
waiting_thread->GetLockOwner()->RemoveWaiter(waiting_thread);
|
||||
waiting_thread->GetLockOwner(kernel)->RemoveWaiter(kernel, waiting_thread);
|
||||
|
||||
// Invoke the base cancel wait handler.
|
||||
KThreadQueue::CancelWait(waiting_thread, wait_result, cancel_timer_task);
|
||||
KThreadQueue::CancelWait(kernel, waiting_thread, wait_result, cancel_timer_task);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -82,14 +83,15 @@ private:
|
|||
KConditionVariable::ThreadTree* m_tree;
|
||||
|
||||
public:
|
||||
explicit ThreadQueueImplForKConditionVariableWaitConditionVariable(
|
||||
KernelCore& kernel, KConditionVariable::ThreadTree* t)
|
||||
: KThreadQueue(kernel), m_tree(t) {}
|
||||
explicit ThreadQueueImplForKConditionVariableWaitConditionVariable(KernelCore& kernel, KConditionVariable::ThreadTree* t)
|
||||
: KThreadQueue(kernel)
|
||||
, m_tree(t)
|
||||
{}
|
||||
|
||||
void CancelWait(KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
void CancelWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
// Remove the thread as a waiter from its owner.
|
||||
if (KThread* owner = waiting_thread->GetLockOwner(); owner != nullptr) {
|
||||
owner->RemoveWaiter(waiting_thread);
|
||||
if (KThread* owner = waiting_thread->GetLockOwner(kernel); owner != nullptr) {
|
||||
owner->RemoveWaiter(kernel, waiting_thread);
|
||||
}
|
||||
|
||||
// If the thread is waiting on a condvar, remove it from the tree.
|
||||
|
|
@ -99,7 +101,7 @@ public:
|
|||
}
|
||||
|
||||
// Invoke the base cancel wait handler.
|
||||
KThreadQueue::CancelWait(waiting_thread, wait_result, cancel_timer_task);
|
||||
KThreadQueue::CancelWait(kernel, waiting_thread, wait_result, cancel_timer_task);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -120,8 +122,7 @@ Result KConditionVariable::SignalToAddress(KernelCore& kernel, KProcessAddress a
|
|||
|
||||
// Remove waiter thread.
|
||||
bool has_waiters{};
|
||||
KThread* const next_owner_thread =
|
||||
owner_thread->RemoveUserWaiterByKey(std::addressof(has_waiters), addr);
|
||||
KThread* const next_owner_thread = owner_thread->RemoveUserWaiterByKey(kernel, std::addressof(has_waiters), addr);
|
||||
|
||||
// Determine the next tag.
|
||||
u32 next_value{};
|
||||
|
|
@ -145,15 +146,14 @@ Result KConditionVariable::SignalToAddress(KernelCore& kernel, KProcessAddress a
|
|||
|
||||
// If necessary, signal the next owner thread.
|
||||
if (next_owner_thread != nullptr) {
|
||||
next_owner_thread->EndWait(result);
|
||||
next_owner_thread->EndWait(kernel, result);
|
||||
}
|
||||
|
||||
R_RETURN(result);
|
||||
}
|
||||
}
|
||||
|
||||
Result KConditionVariable::WaitForAddress(KernelCore& kernel, Handle handle, KProcessAddress addr,
|
||||
u32 value) {
|
||||
Result KConditionVariable::WaitForAddress(KernelCore& kernel, Handle handle, KProcessAddress addr, u32 value) {
|
||||
KThread* cur_thread = GetCurrentThreadPointer(kernel);
|
||||
ThreadQueueImplForKConditionVariableWaitForAddress wait_queue(kernel);
|
||||
|
||||
|
|
@ -181,15 +181,15 @@ Result KConditionVariable::WaitForAddress(KernelCore& kernel, Handle handle, KPr
|
|||
|
||||
// Update the lock.
|
||||
cur_thread->SetUserAddressKey(addr, value);
|
||||
owner_thread->AddWaiter(cur_thread);
|
||||
owner_thread->AddWaiter(kernel, cur_thread);
|
||||
|
||||
// Begin waiting.
|
||||
cur_thread->BeginWait(std::addressof(wait_queue));
|
||||
cur_thread->BeginWait(kernel, std::addressof(wait_queue));
|
||||
cur_thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::ConditionVar);
|
||||
}
|
||||
|
||||
// Close our reference to the owner thread, now that the wait is over.
|
||||
owner_thread->Close();
|
||||
owner_thread->Close(kernel);
|
||||
|
||||
// Get the wait result.
|
||||
R_RETURN(cur_thread->GetWaitResult());
|
||||
|
|
@ -219,7 +219,7 @@ void KConditionVariable::SignalImpl(KernelCore& kernel, KThread* thread) {
|
|||
if (can_access) {
|
||||
if (prev_tag == Svc::InvalidHandle) {
|
||||
// If nobody held the lock previously, we're all good.
|
||||
thread->EndWait(ResultSuccess);
|
||||
thread->EndWait(kernel, ResultSuccess);
|
||||
} else {
|
||||
// Get the previous owner.
|
||||
KThread* owner_thread = GetCurrentProcess(kernel)
|
||||
|
|
@ -229,16 +229,16 @@ void KConditionVariable::SignalImpl(KernelCore& kernel, KThread* thread) {
|
|||
|
||||
if (owner_thread) {
|
||||
// Add the thread as a waiter on the owner.
|
||||
owner_thread->AddWaiter(thread);
|
||||
owner_thread->Close();
|
||||
owner_thread->AddWaiter(kernel, thread);
|
||||
owner_thread->Close(kernel);
|
||||
} else {
|
||||
// The lock was tagged with a thread that doesn't exist.
|
||||
thread->EndWait(ResultInvalidState);
|
||||
thread->EndWait(kernel, ResultInvalidState);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If the address wasn't accessible, note so.
|
||||
thread->EndWait(ResultInvalidCurrentMemory);
|
||||
thread->EndWait(kernel, ResultInvalidCurrentMemory);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -289,7 +289,7 @@ Result KConditionVariable::Wait(KProcessAddress addr, u64 key, u32 value, s64 ti
|
|||
// Remove waiter thread.
|
||||
bool has_waiters{};
|
||||
KThread* next_owner_thread =
|
||||
cur_thread->RemoveUserWaiterByKey(std::addressof(has_waiters), addr);
|
||||
cur_thread->RemoveUserWaiterByKey(m_system.Kernel(), std::addressof(has_waiters), addr);
|
||||
|
||||
// Update for the next owner thread.
|
||||
u32 next_value{};
|
||||
|
|
@ -301,7 +301,7 @@ Result KConditionVariable::Wait(KProcessAddress addr, u64 key, u32 value, s64 ti
|
|||
}
|
||||
|
||||
// Wake up the next owner.
|
||||
next_owner_thread->EndWait(ResultSuccess);
|
||||
next_owner_thread->EndWait(m_system.Kernel(), ResultSuccess);
|
||||
}
|
||||
|
||||
// Write to the cv key.
|
||||
|
|
@ -327,7 +327,7 @@ Result KConditionVariable::Wait(KProcessAddress addr, u64 key, u32 value, s64 ti
|
|||
|
||||
// Begin waiting.
|
||||
wait_queue.SetHardwareTimer(timer);
|
||||
cur_thread->BeginWait(std::addressof(wait_queue));
|
||||
cur_thread->BeginWait(m_system.Kernel(), std::addressof(wait_queue));
|
||||
cur_thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::ConditionVar);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -14,7 +17,7 @@ class KDebug final : public KAutoObjectWithSlabHeapAndContainer<KDebug, KAutoObj
|
|||
public:
|
||||
explicit KDebug(KernelCore& kernel) : KAutoObjectWithSlabHeapAndContainer{kernel} {}
|
||||
|
||||
static void PostDestroy(uintptr_t arg) {}
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -13,13 +16,13 @@ KDeviceAddressSpace::KDeviceAddressSpace(KernelCore& kernel)
|
|||
: KAutoObjectWithSlabHeapAndContainer(kernel), m_lock(kernel), m_is_initialized(false) {}
|
||||
KDeviceAddressSpace::~KDeviceAddressSpace() = default;
|
||||
|
||||
void KDeviceAddressSpace::Initialize() {
|
||||
void KDeviceAddressSpace::Initialize(KernelCore& kernel) {
|
||||
// This just forwards to the device page table manager.
|
||||
// KDevicePageTable::Initialize();
|
||||
}
|
||||
|
||||
// Member functions.
|
||||
Result KDeviceAddressSpace::Initialize(u64 address, u64 size) {
|
||||
Result KDeviceAddressSpace::Initialize(KernelCore& kernel, u64 address, u64 size) {
|
||||
// Initialize the device page table.
|
||||
// R_TRY(m_table.Initialize(address, size));
|
||||
|
||||
|
|
@ -31,7 +34,7 @@ Result KDeviceAddressSpace::Initialize(u64 address, u64 size) {
|
|||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void KDeviceAddressSpace::Finalize() {
|
||||
void KDeviceAddressSpace::Finalize(KernelCore& kernel) {
|
||||
// Finalize the table.
|
||||
// m_table.Finalize();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -20,13 +23,13 @@ public:
|
|||
explicit KDeviceAddressSpace(KernelCore& kernel);
|
||||
~KDeviceAddressSpace();
|
||||
|
||||
Result Initialize(u64 address, u64 size);
|
||||
void Finalize() override;
|
||||
Result Initialize(KernelCore& kernel, u64 address, u64 size);
|
||||
void Finalize(KernelCore& kernel) override;
|
||||
|
||||
bool IsInitialized() const override {
|
||||
return m_is_initialized;
|
||||
}
|
||||
static void PostDestroy(uintptr_t arg) {}
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}
|
||||
|
||||
Result Attach(Svc::DeviceName device_name);
|
||||
Result Detach(Svc::DeviceName device_name);
|
||||
|
|
@ -44,7 +47,7 @@ public:
|
|||
Result Unmap(KProcessPageTable* page_table, KProcessAddress process_address, size_t size,
|
||||
u64 device_address);
|
||||
|
||||
static void Initialize();
|
||||
static void Initialize(KernelCore& kernel);
|
||||
|
||||
private:
|
||||
Result Map(KProcessPageTable* page_table, KProcessAddress process_address, size_t size,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -8,56 +11,58 @@
|
|||
namespace Kernel {
|
||||
|
||||
KEvent::KEvent(KernelCore& kernel)
|
||||
: KAutoObjectWithSlabHeapAndContainer{kernel}, m_readable_event{kernel} {}
|
||||
: KAutoObjectWithSlabHeapAndContainer{kernel}
|
||||
, m_readable_event{kernel}
|
||||
{}
|
||||
|
||||
KEvent::~KEvent() = default;
|
||||
|
||||
void KEvent::Initialize(KProcess* owner) {
|
||||
void KEvent::Initialize(KernelCore& kernel, KProcess* owner) {
|
||||
// Create our readable event.
|
||||
KAutoObject::Create(std::addressof(m_readable_event));
|
||||
|
||||
// Initialize our readable event.
|
||||
m_readable_event.Initialize(this);
|
||||
m_readable_event.Initialize(kernel, this);
|
||||
|
||||
// Set our owner process.
|
||||
// HACK: this should never be nullptr, but service threads don't have a
|
||||
// proper parent process yet.
|
||||
if (owner != nullptr) {
|
||||
m_owner = owner;
|
||||
m_owner->Open();
|
||||
m_owner->Open(kernel);
|
||||
}
|
||||
|
||||
// Mark initialized.
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
void KEvent::Finalize() {
|
||||
KAutoObjectWithSlabHeapAndContainer<KEvent, KAutoObjectWithList>::Finalize();
|
||||
void KEvent::Finalize(KernelCore& kernel) {
|
||||
KAutoObjectWithSlabHeapAndContainer<KEvent, KAutoObjectWithList>::Finalize(kernel);
|
||||
}
|
||||
|
||||
Result KEvent::Signal() {
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
Result KEvent::Signal(KernelCore& kernel) {
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
R_SUCCEED_IF(m_readable_event_destroyed);
|
||||
|
||||
return m_readable_event.Signal();
|
||||
return m_readable_event.Signal(kernel);
|
||||
}
|
||||
|
||||
Result KEvent::Clear() {
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
Result KEvent::Clear(KernelCore& kernel) {
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
R_SUCCEED_IF(m_readable_event_destroyed);
|
||||
|
||||
return m_readable_event.Clear();
|
||||
return m_readable_event.Clear(kernel);
|
||||
}
|
||||
|
||||
void KEvent::PostDestroy(uintptr_t arg) {
|
||||
void KEvent::PostDestroy(KernelCore& kernel, uintptr_t arg) {
|
||||
// Release the event count resource the owner process holds.
|
||||
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
||||
|
||||
if (owner != nullptr) {
|
||||
owner->GetResourceLimit()->Release(LimitableResource::EventCountMax, 1);
|
||||
owner->Close();
|
||||
owner->GetResourceLimit()->Release(kernel, LimitableResource::EventCountMax, 1);
|
||||
owner->Close(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -19,9 +22,9 @@ public:
|
|||
explicit KEvent(KernelCore& kernel);
|
||||
~KEvent() override;
|
||||
|
||||
void Initialize(KProcess* owner);
|
||||
void Initialize(KernelCore& kernel, KProcess* owner);
|
||||
|
||||
void Finalize() override;
|
||||
void Finalize(KernelCore& kernel) override;
|
||||
|
||||
bool IsInitialized() const override {
|
||||
return m_initialized;
|
||||
|
|
@ -39,10 +42,10 @@ public:
|
|||
return m_readable_event;
|
||||
}
|
||||
|
||||
static void PostDestroy(uintptr_t arg);
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg);
|
||||
|
||||
Result Signal();
|
||||
Result Clear();
|
||||
Result Signal(KernelCore& kernel);
|
||||
Result Clear(KernelCore& kernel);
|
||||
|
||||
void OnReadableEventDestroyed() {
|
||||
m_readable_event_destroyed = true;
|
||||
|
|
|
|||
|
|
@ -21,11 +21,9 @@ void KHandleTable::Finalize(KernelCore& kernel) {
|
|||
}
|
||||
|
||||
// Close and free all entries.
|
||||
for (size_t i = 0; i < saved_table_size; i++) {
|
||||
if (KAutoObject* obj = m_objects[i]; obj != nullptr) {
|
||||
obj->Close();
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < saved_table_size; i++)
|
||||
if (KAutoObject* obj = m_objects[i]; obj != nullptr)
|
||||
obj->Close(kernel);
|
||||
}
|
||||
|
||||
bool KHandleTable::Remove(KernelCore& kernel, Handle handle) {
|
||||
|
|
@ -58,7 +56,7 @@ bool KHandleTable::Remove(KernelCore& kernel, Handle handle) {
|
|||
|
||||
// Close the object.
|
||||
kernel.UnregisterInUseObject(obj);
|
||||
obj->Close();
|
||||
obj->Close(kernel);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +75,7 @@ Result KHandleTable::Add(KernelCore& kernel, Handle* out_handle, KAutoObject* ob
|
|||
m_entry_infos[index].linear_id = linear_id;
|
||||
m_objects[index] = obj;
|
||||
|
||||
obj->Open();
|
||||
obj->Open(kernel);
|
||||
|
||||
*out_handle = EncodeHandle(static_cast<u16>(index), linear_id);
|
||||
}
|
||||
|
|
@ -91,10 +89,10 @@ KScopedAutoObject<KAutoObject> KHandleTable::GetObjectForIpc(KernelCore& kernel,
|
|||
if (handle == Svc::PseudoHandle::CurrentProcess) {
|
||||
auto* const cur_process = cur_thread->GetOwnerProcess();
|
||||
ASSERT(cur_process != nullptr);
|
||||
return cur_process;
|
||||
return {kernel, cur_process};
|
||||
}
|
||||
if (handle == Svc::PseudoHandle::CurrentThread) {
|
||||
return cur_thread;
|
||||
return {kernel, cur_thread};
|
||||
}
|
||||
return GetObjectForIpcWithoutPseudoHandle(kernel, handle);
|
||||
}
|
||||
|
|
@ -148,7 +146,7 @@ void KHandleTable::Register(KernelCore& kernel, Handle handle, KAutoObject* obj)
|
|||
m_entry_infos[index].linear_id = static_cast<u16>(linear_id);
|
||||
m_objects[index] = obj;
|
||||
|
||||
obj->Open();
|
||||
obj->Open(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,12 +78,12 @@ public:
|
|||
KScopedSpinLock lk(m_lock);
|
||||
|
||||
if constexpr (std::is_same_v<T, KAutoObject>) {
|
||||
return this->GetObjectImpl(handle);
|
||||
return {kernel, this->GetObjectImpl(handle)};
|
||||
} else {
|
||||
if (auto* obj = this->GetObjectImpl(handle); obj != nullptr) [[likely]] {
|
||||
return obj->DynamicCast<T*>();
|
||||
return {kernel, obj->DynamicCast<T*>()};
|
||||
} else {
|
||||
return nullptr;
|
||||
return {kernel, nullptr};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -95,16 +95,15 @@ public:
|
|||
if (handle == Svc::PseudoHandle::CurrentProcess) {
|
||||
auto* const cur_process = GetCurrentProcessPointer(kernel);
|
||||
ASSERT(cur_process != nullptr);
|
||||
return cur_process;
|
||||
return {kernel, cur_process};
|
||||
}
|
||||
} else if constexpr (std::derived_from<KThread, T>) {
|
||||
if (handle == Svc::PseudoHandle::CurrentThread) {
|
||||
auto* const cur_thread = GetCurrentThreadPointer(kernel);
|
||||
ASSERT(cur_thread != nullptr);
|
||||
return cur_thread;
|
||||
return {kernel, cur_thread};
|
||||
}
|
||||
}
|
||||
|
||||
return this->template GetObjectWithoutPseudoHandle<T>(kernel, handle);
|
||||
}
|
||||
|
||||
|
|
@ -112,14 +111,14 @@ public:
|
|||
// Lock and look up in table.
|
||||
KScopedDisableDispatch dd{kernel};
|
||||
KScopedSpinLock lk(m_lock);
|
||||
return this->GetObjectImpl(handle);
|
||||
return {kernel, this->GetObjectImpl(handle)};
|
||||
}
|
||||
KScopedAutoObject<KAutoObject> GetObjectForIpc(KernelCore& kernel, Handle handle, KThread* cur_thread) const;
|
||||
KScopedAutoObject<KAutoObject> GetObjectByIndex(KernelCore& kernel, Handle* out_handle, size_t index) const {
|
||||
KScopedDisableDispatch dd{kernel};
|
||||
KScopedSpinLock lk(m_lock);
|
||||
|
||||
return this->GetObjectByIndexImpl(out_handle, index);
|
||||
return {kernel, this->GetObjectByIndexImpl(out_handle, index)};
|
||||
}
|
||||
|
||||
Result Reserve(KernelCore& kernel, Handle* out_handle);
|
||||
|
|
@ -147,14 +146,14 @@ public:
|
|||
}
|
||||
|
||||
// Cast the current object to the desired type.
|
||||
T* cur_t = cur_object->DynamicCast<T*>();
|
||||
if (cur_t == nullptr) [[unlikely]] {
|
||||
T* cur_thread = cur_object->DynamicCast<T*>();
|
||||
if (cur_thread == nullptr) [[unlikely]] {
|
||||
break;
|
||||
}
|
||||
|
||||
// Open a reference to the current object.
|
||||
cur_t->Open();
|
||||
out[num_opened] = cur_t;
|
||||
cur_thread->Open(kernel);
|
||||
out[num_opened] = cur_thread;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -165,7 +164,7 @@ public:
|
|||
|
||||
// If we didn't convert entry object, close the ones we opened.
|
||||
for (size_t i = 0; i < num_opened; i++) {
|
||||
out[i]->Close();
|
||||
out[i]->Close(kernel);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -45,7 +48,7 @@ protected:
|
|||
this->RemoveTaskFromTree(task);
|
||||
|
||||
// Handle the task.
|
||||
task->OnTimer();
|
||||
task->OnTimer(m_kernel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -18,14 +21,14 @@ void HandleInterrupt(KernelCore& kernel, s32 core_id) {
|
|||
|
||||
if (auto* process = GetCurrentProcessPointer(kernel); process) {
|
||||
// If the user disable count is set, we may need to pin the current thread.
|
||||
if (current_thread.GetUserDisableCount() && !process->GetPinnedThread(core_id)) {
|
||||
if (current_thread.GetUserDisableCount(kernel) && !process->GetPinnedThread(core_id)) {
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
// Pin the current thread.
|
||||
process->PinCurrentThread();
|
||||
process->PinCurrentThread(kernel);
|
||||
|
||||
// Set the interrupt flag for the thread.
|
||||
GetCurrentThread(kernel).SetInterruptFlag();
|
||||
GetCurrentThread(kernel).SetInterruptFlag(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -11,21 +14,21 @@ KLightClientSession::KLightClientSession(KernelCore& kernel) : KAutoObject(kerne
|
|||
|
||||
KLightClientSession::~KLightClientSession() = default;
|
||||
|
||||
void KLightClientSession::Destroy() {
|
||||
m_parent->OnClientClosed();
|
||||
void KLightClientSession::Destroy(KernelCore& kernel) {
|
||||
m_parent->OnClientClosed(kernel);
|
||||
}
|
||||
|
||||
void KLightClientSession::OnServerClosed() {}
|
||||
void KLightClientSession::OnServerClosed(KernelCore& kernel) {}
|
||||
|
||||
Result KLightClientSession::SendSyncRequest(u32* data) {
|
||||
Result KLightClientSession::SendSyncRequest(KernelCore& kernel, u32* data) {
|
||||
// Get the request thread.
|
||||
KThread* cur_thread = GetCurrentThreadPointer(m_kernel);
|
||||
KThread* cur_thread = GetCurrentThreadPointer(kernel);
|
||||
|
||||
// Set the light data.
|
||||
cur_thread->SetLightSessionData(data);
|
||||
|
||||
// Send the request.
|
||||
R_RETURN(m_parent->OnRequest(cur_thread));
|
||||
R_RETURN(m_parent->OnRequest(kernel, cur_thread));
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -22,15 +25,15 @@ public:
|
|||
m_parent = parent;
|
||||
}
|
||||
|
||||
virtual void Destroy() override;
|
||||
virtual void Destroy(KernelCore& kernel) override;
|
||||
|
||||
const KLightSession* GetParent() const {
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
Result SendSyncRequest(u32* data);
|
||||
Result SendSyncRequest(KernelCore& kernel, u32* data);
|
||||
|
||||
void OnServerClosed();
|
||||
void OnServerClosed(KernelCore& kernel);
|
||||
|
||||
private:
|
||||
KLightSession* m_parent;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -13,11 +16,13 @@ namespace {
|
|||
|
||||
class ThreadQueueImplForKLightConditionVariable final : public KThreadQueue {
|
||||
public:
|
||||
ThreadQueueImplForKLightConditionVariable(KernelCore& kernel, KThread::WaiterList* wl,
|
||||
bool term)
|
||||
: KThreadQueue(kernel), m_wait_list(wl), m_allow_terminating_thread(term) {}
|
||||
ThreadQueueImplForKLightConditionVariable(KernelCore& kernel, KThread::WaiterList* wl, bool term)
|
||||
: KThreadQueue(kernel)
|
||||
, m_wait_list(wl)
|
||||
, m_allow_terminating_thread(term)
|
||||
{}
|
||||
|
||||
void CancelWait(KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
virtual void CancelWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
// Only process waits if we're allowed to.
|
||||
if (ResultTerminationRequested == wait_result && m_allow_terminating_thread) {
|
||||
return;
|
||||
|
|
@ -27,7 +32,7 @@ public:
|
|||
m_wait_list->erase(m_wait_list->iterator_to(*waiting_thread));
|
||||
|
||||
// Invoke the base cancel wait handler.
|
||||
KThreadQueue::CancelWait(waiting_thread, wait_result, cancel_timer_task);
|
||||
KThreadQueue::CancelWait(kernel, waiting_thread, wait_result, cancel_timer_task);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -61,7 +66,7 @@ void KLightConditionVariable::Wait(KLightLock* lock, s64 timeout, bool allow_ter
|
|||
|
||||
// Begin waiting.
|
||||
wait_queue.SetHardwareTimer(timer);
|
||||
owner->BeginWait(std::addressof(wait_queue));
|
||||
owner->BeginWait(m_kernel, std::addressof(wait_queue));
|
||||
}
|
||||
|
||||
// Re-acquire the lock.
|
||||
|
|
@ -73,7 +78,7 @@ void KLightConditionVariable::Broadcast() {
|
|||
|
||||
// Signal all threads.
|
||||
for (auto it = m_wait_list.begin(); it != m_wait_list.end(); it = m_wait_list.erase(it)) {
|
||||
it->EndWait(ResultSuccess);
|
||||
it->EndWait(m_kernel, ResultSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -15,29 +18,25 @@ class ThreadQueueImplForKLightLock final : public KThreadQueue {
|
|||
public:
|
||||
explicit ThreadQueueImplForKLightLock(KernelCore& kernel) : KThreadQueue(kernel) {}
|
||||
|
||||
void CancelWait(KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
void CancelWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
// Remove the thread as a waiter from its owner.
|
||||
if (KThread* owner = waiting_thread->GetLockOwner(); owner != nullptr) {
|
||||
owner->RemoveWaiter(waiting_thread);
|
||||
if (KThread* owner = waiting_thread->GetLockOwner(kernel); owner != nullptr) {
|
||||
owner->RemoveWaiter(kernel, waiting_thread);
|
||||
}
|
||||
|
||||
// Invoke the base cancel wait handler.
|
||||
KThreadQueue::CancelWait(waiting_thread, wait_result, cancel_timer_task);
|
||||
KThreadQueue::CancelWait(kernel, waiting_thread, wait_result, cancel_timer_task);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
void KLightLock::Lock() {
|
||||
const uintptr_t cur_thread = reinterpret_cast<uintptr_t>(GetCurrentThreadPointer(m_kernel));
|
||||
|
||||
const uintptr_t cur_thread = uintptr_t(GetCurrentThreadPointer(m_kernel));
|
||||
while (true) {
|
||||
uintptr_t old_tag = m_tag.load(std::memory_order_relaxed);
|
||||
|
||||
while (!m_tag.compare_exchange_weak(old_tag, (old_tag == 0) ? cur_thread : (old_tag | 1),
|
||||
std::memory_order_acquire)) {
|
||||
}
|
||||
|
||||
while (!m_tag.compare_exchange_weak(old_tag, (old_tag == 0) ? cur_thread : (old_tag | 1), std::memory_order_acquire))
|
||||
;
|
||||
if (old_tag == 0 || this->LockSlowPath(old_tag | 1, cur_thread)) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -69,13 +68,13 @@ bool KLightLock::LockSlowPath(uintptr_t _owner, uintptr_t _cur_thread) {
|
|||
// Add the current thread as a waiter on the owner.
|
||||
KThread* owner_thread = reinterpret_cast<KThread*>(_owner & ~1ULL);
|
||||
cur_thread->SetKernelAddressKey(reinterpret_cast<uintptr_t>(std::addressof(m_tag)));
|
||||
owner_thread->AddWaiter(cur_thread);
|
||||
owner_thread->AddWaiter(m_kernel, cur_thread);
|
||||
|
||||
// Begin waiting to hold the lock.
|
||||
cur_thread->BeginWait(std::addressof(wait_queue));
|
||||
cur_thread->BeginWait(m_kernel, std::addressof(wait_queue));
|
||||
|
||||
if (owner_thread->IsSuspended()) {
|
||||
owner_thread->ContinueIfHasKernelWaiters();
|
||||
owner_thread->ContinueIfHasKernelWaiters(m_kernel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -91,26 +90,25 @@ void KLightLock::UnlockSlowPath(uintptr_t _cur_thread) {
|
|||
|
||||
// Get the next owner.
|
||||
bool has_waiters;
|
||||
KThread* next_owner = owner_thread->RemoveKernelWaiterByKey(
|
||||
std::addressof(has_waiters), reinterpret_cast<uintptr_t>(std::addressof(m_tag)));
|
||||
KThread* next_owner = owner_thread->RemoveKernelWaiterByKey(m_kernel,
|
||||
std::addressof(has_waiters), uintptr_t(std::addressof(m_tag)));
|
||||
|
||||
// Pass the lock to the next owner.
|
||||
uintptr_t next_tag = 0;
|
||||
if (next_owner != nullptr) {
|
||||
next_tag =
|
||||
reinterpret_cast<uintptr_t>(next_owner) | static_cast<uintptr_t>(has_waiters);
|
||||
next_tag = uintptr_t(next_owner) | uintptr_t(has_waiters);
|
||||
|
||||
next_owner->EndWait(ResultSuccess);
|
||||
next_owner->EndWait(m_kernel, ResultSuccess);
|
||||
|
||||
if (next_owner->IsSuspended()) {
|
||||
next_owner->ContinueIfHasKernelWaiters();
|
||||
next_owner->ContinueIfHasKernelWaiters(m_kernel);
|
||||
}
|
||||
}
|
||||
|
||||
// We may have unsuspended in the process of acquiring the lock, so we'll re-suspend now if
|
||||
// so.
|
||||
if (owner_thread->IsSuspended()) {
|
||||
owner_thread->TrySuspend();
|
||||
owner_thread->TrySuspend(m_kernel);
|
||||
}
|
||||
|
||||
// Write the new tag value.
|
||||
|
|
@ -119,8 +117,7 @@ void KLightLock::UnlockSlowPath(uintptr_t _cur_thread) {
|
|||
}
|
||||
|
||||
bool KLightLock::IsLockedByCurrentThread() const {
|
||||
return (m_tag.load() | 1ULL) ==
|
||||
(reinterpret_cast<uintptr_t>(GetCurrentThreadPointer(m_kernel)) | 1ULL);
|
||||
return (m_tag.load() | 1ULL) == (uintptr_t(GetCurrentThreadPointer(m_kernel)) | 1ULL);
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
|
|
@ -24,21 +24,20 @@ public:
|
|||
ThreadQueueImplForKLightServerSessionRequest(KernelCore& kernel, KThread::WaiterList* wl)
|
||||
: KThreadQueue(kernel), m_wait_list(wl) {}
|
||||
|
||||
virtual void EndWait(KThread* waiting_thread, Result wait_result) override {
|
||||
virtual void EndWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result) override {
|
||||
// Remove the thread from our wait list.
|
||||
m_wait_list->erase(m_wait_list->iterator_to(*waiting_thread));
|
||||
|
||||
// Invoke the base end wait handler.
|
||||
KThreadQueue::EndWait(waiting_thread, wait_result);
|
||||
KThreadQueue::EndWait(kernel, waiting_thread, wait_result);
|
||||
}
|
||||
|
||||
virtual void CancelWait(KThread* waiting_thread, Result wait_result,
|
||||
bool cancel_timer_task) override {
|
||||
virtual void CancelWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
// Remove the thread from our wait list.
|
||||
m_wait_list->erase(m_wait_list->iterator_to(*waiting_thread));
|
||||
|
||||
// Invoke the base cancel wait handler.
|
||||
KThreadQueue::CancelWait(waiting_thread, wait_result, cancel_timer_task);
|
||||
KThreadQueue::CancelWait(kernel, waiting_thread, wait_result, cancel_timer_task);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -48,9 +47,11 @@ private:
|
|||
|
||||
public:
|
||||
ThreadQueueImplForKLightServerSessionReceive(KernelCore& kernel, KThread** st)
|
||||
: KThreadQueue(kernel), m_server_thread(st) {}
|
||||
: KThreadQueue(kernel)
|
||||
, m_server_thread(st)
|
||||
{}
|
||||
|
||||
virtual void EndWait(KThread* waiting_thread, Result wait_result) override {
|
||||
virtual void EndWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result) override {
|
||||
// Clear the server thread.
|
||||
*m_server_thread = nullptr;
|
||||
|
||||
|
|
@ -58,11 +59,10 @@ public:
|
|||
waiting_thread->ClearCancellable();
|
||||
|
||||
// Invoke the base end wait handler.
|
||||
KThreadQueue::EndWait(waiting_thread, wait_result);
|
||||
KThreadQueue::EndWait(kernel, waiting_thread, wait_result);
|
||||
}
|
||||
|
||||
virtual void CancelWait(KThread* waiting_thread, Result wait_result,
|
||||
bool cancel_timer_task) override {
|
||||
virtual void CancelWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
// Clear the server thread.
|
||||
*m_server_thread = nullptr;
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ public:
|
|||
waiting_thread->ClearCancellable();
|
||||
|
||||
// Invoke the base cancel wait handler.
|
||||
KThreadQueue::CancelWait(waiting_thread, wait_result, cancel_timer_task);
|
||||
KThreadQueue::CancelWait(kernel, waiting_thread, wait_result, cancel_timer_task);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -79,24 +79,21 @@ public:
|
|||
KLightServerSession::KLightServerSession(KernelCore& kernel) : KAutoObject(kernel) {}
|
||||
KLightServerSession::~KLightServerSession() = default;
|
||||
|
||||
void KLightServerSession::Destroy() {
|
||||
this->CleanupRequests();
|
||||
|
||||
m_parent->OnServerClosed();
|
||||
void KLightServerSession::Destroy(KernelCore& kernel) {
|
||||
this->CleanupRequests(kernel);
|
||||
m_parent->OnServerClosed(kernel);
|
||||
}
|
||||
|
||||
void KLightServerSession::OnClientClosed() {
|
||||
this->CleanupRequests();
|
||||
void KLightServerSession::OnClientClosed(KernelCore& kernel) {
|
||||
this->CleanupRequests(kernel);
|
||||
}
|
||||
|
||||
Result KLightServerSession::OnRequest(KThread* request_thread) {
|
||||
ThreadQueueImplForKLightServerSessionRequest wait_queue(m_kernel,
|
||||
std::addressof(m_request_list));
|
||||
|
||||
Result KLightServerSession::OnRequest(KernelCore& kernel, KThread* request_thread) {
|
||||
ThreadQueueImplForKLightServerSessionRequest wait_queue(kernel, std::addressof(m_request_list));
|
||||
// Send the request.
|
||||
{
|
||||
// Lock the scheduler.
|
||||
KScopedSchedulerLock sl(m_kernel);
|
||||
KScopedSchedulerLock sl(kernel);
|
||||
|
||||
// Check that the server isn't closed.
|
||||
R_UNLESS(!m_parent->IsServerClosed(), ResultSessionClosed);
|
||||
|
|
@ -109,11 +106,11 @@ Result KLightServerSession::OnRequest(KThread* request_thread) {
|
|||
|
||||
// Begin waiting on the request.
|
||||
request_thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::IPC);
|
||||
request_thread->BeginWait(std::addressof(wait_queue));
|
||||
request_thread->BeginWait(kernel, std::addressof(wait_queue));
|
||||
|
||||
// If we have a server thread, end its wait.
|
||||
if (m_server_thread != nullptr) {
|
||||
m_server_thread->EndWait(ResultSuccess);
|
||||
m_server_thread->EndWait(kernel, ResultSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -123,13 +120,13 @@ Result KLightServerSession::OnRequest(KThread* request_thread) {
|
|||
R_RETURN(request_thread->GetWaitResult());
|
||||
}
|
||||
|
||||
Result KLightServerSession::ReplyAndReceive(u32* data) {
|
||||
Result KLightServerSession::ReplyAndReceive(KernelCore& kernel, u32* data) {
|
||||
// Set the server context.
|
||||
GetCurrentThread(m_kernel).SetLightSessionData(data);
|
||||
GetCurrentThread(kernel).SetLightSessionData(data);
|
||||
|
||||
// Reply, if we need to.
|
||||
if (data[0] & KLightSession::ReplyFlag) {
|
||||
KScopedSchedulerLock sl(m_kernel);
|
||||
KScopedSchedulerLock sl(kernel);
|
||||
|
||||
// Check that we're open.
|
||||
R_UNLESS(!m_parent->IsClientClosed(), ResultSessionClosed);
|
||||
|
|
@ -139,17 +136,16 @@ Result KLightServerSession::ReplyAndReceive(u32* data) {
|
|||
R_UNLESS(m_current_request != nullptr, ResultInvalidState);
|
||||
|
||||
// Check that the server thread id is correct.
|
||||
R_UNLESS(m_server_thread_id == GetCurrentThread(m_kernel).GetId(), ResultInvalidState);
|
||||
R_UNLESS(m_server_thread_id == GetCurrentThread(kernel).GetId(), ResultInvalidState);
|
||||
|
||||
// If we can reply, do so.
|
||||
if (!m_current_request->IsTerminationRequested()) {
|
||||
std::memcpy(m_current_request->GetLightSessionData(),
|
||||
GetCurrentThread(m_kernel).GetLightSessionData(), KLightSession::DataSize);
|
||||
m_current_request->EndWait(ResultSuccess);
|
||||
std::memcpy(m_current_request->GetLightSessionData(), GetCurrentThread(kernel).GetLightSessionData(), KLightSession::DataSize);
|
||||
m_current_request->EndWait(kernel, ResultSuccess);
|
||||
}
|
||||
|
||||
// Close our current request.
|
||||
m_current_request->Close();
|
||||
m_current_request->Close(kernel);
|
||||
|
||||
// Clear our current request.
|
||||
m_current_request = nullptr;
|
||||
|
|
@ -157,14 +153,13 @@ Result KLightServerSession::ReplyAndReceive(u32* data) {
|
|||
}
|
||||
|
||||
// Create the wait queue for our receive.
|
||||
ThreadQueueImplForKLightServerSessionReceive wait_queue(m_kernel,
|
||||
std::addressof(m_server_thread));
|
||||
ThreadQueueImplForKLightServerSessionReceive wait_queue(kernel, std::addressof(m_server_thread));
|
||||
|
||||
// Receive.
|
||||
while (true) {
|
||||
// Try to receive a request.
|
||||
{
|
||||
KScopedSchedulerLock sl(m_kernel);
|
||||
KScopedSchedulerLock sl(kernel);
|
||||
|
||||
// Check that we aren't already receiving.
|
||||
R_UNLESS(m_server_thread == nullptr, ResultInvalidState);
|
||||
|
|
@ -175,20 +170,19 @@ Result KLightServerSession::ReplyAndReceive(u32* data) {
|
|||
R_UNLESS(!m_parent->IsServerClosed(), ResultSessionClosed);
|
||||
|
||||
// Check that we're not terminating.
|
||||
R_UNLESS(!GetCurrentThread(m_kernel).IsTerminationRequested(),
|
||||
ResultTerminationRequested);
|
||||
R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(), ResultTerminationRequested);
|
||||
|
||||
// If we have a request available, use it.
|
||||
if (auto head = m_request_list.begin(); head != m_request_list.end()) {
|
||||
// Set our current request.
|
||||
m_current_request = std::addressof(*head);
|
||||
m_current_request->Open();
|
||||
m_current_request->Open(kernel);
|
||||
|
||||
// Set our server thread id.
|
||||
m_server_thread_id = GetCurrentThread(m_kernel).GetId();
|
||||
m_server_thread_id = GetCurrentThread(kernel).GetId();
|
||||
|
||||
// Copy the client request data.
|
||||
std::memcpy(GetCurrentThread(m_kernel).GetLightSessionData(),
|
||||
std::memcpy(GetCurrentThread(kernel).GetLightSessionData(),
|
||||
m_current_request->GetLightSessionData(), KLightSession::DataSize);
|
||||
|
||||
// We successfully received.
|
||||
|
|
@ -198,51 +192,51 @@ Result KLightServerSession::ReplyAndReceive(u32* data) {
|
|||
// We need to wait for a request to come in.
|
||||
|
||||
// Check if we were cancelled.
|
||||
if (GetCurrentThread(m_kernel).IsWaitCancelled()) {
|
||||
GetCurrentThread(m_kernel).ClearWaitCancelled();
|
||||
if (GetCurrentThread(kernel).IsWaitCancelled()) {
|
||||
GetCurrentThread(kernel).ClearWaitCancelled();
|
||||
R_THROW(ResultCancelled);
|
||||
}
|
||||
|
||||
// Mark ourselves as cancellable.
|
||||
GetCurrentThread(m_kernel).SetCancellable();
|
||||
GetCurrentThread(kernel).SetCancellable();
|
||||
|
||||
// Wait for a request to come in.
|
||||
m_server_thread = GetCurrentThreadPointer(m_kernel);
|
||||
GetCurrentThread(m_kernel).SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::IPC);
|
||||
GetCurrentThread(m_kernel).BeginWait(std::addressof(wait_queue));
|
||||
m_server_thread = GetCurrentThreadPointer(kernel);
|
||||
GetCurrentThread(kernel).SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::IPC);
|
||||
GetCurrentThread(kernel).BeginWait(kernel, std::addressof(wait_queue));
|
||||
}
|
||||
|
||||
// We waited to receive a request; if our wait failed, return the failing result.
|
||||
R_TRY(GetCurrentThread(m_kernel).GetWaitResult());
|
||||
R_TRY(GetCurrentThread(kernel).GetWaitResult());
|
||||
}
|
||||
}
|
||||
|
||||
void KLightServerSession::CleanupRequests() {
|
||||
void KLightServerSession::CleanupRequests(KernelCore& kernel) {
|
||||
// Cleanup all pending requests.
|
||||
{
|
||||
KScopedSchedulerLock sl(m_kernel);
|
||||
KScopedSchedulerLock sl(kernel);
|
||||
|
||||
// Handle the current request.
|
||||
if (m_current_request != nullptr) {
|
||||
// Reply to the current request.
|
||||
if (!m_current_request->IsTerminationRequested()) {
|
||||
m_current_request->EndWait(ResultSessionClosed);
|
||||
m_current_request->EndWait(kernel, ResultSessionClosed);
|
||||
}
|
||||
|
||||
// Clear our current request.
|
||||
m_current_request->Close();
|
||||
m_current_request->Close(kernel);
|
||||
m_current_request = nullptr;
|
||||
m_server_thread_id = InvalidThreadId;
|
||||
}
|
||||
|
||||
// Reply to all other requests.
|
||||
for (auto& thread : m_request_list) {
|
||||
thread.EndWait(ResultSessionClosed);
|
||||
thread.EndWait(kernel, ResultSessionClosed);
|
||||
}
|
||||
|
||||
// Wait up our server thread, if we have one.
|
||||
if (m_server_thread != nullptr) {
|
||||
m_server_thread->EndWait(ResultSessionClosed);
|
||||
m_server_thread->EndWait(kernel, ResultSessionClosed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
|
|
@ -34,19 +34,19 @@ public:
|
|||
m_parent = parent;
|
||||
}
|
||||
|
||||
virtual void Destroy() override;
|
||||
virtual void Destroy(KernelCore& kernel) override;
|
||||
|
||||
constexpr const KLightSession* GetParent() const {
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
Result OnRequest(KThread* request_thread);
|
||||
Result ReplyAndReceive(u32* data);
|
||||
Result OnRequest(KernelCore& kernel, KThread* request_thread);
|
||||
Result ReplyAndReceive(KernelCore& kernel, u32* data);
|
||||
|
||||
void OnClientClosed();
|
||||
void OnClientClosed(KernelCore& kernel);
|
||||
|
||||
private:
|
||||
void CleanupRequests();
|
||||
void CleanupRequests(KernelCore& kernel);
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -10,15 +13,18 @@
|
|||
namespace Kernel {
|
||||
|
||||
KLightSession::KLightSession(KernelCore& kernel)
|
||||
: KAutoObjectWithSlabHeapAndContainer(kernel), m_server(kernel), m_client(kernel) {}
|
||||
: KAutoObjectWithSlabHeapAndContainer(kernel)
|
||||
, m_server(kernel)
|
||||
, m_client(kernel)
|
||||
{}
|
||||
KLightSession::~KLightSession() = default;
|
||||
|
||||
void KLightSession::Initialize(KClientPort* client_port, uintptr_t name) {
|
||||
void KLightSession::Initialize(KernelCore& kernel, KClientPort* client_port, uintptr_t name) {
|
||||
// Increment reference count.
|
||||
// Because reference count is one on creation, this will result
|
||||
// in a reference count of two. Thus, when both server and client are closed
|
||||
// this object will be destroyed.
|
||||
this->Open();
|
||||
this->Open(kernel);
|
||||
|
||||
// Create our sub sessions.
|
||||
KAutoObject::Create(std::addressof(m_server));
|
||||
|
|
@ -33,49 +39,47 @@ void KLightSession::Initialize(KClientPort* client_port, uintptr_t name) {
|
|||
m_name = name;
|
||||
|
||||
// Set our owner process.
|
||||
m_process = GetCurrentProcessPointer(m_kernel);
|
||||
m_process->Open();
|
||||
m_process = GetCurrentProcessPointer(kernel);
|
||||
m_process->Open(kernel);
|
||||
|
||||
// Set our port.
|
||||
m_port = client_port;
|
||||
if (m_port != nullptr) {
|
||||
m_port->Open();
|
||||
m_port->Open(kernel);
|
||||
}
|
||||
|
||||
// Mark initialized.
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
void KLightSession::Finalize() {
|
||||
void KLightSession::Finalize(KernelCore& kernel) {
|
||||
if (m_port != nullptr) {
|
||||
m_port->OnSessionFinalized();
|
||||
m_port->Close();
|
||||
m_port->OnSessionFinalized(kernel);
|
||||
m_port->Close(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
void KLightSession::OnServerClosed() {
|
||||
void KLightSession::OnServerClosed(KernelCore& kernel) {
|
||||
if (m_state == State::Normal) {
|
||||
m_state = State::ServerClosed;
|
||||
m_client.OnServerClosed();
|
||||
m_client.OnServerClosed(kernel);
|
||||
}
|
||||
|
||||
this->Close();
|
||||
this->Close(kernel);
|
||||
}
|
||||
|
||||
void KLightSession::OnClientClosed() {
|
||||
void KLightSession::OnClientClosed(KernelCore& kernel) {
|
||||
if (m_state == State::Normal) {
|
||||
m_state = State::ClientClosed;
|
||||
m_server.OnClientClosed();
|
||||
m_server.OnClientClosed(kernel);
|
||||
}
|
||||
|
||||
this->Close();
|
||||
this->Close(kernel);
|
||||
}
|
||||
|
||||
void KLightSession::PostDestroy(uintptr_t arg) {
|
||||
void KLightSession::PostDestroy(KernelCore& kernel, uintptr_t arg) {
|
||||
// Release the session count resource the owner process holds.
|
||||
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
||||
owner->ReleaseResource(Svc::LimitableResource::SessionCountMax, 1);
|
||||
owner->Close();
|
||||
owner->ReleaseResource(kernel, Svc::LimitableResource::SessionCountMax, 1);
|
||||
owner->Close(kernel);
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -43,20 +46,20 @@ public:
|
|||
explicit KLightSession(KernelCore& kernel);
|
||||
~KLightSession();
|
||||
|
||||
void Initialize(KClientPort* client_port, uintptr_t name);
|
||||
void Finalize() override;
|
||||
void Initialize(KernelCore& kernel, KClientPort* client_port, uintptr_t name);
|
||||
void Finalize(KernelCore& kernel) override;
|
||||
|
||||
bool IsInitialized() const override {
|
||||
return m_initialized;
|
||||
}
|
||||
uintptr_t GetPostDestroyArgument() const override {
|
||||
return reinterpret_cast<uintptr_t>(m_process);
|
||||
return uintptr_t(m_process);
|
||||
}
|
||||
|
||||
static void PostDestroy(uintptr_t arg);
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg);
|
||||
|
||||
void OnServerClosed();
|
||||
void OnClientClosed();
|
||||
void OnServerClosed(KernelCore& kernel);
|
||||
void OnClientClosed(KernelCore& kernel);
|
||||
|
||||
bool IsServerClosed() const {
|
||||
return m_state != State::Normal;
|
||||
|
|
@ -65,8 +68,8 @@ public:
|
|||
return m_state != State::Normal;
|
||||
}
|
||||
|
||||
Result OnRequest(KThread* request_thread) {
|
||||
R_RETURN(m_server.OnRequest(request_thread));
|
||||
Result OnRequest(KernelCore& kernel, KThread* request_thread) {
|
||||
R_RETURN(m_server.OnRequest(kernel, request_thread));
|
||||
}
|
||||
|
||||
KLightClientSession& GetClientSession() {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -8,14 +11,14 @@ namespace Kernel {
|
|||
KObjectNameGlobalData::KObjectNameGlobalData(KernelCore& kernel) : m_object_list_lock{kernel} {}
|
||||
KObjectNameGlobalData::~KObjectNameGlobalData() = default;
|
||||
|
||||
void KObjectName::Initialize(KAutoObject* obj, const char* name) {
|
||||
void KObjectName::Initialize(KernelCore& kernel, KAutoObject* obj, const char* name) {
|
||||
// Set member variables.
|
||||
m_object = obj;
|
||||
std::strncpy(m_name.data(), name, sizeof(m_name) - 1);
|
||||
m_name[sizeof(m_name) - 1] = '\x00';
|
||||
|
||||
// Open a reference to the object we hold.
|
||||
m_object->Open();
|
||||
m_object->Open(kernel);
|
||||
}
|
||||
|
||||
bool KObjectName::MatchesName(const char* name) const {
|
||||
|
|
@ -28,7 +31,7 @@ Result KObjectName::NewFromName(KernelCore& kernel, KAutoObject* obj, const char
|
|||
R_UNLESS(new_name != nullptr, ResultOutOfResource);
|
||||
|
||||
// Initialize the new name.
|
||||
new_name->Initialize(obj, name);
|
||||
new_name->Initialize(kernel, obj, name);
|
||||
|
||||
// Check if there's an existing name.
|
||||
{
|
||||
|
|
@ -47,7 +50,7 @@ Result KObjectName::NewFromName(KernelCore& kernel, KAutoObject* obj, const char
|
|||
}
|
||||
|
||||
// The object already exists, which is an error condition. Perform cleanup.
|
||||
obj->Close();
|
||||
obj->Close(kernel);
|
||||
KObjectName::Free(kernel, new_name);
|
||||
R_THROW(ResultInvalidState);
|
||||
}
|
||||
|
|
@ -63,7 +66,7 @@ Result KObjectName::Delete(KernelCore& kernel, KAutoObject* obj, const char* com
|
|||
for (auto& name : gd.GetObjectList()) {
|
||||
if (name.MatchesName(compare_name) && obj == name.GetObject()) {
|
||||
// We found a match, clean up its resources.
|
||||
obj->Close();
|
||||
obj->Close(kernel);
|
||||
gd.GetObjectList().erase(gd.GetObjectList().iterator_to(name));
|
||||
KObjectName::Free(kernel, std::addressof(name));
|
||||
R_SUCCEED();
|
||||
|
|
@ -89,14 +92,12 @@ KScopedAutoObject<KAutoObject> KObjectName::FindImpl(KernelCore& kernel, const c
|
|||
KObjectNameGlobalData& gd{kernel.ObjectNameGlobalData()};
|
||||
|
||||
// Try to find a matching object in the global list.
|
||||
for (const auto& name : gd.GetObjectList()) {
|
||||
if (name.MatchesName(compare_name)) {
|
||||
return name.GetObject();
|
||||
}
|
||||
}
|
||||
for (const auto& name : gd.GetObjectList())
|
||||
if (name.MatchesName(compare_name))
|
||||
return {kernel, name.GetObject()};
|
||||
|
||||
// There's no matching entry in the list.
|
||||
return nullptr;
|
||||
return {kernel, nullptr};
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -41,7 +44,7 @@ public:
|
|||
R_UNLESS(derived != nullptr, ResultNotFound);
|
||||
|
||||
// Check that the object is closed.
|
||||
R_UNLESS(derived->IsServerClosed(), ResultInvalidState);
|
||||
R_UNLESS(derived->IsServerClosed(kernel), ResultInvalidState);
|
||||
|
||||
R_RETURN(Delete(kernel, obj.GetPointerUnsafe(), name));
|
||||
}
|
||||
|
|
@ -49,13 +52,13 @@ public:
|
|||
template <typename Derived>
|
||||
requires(std::derived_from<Derived, KAutoObject>)
|
||||
static KScopedAutoObject<Derived> Find(KernelCore& kernel, const char* name) {
|
||||
return Find(kernel, name);
|
||||
return {kernel, static_cast<Derived*>(Find(kernel, name).GetPointerUnsafe())};
|
||||
}
|
||||
|
||||
private:
|
||||
static KScopedAutoObject<KAutoObject> FindImpl(KernelCore& kernel, const char* name);
|
||||
|
||||
void Initialize(KAutoObject* obj, const char* name);
|
||||
void Initialize(KernelCore& kernel, KAutoObject* obj, const char* name);
|
||||
|
||||
bool MatchesName(const char* name) const;
|
||||
KAutoObject* GetObject() const {
|
||||
|
|
|
|||
|
|
@ -492,14 +492,14 @@ void KPageTableBase::Finalize() {
|
|||
if (auto* const insecure_resource_limit =
|
||||
KSystemControl::GetInsecureMemoryResourceLimit(m_system.Kernel());
|
||||
insecure_resource_limit != nullptr) {
|
||||
insecure_resource_limit->Release(Svc::LimitableResource::PhysicalMemoryMax,
|
||||
insecure_resource_limit->Release(m_system.Kernel(), Svc::LimitableResource::PhysicalMemoryMax,
|
||||
m_mapped_insecure_memory);
|
||||
}
|
||||
}
|
||||
|
||||
// Release any ipc server memory.
|
||||
if (m_mapped_ipc_server_memory) {
|
||||
m_resource_limit->Release(Svc::LimitableResource::PhysicalMemoryMax,
|
||||
m_resource_limit->Release(m_system.Kernel(), Svc::LimitableResource::PhysicalMemoryMax,
|
||||
m_mapped_ipc_server_memory);
|
||||
}
|
||||
}
|
||||
|
|
@ -1389,7 +1389,7 @@ Result KPageTableBase::MapInsecureMemory(KProcessAddress address, size_t size) {
|
|||
|
||||
// Reserve the insecure memory.
|
||||
// NOTE: ResultOutOfMemory is returned here instead of the usual LimitReached.
|
||||
KScopedResourceReservation memory_reservation(insecure_resource_limit,
|
||||
KScopedResourceReservation memory_reservation(m_system.Kernel(), insecure_resource_limit,
|
||||
Svc::LimitableResource::PhysicalMemoryMax, size);
|
||||
R_UNLESS(memory_reservation.Succeeded(), ResultOutOfMemory);
|
||||
|
||||
|
|
@ -1493,7 +1493,7 @@ Result KPageTableBase::UnmapInsecureMemory(KProcessAddress address, size_t size)
|
|||
if (auto* const insecure_resource_limit =
|
||||
KSystemControl::GetInsecureMemoryResourceLimit(m_system.Kernel());
|
||||
insecure_resource_limit != nullptr) {
|
||||
insecure_resource_limit->Release(Svc::LimitableResource::PhysicalMemoryMax, size);
|
||||
insecure_resource_limit->Release(m_system.Kernel(), Svc::LimitableResource::PhysicalMemoryMax, size);
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
|
|
@ -2158,7 +2158,7 @@ Result KPageTableBase::SetHeapSize(KProcessAddress* out, size_t size) {
|
|||
false, unmap_properties, OperationType::Unmap, false));
|
||||
|
||||
// Release the memory from the resource limit.
|
||||
m_resource_limit->Release(Svc::LimitableResource::PhysicalMemoryMax,
|
||||
m_resource_limit->Release(m_system.Kernel(), Svc::LimitableResource::PhysicalMemoryMax,
|
||||
num_pages * PageSize);
|
||||
|
||||
// Apply the memory block update.
|
||||
|
|
@ -2188,7 +2188,7 @@ Result KPageTableBase::SetHeapSize(KProcessAddress* out, size_t size) {
|
|||
}
|
||||
|
||||
// Reserve memory for the heap extension.
|
||||
KScopedResourceReservation memory_reservation(
|
||||
KScopedResourceReservation memory_reservation(m_system.Kernel(),
|
||||
m_resource_limit, Svc::LimitableResource::PhysicalMemoryMax, allocation_size);
|
||||
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
||||
|
||||
|
|
@ -4493,7 +4493,7 @@ Result KPageTableBase::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
|
|||
|
||||
// Reserve space for any partial pages we allocate.
|
||||
const size_t unmapped_size = aligned_src_size - mapping_src_size;
|
||||
KScopedResourceReservation memory_reservation(
|
||||
KScopedResourceReservation memory_reservation(m_system.Kernel(),
|
||||
m_resource_limit, Svc::LimitableResource::PhysicalMemoryMax, unmapped_size);
|
||||
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
||||
|
||||
|
|
@ -4799,7 +4799,7 @@ Result KPageTableBase::CleanupForIpcServer(KProcessAddress address, size_t size,
|
|||
const KProcessAddress mapping_start = Common::AlignUp(GetInteger(address), PageSize);
|
||||
const KProcessAddress mapping_end = Common::AlignDown(GetInteger(address) + size, PageSize);
|
||||
const size_t mapping_size = (mapping_start < mapping_end) ? mapping_end - mapping_start : 0;
|
||||
m_resource_limit->Release(Svc::LimitableResource::PhysicalMemoryMax,
|
||||
m_resource_limit->Release(m_system.Kernel(), Svc::LimitableResource::PhysicalMemoryMax,
|
||||
aligned_size - mapping_size);
|
||||
|
||||
R_SUCCEED();
|
||||
|
|
@ -5168,7 +5168,7 @@ Result KPageTableBase::MapPhysicalMemory(KProcessAddress address, size_t size) {
|
|||
// Allocate and map the memory.
|
||||
{
|
||||
// Reserve the memory from the process resource limit.
|
||||
KScopedResourceReservation memory_reservation(
|
||||
KScopedResourceReservation memory_reservation(m_system.Kernel(),
|
||||
m_resource_limit, Svc::LimitableResource::PhysicalMemoryMax, size - mapped_size);
|
||||
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
||||
|
||||
|
|
@ -5541,7 +5541,7 @@ Result KPageTableBase::UnmapPhysicalMemory(KProcessAddress address, size_t size)
|
|||
|
||||
// Release the memory resource.
|
||||
m_mapped_physical_memory_size -= mapped_size;
|
||||
m_resource_limit->Release(Svc::LimitableResource::PhysicalMemoryMax, mapped_size);
|
||||
m_resource_limit->Release(m_system.Kernel(), Svc::LimitableResource::PhysicalMemoryMax, mapped_size);
|
||||
|
||||
// Update memory blocks.
|
||||
m_memory_block_manager.Update(std::addressof(allocator), address, size / PageSize,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/hle/kernel/k_port.h"
|
||||
#include "core/hle/kernel/k_scheduler.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/hle/kernel/svc_results.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
|
@ -12,15 +16,15 @@ KPort::KPort(KernelCore& kernel)
|
|||
|
||||
KPort::~KPort() = default;
|
||||
|
||||
void KPort::Initialize(s32 max_sessions, bool is_light, uintptr_t name) {
|
||||
void KPort::Initialize(KernelCore& kernel, s32 max_sessions, bool is_light, uintptr_t name) {
|
||||
// Open a new reference count to the initialized port.
|
||||
this->Open();
|
||||
this->Open(kernel);
|
||||
|
||||
// Create and initialize our server/client pair.
|
||||
KAutoObject::Create(std::addressof(m_server));
|
||||
KAutoObject::Create(std::addressof(m_client));
|
||||
m_server.Initialize(this);
|
||||
m_client.Initialize(this, max_sessions);
|
||||
m_server.Initialize(kernel, this);
|
||||
m_client.Initialize(kernel, this, max_sessions);
|
||||
|
||||
// Set our member variables.
|
||||
m_is_light = is_light;
|
||||
|
|
@ -28,42 +32,38 @@ void KPort::Initialize(s32 max_sessions, bool is_light, uintptr_t name) {
|
|||
m_state = State::Normal;
|
||||
}
|
||||
|
||||
void KPort::OnClientClosed() {
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
void KPort::OnClientClosed(KernelCore& kernel) {
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
if (m_state == State::Normal) {
|
||||
m_state = State::ClientClosed;
|
||||
}
|
||||
}
|
||||
|
||||
void KPort::OnServerClosed() {
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
void KPort::OnServerClosed(KernelCore& kernel) {
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
if (m_state == State::Normal) {
|
||||
m_state = State::ServerClosed;
|
||||
}
|
||||
}
|
||||
|
||||
bool KPort::IsServerClosed() const {
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
bool KPort::IsServerClosed(KernelCore& kernel) const {
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
return m_state == State::ServerClosed;
|
||||
}
|
||||
|
||||
Result KPort::EnqueueSession(KServerSession* session) {
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
|
||||
Result KPort::EnqueueSession(KernelCore& kernel, KServerSession* session) {
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
R_UNLESS(m_state == State::Normal, ResultPortClosed);
|
||||
|
||||
m_server.EnqueueSession(session);
|
||||
m_server.EnqueueSession(kernel, session);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result KPort::EnqueueSession(KLightServerSession* session) {
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
|
||||
Result KPort::EnqueueSession(KernelCore& kernel, KLightServerSession* session) {
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
R_UNLESS(m_state == State::Normal, ResultPortClosed);
|
||||
|
||||
m_server.EnqueueSession(session);
|
||||
m_server.EnqueueSession(kernel, session);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -23,11 +26,11 @@ public:
|
|||
explicit KPort(KernelCore& kernel);
|
||||
~KPort() override;
|
||||
|
||||
static void PostDestroy(uintptr_t arg) {}
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}
|
||||
|
||||
void Initialize(s32 max_sessions, bool is_light, uintptr_t name);
|
||||
void OnClientClosed();
|
||||
void OnServerClosed();
|
||||
void Initialize(KernelCore& kernel, s32 max_sessions, bool is_light, uintptr_t name);
|
||||
void OnClientClosed(KernelCore& kernel);
|
||||
void OnServerClosed(KernelCore& kernel);
|
||||
|
||||
uintptr_t GetName() const {
|
||||
return m_name;
|
||||
|
|
@ -36,10 +39,10 @@ public:
|
|||
return m_is_light;
|
||||
}
|
||||
|
||||
bool IsServerClosed() const;
|
||||
bool IsServerClosed(KernelCore& kernel) const;
|
||||
|
||||
Result EnqueueSession(KServerSession* session);
|
||||
Result EnqueueSession(KLightServerSession* session);
|
||||
Result EnqueueSession(KernelCore& kernel, KServerSession* session);
|
||||
Result EnqueueSession(KernelCore& kernel, KLightServerSession* session);
|
||||
|
||||
KClientPort& GetClientPort() {
|
||||
return m_client;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -139,8 +139,8 @@ private:
|
|||
bool m_is_handle_table_initialized : 1 = false;
|
||||
|
||||
private:
|
||||
Result StartTermination();
|
||||
void FinishTermination();
|
||||
Result StartTermination(KernelCore& kernel);
|
||||
void FinishTermination(KernelCore& kernel);
|
||||
|
||||
void PinThread(s32 core_id, KThread* thread) {
|
||||
ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES));
|
||||
|
|
@ -160,16 +160,16 @@ public:
|
|||
explicit KProcess(KernelCore& kernel);
|
||||
~KProcess() override;
|
||||
|
||||
Result Initialize(const Svc::CreateProcessParameter& params, KResourceLimit* res_limit,
|
||||
Result Initialize(KernelCore& kernel, const Svc::CreateProcessParameter& params, KResourceLimit* res_limit,
|
||||
bool is_real);
|
||||
|
||||
Result Initialize(const Svc::CreateProcessParameter& params, const KPageGroup& pg,
|
||||
Result Initialize(KernelCore& kernel, const Svc::CreateProcessParameter& params, const KPageGroup& pg,
|
||||
std::span<const u32> caps, KResourceLimit* res_limit,
|
||||
KMemoryManager::Pool pool, bool immortal);
|
||||
Result Initialize(const Svc::CreateProcessParameter& params, std::span<const u32> user_caps,
|
||||
Result Initialize(KernelCore& kernel, const Svc::CreateProcessParameter& params, std::span<const u32> user_caps,
|
||||
KResourceLimit* res_limit, KMemoryManager::Pool pool,
|
||||
KProcessAddress aslr_space_start);
|
||||
void Exit();
|
||||
void Exit(KernelCore& kernel);
|
||||
|
||||
const char* GetName() const {
|
||||
return m_name.data();
|
||||
|
|
@ -255,7 +255,7 @@ public:
|
|||
m_pointer_buffer_size = size;
|
||||
}
|
||||
|
||||
Result Terminate();
|
||||
Result Terminate(KernelCore& kernel);
|
||||
|
||||
bool IsTerminated() const {
|
||||
return m_state == State::Terminated;
|
||||
|
|
@ -292,9 +292,9 @@ public:
|
|||
return m_thread_list;
|
||||
}
|
||||
|
||||
bool EnterUserException();
|
||||
bool LeaveUserException();
|
||||
bool ReleaseUserException(KThread* thread);
|
||||
bool EnterUserException(KernelCore& kernel);
|
||||
bool LeaveUserException(KernelCore& kernel);
|
||||
bool ReleaseUserException(KernelCore& kernel, KThread* thread);
|
||||
|
||||
KThread* GetPinnedThread(s32 core_id) const {
|
||||
ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES));
|
||||
|
|
@ -309,10 +309,10 @@ public:
|
|||
return m_resource_limit;
|
||||
}
|
||||
|
||||
bool ReserveResource(Svc::LimitableResource which, s64 value);
|
||||
bool ReserveResource(Svc::LimitableResource which, s64 value, s64 timeout);
|
||||
void ReleaseResource(Svc::LimitableResource which, s64 value);
|
||||
void ReleaseResource(Svc::LimitableResource which, s64 value, s64 hint);
|
||||
bool ReserveResource(KernelCore& kernel, Svc::LimitableResource which, s64 value);
|
||||
bool ReserveResource(KernelCore& kernel, Svc::LimitableResource which, s64 value, s64 timeout);
|
||||
void ReleaseResource(KernelCore& kernel, Svc::LimitableResource which, s64 value);
|
||||
void ReleaseResource(KernelCore& kernel, Svc::LimitableResource which, s64 value, s64 hint);
|
||||
|
||||
KLightLock& GetStateLock() {
|
||||
return m_state_lock;
|
||||
|
|
@ -335,16 +335,16 @@ public:
|
|||
return m_handle_table;
|
||||
}
|
||||
|
||||
size_t GetUsedUserPhysicalMemorySize() const;
|
||||
size_t GetTotalUserPhysicalMemorySize() const;
|
||||
size_t GetUsedNonSystemUserPhysicalMemorySize() const;
|
||||
size_t GetTotalNonSystemUserPhysicalMemorySize() const;
|
||||
size_t GetUsedUserPhysicalMemorySize(KernelCore& kernel) const;
|
||||
size_t GetTotalUserPhysicalMemorySize(KernelCore& kernel) const;
|
||||
size_t GetUsedNonSystemUserPhysicalMemorySize(KernelCore& kernel) const;
|
||||
size_t GetTotalNonSystemUserPhysicalMemorySize(KernelCore& kernel) const;
|
||||
|
||||
Result AddSharedMemory(KSharedMemory* shmem, KProcessAddress address, size_t size);
|
||||
void RemoveSharedMemory(KSharedMemory* shmem, KProcessAddress address, size_t size);
|
||||
Result AddSharedMemory(KernelCore& kernel, KSharedMemory* shmem, KProcessAddress address, size_t size);
|
||||
void RemoveSharedMemory(KernelCore& kernel, KSharedMemory* shmem, KProcessAddress address, size_t size);
|
||||
|
||||
Result CreateThreadLocalRegion(KProcessAddress* out);
|
||||
Result DeleteThreadLocalRegion(KProcessAddress addr);
|
||||
Result CreateThreadLocalRegion(KernelCore& kernel, KProcessAddress* out);
|
||||
Result DeleteThreadLocalRegion(KernelCore& kernel, KProcessAddress addr);
|
||||
|
||||
KProcessAddress GetProcessLocalRegionAddress() const {
|
||||
return m_plr_address;
|
||||
|
|
@ -368,8 +368,8 @@ public:
|
|||
++m_schedule_count;
|
||||
}
|
||||
|
||||
void IncrementRunningThreadCount();
|
||||
void DecrementRunningThreadCount();
|
||||
void IncrementRunningThreadCount(KernelCore& kernel);
|
||||
void DecrementRunningThreadCount(KernelCore& kernel);
|
||||
|
||||
size_t GetRequiredSecureMemorySizeNonDefault() const {
|
||||
if (!this->IsDefaultApplicationSystemResource() && m_system_resource->IsSecureResource()) {
|
||||
|
|
@ -414,11 +414,9 @@ public:
|
|||
}
|
||||
|
||||
void ClearRunningThread(KThread* thread) {
|
||||
for (size_t i = 0; i < m_running_threads.size(); ++i) {
|
||||
if (m_running_threads[i] == thread) {
|
||||
for (size_t i = 0; i < m_running_threads.size(); ++i)
|
||||
if (m_running_threads[i] == thread)
|
||||
m_running_threads[i] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const KSystemResource& GetSystemResource() const {
|
||||
|
|
@ -445,30 +443,27 @@ public:
|
|||
return m_running_thread_switch_counts[core];
|
||||
}
|
||||
|
||||
void RegisterThread(KThread* thread);
|
||||
void UnregisterThread(KThread* thread);
|
||||
void RegisterThread(KernelCore& kernel, KThread* thread);
|
||||
void UnregisterThread(KernelCore& kernel, KThread* thread);
|
||||
Result Run(KernelCore& kernel, s32 priority, size_t stack_size);
|
||||
Result Reset(KernelCore& kernel);
|
||||
|
||||
Result Run(s32 priority, size_t stack_size);
|
||||
|
||||
Result Reset();
|
||||
|
||||
void SetDebugBreak() {
|
||||
void SetDebugBreak(KernelCore& kernel) {
|
||||
if (m_state == State::RunningAttached) {
|
||||
this->ChangeState(State::DebugBreak);
|
||||
this->ChangeState(kernel, State::DebugBreak);
|
||||
}
|
||||
}
|
||||
|
||||
void SetAttached() {
|
||||
void SetAttached(KernelCore& kernel) {
|
||||
if (m_state == State::DebugBreak) {
|
||||
this->ChangeState(State::RunningAttached);
|
||||
this->ChangeState(kernel, State::RunningAttached);
|
||||
}
|
||||
}
|
||||
|
||||
Result SetActivity(Svc::ProcessActivity activity);
|
||||
|
||||
void PinCurrentThread();
|
||||
void UnpinCurrentThread();
|
||||
void UnpinThread(KThread* thread);
|
||||
Result SetActivity(KernelCore& kernel, Svc::ProcessActivity activity);
|
||||
void PinCurrentThread(KernelCore& kernel);
|
||||
void UnpinCurrentThread(KernelCore& kernel);
|
||||
void UnpinThread(KernelCore& kernel, KThread* thread);
|
||||
|
||||
void SignalConditionVariable(uintptr_t cv_key, int32_t count) {
|
||||
return m_cond_var.Signal(cv_key, count);
|
||||
|
|
@ -478,19 +473,17 @@ public:
|
|||
R_RETURN(m_cond_var.Wait(address, cv_key, tag, ns));
|
||||
}
|
||||
|
||||
Result SignalAddressArbiter(uintptr_t address, Svc::SignalType signal_type, s32 value,
|
||||
s32 count) {
|
||||
Result SignalAddressArbiter(uintptr_t address, Svc::SignalType signal_type, s32 value, s32 count) {
|
||||
R_RETURN(m_address_arbiter.SignalToAddress(address, signal_type, value, count));
|
||||
}
|
||||
|
||||
Result WaitAddressArbiter(uintptr_t address, Svc::ArbitrationType arb_type, s32 value,
|
||||
s64 timeout) {
|
||||
Result WaitAddressArbiter(uintptr_t address, Svc::ArbitrationType arb_type, s32 value, s64 timeout) {
|
||||
R_RETURN(m_address_arbiter.WaitForAddress(address, arb_type, value, timeout));
|
||||
}
|
||||
|
||||
Result GetThreadList(s32* out_num_threads, KProcessAddress out_thread_ids, s32 max_out_count);
|
||||
Result GetThreadList(KernelCore& kernel, s32* out_num_threads, KProcessAddress out_thread_ids, s32 max_out_count);
|
||||
|
||||
static void Switch(KProcess* cur_process, KProcess* next_process);
|
||||
static void Switch(KernelCore& kernel, KProcess* cur_process, KProcess* next_process);
|
||||
|
||||
#ifdef HAS_NCE
|
||||
ankerl::unordered_dense::map<u64, u64>& GetPostHandlers() noexcept {
|
||||
|
|
@ -504,22 +497,21 @@ public:
|
|||
|
||||
public:
|
||||
// Attempts to insert a watchpoint into a free slot. Returns false if none are available.
|
||||
bool InsertWatchpoint(KProcessAddress addr, u64 size, DebugWatchpointType type);
|
||||
bool InsertWatchpoint(KernelCore& kernel, KProcessAddress addr, u64 size, DebugWatchpointType type);
|
||||
|
||||
// Attempts to remove the watchpoint specified by the given parameters.
|
||||
bool RemoveWatchpoint(KProcessAddress addr, u64 size, DebugWatchpointType type);
|
||||
bool RemoveWatchpoint(KernelCore& kernel, KProcessAddress addr, u64 size, DebugWatchpointType type);
|
||||
|
||||
const std::array<DebugWatchpoint, Core::Hardware::NUM_WATCHPOINTS>& GetWatchpoints() const {
|
||||
return m_watchpoints;
|
||||
}
|
||||
|
||||
public:
|
||||
Result LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std::size_t code_size,
|
||||
KProcessAddress aslr_space_start, size_t aslr_space_offset, bool is_hbl);
|
||||
Result LoadFromMetadata(KernelCore& kernel, const FileSys::ProgramMetadata& metadata, std::size_t code_size, KProcessAddress aslr_space_start, size_t aslr_space_offset, bool is_hbl);
|
||||
|
||||
void LoadModule(CodeSet code_set, KProcessAddress base_addr);
|
||||
void LoadModule(KernelCore& kernel, CodeSet code_set, KProcessAddress base_addr);
|
||||
|
||||
void InitializeInterfaces();
|
||||
void InitializeInterfaces(KernelCore& kernel);
|
||||
|
||||
Core::Memory::Memory& GetMemory() {
|
||||
return m_memory;
|
||||
|
|
@ -535,9 +527,9 @@ public:
|
|||
return m_is_initialized;
|
||||
}
|
||||
|
||||
static void PostDestroy(uintptr_t arg) {}
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}
|
||||
|
||||
void Finalize() override;
|
||||
void Finalize(KernelCore& kernel) override;
|
||||
|
||||
u64 GetIdImpl() const {
|
||||
return this->GetProcessId();
|
||||
|
|
@ -546,34 +538,34 @@ public:
|
|||
return this->GetIdImpl();
|
||||
}
|
||||
|
||||
virtual bool IsSignaled() const override {
|
||||
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(m_kernel));
|
||||
virtual bool IsSignaled(KernelCore& kernel) const override {
|
||||
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
|
||||
return m_is_signaled;
|
||||
}
|
||||
|
||||
void DoWorkerTaskImpl();
|
||||
void DoWorkerTaskImpl(KernelCore& kernel);
|
||||
|
||||
private:
|
||||
void ChangeState(State new_state) {
|
||||
void ChangeState(KernelCore& kernel, State new_state) {
|
||||
if (m_state != new_state) {
|
||||
m_state = new_state;
|
||||
m_is_signaled = true;
|
||||
this->NotifyAvailable();
|
||||
this->NotifyAvailable(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
Result InitializeHandleTable(s32 size) {
|
||||
Result InitializeHandleTable(KernelCore& kernel, s32 size) {
|
||||
// Try to initialize the handle table.
|
||||
R_TRY(m_handle_table.Initialize(m_kernel, size));
|
||||
R_TRY(m_handle_table.Initialize(kernel, size));
|
||||
|
||||
// We succeeded, so note that we did.
|
||||
m_is_handle_table_initialized = true;
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void FinalizeHandleTable() {
|
||||
void FinalizeHandleTable(KernelCore& kernel) {
|
||||
// Finalize the table.
|
||||
m_handle_table.Finalize(m_kernel);
|
||||
m_handle_table.Finalize(kernel);
|
||||
|
||||
// Note that the table is finalized.
|
||||
m_is_handle_table_initialized = false;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -15,50 +18,45 @@ KReadableEvent::KReadableEvent(KernelCore& kernel) : KSynchronizationObject{kern
|
|||
|
||||
KReadableEvent::~KReadableEvent() = default;
|
||||
|
||||
void KReadableEvent::Initialize(KEvent* parent) {
|
||||
void KReadableEvent::Initialize(KernelCore& kernel, KEvent* parent) {
|
||||
m_is_signaled = false;
|
||||
m_parent = parent;
|
||||
|
||||
if (m_parent != nullptr) {
|
||||
m_parent->Open();
|
||||
m_parent->Open(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
bool KReadableEvent::IsSignaled() const {
|
||||
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(m_kernel));
|
||||
|
||||
bool KReadableEvent::IsSignaled(KernelCore& kernel) const {
|
||||
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
|
||||
return m_is_signaled;
|
||||
}
|
||||
|
||||
void KReadableEvent::Destroy() {
|
||||
void KReadableEvent::Destroy(KernelCore& kernel) {
|
||||
if (m_parent) {
|
||||
{
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
m_parent->OnReadableEventDestroyed();
|
||||
}
|
||||
m_parent->Close();
|
||||
m_parent->Close(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
Result KReadableEvent::Signal() {
|
||||
KScopedSchedulerLock lk{m_kernel};
|
||||
|
||||
Result KReadableEvent::Signal(KernelCore& kernel) {
|
||||
KScopedSchedulerLock lk{kernel};
|
||||
if (!m_is_signaled) {
|
||||
m_is_signaled = true;
|
||||
this->NotifyAvailable();
|
||||
this->NotifyAvailable(kernel);
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result KReadableEvent::Clear() {
|
||||
this->Reset();
|
||||
|
||||
Result KReadableEvent::Clear(KernelCore& kernel) {
|
||||
this->Reset(kernel);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result KReadableEvent::Reset() {
|
||||
KScopedSchedulerLock lk{m_kernel};
|
||||
Result KReadableEvent::Reset(KernelCore& kernel) {
|
||||
KScopedSchedulerLock lk{kernel};
|
||||
|
||||
R_UNLESS(m_is_signaled, ResultInvalidState);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -20,19 +23,17 @@ public:
|
|||
explicit KReadableEvent(KernelCore& kernel);
|
||||
~KReadableEvent() override;
|
||||
|
||||
void Initialize(KEvent* parent);
|
||||
void Initialize(KernelCore& kernel, KEvent* parent);
|
||||
|
||||
KEvent* GetParent() const {
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
Result Signal();
|
||||
Result Clear();
|
||||
|
||||
bool IsSignaled() const override;
|
||||
void Destroy() override;
|
||||
|
||||
Result Reset();
|
||||
Result Signal(KernelCore& kernel);
|
||||
Result Clear(KernelCore& kernel);
|
||||
bool IsSignaled(KernelCore& kernel) const override;
|
||||
void Destroy(KernelCore& kernel) override;
|
||||
Result Reset(KernelCore& kernel);
|
||||
|
||||
private:
|
||||
bool m_is_signaled{};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||
|
|
@ -16,12 +16,15 @@ namespace Kernel {
|
|||
constexpr s64 DefaultTimeout = 10000000000; // 10 seconds
|
||||
|
||||
KResourceLimit::KResourceLimit(KernelCore& kernel)
|
||||
: KAutoObjectWithSlabHeapAndContainer{kernel}, m_lock{m_kernel}, m_cond_var{m_kernel} {}
|
||||
: KAutoObjectWithSlabHeapAndContainer{kernel}
|
||||
, m_lock{kernel}
|
||||
, m_cond_var{kernel}
|
||||
{}
|
||||
KResourceLimit::~KResourceLimit() = default;
|
||||
|
||||
void KResourceLimit::Initialize() {}
|
||||
|
||||
void KResourceLimit::Finalize() {}
|
||||
void KResourceLimit::Finalize(KernelCore& kernel) {}
|
||||
|
||||
s64 KResourceLimit::GetLimitValue(LimitableResource which) const {
|
||||
const auto index = static_cast<std::size_t>(which);
|
||||
|
|
@ -87,11 +90,11 @@ Result KResourceLimit::SetLimitValue(LimitableResource which, s64 value) {
|
|||
R_SUCCEED();
|
||||
}
|
||||
|
||||
bool KResourceLimit::Reserve(LimitableResource which, s64 value) {
|
||||
return Reserve(which, value, m_kernel.HardwareTimer().GetTick() + DefaultTimeout);
|
||||
bool KResourceLimit::Reserve(KernelCore& kernel, LimitableResource which, s64 value) {
|
||||
return Reserve(kernel, which, value, kernel.HardwareTimer().GetTick() + DefaultTimeout);
|
||||
}
|
||||
|
||||
bool KResourceLimit::Reserve(LimitableResource which, s64 value, s64 timeout) {
|
||||
bool KResourceLimit::Reserve(KernelCore& kernel, LimitableResource which, s64 value, s64 timeout) {
|
||||
ASSERT(value >= 0);
|
||||
const auto index = static_cast<std::size_t>(which);
|
||||
KScopedLightLock lk(m_lock);
|
||||
|
|
@ -119,7 +122,7 @@ bool KResourceLimit::Reserve(LimitableResource which, s64 value, s64 timeout) {
|
|||
}
|
||||
|
||||
if (m_current_hints[index] + value <= m_limit_values[index] &&
|
||||
(timeout < 0 || m_kernel.HardwareTimer().GetTick() < timeout)) {
|
||||
(timeout < 0 || kernel.HardwareTimer().GetTick() < timeout)) {
|
||||
m_waiter_count++;
|
||||
m_cond_var.Wait(std::addressof(m_lock), timeout, false);
|
||||
m_waiter_count--;
|
||||
|
|
@ -131,11 +134,11 @@ bool KResourceLimit::Reserve(LimitableResource which, s64 value, s64 timeout) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void KResourceLimit::Release(LimitableResource which, s64 value) {
|
||||
Release(which, value, value);
|
||||
void KResourceLimit::Release(KernelCore& kernel, LimitableResource which, s64 value) {
|
||||
Release(kernel, which, value, value);
|
||||
}
|
||||
|
||||
void KResourceLimit::Release(LimitableResource which, s64 value, s64 hint) {
|
||||
void KResourceLimit::Release(KernelCore& kernel, LimitableResource which, s64 value, s64 hint) {
|
||||
ASSERT(value >= 0);
|
||||
ASSERT(hint >= 0);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -32,7 +35,7 @@ public:
|
|||
~KResourceLimit() override;
|
||||
|
||||
void Initialize();
|
||||
void Finalize() override;
|
||||
void Finalize(KernelCore& kernel) override;
|
||||
|
||||
s64 GetLimitValue(LimitableResource which) const;
|
||||
s64 GetCurrentValue(LimitableResource which) const;
|
||||
|
|
@ -41,12 +44,12 @@ public:
|
|||
|
||||
Result SetLimitValue(LimitableResource which, s64 value);
|
||||
|
||||
bool Reserve(LimitableResource which, s64 value);
|
||||
bool Reserve(LimitableResource which, s64 value, s64 timeout);
|
||||
void Release(LimitableResource which, s64 value);
|
||||
void Release(LimitableResource which, s64 value, s64 hint);
|
||||
bool Reserve(KernelCore& kernel, LimitableResource which, s64 value);
|
||||
bool Reserve(KernelCore& kernel, LimitableResource which, s64 value, s64 timeout);
|
||||
void Release(KernelCore& kernel, LimitableResource which, s64 value);
|
||||
void Release(KernelCore& kernel, LimitableResource which, s64 value, s64 hint);
|
||||
|
||||
static void PostDestroy(uintptr_t arg) {}
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}
|
||||
|
||||
private:
|
||||
using ResourceArray = std::array<s64, static_cast<std::size_t>(LimitableResource::Count)>;
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ void KScheduler::RequestScheduleOnInterrupt() {
|
|||
|
||||
void KScheduler::DisableScheduling(KernelCore& kernel) {
|
||||
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() >= 0);
|
||||
GetCurrentThread(kernel).DisableDispatch();
|
||||
GetCurrentThread(kernel).DisableDispatch(kernel);
|
||||
}
|
||||
|
||||
void KScheduler::EnableScheduling(KernelCore& kernel, u64 cores_needing_scheduling) {
|
||||
|
|
@ -74,7 +74,7 @@ void KScheduler::EnableScheduling(KernelCore& kernel, u64 cores_needing_scheduli
|
|||
scheduler->RescheduleOtherCores(cores_needing_scheduling);
|
||||
|
||||
if (GetCurrentThread(kernel).GetDisableDispatchCount() > 1) {
|
||||
GetCurrentThread(kernel).EnableDispatch();
|
||||
GetCurrentThread(kernel).EnableDispatch(kernel);
|
||||
} else {
|
||||
scheduler->RescheduleCurrentCore();
|
||||
}
|
||||
|
|
@ -85,10 +85,10 @@ void KScheduler::RescheduleCurrentHLEThread(KernelCore& kernel) {
|
|||
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() == 1);
|
||||
|
||||
// Ensure dummy threads that are waiting block.
|
||||
GetCurrentThread(kernel).DummyThreadBeginWait();
|
||||
GetCurrentThread(kernel).DummyThreadBeginWait(kernel);
|
||||
|
||||
ASSERT(GetCurrentThread(kernel).GetState() != ThreadState::Waiting);
|
||||
GetCurrentThread(kernel).EnableDispatch();
|
||||
GetCurrentThread(kernel).EnableDispatch(kernel);
|
||||
}
|
||||
|
||||
u64 KScheduler::UpdateHighestPriorityThreads(KernelCore& kernel) {
|
||||
|
|
@ -107,13 +107,13 @@ void KScheduler::Schedule() {
|
|||
}
|
||||
|
||||
void KScheduler::ScheduleOnInterrupt() {
|
||||
GetCurrentThread(m_kernel).DisableDispatch();
|
||||
GetCurrentThread(m_kernel).DisableDispatch(m_kernel);
|
||||
Schedule();
|
||||
GetCurrentThread(m_kernel).EnableDispatch();
|
||||
GetCurrentThread(m_kernel).EnableDispatch(m_kernel);
|
||||
}
|
||||
|
||||
void KScheduler::PreemptSingleCore() {
|
||||
GetCurrentThread(m_kernel).DisableDispatch();
|
||||
GetCurrentThread(m_kernel).DisableDispatch(m_kernel);
|
||||
|
||||
auto* thread = GetCurrentThreadPointer(m_kernel);
|
||||
auto& previous_scheduler = m_kernel.Scheduler(thread->GetCurrentCore());
|
||||
|
|
@ -121,14 +121,14 @@ void KScheduler::PreemptSingleCore() {
|
|||
|
||||
Common::Fiber::YieldTo(thread->GetHostContext(), *m_switch_fiber);
|
||||
|
||||
GetCurrentThread(m_kernel).EnableDispatch();
|
||||
GetCurrentThread(m_kernel).EnableDispatch(m_kernel);
|
||||
}
|
||||
|
||||
void KScheduler::RescheduleCurrentCore() {
|
||||
ASSERT(!m_kernel.IsPhantomModeForSingleCore());
|
||||
ASSERT(GetCurrentThread(m_kernel).GetDisableDispatchCount() == 1);
|
||||
|
||||
GetCurrentThread(m_kernel).EnableDispatch();
|
||||
GetCurrentThread(m_kernel).EnableDispatch(m_kernel);
|
||||
|
||||
if (m_state.needs_scheduling.load()) {
|
||||
// Disable interrupts, and then check again if rescheduling is needed.
|
||||
|
|
@ -141,9 +141,9 @@ void KScheduler::RescheduleCurrentCore() {
|
|||
void KScheduler::RescheduleCurrentCoreImpl() {
|
||||
// Check that scheduling is needed.
|
||||
if (m_state.needs_scheduling.load()) [[likely]] {
|
||||
GetCurrentThread(m_kernel).DisableDispatch();
|
||||
GetCurrentThread(m_kernel).DisableDispatch(m_kernel);
|
||||
Schedule();
|
||||
GetCurrentThread(m_kernel).EnableDispatch();
|
||||
GetCurrentThread(m_kernel).EnableDispatch(m_kernel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +179,7 @@ void KScheduler::Activate() {
|
|||
}
|
||||
|
||||
void KScheduler::OnThreadStart() {
|
||||
GetCurrentThread(m_kernel).EnableDispatch();
|
||||
GetCurrentThread(m_kernel).EnableDispatch(m_kernel);
|
||||
}
|
||||
|
||||
u64 KScheduler::UpdateHighestPriorityThread(KThread* highest_thread) {
|
||||
|
|
@ -319,13 +319,13 @@ u64 KScheduler::UpdateHighestPriorityThreadsImpl(KernelCore& kernel) {
|
|||
}
|
||||
|
||||
// HACK: any waiting dummy threads can wake up now.
|
||||
kernel.GlobalSchedulerContext().WakeupWaitingDummyThreads();
|
||||
kernel.GlobalSchedulerContext().WakeupWaitingDummyThreads(kernel);
|
||||
|
||||
// HACK: if we are a dummy thread, and we need to go sleep, indicate
|
||||
// that for when the lock is released.
|
||||
KThread* const cur_thread = GetCurrentThreadPointer(kernel);
|
||||
if (cur_thread->IsDummyThread() && cur_thread->GetState() != ThreadState::Runnable) {
|
||||
cur_thread->RequestDummyThreadWait();
|
||||
cur_thread->RequestDummyThreadWait(kernel);
|
||||
}
|
||||
|
||||
return cores_needing_scheduling;
|
||||
|
|
@ -386,7 +386,7 @@ void KScheduler::SwitchThread(KThread* next_thread) {
|
|||
// cpu::SwitchThreadLocalRegion(GetInteger(next_thread->GetThreadLocalRegionAddress()));
|
||||
|
||||
// Update the thread's cpu time differential in TLS, if relevant.
|
||||
next_thread->UpdateTlsThreadCpuTime(cur_tick);
|
||||
next_thread->UpdateTlsThreadCpuTime(m_kernel, cur_tick);
|
||||
}
|
||||
|
||||
void KScheduler::ScheduleImpl() {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -11,34 +14,42 @@ namespace Kernel {
|
|||
|
||||
class KScopedResourceReservation {
|
||||
public:
|
||||
explicit KScopedResourceReservation(KResourceLimit* l, LimitableResource r, s64 v, s64 timeout)
|
||||
: m_limit(l), m_value(v), m_resource(r) {
|
||||
explicit KScopedResourceReservation(KernelCore& kernel, KResourceLimit* l, LimitableResource r, s64 v, s64 timeout)
|
||||
: m_kernel{kernel}
|
||||
, m_limit(l)
|
||||
, m_value(v)
|
||||
, m_resource(r)
|
||||
{
|
||||
if (m_limit && m_value) {
|
||||
m_succeeded = m_limit->Reserve(m_resource, m_value, timeout);
|
||||
m_succeeded = m_limit->Reserve(kernel, m_resource, m_value, timeout);
|
||||
} else {
|
||||
m_succeeded = true;
|
||||
}
|
||||
}
|
||||
|
||||
explicit KScopedResourceReservation(KResourceLimit* l, LimitableResource r, s64 v = 1)
|
||||
: m_limit(l), m_value(v), m_resource(r) {
|
||||
explicit KScopedResourceReservation(KernelCore& kernel, KResourceLimit* l, LimitableResource r, s64 v = 1)
|
||||
: m_kernel{kernel}
|
||||
, m_limit(l)
|
||||
, m_value(v)
|
||||
, m_resource(r)
|
||||
{
|
||||
if (m_limit && m_value) {
|
||||
m_succeeded = m_limit->Reserve(m_resource, m_value);
|
||||
m_succeeded = m_limit->Reserve(kernel, m_resource, m_value);
|
||||
} else {
|
||||
m_succeeded = true;
|
||||
}
|
||||
}
|
||||
|
||||
explicit KScopedResourceReservation(const KProcess* p, LimitableResource r, s64 v, s64 t)
|
||||
: KScopedResourceReservation(p->GetResourceLimit(), r, v, t) {}
|
||||
explicit KScopedResourceReservation(KernelCore& kernel, const KProcess* p, LimitableResource r, s64 v, s64 t)
|
||||
: KScopedResourceReservation(kernel, p->GetResourceLimit(), r, v, t) {}
|
||||
|
||||
explicit KScopedResourceReservation(const KProcess* p, LimitableResource r, s64 v = 1)
|
||||
: KScopedResourceReservation(p->GetResourceLimit(), r, v) {}
|
||||
explicit KScopedResourceReservation(KernelCore& kernel, const KProcess* p, LimitableResource r, s64 v = 1)
|
||||
: KScopedResourceReservation(kernel, p->GetResourceLimit(), r, v) {}
|
||||
|
||||
~KScopedResourceReservation() noexcept {
|
||||
if (m_limit && m_value && m_succeeded) {
|
||||
// Resource was not committed, release the reservation.
|
||||
m_limit->Release(m_resource, m_value);
|
||||
m_limit->Release(m_kernel, m_resource, m_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -52,6 +63,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
KernelCore& m_kernel;
|
||||
KResourceLimit* m_limit{};
|
||||
s64 m_value{};
|
||||
LimitableResource m_resource{};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -15,18 +18,18 @@ namespace Kernel {
|
|||
KServerPort::KServerPort(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
||||
KServerPort::~KServerPort() = default;
|
||||
|
||||
void KServerPort::Initialize(KPort* parent) {
|
||||
void KServerPort::Initialize(KernelCore& kernel, KPort* parent) {
|
||||
// Set member variables.
|
||||
m_parent = parent;
|
||||
}
|
||||
|
||||
bool KServerPort::IsLight() const {
|
||||
bool KServerPort::IsLight(KernelCore& kernel) const {
|
||||
return this->GetParent()->IsLight();
|
||||
}
|
||||
|
||||
void KServerPort::CleanupSessions() {
|
||||
void KServerPort::CleanupSessions(KernelCore& kernel) {
|
||||
// Ensure our preconditions are met.
|
||||
if (this->IsLight()) {
|
||||
if (this->IsLight(kernel)) {
|
||||
ASSERT(m_session_list.empty());
|
||||
} else {
|
||||
ASSERT(m_light_session_list.empty());
|
||||
|
|
@ -37,7 +40,7 @@ void KServerPort::CleanupSessions() {
|
|||
// Get the last session in the list.
|
||||
KServerSession* session = nullptr;
|
||||
{
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
if (!m_session_list.empty()) {
|
||||
session = std::addressof(m_session_list.front());
|
||||
m_session_list.pop_front();
|
||||
|
|
@ -46,7 +49,7 @@ void KServerPort::CleanupSessions() {
|
|||
|
||||
// Close the session.
|
||||
if (session != nullptr) {
|
||||
session->Close();
|
||||
session->Close(kernel);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
|
@ -57,7 +60,7 @@ void KServerPort::CleanupSessions() {
|
|||
// Get the last session in the list.
|
||||
KLightServerSession* session = nullptr;
|
||||
{
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
if (!m_light_session_list.empty()) {
|
||||
session = std::addressof(m_light_session_list.front());
|
||||
m_light_session_list.pop_front();
|
||||
|
|
@ -66,60 +69,60 @@ void KServerPort::CleanupSessions() {
|
|||
|
||||
// Close the session.
|
||||
if (session != nullptr) {
|
||||
session->Close();
|
||||
session->Close(kernel);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KServerPort::Destroy() {
|
||||
void KServerPort::Destroy(KernelCore& kernel) {
|
||||
// Note with our parent that we're closed.
|
||||
m_parent->OnServerClosed();
|
||||
m_parent->OnServerClosed(kernel);
|
||||
|
||||
// Perform necessary cleanup of our session lists.
|
||||
this->CleanupSessions();
|
||||
this->CleanupSessions(kernel);
|
||||
|
||||
// Close our reference to our parent.
|
||||
m_parent->Close();
|
||||
m_parent->Close(kernel);
|
||||
}
|
||||
|
||||
bool KServerPort::IsSignaled() const {
|
||||
if (this->IsLight()) {
|
||||
bool KServerPort::IsSignaled(KernelCore& kernel) const {
|
||||
if (this->IsLight(kernel)) {
|
||||
return !m_light_session_list.empty();
|
||||
} else {
|
||||
return !m_session_list.empty();
|
||||
}
|
||||
}
|
||||
|
||||
void KServerPort::EnqueueSession(KServerSession* session) {
|
||||
ASSERT(!this->IsLight());
|
||||
void KServerPort::EnqueueSession(KernelCore& kernel, KServerSession* session) {
|
||||
ASSERT(!this->IsLight(kernel));
|
||||
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
// Add the session to our queue.
|
||||
m_session_list.push_back(*session);
|
||||
if (m_session_list.size() == 1) {
|
||||
this->NotifyAvailable();
|
||||
this->NotifyAvailable(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
void KServerPort::EnqueueSession(KLightServerSession* session) {
|
||||
ASSERT(this->IsLight());
|
||||
void KServerPort::EnqueueSession(KernelCore& kernel, KLightServerSession* session) {
|
||||
ASSERT(this->IsLight(kernel));
|
||||
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
// Add the session to our queue.
|
||||
m_light_session_list.push_back(*session);
|
||||
if (m_light_session_list.size() == 1) {
|
||||
this->NotifyAvailable();
|
||||
this->NotifyAvailable(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
KServerSession* KServerPort::AcceptSession() {
|
||||
ASSERT(!this->IsLight());
|
||||
KServerSession* KServerPort::AcceptSession(KernelCore& kernel) {
|
||||
ASSERT(!this->IsLight(kernel));
|
||||
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
// Return the first session in the list.
|
||||
if (m_session_list.empty()) {
|
||||
|
|
@ -131,10 +134,10 @@ KServerSession* KServerPort::AcceptSession() {
|
|||
return session;
|
||||
}
|
||||
|
||||
KLightServerSession* KServerPort::AcceptLightSession() {
|
||||
ASSERT(this->IsLight());
|
||||
KLightServerSession* KServerPort::AcceptLightSession(KernelCore& kernel) {
|
||||
ASSERT(this->IsLight(kernel));
|
||||
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
// Return the first session in the list.
|
||||
if (m_light_session_list.empty()) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -26,29 +29,29 @@ public:
|
|||
explicit KServerPort(KernelCore& kernel);
|
||||
~KServerPort() override;
|
||||
|
||||
void Initialize(KPort* parent);
|
||||
void Initialize(KernelCore& kernel, KPort* parent);
|
||||
|
||||
void EnqueueSession(KServerSession* session);
|
||||
void EnqueueSession(KLightServerSession* session);
|
||||
void EnqueueSession(KernelCore& kernel, KServerSession* session);
|
||||
void EnqueueSession(KernelCore& kernel, KLightServerSession* session);
|
||||
|
||||
KServerSession* AcceptSession();
|
||||
KLightServerSession* AcceptLightSession();
|
||||
KServerSession* AcceptSession(KernelCore& kernel);
|
||||
KLightServerSession* AcceptLightSession(KernelCore& kernel);
|
||||
|
||||
const KPort* GetParent() const {
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
bool IsLight() const;
|
||||
bool IsLight(KernelCore& kernel) const;
|
||||
|
||||
// Overridden virtual functions.
|
||||
void Destroy() override;
|
||||
bool IsSignaled() const override;
|
||||
void Destroy(KernelCore& kernel) override;
|
||||
bool IsSignaled(KernelCore& kernel) const override;
|
||||
|
||||
private:
|
||||
using SessionList = Common::IntrusiveListBaseTraits<KServerSession>::ListType;
|
||||
using LightSessionList = Common::IntrusiveListBaseTraits<KLightServerSession>::ListType;
|
||||
|
||||
void CleanupSessions();
|
||||
void CleanupSessions(KernelCore& kernel);
|
||||
|
||||
SessionList m_session_list{};
|
||||
LightSessionList m_light_session_list{};
|
||||
|
|
|
|||
|
|
@ -554,7 +554,7 @@ Result ReceiveMessage(KernelCore& kernel, bool& recv_list_broken, uint64_t dst_m
|
|||
recv_list_broken = false;
|
||||
|
||||
// Set the server process for the request.
|
||||
request->SetServerProcess(std::addressof(dst_process));
|
||||
request->SetServerProcess(kernel, std::addressof(dst_process));
|
||||
|
||||
// Determine the message buffers.
|
||||
u32 *dst_msg_ptr, *src_msg_ptr;
|
||||
|
|
@ -1076,19 +1076,17 @@ void ReplyAsyncError(KProcess* to_process, uint64_t to_msg_buf, size_t to_msg_bu
|
|||
} // namespace
|
||||
|
||||
KServerSession::KServerSession(KernelCore& kernel)
|
||||
: KSynchronizationObject{kernel}, m_lock{m_kernel} {}
|
||||
: KSynchronizationObject{kernel}, m_lock{kernel} {}
|
||||
|
||||
KServerSession::~KServerSession() = default;
|
||||
|
||||
void KServerSession::Destroy() {
|
||||
m_parent->OnServerClosed();
|
||||
|
||||
this->CleanupRequests();
|
||||
|
||||
m_parent->Close();
|
||||
void KServerSession::Destroy(KernelCore& kernel) {
|
||||
m_parent->OnServerClosed(kernel);
|
||||
this->CleanupRequests(kernel);
|
||||
m_parent->Close(kernel);
|
||||
}
|
||||
|
||||
Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server_buffer_size,
|
||||
Result KServerSession::ReceiveRequest(KernelCore& kernel, uintptr_t server_message, uintptr_t server_buffer_size,
|
||||
KPhysicalAddress server_message_paddr,
|
||||
std::shared_ptr<Service::HLERequestContext>* out_context,
|
||||
std::weak_ptr<Service::SessionRequestManager> manager) {
|
||||
|
|
@ -1100,7 +1098,7 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||
KThread* client_thread;
|
||||
|
||||
{
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
// Ensure that we can service the request.
|
||||
R_UNLESS(!m_parent->IsClientClosed(), ResultSessionClosed);
|
||||
|
|
@ -1120,11 +1118,11 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||
R_UNLESS(client_thread != nullptr, ResultSessionClosed);
|
||||
|
||||
// Open the client thread.
|
||||
client_thread->Open();
|
||||
client_thread->Open(kernel);
|
||||
}
|
||||
|
||||
SCOPE_EXIT {
|
||||
client_thread->Close();
|
||||
client_thread->Close(kernel);
|
||||
};
|
||||
|
||||
// Set the request as our current.
|
||||
|
|
@ -1146,13 +1144,13 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||
Core::Memory::Memory& memory{client_thread->GetOwnerProcess()->GetMemory()};
|
||||
u32* cmd_buf{reinterpret_cast<u32*>(memory.GetPointer(client_message))};
|
||||
*out_context =
|
||||
std::make_shared<Service::HLERequestContext>(m_kernel, memory, this, client_thread);
|
||||
std::make_shared<Service::HLERequestContext>(kernel, memory, this, client_thread);
|
||||
(*out_context)->SetSessionRequestManager(manager);
|
||||
(*out_context)->PopulateFromIncomingCommandBuffer(cmd_buf);
|
||||
// We succeeded.
|
||||
R_SUCCEED();
|
||||
} else {
|
||||
result = ReceiveMessage(m_kernel, recv_list_broken, server_message, server_buffer_size,
|
||||
result = ReceiveMessage(kernel, recv_list_broken, server_message, server_buffer_size,
|
||||
server_message_paddr, *client_thread, client_message,
|
||||
client_buffer_size, this, request);
|
||||
}
|
||||
|
|
@ -1164,11 +1162,11 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||
|
||||
// Clear the current request.
|
||||
{
|
||||
KScopedSchedulerLock sl(m_kernel);
|
||||
KScopedSchedulerLock sl(kernel);
|
||||
ASSERT(m_current_request == request);
|
||||
m_current_request = nullptr;
|
||||
if (!m_request_list.empty()) {
|
||||
this->NotifyAvailable();
|
||||
this->NotifyAvailable(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1176,7 +1174,7 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||
{
|
||||
// After we reply, close our reference to the request.
|
||||
SCOPE_EXIT {
|
||||
request->Close();
|
||||
request->Close(kernel);
|
||||
};
|
||||
|
||||
// Get the event to check whether the request is async.
|
||||
|
|
@ -1195,13 +1193,13 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||
client_pt.UnlockForIpcUserBuffer(client_message, client_buffer_size);
|
||||
|
||||
// Signal the event.
|
||||
event->Signal();
|
||||
event->Signal(kernel);
|
||||
} else {
|
||||
// End the client thread's wait.
|
||||
KScopedSchedulerLock sl(m_kernel);
|
||||
KScopedSchedulerLock sl(kernel);
|
||||
|
||||
if (!client_thread->IsTerminationRequested()) {
|
||||
client_thread->EndWait(result_for_client);
|
||||
client_thread->EndWait(kernel, result_for_client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1217,7 +1215,7 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||
R_RETURN(result);
|
||||
}
|
||||
|
||||
Result KServerSession::SendReply(uintptr_t server_message, uintptr_t server_buffer_size,
|
||||
Result KServerSession::SendReply(KernelCore& kernel, uintptr_t server_message, uintptr_t server_buffer_size,
|
||||
KPhysicalAddress server_message_paddr, bool is_hle) {
|
||||
// Lock the session.
|
||||
KScopedLightLock lk{m_lock};
|
||||
|
|
@ -1225,7 +1223,7 @@ Result KServerSession::SendReply(uintptr_t server_message, uintptr_t server_buff
|
|||
// Get the request.
|
||||
KSessionRequest* request;
|
||||
{
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
// Get the current request.
|
||||
request = m_current_request;
|
||||
|
|
@ -1234,13 +1232,13 @@ Result KServerSession::SendReply(uintptr_t server_message, uintptr_t server_buff
|
|||
// Clear the current request, since we're processing it.
|
||||
m_current_request = nullptr;
|
||||
if (!m_request_list.empty()) {
|
||||
this->NotifyAvailable();
|
||||
this->NotifyAvailable(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
// Close reference to the request once we're done processing it.
|
||||
SCOPE_EXIT {
|
||||
request->Close();
|
||||
request->Close(kernel);
|
||||
};
|
||||
|
||||
// Extract relevant information from the request.
|
||||
|
|
@ -1259,7 +1257,7 @@ Result KServerSession::SendReply(uintptr_t server_message, uintptr_t server_buff
|
|||
// HLE servers write directly to a pointer to the thread command buffer. Therefore
|
||||
// the reply has already been written in this case.
|
||||
} else {
|
||||
result = SendMessage(m_kernel, server_message, server_buffer_size, server_message_paddr,
|
||||
result = SendMessage(kernel, server_message, server_buffer_size, server_message_paddr,
|
||||
*client_thread, client_message, client_buffer_size, this, request);
|
||||
}
|
||||
} else if (!is_hle) {
|
||||
|
|
@ -1271,7 +1269,7 @@ Result KServerSession::SendReply(uintptr_t server_message, uintptr_t server_buff
|
|||
(client_process != nullptr) ? std::addressof(client_process->GetPageTable()) : nullptr;
|
||||
|
||||
// Cleanup server handles.
|
||||
result = CleanupServerHandles(m_kernel, server_message, server_buffer_size,
|
||||
result = CleanupServerHandles(kernel, server_message, server_buffer_size,
|
||||
server_message_paddr);
|
||||
|
||||
// Cleanup mappings.
|
||||
|
|
@ -1309,13 +1307,13 @@ Result KServerSession::SendReply(uintptr_t server_message, uintptr_t server_buff
|
|||
client_page_table->UnlockForIpcUserBuffer(client_message, client_buffer_size);
|
||||
|
||||
// Signal the event.
|
||||
event->Signal();
|
||||
event->Signal(kernel);
|
||||
} else {
|
||||
// End the client thread's wait.
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
if (!client_thread->IsTerminationRequested()) {
|
||||
client_thread->EndWait(client_result);
|
||||
client_thread->EndWait(kernel, client_result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1323,45 +1321,45 @@ Result KServerSession::SendReply(uintptr_t server_message, uintptr_t server_buff
|
|||
R_RETURN(result);
|
||||
}
|
||||
|
||||
Result KServerSession::OnRequest(KSessionRequest* request) {
|
||||
Result KServerSession::OnRequest(KernelCore& kernel, KSessionRequest* request) {
|
||||
// Create the wait queue.
|
||||
ThreadQueueImplForKServerSessionRequest wait_queue{m_kernel};
|
||||
ThreadQueueImplForKServerSessionRequest wait_queue{kernel};
|
||||
|
||||
{
|
||||
// Lock the scheduler.
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
// Ensure that we can handle new requests.
|
||||
R_UNLESS(!m_parent->IsServerClosed(), ResultSessionClosed);
|
||||
|
||||
// Check that we're not terminating.
|
||||
R_UNLESS(!GetCurrentThread(m_kernel).IsTerminationRequested(), ResultTerminationRequested);
|
||||
R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(), ResultTerminationRequested);
|
||||
|
||||
// Get whether we're empty.
|
||||
const bool was_empty = m_request_list.empty();
|
||||
|
||||
// Add the request to the list.
|
||||
request->Open();
|
||||
request->Open(kernel);
|
||||
m_request_list.push_back(*request);
|
||||
|
||||
// If we were empty, signal.
|
||||
if (was_empty) {
|
||||
this->NotifyAvailable();
|
||||
this->NotifyAvailable(kernel);
|
||||
}
|
||||
|
||||
// If we have a request event, this is asynchronous, and we don't need to wait.
|
||||
R_SUCCEED_IF(request->GetEvent() != nullptr);
|
||||
|
||||
// This is a synchronous request, so we should wait for our request to complete.
|
||||
GetCurrentThread(m_kernel).SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::IPC);
|
||||
GetCurrentThread(m_kernel).BeginWait(std::addressof(wait_queue));
|
||||
GetCurrentThread(kernel).SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::IPC);
|
||||
GetCurrentThread(kernel).BeginWait(kernel, std::addressof(wait_queue));
|
||||
}
|
||||
|
||||
return GetCurrentThread(m_kernel).GetWaitResult();
|
||||
return GetCurrentThread(kernel).GetWaitResult();
|
||||
}
|
||||
|
||||
bool KServerSession::IsSignaled() const {
|
||||
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(m_kernel));
|
||||
bool KServerSession::IsSignaled(KernelCore& kernel) const {
|
||||
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
|
||||
|
||||
// If the client is closed, we're always signaled.
|
||||
if (m_parent->IsClientClosed()) {
|
||||
|
|
@ -1372,7 +1370,7 @@ bool KServerSession::IsSignaled() const {
|
|||
return !m_request_list.empty() && m_current_request == nullptr;
|
||||
}
|
||||
|
||||
void KServerSession::CleanupRequests() {
|
||||
void KServerSession::CleanupRequests(KernelCore& kernel) {
|
||||
KScopedLightLock lk(m_lock);
|
||||
|
||||
// Clean up any pending requests.
|
||||
|
|
@ -1380,7 +1378,7 @@ void KServerSession::CleanupRequests() {
|
|||
// Get the next request.
|
||||
KSessionRequest* request = nullptr;
|
||||
{
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
if (m_current_request) {
|
||||
// Choose the current request if we have one.
|
||||
|
|
@ -1400,7 +1398,7 @@ void KServerSession::CleanupRequests() {
|
|||
|
||||
// Close a reference to the request once it's cleaned up.
|
||||
SCOPE_EXIT {
|
||||
request->Close();
|
||||
request->Close(kernel);
|
||||
};
|
||||
|
||||
// Extract relevant information from the request.
|
||||
|
|
@ -1430,20 +1428,20 @@ void KServerSession::CleanupRequests() {
|
|||
client_page_table->UnlockForIpcUserBuffer(client_message, client_buffer_size);
|
||||
|
||||
// Signal the event.
|
||||
event->Signal();
|
||||
event->Signal(kernel);
|
||||
} else {
|
||||
// End the client thread's wait.
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
if (!client_thread->IsTerminationRequested()) {
|
||||
client_thread->EndWait(ResultSessionClosed);
|
||||
client_thread->EndWait(kernel, ResultSessionClosed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KServerSession::OnClientClosed() {
|
||||
void KServerSession::OnClientClosed(KernelCore& kernel) {
|
||||
KScopedLightLock lk{m_lock};
|
||||
|
||||
// Handle any pending requests.
|
||||
|
|
@ -1458,12 +1456,12 @@ void KServerSession::OnClientClosed() {
|
|||
|
||||
// Get the next request.
|
||||
{
|
||||
KScopedSchedulerLock sl{m_kernel};
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
|
||||
if (m_current_request != nullptr && m_current_request != prev_request) {
|
||||
// Set the request, open a reference as we process it.
|
||||
request = m_current_request;
|
||||
request->Open();
|
||||
request->Open(kernel);
|
||||
cur_request = true;
|
||||
|
||||
// Get thread and event for the request.
|
||||
|
|
@ -1499,14 +1497,14 @@ void KServerSession::OnClientClosed() {
|
|||
|
||||
// Ensure that we close the request when done.
|
||||
SCOPE_EXIT {
|
||||
request->Close();
|
||||
request->Close(kernel);
|
||||
};
|
||||
|
||||
// If we're terminating, close a reference to the thread and event.
|
||||
if (terminate) {
|
||||
thread->Close();
|
||||
thread->Close(kernel);
|
||||
if (event != nullptr) {
|
||||
event->Close();
|
||||
event->Close(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1530,12 +1528,12 @@ void KServerSession::OnClientClosed() {
|
|||
client_pt.UnlockForIpcUserBuffer(request->GetAddress(), request->GetSize());
|
||||
|
||||
// Signal the event.
|
||||
event->Signal();
|
||||
event->Signal(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
// Notify.
|
||||
this->NotifyAvailable(ResultSessionClosed);
|
||||
this->NotifyAvailable(kernel, ResultSessionClosed);
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -36,7 +39,7 @@ public:
|
|||
explicit KServerSession(KernelCore& kernel);
|
||||
~KServerSession() override;
|
||||
|
||||
void Destroy() override;
|
||||
void Destroy(KernelCore& kernel) override;
|
||||
|
||||
void Initialize(KSession* p) {
|
||||
m_parent = p;
|
||||
|
|
@ -46,29 +49,29 @@ public:
|
|||
return m_parent;
|
||||
}
|
||||
|
||||
bool IsSignaled() const override;
|
||||
void OnClientClosed();
|
||||
bool IsSignaled(KernelCore& kernel) const override;
|
||||
void OnClientClosed(KernelCore& kernel);
|
||||
|
||||
Result OnRequest(KSessionRequest* request);
|
||||
Result SendReply(uintptr_t server_message, uintptr_t server_buffer_size,
|
||||
Result OnRequest(KernelCore& kernel, KSessionRequest* request);
|
||||
Result SendReply(KernelCore& kernel, uintptr_t server_message, uintptr_t server_buffer_size,
|
||||
KPhysicalAddress server_message_paddr, bool is_hle = false);
|
||||
Result ReceiveRequest(uintptr_t server_message, uintptr_t server_buffer_size,
|
||||
Result ReceiveRequest(KernelCore& kernel, uintptr_t server_message, uintptr_t server_buffer_size,
|
||||
KPhysicalAddress server_message_paddr,
|
||||
std::shared_ptr<Service::HLERequestContext>* out_context = nullptr,
|
||||
std::weak_ptr<Service::SessionRequestManager> manager = {});
|
||||
|
||||
Result SendReplyHLE() {
|
||||
R_RETURN(this->SendReply(0, 0, 0, true));
|
||||
Result SendReplyHLE(KernelCore& kernel) {
|
||||
R_RETURN(this->SendReply(kernel, 0, 0, 0, true));
|
||||
}
|
||||
|
||||
Result ReceiveRequestHLE(std::shared_ptr<Service::HLERequestContext>* out_context,
|
||||
Result ReceiveRequestHLE(KernelCore& kernel, std::shared_ptr<Service::HLERequestContext>* out_context,
|
||||
std::weak_ptr<Service::SessionRequestManager> manager) {
|
||||
R_RETURN(this->ReceiveRequest(0, 0, 0, out_context, manager));
|
||||
R_RETURN(this->ReceiveRequest(kernel, 0, 0, 0, out_context, manager));
|
||||
}
|
||||
|
||||
private:
|
||||
/// Frees up waiting client sessions when this server session is about to die
|
||||
void CleanupRequests();
|
||||
void CleanupRequests(KernelCore& kernel);
|
||||
|
||||
/// KSession that owns this KServerSession
|
||||
KSession* m_parent{};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -13,12 +16,12 @@ KSession::KSession(KernelCore& kernel)
|
|||
: KAutoObjectWithSlabHeapAndContainer{kernel}, m_server{kernel}, m_client{kernel} {}
|
||||
KSession::~KSession() = default;
|
||||
|
||||
void KSession::Initialize(KClientPort* client_port, uintptr_t name) {
|
||||
void KSession::Initialize(KernelCore& kernel, KClientPort* client_port, uintptr_t name) {
|
||||
// Increment reference count.
|
||||
// Because reference count is one on creation, this will result
|
||||
// in a reference count of two. Thus, when both server and client are closed
|
||||
// this object will be destroyed.
|
||||
this->Open();
|
||||
this->Open(kernel);
|
||||
|
||||
// Create our sub sessions.
|
||||
KAutoObject::Create(std::addressof(m_server));
|
||||
|
|
@ -33,45 +36,45 @@ void KSession::Initialize(KClientPort* client_port, uintptr_t name) {
|
|||
m_name = name;
|
||||
|
||||
// Set our owner process.
|
||||
m_process = GetCurrentProcessPointer(m_kernel);
|
||||
m_process->Open();
|
||||
m_process = GetCurrentProcessPointer(kernel);
|
||||
m_process->Open(kernel);
|
||||
|
||||
// Set our port.
|
||||
m_port = client_port;
|
||||
if (m_port != nullptr) {
|
||||
m_port->Open();
|
||||
m_port->Open(kernel);
|
||||
}
|
||||
|
||||
// Mark initialized.
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
void KSession::Finalize() {
|
||||
void KSession::Finalize(KernelCore& kernel) {
|
||||
if (m_port != nullptr) {
|
||||
m_port->OnSessionFinalized();
|
||||
m_port->Close();
|
||||
m_port->OnSessionFinalized(kernel);
|
||||
m_port->Close(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
void KSession::OnServerClosed() {
|
||||
void KSession::OnServerClosed(KernelCore& kernel) {
|
||||
if (this->GetState() == State::Normal) {
|
||||
this->SetState(State::ServerClosed);
|
||||
m_client.OnServerClosed();
|
||||
}
|
||||
}
|
||||
|
||||
void KSession::OnClientClosed() {
|
||||
void KSession::OnClientClosed(KernelCore& kernel) {
|
||||
if (this->GetState() == State::Normal) {
|
||||
SetState(State::ClientClosed);
|
||||
m_server.OnClientClosed();
|
||||
this->SetState(State::ClientClosed);
|
||||
m_server.OnClientClosed(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
void KSession::PostDestroy(uintptr_t arg) {
|
||||
void KSession::PostDestroy(KernelCore& kernel, uintptr_t arg) {
|
||||
// Release the session count resource the owner process holds.
|
||||
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
||||
owner->GetResourceLimit()->Release(LimitableResource::SessionCountMax, 1);
|
||||
owner->Close();
|
||||
owner->GetResourceLimit()->Release(kernel, LimitableResource::SessionCountMax, 1);
|
||||
owner->Close(kernel);
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -21,8 +24,8 @@ public:
|
|||
explicit KSession(KernelCore& kernel);
|
||||
~KSession() override;
|
||||
|
||||
void Initialize(KClientPort* port, uintptr_t name);
|
||||
void Finalize() override;
|
||||
void Initialize(KernelCore& kernel, KClientPort* port, uintptr_t name);
|
||||
void Finalize(KernelCore& kernel) override;
|
||||
|
||||
bool IsInitialized() const override {
|
||||
return m_initialized;
|
||||
|
|
@ -32,11 +35,9 @@ public:
|
|||
return reinterpret_cast<uintptr_t>(m_process);
|
||||
}
|
||||
|
||||
static void PostDestroy(uintptr_t arg);
|
||||
|
||||
void OnServerClosed();
|
||||
|
||||
void OnClientClosed();
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg);
|
||||
void OnServerClosed(KernelCore& kernel);
|
||||
void OnClientClosed(KernelCore& kernel);
|
||||
|
||||
bool IsServerClosed() const {
|
||||
return this->GetState() != State::Normal;
|
||||
|
|
@ -46,8 +47,8 @@ public:
|
|||
return this->GetState() != State::Normal;
|
||||
}
|
||||
|
||||
Result OnRequest(KSessionRequest* request) {
|
||||
R_RETURN(m_server.OnRequest(request));
|
||||
Result OnRequest(KernelCore& kernel, KSessionRequest* request) {
|
||||
R_RETURN(m_server.OnRequest(kernel, request));
|
||||
}
|
||||
|
||||
KClientSession& GetClientSession() {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -18,7 +21,7 @@ Result KSessionRequest::SessionMappings::PushMap(KProcessAddress client, KProces
|
|||
} else {
|
||||
// Allocate a page for the extra mappings.
|
||||
if (m_mappings == nullptr) {
|
||||
KPageBuffer* page_buffer = KPageBuffer::Allocate(m_kernel);
|
||||
KPageBuffer* page_buffer = KPageBuffer::Allocate(kernel);
|
||||
R_UNLESS(page_buffer != nullptr, ResultOutOfMemory);
|
||||
|
||||
m_mappings = reinterpret_cast<Mapping*>(page_buffer);
|
||||
|
|
@ -54,7 +57,7 @@ Result KSessionRequest::SessionMappings::PushExchange(KProcessAddress client,
|
|||
|
||||
void KSessionRequest::SessionMappings::Finalize() {
|
||||
if (m_mappings) {
|
||||
KPageBuffer::Free(m_kernel, reinterpret_cast<KPageBuffer*>(m_mappings));
|
||||
KPageBuffer::Free(kernel, reinterpret_cast<KPageBuffer*>(m_mappings));
|
||||
m_mappings = nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -56,7 +59,7 @@ public:
|
|||
};
|
||||
|
||||
public:
|
||||
explicit SessionMappings(KernelCore& kernel) : m_kernel(kernel) {}
|
||||
explicit SessionMappings(KernelCore& kernel) : kernel(kernel) {}
|
||||
|
||||
void Initialize() {}
|
||||
void Finalize();
|
||||
|
|
@ -155,7 +158,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
KernelCore& m_kernel;
|
||||
KernelCore& kernel;
|
||||
std::array<Mapping, NumStaticMappings> m_static_mappings{};
|
||||
Mapping* m_mappings{};
|
||||
u8 m_num_send{};
|
||||
|
|
@ -174,26 +177,26 @@ public:
|
|||
return req;
|
||||
}
|
||||
|
||||
void Destroy() override {
|
||||
this->Finalize();
|
||||
KSessionRequest::Free(m_kernel, this);
|
||||
void Destroy(KernelCore& kernel) override {
|
||||
this->Finalize(kernel);
|
||||
KSessionRequest::Free(kernel, this);
|
||||
}
|
||||
|
||||
void Initialize(KEvent* event, uintptr_t address, size_t size) {
|
||||
void Initialize(KernelCore& kernel, KEvent* event, uintptr_t address, size_t size) {
|
||||
m_mappings.Initialize();
|
||||
|
||||
m_thread = GetCurrentThreadPointer(m_kernel);
|
||||
m_thread = GetCurrentThreadPointer(kernel);
|
||||
m_event = event;
|
||||
m_address = address;
|
||||
m_size = size;
|
||||
|
||||
m_thread->Open();
|
||||
m_thread->Open(kernel);
|
||||
if (m_event != nullptr) {
|
||||
m_event->Open();
|
||||
m_event->Open(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
static void PostDestroy(uintptr_t arg) {}
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}
|
||||
|
||||
KThread* GetThread() const {
|
||||
return m_thread;
|
||||
|
|
@ -211,9 +214,9 @@ public:
|
|||
return m_server;
|
||||
}
|
||||
|
||||
void SetServerProcess(KProcess* process) {
|
||||
void SetServerProcess(KernelCore& kernel, KProcess* process) {
|
||||
m_server = process;
|
||||
m_server->Open();
|
||||
m_server->Open(kernel);
|
||||
}
|
||||
|
||||
void ClearThread() {
|
||||
|
|
@ -289,17 +292,16 @@ public:
|
|||
|
||||
private:
|
||||
// NOTE: This is public and virtual in Nintendo's kernel.
|
||||
void Finalize() override {
|
||||
void Finalize(KernelCore& kernel) override {
|
||||
m_mappings.Finalize();
|
||||
|
||||
if (m_thread) {
|
||||
m_thread->Close();
|
||||
m_thread->Close(kernel);
|
||||
}
|
||||
if (m_event) {
|
||||
m_event->Close();
|
||||
m_event->Close(kernel);
|
||||
}
|
||||
if (m_server) {
|
||||
m_server->Close();
|
||||
m_server->Close(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Kernel {
|
|||
KSharedMemory::KSharedMemory(KernelCore& kernel) : KAutoObjectWithSlabHeapAndContainer{kernel} {}
|
||||
KSharedMemory::~KSharedMemory() = default;
|
||||
|
||||
Result KSharedMemory::Initialize(Core::DeviceMemory& device_memory, KProcess* owner_process,
|
||||
Result KSharedMemory::Initialize(KernelCore& kernel, Core::DeviceMemory& device_memory, KProcess* owner_process,
|
||||
Svc::MemoryPermission owner_permission,
|
||||
Svc::MemoryPermission user_permission, std::size_t size) {
|
||||
// Set members.
|
||||
|
|
@ -31,11 +31,10 @@ Result KSharedMemory::Initialize(Core::DeviceMemory& device_memory, KProcess* ow
|
|||
const size_t num_pages = Common::DivideUp(size, PageSize);
|
||||
|
||||
// Get the resource limit.
|
||||
KResourceLimit* reslimit = m_kernel.GetSystemResourceLimit();
|
||||
KResourceLimit* reslimit = kernel.GetSystemResourceLimit();
|
||||
|
||||
// Reserve memory for ourselves.
|
||||
KScopedResourceReservation memory_reservation(reslimit, LimitableResource::PhysicalMemoryMax,
|
||||
size);
|
||||
KScopedResourceReservation memory_reservation(kernel, reslimit, LimitableResource::PhysicalMemoryMax, size);
|
||||
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
||||
|
||||
// Allocate the memory.
|
||||
|
|
@ -43,12 +42,11 @@ Result KSharedMemory::Initialize(Core::DeviceMemory& device_memory, KProcess* ow
|
|||
//! HACK: Open continuous mapping from sysmodule pool.
|
||||
auto option = KMemoryManager::EncodeOption(KMemoryManager::Pool::Secure,
|
||||
KMemoryManager::Direction::FromBack);
|
||||
m_physical_address = m_kernel.MemoryManager().AllocateAndOpenContinuous(num_pages, 1, option);
|
||||
m_physical_address = kernel.MemoryManager().AllocateAndOpenContinuous(num_pages, 1, option);
|
||||
R_UNLESS(m_physical_address != 0, ResultOutOfMemory);
|
||||
|
||||
//! Insert the result into our page group.
|
||||
m_page_group.emplace(m_kernel,
|
||||
std::addressof(m_kernel.GetSystemSystemResource().GetBlockInfoManager()));
|
||||
m_page_group.emplace(kernel, std::addressof(kernel.GetSystemSystemResource().GetBlockInfoManager()));
|
||||
m_page_group->AddBlock(m_physical_address, num_pages);
|
||||
|
||||
// Commit our reservation.
|
||||
|
|
@ -56,7 +54,7 @@ Result KSharedMemory::Initialize(Core::DeviceMemory& device_memory, KProcess* ow
|
|||
|
||||
// Set our resource limit.
|
||||
m_resource_limit = reslimit;
|
||||
m_resource_limit->Open();
|
||||
m_resource_limit->Open(kernel);
|
||||
|
||||
// Mark initialized.
|
||||
m_is_initialized = true;
|
||||
|
|
@ -69,14 +67,14 @@ Result KSharedMemory::Initialize(Core::DeviceMemory& device_memory, KProcess* ow
|
|||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void KSharedMemory::Finalize() {
|
||||
void KSharedMemory::Finalize(KernelCore& kernel) {
|
||||
// Close and finalize the page group.
|
||||
m_page_group->Close(m_kernel);
|
||||
m_page_group->Close(kernel);
|
||||
m_page_group->Finalize();
|
||||
|
||||
// Release the memory reservation.
|
||||
m_resource_limit->Release(LimitableResource::PhysicalMemoryMax, m_size);
|
||||
m_resource_limit->Close();
|
||||
m_resource_limit->Release(kernel, LimitableResource::PhysicalMemoryMax, m_size);
|
||||
m_resource_limit->Close(kernel);
|
||||
}
|
||||
|
||||
Result KSharedMemory::Map(KProcess& target_process, KProcessAddress address, std::size_t map_size,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -26,7 +29,7 @@ public:
|
|||
explicit KSharedMemory(KernelCore& kernel);
|
||||
~KSharedMemory() override;
|
||||
|
||||
Result Initialize(Core::DeviceMemory& device_memory_, KProcess* owner_process_,
|
||||
Result Initialize(KernelCore& kernel, Core::DeviceMemory& device_memory_, KProcess* owner_process_,
|
||||
Svc::MemoryPermission owner_permission_,
|
||||
Svc::MemoryPermission user_permission_, std::size_t size_);
|
||||
|
||||
|
|
@ -66,12 +69,12 @@ public:
|
|||
return m_device_memory->GetPointer<u8>(m_physical_address + offset);
|
||||
}
|
||||
|
||||
void Finalize() override;
|
||||
void Finalize(KernelCore& kernel) override;
|
||||
|
||||
bool IsInitialized() const override {
|
||||
return m_is_initialized;
|
||||
}
|
||||
static void PostDestroy(uintptr_t arg) {}
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}
|
||||
|
||||
private:
|
||||
Core::DeviceMemory* m_device_memory{};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -18,12 +21,10 @@ namespace {
|
|||
|
||||
class ThreadQueueImplForKSynchronizationObjectWait final : public KThreadQueueWithoutEndWait {
|
||||
public:
|
||||
ThreadQueueImplForKSynchronizationObjectWait(KernelCore& kernel, KSynchronizationObject** o,
|
||||
KSynchronizationObject::ThreadListNode* n, s32 c)
|
||||
ThreadQueueImplForKSynchronizationObjectWait(KernelCore& kernel, KSynchronizationObject** o, KSynchronizationObject::ThreadListNode* n, s32 c)
|
||||
: KThreadQueueWithoutEndWait(kernel), m_objects(o), m_nodes(n), m_count(c) {}
|
||||
|
||||
void NotifyAvailable(KThread* waiting_thread, KSynchronizationObject* signaled_object,
|
||||
Result wait_result) override {
|
||||
void NotifyAvailable(KernelCore& kernel, KThread* waiting_thread, KSynchronizationObject* signaled_object, Result wait_result) override {
|
||||
// Determine the sync index, and unlink all nodes.
|
||||
s32 sync_index = -1;
|
||||
for (auto i = 0; i < m_count; ++i) {
|
||||
|
|
@ -43,10 +44,10 @@ public:
|
|||
waiting_thread->ClearCancellable();
|
||||
|
||||
// Invoke the base end wait handler.
|
||||
KThreadQueue::EndWait(waiting_thread, wait_result);
|
||||
KThreadQueue::EndWait(kernel, waiting_thread, wait_result);
|
||||
}
|
||||
|
||||
void CancelWait(KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
void CancelWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||
// Remove all nodes from our list.
|
||||
for (auto i = 0; i < m_count; ++i) {
|
||||
m_objects[i]->UnlinkNode(std::addressof(m_nodes[i]));
|
||||
|
|
@ -56,7 +57,7 @@ public:
|
|||
waiting_thread->ClearCancellable();
|
||||
|
||||
// Invoke the base cancel wait handler.
|
||||
KThreadQueue::CancelWait(waiting_thread, wait_result, cancel_timer_task);
|
||||
KThreadQueue::CancelWait(kernel, waiting_thread, wait_result, cancel_timer_task);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -67,9 +68,9 @@ private:
|
|||
|
||||
} // namespace
|
||||
|
||||
void KSynchronizationObject::Finalize() {
|
||||
void KSynchronizationObject::Finalize(KernelCore& kernel) {
|
||||
this->OnFinalizeSynchronizationObject();
|
||||
KAutoObject::Finalize();
|
||||
KAutoObject::Finalize(kernel);
|
||||
}
|
||||
|
||||
Result KSynchronizationObject::Wait(KernelCore& kernel, s32* out_index,
|
||||
|
|
@ -98,7 +99,7 @@ Result KSynchronizationObject::Wait(KernelCore& kernel, s32* out_index,
|
|||
for (auto i = 0; i < num_objects; ++i) {
|
||||
ASSERT(objects[i] != nullptr);
|
||||
|
||||
if (objects[i]->IsSignaled()) {
|
||||
if (objects[i]->IsSignaled(kernel)) {
|
||||
*out_index = i;
|
||||
slp.CancelSleep();
|
||||
R_THROW(ResultSuccess);
|
||||
|
|
@ -134,7 +135,7 @@ Result KSynchronizationObject::Wait(KernelCore& kernel, s32* out_index,
|
|||
|
||||
// Wait for an object to be signaled.
|
||||
wait_queue.SetHardwareTimer(timer);
|
||||
thread->BeginWait(std::addressof(wait_queue));
|
||||
thread->BeginWait(kernel, std::addressof(wait_queue));
|
||||
thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::Synchronization);
|
||||
}
|
||||
|
||||
|
|
@ -149,26 +150,26 @@ KSynchronizationObject::KSynchronizationObject(KernelCore& kernel) : KAutoObject
|
|||
|
||||
KSynchronizationObject::~KSynchronizationObject() = default;
|
||||
|
||||
void KSynchronizationObject::NotifyAvailable(Result result) {
|
||||
KScopedSchedulerLock sl(m_kernel);
|
||||
void KSynchronizationObject::NotifyAvailable(KernelCore& kernel, Result result) {
|
||||
KScopedSchedulerLock sl(kernel);
|
||||
|
||||
// If we're not signaled, we've nothing to notify.
|
||||
if (!this->IsSignaled()) {
|
||||
if (!this->IsSignaled(kernel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Iterate over each thread.
|
||||
for (auto* cur_node = m_thread_list_head; cur_node != nullptr; cur_node = cur_node->next) {
|
||||
cur_node->thread->NotifyAvailable(this, result);
|
||||
cur_node->thread->NotifyAvailable(kernel, this, result);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<KThread*> KSynchronizationObject::GetWaitingThreadsForDebugging() const {
|
||||
std::vector<KThread*> KSynchronizationObject::GetWaitingThreadsForDebugging(KernelCore& kernel) const {
|
||||
std::vector<KThread*> threads;
|
||||
|
||||
// If debugging, dump the list of waiters.
|
||||
{
|
||||
KScopedSchedulerLock lock(m_kernel);
|
||||
KScopedSchedulerLock lock(kernel);
|
||||
for (auto* cur_node = m_thread_list_head; cur_node != nullptr; cur_node = cur_node->next) {
|
||||
threads.emplace_back(cur_node->thread);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -24,14 +27,13 @@ public:
|
|||
KThread* thread{};
|
||||
};
|
||||
|
||||
static Result Wait(KernelCore& kernel, s32* out_index, KSynchronizationObject** objects,
|
||||
const s32 num_objects, s64 timeout);
|
||||
static Result Wait(KernelCore& kernel, s32* out_index, KSynchronizationObject** objects, const s32 num_objects, s64 timeout);
|
||||
|
||||
void Finalize() override;
|
||||
void Finalize(KernelCore& kernel) override;
|
||||
|
||||
virtual bool IsSignaled() const = 0;
|
||||
virtual bool IsSignaled(KernelCore& kernel) const = 0;
|
||||
|
||||
std::vector<KThread*> GetWaitingThreadsForDebugging() const;
|
||||
std::vector<KThread*> GetWaitingThreadsForDebugging(KernelCore& kernel) const;
|
||||
|
||||
void LinkNode(ThreadListNode* node_) {
|
||||
// Link the node to the list.
|
||||
|
|
@ -71,9 +73,9 @@ protected:
|
|||
|
||||
virtual void OnFinalizeSynchronizationObject() {}
|
||||
|
||||
void NotifyAvailable(Result result);
|
||||
void NotifyAvailable() {
|
||||
return this->NotifyAvailable(ResultSuccess);
|
||||
void NotifyAvailable(KernelCore& kernel, Result result);
|
||||
void NotifyAvailable(KernelCore& kernel) {
|
||||
return this->NotifyAvailable(kernel, ResultSuccess);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -7,8 +10,7 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
Result KSecureSystemResource::Initialize(size_t size, KResourceLimit* resource_limit,
|
||||
KMemoryManager::Pool pool) {
|
||||
Result KSecureSystemResource::Initialize(KernelCore& kernel, size_t size, KResourceLimit* resource_limit, KMemoryManager::Pool pool) {
|
||||
// Set members.
|
||||
m_resource_limit = resource_limit;
|
||||
m_resource_size = size;
|
||||
|
|
@ -18,18 +20,17 @@ Result KSecureSystemResource::Initialize(size_t size, KResourceLimit* resource_l
|
|||
const size_t secure_size = this->CalculateRequiredSecureMemorySize();
|
||||
|
||||
// Reserve memory for our secure resource.
|
||||
KScopedResourceReservation memory_reservation(
|
||||
m_resource_limit, Svc::LimitableResource::PhysicalMemoryMax, secure_size);
|
||||
KScopedResourceReservation memory_reservation(kernel, m_resource_limit, Svc::LimitableResource::PhysicalMemoryMax, secure_size);
|
||||
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
||||
|
||||
// Allocate secure memory.
|
||||
R_TRY(KSystemControl::AllocateSecureMemory(m_kernel, std::addressof(m_resource_address),
|
||||
R_TRY(KSystemControl::AllocateSecureMemory(kernel, std::addressof(m_resource_address),
|
||||
m_resource_size, static_cast<u32>(m_resource_pool)));
|
||||
ASSERT(m_resource_address != 0);
|
||||
|
||||
// Ensure we clean up the secure memory, if we fail past this point.
|
||||
ON_RESULT_FAILURE {
|
||||
KSystemControl::FreeSecureMemory(m_kernel, m_resource_address, m_resource_size,
|
||||
KSystemControl::FreeSecureMemory(kernel, m_resource_address, m_resource_size,
|
||||
static_cast<u32>(m_resource_pool));
|
||||
};
|
||||
|
||||
|
|
@ -40,9 +41,9 @@ Result KSecureSystemResource::Initialize(size_t size, KResourceLimit* resource_l
|
|||
|
||||
// Get resource pointer.
|
||||
KPhysicalAddress resource_paddr =
|
||||
KPageTable::GetHeapPhysicalAddress(m_kernel, m_resource_address);
|
||||
KPageTable::GetHeapPhysicalAddress(kernel, m_resource_address);
|
||||
auto* resource =
|
||||
m_kernel.System().DeviceMemory().GetPointer<KPageTableManager::RefCount>(resource_paddr);
|
||||
kernel.System().DeviceMemory().GetPointer<KPageTableManager::RefCount>(resource_paddr);
|
||||
|
||||
// Initialize slab heaps.
|
||||
m_dynamic_page_manager.Initialize(m_resource_address + rc_size, m_resource_size - rc_size,
|
||||
|
|
@ -66,7 +67,7 @@ Result KSecureSystemResource::Initialize(size_t size, KResourceLimit* resource_l
|
|||
memory_reservation.Commit();
|
||||
|
||||
// Open reference to our resource limit.
|
||||
m_resource_limit->Open();
|
||||
m_resource_limit->Open(kernel);
|
||||
|
||||
// Set ourselves as initialized.
|
||||
m_is_initialized = true;
|
||||
|
|
@ -74,26 +75,25 @@ Result KSecureSystemResource::Initialize(size_t size, KResourceLimit* resource_l
|
|||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void KSecureSystemResource::Finalize() {
|
||||
void KSecureSystemResource::Finalize(KernelCore& kernel) {
|
||||
// Check that we have no outstanding allocations.
|
||||
ASSERT(m_memory_block_slab_manager.GetUsed() == 0);
|
||||
ASSERT(m_block_info_manager.GetUsed() == 0);
|
||||
ASSERT(m_page_table_manager.GetUsed() == 0);
|
||||
|
||||
// Free our secure memory.
|
||||
KSystemControl::FreeSecureMemory(m_kernel, m_resource_address, m_resource_size,
|
||||
KSystemControl::FreeSecureMemory(kernel, m_resource_address, m_resource_size,
|
||||
static_cast<u32>(m_resource_pool));
|
||||
|
||||
// Release the memory reservation.
|
||||
m_resource_limit->Release(Svc::LimitableResource::PhysicalMemoryMax,
|
||||
m_resource_limit->Release(kernel, Svc::LimitableResource::PhysicalMemoryMax,
|
||||
this->CalculateRequiredSecureMemorySize());
|
||||
|
||||
// Close reference to our resource limit.
|
||||
m_resource_limit->Close();
|
||||
m_resource_limit->Close(kernel);
|
||||
}
|
||||
|
||||
size_t KSecureSystemResource::CalculateRequiredSecureMemorySize(size_t size,
|
||||
KMemoryManager::Pool pool) {
|
||||
size_t KSecureSystemResource::CalculateRequiredSecureMemorySize(size_t size, KMemoryManager::Pool pool) {
|
||||
return KSystemControl::CalculateRequiredSecureMemorySize(size, static_cast<u32>(pool));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -29,7 +32,7 @@ protected:
|
|||
}
|
||||
|
||||
public:
|
||||
virtual void Destroy() override {
|
||||
virtual void Destroy(KernelCore& kernel) override {
|
||||
UNREACHABLE_MSG("KSystemResource::Destroy() was called");
|
||||
}
|
||||
|
||||
|
|
@ -93,13 +96,13 @@ public:
|
|||
this->SetSecureResource();
|
||||
}
|
||||
|
||||
Result Initialize(size_t size, KResourceLimit* resource_limit, KMemoryManager::Pool pool);
|
||||
void Finalize();
|
||||
Result Initialize(KernelCore& kernel, size_t size, KResourceLimit* resource_limit, KMemoryManager::Pool pool);
|
||||
void Finalize(KernelCore& kernel);
|
||||
|
||||
bool IsInitialized() const {
|
||||
return m_is_initialized;
|
||||
}
|
||||
static void PostDestroy(uintptr_t arg) {}
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}
|
||||
|
||||
size_t CalculateRequiredSecureMemorySize() const {
|
||||
return CalculateRequiredSecureMemorySize(m_resource_size, m_resource_pool);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,4 +1,4 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
|
|
@ -181,21 +181,17 @@ public:
|
|||
return m_thread_id;
|
||||
}
|
||||
|
||||
void ContinueIfHasKernelWaiters() {
|
||||
void ContinueIfHasKernelWaiters(KernelCore& kernel) {
|
||||
if (GetNumKernelWaiters() > 0) {
|
||||
Continue();
|
||||
Continue(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
void SetBasePriority(s32 value);
|
||||
|
||||
Result Run();
|
||||
|
||||
void Exit();
|
||||
|
||||
Result Terminate();
|
||||
|
||||
ThreadState RequestTerminate();
|
||||
void SetBasePriority(KernelCore& kernel, s32 value);
|
||||
Result Run(KernelCore& kernel);
|
||||
void Exit(KernelCore& kernel);
|
||||
Result Terminate(KernelCore& kernel);
|
||||
ThreadState RequestTerminate(KernelCore& kernel);
|
||||
|
||||
u32 GetSuspendFlags() const {
|
||||
return m_suspend_allowed_flags & m_suspend_request_flags;
|
||||
|
|
@ -215,15 +211,11 @@ public:
|
|||
return m_suspend_request_flags != 0;
|
||||
}
|
||||
|
||||
void RequestSuspend(SuspendType type);
|
||||
|
||||
void Resume(SuspendType type);
|
||||
|
||||
void TrySuspend();
|
||||
|
||||
void UpdateState();
|
||||
|
||||
void Continue();
|
||||
void RequestSuspend(KernelCore& kernel, SuspendType type);
|
||||
void Resume(KernelCore& kernel, SuspendType type);
|
||||
void TrySuspend(KernelCore& kernel);
|
||||
void UpdateState(KernelCore& kernel);
|
||||
void Continue(KernelCore& kernel);
|
||||
|
||||
constexpr void SetSyncedIndex(s32 index) {
|
||||
m_synced_index = index;
|
||||
|
|
@ -262,7 +254,7 @@ public:
|
|||
m_thread_context.tpidr = value;
|
||||
}
|
||||
|
||||
void CloneFpuStatus();
|
||||
void CloneFpuStatus(KernelCore& kernel);
|
||||
|
||||
Svc::ThreadContext& GetContext() {
|
||||
return m_thread_context;
|
||||
|
|
@ -282,7 +274,7 @@ public:
|
|||
return m_thread_state.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
void SetState(ThreadState state);
|
||||
void SetState(KernelCore& kernel, ThreadState state);
|
||||
|
||||
StepState GetStepState() const {
|
||||
return m_step_state;
|
||||
|
|
@ -342,27 +334,27 @@ public:
|
|||
Svc::ArgumentHandleCountMax};
|
||||
}
|
||||
|
||||
u16 GetUserDisableCount() const;
|
||||
void SetInterruptFlag();
|
||||
void ClearInterruptFlag();
|
||||
u16 GetUserDisableCount(KernelCore& kernel) const;
|
||||
void SetInterruptFlag(KernelCore& kernel);
|
||||
void ClearInterruptFlag(KernelCore& kernel);
|
||||
|
||||
void UpdateTlsThreadCpuTime(s64 switch_tick);
|
||||
void UpdateTlsThreadCpuTime(KernelCore& kernel, s64 switch_tick);
|
||||
|
||||
KThread* GetLockOwner() const;
|
||||
KThread* GetLockOwner(KernelCore& kernel) const;
|
||||
|
||||
const KAffinityMask& GetAffinityMask() const {
|
||||
return m_physical_affinity_mask;
|
||||
}
|
||||
|
||||
Result GetCoreMask(s32* out_ideal_core, u64* out_affinity_mask);
|
||||
Result GetCoreMask(KernelCore& kernel, s32* out_ideal_core, u64* out_affinity_mask);
|
||||
|
||||
Result GetPhysicalCoreMask(s32* out_ideal_core, u64* out_affinity_mask);
|
||||
Result GetPhysicalCoreMask(KernelCore& kernel, s32* out_ideal_core, u64* out_affinity_mask);
|
||||
|
||||
Result SetCoreMask(s32 cpu_core_id, u64 v_affinity_mask);
|
||||
Result SetCoreMask(KernelCore& kernel, s32 cpu_core_id, u64 v_affinity_mask);
|
||||
|
||||
Result SetActivity(Svc::ThreadActivity activity);
|
||||
Result SetActivity(KernelCore& kernel, Svc::ThreadActivity activity);
|
||||
|
||||
Result Sleep(s64 timeout);
|
||||
Result Sleep(KernelCore& kernel, s64 timeout);
|
||||
|
||||
s64 GetYieldScheduleCount() const {
|
||||
return m_schedule_count;
|
||||
|
|
@ -372,7 +364,7 @@ public:
|
|||
m_schedule_count = count;
|
||||
}
|
||||
|
||||
void WaitCancel();
|
||||
void WaitCancel(KernelCore& kernel);
|
||||
|
||||
bool IsWaitCancelled() const {
|
||||
return m_wait_cancelled;
|
||||
|
|
@ -417,17 +409,17 @@ public:
|
|||
return reinterpret_cast<uintptr_t>(m_parent) | (m_resource_limit_release_hint ? 1 : 0);
|
||||
}
|
||||
|
||||
void Finalize() override;
|
||||
void Finalize(KernelCore& kernel) override;
|
||||
|
||||
bool IsSignaled() const override;
|
||||
bool IsSignaled(KernelCore& kernel) const override;
|
||||
|
||||
void OnTimer();
|
||||
void OnTimer(KernelCore& kernel);
|
||||
|
||||
void DoWorkerTaskImpl();
|
||||
void DoWorkerTaskImpl(KernelCore& kernel);
|
||||
|
||||
static void PostDestroy(uintptr_t arg);
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg);
|
||||
|
||||
static Result InitializeDummyThread(KThread* thread, KProcess* owner);
|
||||
static Result InitializeDummyThread(Core::System& system, KThread* thread, KProcess* owner);
|
||||
|
||||
static Result InitializeMainThread(Core::System& system, KThread* thread, s32 virt_core);
|
||||
|
||||
|
|
@ -514,19 +506,18 @@ public:
|
|||
return this->GetStackParameters().disable_count;
|
||||
}
|
||||
|
||||
void DisableDispatch() {
|
||||
ASSERT(GetCurrentThread(m_kernel).GetDisableDispatchCount() >= 0);
|
||||
void DisableDispatch(KernelCore& kernel) {
|
||||
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() >= 0);
|
||||
this->GetStackParameters().disable_count++;
|
||||
}
|
||||
|
||||
void EnableDispatch() {
|
||||
ASSERT(GetCurrentThread(m_kernel).GetDisableDispatchCount() > 0);
|
||||
void EnableDispatch(KernelCore& kernel) {
|
||||
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() > 0);
|
||||
this->GetStackParameters().disable_count--;
|
||||
}
|
||||
|
||||
void Pin(s32 current_core);
|
||||
|
||||
void Unpin();
|
||||
void Pin(KernelCore& kernel, s32 current_core);
|
||||
void Unpin(KernelCore& kernel);
|
||||
|
||||
void SetInExceptionHandler() {
|
||||
this->GetStackParameters().is_in_exception_handler = true;
|
||||
|
|
@ -592,18 +583,18 @@ public:
|
|||
return this->GetThreadType() == ThreadType::Dummy;
|
||||
}
|
||||
|
||||
void AddWaiter(KThread* thread);
|
||||
void AddWaiter(KernelCore& kernel, KThread* thread);
|
||||
|
||||
void RemoveWaiter(KThread* thread);
|
||||
void RemoveWaiter(KernelCore& kernel, KThread* thread);
|
||||
|
||||
Result GetThreadContext3(Svc::ThreadContext* out);
|
||||
Result GetThreadContext3(KernelCore& kernel, Svc::ThreadContext* out);
|
||||
|
||||
KThread* RemoveUserWaiterByKey(bool* out_has_waiters, KProcessAddress key) {
|
||||
return this->RemoveWaiterByKey(out_has_waiters, key, false);
|
||||
KThread* RemoveUserWaiterByKey(KernelCore& kernel, bool* out_has_waiters, KProcessAddress key) {
|
||||
return this->RemoveWaiterByKey(kernel, out_has_waiters, key, false);
|
||||
}
|
||||
|
||||
KThread* RemoveKernelWaiterByKey(bool* out_has_waiters, KProcessAddress key) {
|
||||
return this->RemoveWaiterByKey(out_has_waiters, key, true);
|
||||
KThread* RemoveKernelWaiterByKey(KernelCore& kernel, bool* out_has_waiters, KProcessAddress key) {
|
||||
return this->RemoveWaiterByKey(kernel, out_has_waiters, key, true);
|
||||
}
|
||||
|
||||
KProcessAddress GetAddressKey() const {
|
||||
|
|
@ -641,10 +632,10 @@ public:
|
|||
m_wait_queue = nullptr;
|
||||
}
|
||||
|
||||
void BeginWait(KThreadQueue* queue);
|
||||
void NotifyAvailable(KSynchronizationObject* signaled_object, Result wait_result);
|
||||
void EndWait(Result wait_result);
|
||||
void CancelWait(Result wait_result, bool cancel_timer_task);
|
||||
void BeginWait(KernelCore& kernel, KThreadQueue* queue);
|
||||
void NotifyAvailable(KernelCore& kernel, KSynchronizationObject* signaled_object, Result wait_result);
|
||||
void EndWait(KernelCore& kernel, Result wait_result);
|
||||
void CancelWait(KernelCore& kernel, Result wait_result, bool cancel_timer_task);
|
||||
|
||||
s32 GetNumKernelWaiters() const {
|
||||
return m_num_kernel_waiters;
|
||||
|
|
@ -662,9 +653,9 @@ public:
|
|||
// therefore will not block on guest kernel synchronization primitives. These methods handle
|
||||
// blocking as needed.
|
||||
|
||||
void RequestDummyThreadWait();
|
||||
void DummyThreadBeginWait();
|
||||
void DummyThreadEndWait();
|
||||
void RequestDummyThreadWait(KernelCore& kernel);
|
||||
void DummyThreadBeginWait(KernelCore& kernel);
|
||||
void DummyThreadEndWait(KernelCore& kernel);
|
||||
|
||||
uintptr_t GetArgument() const {
|
||||
return m_argument;
|
||||
|
|
@ -690,8 +681,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
KThread* RemoveWaiterByKey(bool* out_has_waiters, KProcessAddress key,
|
||||
bool is_kernel_address_key);
|
||||
KThread* RemoveWaiterByKey(KernelCore& kernel, bool* out_has_waiters, KProcessAddress key, bool is_kernel_address_key);
|
||||
|
||||
static constexpr size_t PriorityInheritanceCountMax = 10;
|
||||
union SyncObjectBuffer {
|
||||
|
|
@ -735,19 +725,19 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
void AddWaiterImpl(KThread* thread);
|
||||
void RemoveWaiterImpl(KThread* thread);
|
||||
void AddWaiterImpl(KernelCore& kernel, KThread* thread);
|
||||
void RemoveWaiterImpl(KernelCore& kernel, KThread* thread);
|
||||
static void RestorePriority(KernelCore& kernel, KThread* thread);
|
||||
|
||||
void StartTermination();
|
||||
void FinishTermination();
|
||||
void StartTermination(KernelCore& kernel);
|
||||
void FinishTermination(KernelCore& kernel);
|
||||
|
||||
void IncreaseBasePriority(s32 priority);
|
||||
void IncreaseBasePriority(KernelCore& kernel, s32 priority);
|
||||
|
||||
Result Initialize(KThreadFunction func, uintptr_t arg, KProcessAddress user_stack_top, s32 prio,
|
||||
Result Initialize(KernelCore& kernel, KThreadFunction func, uintptr_t arg, KProcessAddress user_stack_top, s32 prio,
|
||||
s32 virt_core, KProcess* owner, ThreadType type);
|
||||
|
||||
static Result InitializeThread(KThread* thread, KThreadFunction func, uintptr_t arg,
|
||||
static Result InitializeThread(KernelCore& kernel, KThread* thread, KThreadFunction func, uintptr_t arg,
|
||||
KProcessAddress user_stack_top, s32 prio, s32 core,
|
||||
KProcess* owner, ThreadType type,
|
||||
std::function<void()>&& init_func);
|
||||
|
|
@ -878,9 +868,8 @@ public:
|
|||
return m_waiting_lock_info;
|
||||
}
|
||||
|
||||
void AddHeldLock(LockWithPriorityInheritanceInfo* lock_info);
|
||||
LockWithPriorityInheritanceInfo* FindHeldLock(KProcessAddress address_key,
|
||||
bool is_kernel_address_key);
|
||||
void AddHeldLock(KernelCore& kernel, LockWithPriorityInheritanceInfo* lock_info);
|
||||
LockWithPriorityInheritanceInfo* FindHeldLock(KernelCore& kernel, KProcessAddress address_key, bool is_kernel_address_key);
|
||||
|
||||
private:
|
||||
using LockWithPriorityInheritanceInfoList =
|
||||
|
|
@ -996,7 +985,7 @@ public:
|
|||
if (m_kernel.IsShuttingDown()) {
|
||||
return;
|
||||
}
|
||||
GetCurrentThread(kernel).DisableDispatch();
|
||||
GetCurrentThread(kernel).DisableDispatch(kernel);
|
||||
}
|
||||
|
||||
~KScopedDisableDispatch();
|
||||
|
|
@ -1005,8 +994,8 @@ private:
|
|||
KernelCore& m_kernel;
|
||||
};
|
||||
|
||||
inline void KTimerTask::OnTimer() {
|
||||
static_cast<KThread*>(this)->OnTimer();
|
||||
inline void KTimerTask::OnTimer(KernelCore& kernel) {
|
||||
static_cast<KThread*>(this)->OnTimer(kernel);
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -7,17 +10,16 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
void KThreadQueue::NotifyAvailable(KThread* waiting_thread, KSynchronizationObject* signaled_object,
|
||||
Result wait_result) {
|
||||
void KThreadQueue::NotifyAvailable(KernelCore& kernel, KThread* waiting_thread, KSynchronizationObject* signaled_object, Result wait_result) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
void KThreadQueue::EndWait(KThread* waiting_thread, Result wait_result) {
|
||||
void KThreadQueue::EndWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result) {
|
||||
// Set the thread's wait result.
|
||||
waiting_thread->SetWaitResult(wait_result);
|
||||
|
||||
// Set the thread as runnable.
|
||||
waiting_thread->SetState(ThreadState::Runnable);
|
||||
waiting_thread->SetState(kernel, ThreadState::Runnable);
|
||||
|
||||
// Clear the thread's wait queue.
|
||||
waiting_thread->ClearWaitQueue();
|
||||
|
|
@ -28,12 +30,12 @@ void KThreadQueue::EndWait(KThread* waiting_thread, Result wait_result) {
|
|||
}
|
||||
}
|
||||
|
||||
void KThreadQueue::CancelWait(KThread* waiting_thread, Result wait_result, bool cancel_timer_task) {
|
||||
void KThreadQueue::CancelWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result, bool cancel_timer_task) {
|
||||
// Set the thread's wait result.
|
||||
waiting_thread->SetWaitResult(wait_result);
|
||||
|
||||
// Set the thread as runnable.
|
||||
waiting_thread->SetState(ThreadState::Runnable);
|
||||
waiting_thread->SetState(kernel, ThreadState::Runnable);
|
||||
|
||||
// Clear the thread's wait queue.
|
||||
waiting_thread->ClearWaitQueue();
|
||||
|
|
@ -44,7 +46,7 @@ void KThreadQueue::CancelWait(KThread* waiting_thread, Result wait_result, bool
|
|||
}
|
||||
}
|
||||
|
||||
void KThreadQueueWithoutEndWait::EndWait(KThread* waiting_thread, Result wait_result) {
|
||||
void KThreadQueueWithoutEndWait::EndWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -19,10 +22,9 @@ public:
|
|||
m_hardware_timer = timer;
|
||||
}
|
||||
|
||||
virtual void NotifyAvailable(KThread* waiting_thread, KSynchronizationObject* signaled_object,
|
||||
Result wait_result);
|
||||
virtual void EndWait(KThread* waiting_thread, Result wait_result);
|
||||
virtual void CancelWait(KThread* waiting_thread, Result wait_result, bool cancel_timer_task);
|
||||
virtual void NotifyAvailable(KernelCore& kernel, KThread* waiting_thread, KSynchronizationObject* signaled_object, Result wait_result);
|
||||
virtual void EndWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result);
|
||||
virtual void CancelWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result, bool cancel_timer_task);
|
||||
|
||||
private:
|
||||
KernelCore& m_kernel;
|
||||
|
|
@ -32,8 +34,7 @@ private:
|
|||
class KThreadQueueWithoutEndWait : public KThreadQueue {
|
||||
public:
|
||||
explicit KThreadQueueWithoutEndWait(KernelCore& kernel) : KThreadQueue(kernel) {}
|
||||
|
||||
void EndWait(KThread* waiting_thread, Result wait_result) override final;
|
||||
void EndWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result) override final;
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -7,6 +10,7 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
class KernelCore;
|
||||
class KTimerTask : public Common::IntrusiveRedBlackTreeBaseNode<KTimerTask> {
|
||||
public:
|
||||
static constexpr int Compare(const KTimerTask& lhs, const KTimerTask& rhs) {
|
||||
|
|
@ -30,7 +34,7 @@ public:
|
|||
// NOTE: This is virtual in Nintendo's kernel. Prior to 13.0.0, KWaitObject was also a
|
||||
// TimerTask; this is no longer the case. Since this is now KThread exclusive, we have
|
||||
// devirtualized (see inline declaration for this inside k_thread.h).
|
||||
void OnTimer();
|
||||
void OnTimer(KernelCore& kernel);
|
||||
|
||||
private:
|
||||
// Absolute time in nanoseconds
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/literals.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
using namespace Common::Literals;
|
||||
|
|
|
|||
|
|
@ -17,16 +17,15 @@ KTransferMemory::KTransferMemory(KernelCore& kernel)
|
|||
|
||||
KTransferMemory::~KTransferMemory() = default;
|
||||
|
||||
Result KTransferMemory::Initialize(KProcessAddress addr, std::size_t size,
|
||||
Svc::MemoryPermission own_perm) {
|
||||
Result KTransferMemory::Initialize(KernelCore& kernel, KProcessAddress addr, std::size_t size, Svc::MemoryPermission own_perm) {
|
||||
// Set members.
|
||||
m_owner = GetCurrentProcessPointer(m_kernel);
|
||||
m_owner = GetCurrentProcessPointer(kernel);
|
||||
|
||||
// Get the owner page table.
|
||||
auto& page_table = m_owner->GetPageTable();
|
||||
|
||||
// Construct the page group, guarding to make sure our state is valid on exit.
|
||||
m_page_group.emplace(m_kernel, page_table.GetBlockInfoManager());
|
||||
m_page_group.emplace(kernel, page_table.GetBlockInfoManager());
|
||||
auto pg_guard = SCOPE_GUARD {
|
||||
m_page_group.reset();
|
||||
};
|
||||
|
|
@ -36,7 +35,7 @@ Result KTransferMemory::Initialize(KProcessAddress addr, std::size_t size,
|
|||
ConvertToKMemoryPermission(own_perm)));
|
||||
|
||||
// Set remaining tracking members.
|
||||
m_owner->Open();
|
||||
m_owner->Open(kernel);
|
||||
m_owner_perm = own_perm;
|
||||
m_address = addr;
|
||||
m_is_initialized = true;
|
||||
|
|
@ -47,7 +46,7 @@ Result KTransferMemory::Initialize(KProcessAddress addr, std::size_t size,
|
|||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void KTransferMemory::Finalize() {
|
||||
void KTransferMemory::Finalize(KernelCore& kernel) {
|
||||
// Unlock.
|
||||
if (!m_is_mapped) {
|
||||
const size_t size = m_page_group->GetNumPages() * PageSize;
|
||||
|
|
@ -56,17 +55,17 @@ void KTransferMemory::Finalize() {
|
|||
}
|
||||
|
||||
// Close the page group.
|
||||
m_page_group->Close(m_kernel);
|
||||
m_page_group->Close(kernel);
|
||||
m_page_group->Finalize();
|
||||
}
|
||||
|
||||
void KTransferMemory::PostDestroy(uintptr_t arg) {
|
||||
void KTransferMemory::PostDestroy(KernelCore& kernel, uintptr_t arg) {
|
||||
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
||||
owner->GetResourceLimit()->Release(LimitableResource::TransferMemoryCountMax, 1);
|
||||
owner->Close();
|
||||
owner->GetResourceLimit()->Release(kernel, LimitableResource::TransferMemoryCountMax, 1);
|
||||
owner->Close(kernel);
|
||||
}
|
||||
|
||||
Result KTransferMemory::Map(KProcessAddress address, size_t size, Svc::MemoryPermission map_perm) {
|
||||
Result KTransferMemory::Map(KernelCore& kernel, KProcessAddress address, size_t size, Svc::MemoryPermission map_perm) {
|
||||
// Validate the size.
|
||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
|
||||
|
|
@ -83,7 +82,7 @@ Result KTransferMemory::Map(KProcessAddress address, size_t size, Svc::MemoryPer
|
|||
const KMemoryState state = (m_owner_perm == Svc::MemoryPermission::None)
|
||||
? KMemoryState::Transferred
|
||||
: KMemoryState::SharedTransferred;
|
||||
R_TRY(GetCurrentProcess(m_kernel).GetPageTable().MapPageGroup(
|
||||
R_TRY(GetCurrentProcess(kernel).GetPageTable().MapPageGroup(
|
||||
address, *m_page_group, state, KMemoryPermission::UserReadWrite));
|
||||
|
||||
// Mark ourselves as mapped.
|
||||
|
|
@ -92,7 +91,7 @@ Result KTransferMemory::Map(KProcessAddress address, size_t size, Svc::MemoryPer
|
|||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result KTransferMemory::Unmap(KProcessAddress address, size_t size) {
|
||||
Result KTransferMemory::Unmap(KernelCore& kernel, KProcessAddress address, size_t size) {
|
||||
// Validate the size.
|
||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
|
||||
|
|
@ -103,7 +102,7 @@ Result KTransferMemory::Unmap(KProcessAddress address, size_t size) {
|
|||
const KMemoryState state = (m_owner_perm == Svc::MemoryPermission::None)
|
||||
? KMemoryState::Transferred
|
||||
: KMemoryState::SharedTransferred;
|
||||
R_TRY(GetCurrentProcess(m_kernel).GetPageTable().UnmapPageGroup(address, *m_page_group, state));
|
||||
R_TRY(GetCurrentProcess(kernel).GetPageTable().UnmapPageGroup(address, *m_page_group, state));
|
||||
|
||||
// Mark ourselves as unmapped.
|
||||
ASSERT(m_is_mapped);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -30,9 +33,9 @@ public:
|
|||
explicit KTransferMemory(KernelCore& kernel);
|
||||
~KTransferMemory() override;
|
||||
|
||||
Result Initialize(KProcessAddress address, std::size_t size, Svc::MemoryPermission owner_perm);
|
||||
Result Initialize(KernelCore& kernel, KProcessAddress address, std::size_t size, Svc::MemoryPermission owner_perm);
|
||||
|
||||
void Finalize() override;
|
||||
void Finalize(KernelCore& kernel) override;
|
||||
|
||||
bool IsInitialized() const override {
|
||||
return m_is_initialized;
|
||||
|
|
@ -42,7 +45,7 @@ public:
|
|||
return reinterpret_cast<uintptr_t>(m_owner);
|
||||
}
|
||||
|
||||
static void PostDestroy(uintptr_t arg);
|
||||
static void PostDestroy(KernelCore& kernel, uintptr_t arg);
|
||||
|
||||
KProcess* GetOwner() const override {
|
||||
return m_owner;
|
||||
|
|
@ -54,8 +57,8 @@ public:
|
|||
|
||||
size_t GetSize() const;
|
||||
|
||||
Result Map(KProcessAddress address, size_t size, Svc::MemoryPermission map_perm);
|
||||
Result Unmap(KProcessAddress address, size_t size);
|
||||
Result Map(KernelCore& kernel, KProcessAddress address, size_t size, Svc::MemoryPermission map_perm);
|
||||
Result Unmap(KernelCore& kernel, KProcessAddress address, size_t size);
|
||||
|
||||
private:
|
||||
std::optional<KPageGroup> m_page_group{};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -10,8 +13,7 @@ namespace Kernel {
|
|||
class KWorkerTask : public KSynchronizationObject {
|
||||
public:
|
||||
explicit KWorkerTask(KernelCore& kernel);
|
||||
|
||||
void DoWorkerTask();
|
||||
void DoWorkerTask(KernelCore& kernel);
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -12,14 +15,14 @@ namespace Kernel {
|
|||
|
||||
KWorkerTask::KWorkerTask(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
||||
|
||||
void KWorkerTask::DoWorkerTask() {
|
||||
void KWorkerTask::DoWorkerTask(KernelCore& kernel) {
|
||||
if (auto* const thread = this->DynamicCast<KThread*>(); thread != nullptr) {
|
||||
return thread->DoWorkerTaskImpl();
|
||||
return thread->DoWorkerTaskImpl(kernel);
|
||||
} else {
|
||||
auto* const process = this->DynamicCast<KProcess*>();
|
||||
ASSERT(process != nullptr);
|
||||
|
||||
return process->DoWorkerTaskImpl();
|
||||
return process->DoWorkerTaskImpl(kernel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -32,9 +35,9 @@ void KWorkerTaskManager::AddTask(KernelCore& kernel, WorkerType type, KWorkerTas
|
|||
|
||||
void KWorkerTaskManager::AddTask(KernelCore& kernel, KWorkerTask* task) {
|
||||
KScopedSchedulerLock sl(kernel);
|
||||
m_waiting_thread.QueueWork([task]() {
|
||||
m_waiting_thread.QueueWork([&kernel, task]() {
|
||||
// Do the task.
|
||||
task->DoWorkerTask();
|
||||
task->DoWorkerTask(kernel);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,14 +121,14 @@ struct KernelCore::Impl {
|
|||
void TerminateAllProcesses() {
|
||||
std::scoped_lock lk{process_list_lock};
|
||||
for (auto& process : process_list) {
|
||||
process->Terminate();
|
||||
process->Close();
|
||||
process->Terminate(system.Kernel());
|
||||
process->Close(system.Kernel());
|
||||
process = nullptr;
|
||||
}
|
||||
process_list.clear();
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
void Shutdown(KernelCore& kernel) {
|
||||
is_shutting_down.store(true, std::memory_order_relaxed);
|
||||
SCOPE_EXIT {
|
||||
is_shutting_down.store(false, std::memory_order_relaxed);
|
||||
|
|
@ -137,7 +137,7 @@ struct KernelCore::Impl {
|
|||
CloseServices();
|
||||
|
||||
if (application_process) {
|
||||
application_process->Close();
|
||||
application_process->Close(system.Kernel());
|
||||
application_process = nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -149,9 +149,9 @@ struct KernelCore::Impl {
|
|||
preemption_event = nullptr;
|
||||
|
||||
// Cleanup persistent kernel objects
|
||||
auto CleanupObject = [](KAutoObject* obj) {
|
||||
auto CleanupObject = [&kernel](KAutoObject* obj) {
|
||||
if (obj) {
|
||||
obj->Close();
|
||||
obj->Close(kernel);
|
||||
obj = nullptr;
|
||||
}
|
||||
};
|
||||
|
|
@ -163,7 +163,7 @@ struct KernelCore::Impl {
|
|||
|
||||
for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) {
|
||||
if (shutdown_threads[core_id]) {
|
||||
shutdown_threads[core_id]->Close();
|
||||
shutdown_threads[core_id]->Close(kernel);
|
||||
shutdown_threads[core_id] = nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +178,7 @@ struct KernelCore::Impl {
|
|||
std::scoped_lock lk{registered_in_use_objects_lock};
|
||||
if (registered_in_use_objects.size()) {
|
||||
for (auto& object : registered_in_use_objects) {
|
||||
object->Close();
|
||||
object->Close(kernel);
|
||||
}
|
||||
registered_in_use_objects.clear();
|
||||
}
|
||||
|
|
@ -247,12 +247,11 @@ struct KernelCore::Impl {
|
|||
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::EventCountMax, 900).IsSuccess());
|
||||
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::TransferMemoryCountMax, 200).IsSuccess());
|
||||
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::SessionCountMax, 1133).IsSuccess());
|
||||
system_resource_limit->Reserve(LimitableResource::PhysicalMemoryMax, kernel_size);
|
||||
system_resource_limit->Reserve(kernel, LimitableResource::PhysicalMemoryMax, kernel_size);
|
||||
|
||||
// Reserve secure applet memory, introduced in firmware 5.0.0
|
||||
constexpr u64 secure_applet_memory_size{4_MiB};
|
||||
ASSERT(system_resource_limit->Reserve(LimitableResource::PhysicalMemoryMax,
|
||||
secure_applet_memory_size));
|
||||
ASSERT(system_resource_limit->Reserve(kernel, LimitableResource::PhysicalMemoryMax, secure_applet_memory_size));
|
||||
}
|
||||
|
||||
void InitializePreemption(KernelCore& kernel) {
|
||||
|
|
@ -350,9 +349,9 @@ struct KernelCore::Impl {
|
|||
object_name_global_data.emplace(kernel);
|
||||
}
|
||||
|
||||
void MakeApplicationProcess(KProcess* process) {
|
||||
void MakeApplicationProcess(KernelCore& kernel, KProcess* process) {
|
||||
application_process = process;
|
||||
application_process->Open();
|
||||
application_process->Open(kernel);
|
||||
}
|
||||
|
||||
/// Sets the host thread ID for the caller.
|
||||
|
|
@ -374,10 +373,10 @@ struct KernelCore::Impl {
|
|||
// Gets the dummy KThread for the caller, allocating a new one if this is the first time
|
||||
KThread* GetHostDummyThread(ThreadLocalData& t, KThread* existing_thread) {
|
||||
if (t.thread == nullptr) {
|
||||
auto const initialize{[](KThread* thread) {
|
||||
ASSERT(KThread::InitializeDummyThread(thread, nullptr).IsSuccess());
|
||||
auto const initialize = [this](KThread* thread) {
|
||||
ASSERT(KThread::InitializeDummyThread(system, thread, nullptr).IsSuccess());
|
||||
return thread;
|
||||
}};
|
||||
};
|
||||
t.raw_thread.emplace(system.Kernel());
|
||||
t.thread = existing_thread ? existing_thread : initialize(&*t.raw_thread);
|
||||
ASSERT(t.thread != nullptr);
|
||||
|
|
@ -742,19 +741,19 @@ struct KernelCore::Impl {
|
|||
time_shared_mem = KSharedMemory::Create(system.Kernel());
|
||||
hidbus_shared_mem = KSharedMemory::Create(system.Kernel());
|
||||
|
||||
font_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None,
|
||||
font_shared_mem->Initialize(system.Kernel(), system.DeviceMemory(), nullptr, Svc::MemoryPermission::None,
|
||||
Svc::MemoryPermission::Read, font_size);
|
||||
KSharedMemory::Register(kernel, font_shared_mem);
|
||||
|
||||
irs_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None,
|
||||
irs_shared_mem->Initialize(system.Kernel(), system.DeviceMemory(), nullptr, Svc::MemoryPermission::None,
|
||||
Svc::MemoryPermission::Read, irs_size);
|
||||
KSharedMemory::Register(kernel, irs_shared_mem);
|
||||
|
||||
time_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None,
|
||||
time_shared_mem->Initialize(system.Kernel(), system.DeviceMemory(), nullptr, Svc::MemoryPermission::None,
|
||||
Svc::MemoryPermission::Read, time_size);
|
||||
KSharedMemory::Register(kernel, time_shared_mem);
|
||||
|
||||
hidbus_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None,
|
||||
hidbus_shared_mem->Initialize(system.Kernel(), system.DeviceMemory(), nullptr, Svc::MemoryPermission::None,
|
||||
Svc::MemoryPermission::Read, hidbus_size);
|
||||
KSharedMemory::Register(kernel, hidbus_shared_mem);
|
||||
}
|
||||
|
|
@ -852,7 +851,7 @@ void KernelCore::Initialize() {
|
|||
}
|
||||
|
||||
void KernelCore::Shutdown() {
|
||||
impl->Shutdown();
|
||||
impl->Shutdown(*this);
|
||||
}
|
||||
|
||||
void KernelCore::CloseServices() {
|
||||
|
|
@ -868,7 +867,7 @@ KResourceLimit* KernelCore::GetSystemResourceLimit() {
|
|||
}
|
||||
|
||||
void KernelCore::AppendNewProcess(KProcess* process) {
|
||||
process->Open();
|
||||
process->Open(*this);
|
||||
|
||||
std::scoped_lock lk{impl->process_list_lock};
|
||||
impl->process_list.push_back(process);
|
||||
|
|
@ -877,12 +876,12 @@ void KernelCore::AppendNewProcess(KProcess* process) {
|
|||
void KernelCore::RemoveProcess(KProcess* process) {
|
||||
std::scoped_lock lk{impl->process_list_lock};
|
||||
if (std::erase(impl->process_list, process)) {
|
||||
process->Close();
|
||||
process->Close(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void KernelCore::MakeApplicationProcess(KProcess* process) {
|
||||
impl->MakeApplicationProcess(process);
|
||||
impl->MakeApplicationProcess(*this, process);
|
||||
}
|
||||
|
||||
KProcess* KernelCore::ApplicationProcess() {
|
||||
|
|
@ -896,11 +895,8 @@ const KProcess* KernelCore::ApplicationProcess() const {
|
|||
std::list<KScopedAutoObject<KProcess>> KernelCore::GetProcessList() {
|
||||
std::list<KScopedAutoObject<KProcess>> processes;
|
||||
std::scoped_lock lk{impl->process_list_lock};
|
||||
|
||||
for (auto* const process : impl->process_list) {
|
||||
processes.emplace_back(process);
|
||||
}
|
||||
|
||||
for (auto* const process : impl->process_list)
|
||||
processes.emplace_back(*this, process);
|
||||
return processes;
|
||||
}
|
||||
|
||||
|
|
@ -1029,15 +1025,14 @@ void KernelCore::RegisterHostThread(KThread* existing_thread) {
|
|||
}
|
||||
}
|
||||
|
||||
static std::jthread RunHostThreadFunc(KernelCore& kernel, KProcess* process,
|
||||
std::string&& thread_name, std::function<void()>&& func) {
|
||||
static std::jthread RunHostThreadFunc(KernelCore& kernel, KProcess* process, std::string&& thread_name, std::function<void()>&& func) {
|
||||
// Reserve a new thread from the process resource limit.
|
||||
KScopedResourceReservation thread_reservation(process, LimitableResource::ThreadCountMax);
|
||||
KScopedResourceReservation thread_reservation(kernel, process, LimitableResource::ThreadCountMax);
|
||||
ASSERT(thread_reservation.Succeeded());
|
||||
|
||||
// Initialize the thread.
|
||||
KThread* thread = KThread::Create(kernel);
|
||||
ASSERT(R_SUCCEEDED(KThread::InitializeDummyThread(thread, process)));
|
||||
ASSERT(R_SUCCEEDED(KThread::InitializeDummyThread(kernel.System(), thread, process)));
|
||||
|
||||
// Commit the thread reservation.
|
||||
thread_reservation.Commit();
|
||||
|
|
@ -1057,7 +1052,7 @@ static std::jthread RunHostThreadFunc(KernelCore& kernel, KProcess* process,
|
|||
|
||||
// Close the thread.
|
||||
// This will free the process if it is the last reference.
|
||||
thread->Close();
|
||||
thread->Close(kernel);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -1066,11 +1061,11 @@ std::jthread KernelCore::RunOnHostCoreProcess(std::string&& process_name,
|
|||
// Make a new process.
|
||||
KProcess* process = KProcess::Create(*this);
|
||||
ASSERT(R_SUCCEEDED(
|
||||
process->Initialize(Svc::CreateProcessParameter{}, GetSystemResourceLimit(), false)));
|
||||
process->Initialize(*this, Svc::CreateProcessParameter{}, GetSystemResourceLimit(), false)));
|
||||
|
||||
// Ensure that we don't hold onto any extra references.
|
||||
SCOPE_EXIT {
|
||||
process->Close();
|
||||
process->Close(*this);
|
||||
};
|
||||
|
||||
// Register the new process.
|
||||
|
|
@ -1096,18 +1091,18 @@ void KernelCore::RunOnGuestCoreProcess(std::string&& process_name, std::function
|
|||
// Make a new process.
|
||||
KProcess* process = KProcess::Create(*this);
|
||||
ASSERT(R_SUCCEEDED(
|
||||
process->Initialize(Svc::CreateProcessParameter{}, GetSystemResourceLimit(), false)));
|
||||
process->Initialize(*this, Svc::CreateProcessParameter{}, GetSystemResourceLimit(), false)));
|
||||
|
||||
// Ensure that we don't hold onto any extra references.
|
||||
SCOPE_EXIT {
|
||||
process->Close();
|
||||
process->Close(*this);
|
||||
};
|
||||
|
||||
// Register the new process.
|
||||
KProcess::Register(*this, process);
|
||||
|
||||
// Reserve a new thread from the process resource limit.
|
||||
KScopedResourceReservation thread_reservation(process, LimitableResource::ThreadCountMax);
|
||||
KScopedResourceReservation thread_reservation(*this, process, LimitableResource::ThreadCountMax);
|
||||
ASSERT(thread_reservation.Succeeded());
|
||||
|
||||
// Initialize the thread.
|
||||
|
|
@ -1122,7 +1117,7 @@ void KernelCore::RunOnGuestCoreProcess(std::string&& process_name, std::function
|
|||
KThread::Register(*this, thread);
|
||||
|
||||
// Begin running the thread.
|
||||
ASSERT(R_SUCCEEDED(thread->Run()));
|
||||
ASSERT(R_SUCCEEDED(thread->Run(*this)));
|
||||
}
|
||||
|
||||
u32 KernelCore::GetCurrentHostThreadID() const {
|
||||
|
|
@ -1206,9 +1201,9 @@ void KernelCore::SuspendEmulation(bool suspended) {
|
|||
|
||||
for (auto& thread : process->GetThreadList()) {
|
||||
if (should_suspend) {
|
||||
thread.RequestSuspend(SuspendType::System);
|
||||
thread.RequestSuspend(*this, SuspendType::System);
|
||||
} else {
|
||||
thread.Resume(SuspendType::System);
|
||||
thread.Resume(*this, SuspendType::System);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1244,12 +1239,9 @@ void KernelCore::SuspendEmulation(bool suspended) {
|
|||
|
||||
void KernelCore::ShutdownCores() {
|
||||
impl->TerminateAllProcesses();
|
||||
|
||||
KScopedSchedulerLock lk{*this};
|
||||
|
||||
for (auto* thread : impl->shutdown_threads) {
|
||||
void(thread->Run());
|
||||
}
|
||||
for (auto* thread : impl->shutdown_threads)
|
||||
void(thread->Run(*this));
|
||||
}
|
||||
|
||||
bool KernelCore::IsMulticore() const {
|
||||
|
|
|
|||
|
|
@ -73,14 +73,14 @@ void PhysicalCore::RunThread(KernelCore& kernel, Kernel::KThread* thread) {
|
|||
while (true) {
|
||||
// If the thread is scheduled for termination, exit.
|
||||
if (thread->HasDpc() && thread->IsTerminationRequested()) {
|
||||
thread->Exit();
|
||||
thread->Exit(kernel);
|
||||
}
|
||||
|
||||
// Notify the debugger and go to sleep if a step was performed
|
||||
// and this thread has been scheduled again.
|
||||
if (thread->GetStepState() == StepState::StepPerformed) {
|
||||
system.GetDebugger().NotifyThreadStopped(thread);
|
||||
thread->RequestSuspend(SuspendType::Debug);
|
||||
thread->RequestSuspend(kernel, SuspendType::Debug);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ void PhysicalCore::RunThread(KernelCore& kernel, Kernel::KThread* thread) {
|
|||
} else {
|
||||
interface->LogBacktrace(process);
|
||||
}
|
||||
thread->RequestSuspend(SuspendType::Debug);
|
||||
thread->RequestSuspend(kernel, SuspendType::Debug);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +145,7 @@ void PhysicalCore::RunThread(KernelCore& kernel, Kernel::KThread* thread) {
|
|||
if (system.DebuggerEnabled()) {
|
||||
system.GetDebugger().NotifyThreadWatchpoint(thread, *interface->HaltedWatchpoint());
|
||||
}
|
||||
thread->RequestSuspend(SuspendType::Debug);
|
||||
thread->RequestSuspend(kernel, SuspendType::Debug);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -69,16 +72,16 @@ public:
|
|||
explicit KAutoObjectWithSlabHeap(KernelCore& kernel) : Base(kernel) {}
|
||||
virtual ~KAutoObjectWithSlabHeap() = default;
|
||||
|
||||
virtual void Destroy() override {
|
||||
virtual void Destroy(KernelCore& kernel) override {
|
||||
const bool is_initialized = this->IsInitialized();
|
||||
uintptr_t arg = 0;
|
||||
if (is_initialized) {
|
||||
arg = this->GetPostDestroyArgument();
|
||||
this->Finalize();
|
||||
this->Finalize(kernel);
|
||||
}
|
||||
Free(Base::m_kernel, static_cast<Derived*>(this));
|
||||
Free(kernel, static_cast<Derived*>(this));
|
||||
if (is_initialized) {
|
||||
Derived::PostDestroy(arg);
|
||||
Derived::PostDestroy(kernel, arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,8 +92,8 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
size_t GetSlabIndex() const {
|
||||
return SlabHeap<Derived>(Base::m_kernel).GetObjectIndex(static_cast<const Derived*>(this));
|
||||
size_t GetSlabIndex(KernelCore& kernel) const {
|
||||
return SlabHeap<Derived>(kernel).GetObjectIndex(static_cast<const Derived*>(this));
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
@ -144,17 +147,17 @@ public:
|
|||
KAutoObjectWithSlabHeapAndContainer(KernelCore& kernel) : Base(kernel) {}
|
||||
virtual ~KAutoObjectWithSlabHeapAndContainer() {}
|
||||
|
||||
virtual void Destroy() override {
|
||||
virtual void Destroy(KernelCore& kernel) override {
|
||||
const bool is_initialized = this->IsInitialized();
|
||||
uintptr_t arg = 0;
|
||||
if (is_initialized) {
|
||||
Base::m_kernel.ObjectListContainer().Unregister(this);
|
||||
kernel.ObjectListContainer().Unregister(this);
|
||||
arg = this->GetPostDestroyArgument();
|
||||
this->Finalize();
|
||||
this->Finalize(kernel);
|
||||
}
|
||||
Free(Base::m_kernel, static_cast<Derived*>(this));
|
||||
Free(kernel, static_cast<Derived*>(this));
|
||||
if (is_initialized) {
|
||||
Derived::PostDestroy(arg);
|
||||
Derived::PostDestroy(kernel, arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -165,8 +168,8 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
size_t GetSlabIndex() const {
|
||||
return SlabHeap<Derived>(Base::m_kernel).GetObjectIndex(static_cast<const Derived*>(this));
|
||||
size_t GetSlabIndex(KernelCore& kernel) const {
|
||||
return SlabHeap<Derived>(kernel).GetObjectIndex(static_cast<const Derived*>(this));
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
@ -177,9 +180,8 @@ public:
|
|||
|
||||
static Derived* Create(KernelCore& kernel) {
|
||||
Derived* obj = Allocate(kernel);
|
||||
if (obj != nullptr) {
|
||||
if (obj != nullptr)
|
||||
KAutoObject::Create(obj);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ Result SetThreadActivity(Core::System& system, Handle thread_handle,
|
|||
R_UNLESS(thread.GetPointerUnsafe() != GetCurrentThreadPointer(system.Kernel()), ResultBusy);
|
||||
|
||||
// Set the activity.
|
||||
R_TRY(thread->SetActivity(thread_activity));
|
||||
R_TRY(thread->SetActivity(system.Kernel(), thread_activity));
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,9 +35,6 @@ constexpr bool IsValidUnmapFromOwnerCodeMemoryPermission(MemoryPermission perm)
|
|||
Result CreateCodeMemory(Core::System& system, Handle* out, u64 address, uint64_t size) {
|
||||
LOG_TRACE(Kernel_SVC, "called, address={:#X}, size=0x{:X}", address, size);
|
||||
|
||||
// Get kernel instance.
|
||||
auto& kernel = system.Kernel();
|
||||
|
||||
// Validate address / size.
|
||||
R_UNLESS(Common::IsAligned(address, PageSize), ResultInvalidAddress);
|
||||
R_UNLESS(Common::IsAligned(size, PageSize), ResultInvalidSize);
|
||||
|
|
@ -46,21 +43,20 @@ Result CreateCodeMemory(Core::System& system, Handle* out, u64 address, uint64_t
|
|||
|
||||
// Create the code memory.
|
||||
|
||||
KCodeMemory* code_mem = KCodeMemory::Create(kernel);
|
||||
KCodeMemory* code_mem = KCodeMemory::Create(system.Kernel());
|
||||
R_UNLESS(code_mem != nullptr, ResultOutOfResource);
|
||||
SCOPE_EXIT {
|
||||
code_mem->Close();
|
||||
code_mem->Close(system.Kernel());
|
||||
};
|
||||
|
||||
// Verify that the region is in range.
|
||||
R_UNLESS(GetCurrentProcess(system.Kernel()).GetPageTable().Contains(address, size),
|
||||
ResultInvalidCurrentMemory);
|
||||
R_UNLESS(GetCurrentProcess(system.Kernel()).GetPageTable().Contains(address, size), ResultInvalidCurrentMemory);
|
||||
|
||||
// Initialize the code memory.
|
||||
R_TRY(code_mem->Initialize(system.DeviceMemory(), address, size));
|
||||
R_TRY(code_mem->Initialize(system.Kernel(), system.DeviceMemory(), address, size));
|
||||
|
||||
// Register the code memory.
|
||||
KCodeMemory::Register(kernel, code_mem);
|
||||
KCodeMemory::Register(system.Kernel(), code_mem);
|
||||
|
||||
// Add the code memory to the handle table.
|
||||
R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(system.Kernel(), out, code_mem));
|
||||
|
|
@ -96,29 +92,23 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
|
|||
switch (operation) {
|
||||
case CodeMemoryOperation::Map: {
|
||||
// Check that the region is in range.
|
||||
R_UNLESS(GetCurrentProcess(system.Kernel())
|
||||
.GetPageTable()
|
||||
.CanContain(address, size, KMemoryState::CodeOut),
|
||||
ResultInvalidMemoryRegion);
|
||||
R_UNLESS(GetCurrentProcess(system.Kernel()).GetPageTable().CanContain(address, size, KMemoryState::CodeOut), ResultInvalidMemoryRegion);
|
||||
|
||||
// Check the memory permission.
|
||||
R_UNLESS(IsValidMapCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission);
|
||||
|
||||
// Map the memory.
|
||||
R_TRY(code_mem->Map(address, size));
|
||||
R_TRY(code_mem->Map(system.Kernel(), address, size));
|
||||
} break;
|
||||
case CodeMemoryOperation::Unmap: {
|
||||
// Check that the region is in range.
|
||||
R_UNLESS(GetCurrentProcess(system.Kernel())
|
||||
.GetPageTable()
|
||||
.CanContain(address, size, KMemoryState::CodeOut),
|
||||
ResultInvalidMemoryRegion);
|
||||
R_UNLESS(GetCurrentProcess(system.Kernel()).GetPageTable().CanContain(address, size, KMemoryState::CodeOut), ResultInvalidMemoryRegion);
|
||||
|
||||
// Check the memory permission.
|
||||
R_UNLESS(IsValidUnmapCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission);
|
||||
|
||||
// Unmap the memory.
|
||||
R_TRY(code_mem->Unmap(address, size));
|
||||
R_TRY(code_mem->Unmap(system.Kernel(), address, size));
|
||||
} break;
|
||||
case CodeMemoryOperation::MapToOwner: {
|
||||
// Check that the region is in range.
|
||||
|
|
@ -130,7 +120,7 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
|
|||
R_UNLESS(IsValidMapToOwnerCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission);
|
||||
|
||||
// Map the memory to its owner.
|
||||
R_TRY(code_mem->MapToOwner(address, size, perm));
|
||||
R_TRY(code_mem->MapToOwner(system.Kernel(), address, size, perm));
|
||||
} break;
|
||||
case CodeMemoryOperation::UnmapFromOwner: {
|
||||
// Check that the region is in range.
|
||||
|
|
@ -142,7 +132,7 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
|
|||
R_UNLESS(IsValidUnmapFromOwnerCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission);
|
||||
|
||||
// Unmap the memory from its owner.
|
||||
R_TRY(code_mem->UnmapFromOwner(address, size));
|
||||
R_TRY(code_mem->UnmapFromOwner(system.Kernel(), address, size));
|
||||
} break;
|
||||
default:
|
||||
R_THROW(ResultInvalidEnumValue);
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ Result CreateDeviceAddressSpace(Core::System& system, Handle* out, uint64_t das_
|
|||
KDeviceAddressSpace* das = KDeviceAddressSpace::Create(system.Kernel());
|
||||
R_UNLESS(das != nullptr, ResultOutOfResource);
|
||||
SCOPE_EXIT {
|
||||
das->Close();
|
||||
das->Close(system.Kernel());
|
||||
};
|
||||
|
||||
// Initialize the device address space.
|
||||
R_TRY(das->Initialize(das_address, das_size));
|
||||
R_TRY(das->Initialize(system.Kernel(), das_address, das_size));
|
||||
|
||||
// Register the device address space.
|
||||
KDeviceAddressSpace::Register(system.Kernel(), das);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ Result SignalEvent(Core::System& system, Handle event_handle) {
|
|||
if ((program_id & 0xFFFFFFFFFFFFFF00ull) == 0x0100000000001000ull) {
|
||||
KScopedAutoObject event = handle_table.GetObject<KEvent>(system.Kernel(), event_handle);
|
||||
if (event.IsNotNull()) {
|
||||
event->Signal();
|
||||
event->Signal(system.Kernel());
|
||||
} else {
|
||||
LOG_WARNING(Kernel_SVC, "SignalEvent best-effort unknown handle=0x{:08X} (ignored)",
|
||||
event_handle);
|
||||
|
|
@ -37,7 +37,7 @@ Result SignalEvent(Core::System& system, Handle event_handle) {
|
|||
KScopedAutoObject event = handle_table.GetObject<KEvent>(system.Kernel(), event_handle);
|
||||
R_UNLESS(event.IsNotNull(), ResultInvalidHandle);
|
||||
|
||||
R_RETURN(event->Signal());
|
||||
R_RETURN(event->Signal(system.Kernel()));
|
||||
}
|
||||
|
||||
Result ClearEvent(Core::System& system, Handle event_handle) {
|
||||
|
|
@ -50,7 +50,7 @@ Result ClearEvent(Core::System& system, Handle event_handle) {
|
|||
{
|
||||
KScopedAutoObject event = handle_table.GetObject<KEvent>(system.Kernel(), event_handle);
|
||||
if (event.IsNotNull()) {
|
||||
event->Clear();
|
||||
event->Clear(system.Kernel());
|
||||
R_SUCCEED();
|
||||
}
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ Result ClearEvent(Core::System& system, Handle event_handle) {
|
|||
{
|
||||
KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(system.Kernel(), event_handle);
|
||||
if (readable_event.IsNotNull()) {
|
||||
readable_event->Clear();
|
||||
readable_event->Clear(system.Kernel());
|
||||
R_SUCCEED();
|
||||
}
|
||||
}
|
||||
|
|
@ -71,32 +71,31 @@ Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) {
|
|||
LOG_DEBUG(Kernel_SVC, "called");
|
||||
|
||||
// Get the kernel reference and handle table.
|
||||
auto& kernel = system.Kernel();
|
||||
auto& handle_table = GetCurrentProcess(kernel).GetHandleTable();
|
||||
auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
|
||||
|
||||
// Reserve a new event from the process resource limit
|
||||
KScopedResourceReservation event_reservation(GetCurrentProcessPointer(kernel),
|
||||
KScopedResourceReservation event_reservation(system.Kernel(), GetCurrentProcessPointer(system.Kernel()),
|
||||
LimitableResource::EventCountMax);
|
||||
R_UNLESS(event_reservation.Succeeded(), ResultLimitReached);
|
||||
|
||||
// Create a new event.
|
||||
KEvent* event = KEvent::Create(kernel);
|
||||
KEvent* event = KEvent::Create(system.Kernel());
|
||||
R_UNLESS(event != nullptr, ResultOutOfResource);
|
||||
|
||||
// Initialize the event.
|
||||
event->Initialize(GetCurrentProcessPointer(kernel));
|
||||
event->Initialize(system.Kernel(), GetCurrentProcessPointer(system.Kernel()));
|
||||
|
||||
// Commit the thread reservation.
|
||||
event_reservation.Commit();
|
||||
|
||||
// Ensure that we clean up the event (and its only references are handle table) on function end.
|
||||
SCOPE_EXIT {
|
||||
event->GetReadableEvent().Close();
|
||||
event->Close();
|
||||
event->GetReadableEvent().Close(system.Kernel());
|
||||
event->Close(system.Kernel());
|
||||
};
|
||||
|
||||
// Register the event.
|
||||
KEvent::Register(kernel, event);
|
||||
KEvent::Register(system.Kernel(), event);
|
||||
|
||||
// Add the event to the handle table.
|
||||
R_TRY(handle_table.Add(system.Kernel(), out_write, event));
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ void Break(Core::System& system, BreakReason reason, u64 info1, u64 info2) {
|
|||
if (system.DebuggerEnabled() && should_break) {
|
||||
auto* thread = system.Kernel().GetCurrentEmuThread();
|
||||
system.GetDebugger().NotifyThreadStopped(thread);
|
||||
thread->RequestSuspend(Kernel::SuspendType::Debug);
|
||||
thread->RequestSuspend(system.Kernel(), Kernel::SuspendType::Debug);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,11 +90,11 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
|
|||
R_SUCCEED();
|
||||
|
||||
case InfoType::TotalMemorySize:
|
||||
*result = process->GetTotalUserPhysicalMemorySize();
|
||||
*result = process->GetTotalUserPhysicalMemorySize(system.Kernel());
|
||||
R_SUCCEED();
|
||||
|
||||
case InfoType::UsedMemorySize:
|
||||
*result = process->GetUsedUserPhysicalMemorySize();
|
||||
*result = process->GetUsedUserPhysicalMemorySize(system.Kernel());
|
||||
R_SUCCEED();
|
||||
|
||||
case InfoType::SystemResourceSizeTotal:
|
||||
|
|
@ -114,11 +114,11 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
|
|||
R_SUCCEED();
|
||||
|
||||
case InfoType::TotalNonSystemMemorySize:
|
||||
*result = process->GetTotalNonSystemUserPhysicalMemorySize();
|
||||
*result = process->GetTotalNonSystemUserPhysicalMemorySize(system.Kernel());
|
||||
R_SUCCEED();
|
||||
|
||||
case InfoType::UsedNonSystemMemorySize:
|
||||
*result = process->GetUsedNonSystemUserPhysicalMemorySize();
|
||||
*result = process->GetUsedNonSystemUserPhysicalMemorySize(system.Kernel());
|
||||
R_SUCCEED();
|
||||
|
||||
case InfoType::IsApplication:
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@ Result SendSyncRequestImpl(KernelCore& kernel, uintptr_t message, size_t buffer_
|
|||
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
|
||||
|
||||
// Get the parent, and persist a reference to it until we're done.
|
||||
KScopedAutoObject parent = session->GetParent();
|
||||
KScopedAutoObject parent = {kernel, session->GetParent()};
|
||||
ASSERT(parent.IsNotNull());
|
||||
|
||||
// Send the request.
|
||||
R_RETURN(session->SendSyncRequest(message, buffer_size));
|
||||
R_RETURN(session->SendSyncRequest(kernel, message, buffer_size));
|
||||
}
|
||||
|
||||
Result ReplyAndReceiveImpl(KernelCore& kernel, int32_t* out_index, uintptr_t message,
|
||||
|
|
@ -48,7 +48,7 @@ Result ReplyAndReceiveImpl(KernelCore& kernel, int32_t* out_index, uintptr_t mes
|
|||
};
|
||||
|
||||
// Send the reply.
|
||||
R_TRY(session->SendReply(message, buffer_size, message_paddr));
|
||||
R_TRY(session->SendReply(kernel, message, buffer_size, message_paddr));
|
||||
}
|
||||
|
||||
// Receive a message.
|
||||
|
|
@ -74,8 +74,7 @@ Result ReplyAndReceiveImpl(KernelCore& kernel, int32_t* out_index, uintptr_t mes
|
|||
while (true) {
|
||||
// Wait for an object.
|
||||
s32 index;
|
||||
Result result = KSynchronizationObject::Wait(kernel, std::addressof(index), objs,
|
||||
num_objects, timeout);
|
||||
Result result = KSynchronizationObject::Wait(kernel, std::addressof(index), objs, num_objects, timeout);
|
||||
if (ResultTimedOut == result) {
|
||||
R_THROW(result);
|
||||
}
|
||||
|
|
@ -84,7 +83,7 @@ Result ReplyAndReceiveImpl(KernelCore& kernel, int32_t* out_index, uintptr_t mes
|
|||
if (R_SUCCEEDED(result)) {
|
||||
KServerSession* session = objs[index]->DynamicCast<KServerSession*>();
|
||||
if (session != nullptr) {
|
||||
result = session->ReceiveRequest(message, buffer_size, message_paddr);
|
||||
result = session->ReceiveRequest(kernel, message, buffer_size, message_paddr);
|
||||
if (ResultNotFound == result) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -131,7 +130,7 @@ Result ReplyAndReceiveImpl(KernelCore& kernel, int32_t* out_index, uintptr_t mes
|
|||
// Ensure handles are closed when we're done.
|
||||
SCOPE_EXIT {
|
||||
for (auto i = 0; i < num_handles; ++i) {
|
||||
objs[i]->Close();
|
||||
objs[i]->Close(kernel);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -185,8 +184,7 @@ Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_ha
|
|||
auto& handle_table = process.GetHandleTable();
|
||||
|
||||
// Reserve a new event from the process resource limit.
|
||||
KScopedResourceReservation event_reservation(std::addressof(process),
|
||||
Svc::LimitableResource::EventCountMax);
|
||||
KScopedResourceReservation event_reservation(system.Kernel(), std::addressof(process), Svc::LimitableResource::EventCountMax);
|
||||
R_UNLESS(event_reservation.Succeeded(), ResultLimitReached);
|
||||
|
||||
// Get the client session.
|
||||
|
|
@ -194,7 +192,7 @@ Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_ha
|
|||
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
|
||||
|
||||
// Get the parent, and persist a reference to it until we're done.
|
||||
KScopedAutoObject parent = session->GetParent();
|
||||
KScopedAutoObject parent = {system.Kernel(), session->GetParent()};
|
||||
ASSERT(parent.IsNotNull());
|
||||
|
||||
// Create a new event.
|
||||
|
|
@ -202,15 +200,15 @@ Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_ha
|
|||
R_UNLESS(event != nullptr, ResultOutOfResource);
|
||||
|
||||
// Initialize the event.
|
||||
event->Initialize(std::addressof(process));
|
||||
event->Initialize(system.Kernel(), std::addressof(process));
|
||||
|
||||
// Commit our reservation.
|
||||
event_reservation.Commit();
|
||||
|
||||
// At end of scope, kill the standing references to the sub events.
|
||||
SCOPE_EXIT {
|
||||
event->GetReadableEvent().Close();
|
||||
event->Close();
|
||||
event->GetReadableEvent().Close(system.Kernel());
|
||||
event->Close(system.Kernel());
|
||||
};
|
||||
|
||||
// Register the event.
|
||||
|
|
@ -225,7 +223,7 @@ Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_ha
|
|||
};
|
||||
|
||||
// Send the async request.
|
||||
R_RETURN(session->SendAsyncRequest(event, message, buffer_size));
|
||||
R_RETURN(session->SendAsyncRequest(system.Kernel(), event, message, buffer_size));
|
||||
}
|
||||
|
||||
Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles, s32 num_handles,
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ Result SendSyncRequestLight(Core::System& system, Handle session_handle, u32* ar
|
|||
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
|
||||
|
||||
// Send the request.
|
||||
R_TRY(session->SendSyncRequest(args));
|
||||
R_TRY(session->SendSyncRequest(system.Kernel(), args));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ Result ReplyAndReceiveLight(Core::System& system, Handle session_handle, u32* ar
|
|||
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
|
||||
|
||||
// Handle the request.
|
||||
R_TRY(session->ReplyAndReceive(args));
|
||||
R_TRY(session->ReplyAndReceive(system.Kernel(), args));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,11 +43,11 @@ Result ConnectToNamedPort(Core::System& system, Handle* out, u64 user_name) {
|
|||
|
||||
// Create a session.
|
||||
KClientSession* session;
|
||||
R_TRY(port->CreateSession(std::addressof(session)));
|
||||
R_TRY(port->CreateSession(system.Kernel(), std::addressof(session)));
|
||||
|
||||
// Register the session in the table, close the extra reference.
|
||||
handle_table.Register(system.Kernel(), *out, session);
|
||||
session->Close();
|
||||
session->Close(system.Kernel());
|
||||
|
||||
// We succeeded.
|
||||
R_SUCCEED();
|
||||
|
|
@ -68,12 +68,12 @@ Result CreatePort(Core::System& system, Handle* out_server, Handle* out_client,
|
|||
R_UNLESS(port != nullptr, ResultOutOfResource);
|
||||
|
||||
// Initialize the port.
|
||||
port->Initialize(max_sessions, is_light, name);
|
||||
port->Initialize(system.Kernel(), max_sessions, is_light, name);
|
||||
|
||||
// Ensure that we clean up the port (and its only references are handle table) on function end.
|
||||
SCOPE_EXIT {
|
||||
port->GetServerPort().Close();
|
||||
port->GetClientPort().Close();
|
||||
port->GetServerPort().Close(system.Kernel());
|
||||
port->GetClientPort().Close(system.Kernel());
|
||||
};
|
||||
|
||||
// Register the port.
|
||||
|
|
@ -108,17 +108,15 @@ Result ConnectToPort(Core::System& system, Handle* out, Handle port) {
|
|||
|
||||
// Create the session.
|
||||
KAutoObject* session;
|
||||
if (client_port->IsLight()) {
|
||||
R_TRY(client_port->CreateLightSession(
|
||||
reinterpret_cast<KLightClientSession**>(std::addressof(session))));
|
||||
if (client_port->IsLight(system.Kernel())) {
|
||||
R_TRY(client_port->CreateLightSession(system.Kernel(), reinterpret_cast<KLightClientSession**>(std::addressof(session))));
|
||||
} else {
|
||||
R_TRY(client_port->CreateSession(
|
||||
reinterpret_cast<KClientSession**>(std::addressof(session))));
|
||||
R_TRY(client_port->CreateSession(system.Kernel(), reinterpret_cast<KClientSession**>(std::addressof(session))));
|
||||
}
|
||||
|
||||
// Register the session.
|
||||
handle_table.Register(system.Kernel(), *out, session);
|
||||
session->Close();
|
||||
session->Close(system.Kernel());
|
||||
|
||||
// We succeeded.
|
||||
R_SUCCEED();
|
||||
|
|
@ -146,15 +144,15 @@ Result ManageNamedPort(Core::System& system, Handle* out_server_handle, uint64_t
|
|||
R_UNLESS(port != nullptr, ResultOutOfResource);
|
||||
|
||||
// Initialize the new port.
|
||||
port->Initialize(max_sessions, false, 0);
|
||||
port->Initialize(system.Kernel(), max_sessions, false, 0);
|
||||
|
||||
// Register the port.
|
||||
KPort::Register(system.Kernel(), port);
|
||||
|
||||
// Ensure that our only reference to the port is in the handle table when we're done.
|
||||
SCOPE_EXIT {
|
||||
port->GetClientPort().Close();
|
||||
port->GetServerPort().Close();
|
||||
port->GetClientPort().Close(system.Kernel());
|
||||
port->GetServerPort().Close(system.Kernel());
|
||||
};
|
||||
|
||||
// Register the handle in the table.
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ Result CreateResourceLimit(Core::System& system, Handle* out_handle) {
|
|||
|
||||
// Ensure we don't leak a reference to the limit.
|
||||
SCOPE_EXIT {
|
||||
resource_limit->Close();
|
||||
resource_limit->Close(system.Kernel());
|
||||
};
|
||||
|
||||
// Initialize the resource limit.
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien
|
|||
|
||||
// Reserve a new session from the process resource limit.
|
||||
// TODO: Dynamic resource limits
|
||||
KScopedResourceReservation session_reservation(std::addressof(process),
|
||||
KScopedResourceReservation session_reservation(system.Kernel(), std::addressof(process),
|
||||
LimitableResource::SessionCountMax);
|
||||
if (session_reservation.Succeeded()) {
|
||||
session = T::Create(system.Kernel());
|
||||
|
|
@ -65,7 +65,7 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien
|
|||
R_UNLESS(session != nullptr, ResultOutOfResource);
|
||||
|
||||
// Initialize the session.
|
||||
session->Initialize(nullptr, name);
|
||||
session->Initialize(system.Kernel(), nullptr, name);
|
||||
|
||||
// Commit the session reservation.
|
||||
session_reservation.Commit();
|
||||
|
|
@ -73,8 +73,8 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien
|
|||
// Ensure that we clean up the session (and its only references are handle table) on function
|
||||
// end.
|
||||
SCOPE_EXIT {
|
||||
session->GetClientSession().Close();
|
||||
session->GetServerSession().Close();
|
||||
session->GetClientSession().Close(system.Kernel());
|
||||
session->GetServerSession().Close(system.Kernel());
|
||||
};
|
||||
|
||||
// Register the session.
|
||||
|
|
@ -119,10 +119,10 @@ Result AcceptSession(Core::System& system, Handle* out, Handle port_handle) {
|
|||
|
||||
// Accept the session.
|
||||
KAutoObject* session;
|
||||
if (port->IsLight()) {
|
||||
session = port->AcceptLightSession();
|
||||
if (port->IsLight(system.Kernel())) {
|
||||
session = port->AcceptLightSession(system.Kernel());
|
||||
} else {
|
||||
session = port->AcceptSession();
|
||||
session = port->AcceptSession(system.Kernel());
|
||||
}
|
||||
|
||||
// Ensure we accepted successfully.
|
||||
|
|
@ -130,7 +130,7 @@ Result AcceptSession(Core::System& system, Handle* out, Handle port_handle) {
|
|||
|
||||
// Register the session.
|
||||
handle_table.Register(system.Kernel(), *out, session);
|
||||
session->Close();
|
||||
session->Close(system.Kernel());
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,11 +56,11 @@ Result MapSharedMemory(Core::System& system, Handle shmem_handle, u64 address, u
|
|||
R_UNLESS(page_table.CanContain(address, size, KMemoryState::Shared), ResultInvalidMemoryRegion);
|
||||
|
||||
// Add the shared memory to the process.
|
||||
R_TRY(process.AddSharedMemory(shmem.GetPointerUnsafe(), address, size));
|
||||
R_TRY(process.AddSharedMemory(system.Kernel(), shmem.GetPointerUnsafe(), address, size));
|
||||
|
||||
// Ensure that we clean up the shared memory if we fail to map it.
|
||||
ON_RESULT_FAILURE {
|
||||
process.RemoveSharedMemory(shmem.GetPointerUnsafe(), address, size);
|
||||
process.RemoveSharedMemory(system.Kernel(), shmem.GetPointerUnsafe(), address, size);
|
||||
};
|
||||
|
||||
// Map the shared memory.
|
||||
|
|
@ -89,7 +89,7 @@ Result UnmapSharedMemory(Core::System& system, Handle shmem_handle, u64 address,
|
|||
R_TRY(shmem->Unmap(process, address, size));
|
||||
|
||||
// Remove the shared memory from the process.
|
||||
process.RemoveSharedMemory(shmem.GetPointerUnsafe(), address, size);
|
||||
process.RemoveSharedMemory(system.Kernel(), shmem.GetPointerUnsafe(), address, size);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ Result ResetSignal(Core::System& system, Handle handle) {
|
|||
{
|
||||
KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(system.Kernel(), handle);
|
||||
if (readable_event.IsNotNull()) {
|
||||
R_RETURN(readable_event->Reset());
|
||||
R_RETURN(readable_event->Reset(system.Kernel()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ Result ResetSignal(Core::System& system, Handle handle) {
|
|||
{
|
||||
KScopedAutoObject process = handle_table.GetObject<KProcess>(system.Kernel(), handle);
|
||||
if (process.IsNotNull()) {
|
||||
R_RETURN(process->Reset());
|
||||
R_RETURN(process->Reset(system.Kernel()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,17 +62,14 @@ Result WaitSynchronization(Core::System& system, int32_t* out_index, u64 user_ha
|
|||
R_UNLESS(0 <= num_handles && num_handles <= Svc::ArgumentHandleCountMax, ResultOutOfRange);
|
||||
|
||||
// Get the synchronization context.
|
||||
auto& kernel = system.Kernel();
|
||||
auto& handle_table = GetCurrentProcess(kernel).GetHandleTable();
|
||||
auto objs = GetCurrentThread(kernel).GetSynchronizationObjectBuffer();
|
||||
auto handles = GetCurrentThread(kernel).GetHandleBuffer();
|
||||
auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
|
||||
auto objs = GetCurrentThread(system.Kernel()).GetSynchronizationObjectBuffer();
|
||||
auto handles = GetCurrentThread(system.Kernel()).GetHandleBuffer();
|
||||
|
||||
// Copy user handles.
|
||||
if (num_handles > 0) {
|
||||
// Get the handles.
|
||||
R_UNLESS(GetCurrentMemory(kernel).ReadBlock(user_handles, handles.data(),
|
||||
sizeof(Handle) * num_handles),
|
||||
ResultInvalidPointer);
|
||||
R_UNLESS(GetCurrentMemory(system.Kernel()).ReadBlock(user_handles, handles.data(), sizeof(Handle) * num_handles), ResultInvalidPointer);
|
||||
|
||||
// Convert the handles to objects.
|
||||
R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(system.Kernel(), objs.data(), handles.data(), num_handles), ResultInvalidHandle);
|
||||
|
|
@ -81,14 +78,14 @@ Result WaitSynchronization(Core::System& system, int32_t* out_index, u64 user_ha
|
|||
// Ensure handles are closed when we're done.
|
||||
SCOPE_EXIT {
|
||||
for (auto i = 0; i < num_handles; ++i) {
|
||||
objs[i]->Close();
|
||||
objs[i]->Close(system.Kernel());
|
||||
}
|
||||
};
|
||||
|
||||
// Convert the timeout from nanoseconds to ticks.
|
||||
s64 timeout;
|
||||
if (timeout_ns > 0) {
|
||||
u64 ticks = kernel.HardwareTimer().GetTick();
|
||||
u64 ticks = system.Kernel().HardwareTimer().GetTick();
|
||||
ticks += timeout_ns;
|
||||
ticks += 2;
|
||||
|
||||
|
|
@ -98,7 +95,7 @@ Result WaitSynchronization(Core::System& system, int32_t* out_index, u64 user_ha
|
|||
}
|
||||
|
||||
// Wait on the objects.
|
||||
Result res = KSynchronizationObject::Wait(kernel, out_index, objs.data(), num_handles, timeout);
|
||||
Result res = KSynchronizationObject::Wait(system.Kernel(), out_index, objs.data(), num_handles, timeout);
|
||||
|
||||
R_SUCCEED_IF(res == ResultSessionClosed);
|
||||
R_RETURN(res);
|
||||
|
|
@ -109,31 +106,28 @@ Result CancelSynchronization(Core::System& system, Handle handle) {
|
|||
LOG_TRACE(Kernel_SVC, "called handle={:#X}", handle);
|
||||
|
||||
// Get the thread from its handle.
|
||||
KScopedAutoObject thread =
|
||||
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), handle);
|
||||
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), handle);
|
||||
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
|
||||
|
||||
// Cancel the thread's wait.
|
||||
thread->WaitCancel();
|
||||
thread->WaitCancel(system.Kernel());
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void SynchronizePreemptionState(Core::System& system) {
|
||||
auto& kernel = system.Kernel();
|
||||
|
||||
// Lock the scheduler.
|
||||
KScopedSchedulerLock sl{kernel};
|
||||
KScopedSchedulerLock sl{system.Kernel()};
|
||||
|
||||
// If the current thread is pinned, unpin it.
|
||||
KProcess* cur_process = GetCurrentProcessPointer(kernel);
|
||||
const auto core_id = GetCurrentCoreId(kernel);
|
||||
KProcess* cur_process = GetCurrentProcessPointer(system.Kernel());
|
||||
const auto core_id = GetCurrentCoreId(system.Kernel());
|
||||
|
||||
if (cur_process->GetPinnedThread(core_id) == GetCurrentThreadPointer(kernel)) {
|
||||
if (cur_process->GetPinnedThread(core_id) == GetCurrentThreadPointer(system.Kernel())) {
|
||||
// Clear the current thread's interrupt flag.
|
||||
GetCurrentThread(kernel).ClearInterruptFlag();
|
||||
GetCurrentThread(system.Kernel()).ClearInterruptFlag(system.Kernel());
|
||||
|
||||
// Unpin the current thread.
|
||||
cur_process->UnpinCurrentThread();
|
||||
cur_process->UnpinCurrentThread(system.Kernel());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ Result CreateThread(Core::System& system, Handle* out_handle, u64 entry_point, u
|
|||
R_UNLESS(process.CheckThreadPriority(priority), ResultInvalidPriority);
|
||||
|
||||
// Reserve a new thread from the process resource limit (waiting up to 100ms).
|
||||
KScopedResourceReservation thread_reservation(std::addressof(process),
|
||||
KScopedResourceReservation thread_reservation(system.Kernel(), std::addressof(process),
|
||||
LimitableResource::ThreadCountMax, 1,
|
||||
kernel.HardwareTimer().GetTick() + 100000000);
|
||||
R_UNLESS(thread_reservation.Succeeded(), ResultLimitReached);
|
||||
|
|
@ -55,7 +55,7 @@ Result CreateThread(Core::System& system, Handle* out_handle, u64 entry_point, u
|
|||
KThread* thread = KThread::Create(kernel);
|
||||
R_UNLESS(thread != nullptr, ResultOutOfResource)
|
||||
SCOPE_EXIT {
|
||||
thread->Close();
|
||||
thread->Close(system.Kernel());
|
||||
};
|
||||
|
||||
// Initialize the thread.
|
||||
|
|
@ -69,7 +69,7 @@ Result CreateThread(Core::System& system, Handle* out_handle, u64 entry_point, u
|
|||
thread_reservation.Commit();
|
||||
|
||||
// Clone the current fpu status to the new thread.
|
||||
thread->CloneFpuStatus();
|
||||
thread->CloneFpuStatus(system.Kernel());
|
||||
|
||||
// Register the new thread.
|
||||
KThread::Register(kernel, thread);
|
||||
|
|
@ -92,7 +92,7 @@ Result StartThread(Core::System& system, Handle thread_handle) {
|
|||
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
|
||||
|
||||
// Try to start the thread.
|
||||
R_TRY(thread->Run());
|
||||
R_TRY(thread->Run(system.Kernel()));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
|
@ -101,7 +101,7 @@ Result StartThread(Core::System& system, Handle thread_handle) {
|
|||
void ExitThread(Core::System& system) {
|
||||
auto* const current_thread = GetCurrentThreadPointer(system.Kernel());
|
||||
system.GlobalSchedulerContext().RemoveThread(current_thread);
|
||||
current_thread->Exit();
|
||||
current_thread->Exit(system.Kernel());
|
||||
}
|
||||
|
||||
/// Sleep the current thread
|
||||
|
|
@ -129,7 +129,7 @@ void SleepThread(Core::System& system, s64 ns) {
|
|||
|
||||
// Sleep.
|
||||
// NOTE: Nintendo does not check the result of this sleep.
|
||||
static_cast<void>(GetCurrentThread(kernel).Sleep(timeout));
|
||||
static_cast<void>(GetCurrentThread(kernel).Sleep(kernel, timeout));
|
||||
} else if (yield_type == Svc::YieldType::WithoutCoreMigration) {
|
||||
KScheduler::YieldWithoutCoreMigration(kernel);
|
||||
} else if (yield_type == Svc::YieldType::WithCoreMigration) {
|
||||
|
|
@ -143,26 +143,23 @@ void SleepThread(Core::System& system, s64 ns) {
|
|||
|
||||
/// Gets the thread context
|
||||
Result GetThreadContext3(Core::System& system, u64 out_context, Handle thread_handle) {
|
||||
LOG_DEBUG(Kernel_SVC, "called, out_context=0x{:08X}, thread_handle={:#X}", out_context,
|
||||
thread_handle);
|
||||
|
||||
auto& kernel = system.Kernel();
|
||||
LOG_DEBUG(Kernel_SVC, "called, out_context=0x{:08X}, thread_handle={:#X}", out_context, thread_handle);
|
||||
|
||||
// Get the thread from its handle.
|
||||
KScopedAutoObject thread = GetCurrentProcess(kernel).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
|
||||
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
|
||||
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
|
||||
|
||||
// Require the handle be to a non-current thread in the current process.
|
||||
R_UNLESS(thread->GetOwnerProcess() == GetCurrentProcessPointer(kernel), ResultInvalidHandle);
|
||||
R_UNLESS(thread.GetPointerUnsafe() != GetCurrentThreadPointer(kernel), ResultBusy);
|
||||
R_UNLESS(thread->GetOwnerProcess() == GetCurrentProcessPointer(system.Kernel()), ResultInvalidHandle);
|
||||
R_UNLESS(thread.GetPointerUnsafe() != GetCurrentThreadPointer(system.Kernel()), ResultBusy);
|
||||
|
||||
// Get the thread context.
|
||||
Svc::ThreadContext context{};
|
||||
R_TRY(thread->GetThreadContext3(std::addressof(context)));
|
||||
R_TRY(thread->GetThreadContext3(system.Kernel(), std::addressof(context)));
|
||||
|
||||
// Copy the thread context to user space.
|
||||
R_UNLESS(
|
||||
GetCurrentMemory(kernel).WriteBlock(out_context, std::addressof(context), sizeof(context)),
|
||||
GetCurrentMemory(system.Kernel()).WriteBlock(out_context, std::addressof(context), sizeof(context)),
|
||||
ResultInvalidPointer);
|
||||
|
||||
R_SUCCEED();
|
||||
|
|
@ -196,7 +193,7 @@ Result SetThreadPriority(Core::System& system, Handle thread_handle, s32 priorit
|
|||
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
|
||||
|
||||
// Set the thread priority.
|
||||
thread->SetBasePriority(priority);
|
||||
thread->SetBasePriority(system.Kernel(), priority);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
|
|
@ -249,7 +246,7 @@ Result GetThreadCoreMask(Core::System& system, s32* out_core_id, u64* out_affini
|
|||
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
|
||||
|
||||
// Get the core mask.
|
||||
R_RETURN(thread->GetCoreMask(out_core_id, out_affinity_mask));
|
||||
R_RETURN(thread->GetCoreMask(system.Kernel(), out_core_id, out_affinity_mask));
|
||||
}
|
||||
|
||||
Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id,
|
||||
|
|
@ -279,7 +276,7 @@ Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id
|
|||
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
|
||||
|
||||
// Set the core mask.
|
||||
R_RETURN(thread->SetCoreMask(core_id, affinity_mask));
|
||||
R_RETURN(thread->SetCoreMask(system.Kernel(), core_id, affinity_mask));
|
||||
}
|
||||
|
||||
/// Get the ID for the specified thread.
|
||||
|
|
|
|||
|
|
@ -46,8 +46,7 @@ Result CreateTransferMemory(Core::System& system, Handle* out, u64 address, u64
|
|||
auto& handle_table = process.GetHandleTable();
|
||||
|
||||
// Reserve a new transfer memory from the process resource limit.
|
||||
KScopedResourceReservation trmem_reservation(std::addressof(process),
|
||||
LimitableResource::TransferMemoryCountMax);
|
||||
KScopedResourceReservation trmem_reservation(system.Kernel(), std::addressof(process), LimitableResource::TransferMemoryCountMax);
|
||||
R_UNLESS(trmem_reservation.Succeeded(), ResultLimitReached);
|
||||
|
||||
// Create the transfer memory.
|
||||
|
|
@ -56,14 +55,14 @@ Result CreateTransferMemory(Core::System& system, Handle* out, u64 address, u64
|
|||
|
||||
// Ensure the only reference is in the handle table when we're done.
|
||||
SCOPE_EXIT {
|
||||
trmem->Close();
|
||||
trmem->Close(system.Kernel());
|
||||
};
|
||||
|
||||
// Ensure that the region is in range.
|
||||
R_UNLESS(process.GetPageTable().Contains(address, size), ResultInvalidCurrentMemory);
|
||||
|
||||
// Initialize the transfer memory.
|
||||
R_TRY(trmem->Initialize(address, size, map_perm));
|
||||
R_TRY(trmem->Initialize(system.Kernel(), address, size, map_perm));
|
||||
|
||||
// Commit the reservation.
|
||||
trmem_reservation.Commit();
|
||||
|
|
@ -99,7 +98,7 @@ Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t add
|
|||
ResultInvalidMemoryRegion);
|
||||
|
||||
// Map the transfer memory.
|
||||
R_TRY(trmem->Map(address, size, map_perm));
|
||||
R_TRY(trmem->Map(system.Kernel(), address, size, map_perm));
|
||||
|
||||
// We succeeded.
|
||||
R_SUCCEED();
|
||||
|
|
@ -126,7 +125,7 @@ Result UnmapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t a
|
|||
ResultInvalidMemoryRegion);
|
||||
|
||||
// Unmap the transfer memory.
|
||||
R_TRY(trmem->Unmap(address, size));
|
||||
R_TRY(trmem->Unmap(system.Kernel(), address, size));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -64,7 +67,7 @@ void IAsyncContext::GetResult(HLERequestContext& ctx) {
|
|||
|
||||
void IAsyncContext::MarkComplete() {
|
||||
is_complete.store(true);
|
||||
completion_event->Signal();
|
||||
completion_event->Signal(system.Kernel());
|
||||
}
|
||||
|
||||
} // namespace Service::Account
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator
|
||||
|
|
@ -76,7 +76,7 @@ void Applet::SetInteractibleLocked(bool interactible) {
|
|||
|
||||
void Applet::OnProcessTerminatedLocked() {
|
||||
is_completed = true;
|
||||
state_changed_event.Signal();
|
||||
state_changed_event.Signal(context.kernel);
|
||||
}
|
||||
|
||||
} // namespace Service::AM
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -11,22 +14,23 @@
|
|||
namespace Service::AM {
|
||||
|
||||
AppletStorageChannel::AppletStorageChannel(KernelHelpers::ServiceContext& context)
|
||||
: m_event(context) {}
|
||||
: m_event(context)
|
||||
{}
|
||||
AppletStorageChannel::~AppletStorageChannel() = default;
|
||||
|
||||
void AppletStorageChannel::Push(std::shared_ptr<IStorage> storage) {
|
||||
void AppletStorageChannel::Push(Kernel::KernelCore& kernel, std::shared_ptr<IStorage> storage) {
|
||||
std::scoped_lock lk{m_lock};
|
||||
|
||||
m_data.emplace_back(std::move(storage));
|
||||
m_event.Signal();
|
||||
m_event.Signal(kernel);
|
||||
}
|
||||
|
||||
Result AppletStorageChannel::Pop(std::shared_ptr<IStorage>* out_storage) {
|
||||
Result AppletStorageChannel::Pop(Kernel::KernelCore& kernel, std::shared_ptr<IStorage>* out_storage) {
|
||||
std::scoped_lock lk{m_lock};
|
||||
|
||||
SCOPE_EXIT {
|
||||
if (m_data.empty()) {
|
||||
m_event.Clear();
|
||||
m_event.Clear(kernel);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -22,8 +25,8 @@ public:
|
|||
explicit AppletStorageChannel(KernelHelpers::ServiceContext& ctx);
|
||||
~AppletStorageChannel();
|
||||
|
||||
void Push(std::shared_ptr<IStorage> storage);
|
||||
Result Pop(std::shared_ptr<IStorage>* out_storage);
|
||||
void Push(Kernel::KernelCore& kernel, std::shared_ptr<IStorage> storage);
|
||||
Result Pop(Kernel::KernelCore& kernel, std::shared_ptr<IStorage>* out_storage);
|
||||
Kernel::KReadableEvent* GetEvent();
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -34,8 +34,7 @@ struct LaunchParameterAccountPreselectedUser {
|
|||
};
|
||||
static_assert(sizeof(LaunchParameterAccountPreselectedUser) == 0x88);
|
||||
|
||||
AppletStorageChannel& InitializeFakeCallerApplet(Core::System& system,
|
||||
std::shared_ptr<Applet>& applet) {
|
||||
AppletStorageChannel& InitializeFakeCallerApplet(Core::System& system, std::shared_ptr<Applet>& applet) {
|
||||
applet->caller_applet_broker = std::make_shared<AppletDataBroker>(system);
|
||||
return applet->caller_applet_broker->GetInData();
|
||||
}
|
||||
|
|
@ -52,7 +51,7 @@ void PushInShowQlaunch(Core::System& system, AppletStorageChannel& channel) {
|
|||
|
||||
std::vector<u8> argument_data(sizeof(arguments));
|
||||
std::memcpy(argument_data.data(), &arguments, sizeof(arguments));
|
||||
channel.Push(std::make_shared<IStorage>(system, std::move(argument_data)));
|
||||
channel.Push(system.Kernel(), std::make_shared<IStorage>(system, std::move(argument_data)));
|
||||
}
|
||||
|
||||
void PushInShowAlbum(Core::System& system, AppletStorageChannel& channel) {
|
||||
|
|
@ -68,8 +67,8 @@ void PushInShowAlbum(Core::System& system, AppletStorageChannel& channel) {
|
|||
std::vector<u8> argument_data(sizeof(arguments));
|
||||
std::vector<u8> settings_data{2};
|
||||
std::memcpy(argument_data.data(), &arguments, sizeof(arguments));
|
||||
channel.Push(std::make_shared<IStorage>(system, std::move(argument_data)));
|
||||
channel.Push(std::make_shared<IStorage>(system, std::move(settings_data)));
|
||||
channel.Push(system.Kernel(), std::make_shared<IStorage>(system, std::move(argument_data)));
|
||||
channel.Push(system.Kernel(), std::make_shared<IStorage>(system, std::move(settings_data)));
|
||||
}
|
||||
|
||||
void PushInShowController(Core::System& system, AppletStorageChannel& channel) {
|
||||
|
|
@ -116,9 +115,9 @@ void PushInShowController(Core::System& system, AppletStorageChannel& channel) {
|
|||
std::memcpy(private_args_data.data(), &private_args, sizeof(private_args));
|
||||
std::memcpy(user_args_data.data(), &user_args, sizeof(user_args));
|
||||
|
||||
channel.Push(std::make_shared<IStorage>(system, std::move(common_args_data)));
|
||||
channel.Push(std::make_shared<IStorage>(system, std::move(private_args_data)));
|
||||
channel.Push(std::make_shared<IStorage>(system, std::move(user_args_data)));
|
||||
channel.Push(system.Kernel(), std::make_shared<IStorage>(system, std::move(common_args_data)));
|
||||
channel.Push(system.Kernel(), std::make_shared<IStorage>(system, std::move(private_args_data)));
|
||||
channel.Push(system.Kernel(), std::make_shared<IStorage>(system, std::move(user_args_data)));
|
||||
}
|
||||
|
||||
void PushInShowCabinetData(Core::System& system, AppletStorageChannel& channel) {
|
||||
|
|
@ -146,8 +145,8 @@ void PushInShowCabinetData(Core::System& system, AppletStorageChannel& channel)
|
|||
std::vector<u8> settings_data(sizeof(amiibo_settings));
|
||||
std::memcpy(argument_data.data(), &arguments, sizeof(arguments));
|
||||
std::memcpy(settings_data.data(), &amiibo_settings, sizeof(amiibo_settings));
|
||||
channel.Push(std::make_shared<IStorage>(system, std::move(argument_data)));
|
||||
channel.Push(std::make_shared<IStorage>(system, std::move(settings_data)));
|
||||
channel.Push(system.Kernel(), std::make_shared<IStorage>(system, std::move(argument_data)));
|
||||
channel.Push(system.Kernel(), std::make_shared<IStorage>(system, std::move(settings_data)));
|
||||
}
|
||||
|
||||
void PushInShowMiiEditData(Core::System& system, AppletStorageChannel& channel) {
|
||||
|
|
@ -169,7 +168,7 @@ void PushInShowMiiEditData(Core::System& system, AppletStorageChannel& channel)
|
|||
std::vector<u8> argument_data(sizeof(mii_arguments));
|
||||
std::memcpy(argument_data.data(), &mii_arguments, sizeof(mii_arguments));
|
||||
|
||||
channel.Push(std::make_shared<IStorage>(system, std::move(argument_data)));
|
||||
channel.Push(system.Kernel(), std::make_shared<IStorage>(system, std::move(argument_data)));
|
||||
}
|
||||
|
||||
void PushInShowSoftwareKeyboard(Core::System& system, AppletStorageChannel& channel) {
|
||||
|
|
@ -222,9 +221,9 @@ void PushInShowSoftwareKeyboard(Core::System& system, AppletStorageChannel& chan
|
|||
std::memcpy(work_buffer.data(), initial_string.data(),
|
||||
swkbd_config.initial_string_length * sizeof(char16_t));
|
||||
|
||||
channel.Push(std::make_shared<IStorage>(system, std::move(argument_data)));
|
||||
channel.Push(std::make_shared<IStorage>(system, std::move(swkbd_data)));
|
||||
channel.Push(std::make_shared<IStorage>(system, std::move(work_buffer)));
|
||||
channel.Push(system.Kernel(), std::make_shared<IStorage>(system, std::move(argument_data)));
|
||||
channel.Push(system.Kernel(), std::make_shared<IStorage>(system, std::move(swkbd_data)));
|
||||
channel.Push(system.Kernel(), std::make_shared<IStorage>(system, std::move(work_buffer)));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
@ -340,7 +339,7 @@ void AppletManager::SetWindowSystem(WindowSystem* window_system) {
|
|||
}
|
||||
|
||||
// Applet was started by frontend, so it is foreground.
|
||||
applet->lifecycle_manager.SetFocusState(FocusState::InFocus);
|
||||
applet->lifecycle_manager.SetFocusState(m_system.Kernel(), FocusState::InFocus);
|
||||
|
||||
if (applet->applet_id == AppletId::QLaunch) {
|
||||
applet->lifecycle_manager.SetFocusHandlingMode(false);
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ EventObserver::EventObserver(Core::System& system, WindowSystem& window_system)
|
|||
EventObserver::~EventObserver() {
|
||||
// Signal thread and wait for processing to finish.
|
||||
m_stop_source.request_stop();
|
||||
m_wakeup_event.Signal();
|
||||
m_wakeup_event.Signal(m_system.Kernel());
|
||||
m_thread.join();
|
||||
|
||||
// Free remaining owned sessions.
|
||||
|
|
@ -76,11 +76,11 @@ void EventObserver::TrackAppletProcess(Applet& applet) {
|
|||
}
|
||||
|
||||
// Signal wakeup.
|
||||
m_wakeup_event.Signal();
|
||||
m_wakeup_event.Signal(m_system.Kernel());
|
||||
}
|
||||
|
||||
void EventObserver::RequestUpdate() {
|
||||
m_wakeup_event.Signal();
|
||||
m_wakeup_event.Signal(m_system.Kernel());
|
||||
}
|
||||
|
||||
void EventObserver::LinkDeferred() {
|
||||
|
|
@ -121,7 +121,7 @@ void EventObserver::Process(MultiWaitHolder* holder) {
|
|||
}
|
||||
|
||||
void EventObserver::OnWakeupEvent(MultiWaitHolder* holder) {
|
||||
m_wakeup_event.Clear();
|
||||
m_wakeup_event.Clear(m_system.Kernel());
|
||||
|
||||
// Perform recalculation.
|
||||
m_window_system.Update();
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue