mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-07-11 02:16:39 +02:00
[video_core, hle] remove redundant parent references in system structs (#3908)
reworked a bit to remove references of parent objects and instead pass as arguments to methods to prevent useless reloads Signed-off-by: lizzie <lizzie@eden-emu.dev> Co-authored-by: maufeat <sahyno1996@gmail.com> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3908 Reviewed-by: Maufeat <sahyno1996@gmail.com> Reviewed-by: crueter <crueter@eden-emu.dev>
This commit is contained in:
@@ -7,7 +7,6 @@
|
|||||||
# Build directory
|
# Build directory
|
||||||
/[Bb]uild*/
|
/[Bb]uild*/
|
||||||
doc-build/
|
doc-build/
|
||||||
out/
|
|
||||||
AppDir/
|
AppDir/
|
||||||
uruntime
|
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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -8,10 +11,11 @@
|
|||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
|
|
||||||
AudioCore::AudioCore(Core::System& system) : audio_manager{std::make_unique<AudioManager>()} {
|
AudioCore::AudioCore(Core::System& system) {
|
||||||
|
audio_manager.emplace();
|
||||||
CreateSinks();
|
CreateSinks();
|
||||||
// Must be created after the sinks
|
// Must be created after the sinks
|
||||||
adsp = std::make_unique<ADSP::ADSP>(system, *output_sink);
|
adsp.emplace(system, *output_sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioCore ::~AudioCore() {
|
AudioCore ::~AudioCore() {
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -15,10 +18,7 @@ class System;
|
|||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
|
|
||||||
class AudioManager;
|
/// @brief Main audio class, stored inside the core, and holding the audio manager, all sinks, and the ADSP.
|
||||||
/**
|
|
||||||
* Main audio class, stored inside the core, and holding the audio manager, all sinks, and the ADSP.
|
|
||||||
*/
|
|
||||||
class AudioCore {
|
class AudioCore {
|
||||||
public:
|
public:
|
||||||
explicit AudioCore(Core::System& system);
|
explicit AudioCore(Core::System& system);
|
||||||
@@ -50,27 +50,22 @@ public:
|
|||||||
*/
|
*/
|
||||||
Sink::Sink& GetInputSink();
|
Sink::Sink& GetInputSink();
|
||||||
|
|
||||||
/**
|
/// @brief Get the ADSP.
|
||||||
* Get the ADSP.
|
/// @return Ref to the ADSP.
|
||||||
*
|
|
||||||
* @return Ref to the ADSP.
|
|
||||||
*/
|
|
||||||
ADSP::ADSP& ADSP();
|
ADSP::ADSP& ADSP();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/// @brief Create the sinks on startup.
|
||||||
* Create the sinks on startup.
|
|
||||||
*/
|
|
||||||
void CreateSinks();
|
void CreateSinks();
|
||||||
|
|
||||||
/// Main audio manager for audio in/out
|
/// Main audio manager for audio in/out
|
||||||
std::unique_ptr<AudioManager> audio_manager;
|
std::optional<AudioManager> audio_manager;
|
||||||
/// Sink used for audio renderer and audio out
|
/// Sink used for audio renderer and audio out
|
||||||
std::unique_ptr<Sink::Sink> output_sink;
|
std::unique_ptr<Sink::Sink> output_sink;
|
||||||
/// Sink used for audio input
|
/// Sink used for audio input
|
||||||
std::unique_ptr<Sink::Sink> input_sink;
|
std::unique_ptr<Sink::Sink> input_sink;
|
||||||
/// The ADSP in the sysmodule
|
/// The ADSP in the sysmodule
|
||||||
std::unique_ptr<ADSP::ADSP> adsp;
|
std::optional<ADSP::ADSP> adsp;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace AudioCore
|
} // namespace AudioCore
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -41,8 +44,7 @@ void Manager::ReleaseSessionId(const size_t session_id) {
|
|||||||
Result Manager::LinkToManager() {
|
Result Manager::LinkToManager() {
|
||||||
std::scoped_lock l{mutex};
|
std::scoped_lock l{mutex};
|
||||||
if (!linked_to_manager) {
|
if (!linked_to_manager) {
|
||||||
AudioManager& manager{system.AudioCore().GetAudioManager()};
|
system.AudioCore().GetAudioManager().SetInManager(std::bind(&Manager::BufferReleaseAndRegister, this));
|
||||||
manager.SetInManager(std::bind(&Manager::BufferReleaseAndRegister, this));
|
|
||||||
linked_to_manager = true;
|
linked_to_manager = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,81 +1,77 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "audio_core/audio_manager.h"
|
#include "audio_core/audio_manager.h"
|
||||||
|
#include "common/thread.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/hle/service/audio/errors.h"
|
#include "core/hle/service/audio/errors.h"
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
|
|
||||||
AudioManager::AudioManager() {
|
AudioManager::AudioManager() {
|
||||||
thread = std::jthread([this]() { ThreadFunc(); });
|
thread = std::jthread([this](std::stop_token stop_token) {
|
||||||
|
Common::SetCurrentThreadName("AudioManager");
|
||||||
|
std::unique_lock l{events.GetAudioEventLock()};
|
||||||
|
events.ClearEvents();
|
||||||
|
while (!stop_token.stop_requested()) {
|
||||||
|
const auto timed_out{events.Wait(l, std::chrono::seconds(2))};
|
||||||
|
if (events.CheckAudioEventSet(Event::Type::Max)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < buffer_events.size(); i++) {
|
||||||
|
const auto event_type = Event::Type(i);
|
||||||
|
if (events.CheckAudioEventSet(event_type) || timed_out) {
|
||||||
|
if (buffer_events[i]) {
|
||||||
|
buffer_events[i]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
events.SetAudioEvent(event_type, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioManager::Shutdown() {
|
void AudioManager::Shutdown() {
|
||||||
running = false;
|
|
||||||
events.SetAudioEvent(Event::Type::Max, true);
|
events.SetAudioEvent(Event::Type::Max, true);
|
||||||
thread.join();
|
if (thread.joinable()) {
|
||||||
|
thread.request_stop();
|
||||||
|
thread.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result AudioManager::SetOutManager(BufferEventFunc buffer_func) {
|
Result AudioManager::SetOutManager(BufferEventFunc buffer_func) {
|
||||||
if (!running) {
|
if (thread.joinable()) {
|
||||||
return Service::Audio::ResultOperationFailed;
|
std::scoped_lock l{lock};
|
||||||
|
const auto index{events.GetManagerIndex(Event::Type::AudioOutManager)};
|
||||||
|
if (buffer_events[index] == nullptr) {
|
||||||
|
buffer_events[index] = std::move(buffer_func);
|
||||||
|
needs_update = true;
|
||||||
|
events.SetAudioEvent(Event::Type::AudioOutManager, true);
|
||||||
|
}
|
||||||
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
return Service::Audio::ResultOperationFailed;
|
||||||
std::scoped_lock l{lock};
|
|
||||||
|
|
||||||
const auto index{events.GetManagerIndex(Event::Type::AudioOutManager)};
|
|
||||||
if (buffer_events[index] == nullptr) {
|
|
||||||
buffer_events[index] = std::move(buffer_func);
|
|
||||||
needs_update = true;
|
|
||||||
events.SetAudioEvent(Event::Type::AudioOutManager, true);
|
|
||||||
}
|
|
||||||
return ResultSuccess;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result AudioManager::SetInManager(BufferEventFunc buffer_func) {
|
Result AudioManager::SetInManager(BufferEventFunc buffer_func) {
|
||||||
if (!running) {
|
if (thread.joinable()) {
|
||||||
return Service::Audio::ResultOperationFailed;
|
std::scoped_lock l{lock};
|
||||||
|
const auto index{events.GetManagerIndex(Event::Type::AudioInManager)};
|
||||||
|
if (buffer_events[index] == nullptr) {
|
||||||
|
buffer_events[index] = std::move(buffer_func);
|
||||||
|
needs_update = true;
|
||||||
|
events.SetAudioEvent(Event::Type::AudioInManager, true);
|
||||||
|
}
|
||||||
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
return Service::Audio::ResultOperationFailed;
|
||||||
std::scoped_lock l{lock};
|
|
||||||
|
|
||||||
const auto index{events.GetManagerIndex(Event::Type::AudioInManager)};
|
|
||||||
if (buffer_events[index] == nullptr) {
|
|
||||||
buffer_events[index] = std::move(buffer_func);
|
|
||||||
needs_update = true;
|
|
||||||
events.SetAudioEvent(Event::Type::AudioInManager, true);
|
|
||||||
}
|
|
||||||
return ResultSuccess;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioManager::SetEvent(const Event::Type type, const bool signalled) {
|
void AudioManager::SetEvent(const Event::Type type, const bool signalled) {
|
||||||
events.SetAudioEvent(type, signalled);
|
events.SetAudioEvent(type, signalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioManager::ThreadFunc() {
|
|
||||||
std::unique_lock l{events.GetAudioEventLock()};
|
|
||||||
events.ClearEvents();
|
|
||||||
running = true;
|
|
||||||
|
|
||||||
while (running) {
|
|
||||||
const auto timed_out{events.Wait(l, std::chrono::seconds(2))};
|
|
||||||
|
|
||||||
if (events.CheckAudioEventSet(Event::Type::Max)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < buffer_events.size(); i++) {
|
|
||||||
const auto event_type = static_cast<Event::Type>(i);
|
|
||||||
|
|
||||||
if (events.CheckAudioEventSet(event_type) || timed_out) {
|
|
||||||
if (buffer_events[i]) {
|
|
||||||
buffer_events[i]();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
events.SetAudioEvent(event_type, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace AudioCore
|
} // namespace AudioCore
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -66,13 +69,6 @@ public:
|
|||||||
void SetEvent(Event::Type type, bool signalled);
|
void SetEvent(Event::Type type, bool signalled);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* Main thread, waiting on a manager signal and calling the registered function.
|
|
||||||
*/
|
|
||||||
void ThreadFunc();
|
|
||||||
|
|
||||||
/// Is the main thread running?
|
|
||||||
std::atomic<bool> running{};
|
|
||||||
/// Unused
|
/// Unused
|
||||||
bool needs_update{};
|
bool needs_update{};
|
||||||
/// Events to be set and signalled
|
/// Events to be set and signalled
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -40,8 +43,7 @@ void Manager::ReleaseSessionId(const size_t session_id) {
|
|||||||
Result Manager::LinkToManager() {
|
Result Manager::LinkToManager() {
|
||||||
std::scoped_lock l{mutex};
|
std::scoped_lock l{mutex};
|
||||||
if (!linked_to_manager) {
|
if (!linked_to_manager) {
|
||||||
AudioManager& manager{system.AudioCore().GetAudioManager()};
|
system.AudioCore().GetAudioManager().SetOutManager(std::bind(&Manager::BufferReleaseAndRegister, this));
|
||||||
manager.SetOutManager(std::bind(&Manager::BufferReleaseAndRegister, this));
|
|
||||||
linked_to_manager = true;
|
linked_to_manager = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// 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_;
|
channel_count = channel_count_;
|
||||||
session_id = session_id_;
|
session_id = session_id_;
|
||||||
handle = handle_;
|
handle = handle_;
|
||||||
handle->Open();
|
handle->Open(system.Kernel());
|
||||||
applet_resource_user_id = applet_resource_user_id_;
|
applet_resource_user_id = applet_resource_user_id_;
|
||||||
|
|
||||||
if (type == Sink::StreamType::In) {
|
if (type == Sink::StreamType::In) {
|
||||||
@@ -60,7 +63,7 @@ void DeviceSession::Finalize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (handle) {
|
if (handle) {
|
||||||
handle->Close();
|
handle->Close(system.Kernel());
|
||||||
handle = nullptr;
|
handle = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ Result System::Stop() {
|
|||||||
session->SetVolume(0.0f);
|
session->SetVolume(0.0f);
|
||||||
session->ClearBuffers();
|
session->ClearBuffers();
|
||||||
if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) {
|
if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) {
|
||||||
buffer_event->Signal();
|
buffer_event->Signal(system.Kernel());
|
||||||
}
|
}
|
||||||
state = State::Stopped;
|
state = State::Stopped;
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ void System::ReleaseBuffers() {
|
|||||||
|
|
||||||
if (signal) {
|
if (signal) {
|
||||||
// Signal if any buffer was released, or if none are registered, we need more.
|
// 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);
|
buffers.FlushBuffers(buffers_released);
|
||||||
|
|
||||||
if (buffers_released > 0) {
|
if (buffers_released > 0) {
|
||||||
buffer_event->Signal();
|
buffer_event->Signal(system.Kernel());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ Result System::Stop() {
|
|||||||
session->SetVolume(0.0f);
|
session->SetVolume(0.0f);
|
||||||
session->ClearBuffers();
|
session->ClearBuffers();
|
||||||
if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) {
|
if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) {
|
||||||
buffer_event->Signal();
|
buffer_event->Signal(system.Kernel());
|
||||||
}
|
}
|
||||||
state = State::Stopped;
|
state = State::Stopped;
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ void System::ReleaseBuffers() {
|
|||||||
bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session, false)};
|
bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session, false)};
|
||||||
if (signal) {
|
if (signal) {
|
||||||
// Signal if any buffer was released, or if none are registered, we need more.
|
// 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);
|
buffers.FlushBuffers(buffers_released);
|
||||||
|
|
||||||
if (buffers_released > 0) {
|
if (buffers_released > 0) {
|
||||||
buffer_event->Signal();
|
buffer_event->Signal(system.Kernel());
|
||||||
}
|
}
|
||||||
return true;
|
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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
// 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
adsp_rendered_event->Clear();
|
adsp_rendered_event->Clear(core.Kernel());
|
||||||
num_times_updated++;
|
num_times_updated++;
|
||||||
|
|
||||||
const auto end_time{core.CoreTiming().GetGlobalTimeNs().count()};
|
const auto end_time{core.CoreTiming().GetGlobalTimeNs().count()};
|
||||||
@@ -624,7 +624,7 @@ void System::SendCommandToDsp() {
|
|||||||
reset_command_buffers = false;
|
reset_command_buffers = false;
|
||||||
command_buffer_size = command_size;
|
command_buffer_size = command_size;
|
||||||
if (remaining_command_count == 0) {
|
if (remaining_command_count == 0) {
|
||||||
adsp_rendered_event->Signal();
|
adsp_rendered_event->Signal(core.Kernel());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
audio_renderer.ClearRemainCommandCount(session_id);
|
audio_renderer.ClearRemainCommandCount(session_id);
|
||||||
|
|||||||
+7
-9
@@ -108,7 +108,7 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
|
|||||||
|
|
||||||
struct System::Impl {
|
struct System::Impl {
|
||||||
explicit Impl(System& system)
|
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{} {}
|
reporter{system}, applet_manager{system}, frontend_applets{system}, profile_manager{} {}
|
||||||
|
|
||||||
u64 program_id;
|
u64 program_id;
|
||||||
@@ -271,7 +271,7 @@ struct System::Impl {
|
|||||||
|
|
||||||
SystemResultStatus SetupForApplicationProcess(System& system, Frontend::EmuWindow& emu_window) {
|
SystemResultStatus SetupForApplicationProcess(System& system, Frontend::EmuWindow& emu_window) {
|
||||||
host1x_core.emplace(system);
|
host1x_core.emplace(system);
|
||||||
gpu_core = VideoCore::CreateGPU(emu_window, system);
|
VideoCore::CreateGPU(gpu_core, emu_window, system);
|
||||||
if (!gpu_core)
|
if (!gpu_core)
|
||||||
return SystemResultStatus::ErrorVideoCore;
|
return SystemResultStatus::ErrorVideoCore;
|
||||||
|
|
||||||
@@ -347,7 +347,7 @@ struct System::Impl {
|
|||||||
|
|
||||||
// Register with applet manager
|
// Register with applet manager
|
||||||
// All threads are started, begin main process execution, now that we're in the clear
|
// All threads are started, begin main process execution, now that we're in the clear
|
||||||
applet_manager.CreateAndInsertByFrontendAppletParameters(std::move(process), params);
|
applet_manager.CreateAndInsertByFrontendAppletParameters(std::make_unique<Service::Process>(*std::move(process)), params);
|
||||||
|
|
||||||
if (Settings::values.gamecard_inserted) {
|
if (Settings::values.gamecard_inserted) {
|
||||||
if (Settings::values.gamecard_current_game) {
|
if (Settings::values.gamecard_current_game) {
|
||||||
@@ -391,10 +391,8 @@ struct System::Impl {
|
|||||||
is_powered_on = false;
|
is_powered_on = false;
|
||||||
exit_locked = false;
|
exit_locked = false;
|
||||||
exit_requested = false;
|
exit_requested = false;
|
||||||
|
if (gpu_core)
|
||||||
if (gpu_core != nullptr) {
|
|
||||||
gpu_core->NotifyShutdown();
|
gpu_core->NotifyShutdown();
|
||||||
}
|
|
||||||
|
|
||||||
stop_event.request_stop();
|
stop_event.request_stop();
|
||||||
core_timing.SyncPause(false);
|
core_timing.SyncPause(false);
|
||||||
@@ -478,6 +476,7 @@ struct System::Impl {
|
|||||||
std::optional<Memory::CheatEngine> cheat_engine;
|
std::optional<Memory::CheatEngine> cheat_engine;
|
||||||
std::optional<Tools::Freezer> memory_freezer;
|
std::optional<Tools::Freezer> memory_freezer;
|
||||||
std::optional<Tools::RenderdocAPI> renderdoc_api;
|
std::optional<Tools::RenderdocAPI> renderdoc_api;
|
||||||
|
std::optional<Tegra::GPU> gpu_core;
|
||||||
|
|
||||||
std::array<Core::GPUDirtyMemoryManager, Core::Hardware::NUM_CPU_CORES> gpu_dirty_memory_managers;
|
std::array<Core::GPUDirtyMemoryManager, Core::Hardware::NUM_CPU_CORES> gpu_dirty_memory_managers;
|
||||||
std::vector<std::vector<u8>> user_channel;
|
std::vector<std::vector<u8>> user_channel;
|
||||||
@@ -492,7 +491,6 @@ struct System::Impl {
|
|||||||
std::unique_ptr<FileSys::ContentProviderUnion> content_provider;
|
std::unique_ptr<FileSys::ContentProviderUnion> content_provider;
|
||||||
/// AppLoader used to load the current executing application
|
/// AppLoader used to load the current executing application
|
||||||
std::unique_ptr<Loader::AppLoader> app_loader;
|
std::unique_ptr<Loader::AppLoader> app_loader;
|
||||||
std::unique_ptr<Tegra::GPU> gpu_core;
|
|
||||||
std::stop_source stop_event;
|
std::stop_source stop_event;
|
||||||
|
|
||||||
mutable std::mutex suspend_guard;
|
mutable std::mutex suspend_guard;
|
||||||
@@ -925,7 +923,7 @@ void System::PushGeneralChannelData(std::vector<u8>&& data) {
|
|||||||
const bool was_empty = impl->general_channel.empty();
|
const bool was_empty = impl->general_channel.empty();
|
||||||
impl->general_channel.push_back(std::move(data));
|
impl->general_channel.push_back(std::move(data));
|
||||||
if (was_empty) {
|
if (was_empty) {
|
||||||
impl->general_channel_event->Signal();
|
impl->general_channel_event->Signal(impl->kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -937,7 +935,7 @@ bool System::TryPopGeneralChannel(std::vector<u8>& out_data) {
|
|||||||
out_data = std::move(impl->general_channel.back());
|
out_data = std::move(impl->general_channel.back());
|
||||||
impl->general_channel.pop_back();
|
impl->general_channel.pop_back();
|
||||||
if (impl->general_channel.empty()) {
|
if (impl->general_channel.empty()) {
|
||||||
impl->general_channel_event->Clear();
|
impl->general_channel_event->Clear(impl->kernel);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -438,7 +438,6 @@ public:
|
|||||||
/// Applies any changes to settings to this core instance.
|
/// Applies any changes to settings to this core instance.
|
||||||
void ApplySettings();
|
void ApplySettings();
|
||||||
|
|
||||||
private:
|
|
||||||
struct Impl;
|
struct Impl;
|
||||||
std::unique_ptr<Impl> impl;
|
std::unique_ptr<Impl> impl;
|
||||||
};
|
};
|
||||||
|
|||||||
+35
-50
@@ -25,9 +25,11 @@ CpuManager::~CpuManager() = default;
|
|||||||
|
|
||||||
void CpuManager::Initialize() {
|
void CpuManager::Initialize() {
|
||||||
num_cores = is_multicore ? Core::Hardware::NUM_CPU_CORES : 1;
|
num_cores = is_multicore ? Core::Hardware::NUM_CPU_CORES : 1;
|
||||||
gpu_barrier = std::make_unique<Common::Barrier>(num_cores + 1);
|
gpu_barrier.emplace(num_cores + 1);
|
||||||
for (std::size_t core = 0; core < num_cores; core++)
|
for (std::size_t core = 0; core < num_cores; core++)
|
||||||
core_data[core].host_thread = std::jthread([this, core](std::stop_token token) { RunThread(token, core); });
|
core_data[core].host_thread = std::jthread([this, core](std::stop_token token) {
|
||||||
|
RunThread(token, core);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpuManager::Shutdown() {
|
void CpuManager::Shutdown() {
|
||||||
@@ -39,69 +41,61 @@ void CpuManager::Shutdown() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpuManager::GuestThreadFunction() {
|
void CpuManager::GuestThreadFunction(Kernel::KernelCore& kernel) {
|
||||||
if (is_multicore) {
|
if (is_multicore) {
|
||||||
MultiCoreRunGuestThread();
|
MultiCoreRunGuestThread(kernel);
|
||||||
} else {
|
} else {
|
||||||
SingleCoreRunGuestThread();
|
SingleCoreRunGuestThread(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpuManager::IdleThreadFunction() {
|
void CpuManager::IdleThreadFunction(Kernel::KernelCore& kernel) {
|
||||||
if (is_multicore) {
|
if (is_multicore) {
|
||||||
MultiCoreRunIdleThread();
|
MultiCoreRunIdleThread(kernel);
|
||||||
} else {
|
} else {
|
||||||
SingleCoreRunIdleThread();
|
SingleCoreRunIdleThread(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpuManager::ShutdownThreadFunction() {
|
void CpuManager::ShutdownThreadFunction(Kernel::KernelCore& kernel) {
|
||||||
ShutdownThread();
|
ShutdownThread(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpuManager::HandleInterrupt() {
|
void CpuManager::HandleInterrupt(Kernel::KernelCore& kernel) {
|
||||||
auto& kernel = system.Kernel();
|
|
||||||
auto core_index = kernel.CurrentPhysicalCoreIndex();
|
auto core_index = kernel.CurrentPhysicalCoreIndex();
|
||||||
|
Kernel::KInterruptManager::HandleInterrupt(kernel, s32(core_index));
|
||||||
Kernel::KInterruptManager::HandleInterrupt(kernel, static_cast<s32>(core_index));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
/// MultiCore ///
|
/// MultiCore ///
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void CpuManager::MultiCoreRunGuestThread() {
|
void CpuManager::MultiCoreRunGuestThread(Kernel::KernelCore& kernel) {
|
||||||
// Similar to UserModeThreadStarter in HOS
|
// Similar to UserModeThreadStarter in HOS
|
||||||
auto& kernel = system.Kernel();
|
|
||||||
auto* thread = Kernel::GetCurrentThreadPointer(kernel);
|
auto* thread = Kernel::GetCurrentThreadPointer(kernel);
|
||||||
kernel.CurrentScheduler()->OnThreadStart();
|
kernel.CurrentScheduler()->OnThreadStart(kernel);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
auto* physical_core = &kernel.CurrentPhysicalCore();
|
auto* physical_core = &kernel.CurrentPhysicalCore();
|
||||||
while (!physical_core->IsInterrupted()) {
|
while (!physical_core->IsInterrupted()) {
|
||||||
physical_core->RunThread(thread);
|
physical_core->RunThread(kernel, thread);
|
||||||
physical_core = &kernel.CurrentPhysicalCore();
|
physical_core = &kernel.CurrentPhysicalCore();
|
||||||
}
|
}
|
||||||
|
HandleInterrupt(kernel);
|
||||||
HandleInterrupt();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpuManager::MultiCoreRunIdleThread() {
|
void CpuManager::MultiCoreRunIdleThread(Kernel::KernelCore& kernel) {
|
||||||
// Not accurate to HOS. Remove this entire method when singlecore is removed.
|
// Not accurate to HOS. Remove this entire method when singlecore is removed.
|
||||||
// See notes in KScheduler::ScheduleImpl for more information about why this
|
// See notes in KScheduler::ScheduleImpl for more information about why this
|
||||||
// is inaccurate.
|
// is inaccurate.
|
||||||
|
kernel.CurrentScheduler()->OnThreadStart(kernel);
|
||||||
auto& kernel = system.Kernel();
|
|
||||||
kernel.CurrentScheduler()->OnThreadStart();
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
auto& physical_core = kernel.CurrentPhysicalCore();
|
auto& physical_core = kernel.CurrentPhysicalCore();
|
||||||
if (!physical_core.IsInterrupted()) {
|
if (!physical_core.IsInterrupted()) {
|
||||||
physical_core.Idle();
|
physical_core.Idle();
|
||||||
}
|
}
|
||||||
|
HandleInterrupt(kernel);
|
||||||
HandleInterrupt();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,15 +103,14 @@ void CpuManager::MultiCoreRunIdleThread() {
|
|||||||
/// SingleCore ///
|
/// SingleCore ///
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void CpuManager::SingleCoreRunGuestThread() {
|
void CpuManager::SingleCoreRunGuestThread(Kernel::KernelCore& kernel) {
|
||||||
auto& kernel = system.Kernel();
|
|
||||||
auto* thread = Kernel::GetCurrentThreadPointer(kernel);
|
auto* thread = Kernel::GetCurrentThreadPointer(kernel);
|
||||||
kernel.CurrentScheduler()->OnThreadStart();
|
kernel.CurrentScheduler()->OnThreadStart(kernel);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
auto* physical_core = &kernel.CurrentPhysicalCore();
|
auto* physical_core = &kernel.CurrentPhysicalCore();
|
||||||
if (!physical_core->IsInterrupted()) {
|
if (!physical_core->IsInterrupted()) {
|
||||||
physical_core->RunThread(thread);
|
physical_core->RunThread(kernel, thread);
|
||||||
physical_core = &kernel.CurrentPhysicalCore();
|
physical_core = &kernel.CurrentPhysicalCore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,26 +118,22 @@ void CpuManager::SingleCoreRunGuestThread() {
|
|||||||
system.CoreTiming().Advance();
|
system.CoreTiming().Advance();
|
||||||
kernel.SetIsPhantomModeForSingleCore(false);
|
kernel.SetIsPhantomModeForSingleCore(false);
|
||||||
|
|
||||||
PreemptSingleCore();
|
PreemptSingleCore(kernel);
|
||||||
HandleInterrupt();
|
HandleInterrupt(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpuManager::SingleCoreRunIdleThread() {
|
void CpuManager::SingleCoreRunIdleThread(Kernel::KernelCore& kernel) {
|
||||||
auto& kernel = system.Kernel();
|
kernel.CurrentScheduler()->OnThreadStart(kernel);
|
||||||
kernel.CurrentScheduler()->OnThreadStart();
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
PreemptSingleCore(false);
|
PreemptSingleCore(kernel, false);
|
||||||
system.CoreTiming().AddTicks(1000U);
|
system.CoreTiming().AddTicks(1000U);
|
||||||
idle_count++;
|
idle_count++;
|
||||||
HandleInterrupt();
|
HandleInterrupt(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpuManager::PreemptSingleCore(bool from_running_environment) {
|
void CpuManager::PreemptSingleCore(Kernel::KernelCore& kernel, bool from_running_environment) {
|
||||||
auto& kernel = system.Kernel();
|
|
||||||
|
|
||||||
if (idle_count >= 4 || from_running_environment) {
|
if (idle_count >= 4 || from_running_environment) {
|
||||||
if (!from_running_environment) {
|
if (!from_running_environment) {
|
||||||
system.CoreTiming().Idle();
|
system.CoreTiming().Idle();
|
||||||
@@ -156,7 +145,7 @@ void CpuManager::PreemptSingleCore(bool from_running_environment) {
|
|||||||
}
|
}
|
||||||
current_core.store((current_core + 1) % Core::Hardware::NUM_CPU_CORES);
|
current_core.store((current_core + 1) % Core::Hardware::NUM_CPU_CORES);
|
||||||
system.CoreTiming().ResetTicks();
|
system.CoreTiming().ResetTicks();
|
||||||
kernel.Scheduler(current_core).PreemptSingleCore();
|
kernel.Scheduler(current_core).PreemptSingleCore(kernel);
|
||||||
|
|
||||||
// We've now been scheduled again, and we may have exchanged schedulers.
|
// We've now been scheduled again, and we may have exchanged schedulers.
|
||||||
// Reload the scheduler in case it's different.
|
// Reload the scheduler in case it's different.
|
||||||
@@ -165,20 +154,16 @@ void CpuManager::PreemptSingleCore(bool from_running_environment) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpuManager::GuestActivate() {
|
void CpuManager::GuestActivate(Kernel::KernelCore& kernel) {
|
||||||
// Similar to the HorizonKernelMain callback in HOS
|
// Similar to the HorizonKernelMain callback in HOS
|
||||||
auto& kernel = system.Kernel();
|
|
||||||
auto* scheduler = kernel.CurrentScheduler();
|
auto* scheduler = kernel.CurrentScheduler();
|
||||||
|
scheduler->Activate(kernel);
|
||||||
scheduler->Activate();
|
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpuManager::ShutdownThread() {
|
void CpuManager::ShutdownThread(Kernel::KernelCore& kernel) {
|
||||||
auto& kernel = system.Kernel();
|
|
||||||
auto* thread = kernel.GetCurrentEmuThread();
|
auto* thread = kernel.GetCurrentEmuThread();
|
||||||
auto core = is_multicore ? kernel.CurrentPhysicalCoreIndex() : 0;
|
auto core = is_multicore ? kernel.CurrentPhysicalCoreIndex() : 0;
|
||||||
|
|
||||||
Common::Fiber::YieldTo(thread->GetHostContext(), *core_data[core].host_context);
|
Common::Fiber::YieldTo(thread->GetHostContext(), *core_data[core].host_context);
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-27
@@ -1,3 +1,6 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -14,6 +17,10 @@
|
|||||||
#include "common/thread.h"
|
#include "common/thread.h"
|
||||||
#include "core/hardware_properties.h"
|
#include "core/hardware_properties.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
class KernelCore;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
class Event;
|
class Event;
|
||||||
class Fiber;
|
class Fiber;
|
||||||
@@ -51,57 +58,55 @@ public:
|
|||||||
void Initialize();
|
void Initialize();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
std::function<void()> GetGuestActivateFunc() {
|
std::function<void()> GetGuestActivateFunc(Kernel::KernelCore& kernel) {
|
||||||
return [this] { GuestActivate(); };
|
return [this, &kernel] { GuestActivate(kernel); };
|
||||||
}
|
}
|
||||||
std::function<void()> GetGuestThreadFunc() {
|
std::function<void()> GetGuestThreadFunc(Kernel::KernelCore& kernel) {
|
||||||
return [this] { GuestThreadFunction(); };
|
return [this, &kernel] { GuestThreadFunction(kernel); };
|
||||||
}
|
}
|
||||||
std::function<void()> GetIdleThreadStartFunc() {
|
std::function<void()> GetIdleThreadStartFunc(Kernel::KernelCore& kernel) {
|
||||||
return [this] { IdleThreadFunction(); };
|
return [this, &kernel] { IdleThreadFunction(kernel); };
|
||||||
}
|
}
|
||||||
std::function<void()> GetShutdownThreadStartFunc() {
|
std::function<void()> GetShutdownThreadStartFunc(Kernel::KernelCore& kernel) {
|
||||||
return [this] { ShutdownThreadFunction(); };
|
return [this, &kernel] { ShutdownThreadFunction(kernel); };
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreemptSingleCore(bool from_running_environment = true);
|
void PreemptSingleCore(Kernel::KernelCore& kernel, bool from_running_environment = true);
|
||||||
|
|
||||||
std::size_t CurrentCore() const {
|
std::size_t CurrentCore() const {
|
||||||
return current_core.load();
|
return current_core.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void GuestThreadFunction();
|
void GuestThreadFunction(Kernel::KernelCore& kernel);
|
||||||
void IdleThreadFunction();
|
void IdleThreadFunction(Kernel::KernelCore& kernel);
|
||||||
void ShutdownThreadFunction();
|
void ShutdownThreadFunction(Kernel::KernelCore& kernel);
|
||||||
|
|
||||||
void MultiCoreRunGuestThread();
|
void MultiCoreRunGuestThread(Kernel::KernelCore& kernel);
|
||||||
void MultiCoreRunIdleThread();
|
void MultiCoreRunIdleThread(Kernel::KernelCore& kernel);
|
||||||
|
|
||||||
void SingleCoreRunGuestThread();
|
void SingleCoreRunGuestThread(Kernel::KernelCore& kernel);
|
||||||
void SingleCoreRunIdleThread();
|
void SingleCoreRunIdleThread(Kernel::KernelCore& kernel);
|
||||||
|
|
||||||
void GuestActivate();
|
void GuestActivate(Kernel::KernelCore& kernel);
|
||||||
void HandleInterrupt();
|
void HandleInterrupt(Kernel::KernelCore& kernel);
|
||||||
void ShutdownThread();
|
void ShutdownThread(Kernel::KernelCore& kernel);
|
||||||
void RunThread(std::stop_token stop_token, std::size_t core);
|
void RunThread(std::stop_token stop_token, std::size_t core);
|
||||||
|
|
||||||
|
static constexpr std::size_t max_cycle_runs = 5;
|
||||||
|
|
||||||
|
std::optional<Common::Barrier> gpu_barrier{};
|
||||||
struct CoreData {
|
struct CoreData {
|
||||||
std::shared_ptr<Common::Fiber> host_context;
|
std::shared_ptr<Common::Fiber> host_context;
|
||||||
std::jthread host_thread;
|
std::jthread host_thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<Common::Barrier> gpu_barrier{};
|
|
||||||
std::array<CoreData, Core::Hardware::NUM_CPU_CORES> core_data{};
|
std::array<CoreData, Core::Hardware::NUM_CPU_CORES> core_data{};
|
||||||
|
Core::System& system;
|
||||||
bool is_async_gpu{};
|
|
||||||
bool is_multicore{};
|
|
||||||
std::atomic<std::size_t> current_core{};
|
std::atomic<std::size_t> current_core{};
|
||||||
std::size_t idle_count{};
|
std::size_t idle_count{};
|
||||||
std::size_t num_cores{};
|
std::size_t num_cores{};
|
||||||
static constexpr std::size_t max_cycle_runs = 5;
|
bool is_async_gpu{};
|
||||||
|
bool is_multicore{};
|
||||||
System& system;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|||||||
@@ -81,7 +81,10 @@ namespace Core {
|
|||||||
|
|
||||||
class DebuggerImpl : public DebuggerBackend {
|
class DebuggerImpl : public DebuggerBackend {
|
||||||
public:
|
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);
|
InitializeServer(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +124,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SetActiveThread(Kernel::KThread* thread) override {
|
void SetActiveThread(Kernel::KThread* thread) override {
|
||||||
state->active_thread = thread;
|
state->active_thread = {system.Kernel(), thread};
|
||||||
}
|
}
|
||||||
|
|
||||||
Kernel::KThread* GetActiveThread() override {
|
Kernel::KThread* GetActiveThread() override {
|
||||||
@@ -168,14 +171,7 @@ private:
|
|||||||
frontend = std::make_unique<GDBStub>(*this, system, debug_process.GetPointerUnsafe());
|
frontend = std::make_unique<GDBStub>(*this, system, debug_process.GetPointerUnsafe());
|
||||||
|
|
||||||
// Set the new state. This will tear down any existing state.
|
// Set the new state. This will tear down any existing state.
|
||||||
state = ConnectionState{
|
state.emplace(std::move(peer), io_context, system.Kernel());
|
||||||
.client_socket{std::move(peer)},
|
|
||||||
.signal_pipe{io_context},
|
|
||||||
.info{},
|
|
||||||
.active_thread{},
|
|
||||||
.client_data{},
|
|
||||||
.pipe_data{},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Set up the client signals for new data.
|
// Set up the client signals for new data.
|
||||||
AsyncReceiveInto(state->signal_pipe, state->pipe_data, [&](auto d) { PipeData(d); });
|
AsyncReceiveInto(state->signal_pipe, state->pipe_data, [&](auto d) { PipeData(d); });
|
||||||
@@ -204,7 +200,7 @@ private:
|
|||||||
PauseEmulation();
|
PauseEmulation();
|
||||||
|
|
||||||
// Notify the client.
|
// Notify the client.
|
||||||
state->active_thread = state->info.thread;
|
state->active_thread = {system.Kernel(), state->info.thread};
|
||||||
UpdateActiveThread();
|
UpdateActiveThread();
|
||||||
|
|
||||||
if (state->info.type == SignalType::Watchpoint) {
|
if (state->info.type == SignalType::Watchpoint) {
|
||||||
@@ -258,7 +254,7 @@ private:
|
|||||||
auto* gdb = static_cast<GDBStub*>(frontend.get());
|
auto* gdb = static_cast<GDBStub*>(frontend.get());
|
||||||
MarkResumed([this, threads = std::move(gdb->resume_threads)] {
|
MarkResumed([this, threads = std::move(gdb->resume_threads)] {
|
||||||
state->active_thread->SetStepState(Kernel::StepState::StepPending);
|
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());
|
ResumeThreads(threads, state->active_thread.GetPointerUnsafe());
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -281,7 +277,7 @@ private:
|
|||||||
|
|
||||||
// Put all threads to sleep on next scheduler round.
|
// Put all threads to sleep on next scheduler round.
|
||||||
for (auto& thread : ThreadList()) {
|
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.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->SetStepState(Kernel::StepState::NotStepping);
|
||||||
thread->Resume(Kernel::SuspendType::Debug);
|
thread->Resume(system.Kernel(), Kernel::SuspendType::Debug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,7 +328,7 @@ private:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state->active_thread = std::addressof(threads.front());
|
state->active_thread = {system.Kernel(), std::addressof(threads.front())};
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -354,13 +350,20 @@ private:
|
|||||||
std::mutex connection_lock;
|
std::mutex connection_lock;
|
||||||
|
|
||||||
struct ConnectionState {
|
struct ConnectionState {
|
||||||
boost::asio::ip::tcp::socket client_socket;
|
|
||||||
#ifdef USE_BOOST_v1
|
#ifdef USE_BOOST_v1
|
||||||
boost::process::v1::async_pipe signal_pipe;
|
using async_pipe = boost::process::v1::async_pipe;
|
||||||
#else
|
#else
|
||||||
boost::process::async_pipe signal_pipe;
|
using async_pipe = boost::process::async_pipe;
|
||||||
#endif
|
#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;
|
SignalInfo info;
|
||||||
Kernel::KScopedAutoObject<Kernel::KThread> active_thread;
|
Kernel::KScopedAutoObject<Kernel::KThread> active_thread;
|
||||||
std::array<u8, 4096> client_data;
|
std::array<u8, 4096> client_data;
|
||||||
|
|||||||
@@ -323,13 +323,13 @@ void GDBStub::HandleBreakpointInsert(std::string_view command) {
|
|||||||
success = true;
|
success = true;
|
||||||
break;
|
break;
|
||||||
case BreakpointType::WriteWatch:
|
case BreakpointType::WriteWatch:
|
||||||
success = debug_process->InsertWatchpoint(addr, size, Kernel::DebugWatchpointType::Write);
|
success = debug_process->InsertWatchpoint(system.Kernel(), addr, size, Kernel::DebugWatchpointType::Write);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::ReadWatch:
|
case BreakpointType::ReadWatch:
|
||||||
success = debug_process->InsertWatchpoint(addr, size, Kernel::DebugWatchpointType::Read);
|
success = debug_process->InsertWatchpoint(system.Kernel(), addr, size, Kernel::DebugWatchpointType::Read);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::AccessWatch:
|
case BreakpointType::AccessWatch:
|
||||||
success = debug_process->InsertWatchpoint(addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
success = debug_process->InsertWatchpoint(system.Kernel(), addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::Hardware:
|
case BreakpointType::Hardware:
|
||||||
default:
|
default:
|
||||||
@@ -368,13 +368,13 @@ void GDBStub::HandleBreakpointRemove(std::string_view sv) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BreakpointType::WriteWatch:
|
case BreakpointType::WriteWatch:
|
||||||
success = debug_process->RemoveWatchpoint(addr, size, Kernel::DebugWatchpointType::Write);
|
success = debug_process->RemoveWatchpoint(system.Kernel(), addr, size, Kernel::DebugWatchpointType::Write);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::ReadWatch:
|
case BreakpointType::ReadWatch:
|
||||||
success = debug_process->RemoveWatchpoint(addr, size, Kernel::DebugWatchpointType::Read);
|
success = debug_process->RemoveWatchpoint(system.Kernel(), addr, size, Kernel::DebugWatchpointType::Read);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::AccessWatch:
|
case BreakpointType::AccessWatch:
|
||||||
success = debug_process->RemoveWatchpoint(addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
success = debug_process->RemoveWatchpoint(system.Kernel(), addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
|
||||||
break;
|
break;
|
||||||
case BreakpointType::Hardware:
|
case BreakpointType::Hardware:
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
@@ -17,7 +17,8 @@
|
|||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
GlobalSchedulerContext::GlobalSchedulerContext(KernelCore& kernel)
|
GlobalSchedulerContext::GlobalSchedulerContext(KernelCore& kernel)
|
||||||
: m_kernel{kernel}, m_scheduler_lock{kernel} {}
|
: m_scheduler_lock{kernel}
|
||||||
|
{}
|
||||||
|
|
||||||
GlobalSchedulerContext::~GlobalSchedulerContext() = default;
|
GlobalSchedulerContext::~GlobalSchedulerContext() = default;
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ void GlobalSchedulerContext::RemoveThread(KThread* thread) noexcept {
|
|||||||
/// and then does some core rebalancing. Preemption priorities can be found
|
/// and then does some core rebalancing. Preemption priorities can be found
|
||||||
/// in the array 'preemption_priorities'.
|
/// in the array 'preemption_priorities'.
|
||||||
/// @note This operation happens every 10ms.
|
/// @note This operation happens every 10ms.
|
||||||
void GlobalSchedulerContext::PreemptThreads() noexcept {
|
void GlobalSchedulerContext::PreemptThreads(KernelCore& kernel) noexcept {
|
||||||
// The priority levels at which the global scheduler preempts threads every 10 ms. They are
|
// The priority levels at which the global scheduler preempts threads every 10 ms. They are
|
||||||
// ordered from Core 0 to Core 3.
|
// ordered from Core 0 to Core 3.
|
||||||
static constexpr std::array<u32, Core::Hardware::NUM_CPU_CORES> per_core{
|
static constexpr std::array<u32, Core::Hardware::NUM_CPU_CORES> per_core{
|
||||||
@@ -46,9 +47,9 @@ void GlobalSchedulerContext::PreemptThreads() noexcept {
|
|||||||
59,
|
59,
|
||||||
63,
|
63,
|
||||||
};
|
};
|
||||||
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(m_kernel));
|
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
|
||||||
for (u32 core_id = 0; core_id < per_core.size(); core_id++)
|
for (u32 core_id = 0; core_id < per_core.size(); core_id++)
|
||||||
KScheduler::RotateScheduledQueue(m_kernel, core_id, per_core[core_id]);
|
KScheduler::RotateScheduledQueue(kernel, core_id, per_core[core_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Returns true if the global scheduler lock is acquired
|
/// @brief Returns true if the global scheduler lock is acquired
|
||||||
@@ -69,11 +70,11 @@ void GlobalSchedulerContext::UnregisterDummyThreadForWakeup(KThread* thread) noe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalSchedulerContext::WakeupWaitingDummyThreads() noexcept {
|
void GlobalSchedulerContext::WakeupWaitingDummyThreads(KernelCore& kernel) noexcept {
|
||||||
ASSERT(this->IsLocked());
|
ASSERT(this->IsLocked());
|
||||||
if (m_woken_dummy_threads.size() > 0) {
|
if (m_woken_dummy_threads.size() > 0) {
|
||||||
for (auto* thread : m_woken_dummy_threads)
|
for (auto* thread : m_woken_dummy_threads)
|
||||||
thread->DummyThreadEndWait();
|
thread->DummyThreadEndWait(kernel);
|
||||||
m_woken_dummy_threads.clear();
|
m_woken_dummy_threads.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
@@ -50,17 +50,16 @@ public:
|
|||||||
}
|
}
|
||||||
void AddThread(KThread* thread) noexcept;
|
void AddThread(KThread* thread) noexcept;
|
||||||
void RemoveThread(KThread* thread) noexcept;
|
void RemoveThread(KThread* thread) noexcept;
|
||||||
void PreemptThreads() noexcept;
|
void PreemptThreads(KernelCore& kernel) noexcept;
|
||||||
bool IsLocked() const noexcept;
|
bool IsLocked() const noexcept;
|
||||||
void UnregisterDummyThreadForWakeup(KThread* thread) noexcept;
|
void UnregisterDummyThreadForWakeup(KThread* thread) noexcept;
|
||||||
void RegisterDummyThreadForWakeup(KThread* thread) noexcept;
|
void RegisterDummyThreadForWakeup(KThread* thread) noexcept;
|
||||||
void WakeupWaitingDummyThreads() noexcept;
|
void WakeupWaitingDummyThreads(KernelCore& kernel) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class KScopedSchedulerLock;
|
friend class KScopedSchedulerLock;
|
||||||
friend class KScopedSchedulerLockAndSleep;
|
friend class KScopedSchedulerLockAndSleep;
|
||||||
|
|
||||||
KernelCore& m_kernel;
|
|
||||||
std::atomic_bool m_scheduler_update_needed{};
|
std::atomic_bool m_scheduler_update_needed{};
|
||||||
KSchedulerPriorityQueue m_priority_queue;
|
KSchedulerPriorityQueue m_priority_queue;
|
||||||
LockType m_scheduler_lock;
|
LockType m_scheduler_lock;
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// 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.
|
// Reserve memory from the system resource limit.
|
||||||
ASSERT(
|
ASSERT(
|
||||||
kernel.GetSystemResourceLimit()->Reserve(LimitableResource::PhysicalMemoryMax, slab_size));
|
kernel.GetSystemResourceLimit()->Reserve(kernel, LimitableResource::PhysicalMemoryMax, slab_size));
|
||||||
|
|
||||||
// Allocate memory for the slab.
|
// Allocate memory for the slab.
|
||||||
constexpr auto AllocateOption = KMemoryManager::EncodeOption(
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -16,8 +19,9 @@
|
|||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
KAddressArbiter::KAddressArbiter(Core::System& system)
|
KAddressArbiter::KAddressArbiter(Core::System& system_)
|
||||||
: m_system{system}, m_kernel{system.Kernel()} {}
|
: system{system_}
|
||||||
|
{}
|
||||||
KAddressArbiter::~KAddressArbiter() = default;
|
KAddressArbiter::~KAddressArbiter() = default;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -112,7 +116,7 @@ public:
|
|||||||
explicit ThreadQueueImplForKAddressArbiter(KernelCore& kernel, KAddressArbiter::ThreadTree* t)
|
explicit ThreadQueueImplForKAddressArbiter(KernelCore& kernel, KAddressArbiter::ThreadTree* t)
|
||||||
: KThreadQueue(kernel), m_tree(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 the thread is waiting on an address arbiter, remove it from the tree.
|
||||||
if (waiting_thread->IsWaitingForAddressArbiter()) {
|
if (waiting_thread->IsWaitingForAddressArbiter()) {
|
||||||
m_tree->erase(m_tree->iterator_to(*waiting_thread));
|
m_tree->erase(m_tree->iterator_to(*waiting_thread));
|
||||||
@@ -120,7 +124,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Invoke the base cancel wait handler.
|
// 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:
|
private:
|
||||||
@@ -133,14 +137,14 @@ Result KAddressArbiter::Signal(uint64_t addr, s32 count) {
|
|||||||
// Perform signaling.
|
// Perform signaling.
|
||||||
s32 num_waiters{};
|
s32 num_waiters{};
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl(m_kernel);
|
KScopedSchedulerLock sl(system.Kernel());
|
||||||
|
|
||||||
auto it = m_tree.nfind_key({addr, -1});
|
auto it = m_tree.nfind_key({addr, -1});
|
||||||
while ((it != m_tree.end()) && (count <= 0 || num_waiters < count) &&
|
while ((it != m_tree.end()) && (count <= 0 || num_waiters < count) &&
|
||||||
(it->GetAddressArbiterKey() == addr)) {
|
(it->GetAddressArbiterKey() == addr)) {
|
||||||
// End the thread's wait.
|
// End the thread's wait.
|
||||||
KThread* target_thread = std::addressof(*it);
|
KThread* target_thread = std::addressof(*it);
|
||||||
target_thread->EndWait(ResultSuccess);
|
target_thread->EndWait(system.Kernel(), ResultSuccess);
|
||||||
|
|
||||||
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
||||||
target_thread->ClearAddressArbiter();
|
target_thread->ClearAddressArbiter();
|
||||||
@@ -156,11 +160,11 @@ Result KAddressArbiter::SignalAndIncrementIfEqual(uint64_t addr, s32 value, s32
|
|||||||
// Perform signaling.
|
// Perform signaling.
|
||||||
s32 num_waiters{};
|
s32 num_waiters{};
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl(m_kernel);
|
KScopedSchedulerLock sl(system.Kernel());
|
||||||
|
|
||||||
// Check the userspace value.
|
// Check the userspace value.
|
||||||
s32 user_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);
|
ResultInvalidCurrentMemory);
|
||||||
R_UNLESS(user_value == value, ResultInvalidState);
|
R_UNLESS(user_value == value, ResultInvalidState);
|
||||||
|
|
||||||
@@ -169,7 +173,7 @@ Result KAddressArbiter::SignalAndIncrementIfEqual(uint64_t addr, s32 value, s32
|
|||||||
(it->GetAddressArbiterKey() == addr)) {
|
(it->GetAddressArbiterKey() == addr)) {
|
||||||
// End the thread's wait.
|
// End the thread's wait.
|
||||||
KThread* target_thread = std::addressof(*it);
|
KThread* target_thread = std::addressof(*it);
|
||||||
target_thread->EndWait(ResultSuccess);
|
target_thread->EndWait(system.Kernel(), ResultSuccess);
|
||||||
|
|
||||||
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
||||||
target_thread->ClearAddressArbiter();
|
target_thread->ClearAddressArbiter();
|
||||||
@@ -185,7 +189,7 @@ Result KAddressArbiter::SignalAndModifyByWaitingCountIfEqual(uint64_t addr, s32
|
|||||||
// Perform signaling.
|
// Perform signaling.
|
||||||
s32 num_waiters{};
|
s32 num_waiters{};
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl(m_kernel);
|
KScopedSchedulerLock sl(system.Kernel());
|
||||||
|
|
||||||
auto it = m_tree.nfind_key({addr, -1});
|
auto it = m_tree.nfind_key({addr, -1});
|
||||||
// Determine the updated value.
|
// Determine the updated value.
|
||||||
@@ -220,9 +224,9 @@ Result KAddressArbiter::SignalAndModifyByWaitingCountIfEqual(uint64_t addr, s32
|
|||||||
s32 user_value{};
|
s32 user_value{};
|
||||||
bool succeeded{};
|
bool succeeded{};
|
||||||
if (value != new_value) {
|
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 {
|
} else {
|
||||||
succeeded = ReadFromUser(m_kernel, std::addressof(user_value), addr);
|
succeeded = ReadFromUser(system.Kernel(), std::addressof(user_value), addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
R_UNLESS(succeeded, ResultInvalidCurrentMemory);
|
R_UNLESS(succeeded, ResultInvalidCurrentMemory);
|
||||||
@@ -232,7 +236,7 @@ Result KAddressArbiter::SignalAndModifyByWaitingCountIfEqual(uint64_t addr, s32
|
|||||||
(it->GetAddressArbiterKey() == addr)) {
|
(it->GetAddressArbiterKey() == addr)) {
|
||||||
// End the thread's wait.
|
// End the thread's wait.
|
||||||
KThread* target_thread = std::addressof(*it);
|
KThread* target_thread = std::addressof(*it);
|
||||||
target_thread->EndWait(ResultSuccess);
|
target_thread->EndWait(system.Kernel(), ResultSuccess);
|
||||||
|
|
||||||
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
ASSERT(target_thread->IsWaitingForAddressArbiter());
|
||||||
target_thread->ClearAddressArbiter();
|
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) {
|
Result KAddressArbiter::WaitIfLessThan(uint64_t addr, s32 value, bool decrement, s64 timeout) {
|
||||||
// Prepare to wait.
|
// Prepare to wait.
|
||||||
KThread* cur_thread = GetCurrentThreadPointer(m_kernel);
|
KThread* cur_thread = GetCurrentThreadPointer(system.Kernel());
|
||||||
KHardwareTimer* timer{};
|
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.
|
// Check that the thread isn't terminating.
|
||||||
if (cur_thread->IsTerminationRequested()) {
|
if (cur_thread->IsTerminationRequested()) {
|
||||||
@@ -263,9 +267,9 @@ Result KAddressArbiter::WaitIfLessThan(uint64_t addr, s32 value, bool decrement,
|
|||||||
s32 user_value{};
|
s32 user_value{};
|
||||||
bool succeeded{};
|
bool succeeded{};
|
||||||
if (decrement) {
|
if (decrement) {
|
||||||
succeeded = DecrementIfLessThan(m_kernel, std::addressof(user_value), addr, value);
|
succeeded = DecrementIfLessThan(system.Kernel(), std::addressof(user_value), addr, value);
|
||||||
} else {
|
} else {
|
||||||
succeeded = ReadFromUser(m_kernel, std::addressof(user_value), addr);
|
succeeded = ReadFromUser(system.Kernel(), std::addressof(user_value), addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!succeeded) {
|
if (!succeeded) {
|
||||||
@@ -291,7 +295,7 @@ Result KAddressArbiter::WaitIfLessThan(uint64_t addr, s32 value, bool decrement,
|
|||||||
|
|
||||||
// Wait for the thread to finish.
|
// Wait for the thread to finish.
|
||||||
wait_queue.SetHardwareTimer(timer);
|
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);
|
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) {
|
Result KAddressArbiter::WaitIfEqual(uint64_t addr, s32 value, s64 timeout) {
|
||||||
// Prepare to wait.
|
// Prepare to wait.
|
||||||
KThread* cur_thread = GetCurrentThreadPointer(m_kernel);
|
KThread* cur_thread = GetCurrentThreadPointer(system.Kernel());
|
||||||
KHardwareTimer* timer{};
|
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.
|
// Check that the thread isn't terminating.
|
||||||
if (cur_thread->IsTerminationRequested()) {
|
if (cur_thread->IsTerminationRequested()) {
|
||||||
@@ -316,7 +320,7 @@ Result KAddressArbiter::WaitIfEqual(uint64_t addr, s32 value, s64 timeout) {
|
|||||||
|
|
||||||
// Read the value from userspace.
|
// Read the value from userspace.
|
||||||
s32 user_value{};
|
s32 user_value{};
|
||||||
if (!ReadFromUser(m_kernel, std::addressof(user_value), addr)) {
|
if (!ReadFromUser(system.Kernel(), std::addressof(user_value), addr)) {
|
||||||
slp.CancelSleep();
|
slp.CancelSleep();
|
||||||
R_THROW(ResultInvalidCurrentMemory);
|
R_THROW(ResultInvalidCurrentMemory);
|
||||||
}
|
}
|
||||||
@@ -339,7 +343,7 @@ Result KAddressArbiter::WaitIfEqual(uint64_t addr, s32 value, s64 timeout) {
|
|||||||
|
|
||||||
// Wait for the thread to finish.
|
// Wait for the thread to finish.
|
||||||
wait_queue.SetHardwareTimer(timer);
|
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);
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -60,8 +63,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ThreadTree m_tree;
|
ThreadTree m_tree;
|
||||||
Core::System& m_system;
|
Core::System& system;
|
||||||
KernelCore& m_kernel;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Kernel
|
} // 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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
@@ -15,8 +15,8 @@ KAutoObject* KAutoObject::Create(KAutoObject* obj) {
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KAutoObject::RegisterWithKernel() {
|
void KAutoObject::RegisterWithKernel(KernelCore& kernel) {
|
||||||
m_kernel.RegisterKernelObject(this);
|
kernel.RegisterKernelObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KAutoObject::UnregisterWithKernel(KernelCore& kernel, KAutoObject* self) {
|
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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
@@ -87,21 +87,21 @@ private:
|
|||||||
KERNEL_AUTOOBJECT_TRAITS_IMPL(KAutoObject, KAutoObject, const);
|
KERNEL_AUTOOBJECT_TRAITS_IMPL(KAutoObject, KAutoObject, const);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit KAutoObject(KernelCore& kernel) : m_kernel(kernel) {
|
explicit KAutoObject(KernelCore& kernel) {
|
||||||
m_class_token = GetStaticTypeObj().GetClassToken();
|
m_class_token = GetStaticTypeObj().GetClassToken();
|
||||||
RegisterWithKernel();
|
RegisterWithKernel(kernel);
|
||||||
}
|
}
|
||||||
virtual ~KAutoObject() = default;
|
virtual ~KAutoObject() = default;
|
||||||
|
|
||||||
static KAutoObject* Create(KAutoObject* ptr);
|
static KAutoObject* Create(KAutoObject* ptr);
|
||||||
|
|
||||||
// Destroy is responsible for destroying the auto object's resources when ref_count hits zero.
|
// Destroy is responsible for destroying the auto object's resources when ref_count hits zero.
|
||||||
virtual void Destroy() {
|
virtual void Destroy(KernelCore& kernel) {
|
||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finalize is responsible for cleaning up resource, but does not destroy the object.
|
// 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 {
|
virtual KProcess* GetOwner() const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -123,67 +123,50 @@ public:
|
|||||||
Derived DynamicCast() {
|
Derived DynamicCast() {
|
||||||
static_assert(std::is_pointer_v<Derived>);
|
static_assert(std::is_pointer_v<Derived>);
|
||||||
using DerivedType = std::remove_pointer_t<Derived>;
|
using DerivedType = std::remove_pointer_t<Derived>;
|
||||||
|
if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj()))
|
||||||
if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj())) {
|
return Derived(this);
|
||||||
return static_cast<Derived>(this);
|
return nullptr;
|
||||||
} else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Derived>
|
template <typename Derived>
|
||||||
const Derived DynamicCast() const {
|
const Derived DynamicCast() const {
|
||||||
static_assert(std::is_pointer_v<Derived>);
|
static_assert(std::is_pointer_v<Derived>);
|
||||||
using DerivedType = std::remove_pointer_t<Derived>;
|
using DerivedType = std::remove_pointer_t<Derived>;
|
||||||
|
if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj()))
|
||||||
if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj())) {
|
return Derived(this);
|
||||||
return static_cast<Derived>(this);
|
return nullptr;
|
||||||
} else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Open() {
|
bool Open(KernelCore& kernel) {
|
||||||
// Atomically increment the reference count, only if it's positive.
|
// Atomically increment the reference count, only if it's positive.
|
||||||
u32 cur_ref_count = m_ref_count.load(std::memory_order_acquire);
|
u32 cur_ref_count = m_ref_count.load(std::memory_order_acquire);
|
||||||
do {
|
do {
|
||||||
if (cur_ref_count == 0) {
|
if (cur_ref_count == 0)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
ASSERT(cur_ref_count < cur_ref_count + 1);
|
ASSERT(cur_ref_count < cur_ref_count + 1);
|
||||||
} while (!m_ref_count.compare_exchange_weak(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));
|
||||||
std::memory_order_relaxed));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Close() {
|
void Close(KernelCore& kernel) {
|
||||||
// Atomically decrement the reference count, not allowing it to become negative.
|
// Atomically decrement the reference count, not allowing it to become negative.
|
||||||
u32 cur_ref_count = m_ref_count.load(std::memory_order_acquire);
|
u32 cur_ref_count = m_ref_count.load(std::memory_order_acquire);
|
||||||
do {
|
do {
|
||||||
if (cur_ref_count == 0) {
|
if (cur_ref_count == 0)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
ASSERT(cur_ref_count > 0);
|
ASSERT(cur_ref_count > 0);
|
||||||
} while (!m_ref_count.compare_exchange_weak(cur_ref_count, cur_ref_count - 1,
|
} while (!m_ref_count.compare_exchange_weak(cur_ref_count, cur_ref_count - 1, std::memory_order_acq_rel));
|
||||||
std::memory_order_acq_rel));
|
|
||||||
|
|
||||||
// If ref count hits 1, destroy the object.
|
// If ref count hits 1, destroy the object.
|
||||||
if (cur_ref_count == 1) {
|
if (cur_ref_count == 1) {
|
||||||
KernelCore& kernel = m_kernel;
|
this->Destroy(kernel);
|
||||||
this->Destroy();
|
|
||||||
KAutoObject::UnregisterWithKernel(kernel, this);
|
KAutoObject::UnregisterWithKernel(kernel, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RegisterWithKernel();
|
void RegisterWithKernel(KernelCore& kernel);
|
||||||
static void UnregisterWithKernel(KernelCore& kernel, KAutoObject* self);
|
static void UnregisterWithKernel(KernelCore& kernel, KAutoObject* self);
|
||||||
|
|
||||||
protected:
|
|
||||||
KernelCore& m_kernel;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::atomic<u32> m_ref_count{};
|
std::atomic<u32> m_ref_count{};
|
||||||
ClassTokenType m_class_token{};
|
ClassTokenType m_class_token{};
|
||||||
};
|
};
|
||||||
@@ -225,17 +208,22 @@ class KScopedAutoObject {
|
|||||||
public:
|
public:
|
||||||
YUZU_NON_COPYABLE(KScopedAutoObject);
|
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) {
|
if (m_obj != nullptr) {
|
||||||
m_obj->Open();
|
m_obj->Open(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~KScopedAutoObject() {
|
~KScopedAutoObject() {
|
||||||
if (m_obj != nullptr) {
|
if (m_obj != nullptr) {
|
||||||
m_obj->Close();
|
m_obj->Close(kernel);
|
||||||
}
|
}
|
||||||
m_obj = nullptr;
|
m_obj = nullptr;
|
||||||
}
|
}
|
||||||
@@ -253,7 +241,7 @@ public:
|
|||||||
if (rhs.m_obj != nullptr) {
|
if (rhs.m_obj != nullptr) {
|
||||||
derived = rhs.m_obj->template DynamicCast<T*>();
|
derived = rhs.m_obj->template DynamicCast<T*>();
|
||||||
if (derived == nullptr) {
|
if (derived == nullptr) {
|
||||||
rhs.m_obj->Close();
|
rhs.m_obj->Close(rhs.kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,8 +262,16 @@ public:
|
|||||||
return *m_obj;
|
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) {
|
constexpr void Reset(T* o) {
|
||||||
KScopedAutoObject(o).Swap(*this);
|
KScopedAutoObject(kernel, o).Swap(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr T* GetPointerUnsafe() {
|
constexpr T* GetPointerUnsafe() {
|
||||||
@@ -304,6 +300,7 @@ private:
|
|||||||
friend class KScopedAutoObject;
|
friend class KScopedAutoObject;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
KernelCore& kernel;
|
||||||
T* m_obj{};
|
T* m_obj{};
|
||||||
|
|
||||||
private:
|
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-FileCopyrightText: 2021 Citra Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -15,7 +18,7 @@ namespace Kernel {
|
|||||||
KClientPort::KClientPort(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
KClientPort::KClientPort(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
||||||
KClientPort::~KClientPort() = default;
|
KClientPort::~KClientPort() = default;
|
||||||
|
|
||||||
void KClientPort::Initialize(KPort* parent, s32 max_sessions) {
|
void KClientPort::Initialize(KernelCore& kernel, KPort* parent, s32 max_sessions) {
|
||||||
// Set member variables.
|
// Set member variables.
|
||||||
m_num_sessions = 0;
|
m_num_sessions = 0;
|
||||||
m_peak_sessions = 0;
|
m_peak_sessions = 0;
|
||||||
@@ -23,48 +26,48 @@ void KClientPort::Initialize(KPort* parent, s32 max_sessions) {
|
|||||||
m_max_sessions = max_sessions;
|
m_max_sessions = max_sessions;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KClientPort::OnSessionFinalized() {
|
void KClientPort::OnSessionFinalized(KernelCore& kernel) {
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
if (const auto prev = m_num_sessions--; prev == m_max_sessions) {
|
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();
|
return this->GetParent()->IsLight();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KClientPort::IsServerClosed() const {
|
bool KClientPort::IsServerClosed(KernelCore& kernel) const {
|
||||||
return this->GetParent()->IsServerClosed();
|
return this->GetParent()->IsServerClosed(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KClientPort::Destroy() {
|
void KClientPort::Destroy(KernelCore& kernel) {
|
||||||
// Note with our parent that we're closed.
|
// Note with our parent that we're closed.
|
||||||
m_parent->OnClientClosed();
|
m_parent->OnClientClosed(kernel);
|
||||||
|
|
||||||
// Close our reference to our parent.
|
// 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;
|
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.
|
// Declare the session we're going to allocate.
|
||||||
KSession* session{};
|
KSession* session{};
|
||||||
|
|
||||||
// Reserve a new session from the resource limit.
|
// Reserve a new session from the resource limit.
|
||||||
KScopedResourceReservation session_reservation(GetCurrentProcessPointer(m_kernel),
|
KScopedResourceReservation session_reservation(kernel, GetCurrentProcessPointer(kernel),
|
||||||
LimitableResource::SessionCountMax);
|
LimitableResource::SessionCountMax);
|
||||||
R_UNLESS(session_reservation.Succeeded(), ResultLimitReached);
|
R_UNLESS(session_reservation.Succeeded(), ResultLimitReached);
|
||||||
|
|
||||||
// Allocate a session normally.
|
// Allocate a session normally.
|
||||||
// TODO: Dynamic resource limits
|
// TODO: Dynamic resource limits
|
||||||
session = KSession::Create(m_kernel);
|
session = KSession::Create(kernel);
|
||||||
|
|
||||||
// Check that we successfully created a session.
|
// Check that we successfully created a session.
|
||||||
R_UNLESS(session != nullptr, ResultOutOfResource);
|
R_UNLESS(session != nullptr, ResultOutOfResource);
|
||||||
@@ -72,7 +75,7 @@ Result KClientPort::CreateSession(KClientSession** out) {
|
|||||||
// Update the session counts.
|
// Update the session counts.
|
||||||
{
|
{
|
||||||
ON_RESULT_FAILURE {
|
ON_RESULT_FAILURE {
|
||||||
session->Close();
|
session->Close(kernel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Atomically increment the number of sessions.
|
// Atomically increment the number of sessions.
|
||||||
@@ -100,38 +103,37 @@ Result KClientPort::CreateSession(KClientSession** out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the session.
|
// Initialize the session.
|
||||||
session->Initialize(this, m_parent->GetName());
|
session->Initialize(kernel, this, m_parent->GetName());
|
||||||
|
|
||||||
// Commit the session reservation.
|
// Commit the session reservation.
|
||||||
session_reservation.Commit();
|
session_reservation.Commit();
|
||||||
|
|
||||||
// Register the session.
|
// Register the session.
|
||||||
KSession::Register(m_kernel, session);
|
KSession::Register(kernel, session);
|
||||||
ON_RESULT_FAILURE {
|
ON_RESULT_FAILURE {
|
||||||
session->GetClientSession().Close();
|
session->GetClientSession().Close(kernel);
|
||||||
session->GetServerSession().Close();
|
session->GetServerSession().Close(kernel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Enqueue the session with our parent.
|
// 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.
|
// We succeeded, so set the output.
|
||||||
*out = std::addressof(session->GetClientSession());
|
*out = std::addressof(session->GetClientSession());
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KClientPort::CreateLightSession(KLightClientSession** out) {
|
Result KClientPort::CreateLightSession(KernelCore& kernel, KLightClientSession** out) {
|
||||||
// Declare the session we're going to allocate.
|
// Declare the session we're going to allocate.
|
||||||
KLightSession* session{};
|
KLightSession* session{};
|
||||||
|
|
||||||
// Reserve a new session from the resource limit.
|
// Reserve a new session from the resource limit.
|
||||||
KScopedResourceReservation session_reservation(GetCurrentProcessPointer(m_kernel),
|
KScopedResourceReservation session_reservation(kernel, GetCurrentProcessPointer(kernel), Svc::LimitableResource::SessionCountMax);
|
||||||
Svc::LimitableResource::SessionCountMax);
|
|
||||||
R_UNLESS(session_reservation.Succeeded(), ResultLimitReached);
|
R_UNLESS(session_reservation.Succeeded(), ResultLimitReached);
|
||||||
|
|
||||||
// Allocate a session normally.
|
// Allocate a session normally.
|
||||||
// TODO: Dynamic resource limits
|
// TODO: Dynamic resource limits
|
||||||
session = KLightSession::Create(m_kernel);
|
session = KLightSession::Create(kernel);
|
||||||
|
|
||||||
// Check that we successfully created a session.
|
// Check that we successfully created a session.
|
||||||
R_UNLESS(session != nullptr, ResultOutOfResource);
|
R_UNLESS(session != nullptr, ResultOutOfResource);
|
||||||
@@ -139,7 +141,7 @@ Result KClientPort::CreateLightSession(KLightClientSession** out) {
|
|||||||
// Update the session counts.
|
// Update the session counts.
|
||||||
{
|
{
|
||||||
ON_RESULT_FAILURE {
|
ON_RESULT_FAILURE {
|
||||||
session->Close();
|
session->Close(kernel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Atomically increment the number of sessions.
|
// Atomically increment the number of sessions.
|
||||||
@@ -167,20 +169,20 @@ Result KClientPort::CreateLightSession(KLightClientSession** out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the session.
|
// Initialize the session.
|
||||||
session->Initialize(this, m_parent->GetName());
|
session->Initialize(kernel, this, m_parent->GetName());
|
||||||
|
|
||||||
// Commit the session reservation.
|
// Commit the session reservation.
|
||||||
session_reservation.Commit();
|
session_reservation.Commit();
|
||||||
|
|
||||||
// Register the session.
|
// Register the session.
|
||||||
KLightSession::Register(m_kernel, session);
|
KLightSession::Register(kernel, session);
|
||||||
ON_RESULT_FAILURE {
|
ON_RESULT_FAILURE {
|
||||||
session->GetClientSession().Close();
|
session->GetClientSession().Close(kernel);
|
||||||
session->GetServerSession().Close();
|
session->GetServerSession().Close(kernel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Enqueue the session with our parent.
|
// 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.
|
// We succeeded, so set the output.
|
||||||
*out = std::addressof(session->GetClientSession());
|
*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-FileCopyrightText: 2016 Citra Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -23,9 +26,9 @@ public:
|
|||||||
explicit KClientPort(KernelCore& kernel);
|
explicit KClientPort(KernelCore& kernel);
|
||||||
~KClientPort() override;
|
~KClientPort() override;
|
||||||
|
|
||||||
void Initialize(KPort* parent, s32 max_sessions);
|
void Initialize(KernelCore& kernel, KPort* parent, s32 max_sessions);
|
||||||
void OnSessionFinalized();
|
void OnSessionFinalized(KernelCore& kernel);
|
||||||
void OnServerClosed();
|
void OnServerClosed(KernelCore& kernel);
|
||||||
|
|
||||||
const KPort* GetParent() const {
|
const KPort* GetParent() const {
|
||||||
return m_parent;
|
return m_parent;
|
||||||
@@ -44,15 +47,15 @@ public:
|
|||||||
return m_max_sessions;
|
return m_max_sessions;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsLight() const;
|
bool IsLight(KernelCore& kernel) const;
|
||||||
bool IsServerClosed() const;
|
bool IsServerClosed(KernelCore& kernel) const;
|
||||||
|
|
||||||
// Overridden virtual functions.
|
// Overridden virtual functions.
|
||||||
void Destroy() override;
|
void Destroy(KernelCore& kernel) override;
|
||||||
bool IsSignaled() const override;
|
bool IsSignaled(KernelCore& kernel) const override;
|
||||||
|
|
||||||
Result CreateSession(KClientSession** out);
|
Result CreateSession(KernelCore& kernel, KClientSession** out);
|
||||||
Result CreateLightSession(KLightClientSession** out);
|
Result CreateLightSession(KernelCore& kernel, KLightClientSession** out);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::atomic<s32> m_num_sessions{};
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -13,41 +16,41 @@ namespace Kernel {
|
|||||||
KClientSession::KClientSession(KernelCore& kernel) : KAutoObject{kernel} {}
|
KClientSession::KClientSession(KernelCore& kernel) : KAutoObject{kernel} {}
|
||||||
KClientSession::~KClientSession() = default;
|
KClientSession::~KClientSession() = default;
|
||||||
|
|
||||||
void KClientSession::Destroy() {
|
void KClientSession::Destroy(KernelCore& kernel) {
|
||||||
m_parent->OnClientClosed();
|
m_parent->OnClientClosed(kernel);
|
||||||
m_parent->Close();
|
m_parent->Close(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KClientSession::OnServerClosed() {}
|
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.
|
// Create a session request.
|
||||||
KSessionRequest* request = KSessionRequest::Create(m_kernel);
|
KSessionRequest* request = KSessionRequest::Create(kernel);
|
||||||
R_UNLESS(request != nullptr, ResultOutOfResource);
|
R_UNLESS(request != nullptr, ResultOutOfResource);
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
request->Close();
|
request->Close(kernel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize the request.
|
// Initialize the request.
|
||||||
request->Initialize(nullptr, address, size);
|
request->Initialize(kernel, nullptr, address, size);
|
||||||
|
|
||||||
// Send the request.
|
// 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.
|
// Create a session request.
|
||||||
KSessionRequest* request = KSessionRequest::Create(m_kernel);
|
KSessionRequest* request = KSessionRequest::Create(kernel);
|
||||||
R_UNLESS(request != nullptr, ResultOutOfResource);
|
R_UNLESS(request != nullptr, ResultOutOfResource);
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
request->Close();
|
request->Close(kernel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize the request.
|
// Initialize the request.
|
||||||
request->Initialize(event, address, size);
|
request->Initialize(kernel, event, address, size);
|
||||||
|
|
||||||
// Send the request.
|
// Send the request.
|
||||||
R_RETURN(m_parent->OnRequest(request));
|
R_RETURN(m_parent->OnRequest(kernel, request));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace 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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -26,14 +29,14 @@ public:
|
|||||||
m_parent = parent;
|
m_parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Destroy() override;
|
void Destroy(KernelCore& kernel) override;
|
||||||
|
|
||||||
KSession* GetParent() const {
|
KSession* GetParent() const {
|
||||||
return m_parent;
|
return m_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SendSyncRequest(uintptr_t address, size_t size);
|
Result SendSyncRequest(KernelCore& kernel, uintptr_t address, size_t size);
|
||||||
Result SendAsyncRequest(KEvent* event, uintptr_t address, size_t size);
|
Result SendAsyncRequest(KernelCore& kernel, KEvent* event, uintptr_t address, size_t size);
|
||||||
|
|
||||||
void OnServerClosed();
|
void OnServerClosed();
|
||||||
|
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -19,16 +22,15 @@ namespace Kernel {
|
|||||||
KCodeMemory::KCodeMemory(KernelCore& kernel)
|
KCodeMemory::KCodeMemory(KernelCore& kernel)
|
||||||
: KAutoObjectWithSlabHeapAndContainer{kernel}, m_lock(kernel) {}
|
: KAutoObjectWithSlabHeapAndContainer{kernel}, m_lock(kernel) {}
|
||||||
|
|
||||||
Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, KProcessAddress addr,
|
Result KCodeMemory::Initialize(KernelCore& kernel, Core::DeviceMemory& device_memory, KProcessAddress addr, size_t size) {
|
||||||
size_t size) {
|
|
||||||
// Set members.
|
// Set members.
|
||||||
m_owner = GetCurrentProcessPointer(m_kernel);
|
m_owner = GetCurrentProcessPointer(kernel);
|
||||||
|
|
||||||
// Get the owner page table.
|
// Get the owner page table.
|
||||||
auto& page_table = m_owner->GetPageTable();
|
auto& page_table = m_owner->GetPageTable();
|
||||||
|
|
||||||
// Construct the page group.
|
// Construct the page group.
|
||||||
m_page_group.emplace(m_kernel, page_table.GetBlockInfoManager());
|
m_page_group.emplace(kernel, page_table.GetBlockInfoManager());
|
||||||
|
|
||||||
// Lock the memory.
|
// Lock the memory.
|
||||||
R_TRY(page_table.LockForCodeMemory(std::addressof(*m_page_group), addr, size))
|
R_TRY(page_table.LockForCodeMemory(std::addressof(*m_page_group), addr, size))
|
||||||
@@ -39,7 +41,7 @@ Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, KProcessAddres
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set remaining tracking members.
|
// Set remaining tracking members.
|
||||||
m_owner->Open();
|
m_owner->Open(kernel);
|
||||||
m_address = addr;
|
m_address = addr;
|
||||||
m_is_initialized = true;
|
m_is_initialized = true;
|
||||||
m_is_owner_mapped = false;
|
m_is_owner_mapped = false;
|
||||||
@@ -49,7 +51,7 @@ Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, KProcessAddres
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KCodeMemory::Finalize() {
|
void KCodeMemory::Finalize(KernelCore& kernel) {
|
||||||
// Unlock.
|
// Unlock.
|
||||||
if (!m_is_mapped && !m_is_owner_mapped) {
|
if (!m_is_mapped && !m_is_owner_mapped) {
|
||||||
const size_t size = m_page_group->GetNumPages() * PageSize;
|
const size_t size = m_page_group->GetNumPages() * PageSize;
|
||||||
@@ -57,14 +59,14 @@ void KCodeMemory::Finalize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close the page group.
|
// Close the page group.
|
||||||
m_page_group->Close();
|
m_page_group->Close(kernel);
|
||||||
m_page_group->Finalize();
|
m_page_group->Finalize();
|
||||||
|
|
||||||
// Close our reference to our owner.
|
// 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.
|
// Validate the size.
|
||||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||||
|
|
||||||
@@ -75,7 +77,7 @@ Result KCodeMemory::Map(KProcessAddress address, size_t size) {
|
|||||||
R_UNLESS(!m_is_mapped, ResultInvalidState);
|
R_UNLESS(!m_is_mapped, ResultInvalidState);
|
||||||
|
|
||||||
// Map the memory.
|
// Map the memory.
|
||||||
R_TRY(GetCurrentProcess(m_kernel).GetPageTable().MapPageGroup(
|
R_TRY(GetCurrentProcess(kernel).GetPageTable().MapPageGroup(
|
||||||
address, *m_page_group, KMemoryState::CodeOut, KMemoryPermission::UserReadWrite));
|
address, *m_page_group, KMemoryState::CodeOut, KMemoryPermission::UserReadWrite));
|
||||||
|
|
||||||
// Mark ourselves as mapped.
|
// Mark ourselves as mapped.
|
||||||
@@ -84,7 +86,7 @@ Result KCodeMemory::Map(KProcessAddress address, size_t size) {
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KCodeMemory::Unmap(KProcessAddress address, size_t size) {
|
Result KCodeMemory::Unmap(KernelCore& kernel, KProcessAddress address, size_t size) {
|
||||||
// Validate the size.
|
// Validate the size.
|
||||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||||
|
|
||||||
@@ -92,7 +94,7 @@ Result KCodeMemory::Unmap(KProcessAddress address, size_t size) {
|
|||||||
KScopedLightLock lk(m_lock);
|
KScopedLightLock lk(m_lock);
|
||||||
|
|
||||||
// Unmap the memory.
|
// 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));
|
KMemoryState::CodeOut));
|
||||||
|
|
||||||
// Mark ourselves as unmapped.
|
// Mark ourselves as unmapped.
|
||||||
@@ -101,7 +103,7 @@ Result KCodeMemory::Unmap(KProcessAddress address, size_t size) {
|
|||||||
R_SUCCEED();
|
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.
|
// Validate the size.
|
||||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||||
|
|
||||||
@@ -135,7 +137,7 @@ Result KCodeMemory::MapToOwner(KProcessAddress address, size_t size, Svc::Memory
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KCodeMemory::UnmapFromOwner(KProcessAddress address, size_t size) {
|
Result KCodeMemory::UnmapFromOwner(KernelCore& kernel, KProcessAddress address, size_t size) {
|
||||||
// Validate the size.
|
// Validate the size.
|
||||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -31,18 +34,18 @@ class KCodeMemory final
|
|||||||
public:
|
public:
|
||||||
explicit KCodeMemory(KernelCore& kernel);
|
explicit KCodeMemory(KernelCore& kernel);
|
||||||
|
|
||||||
Result Initialize(Core::DeviceMemory& device_memory, KProcessAddress address, size_t size);
|
Result Initialize(KernelCore& kernel, Core::DeviceMemory& device_memory, KProcessAddress address, size_t size);
|
||||||
void Finalize() override;
|
void Finalize(KernelCore& kernel) override;
|
||||||
|
|
||||||
Result Map(KProcessAddress address, size_t size);
|
Result Map(KernelCore& kernel, KProcessAddress address, size_t size);
|
||||||
Result Unmap(KProcessAddress address, size_t size);
|
Result Unmap(KernelCore& kernel, KProcessAddress address, size_t size);
|
||||||
Result MapToOwner(KProcessAddress address, size_t size, Svc::MemoryPermission perm);
|
Result MapToOwner(KernelCore& kernel, KProcessAddress address, size_t size, Svc::MemoryPermission perm);
|
||||||
Result UnmapFromOwner(KProcessAddress address, size_t size);
|
Result UnmapFromOwner(KernelCore& kernel, KProcessAddress address, size_t size);
|
||||||
|
|
||||||
bool IsInitialized() const override {
|
bool IsInitialized() const override {
|
||||||
return m_is_initialized;
|
return m_is_initialized;
|
||||||
}
|
}
|
||||||
static void PostDestroy(uintptr_t arg) {}
|
static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}
|
||||||
|
|
||||||
KProcess* GetOwner() const override {
|
KProcess* GetOwner() const override {
|
||||||
return m_owner;
|
return m_owner;
|
||||||
|
|||||||
@@ -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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
@@ -66,14 +66,15 @@ bool UpdateLockAtomic(KernelCore& kernel, u32* out, KProcessAddress address, u32
|
|||||||
class ThreadQueueImplForKConditionVariableWaitForAddress final : public KThreadQueue {
|
class ThreadQueueImplForKConditionVariableWaitForAddress final : public KThreadQueue {
|
||||||
public:
|
public:
|
||||||
explicit ThreadQueueImplForKConditionVariableWaitForAddress(KernelCore& kernel)
|
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.
|
// 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.
|
// 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;
|
KConditionVariable::ThreadTree* m_tree;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ThreadQueueImplForKConditionVariableWaitConditionVariable(
|
explicit ThreadQueueImplForKConditionVariableWaitConditionVariable(KernelCore& kernel, KConditionVariable::ThreadTree* t)
|
||||||
KernelCore& kernel, KConditionVariable::ThreadTree* t)
|
: KThreadQueue(kernel)
|
||||||
: KThreadQueue(kernel), m_tree(t) {}
|
, 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.
|
// Remove the thread as a waiter from its owner.
|
||||||
if (KThread* owner = waiting_thread->GetLockOwner(); owner != nullptr) {
|
if (KThread* owner = waiting_thread->GetLockOwner(kernel); owner != nullptr) {
|
||||||
owner->RemoveWaiter(waiting_thread);
|
owner->RemoveWaiter(kernel, waiting_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the thread is waiting on a condvar, remove it from the tree.
|
// If the thread is waiting on a condvar, remove it from the tree.
|
||||||
@@ -99,14 +101,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Invoke the base cancel wait handler.
|
// 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
|
} // namespace
|
||||||
|
|
||||||
KConditionVariable::KConditionVariable(Core::System& system)
|
KConditionVariable::KConditionVariable(Core::System& system)
|
||||||
: m_system{system}, m_kernel{system.Kernel()} {}
|
: m_system{system}
|
||||||
|
{}
|
||||||
|
|
||||||
KConditionVariable::~KConditionVariable() = default;
|
KConditionVariable::~KConditionVariable() = default;
|
||||||
|
|
||||||
@@ -119,8 +122,7 @@ Result KConditionVariable::SignalToAddress(KernelCore& kernel, KProcessAddress a
|
|||||||
|
|
||||||
// Remove waiter thread.
|
// Remove waiter thread.
|
||||||
bool has_waiters{};
|
bool has_waiters{};
|
||||||
KThread* const next_owner_thread =
|
KThread* const next_owner_thread = owner_thread->RemoveUserWaiterByKey(kernel, std::addressof(has_waiters), addr);
|
||||||
owner_thread->RemoveUserWaiterByKey(std::addressof(has_waiters), addr);
|
|
||||||
|
|
||||||
// Determine the next tag.
|
// Determine the next tag.
|
||||||
u32 next_value{};
|
u32 next_value{};
|
||||||
@@ -144,15 +146,14 @@ Result KConditionVariable::SignalToAddress(KernelCore& kernel, KProcessAddress a
|
|||||||
|
|
||||||
// If necessary, signal the next owner thread.
|
// If necessary, signal the next owner thread.
|
||||||
if (next_owner_thread != nullptr) {
|
if (next_owner_thread != nullptr) {
|
||||||
next_owner_thread->EndWait(result);
|
next_owner_thread->EndWait(kernel, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
R_RETURN(result);
|
R_RETURN(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KConditionVariable::WaitForAddress(KernelCore& kernel, Handle handle, KProcessAddress addr,
|
Result KConditionVariable::WaitForAddress(KernelCore& kernel, Handle handle, KProcessAddress addr, u32 value) {
|
||||||
u32 value) {
|
|
||||||
KThread* cur_thread = GetCurrentThreadPointer(kernel);
|
KThread* cur_thread = GetCurrentThreadPointer(kernel);
|
||||||
ThreadQueueImplForKConditionVariableWaitForAddress wait_queue(kernel);
|
ThreadQueueImplForKConditionVariableWaitForAddress wait_queue(kernel);
|
||||||
|
|
||||||
@@ -173,30 +174,30 @@ Result KConditionVariable::WaitForAddress(KernelCore& kernel, Handle handle, KPr
|
|||||||
|
|
||||||
// Get the lock owner thread.
|
// Get the lock owner thread.
|
||||||
owner_thread = GetCurrentProcess(kernel)
|
owner_thread = GetCurrentProcess(kernel)
|
||||||
.GetHandleTable()
|
.GetHandleTable()
|
||||||
.GetObjectWithoutPseudoHandle<KThread>(handle)
|
.GetObjectWithoutPseudoHandle<KThread>(kernel, handle)
|
||||||
.ReleasePointerUnsafe();
|
.ReleasePointerUnsafe();
|
||||||
R_UNLESS(owner_thread != nullptr, ResultInvalidHandle);
|
R_UNLESS(owner_thread != nullptr, ResultInvalidHandle);
|
||||||
|
|
||||||
// Update the lock.
|
// Update the lock.
|
||||||
cur_thread->SetUserAddressKey(addr, value);
|
cur_thread->SetUserAddressKey(addr, value);
|
||||||
owner_thread->AddWaiter(cur_thread);
|
owner_thread->AddWaiter(kernel, cur_thread);
|
||||||
|
|
||||||
// Begin waiting.
|
// Begin waiting.
|
||||||
cur_thread->BeginWait(std::addressof(wait_queue));
|
cur_thread->BeginWait(kernel, std::addressof(wait_queue));
|
||||||
cur_thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::ConditionVar);
|
cur_thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::ConditionVar);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close our reference to the owner thread, now that the wait is over.
|
// Close our reference to the owner thread, now that the wait is over.
|
||||||
owner_thread->Close();
|
owner_thread->Close(kernel);
|
||||||
|
|
||||||
// Get the wait result.
|
// Get the wait result.
|
||||||
R_RETURN(cur_thread->GetWaitResult());
|
R_RETURN(cur_thread->GetWaitResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
void KConditionVariable::SignalImpl(KThread* thread) {
|
void KConditionVariable::SignalImpl(KernelCore& kernel, KThread* thread) {
|
||||||
// Check pre-conditions.
|
// Check pre-conditions.
|
||||||
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(m_kernel));
|
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
|
||||||
|
|
||||||
// Update the tag.
|
// Update the tag.
|
||||||
KProcessAddress address = thread->GetAddressKey();
|
KProcessAddress address = thread->GetAddressKey();
|
||||||
@@ -211,35 +212,33 @@ void KConditionVariable::SignalImpl(KThread* thread) {
|
|||||||
// TODO(bunnei): We should call CanAccessAtomic(..) here.
|
// TODO(bunnei): We should call CanAccessAtomic(..) here.
|
||||||
can_access = true;
|
can_access = true;
|
||||||
if (can_access) {
|
if (can_access) {
|
||||||
UpdateLockAtomic(m_kernel, std::addressof(prev_tag), address, own_tag,
|
UpdateLockAtomic(kernel, std::addressof(prev_tag), address, own_tag, Svc::HandleWaitMask);
|
||||||
Svc::HandleWaitMask);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (can_access) {
|
if (can_access) {
|
||||||
if (prev_tag == Svc::InvalidHandle) {
|
if (prev_tag == Svc::InvalidHandle) {
|
||||||
// If nobody held the lock previously, we're all good.
|
// If nobody held the lock previously, we're all good.
|
||||||
thread->EndWait(ResultSuccess);
|
thread->EndWait(kernel, ResultSuccess);
|
||||||
} else {
|
} else {
|
||||||
// Get the previous owner.
|
// Get the previous owner.
|
||||||
KThread* owner_thread = GetCurrentProcess(m_kernel)
|
KThread* owner_thread = GetCurrentProcess(kernel)
|
||||||
.GetHandleTable()
|
.GetHandleTable()
|
||||||
.GetObjectWithoutPseudoHandle<KThread>(
|
.GetObjectWithoutPseudoHandle<KThread>(kernel, Handle(prev_tag & ~Svc::HandleWaitMask))
|
||||||
static_cast<Handle>(prev_tag & ~Svc::HandleWaitMask))
|
.ReleasePointerUnsafe();
|
||||||
.ReleasePointerUnsafe();
|
|
||||||
|
|
||||||
if (owner_thread) {
|
if (owner_thread) {
|
||||||
// Add the thread as a waiter on the owner.
|
// Add the thread as a waiter on the owner.
|
||||||
owner_thread->AddWaiter(thread);
|
owner_thread->AddWaiter(kernel, thread);
|
||||||
owner_thread->Close();
|
owner_thread->Close(kernel);
|
||||||
} else {
|
} else {
|
||||||
// The lock was tagged with a thread that doesn't exist.
|
// The lock was tagged with a thread that doesn't exist.
|
||||||
thread->EndWait(ResultInvalidState);
|
thread->EndWait(kernel, ResultInvalidState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If the address wasn't accessible, note so.
|
// If the address wasn't accessible, note so.
|
||||||
thread->EndWait(ResultInvalidCurrentMemory);
|
thread->EndWait(kernel, ResultInvalidCurrentMemory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,17 +246,16 @@ void KConditionVariable::Signal(u64 cv_key, s32 count) {
|
|||||||
// Perform signaling.
|
// Perform signaling.
|
||||||
s32 num_waiters{};
|
s32 num_waiters{};
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl(m_kernel);
|
KScopedSchedulerLock sl(m_system.Kernel());
|
||||||
|
|
||||||
auto it = m_tree.nfind_key({cv_key, -1});
|
auto it = m_tree.nfind_key({cv_key, -1});
|
||||||
while ((it != m_tree.end()) && (count <= 0 || num_waiters < count) &&
|
while ((it != m_tree.end()) && (count <= 0 || num_waiters < count) && (it->GetConditionVariableKey() == cv_key)) {
|
||||||
(it->GetConditionVariableKey() == cv_key)) {
|
|
||||||
KThread* target_thread = std::addressof(*it);
|
KThread* target_thread = std::addressof(*it);
|
||||||
|
|
||||||
it = m_tree.erase(it);
|
it = m_tree.erase(it);
|
||||||
target_thread->ClearConditionVariable();
|
target_thread->ClearConditionVariable();
|
||||||
|
|
||||||
this->SignalImpl(target_thread);
|
this->SignalImpl(m_system.Kernel(), target_thread);
|
||||||
|
|
||||||
++num_waiters;
|
++num_waiters;
|
||||||
}
|
}
|
||||||
@@ -265,20 +263,20 @@ void KConditionVariable::Signal(u64 cv_key, s32 count) {
|
|||||||
// If we have no waiters, clear the has waiter flag.
|
// If we have no waiters, clear the has waiter flag.
|
||||||
if (it == m_tree.end() || it->GetConditionVariableKey() != cv_key) {
|
if (it == m_tree.end() || it->GetConditionVariableKey() != cv_key) {
|
||||||
constexpr u32 HasNoWaiterFlag = 0;
|
constexpr u32 HasNoWaiterFlag = 0;
|
||||||
WriteToUser(m_kernel, cv_key, HasNoWaiterFlag);
|
WriteToUser(m_system.Kernel(), cv_key, HasNoWaiterFlag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KConditionVariable::Wait(KProcessAddress addr, u64 key, u32 value, s64 timeout) {
|
Result KConditionVariable::Wait(KProcessAddress addr, u64 key, u32 value, s64 timeout) {
|
||||||
// Prepare to wait.
|
// Prepare to wait.
|
||||||
KThread* cur_thread = GetCurrentThreadPointer(m_kernel);
|
KThread* cur_thread = GetCurrentThreadPointer(m_system.Kernel());
|
||||||
KHardwareTimer* timer{};
|
KHardwareTimer* timer{};
|
||||||
ThreadQueueImplForKConditionVariableWaitConditionVariable wait_queue(m_kernel,
|
ThreadQueueImplForKConditionVariableWaitConditionVariable wait_queue(m_system.Kernel(),
|
||||||
std::addressof(m_tree));
|
std::addressof(m_tree));
|
||||||
|
|
||||||
{
|
{
|
||||||
KScopedSchedulerLockAndSleep slp(m_kernel, std::addressof(timer), cur_thread, timeout);
|
KScopedSchedulerLockAndSleep slp(m_system.Kernel(), std::addressof(timer), cur_thread, timeout);
|
||||||
|
|
||||||
// Check that the thread isn't terminating.
|
// Check that the thread isn't terminating.
|
||||||
if (cur_thread->IsTerminationRequested()) {
|
if (cur_thread->IsTerminationRequested()) {
|
||||||
@@ -291,7 +289,7 @@ Result KConditionVariable::Wait(KProcessAddress addr, u64 key, u32 value, s64 ti
|
|||||||
// Remove waiter thread.
|
// Remove waiter thread.
|
||||||
bool has_waiters{};
|
bool has_waiters{};
|
||||||
KThread* next_owner_thread =
|
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.
|
// Update for the next owner thread.
|
||||||
u32 next_value{};
|
u32 next_value{};
|
||||||
@@ -303,18 +301,18 @@ Result KConditionVariable::Wait(KProcessAddress addr, u64 key, u32 value, s64 ti
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wake up the next owner.
|
// Wake up the next owner.
|
||||||
next_owner_thread->EndWait(ResultSuccess);
|
next_owner_thread->EndWait(m_system.Kernel(), ResultSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write to the cv key.
|
// Write to the cv key.
|
||||||
{
|
{
|
||||||
constexpr u32 HasWaiterFlag = 1;
|
constexpr u32 HasWaiterFlag = 1;
|
||||||
WriteToUser(m_kernel, key, HasWaiterFlag);
|
WriteToUser(m_system.Kernel(), key, HasWaiterFlag);
|
||||||
std::atomic_thread_fence(std::memory_order_seq_cst);
|
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the value to userspace.
|
// Write the value to userspace.
|
||||||
if (!WriteToUser(m_kernel, addr, next_value)) {
|
if (!WriteToUser(m_system.Kernel(), addr, next_value)) {
|
||||||
slp.CancelSleep();
|
slp.CancelSleep();
|
||||||
R_THROW(ResultInvalidCurrentMemory);
|
R_THROW(ResultInvalidCurrentMemory);
|
||||||
}
|
}
|
||||||
@@ -329,7 +327,7 @@ Result KConditionVariable::Wait(KProcessAddress addr, u64 key, u32 value, s64 ti
|
|||||||
|
|
||||||
// Begin waiting.
|
// Begin waiting.
|
||||||
wait_queue.SetHardwareTimer(timer);
|
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);
|
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 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -26,19 +29,17 @@ public:
|
|||||||
|
|
||||||
// Arbitration.
|
// Arbitration.
|
||||||
static Result SignalToAddress(KernelCore& kernel, KProcessAddress addr);
|
static Result SignalToAddress(KernelCore& kernel, KProcessAddress addr);
|
||||||
static Result WaitForAddress(KernelCore& kernel, Handle handle, KProcessAddress addr,
|
static Result WaitForAddress(KernelCore& kernel, Handle handle, KProcessAddress addr, u32 value);
|
||||||
u32 value);
|
|
||||||
|
|
||||||
// Condition variable.
|
// Condition variable.
|
||||||
void Signal(u64 cv_key, s32 count);
|
void Signal(u64 cv_key, s32 count);
|
||||||
Result Wait(KProcessAddress addr, u64 key, u32 value, s64 timeout);
|
Result Wait(KProcessAddress addr, u64 key, u32 value, s64 timeout);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SignalImpl(KThread* thread);
|
void SignalImpl(KernelCore& kernel, KThread* thread);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::System& m_system;
|
Core::System& m_system;
|
||||||
KernelCore& m_kernel;
|
|
||||||
ThreadTree m_tree{};
|
ThreadTree m_tree{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -14,7 +17,7 @@ class KDebug final : public KAutoObjectWithSlabHeapAndContainer<KDebug, KAutoObj
|
|||||||
public:
|
public:
|
||||||
explicit KDebug(KernelCore& kernel) : KAutoObjectWithSlabHeapAndContainer{kernel} {}
|
explicit KDebug(KernelCore& kernel) : KAutoObjectWithSlabHeapAndContainer{kernel} {}
|
||||||
|
|
||||||
static void PostDestroy(uintptr_t arg) {}
|
static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace 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-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// 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) {}
|
: KAutoObjectWithSlabHeapAndContainer(kernel), m_lock(kernel), m_is_initialized(false) {}
|
||||||
KDeviceAddressSpace::~KDeviceAddressSpace() = default;
|
KDeviceAddressSpace::~KDeviceAddressSpace() = default;
|
||||||
|
|
||||||
void KDeviceAddressSpace::Initialize() {
|
void KDeviceAddressSpace::Initialize(KernelCore& kernel) {
|
||||||
// This just forwards to the device page table manager.
|
// This just forwards to the device page table manager.
|
||||||
// KDevicePageTable::Initialize();
|
// KDevicePageTable::Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Member functions.
|
// Member functions.
|
||||||
Result KDeviceAddressSpace::Initialize(u64 address, u64 size) {
|
Result KDeviceAddressSpace::Initialize(KernelCore& kernel, u64 address, u64 size) {
|
||||||
// Initialize the device page table.
|
// Initialize the device page table.
|
||||||
// R_TRY(m_table.Initialize(address, size));
|
// R_TRY(m_table.Initialize(address, size));
|
||||||
|
|
||||||
@@ -31,7 +34,7 @@ Result KDeviceAddressSpace::Initialize(u64 address, u64 size) {
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KDeviceAddressSpace::Finalize() {
|
void KDeviceAddressSpace::Finalize(KernelCore& kernel) {
|
||||||
// Finalize the table.
|
// Finalize the table.
|
||||||
// m_table.Finalize();
|
// 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-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -20,13 +23,13 @@ public:
|
|||||||
explicit KDeviceAddressSpace(KernelCore& kernel);
|
explicit KDeviceAddressSpace(KernelCore& kernel);
|
||||||
~KDeviceAddressSpace();
|
~KDeviceAddressSpace();
|
||||||
|
|
||||||
Result Initialize(u64 address, u64 size);
|
Result Initialize(KernelCore& kernel, u64 address, u64 size);
|
||||||
void Finalize() override;
|
void Finalize(KernelCore& kernel) override;
|
||||||
|
|
||||||
bool IsInitialized() const override {
|
bool IsInitialized() const override {
|
||||||
return m_is_initialized;
|
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 Attach(Svc::DeviceName device_name);
|
||||||
Result Detach(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,
|
Result Unmap(KProcessPageTable* page_table, KProcessAddress process_address, size_t size,
|
||||||
u64 device_address);
|
u64 device_address);
|
||||||
|
|
||||||
static void Initialize();
|
static void Initialize(KernelCore& kernel);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Result Map(KProcessPageTable* page_table, KProcessAddress process_address, size_t size,
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -8,56 +11,58 @@
|
|||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
KEvent::KEvent(KernelCore& kernel)
|
KEvent::KEvent(KernelCore& kernel)
|
||||||
: KAutoObjectWithSlabHeapAndContainer{kernel}, m_readable_event{kernel} {}
|
: KAutoObjectWithSlabHeapAndContainer{kernel}
|
||||||
|
, m_readable_event{kernel}
|
||||||
|
{}
|
||||||
|
|
||||||
KEvent::~KEvent() = default;
|
KEvent::~KEvent() = default;
|
||||||
|
|
||||||
void KEvent::Initialize(KProcess* owner) {
|
void KEvent::Initialize(KernelCore& kernel, KProcess* owner) {
|
||||||
// Create our readable event.
|
// Create our readable event.
|
||||||
KAutoObject::Create(std::addressof(m_readable_event));
|
KAutoObject::Create(std::addressof(m_readable_event));
|
||||||
|
|
||||||
// Initialize our readable event.
|
// Initialize our readable event.
|
||||||
m_readable_event.Initialize(this);
|
m_readable_event.Initialize(kernel, this);
|
||||||
|
|
||||||
// Set our owner process.
|
// Set our owner process.
|
||||||
// HACK: this should never be nullptr, but service threads don't have a
|
// HACK: this should never be nullptr, but service threads don't have a
|
||||||
// proper parent process yet.
|
// proper parent process yet.
|
||||||
if (owner != nullptr) {
|
if (owner != nullptr) {
|
||||||
m_owner = owner;
|
m_owner = owner;
|
||||||
m_owner->Open();
|
m_owner->Open(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark initialized.
|
// Mark initialized.
|
||||||
m_initialized = true;
|
m_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KEvent::Finalize() {
|
void KEvent::Finalize(KernelCore& kernel) {
|
||||||
KAutoObjectWithSlabHeapAndContainer<KEvent, KAutoObjectWithList>::Finalize();
|
KAutoObjectWithSlabHeapAndContainer<KEvent, KAutoObjectWithList>::Finalize(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KEvent::Signal() {
|
Result KEvent::Signal(KernelCore& kernel) {
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
R_SUCCEED_IF(m_readable_event_destroyed);
|
R_SUCCEED_IF(m_readable_event_destroyed);
|
||||||
|
|
||||||
return m_readable_event.Signal();
|
return m_readable_event.Signal(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KEvent::Clear() {
|
Result KEvent::Clear(KernelCore& kernel) {
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
R_SUCCEED_IF(m_readable_event_destroyed);
|
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.
|
// Release the event count resource the owner process holds.
|
||||||
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
||||||
|
|
||||||
if (owner != nullptr) {
|
if (owner != nullptr) {
|
||||||
owner->GetResourceLimit()->Release(LimitableResource::EventCountMax, 1);
|
owner->GetResourceLimit()->Release(kernel, LimitableResource::EventCountMax, 1);
|
||||||
owner->Close();
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -19,9 +22,9 @@ public:
|
|||||||
explicit KEvent(KernelCore& kernel);
|
explicit KEvent(KernelCore& kernel);
|
||||||
~KEvent() override;
|
~KEvent() override;
|
||||||
|
|
||||||
void Initialize(KProcess* owner);
|
void Initialize(KernelCore& kernel, KProcess* owner);
|
||||||
|
|
||||||
void Finalize() override;
|
void Finalize(KernelCore& kernel) override;
|
||||||
|
|
||||||
bool IsInitialized() const override {
|
bool IsInitialized() const override {
|
||||||
return m_initialized;
|
return m_initialized;
|
||||||
@@ -39,10 +42,10 @@ public:
|
|||||||
return m_readable_event;
|
return m_readable_event;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PostDestroy(uintptr_t arg);
|
static void PostDestroy(KernelCore& kernel, uintptr_t arg);
|
||||||
|
|
||||||
Result Signal();
|
Result Signal(KernelCore& kernel);
|
||||||
Result Clear();
|
Result Clear(KernelCore& kernel);
|
||||||
|
|
||||||
void OnReadableEventDestroyed() {
|
void OnReadableEventDestroyed() {
|
||||||
m_readable_event_destroyed = true;
|
m_readable_event_destroyed = 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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
@@ -6,28 +6,27 @@
|
|||||||
|
|
||||||
#include "core/hle/kernel/k_handle_table.h"
|
#include "core/hle/kernel/k_handle_table.h"
|
||||||
#include "core/hle/kernel/k_process.h"
|
#include "core/hle/kernel/k_process.h"
|
||||||
|
#include "core/hle/kernel/kernel.h"
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
void KHandleTable::Finalize() {
|
void KHandleTable::Finalize(KernelCore& kernel) {
|
||||||
// Get the table and clear our record of it.
|
// Get the table and clear our record of it.
|
||||||
u16 saved_table_size = 0;
|
u16 saved_table_size = 0;
|
||||||
{
|
{
|
||||||
KScopedDisableDispatch dd{m_kernel};
|
KScopedDisableDispatch dd{kernel};
|
||||||
KScopedSpinLock lk(m_lock);
|
KScopedSpinLock lk(m_lock);
|
||||||
|
|
||||||
std::swap(m_table_size, saved_table_size);
|
std::swap(m_table_size, saved_table_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close and free all entries.
|
// Close and free all entries.
|
||||||
for (size_t i = 0; i < saved_table_size; i++) {
|
for (size_t i = 0; i < saved_table_size; i++)
|
||||||
if (KAutoObject* obj = m_objects[i]; obj != nullptr) {
|
if (KAutoObject* obj = m_objects[i]; obj != nullptr)
|
||||||
obj->Close();
|
obj->Close(kernel);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KHandleTable::Remove(Handle handle) {
|
bool KHandleTable::Remove(KernelCore& kernel, Handle handle) {
|
||||||
// Don't allow removal of a pseudo-handle.
|
// Don't allow removal of a pseudo-handle.
|
||||||
if (Svc::IsPseudoHandle(handle)) [[unlikely]] {
|
if (Svc::IsPseudoHandle(handle)) [[unlikely]] {
|
||||||
return false;
|
return false;
|
||||||
@@ -42,7 +41,7 @@ bool KHandleTable::Remove(Handle handle) {
|
|||||||
// Find the object and free the entry.
|
// Find the object and free the entry.
|
||||||
KAutoObject* obj = nullptr;
|
KAutoObject* obj = nullptr;
|
||||||
{
|
{
|
||||||
KScopedDisableDispatch dd{m_kernel};
|
KScopedDisableDispatch dd{kernel};
|
||||||
KScopedSpinLock lk(m_lock);
|
KScopedSpinLock lk(m_lock);
|
||||||
|
|
||||||
if (this->IsValidHandle(handle)) [[likely]] {
|
if (this->IsValidHandle(handle)) [[likely]] {
|
||||||
@@ -56,13 +55,13 @@ bool KHandleTable::Remove(Handle handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close the object.
|
// Close the object.
|
||||||
m_kernel.UnregisterInUseObject(obj);
|
kernel.UnregisterInUseObject(obj);
|
||||||
obj->Close();
|
obj->Close(kernel);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KHandleTable::Add(Handle* out_handle, KAutoObject* obj) {
|
Result KHandleTable::Add(KernelCore& kernel, Handle* out_handle, KAutoObject* obj) {
|
||||||
KScopedDisableDispatch dd{m_kernel};
|
KScopedDisableDispatch dd{kernel};
|
||||||
KScopedSpinLock lk(m_lock);
|
KScopedSpinLock lk(m_lock);
|
||||||
|
|
||||||
// Never exceed our capacity.
|
// Never exceed our capacity.
|
||||||
@@ -76,7 +75,7 @@ Result KHandleTable::Add(Handle* out_handle, KAutoObject* obj) {
|
|||||||
m_entry_infos[index].linear_id = linear_id;
|
m_entry_infos[index].linear_id = linear_id;
|
||||||
m_objects[index] = obj;
|
m_objects[index] = obj;
|
||||||
|
|
||||||
obj->Open();
|
obj->Open(kernel);
|
||||||
|
|
||||||
*out_handle = EncodeHandle(static_cast<u16>(index), linear_id);
|
*out_handle = EncodeHandle(static_cast<u16>(index), linear_id);
|
||||||
}
|
}
|
||||||
@@ -84,24 +83,22 @@ Result KHandleTable::Add(Handle* out_handle, KAutoObject* obj) {
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
KScopedAutoObject<KAutoObject> KHandleTable::GetObjectForIpc(Handle handle,
|
KScopedAutoObject<KAutoObject> KHandleTable::GetObjectForIpc(KernelCore& kernel, Handle handle, KThread* cur_thread) const {
|
||||||
KThread* cur_thread) const {
|
|
||||||
// Handle pseudo-handles.
|
// Handle pseudo-handles.
|
||||||
ASSERT(cur_thread != nullptr);
|
ASSERT(cur_thread != nullptr);
|
||||||
if (handle == Svc::PseudoHandle::CurrentProcess) {
|
if (handle == Svc::PseudoHandle::CurrentProcess) {
|
||||||
auto* const cur_process = cur_thread->GetOwnerProcess();
|
auto* const cur_process = cur_thread->GetOwnerProcess();
|
||||||
ASSERT(cur_process != nullptr);
|
ASSERT(cur_process != nullptr);
|
||||||
return cur_process;
|
return {kernel, cur_process};
|
||||||
}
|
}
|
||||||
if (handle == Svc::PseudoHandle::CurrentThread) {
|
if (handle == Svc::PseudoHandle::CurrentThread) {
|
||||||
return cur_thread;
|
return {kernel, cur_thread};
|
||||||
}
|
}
|
||||||
|
return GetObjectForIpcWithoutPseudoHandle(kernel, handle);
|
||||||
return GetObjectForIpcWithoutPseudoHandle(handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KHandleTable::Reserve(Handle* out_handle) {
|
Result KHandleTable::Reserve(KernelCore& kernel, Handle* out_handle) {
|
||||||
KScopedDisableDispatch dd{m_kernel};
|
KScopedDisableDispatch dd{kernel};
|
||||||
KScopedSpinLock lk(m_lock);
|
KScopedSpinLock lk(m_lock);
|
||||||
|
|
||||||
// Never exceed our capacity.
|
// Never exceed our capacity.
|
||||||
@@ -111,8 +108,8 @@ Result KHandleTable::Reserve(Handle* out_handle) {
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KHandleTable::Unreserve(Handle handle) {
|
void KHandleTable::Unreserve(KernelCore& kernel, Handle handle) {
|
||||||
KScopedDisableDispatch dd{m_kernel};
|
KScopedDisableDispatch dd{kernel};
|
||||||
KScopedSpinLock lk(m_lock);
|
KScopedSpinLock lk(m_lock);
|
||||||
|
|
||||||
// Unpack the handle.
|
// Unpack the handle.
|
||||||
@@ -130,8 +127,8 @@ void KHandleTable::Unreserve(Handle handle) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KHandleTable::Register(Handle handle, KAutoObject* obj) {
|
void KHandleTable::Register(KernelCore& kernel, Handle handle, KAutoObject* obj) {
|
||||||
KScopedDisableDispatch dd{m_kernel};
|
KScopedDisableDispatch dd{kernel};
|
||||||
KScopedSpinLock lk(m_lock);
|
KScopedSpinLock lk(m_lock);
|
||||||
|
|
||||||
// Unpack the handle.
|
// Unpack the handle.
|
||||||
@@ -149,7 +146,7 @@ void KHandleTable::Register(Handle handle, KAutoObject* obj) {
|
|||||||
m_entry_infos[index].linear_id = static_cast<u16>(linear_id);
|
m_entry_infos[index].linear_id = static_cast<u16>(linear_id);
|
||||||
m_objects[index] = obj;
|
m_objects[index] = obj;
|
||||||
|
|
||||||
obj->Open();
|
obj->Open(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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
@@ -31,14 +31,14 @@ public:
|
|||||||
static constexpr size_t MaxTableSize = 1024;
|
static constexpr size_t MaxTableSize = 1024;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit KHandleTable(KernelCore& kernel) : m_kernel(kernel) {}
|
explicit KHandleTable(KernelCore& kernel) {}
|
||||||
|
|
||||||
Result Initialize(s32 size) {
|
Result Initialize(KernelCore& kernel, s32 size) {
|
||||||
// Check that the table size is valid.
|
// Check that the table size is valid.
|
||||||
R_UNLESS(size <= static_cast<s32>(MaxTableSize), ResultOutOfMemory);
|
R_UNLESS(size <= static_cast<s32>(MaxTableSize), ResultOutOfMemory);
|
||||||
|
|
||||||
// Lock.
|
// Lock.
|
||||||
KScopedDisableDispatch dd{m_kernel};
|
KScopedDisableDispatch dd{kernel};
|
||||||
KScopedSpinLock lk(m_lock);
|
KScopedSpinLock lk(m_lock);
|
||||||
|
|
||||||
// Initialize all fields.
|
// Initialize all fields.
|
||||||
@@ -68,76 +68,72 @@ public:
|
|||||||
return m_max_count;
|
return m_max_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Finalize();
|
void Finalize(KernelCore& kernel);
|
||||||
bool Remove(Handle handle);
|
bool Remove(KernelCore& kernel, Handle handle);
|
||||||
|
|
||||||
template <typename T = KAutoObject>
|
template <typename T = KAutoObject>
|
||||||
KScopedAutoObject<T> GetObjectWithoutPseudoHandle(Handle handle) const {
|
KScopedAutoObject<T> GetObjectWithoutPseudoHandle(KernelCore& kernel, Handle handle) const {
|
||||||
// Lock and look up in table.
|
// Lock and look up in table.
|
||||||
KScopedDisableDispatch dd{m_kernel};
|
KScopedDisableDispatch dd{kernel};
|
||||||
KScopedSpinLock lk(m_lock);
|
KScopedSpinLock lk(m_lock);
|
||||||
|
|
||||||
if constexpr (std::is_same_v<T, KAutoObject>) {
|
if constexpr (std::is_same_v<T, KAutoObject>) {
|
||||||
return this->GetObjectImpl(handle);
|
return {kernel, this->GetObjectImpl(handle)};
|
||||||
} else {
|
} else {
|
||||||
if (auto* obj = this->GetObjectImpl(handle); obj != nullptr) [[likely]] {
|
if (auto* obj = this->GetObjectImpl(handle); obj != nullptr) [[likely]] {
|
||||||
return obj->DynamicCast<T*>();
|
return {kernel, obj->DynamicCast<T*>()};
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
return {kernel, nullptr};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T = KAutoObject>
|
template <typename T = KAutoObject>
|
||||||
KScopedAutoObject<T> GetObject(Handle handle) const {
|
KScopedAutoObject<T> GetObject(KernelCore& kernel, Handle handle) const {
|
||||||
// Handle pseudo-handles.
|
// Handle pseudo-handles.
|
||||||
if constexpr (std::derived_from<KProcess, T>) {
|
if constexpr (std::derived_from<KProcess, T>) {
|
||||||
if (handle == Svc::PseudoHandle::CurrentProcess) {
|
if (handle == Svc::PseudoHandle::CurrentProcess) {
|
||||||
auto* const cur_process = GetCurrentProcessPointer(m_kernel);
|
auto* const cur_process = GetCurrentProcessPointer(kernel);
|
||||||
ASSERT(cur_process != nullptr);
|
ASSERT(cur_process != nullptr);
|
||||||
return cur_process;
|
return {kernel, cur_process};
|
||||||
}
|
}
|
||||||
} else if constexpr (std::derived_from<KThread, T>) {
|
} else if constexpr (std::derived_from<KThread, T>) {
|
||||||
if (handle == Svc::PseudoHandle::CurrentThread) {
|
if (handle == Svc::PseudoHandle::CurrentThread) {
|
||||||
auto* const cur_thread = GetCurrentThreadPointer(m_kernel);
|
auto* const cur_thread = GetCurrentThreadPointer(kernel);
|
||||||
ASSERT(cur_thread != nullptr);
|
ASSERT(cur_thread != nullptr);
|
||||||
return cur_thread;
|
return {kernel, cur_thread};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return this->template GetObjectWithoutPseudoHandle<T>(kernel, handle);
|
||||||
return this->template GetObjectWithoutPseudoHandle<T>(handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KScopedAutoObject<KAutoObject> GetObjectForIpcWithoutPseudoHandle(Handle handle) const {
|
KScopedAutoObject<KAutoObject> GetObjectForIpcWithoutPseudoHandle(KernelCore& kernel, Handle handle) const {
|
||||||
// Lock and look up in table.
|
// Lock and look up in table.
|
||||||
KScopedDisableDispatch dd{m_kernel};
|
KScopedDisableDispatch dd{kernel};
|
||||||
|
KScopedSpinLock lk(m_lock);
|
||||||
|
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);
|
KScopedSpinLock lk(m_lock);
|
||||||
|
|
||||||
return this->GetObjectImpl(handle);
|
return {kernel, this->GetObjectByIndexImpl(out_handle, index)};
|
||||||
}
|
}
|
||||||
|
|
||||||
KScopedAutoObject<KAutoObject> GetObjectForIpc(Handle handle, KThread* cur_thread) const;
|
Result Reserve(KernelCore& kernel, Handle* out_handle);
|
||||||
|
void Unreserve(KernelCore& kernel, Handle handle);
|
||||||
|
|
||||||
KScopedAutoObject<KAutoObject> GetObjectByIndex(Handle* out_handle, size_t index) const {
|
Result Add(KernelCore& kernel, Handle* out_handle, KAutoObject* obj);
|
||||||
KScopedDisableDispatch dd{m_kernel};
|
void Register(KernelCore& kernel, Handle handle, KAutoObject* obj);
|
||||||
KScopedSpinLock lk(m_lock);
|
|
||||||
|
|
||||||
return this->GetObjectByIndexImpl(out_handle, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result Reserve(Handle* out_handle);
|
|
||||||
void Unreserve(Handle handle);
|
|
||||||
|
|
||||||
Result Add(Handle* out_handle, KAutoObject* obj);
|
|
||||||
void Register(Handle handle, KAutoObject* obj);
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool GetMultipleObjects(T** out, const Handle* handles, size_t num_handles) const {
|
bool GetMultipleObjects(KernelCore& kernel, T** out, const Handle* handles, size_t num_handles) const {
|
||||||
// Try to convert and open all the handles.
|
// Try to convert and open all the handles.
|
||||||
size_t num_opened;
|
size_t num_opened;
|
||||||
{
|
{
|
||||||
// Lock the table.
|
// Lock the table.
|
||||||
KScopedDisableDispatch dd{m_kernel};
|
KScopedDisableDispatch dd{kernel};
|
||||||
KScopedSpinLock lk(m_lock);
|
KScopedSpinLock lk(m_lock);
|
||||||
for (num_opened = 0; num_opened < num_handles; num_opened++) {
|
for (num_opened = 0; num_opened < num_handles; num_opened++) {
|
||||||
// Get the current handle.
|
// Get the current handle.
|
||||||
@@ -150,14 +146,14 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cast the current object to the desired type.
|
// Cast the current object to the desired type.
|
||||||
T* cur_t = cur_object->DynamicCast<T*>();
|
T* cur_thread = cur_object->DynamicCast<T*>();
|
||||||
if (cur_t == nullptr) [[unlikely]] {
|
if (cur_thread == nullptr) [[unlikely]] {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open a reference to the current object.
|
// Open a reference to the current object.
|
||||||
cur_t->Open();
|
cur_thread->Open(kernel);
|
||||||
out[num_opened] = cur_t;
|
out[num_opened] = cur_thread;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +164,7 @@ public:
|
|||||||
|
|
||||||
// If we didn't convert entry object, close the ones we opened.
|
// If we didn't convert entry object, close the ones we opened.
|
||||||
for (size_t i = 0; i < num_opened; i++) {
|
for (size_t i = 0; i < num_opened; i++) {
|
||||||
out[i]->Close();
|
out[i]->Close(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -177,13 +173,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
s32 AllocateEntry() {
|
s32 AllocateEntry() {
|
||||||
ASSERT(m_count < m_table_size);
|
ASSERT(m_count < m_table_size);
|
||||||
|
|
||||||
const auto index = m_free_head_index;
|
const auto index = m_free_head_index;
|
||||||
|
|
||||||
m_free_head_index = m_entry_infos[index].GetNextFreeIndex();
|
m_free_head_index = m_entry_infos[index].GetNextFreeIndex();
|
||||||
|
|
||||||
m_max_count = (std::max)(m_max_count, ++m_count);
|
m_max_count = (std::max)(m_max_count, ++m_count);
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,7 +294,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KernelCore& m_kernel;
|
|
||||||
std::array<EntryInfo, MaxTableSize> m_entry_infos{};
|
std::array<EntryInfo, MaxTableSize> m_entry_infos{};
|
||||||
std::array<KAutoObject*, MaxTableSize> m_objects{};
|
std::array<KAutoObject*, MaxTableSize> m_objects{};
|
||||||
mutable KSpinLock m_lock;
|
mutable KSpinLock m_lock;
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -45,7 +48,7 @@ protected:
|
|||||||
this->RemoveTaskFromTree(task);
|
this->RemoveTaskFromTree(task);
|
||||||
|
|
||||||
// Handle the 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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -18,19 +21,19 @@ void HandleInterrupt(KernelCore& kernel, s32 core_id) {
|
|||||||
|
|
||||||
if (auto* process = GetCurrentProcessPointer(kernel); process) {
|
if (auto* process = GetCurrentProcessPointer(kernel); process) {
|
||||||
// If the user disable count is set, we may need to pin the current thread.
|
// 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};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
// Pin the current thread.
|
// Pin the current thread.
|
||||||
process->PinCurrentThread();
|
process->PinCurrentThread(kernel);
|
||||||
|
|
||||||
// Set the interrupt flag for the thread.
|
// Set the interrupt flag for the thread.
|
||||||
GetCurrentThread(kernel).SetInterruptFlag();
|
GetCurrentThread(kernel).SetInterruptFlag(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request interrupt scheduling.
|
// Request interrupt scheduling.
|
||||||
kernel.CurrentScheduler()->RequestScheduleOnInterrupt();
|
kernel.CurrentScheduler()->RequestScheduleOnInterrupt(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendInterProcessorInterrupt(KernelCore& kernel, u64 core_mask) {
|
void SendInterProcessorInterrupt(KernelCore& kernel, u64 core_mask) {
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -11,21 +14,21 @@ KLightClientSession::KLightClientSession(KernelCore& kernel) : KAutoObject(kerne
|
|||||||
|
|
||||||
KLightClientSession::~KLightClientSession() = default;
|
KLightClientSession::~KLightClientSession() = default;
|
||||||
|
|
||||||
void KLightClientSession::Destroy() {
|
void KLightClientSession::Destroy(KernelCore& kernel) {
|
||||||
m_parent->OnClientClosed();
|
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.
|
// Get the request thread.
|
||||||
KThread* cur_thread = GetCurrentThreadPointer(m_kernel);
|
KThread* cur_thread = GetCurrentThreadPointer(kernel);
|
||||||
|
|
||||||
// Set the light data.
|
// Set the light data.
|
||||||
cur_thread->SetLightSessionData(data);
|
cur_thread->SetLightSessionData(data);
|
||||||
|
|
||||||
// Send the request.
|
// Send the request.
|
||||||
R_RETURN(m_parent->OnRequest(cur_thread));
|
R_RETURN(m_parent->OnRequest(kernel, cur_thread));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace 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-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -22,15 +25,15 @@ public:
|
|||||||
m_parent = parent;
|
m_parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Destroy() override;
|
virtual void Destroy(KernelCore& kernel) override;
|
||||||
|
|
||||||
const KLightSession* GetParent() const {
|
const KLightSession* GetParent() const {
|
||||||
return m_parent;
|
return m_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SendSyncRequest(u32* data);
|
Result SendSyncRequest(KernelCore& kernel, u32* data);
|
||||||
|
|
||||||
void OnServerClosed();
|
void OnServerClosed(KernelCore& kernel);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KLightSession* m_parent;
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -13,11 +16,13 @@ namespace {
|
|||||||
|
|
||||||
class ThreadQueueImplForKLightConditionVariable final : public KThreadQueue {
|
class ThreadQueueImplForKLightConditionVariable final : public KThreadQueue {
|
||||||
public:
|
public:
|
||||||
ThreadQueueImplForKLightConditionVariable(KernelCore& kernel, KThread::WaiterList* wl,
|
ThreadQueueImplForKLightConditionVariable(KernelCore& kernel, KThread::WaiterList* wl, bool term)
|
||||||
bool term)
|
: KThreadQueue(kernel)
|
||||||
: KThreadQueue(kernel), m_wait_list(wl), m_allow_terminating_thread(term) {}
|
, 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.
|
// Only process waits if we're allowed to.
|
||||||
if (ResultTerminationRequested == wait_result && m_allow_terminating_thread) {
|
if (ResultTerminationRequested == wait_result && m_allow_terminating_thread) {
|
||||||
return;
|
return;
|
||||||
@@ -27,7 +32,7 @@ public:
|
|||||||
m_wait_list->erase(m_wait_list->iterator_to(*waiting_thread));
|
m_wait_list->erase(m_wait_list->iterator_to(*waiting_thread));
|
||||||
|
|
||||||
// Invoke the base cancel wait handler.
|
// 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:
|
private:
|
||||||
@@ -61,7 +66,7 @@ void KLightConditionVariable::Wait(KLightLock* lock, s64 timeout, bool allow_ter
|
|||||||
|
|
||||||
// Begin waiting.
|
// Begin waiting.
|
||||||
wait_queue.SetHardwareTimer(timer);
|
wait_queue.SetHardwareTimer(timer);
|
||||||
owner->BeginWait(std::addressof(wait_queue));
|
owner->BeginWait(m_kernel, std::addressof(wait_queue));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-acquire the lock.
|
// Re-acquire the lock.
|
||||||
@@ -73,7 +78,7 @@ void KLightConditionVariable::Broadcast() {
|
|||||||
|
|
||||||
// Signal all threads.
|
// Signal all threads.
|
||||||
for (auto it = m_wait_list.begin(); it != m_wait_list.end(); it = m_wait_list.erase(it)) {
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -15,29 +18,25 @@ class ThreadQueueImplForKLightLock final : public KThreadQueue {
|
|||||||
public:
|
public:
|
||||||
explicit ThreadQueueImplForKLightLock(KernelCore& kernel) : KThreadQueue(kernel) {}
|
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.
|
// Remove the thread as a waiter from its owner.
|
||||||
if (KThread* owner = waiting_thread->GetLockOwner(); owner != nullptr) {
|
if (KThread* owner = waiting_thread->GetLockOwner(kernel); owner != nullptr) {
|
||||||
owner->RemoveWaiter(waiting_thread);
|
owner->RemoveWaiter(kernel, waiting_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoke the base cancel wait handler.
|
// 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
|
} // namespace
|
||||||
|
|
||||||
void KLightLock::Lock() {
|
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) {
|
while (true) {
|
||||||
uintptr_t old_tag = m_tag.load(std::memory_order_relaxed);
|
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)) {
|
if (old_tag == 0 || this->LockSlowPath(old_tag | 1, cur_thread)) {
|
||||||
break;
|
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.
|
// Add the current thread as a waiter on the owner.
|
||||||
KThread* owner_thread = reinterpret_cast<KThread*>(_owner & ~1ULL);
|
KThread* owner_thread = reinterpret_cast<KThread*>(_owner & ~1ULL);
|
||||||
cur_thread->SetKernelAddressKey(reinterpret_cast<uintptr_t>(std::addressof(m_tag)));
|
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.
|
// 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()) {
|
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.
|
// Get the next owner.
|
||||||
bool has_waiters;
|
bool has_waiters;
|
||||||
KThread* next_owner = owner_thread->RemoveKernelWaiterByKey(
|
KThread* next_owner = owner_thread->RemoveKernelWaiterByKey(m_kernel,
|
||||||
std::addressof(has_waiters), reinterpret_cast<uintptr_t>(std::addressof(m_tag)));
|
std::addressof(has_waiters), uintptr_t(std::addressof(m_tag)));
|
||||||
|
|
||||||
// Pass the lock to the next owner.
|
// Pass the lock to the next owner.
|
||||||
uintptr_t next_tag = 0;
|
uintptr_t next_tag = 0;
|
||||||
if (next_owner != nullptr) {
|
if (next_owner != nullptr) {
|
||||||
next_tag =
|
next_tag = uintptr_t(next_owner) | uintptr_t(has_waiters);
|
||||||
reinterpret_cast<uintptr_t>(next_owner) | static_cast<uintptr_t>(has_waiters);
|
|
||||||
|
|
||||||
next_owner->EndWait(ResultSuccess);
|
next_owner->EndWait(m_kernel, ResultSuccess);
|
||||||
|
|
||||||
if (next_owner->IsSuspended()) {
|
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
|
// We may have unsuspended in the process of acquiring the lock, so we'll re-suspend now if
|
||||||
// so.
|
// so.
|
||||||
if (owner_thread->IsSuspended()) {
|
if (owner_thread->IsSuspended()) {
|
||||||
owner_thread->TrySuspend();
|
owner_thread->TrySuspend(m_kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the new tag value.
|
// Write the new tag value.
|
||||||
@@ -119,8 +117,7 @@ void KLightLock::UnlockSlowPath(uintptr_t _cur_thread) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool KLightLock::IsLockedByCurrentThread() const {
|
bool KLightLock::IsLockedByCurrentThread() const {
|
||||||
return (m_tag.load() | 1ULL) ==
|
return (m_tag.load() | 1ULL) == (uintptr_t(GetCurrentThreadPointer(m_kernel)) | 1ULL);
|
||||||
(reinterpret_cast<uintptr_t>(GetCurrentThreadPointer(m_kernel)) | 1ULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // 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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
@@ -24,21 +24,20 @@ public:
|
|||||||
ThreadQueueImplForKLightServerSessionRequest(KernelCore& kernel, KThread::WaiterList* wl)
|
ThreadQueueImplForKLightServerSessionRequest(KernelCore& kernel, KThread::WaiterList* wl)
|
||||||
: KThreadQueue(kernel), m_wait_list(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.
|
// Remove the thread from our wait list.
|
||||||
m_wait_list->erase(m_wait_list->iterator_to(*waiting_thread));
|
m_wait_list->erase(m_wait_list->iterator_to(*waiting_thread));
|
||||||
|
|
||||||
// Invoke the base end wait handler.
|
// 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,
|
virtual void CancelWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||||
bool cancel_timer_task) override {
|
|
||||||
// Remove the thread from our wait list.
|
// Remove the thread from our wait list.
|
||||||
m_wait_list->erase(m_wait_list->iterator_to(*waiting_thread));
|
m_wait_list->erase(m_wait_list->iterator_to(*waiting_thread));
|
||||||
|
|
||||||
// Invoke the base cancel wait handler.
|
// 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:
|
public:
|
||||||
ThreadQueueImplForKLightServerSessionReceive(KernelCore& kernel, KThread** st)
|
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.
|
// Clear the server thread.
|
||||||
*m_server_thread = nullptr;
|
*m_server_thread = nullptr;
|
||||||
|
|
||||||
@@ -58,11 +59,10 @@ public:
|
|||||||
waiting_thread->ClearCancellable();
|
waiting_thread->ClearCancellable();
|
||||||
|
|
||||||
// Invoke the base end wait handler.
|
// 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,
|
virtual void CancelWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result, bool cancel_timer_task) override {
|
||||||
bool cancel_timer_task) override {
|
|
||||||
// Clear the server thread.
|
// Clear the server thread.
|
||||||
*m_server_thread = nullptr;
|
*m_server_thread = nullptr;
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ public:
|
|||||||
waiting_thread->ClearCancellable();
|
waiting_thread->ClearCancellable();
|
||||||
|
|
||||||
// Invoke the base cancel wait handler.
|
// 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(KernelCore& kernel) : KAutoObject(kernel) {}
|
||||||
KLightServerSession::~KLightServerSession() = default;
|
KLightServerSession::~KLightServerSession() = default;
|
||||||
|
|
||||||
void KLightServerSession::Destroy() {
|
void KLightServerSession::Destroy(KernelCore& kernel) {
|
||||||
this->CleanupRequests();
|
this->CleanupRequests(kernel);
|
||||||
|
m_parent->OnServerClosed(kernel);
|
||||||
m_parent->OnServerClosed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KLightServerSession::OnClientClosed() {
|
void KLightServerSession::OnClientClosed(KernelCore& kernel) {
|
||||||
this->CleanupRequests();
|
this->CleanupRequests(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KLightServerSession::OnRequest(KThread* request_thread) {
|
Result KLightServerSession::OnRequest(KernelCore& kernel, KThread* request_thread) {
|
||||||
ThreadQueueImplForKLightServerSessionRequest wait_queue(m_kernel,
|
ThreadQueueImplForKLightServerSessionRequest wait_queue(kernel, std::addressof(m_request_list));
|
||||||
std::addressof(m_request_list));
|
|
||||||
|
|
||||||
// Send the request.
|
// Send the request.
|
||||||
{
|
{
|
||||||
// Lock the scheduler.
|
// Lock the scheduler.
|
||||||
KScopedSchedulerLock sl(m_kernel);
|
KScopedSchedulerLock sl(kernel);
|
||||||
|
|
||||||
// Check that the server isn't closed.
|
// Check that the server isn't closed.
|
||||||
R_UNLESS(!m_parent->IsServerClosed(), ResultSessionClosed);
|
R_UNLESS(!m_parent->IsServerClosed(), ResultSessionClosed);
|
||||||
@@ -109,11 +106,11 @@ Result KLightServerSession::OnRequest(KThread* request_thread) {
|
|||||||
|
|
||||||
// Begin waiting on the request.
|
// Begin waiting on the request.
|
||||||
request_thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::IPC);
|
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 we have a server thread, end its wait.
|
||||||
if (m_server_thread != nullptr) {
|
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());
|
R_RETURN(request_thread->GetWaitResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KLightServerSession::ReplyAndReceive(u32* data) {
|
Result KLightServerSession::ReplyAndReceive(KernelCore& kernel, u32* data) {
|
||||||
// Set the server context.
|
// Set the server context.
|
||||||
GetCurrentThread(m_kernel).SetLightSessionData(data);
|
GetCurrentThread(kernel).SetLightSessionData(data);
|
||||||
|
|
||||||
// Reply, if we need to.
|
// Reply, if we need to.
|
||||||
if (data[0] & KLightSession::ReplyFlag) {
|
if (data[0] & KLightSession::ReplyFlag) {
|
||||||
KScopedSchedulerLock sl(m_kernel);
|
KScopedSchedulerLock sl(kernel);
|
||||||
|
|
||||||
// Check that we're open.
|
// Check that we're open.
|
||||||
R_UNLESS(!m_parent->IsClientClosed(), ResultSessionClosed);
|
R_UNLESS(!m_parent->IsClientClosed(), ResultSessionClosed);
|
||||||
@@ -139,17 +136,16 @@ Result KLightServerSession::ReplyAndReceive(u32* data) {
|
|||||||
R_UNLESS(m_current_request != nullptr, ResultInvalidState);
|
R_UNLESS(m_current_request != nullptr, ResultInvalidState);
|
||||||
|
|
||||||
// Check that the server thread id is correct.
|
// 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 we can reply, do so.
|
||||||
if (!m_current_request->IsTerminationRequested()) {
|
if (!m_current_request->IsTerminationRequested()) {
|
||||||
std::memcpy(m_current_request->GetLightSessionData(),
|
std::memcpy(m_current_request->GetLightSessionData(), GetCurrentThread(kernel).GetLightSessionData(), KLightSession::DataSize);
|
||||||
GetCurrentThread(m_kernel).GetLightSessionData(), KLightSession::DataSize);
|
m_current_request->EndWait(kernel, ResultSuccess);
|
||||||
m_current_request->EndWait(ResultSuccess);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close our current request.
|
// Close our current request.
|
||||||
m_current_request->Close();
|
m_current_request->Close(kernel);
|
||||||
|
|
||||||
// Clear our current request.
|
// Clear our current request.
|
||||||
m_current_request = nullptr;
|
m_current_request = nullptr;
|
||||||
@@ -157,14 +153,13 @@ Result KLightServerSession::ReplyAndReceive(u32* data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the wait queue for our receive.
|
// Create the wait queue for our receive.
|
||||||
ThreadQueueImplForKLightServerSessionReceive wait_queue(m_kernel,
|
ThreadQueueImplForKLightServerSessionReceive wait_queue(kernel, std::addressof(m_server_thread));
|
||||||
std::addressof(m_server_thread));
|
|
||||||
|
|
||||||
// Receive.
|
// Receive.
|
||||||
while (true) {
|
while (true) {
|
||||||
// Try to receive a request.
|
// Try to receive a request.
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl(m_kernel);
|
KScopedSchedulerLock sl(kernel);
|
||||||
|
|
||||||
// Check that we aren't already receiving.
|
// Check that we aren't already receiving.
|
||||||
R_UNLESS(m_server_thread == nullptr, ResultInvalidState);
|
R_UNLESS(m_server_thread == nullptr, ResultInvalidState);
|
||||||
@@ -175,20 +170,19 @@ Result KLightServerSession::ReplyAndReceive(u32* data) {
|
|||||||
R_UNLESS(!m_parent->IsServerClosed(), ResultSessionClosed);
|
R_UNLESS(!m_parent->IsServerClosed(), ResultSessionClosed);
|
||||||
|
|
||||||
// Check that we're not terminating.
|
// Check that we're not terminating.
|
||||||
R_UNLESS(!GetCurrentThread(m_kernel).IsTerminationRequested(),
|
R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(), ResultTerminationRequested);
|
||||||
ResultTerminationRequested);
|
|
||||||
|
|
||||||
// If we have a request available, use it.
|
// If we have a request available, use it.
|
||||||
if (auto head = m_request_list.begin(); head != m_request_list.end()) {
|
if (auto head = m_request_list.begin(); head != m_request_list.end()) {
|
||||||
// Set our current request.
|
// Set our current request.
|
||||||
m_current_request = std::addressof(*head);
|
m_current_request = std::addressof(*head);
|
||||||
m_current_request->Open();
|
m_current_request->Open(kernel);
|
||||||
|
|
||||||
// Set our server thread id.
|
// 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.
|
// Copy the client request data.
|
||||||
std::memcpy(GetCurrentThread(m_kernel).GetLightSessionData(),
|
std::memcpy(GetCurrentThread(kernel).GetLightSessionData(),
|
||||||
m_current_request->GetLightSessionData(), KLightSession::DataSize);
|
m_current_request->GetLightSessionData(), KLightSession::DataSize);
|
||||||
|
|
||||||
// We successfully received.
|
// We successfully received.
|
||||||
@@ -198,51 +192,51 @@ Result KLightServerSession::ReplyAndReceive(u32* data) {
|
|||||||
// We need to wait for a request to come in.
|
// We need to wait for a request to come in.
|
||||||
|
|
||||||
// Check if we were cancelled.
|
// Check if we were cancelled.
|
||||||
if (GetCurrentThread(m_kernel).IsWaitCancelled()) {
|
if (GetCurrentThread(kernel).IsWaitCancelled()) {
|
||||||
GetCurrentThread(m_kernel).ClearWaitCancelled();
|
GetCurrentThread(kernel).ClearWaitCancelled();
|
||||||
R_THROW(ResultCancelled);
|
R_THROW(ResultCancelled);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark ourselves as cancellable.
|
// Mark ourselves as cancellable.
|
||||||
GetCurrentThread(m_kernel).SetCancellable();
|
GetCurrentThread(kernel).SetCancellable();
|
||||||
|
|
||||||
// Wait for a request to come in.
|
// Wait for a request to come in.
|
||||||
m_server_thread = GetCurrentThreadPointer(m_kernel);
|
m_server_thread = GetCurrentThreadPointer(kernel);
|
||||||
GetCurrentThread(m_kernel).SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::IPC);
|
GetCurrentThread(kernel).SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::IPC);
|
||||||
GetCurrentThread(m_kernel).BeginWait(std::addressof(wait_queue));
|
GetCurrentThread(kernel).BeginWait(kernel, std::addressof(wait_queue));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We waited to receive a request; if our wait failed, return the failing result.
|
// 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.
|
// Cleanup all pending requests.
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl(m_kernel);
|
KScopedSchedulerLock sl(kernel);
|
||||||
|
|
||||||
// Handle the current request.
|
// Handle the current request.
|
||||||
if (m_current_request != nullptr) {
|
if (m_current_request != nullptr) {
|
||||||
// Reply to the current request.
|
// Reply to the current request.
|
||||||
if (!m_current_request->IsTerminationRequested()) {
|
if (!m_current_request->IsTerminationRequested()) {
|
||||||
m_current_request->EndWait(ResultSessionClosed);
|
m_current_request->EndWait(kernel, ResultSessionClosed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear our current request.
|
// Clear our current request.
|
||||||
m_current_request->Close();
|
m_current_request->Close(kernel);
|
||||||
m_current_request = nullptr;
|
m_current_request = nullptr;
|
||||||
m_server_thread_id = InvalidThreadId;
|
m_server_thread_id = InvalidThreadId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reply to all other requests.
|
// Reply to all other requests.
|
||||||
for (auto& thread : m_request_list) {
|
for (auto& thread : m_request_list) {
|
||||||
thread.EndWait(ResultSessionClosed);
|
thread.EndWait(kernel, ResultSessionClosed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait up our server thread, if we have one.
|
// Wait up our server thread, if we have one.
|
||||||
if (m_server_thread != nullptr) {
|
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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
@@ -34,19 +34,19 @@ public:
|
|||||||
m_parent = parent;
|
m_parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Destroy() override;
|
virtual void Destroy(KernelCore& kernel) override;
|
||||||
|
|
||||||
constexpr const KLightSession* GetParent() const {
|
constexpr const KLightSession* GetParent() const {
|
||||||
return m_parent;
|
return m_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OnRequest(KThread* request_thread);
|
Result OnRequest(KernelCore& kernel, KThread* request_thread);
|
||||||
Result ReplyAndReceive(u32* data);
|
Result ReplyAndReceive(KernelCore& kernel, u32* data);
|
||||||
|
|
||||||
void OnClientClosed();
|
void OnClientClosed(KernelCore& kernel);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void CleanupRequests();
|
void CleanupRequests(KernelCore& kernel);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace 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-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -10,15 +13,18 @@
|
|||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
KLightSession::KLightSession(KernelCore& kernel)
|
KLightSession::KLightSession(KernelCore& kernel)
|
||||||
: KAutoObjectWithSlabHeapAndContainer(kernel), m_server(kernel), m_client(kernel) {}
|
: KAutoObjectWithSlabHeapAndContainer(kernel)
|
||||||
|
, m_server(kernel)
|
||||||
|
, m_client(kernel)
|
||||||
|
{}
|
||||||
KLightSession::~KLightSession() = default;
|
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.
|
// Increment reference count.
|
||||||
// Because reference count is one on creation, this will result
|
// Because reference count is one on creation, this will result
|
||||||
// in a reference count of two. Thus, when both server and client are closed
|
// in a reference count of two. Thus, when both server and client are closed
|
||||||
// this object will be destroyed.
|
// this object will be destroyed.
|
||||||
this->Open();
|
this->Open(kernel);
|
||||||
|
|
||||||
// Create our sub sessions.
|
// Create our sub sessions.
|
||||||
KAutoObject::Create(std::addressof(m_server));
|
KAutoObject::Create(std::addressof(m_server));
|
||||||
@@ -33,49 +39,47 @@ void KLightSession::Initialize(KClientPort* client_port, uintptr_t name) {
|
|||||||
m_name = name;
|
m_name = name;
|
||||||
|
|
||||||
// Set our owner process.
|
// Set our owner process.
|
||||||
m_process = GetCurrentProcessPointer(m_kernel);
|
m_process = GetCurrentProcessPointer(kernel);
|
||||||
m_process->Open();
|
m_process->Open(kernel);
|
||||||
|
|
||||||
// Set our port.
|
// Set our port.
|
||||||
m_port = client_port;
|
m_port = client_port;
|
||||||
if (m_port != nullptr) {
|
if (m_port != nullptr) {
|
||||||
m_port->Open();
|
m_port->Open(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark initialized.
|
// Mark initialized.
|
||||||
m_initialized = true;
|
m_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KLightSession::Finalize() {
|
void KLightSession::Finalize(KernelCore& kernel) {
|
||||||
if (m_port != nullptr) {
|
if (m_port != nullptr) {
|
||||||
m_port->OnSessionFinalized();
|
m_port->OnSessionFinalized(kernel);
|
||||||
m_port->Close();
|
m_port->Close(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KLightSession::OnServerClosed() {
|
void KLightSession::OnServerClosed(KernelCore& kernel) {
|
||||||
if (m_state == State::Normal) {
|
if (m_state == State::Normal) {
|
||||||
m_state = State::ServerClosed;
|
m_state = State::ServerClosed;
|
||||||
m_client.OnServerClosed();
|
m_client.OnServerClosed(kernel);
|
||||||
}
|
}
|
||||||
|
this->Close(kernel);
|
||||||
this->Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KLightSession::OnClientClosed() {
|
void KLightSession::OnClientClosed(KernelCore& kernel) {
|
||||||
if (m_state == State::Normal) {
|
if (m_state == State::Normal) {
|
||||||
m_state = State::ClientClosed;
|
m_state = State::ClientClosed;
|
||||||
m_server.OnClientClosed();
|
m_server.OnClientClosed(kernel);
|
||||||
}
|
}
|
||||||
|
this->Close(kernel);
|
||||||
this->Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KLightSession::PostDestroy(uintptr_t arg) {
|
void KLightSession::PostDestroy(KernelCore& kernel, uintptr_t arg) {
|
||||||
// Release the session count resource the owner process holds.
|
// Release the session count resource the owner process holds.
|
||||||
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
||||||
owner->ReleaseResource(Svc::LimitableResource::SessionCountMax, 1);
|
owner->ReleaseResource(kernel, Svc::LimitableResource::SessionCountMax, 1);
|
||||||
owner->Close();
|
owner->Close(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace 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-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -43,20 +46,20 @@ public:
|
|||||||
explicit KLightSession(KernelCore& kernel);
|
explicit KLightSession(KernelCore& kernel);
|
||||||
~KLightSession();
|
~KLightSession();
|
||||||
|
|
||||||
void Initialize(KClientPort* client_port, uintptr_t name);
|
void Initialize(KernelCore& kernel, KClientPort* client_port, uintptr_t name);
|
||||||
void Finalize() override;
|
void Finalize(KernelCore& kernel) override;
|
||||||
|
|
||||||
bool IsInitialized() const override {
|
bool IsInitialized() const override {
|
||||||
return m_initialized;
|
return m_initialized;
|
||||||
}
|
}
|
||||||
uintptr_t GetPostDestroyArgument() const override {
|
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 OnServerClosed(KernelCore& kernel);
|
||||||
void OnClientClosed();
|
void OnClientClosed(KernelCore& kernel);
|
||||||
|
|
||||||
bool IsServerClosed() const {
|
bool IsServerClosed() const {
|
||||||
return m_state != State::Normal;
|
return m_state != State::Normal;
|
||||||
@@ -65,8 +68,8 @@ public:
|
|||||||
return m_state != State::Normal;
|
return m_state != State::Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OnRequest(KThread* request_thread) {
|
Result OnRequest(KernelCore& kernel, KThread* request_thread) {
|
||||||
R_RETURN(m_server.OnRequest(request_thread));
|
R_RETURN(m_server.OnRequest(kernel, request_thread));
|
||||||
}
|
}
|
||||||
|
|
||||||
KLightClientSession& GetClientSession() {
|
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-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// 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(KernelCore& kernel) : m_object_list_lock{kernel} {}
|
||||||
KObjectNameGlobalData::~KObjectNameGlobalData() = default;
|
KObjectNameGlobalData::~KObjectNameGlobalData() = default;
|
||||||
|
|
||||||
void KObjectName::Initialize(KAutoObject* obj, const char* name) {
|
void KObjectName::Initialize(KernelCore& kernel, KAutoObject* obj, const char* name) {
|
||||||
// Set member variables.
|
// Set member variables.
|
||||||
m_object = obj;
|
m_object = obj;
|
||||||
std::strncpy(m_name.data(), name, sizeof(m_name) - 1);
|
std::strncpy(m_name.data(), name, sizeof(m_name) - 1);
|
||||||
m_name[sizeof(m_name) - 1] = '\x00';
|
m_name[sizeof(m_name) - 1] = '\x00';
|
||||||
|
|
||||||
// Open a reference to the object we hold.
|
// Open a reference to the object we hold.
|
||||||
m_object->Open();
|
m_object->Open(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KObjectName::MatchesName(const char* name) const {
|
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);
|
R_UNLESS(new_name != nullptr, ResultOutOfResource);
|
||||||
|
|
||||||
// Initialize the new name.
|
// Initialize the new name.
|
||||||
new_name->Initialize(obj, name);
|
new_name->Initialize(kernel, obj, name);
|
||||||
|
|
||||||
// Check if there's an existing 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.
|
// The object already exists, which is an error condition. Perform cleanup.
|
||||||
obj->Close();
|
obj->Close(kernel);
|
||||||
KObjectName::Free(kernel, new_name);
|
KObjectName::Free(kernel, new_name);
|
||||||
R_THROW(ResultInvalidState);
|
R_THROW(ResultInvalidState);
|
||||||
}
|
}
|
||||||
@@ -63,7 +66,7 @@ Result KObjectName::Delete(KernelCore& kernel, KAutoObject* obj, const char* com
|
|||||||
for (auto& name : gd.GetObjectList()) {
|
for (auto& name : gd.GetObjectList()) {
|
||||||
if (name.MatchesName(compare_name) && obj == name.GetObject()) {
|
if (name.MatchesName(compare_name) && obj == name.GetObject()) {
|
||||||
// We found a match, clean up its resources.
|
// We found a match, clean up its resources.
|
||||||
obj->Close();
|
obj->Close(kernel);
|
||||||
gd.GetObjectList().erase(gd.GetObjectList().iterator_to(name));
|
gd.GetObjectList().erase(gd.GetObjectList().iterator_to(name));
|
||||||
KObjectName::Free(kernel, std::addressof(name));
|
KObjectName::Free(kernel, std::addressof(name));
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
@@ -89,14 +92,12 @@ KScopedAutoObject<KAutoObject> KObjectName::FindImpl(KernelCore& kernel, const c
|
|||||||
KObjectNameGlobalData& gd{kernel.ObjectNameGlobalData()};
|
KObjectNameGlobalData& gd{kernel.ObjectNameGlobalData()};
|
||||||
|
|
||||||
// Try to find a matching object in the global list.
|
// Try to find a matching object in the global list.
|
||||||
for (const auto& name : gd.GetObjectList()) {
|
for (const auto& name : gd.GetObjectList())
|
||||||
if (name.MatchesName(compare_name)) {
|
if (name.MatchesName(compare_name))
|
||||||
return name.GetObject();
|
return {kernel, name.GetObject()};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// There's no matching entry in the list.
|
// There's no matching entry in the list.
|
||||||
return nullptr;
|
return {kernel, nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace 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-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -41,7 +44,7 @@ public:
|
|||||||
R_UNLESS(derived != nullptr, ResultNotFound);
|
R_UNLESS(derived != nullptr, ResultNotFound);
|
||||||
|
|
||||||
// Check that the object is closed.
|
// Check that the object is closed.
|
||||||
R_UNLESS(derived->IsServerClosed(), ResultInvalidState);
|
R_UNLESS(derived->IsServerClosed(kernel), ResultInvalidState);
|
||||||
|
|
||||||
R_RETURN(Delete(kernel, obj.GetPointerUnsafe(), name));
|
R_RETURN(Delete(kernel, obj.GetPointerUnsafe(), name));
|
||||||
}
|
}
|
||||||
@@ -49,13 +52,13 @@ public:
|
|||||||
template <typename Derived>
|
template <typename Derived>
|
||||||
requires(std::derived_from<Derived, KAutoObject>)
|
requires(std::derived_from<Derived, KAutoObject>)
|
||||||
static KScopedAutoObject<Derived> Find(KernelCore& kernel, const char* name) {
|
static KScopedAutoObject<Derived> Find(KernelCore& kernel, const char* name) {
|
||||||
return Find(kernel, name);
|
return {kernel, static_cast<Derived*>(Find(kernel, name).GetPointerUnsafe())};
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static KScopedAutoObject<KAutoObject> FindImpl(KernelCore& kernel, const char* name);
|
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;
|
bool MatchesName(const char* name) const;
|
||||||
KAutoObject* GetObject() const {
|
KAutoObject* GetObject() const {
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -21,8 +24,8 @@ void KPageGroup::Finalize() {
|
|||||||
m_last_block = nullptr;
|
m_last_block = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KPageGroup::CloseAndReset() {
|
void KPageGroup::CloseAndReset(KernelCore& kernel) {
|
||||||
auto& mm = m_kernel.MemoryManager();
|
auto& mm = kernel.MemoryManager();
|
||||||
|
|
||||||
KBlockInfo* cur = m_first_block;
|
KBlockInfo* cur = m_first_block;
|
||||||
while (cur != nullptr) {
|
while (cur != nullptr) {
|
||||||
@@ -76,28 +79,22 @@ Result KPageGroup::AddBlock(KPhysicalAddress addr, size_t num_pages) {
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KPageGroup::Open() const {
|
void KPageGroup::Open(KernelCore& kernel) const {
|
||||||
auto& mm = m_kernel.MemoryManager();
|
auto& mm = kernel.MemoryManager();
|
||||||
|
for (const auto& it : *this)
|
||||||
for (const auto& it : *this) {
|
|
||||||
mm.Open(it.GetAddress(), it.GetNumPages());
|
mm.Open(it.GetAddress(), it.GetNumPages());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KPageGroup::OpenFirst() const {
|
void KPageGroup::OpenFirst(KernelCore& kernel) const {
|
||||||
auto& mm = m_kernel.MemoryManager();
|
auto& mm = kernel.MemoryManager();
|
||||||
|
for (const auto& it : *this)
|
||||||
for (const auto& it : *this) {
|
|
||||||
mm.OpenFirst(it.GetAddress(), it.GetNumPages());
|
mm.OpenFirst(it.GetAddress(), it.GetNumPages());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KPageGroup::Close() const {
|
void KPageGroup::Close(KernelCore& kernel) const {
|
||||||
auto& mm = m_kernel.MemoryManager();
|
auto& mm = kernel.MemoryManager();
|
||||||
|
for (const auto& it : *this)
|
||||||
for (const auto& it : *this) {
|
|
||||||
mm.Close(it.GetAddress(), it.GetNumPages());
|
mm.Close(it.GetAddress(), it.GetNumPages());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KPageGroup::IsEquivalentTo(const KPageGroup& rhs) const {
|
bool KPageGroup::IsEquivalentTo(const KPageGroup& rhs) const {
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -139,12 +142,12 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
explicit KPageGroup(KernelCore& kernel, KBlockInfoManager* m)
|
explicit KPageGroup(KernelCore& kernel, KBlockInfoManager* m)
|
||||||
: m_kernel{kernel}, m_manager{m} {}
|
: m_manager{m} {}
|
||||||
~KPageGroup() {
|
~KPageGroup() {
|
||||||
this->Finalize();
|
this->Finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloseAndReset();
|
void CloseAndReset(KernelCore& kernel);
|
||||||
void Finalize();
|
void Finalize();
|
||||||
|
|
||||||
Iterator begin() const {
|
Iterator begin() const {
|
||||||
@@ -158,9 +161,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result AddBlock(KPhysicalAddress addr, size_t num_pages);
|
Result AddBlock(KPhysicalAddress addr, size_t num_pages);
|
||||||
void Open() const;
|
void Open(KernelCore& kernel) const;
|
||||||
void OpenFirst() const;
|
void OpenFirst(KernelCore& kernel) const;
|
||||||
void Close() const;
|
void Close(KernelCore& kernel) const;
|
||||||
|
|
||||||
size_t GetNumPages() const;
|
size_t GetNumPages() const;
|
||||||
|
|
||||||
@@ -175,7 +178,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KernelCore& m_kernel;
|
|
||||||
KBlockInfo* m_first_block{};
|
KBlockInfo* m_first_block{};
|
||||||
KBlockInfo* m_last_block{};
|
KBlockInfo* m_last_block{};
|
||||||
KBlockInfoManager* m_manager{};
|
KBlockInfoManager* m_manager{};
|
||||||
@@ -183,21 +185,24 @@ private:
|
|||||||
|
|
||||||
class KScopedPageGroup {
|
class KScopedPageGroup {
|
||||||
public:
|
public:
|
||||||
explicit KScopedPageGroup(const KPageGroup* gp, bool not_first = true) : m_pg(gp) {
|
explicit KScopedPageGroup(KernelCore& kernel, const KPageGroup* gp, bool not_first = true)
|
||||||
|
: m_kernel{kernel}
|
||||||
|
, m_pg{gp}
|
||||||
|
{
|
||||||
if (m_pg) {
|
if (m_pg) {
|
||||||
if (not_first) {
|
if (not_first) {
|
||||||
m_pg->Open();
|
m_pg->Open(kernel);
|
||||||
} else {
|
} else {
|
||||||
m_pg->OpenFirst();
|
m_pg->OpenFirst(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
explicit KScopedPageGroup(const KPageGroup& gp, bool not_first = true)
|
explicit KScopedPageGroup(KernelCore& kernel, const KPageGroup& gp, bool not_first = true)
|
||||||
: KScopedPageGroup(std::addressof(gp), not_first) {}
|
: KScopedPageGroup(kernel, std::addressof(gp), not_first) {}
|
||||||
|
|
||||||
~KScopedPageGroup() {
|
~KScopedPageGroup() {
|
||||||
if (m_pg) {
|
if (m_pg)
|
||||||
m_pg->Close();
|
m_pg->Close(m_kernel);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CancelClose() {
|
void CancelClose() {
|
||||||
@@ -205,6 +210,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
KernelCore& m_kernel;
|
||||||
const KPageGroup* m_pg{};
|
const KPageGroup* m_pg{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -127,22 +127,22 @@ constexpr Common::MemoryPermission ConvertToMemoryPermission(KMemoryPermission p
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void KPageTableBase::MemoryRange::Open() {
|
void KPageTableBase::MemoryRange::Open(KernelCore& kernel) {
|
||||||
// If the range contains heap pages, open them.
|
// If the range contains heap pages, open them.
|
||||||
if (this->IsHeap()) {
|
if (this->IsHeap()) {
|
||||||
m_kernel.MemoryManager().Open(this->GetAddress(), this->GetSize() / PageSize);
|
kernel.MemoryManager().Open(this->GetAddress(), this->GetSize() / PageSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KPageTableBase::MemoryRange::Close() {
|
void KPageTableBase::MemoryRange::Close(KernelCore& kernel) {
|
||||||
// If the range contains heap pages, close them.
|
// If the range contains heap pages, close them.
|
||||||
if (this->IsHeap()) {
|
if (this->IsHeap()) {
|
||||||
m_kernel.MemoryManager().Close(this->GetAddress(), this->GetSize() / PageSize);
|
kernel.MemoryManager().Close(this->GetAddress(), this->GetSize() / PageSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KPageTableBase::KPageTableBase(KernelCore& kernel)
|
KPageTableBase::KPageTableBase(KernelCore& kernel)
|
||||||
: m_kernel(kernel), m_system(kernel.System()), m_general_lock(kernel),
|
: m_system(kernel.System()), m_general_lock(kernel),
|
||||||
m_map_physical_memory_lock(kernel), m_device_map_lock(kernel) {}
|
m_map_physical_memory_lock(kernel), m_device_map_lock(kernel) {}
|
||||||
KPageTableBase::~KPageTableBase() = default;
|
KPageTableBase::~KPageTableBase() = default;
|
||||||
|
|
||||||
@@ -177,9 +177,9 @@ Result KPageTableBase::InitializeForKernel(bool is_64_bit, KVirtualAddress start
|
|||||||
m_mapped_ipc_server_memory = 0;
|
m_mapped_ipc_server_memory = 0;
|
||||||
|
|
||||||
m_memory_block_slab_manager =
|
m_memory_block_slab_manager =
|
||||||
m_kernel.GetSystemSystemResource().GetMemoryBlockSlabManagerPointer();
|
m_system.Kernel().GetSystemSystemResource().GetMemoryBlockSlabManagerPointer();
|
||||||
m_block_info_manager = m_kernel.GetSystemSystemResource().GetBlockInfoManagerPointer();
|
m_block_info_manager = m_system.Kernel().GetSystemSystemResource().GetBlockInfoManagerPointer();
|
||||||
m_resource_limit = m_kernel.GetSystemResourceLimit();
|
m_resource_limit = m_system.Kernel().GetSystemResourceLimit();
|
||||||
|
|
||||||
m_allocate_option = KMemoryManager::EncodeOption(KMemoryManager::Pool::System,
|
m_allocate_option = KMemoryManager::EncodeOption(KMemoryManager::Pool::System,
|
||||||
KMemoryManager::Direction::FromFront);
|
KMemoryManager::Direction::FromFront);
|
||||||
@@ -469,11 +469,11 @@ void KPageTableBase::Finalize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get physical pages.
|
// Get physical pages.
|
||||||
KPageGroup pg(m_kernel, m_block_info_manager);
|
KPageGroup pg(m_system.Kernel(), m_block_info_manager);
|
||||||
this->MakePageGroup(pg, addr, size / PageSize);
|
this->MakePageGroup(pg, addr, size / PageSize);
|
||||||
|
|
||||||
// Free the pages.
|
// Free the pages.
|
||||||
pg.CloseAndReset();
|
pg.CloseAndReset(m_system.Kernel());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Finalize memory blocks.
|
// Finalize memory blocks.
|
||||||
@@ -490,16 +490,16 @@ void KPageTableBase::Finalize() {
|
|||||||
// Release any insecure mapped memory.
|
// Release any insecure mapped memory.
|
||||||
if (m_mapped_insecure_memory) {
|
if (m_mapped_insecure_memory) {
|
||||||
if (auto* const insecure_resource_limit =
|
if (auto* const insecure_resource_limit =
|
||||||
KSystemControl::GetInsecureMemoryResourceLimit(m_kernel);
|
KSystemControl::GetInsecureMemoryResourceLimit(m_system.Kernel());
|
||||||
insecure_resource_limit != nullptr) {
|
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);
|
m_mapped_insecure_memory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release any ipc server memory.
|
// Release any ipc server memory.
|
||||||
if (m_mapped_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);
|
m_mapped_ipc_server_memory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -833,7 +833,7 @@ Result KPageTableBase::LockMemoryAndOpen(KPageGroup* out_pg, KPhysicalAddress* o
|
|||||||
|
|
||||||
// If we have an output group, open.
|
// If we have an output group, open.
|
||||||
if (out_pg) {
|
if (out_pg) {
|
||||||
out_pg->Open();
|
out_pg->Open(m_system.Kernel());
|
||||||
}
|
}
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
@@ -1041,7 +1041,7 @@ Result KPageTableBase::MapMemory(KProcessAddress dst_address, KProcessAddress sr
|
|||||||
const size_t num_pages = size / PageSize;
|
const size_t num_pages = size / PageSize;
|
||||||
|
|
||||||
// Create page groups for the memory being unmapped.
|
// Create page groups for the memory being unmapped.
|
||||||
KPageGroup pg(m_kernel, m_block_info_manager);
|
KPageGroup pg(m_system.Kernel(), m_block_info_manager);
|
||||||
|
|
||||||
// Create the page group representing the source.
|
// Create the page group representing the source.
|
||||||
R_TRY(this->MakePageGroup(pg, src_address, num_pages));
|
R_TRY(this->MakePageGroup(pg, src_address, num_pages));
|
||||||
@@ -1129,7 +1129,7 @@ Result KPageTableBase::UnmapMemory(KProcessAddress dst_address, KProcessAddress
|
|||||||
const size_t num_pages = size / PageSize;
|
const size_t num_pages = size / PageSize;
|
||||||
|
|
||||||
// Create page groups for the memory being unmapped.
|
// Create page groups for the memory being unmapped.
|
||||||
KPageGroup pg(m_kernel, m_block_info_manager);
|
KPageGroup pg(m_system.Kernel(), m_block_info_manager);
|
||||||
|
|
||||||
// Create the page group representing the destination.
|
// Create the page group representing the destination.
|
||||||
R_TRY(this->MakePageGroup(pg, dst_address, num_pages));
|
R_TRY(this->MakePageGroup(pg, dst_address, num_pages));
|
||||||
@@ -1217,7 +1217,7 @@ Result KPageTableBase::MapCodeMemory(KProcessAddress dst_address, KProcessAddres
|
|||||||
const size_t num_pages = size / PageSize;
|
const size_t num_pages = size / PageSize;
|
||||||
|
|
||||||
// Create page groups for the memory being unmapped.
|
// Create page groups for the memory being unmapped.
|
||||||
KPageGroup pg(m_kernel, m_block_info_manager);
|
KPageGroup pg(m_system.Kernel(), m_block_info_manager);
|
||||||
|
|
||||||
// Create the page group representing the source.
|
// Create the page group representing the source.
|
||||||
R_TRY(this->MakePageGroup(pg, src_address, num_pages));
|
R_TRY(this->MakePageGroup(pg, src_address, num_pages));
|
||||||
@@ -1312,7 +1312,7 @@ Result KPageTableBase::UnmapCodeMemory(KProcessAddress dst_address, KProcessAddr
|
|||||||
bool reprotected_pages = false;
|
bool reprotected_pages = false;
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
if (reprotected_pages && any_code_pages) {
|
if (reprotected_pages && any_code_pages) {
|
||||||
InvalidateInstructionCache(m_kernel, this, dst_address, size);
|
InvalidateInstructionCache(m_system.Kernel(), this, dst_address, size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1322,7 +1322,7 @@ Result KPageTableBase::UnmapCodeMemory(KProcessAddress dst_address, KProcessAddr
|
|||||||
const size_t num_pages = size / PageSize;
|
const size_t num_pages = size / PageSize;
|
||||||
|
|
||||||
// Create page groups for the memory being unmapped.
|
// Create page groups for the memory being unmapped.
|
||||||
KPageGroup pg(m_kernel, m_block_info_manager);
|
KPageGroup pg(m_system.Kernel(), m_block_info_manager);
|
||||||
|
|
||||||
// Create the page group representing the destination.
|
// Create the page group representing the destination.
|
||||||
R_TRY(this->MakePageGroup(pg, dst_address, num_pages));
|
R_TRY(this->MakePageGroup(pg, dst_address, num_pages));
|
||||||
@@ -1383,19 +1383,19 @@ Result KPageTableBase::UnmapCodeMemory(KProcessAddress dst_address, KProcessAddr
|
|||||||
|
|
||||||
Result KPageTableBase::MapInsecureMemory(KProcessAddress address, size_t size) {
|
Result KPageTableBase::MapInsecureMemory(KProcessAddress address, size_t size) {
|
||||||
// Get the insecure memory resource limit and pool.
|
// Get the insecure memory resource limit and pool.
|
||||||
auto* const insecure_resource_limit = KSystemControl::GetInsecureMemoryResourceLimit(m_kernel);
|
auto* const insecure_resource_limit = KSystemControl::GetInsecureMemoryResourceLimit(m_system.Kernel());
|
||||||
const auto insecure_pool =
|
const auto insecure_pool =
|
||||||
static_cast<KMemoryManager::Pool>(KSystemControl::GetInsecureMemoryPool());
|
static_cast<KMemoryManager::Pool>(KSystemControl::GetInsecureMemoryPool());
|
||||||
|
|
||||||
// Reserve the insecure memory.
|
// Reserve the insecure memory.
|
||||||
// NOTE: ResultOutOfMemory is returned here instead of the usual LimitReached.
|
// 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);
|
Svc::LimitableResource::PhysicalMemoryMax, size);
|
||||||
R_UNLESS(memory_reservation.Succeeded(), ResultOutOfMemory);
|
R_UNLESS(memory_reservation.Succeeded(), ResultOutOfMemory);
|
||||||
|
|
||||||
// Allocate pages for the insecure memory.
|
// Allocate pages for the insecure memory.
|
||||||
KPageGroup pg(m_kernel, m_block_info_manager);
|
KPageGroup pg(m_system.Kernel(), m_block_info_manager);
|
||||||
R_TRY(m_kernel.MemoryManager().AllocateAndOpen(
|
R_TRY(m_system.Kernel().MemoryManager().AllocateAndOpen(
|
||||||
std::addressof(pg), size / PageSize,
|
std::addressof(pg), size / PageSize,
|
||||||
KMemoryManager::EncodeOption(insecure_pool, KMemoryManager::Direction::FromFront)));
|
KMemoryManager::EncodeOption(insecure_pool, KMemoryManager::Direction::FromFront)));
|
||||||
|
|
||||||
@@ -1403,7 +1403,7 @@ Result KPageTableBase::MapInsecureMemory(KProcessAddress address, size_t size) {
|
|||||||
// If the mapping succeeds, each page will gain an extra reference, otherwise they will be freed
|
// If the mapping succeeds, each page will gain an extra reference, otherwise they will be freed
|
||||||
// automatically.
|
// automatically.
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
pg.Close();
|
pg.Close(m_system.Kernel());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Clear all the newly allocated pages.
|
// Clear all the newly allocated pages.
|
||||||
@@ -1491,9 +1491,9 @@ Result KPageTableBase::UnmapInsecureMemory(KProcessAddress address, size_t size)
|
|||||||
|
|
||||||
// Release the insecure memory from the insecure limit.
|
// Release the insecure memory from the insecure limit.
|
||||||
if (auto* const insecure_resource_limit =
|
if (auto* const insecure_resource_limit =
|
||||||
KSystemControl::GetInsecureMemoryResourceLimit(m_kernel);
|
KSystemControl::GetInsecureMemoryResourceLimit(m_system.Kernel());
|
||||||
insecure_resource_limit != nullptr) {
|
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();
|
R_SUCCEED();
|
||||||
@@ -1603,15 +1603,15 @@ Result KPageTableBase::AllocateAndMapPagesImpl(PageLinkedList* page_list, KProce
|
|||||||
ASSERT(this->IsLockedByCurrentThread());
|
ASSERT(this->IsLockedByCurrentThread());
|
||||||
|
|
||||||
// Create a page group to hold the pages we allocate.
|
// Create a page group to hold the pages we allocate.
|
||||||
KPageGroup pg(m_kernel, m_block_info_manager);
|
KPageGroup pg(m_system.Kernel(), m_block_info_manager);
|
||||||
|
|
||||||
// Allocate the pages.
|
// Allocate the pages.
|
||||||
R_TRY(
|
R_TRY(
|
||||||
m_kernel.MemoryManager().AllocateAndOpen(std::addressof(pg), num_pages, m_allocate_option));
|
m_system.Kernel().MemoryManager().AllocateAndOpen(std::addressof(pg), num_pages, m_allocate_option));
|
||||||
|
|
||||||
// Ensure that the page group is closed when we're done working with it.
|
// Ensure that the page group is closed when we're done working with it.
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
pg.Close();
|
pg.Close(m_system.Kernel());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Clear all pages.
|
// Clear all pages.
|
||||||
@@ -1992,7 +1992,7 @@ Result KPageTableBase::SetProcessMemoryPermission(KProcessAddress addr, size_t s
|
|||||||
KMemoryAttribute::All, KMemoryAttribute::None));
|
KMemoryAttribute::All, KMemoryAttribute::None));
|
||||||
|
|
||||||
// Make a new page group for the region.
|
// Make a new page group for the region.
|
||||||
KPageGroup pg(m_kernel, m_block_info_manager);
|
KPageGroup pg(m_system.Kernel(), m_block_info_manager);
|
||||||
|
|
||||||
// Determine new perm/state.
|
// Determine new perm/state.
|
||||||
const KMemoryPermission new_perm = ConvertToKMemoryPermission(svc_perm);
|
const KMemoryPermission new_perm = ConvertToKMemoryPermission(svc_perm);
|
||||||
@@ -2048,9 +2048,9 @@ Result KPageTableBase::SetProcessMemoryPermission(KProcessAddress addr, size_t s
|
|||||||
// Ensure cache coherency, if we're setting pages as executable.
|
// Ensure cache coherency, if we're setting pages as executable.
|
||||||
if (is_x) {
|
if (is_x) {
|
||||||
for (const auto& block : pg) {
|
for (const auto& block : pg) {
|
||||||
StoreDataCache(GetHeapVirtualPointer(m_kernel, block.GetAddress()), block.GetSize());
|
StoreDataCache(GetHeapVirtualPointer(m_system.Kernel(), block.GetAddress()), block.GetSize());
|
||||||
}
|
}
|
||||||
InvalidateInstructionCache(m_kernel, this, addr, size);
|
InvalidateInstructionCache(m_system.Kernel(), this, addr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
@@ -2158,7 +2158,7 @@ Result KPageTableBase::SetHeapSize(KProcessAddress* out, size_t size) {
|
|||||||
false, unmap_properties, OperationType::Unmap, false));
|
false, unmap_properties, OperationType::Unmap, false));
|
||||||
|
|
||||||
// Release the memory from the resource limit.
|
// 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);
|
num_pages * PageSize);
|
||||||
|
|
||||||
// Apply the memory block update.
|
// Apply the memory block update.
|
||||||
@@ -2188,20 +2188,20 @@ Result KPageTableBase::SetHeapSize(KProcessAddress* out, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reserve memory for the heap extension.
|
// Reserve memory for the heap extension.
|
||||||
KScopedResourceReservation memory_reservation(
|
KScopedResourceReservation memory_reservation(m_system.Kernel(),
|
||||||
m_resource_limit, Svc::LimitableResource::PhysicalMemoryMax, allocation_size);
|
m_resource_limit, Svc::LimitableResource::PhysicalMemoryMax, allocation_size);
|
||||||
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
||||||
|
|
||||||
// Allocate pages for the heap extension.
|
// Allocate pages for the heap extension.
|
||||||
KPageGroup pg(m_kernel, m_block_info_manager);
|
KPageGroup pg(m_system.Kernel(), m_block_info_manager);
|
||||||
R_TRY(m_kernel.MemoryManager().AllocateAndOpen(std::addressof(pg), allocation_size / PageSize,
|
R_TRY(m_system.Kernel().MemoryManager().AllocateAndOpen(std::addressof(pg), allocation_size / PageSize,
|
||||||
m_allocate_option));
|
m_allocate_option));
|
||||||
|
|
||||||
// Close the opened pages when we're done with them.
|
// Close the opened pages when we're done with them.
|
||||||
// If the mapping succeeds, each page will gain an extra reference, otherwise they will be freed
|
// If the mapping succeeds, each page will gain an extra reference, otherwise they will be freed
|
||||||
// automatically.
|
// automatically.
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
pg.Close();
|
pg.Close(m_system.Kernel());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Clear all the newly allocated pages.
|
// Clear all the newly allocated pages.
|
||||||
@@ -2406,7 +2406,7 @@ Result KPageTableBase::MapIoImpl(KProcessAddress* out, PageLinkedList* page_list
|
|||||||
ASSERT(this->CanContain(region_start, region_size, state));
|
ASSERT(this->CanContain(region_start, region_size, state));
|
||||||
|
|
||||||
// Locate the memory region.
|
// Locate the memory region.
|
||||||
const KMemoryRegion* region = KMemoryLayout::Find(m_kernel.MemoryLayout(), phys_addr);
|
const KMemoryRegion* region = KMemoryLayout::Find(m_system.Kernel().MemoryLayout(), phys_addr);
|
||||||
R_UNLESS(region != nullptr, ResultInvalidAddress);
|
R_UNLESS(region != nullptr, ResultInvalidAddress);
|
||||||
|
|
||||||
ASSERT(region->Contains(GetInteger(phys_addr)));
|
ASSERT(region->Contains(GetInteger(phys_addr)));
|
||||||
@@ -2640,7 +2640,7 @@ Result KPageTableBase::MapStatic(KPhysicalAddress phys_addr, size_t size, KMemor
|
|||||||
const size_t region_num_pages = region_size / PageSize;
|
const size_t region_num_pages = region_size / PageSize;
|
||||||
|
|
||||||
// Locate the memory region.
|
// Locate the memory region.
|
||||||
const KMemoryRegion* region = KMemoryLayout::Find(m_kernel.MemoryLayout(), phys_addr);
|
const KMemoryRegion* region = KMemoryLayout::Find(m_system.Kernel().MemoryLayout(), phys_addr);
|
||||||
R_UNLESS(region != nullptr, ResultInvalidAddress);
|
R_UNLESS(region != nullptr, ResultInvalidAddress);
|
||||||
|
|
||||||
ASSERT(region->Contains(GetInteger(phys_addr)));
|
ASSERT(region->Contains(GetInteger(phys_addr)));
|
||||||
@@ -2707,7 +2707,7 @@ Result KPageTableBase::MapStatic(KPhysicalAddress phys_addr, size_t size, KMemor
|
|||||||
Result KPageTableBase::MapRegion(KMemoryRegionType region_type, KMemoryPermission perm) {
|
Result KPageTableBase::MapRegion(KMemoryRegionType region_type, KMemoryPermission perm) {
|
||||||
// Get the memory region.
|
// Get the memory region.
|
||||||
const KMemoryRegion* region =
|
const KMemoryRegion* region =
|
||||||
m_kernel.MemoryLayout().GetPhysicalMemoryRegionTree().FindFirstDerived(region_type);
|
m_system.Kernel().MemoryLayout().GetPhysicalMemoryRegionTree().FindFirstDerived(region_type);
|
||||||
R_UNLESS(region != nullptr, ResultOutOfRange);
|
R_UNLESS(region != nullptr, ResultOutOfRange);
|
||||||
|
|
||||||
// Check that the region is valid.
|
// Check that the region is valid.
|
||||||
@@ -3004,7 +3004,7 @@ Result KPageTableBase::MakeAndOpenPageGroup(KPageGroup* out, KProcessAddress add
|
|||||||
R_TRY(this->MakePageGroup(*out, address, num_pages));
|
R_TRY(this->MakePageGroup(*out, address, num_pages));
|
||||||
|
|
||||||
// Open a new reference to the pages in the group.
|
// Open a new reference to the pages in the group.
|
||||||
out->Open();
|
out->Open(m_system.Kernel());
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
@@ -3051,7 +3051,7 @@ Result KPageTableBase::InvalidateProcessDataCache(KProcessAddress address, size_
|
|||||||
// Invalidate the block.
|
// Invalidate the block.
|
||||||
if (cur_size > 0) {
|
if (cur_size > 0) {
|
||||||
// NOTE: Nintendo does not check the result of invalidation.
|
// NOTE: Nintendo does not check the result of invalidation.
|
||||||
InvalidateDataCache(GetLinearMappedVirtualPointer(m_kernel, cur_addr), cur_size);
|
InvalidateDataCache(GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr), cur_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance.
|
// Advance.
|
||||||
@@ -3075,7 +3075,7 @@ Result KPageTableBase::InvalidateProcessDataCache(KProcessAddress address, size_
|
|||||||
// Invalidate the last block.
|
// Invalidate the last block.
|
||||||
if (cur_size > 0) {
|
if (cur_size > 0) {
|
||||||
// NOTE: Nintendo does not check the result of invalidation.
|
// NOTE: Nintendo does not check the result of invalidation.
|
||||||
InvalidateDataCache(GetLinearMappedVirtualPointer(m_kernel, cur_addr), cur_size);
|
InvalidateDataCache(GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr), cur_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
@@ -3083,7 +3083,7 @@ Result KPageTableBase::InvalidateProcessDataCache(KProcessAddress address, size_
|
|||||||
|
|
||||||
Result KPageTableBase::InvalidateCurrentProcessDataCache(KProcessAddress address, size_t size) {
|
Result KPageTableBase::InvalidateCurrentProcessDataCache(KProcessAddress address, size_t size) {
|
||||||
// Check pre-condition: this is being called on the current process.
|
// Check pre-condition: this is being called on the current process.
|
||||||
ASSERT(this == std::addressof(GetCurrentProcess(m_kernel).GetPageTable().GetBasePageTable()));
|
ASSERT(this == std::addressof(GetCurrentProcess(m_system.Kernel()).GetPageTable().GetBasePageTable()));
|
||||||
|
|
||||||
// Check that the region is in range.
|
// Check that the region is in range.
|
||||||
R_UNLESS(this->Contains(address, size), ResultInvalidCurrentMemory);
|
R_UNLESS(this->Contains(address, size), ResultInvalidCurrentMemory);
|
||||||
@@ -3144,7 +3144,7 @@ Result KPageTableBase::ReadDebugMemory(KProcessAddress dst_address, KProcessAddr
|
|||||||
// Copy as much aligned data as we can.
|
// Copy as much aligned data as we can.
|
||||||
if (cur_size >= sizeof(u32)) {
|
if (cur_size >= sizeof(u32)) {
|
||||||
const size_t copy_size = Common::AlignDown(cur_size, sizeof(u32));
|
const size_t copy_size = Common::AlignDown(cur_size, sizeof(u32));
|
||||||
const void* copy_src = GetLinearMappedVirtualPointer(m_kernel, cur_addr);
|
const void* copy_src = GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr);
|
||||||
FlushDataCache(copy_src, copy_size);
|
FlushDataCache(copy_src, copy_size);
|
||||||
R_UNLESS(dst_memory.WriteBlock(dst_address, copy_src, copy_size), ResultInvalidPointer);
|
R_UNLESS(dst_memory.WriteBlock(dst_address, copy_src, copy_size), ResultInvalidPointer);
|
||||||
|
|
||||||
@@ -3155,7 +3155,7 @@ Result KPageTableBase::ReadDebugMemory(KProcessAddress dst_address, KProcessAddr
|
|||||||
|
|
||||||
// Copy remaining data.
|
// Copy remaining data.
|
||||||
if (cur_size > 0) {
|
if (cur_size > 0) {
|
||||||
const void* copy_src = GetLinearMappedVirtualPointer(m_kernel, cur_addr);
|
const void* copy_src = GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr);
|
||||||
FlushDataCache(copy_src, cur_size);
|
FlushDataCache(copy_src, cur_size);
|
||||||
R_UNLESS(dst_memory.WriteBlock(dst_address, copy_src, cur_size), ResultInvalidPointer);
|
R_UNLESS(dst_memory.WriteBlock(dst_address, copy_src, cur_size), ResultInvalidPointer);
|
||||||
}
|
}
|
||||||
@@ -3240,11 +3240,11 @@ Result KPageTableBase::WriteDebugMemory(KProcessAddress dst_address, KProcessAdd
|
|||||||
// Copy as much aligned data as we can.
|
// Copy as much aligned data as we can.
|
||||||
if (cur_size >= sizeof(u32)) {
|
if (cur_size >= sizeof(u32)) {
|
||||||
const size_t copy_size = Common::AlignDown(cur_size, sizeof(u32));
|
const size_t copy_size = Common::AlignDown(cur_size, sizeof(u32));
|
||||||
void* copy_dst = GetLinearMappedVirtualPointer(m_kernel, cur_addr);
|
void* copy_dst = GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr);
|
||||||
R_UNLESS(src_memory.ReadBlock(src_address, copy_dst, copy_size),
|
R_UNLESS(src_memory.ReadBlock(src_address, copy_dst, copy_size),
|
||||||
ResultInvalidCurrentMemory);
|
ResultInvalidCurrentMemory);
|
||||||
|
|
||||||
StoreDataCache(GetLinearMappedVirtualPointer(m_kernel, cur_addr), copy_size);
|
StoreDataCache(GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr), copy_size);
|
||||||
|
|
||||||
src_address += copy_size;
|
src_address += copy_size;
|
||||||
cur_addr += copy_size;
|
cur_addr += copy_size;
|
||||||
@@ -3253,11 +3253,11 @@ Result KPageTableBase::WriteDebugMemory(KProcessAddress dst_address, KProcessAdd
|
|||||||
|
|
||||||
// Copy remaining data.
|
// Copy remaining data.
|
||||||
if (cur_size > 0) {
|
if (cur_size > 0) {
|
||||||
void* copy_dst = GetLinearMappedVirtualPointer(m_kernel, cur_addr);
|
void* copy_dst = GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr);
|
||||||
R_UNLESS(src_memory.ReadBlock(src_address, copy_dst, cur_size),
|
R_UNLESS(src_memory.ReadBlock(src_address, copy_dst, cur_size),
|
||||||
ResultInvalidCurrentMemory);
|
ResultInvalidCurrentMemory);
|
||||||
|
|
||||||
StoreDataCache(GetLinearMappedVirtualPointer(m_kernel, cur_addr), cur_size);
|
StoreDataCache(GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr), cur_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
@@ -3295,7 +3295,7 @@ Result KPageTableBase::WriteDebugMemory(KProcessAddress dst_address, KProcessAdd
|
|||||||
R_TRY(PerformCopy());
|
R_TRY(PerformCopy());
|
||||||
|
|
||||||
// Invalidate the instruction cache, as this svc allows modifying executable pages.
|
// Invalidate the instruction cache, as this svc allows modifying executable pages.
|
||||||
InvalidateInstructionCache(m_kernel, this, dst_address, size);
|
InvalidateInstructionCache(m_system.Kernel(), this, dst_address, size);
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
@@ -3311,7 +3311,7 @@ Result KPageTableBase::ReadIoMemoryImpl(KProcessAddress dst_addr, KPhysicalAddre
|
|||||||
const size_t map_size = map_end - map_start;
|
const size_t map_size = map_end - map_start;
|
||||||
|
|
||||||
// Get the memory reference to write into.
|
// Get the memory reference to write into.
|
||||||
auto& dst_memory = GetCurrentMemory(m_kernel);
|
auto& dst_memory = GetCurrentMemory(m_system.Kernel());
|
||||||
|
|
||||||
// We're going to perform an update, so create a helper.
|
// We're going to perform an update, so create a helper.
|
||||||
KScopedPageTableUpdater updater(this);
|
KScopedPageTableUpdater updater(this);
|
||||||
@@ -3347,7 +3347,7 @@ Result KPageTableBase::WriteIoMemoryImpl(KPhysicalAddress phys_addr, KProcessAdd
|
|||||||
const size_t map_size = map_end - map_start;
|
const size_t map_size = map_end - map_start;
|
||||||
|
|
||||||
// Get the memory reference to read from.
|
// Get the memory reference to read from.
|
||||||
auto& src_memory = GetCurrentMemory(m_kernel);
|
auto& src_memory = GetCurrentMemory(m_system.Kernel());
|
||||||
|
|
||||||
// We're going to perform an update, so create a helper.
|
// We're going to perform an update, so create a helper.
|
||||||
KScopedPageTableUpdater updater(this);
|
KScopedPageTableUpdater updater(this);
|
||||||
@@ -3379,7 +3379,7 @@ Result KPageTableBase::ReadDebugIoMemory(KProcessAddress dst_address, KProcessAd
|
|||||||
|
|
||||||
// We need to lock both this table, and the current process's table, so set up some aliases.
|
// We need to lock both this table, and the current process's table, so set up some aliases.
|
||||||
KPageTableBase& src_page_table = *this;
|
KPageTableBase& src_page_table = *this;
|
||||||
KPageTableBase& dst_page_table = GetCurrentProcess(m_kernel).GetPageTable().GetBasePageTable();
|
KPageTableBase& dst_page_table = GetCurrentProcess(m_system.Kernel()).GetPageTable().GetBasePageTable();
|
||||||
|
|
||||||
// Acquire the table locks.
|
// Acquire the table locks.
|
||||||
KScopedLightLockPair lk(src_page_table.m_general_lock, dst_page_table.m_general_lock);
|
KScopedLightLockPair lk(src_page_table.m_general_lock, dst_page_table.m_general_lock);
|
||||||
@@ -3421,7 +3421,7 @@ Result KPageTableBase::WriteDebugIoMemory(KProcessAddress dst_address, KProcessA
|
|||||||
|
|
||||||
// We need to lock both this table, and the current process's table, so set up some aliases.
|
// We need to lock both this table, and the current process's table, so set up some aliases.
|
||||||
KPageTableBase& src_page_table = *this;
|
KPageTableBase& src_page_table = *this;
|
||||||
KPageTableBase& dst_page_table = GetCurrentProcess(m_kernel).GetPageTable().GetBasePageTable();
|
KPageTableBase& dst_page_table = GetCurrentProcess(m_system.Kernel()).GetPageTable().GetBasePageTable();
|
||||||
|
|
||||||
// Acquire the table locks.
|
// Acquire the table locks.
|
||||||
KScopedLightLockPair lk(src_page_table.m_general_lock, dst_page_table.m_general_lock);
|
KScopedLightLockPair lk(src_page_table.m_general_lock, dst_page_table.m_general_lock);
|
||||||
@@ -3606,7 +3606,7 @@ Result KPageTableBase::OpenMemoryRangeForMapDeviceAddressSpace(KPageTableBase::M
|
|||||||
KMemoryAttribute::IpcLocked | KMemoryAttribute::Locked, KMemoryAttribute::None));
|
KMemoryAttribute::IpcLocked | KMemoryAttribute::Locked, KMemoryAttribute::None));
|
||||||
|
|
||||||
// We got the range, so open it.
|
// We got the range, so open it.
|
||||||
out->Open();
|
out->Open(m_system.Kernel());
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
@@ -3624,7 +3624,7 @@ Result KPageTableBase::OpenMemoryRangeForUnmapDeviceAddressSpace(MemoryRange* ou
|
|||||||
KMemoryAttribute::DeviceShared | KMemoryAttribute::Locked, KMemoryAttribute::DeviceShared));
|
KMemoryAttribute::DeviceShared | KMemoryAttribute::Locked, KMemoryAttribute::DeviceShared));
|
||||||
|
|
||||||
// We got the range, so open it.
|
// We got the range, so open it.
|
||||||
out->Open();
|
out->Open(m_system.Kernel());
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
@@ -3697,7 +3697,7 @@ Result KPageTableBase::OpenMemoryRangeForProcessCacheOperation(MemoryRange* out,
|
|||||||
KMemoryAttribute::None));
|
KMemoryAttribute::None));
|
||||||
|
|
||||||
// We got the range, so open it.
|
// We got the range, so open it.
|
||||||
out->Open();
|
out->Open(m_system.Kernel());
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
@@ -3710,7 +3710,7 @@ Result KPageTableBase::CopyMemoryFromLinearToUser(
|
|||||||
R_UNLESS(this->Contains(src_addr, size), ResultInvalidCurrentMemory);
|
R_UNLESS(this->Contains(src_addr, size), ResultInvalidCurrentMemory);
|
||||||
|
|
||||||
// Get the destination memory reference.
|
// Get the destination memory reference.
|
||||||
auto& dst_memory = GetCurrentMemory(m_kernel);
|
auto& dst_memory = GetCurrentMemory(m_system.Kernel());
|
||||||
|
|
||||||
// Copy the memory.
|
// Copy the memory.
|
||||||
{
|
{
|
||||||
@@ -3745,7 +3745,7 @@ Result KPageTableBase::CopyMemoryFromLinearToUser(
|
|||||||
if (cur_size >= sizeof(u32)) {
|
if (cur_size >= sizeof(u32)) {
|
||||||
const size_t copy_size = Common::AlignDown(cur_size, sizeof(u32));
|
const size_t copy_size = Common::AlignDown(cur_size, sizeof(u32));
|
||||||
R_UNLESS(dst_memory.WriteBlock(dst_addr,
|
R_UNLESS(dst_memory.WriteBlock(dst_addr,
|
||||||
GetLinearMappedVirtualPointer(m_kernel, cur_addr),
|
GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr),
|
||||||
copy_size),
|
copy_size),
|
||||||
ResultInvalidCurrentMemory);
|
ResultInvalidCurrentMemory);
|
||||||
|
|
||||||
@@ -3757,7 +3757,7 @@ Result KPageTableBase::CopyMemoryFromLinearToUser(
|
|||||||
// Copy remaining data.
|
// Copy remaining data.
|
||||||
if (cur_size > 0) {
|
if (cur_size > 0) {
|
||||||
R_UNLESS(dst_memory.WriteBlock(
|
R_UNLESS(dst_memory.WriteBlock(
|
||||||
dst_addr, GetLinearMappedVirtualPointer(m_kernel, cur_addr), cur_size),
|
dst_addr, GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr), cur_size),
|
||||||
ResultInvalidCurrentMemory);
|
ResultInvalidCurrentMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3836,7 +3836,7 @@ Result KPageTableBase::CopyMemoryFromLinearToKernel(
|
|||||||
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), ResultInvalidCurrentMemory);
|
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), ResultInvalidCurrentMemory);
|
||||||
|
|
||||||
// Copy the data.
|
// Copy the data.
|
||||||
std::memcpy(buffer, GetLinearMappedVirtualPointer(m_kernel, cur_addr), cur_size);
|
std::memcpy(buffer, GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr), cur_size);
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
};
|
};
|
||||||
@@ -3884,7 +3884,7 @@ Result KPageTableBase::CopyMemoryFromUserToLinear(
|
|||||||
R_UNLESS(this->Contains(dst_addr, size), ResultInvalidCurrentMemory);
|
R_UNLESS(this->Contains(dst_addr, size), ResultInvalidCurrentMemory);
|
||||||
|
|
||||||
// Get the source memory reference.
|
// Get the source memory reference.
|
||||||
auto& src_memory = GetCurrentMemory(m_kernel);
|
auto& src_memory = GetCurrentMemory(m_system.Kernel());
|
||||||
|
|
||||||
// Copy the memory.
|
// Copy the memory.
|
||||||
{
|
{
|
||||||
@@ -3919,7 +3919,7 @@ Result KPageTableBase::CopyMemoryFromUserToLinear(
|
|||||||
if (cur_size >= sizeof(u32)) {
|
if (cur_size >= sizeof(u32)) {
|
||||||
const size_t copy_size = Common::AlignDown(cur_size, sizeof(u32));
|
const size_t copy_size = Common::AlignDown(cur_size, sizeof(u32));
|
||||||
R_UNLESS(src_memory.ReadBlock(src_addr,
|
R_UNLESS(src_memory.ReadBlock(src_addr,
|
||||||
GetLinearMappedVirtualPointer(m_kernel, cur_addr),
|
GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr),
|
||||||
copy_size),
|
copy_size),
|
||||||
ResultInvalidCurrentMemory);
|
ResultInvalidCurrentMemory);
|
||||||
src_addr += copy_size;
|
src_addr += copy_size;
|
||||||
@@ -3930,7 +3930,7 @@ Result KPageTableBase::CopyMemoryFromUserToLinear(
|
|||||||
// Copy remaining data.
|
// Copy remaining data.
|
||||||
if (cur_size > 0) {
|
if (cur_size > 0) {
|
||||||
R_UNLESS(src_memory.ReadBlock(
|
R_UNLESS(src_memory.ReadBlock(
|
||||||
src_addr, GetLinearMappedVirtualPointer(m_kernel, cur_addr), cur_size),
|
src_addr, GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr), cur_size),
|
||||||
ResultInvalidCurrentMemory);
|
ResultInvalidCurrentMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4011,7 +4011,7 @@ Result KPageTableBase::CopyMemoryFromKernelToLinear(KProcessAddress dst_addr, si
|
|||||||
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), ResultInvalidCurrentMemory);
|
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), ResultInvalidCurrentMemory);
|
||||||
|
|
||||||
// Copy the data.
|
// Copy the data.
|
||||||
std::memcpy(GetLinearMappedVirtualPointer(m_kernel, cur_addr), buffer, cur_size);
|
std::memcpy(GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr), buffer, cur_size);
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
};
|
};
|
||||||
@@ -4162,8 +4162,8 @@ Result KPageTableBase::CopyMemoryFromHeapToHeap(
|
|||||||
R_UNLESS(IsHeapPhysicalAddress(cur_dst_addr), ResultInvalidCurrentMemory);
|
R_UNLESS(IsHeapPhysicalAddress(cur_dst_addr), ResultInvalidCurrentMemory);
|
||||||
|
|
||||||
// Copy the data.
|
// Copy the data.
|
||||||
std::memcpy(GetHeapVirtualPointer(m_kernel, cur_dst_addr),
|
std::memcpy(GetHeapVirtualPointer(m_system.Kernel(), cur_dst_addr),
|
||||||
GetHeapVirtualPointer(m_kernel, cur_src_addr), cur_copy_size);
|
GetHeapVirtualPointer(m_system.Kernel(), cur_src_addr), cur_copy_size);
|
||||||
|
|
||||||
// Update.
|
// Update.
|
||||||
cur_src_block_addr = src_next_entry.phys_addr;
|
cur_src_block_addr = src_next_entry.phys_addr;
|
||||||
@@ -4296,8 +4296,8 @@ Result KPageTableBase::CopyMemoryFromHeapToHeapWithoutCheckDestination(
|
|||||||
R_UNLESS(IsHeapPhysicalAddress(cur_dst_addr), ResultInvalidCurrentMemory);
|
R_UNLESS(IsHeapPhysicalAddress(cur_dst_addr), ResultInvalidCurrentMemory);
|
||||||
|
|
||||||
// Copy the data.
|
// Copy the data.
|
||||||
std::memcpy(GetHeapVirtualPointer(m_kernel, cur_dst_addr),
|
std::memcpy(GetHeapVirtualPointer(m_system.Kernel(), cur_dst_addr),
|
||||||
GetHeapVirtualPointer(m_kernel, cur_src_addr), cur_copy_size);
|
GetHeapVirtualPointer(m_system.Kernel(), cur_src_addr), cur_copy_size);
|
||||||
|
|
||||||
// Update.
|
// Update.
|
||||||
cur_src_block_addr = src_next_entry.phys_addr;
|
cur_src_block_addr = src_next_entry.phys_addr;
|
||||||
@@ -4493,7 +4493,7 @@ Result KPageTableBase::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
|
|||||||
|
|
||||||
// Reserve space for any partial pages we allocate.
|
// Reserve space for any partial pages we allocate.
|
||||||
const size_t unmapped_size = aligned_src_size - mapping_src_size;
|
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);
|
m_resource_limit, Svc::LimitableResource::PhysicalMemoryMax, unmapped_size);
|
||||||
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
||||||
|
|
||||||
@@ -4506,10 +4506,10 @@ Result KPageTableBase::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
|
|||||||
// free on scope exit.
|
// free on scope exit.
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
if (start_partial_page != 0) {
|
if (start_partial_page != 0) {
|
||||||
m_kernel.MemoryManager().Close(start_partial_page, 1);
|
m_system.Kernel().MemoryManager().Close(start_partial_page, 1);
|
||||||
}
|
}
|
||||||
if (end_partial_page != 0) {
|
if (end_partial_page != 0) {
|
||||||
m_kernel.MemoryManager().Close(end_partial_page, 1);
|
m_system.Kernel().MemoryManager().Close(end_partial_page, 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -4526,7 +4526,7 @@ Result KPageTableBase::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
|
|||||||
// Allocate the start page as needed.
|
// Allocate the start page as needed.
|
||||||
if (aligned_src_start < mapping_src_start) {
|
if (aligned_src_start < mapping_src_start) {
|
||||||
start_partial_page =
|
start_partial_page =
|
||||||
m_kernel.MemoryManager().AllocateAndOpenContinuous(1, 1, m_allocate_option);
|
m_system.Kernel().MemoryManager().AllocateAndOpenContinuous(1, 1, m_allocate_option);
|
||||||
R_UNLESS(start_partial_page != 0, ResultOutOfMemory);
|
R_UNLESS(start_partial_page != 0, ResultOutOfMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4534,7 +4534,7 @@ Result KPageTableBase::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
|
|||||||
if (mapping_src_end < aligned_src_end &&
|
if (mapping_src_end < aligned_src_end &&
|
||||||
(aligned_src_start < mapping_src_end || aligned_src_start == mapping_src_start)) {
|
(aligned_src_start < mapping_src_end || aligned_src_start == mapping_src_start)) {
|
||||||
end_partial_page =
|
end_partial_page =
|
||||||
m_kernel.MemoryManager().AllocateAndOpenContinuous(1, 1, m_allocate_option);
|
m_system.Kernel().MemoryManager().AllocateAndOpenContinuous(1, 1, m_allocate_option);
|
||||||
R_UNLESS(end_partial_page != 0, ResultOutOfMemory);
|
R_UNLESS(end_partial_page != 0, ResultOutOfMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4560,7 +4560,7 @@ Result KPageTableBase::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
|
|||||||
// Map the start page, if we have one.
|
// Map the start page, if we have one.
|
||||||
if (start_partial_page != 0) {
|
if (start_partial_page != 0) {
|
||||||
// Ensure the page holds correct data.
|
// Ensure the page holds correct data.
|
||||||
u8* const start_partial_virt = GetHeapVirtualPointer(m_kernel, start_partial_page);
|
u8* const start_partial_virt = GetHeapVirtualPointer(m_system.Kernel(), start_partial_page);
|
||||||
if (send) {
|
if (send) {
|
||||||
const size_t partial_offset = src_start - aligned_src_start;
|
const size_t partial_offset = src_start - aligned_src_start;
|
||||||
size_t copy_size, clear_size;
|
size_t copy_size, clear_size;
|
||||||
@@ -4574,7 +4574,7 @@ Result KPageTableBase::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
|
|||||||
|
|
||||||
std::memset(start_partial_virt, fill_val, partial_offset);
|
std::memset(start_partial_virt, fill_val, partial_offset);
|
||||||
std::memcpy(start_partial_virt + partial_offset,
|
std::memcpy(start_partial_virt + partial_offset,
|
||||||
GetHeapVirtualPointer(m_kernel, cur_block_addr) + partial_offset,
|
GetHeapVirtualPointer(m_system.Kernel(), cur_block_addr) + partial_offset,
|
||||||
copy_size);
|
copy_size);
|
||||||
if (clear_size > 0) {
|
if (clear_size > 0) {
|
||||||
std::memset(start_partial_virt + partial_offset + copy_size, fill_val, clear_size);
|
std::memset(start_partial_virt + partial_offset + copy_size, fill_val, clear_size);
|
||||||
@@ -4663,10 +4663,10 @@ Result KPageTableBase::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
|
|||||||
// Map the end page, if we have one.
|
// Map the end page, if we have one.
|
||||||
if (end_partial_page != 0) {
|
if (end_partial_page != 0) {
|
||||||
// Ensure the page holds correct data.
|
// Ensure the page holds correct data.
|
||||||
u8* const end_partial_virt = GetHeapVirtualPointer(m_kernel, end_partial_page);
|
u8* const end_partial_virt = GetHeapVirtualPointer(m_system.Kernel(), end_partial_page);
|
||||||
if (send) {
|
if (send) {
|
||||||
const size_t copy_size = src_end - mapping_src_end;
|
const size_t copy_size = src_end - mapping_src_end;
|
||||||
std::memcpy(end_partial_virt, GetHeapVirtualPointer(m_kernel, cur_block_addr),
|
std::memcpy(end_partial_virt, GetHeapVirtualPointer(m_system.Kernel(), cur_block_addr),
|
||||||
copy_size);
|
copy_size);
|
||||||
std::memset(end_partial_virt + copy_size, fill_val, PageSize - copy_size);
|
std::memset(end_partial_virt + copy_size, fill_val, PageSize - copy_size);
|
||||||
} else {
|
} else {
|
||||||
@@ -4799,7 +4799,7 @@ Result KPageTableBase::CleanupForIpcServer(KProcessAddress address, size_t size,
|
|||||||
const KProcessAddress mapping_start = Common::AlignUp(GetInteger(address), PageSize);
|
const KProcessAddress mapping_start = Common::AlignUp(GetInteger(address), PageSize);
|
||||||
const KProcessAddress mapping_end = Common::AlignDown(GetInteger(address) + size, 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;
|
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);
|
aligned_size - mapping_size);
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
@@ -5168,20 +5168,20 @@ Result KPageTableBase::MapPhysicalMemory(KProcessAddress address, size_t size) {
|
|||||||
// Allocate and map the memory.
|
// Allocate and map the memory.
|
||||||
{
|
{
|
||||||
// Reserve the memory from the process resource limit.
|
// 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);
|
m_resource_limit, Svc::LimitableResource::PhysicalMemoryMax, size - mapped_size);
|
||||||
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
||||||
|
|
||||||
// Allocate pages for the new memory.
|
// Allocate pages for the new memory.
|
||||||
KPageGroup pg(m_kernel, m_block_info_manager);
|
KPageGroup pg(m_system.Kernel(), m_block_info_manager);
|
||||||
R_TRY(m_kernel.MemoryManager().AllocateForProcess(
|
R_TRY(m_system.Kernel().MemoryManager().AllocateForProcess(
|
||||||
std::addressof(pg), (size - mapped_size) / PageSize, m_allocate_option,
|
std::addressof(pg), (size - mapped_size) / PageSize, m_allocate_option,
|
||||||
GetCurrentProcess(m_kernel).GetId(), m_heap_fill_value));
|
GetCurrentProcess(m_system.Kernel()).GetId(), m_heap_fill_value));
|
||||||
|
|
||||||
// If we fail in the next bit (or retry), we need to cleanup the pages.
|
// If we fail in the next bit (or retry), we need to cleanup the pages.
|
||||||
auto pg_guard = SCOPE_GUARD {
|
auto pg_guard = SCOPE_GUARD {
|
||||||
pg.OpenFirst();
|
pg.OpenFirst(m_system.Kernel());
|
||||||
pg.Close();
|
pg.Close(m_system.Kernel());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Map the memory.
|
// Map the memory.
|
||||||
@@ -5304,12 +5304,12 @@ Result KPageTableBase::MapPhysicalMemory(KProcessAddress address, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Release any remaining unmapped memory.
|
// Release any remaining unmapped memory.
|
||||||
m_kernel.MemoryManager().OpenFirst(pg_phys_addr, pg_pages);
|
m_system.Kernel().MemoryManager().OpenFirst(pg_phys_addr, pg_pages);
|
||||||
m_kernel.MemoryManager().Close(pg_phys_addr, pg_pages);
|
m_system.Kernel().MemoryManager().Close(pg_phys_addr, pg_pages);
|
||||||
for (++pg_it; pg_it != pg.end(); ++pg_it) {
|
for (++pg_it; pg_it != pg.end(); ++pg_it) {
|
||||||
m_kernel.MemoryManager().OpenFirst(pg_it->GetAddress(),
|
m_system.Kernel().MemoryManager().OpenFirst(pg_it->GetAddress(),
|
||||||
pg_it->GetNumPages());
|
pg_it->GetNumPages());
|
||||||
m_kernel.MemoryManager().Close(pg_it->GetAddress(), pg_it->GetNumPages());
|
m_system.Kernel().MemoryManager().Close(pg_it->GetAddress(), pg_it->GetNumPages());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -5337,11 +5337,11 @@ Result KPageTableBase::MapPhysicalMemory(KProcessAddress address, size_t size) {
|
|||||||
// While we have pages to map, map them.
|
// While we have pages to map, map them.
|
||||||
{
|
{
|
||||||
// Create a page group for the current mapping range.
|
// Create a page group for the current mapping range.
|
||||||
KPageGroup cur_pg(m_kernel, m_block_info_manager);
|
KPageGroup cur_pg(m_system.Kernel(), m_block_info_manager);
|
||||||
{
|
{
|
||||||
ON_RESULT_FAILURE_2 {
|
ON_RESULT_FAILURE_2 {
|
||||||
cur_pg.OpenFirst();
|
cur_pg.OpenFirst(m_system.Kernel());
|
||||||
cur_pg.Close();
|
cur_pg.Close(m_system.Kernel());
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t remain_pages = map_pages;
|
size_t remain_pages = map_pages;
|
||||||
@@ -5541,7 +5541,7 @@ Result KPageTableBase::UnmapPhysicalMemory(KProcessAddress address, size_t size)
|
|||||||
|
|
||||||
// Release the memory resource.
|
// Release the memory resource.
|
||||||
m_mapped_physical_memory_size -= mapped_size;
|
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.
|
// Update memory blocks.
|
||||||
m_memory_block_manager.Update(std::addressof(allocator), address, size / PageSize,
|
m_memory_block_manager.Update(std::addressof(allocator), address, size / PageSize,
|
||||||
@@ -5706,9 +5706,9 @@ Result KPageTableBase::Operate(PageLinkedList* page_list, KProcessAddress virt_a
|
|||||||
const bool separate_heap = operation == OperationType::UnmapPhysical;
|
const bool separate_heap = operation == OperationType::UnmapPhysical;
|
||||||
|
|
||||||
// Ensure that any pages we track are closed on exit.
|
// Ensure that any pages we track are closed on exit.
|
||||||
KPageGroup pages_to_close(m_kernel, this->GetBlockInfoManager());
|
KPageGroup pages_to_close(m_system.Kernel(), this->GetBlockInfoManager());
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
pages_to_close.CloseAndReset();
|
pages_to_close.CloseAndReset(m_system.Kernel());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Make a page group representing the region to unmap.
|
// Make a page group representing the region to unmap.
|
||||||
@@ -5727,7 +5727,7 @@ Result KPageTableBase::Operate(PageLinkedList* page_list, KProcessAddress virt_a
|
|||||||
|
|
||||||
// Open references to pages, if we should.
|
// Open references to pages, if we should.
|
||||||
if (this->IsHeapPhysicalAddress(phys_addr)) {
|
if (this->IsHeapPhysicalAddress(phys_addr)) {
|
||||||
m_kernel.MemoryManager().Open(phys_addr, num_pages);
|
m_system.Kernel().MemoryManager().Open(phys_addr, num_pages);
|
||||||
}
|
}
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
@@ -5767,7 +5767,7 @@ Result KPageTableBase::Operate(PageLinkedList* page_list, KProcessAddress virt_a
|
|||||||
const bool separate_heap = operation == OperationType::MapFirstGroupPhysical;
|
const bool separate_heap = operation == OperationType::MapFirstGroupPhysical;
|
||||||
|
|
||||||
// We want to maintain a new reference to every page in the group.
|
// We want to maintain a new reference to every page in the group.
|
||||||
KScopedPageGroup spg(page_group, operation == OperationType::MapGroup);
|
KScopedPageGroup spg(m_system.Kernel(), page_group, operation == OperationType::MapGroup);
|
||||||
|
|
||||||
for (const auto& node : page_group) {
|
for (const auto& node : page_group) {
|
||||||
const size_t size{node.GetNumPages() * PageSize};
|
const size_t size{node.GetNumPages() * PageSize};
|
||||||
|
|||||||
@@ -61,14 +61,12 @@ public:
|
|||||||
|
|
||||||
class MemoryRange {
|
class MemoryRange {
|
||||||
private:
|
private:
|
||||||
KernelCore& m_kernel;
|
KPhysicalAddress m_address = 0;
|
||||||
KPhysicalAddress m_address;
|
size_t m_size = 0;
|
||||||
size_t m_size;
|
bool m_heap = false;
|
||||||
bool m_heap;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MemoryRange(KernelCore& kernel)
|
explicit MemoryRange() : m_address(0), m_size(0), m_heap(false) {}
|
||||||
: m_kernel(kernel), m_address(0), m_size(0), m_heap(false) {}
|
|
||||||
|
|
||||||
void Set(KPhysicalAddress address, size_t size, bool heap) {
|
void Set(KPhysicalAddress address, size_t size, bool heap) {
|
||||||
m_address = address;
|
m_address = address;
|
||||||
@@ -86,8 +84,8 @@ public:
|
|||||||
return m_heap;
|
return m_heap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Open();
|
void Open(KernelCore& kernel);
|
||||||
void Close();
|
void Close(KernelCore& kernel);
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -189,7 +187,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KernelCore& m_kernel;
|
|
||||||
Core::System& m_system;
|
Core::System& m_system;
|
||||||
KProcessAddress m_address_space_start{};
|
KProcessAddress m_address_space_start{};
|
||||||
KProcessAddress m_address_space_end{};
|
KProcessAddress m_address_space_end{};
|
||||||
@@ -329,35 +326,35 @@ protected:
|
|||||||
bool IsLinearMappedPhysicalAddress(KPhysicalAddress phys_addr) {
|
bool IsLinearMappedPhysicalAddress(KPhysicalAddress phys_addr) {
|
||||||
ASSERT(this->IsLockedByCurrentThread());
|
ASSERT(this->IsLockedByCurrentThread());
|
||||||
|
|
||||||
return m_kernel.MemoryLayout().IsLinearMappedPhysicalAddress(
|
return m_system.Kernel().MemoryLayout().IsLinearMappedPhysicalAddress(
|
||||||
m_cached_physical_linear_region, phys_addr);
|
m_cached_physical_linear_region, phys_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsLinearMappedPhysicalAddress(KPhysicalAddress phys_addr, size_t size) {
|
bool IsLinearMappedPhysicalAddress(KPhysicalAddress phys_addr, size_t size) {
|
||||||
ASSERT(this->IsLockedByCurrentThread());
|
ASSERT(this->IsLockedByCurrentThread());
|
||||||
|
|
||||||
return m_kernel.MemoryLayout().IsLinearMappedPhysicalAddress(
|
return m_system.Kernel().MemoryLayout().IsLinearMappedPhysicalAddress(
|
||||||
m_cached_physical_linear_region, phys_addr, size);
|
m_cached_physical_linear_region, phys_addr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsHeapPhysicalAddress(KPhysicalAddress phys_addr) {
|
bool IsHeapPhysicalAddress(KPhysicalAddress phys_addr) {
|
||||||
ASSERT(this->IsLockedByCurrentThread());
|
ASSERT(this->IsLockedByCurrentThread());
|
||||||
|
|
||||||
return m_kernel.MemoryLayout().IsHeapPhysicalAddress(m_cached_physical_heap_region,
|
return m_system.Kernel().MemoryLayout().IsHeapPhysicalAddress(m_cached_physical_heap_region,
|
||||||
phys_addr);
|
phys_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsHeapPhysicalAddress(KPhysicalAddress phys_addr, size_t size) {
|
bool IsHeapPhysicalAddress(KPhysicalAddress phys_addr, size_t size) {
|
||||||
ASSERT(this->IsLockedByCurrentThread());
|
ASSERT(this->IsLockedByCurrentThread());
|
||||||
|
|
||||||
return m_kernel.MemoryLayout().IsHeapPhysicalAddress(m_cached_physical_heap_region,
|
return m_system.Kernel().MemoryLayout().IsHeapPhysicalAddress(m_cached_physical_heap_region,
|
||||||
phys_addr, size);
|
phys_addr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsHeapPhysicalAddressForFinalize(KPhysicalAddress phys_addr) {
|
bool IsHeapPhysicalAddressForFinalize(KPhysicalAddress phys_addr) {
|
||||||
ASSERT(!this->IsLockedByCurrentThread());
|
ASSERT(!this->IsLockedByCurrentThread());
|
||||||
|
|
||||||
return m_kernel.MemoryLayout().IsHeapPhysicalAddress(m_cached_physical_heap_region,
|
return m_system.Kernel().MemoryLayout().IsHeapPhysicalAddress(m_cached_physical_heap_region,
|
||||||
phys_addr);
|
phys_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -744,15 +741,15 @@ public:
|
|||||||
|
|
||||||
// Member heap
|
// Member heap
|
||||||
u8* GetHeapVirtualPointer(KPhysicalAddress addr) {
|
u8* GetHeapVirtualPointer(KPhysicalAddress addr) {
|
||||||
return GetHeapVirtualPointer(m_kernel, addr);
|
return GetHeapVirtualPointer(m_system.Kernel(), addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
KPhysicalAddress GetHeapPhysicalAddress(KVirtualAddress addr) {
|
KPhysicalAddress GetHeapPhysicalAddress(KVirtualAddress addr) {
|
||||||
return GetHeapPhysicalAddress(m_kernel, addr);
|
return GetHeapPhysicalAddress(m_system.Kernel(), addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
KVirtualAddress GetHeapVirtualAddress(KPhysicalAddress addr) {
|
KVirtualAddress GetHeapVirtualAddress(KPhysicalAddress addr) {
|
||||||
return GetHeapVirtualAddress(m_kernel, addr);
|
return GetHeapVirtualAddress(m_system.Kernel(), addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: GetPageTableVirtualAddress
|
// TODO: GetPageTableVirtualAddress
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "core/hle/kernel/k_port.h"
|
#include "core/hle/kernel/k_port.h"
|
||||||
#include "core/hle/kernel/k_scheduler.h"
|
#include "core/hle/kernel/k_scheduler.h"
|
||||||
|
#include "core/hle/kernel/kernel.h"
|
||||||
#include "core/hle/kernel/svc_results.h"
|
#include "core/hle/kernel/svc_results.h"
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
@@ -12,15 +16,15 @@ KPort::KPort(KernelCore& kernel)
|
|||||||
|
|
||||||
KPort::~KPort() = default;
|
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.
|
// Open a new reference count to the initialized port.
|
||||||
this->Open();
|
this->Open(kernel);
|
||||||
|
|
||||||
// Create and initialize our server/client pair.
|
// Create and initialize our server/client pair.
|
||||||
KAutoObject::Create(std::addressof(m_server));
|
KAutoObject::Create(std::addressof(m_server));
|
||||||
KAutoObject::Create(std::addressof(m_client));
|
KAutoObject::Create(std::addressof(m_client));
|
||||||
m_server.Initialize(this);
|
m_server.Initialize(kernel, this);
|
||||||
m_client.Initialize(this, max_sessions);
|
m_client.Initialize(kernel, this, max_sessions);
|
||||||
|
|
||||||
// Set our member variables.
|
// Set our member variables.
|
||||||
m_is_light = is_light;
|
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;
|
m_state = State::Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KPort::OnClientClosed() {
|
void KPort::OnClientClosed(KernelCore& kernel) {
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
if (m_state == State::Normal) {
|
if (m_state == State::Normal) {
|
||||||
m_state = State::ClientClosed;
|
m_state = State::ClientClosed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KPort::OnServerClosed() {
|
void KPort::OnServerClosed(KernelCore& kernel) {
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
if (m_state == State::Normal) {
|
if (m_state == State::Normal) {
|
||||||
m_state = State::ServerClosed;
|
m_state = State::ServerClosed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KPort::IsServerClosed() const {
|
bool KPort::IsServerClosed(KernelCore& kernel) const {
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
return m_state == State::ServerClosed;
|
return m_state == State::ServerClosed;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KPort::EnqueueSession(KServerSession* session) {
|
Result KPort::EnqueueSession(KernelCore& kernel, KServerSession* session) {
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
R_UNLESS(m_state == State::Normal, ResultPortClosed);
|
R_UNLESS(m_state == State::Normal, ResultPortClosed);
|
||||||
|
m_server.EnqueueSession(kernel, session);
|
||||||
m_server.EnqueueSession(session);
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KPort::EnqueueSession(KLightServerSession* session) {
|
Result KPort::EnqueueSession(KernelCore& kernel, KLightServerSession* session) {
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
R_UNLESS(m_state == State::Normal, ResultPortClosed);
|
R_UNLESS(m_state == State::Normal, ResultPortClosed);
|
||||||
|
m_server.EnqueueSession(kernel, session);
|
||||||
m_server.EnqueueSession(session);
|
|
||||||
R_SUCCEED();
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -23,11 +26,11 @@ public:
|
|||||||
explicit KPort(KernelCore& kernel);
|
explicit KPort(KernelCore& kernel);
|
||||||
~KPort() override;
|
~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 Initialize(KernelCore& kernel, s32 max_sessions, bool is_light, uintptr_t name);
|
||||||
void OnClientClosed();
|
void OnClientClosed(KernelCore& kernel);
|
||||||
void OnServerClosed();
|
void OnServerClosed(KernelCore& kernel);
|
||||||
|
|
||||||
uintptr_t GetName() const {
|
uintptr_t GetName() const {
|
||||||
return m_name;
|
return m_name;
|
||||||
@@ -36,10 +39,10 @@ public:
|
|||||||
return m_is_light;
|
return m_is_light;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsServerClosed() const;
|
bool IsServerClosed(KernelCore& kernel) const;
|
||||||
|
|
||||||
Result EnqueueSession(KServerSession* session);
|
Result EnqueueSession(KernelCore& kernel, KServerSession* session);
|
||||||
Result EnqueueSession(KLightServerSession* session);
|
Result EnqueueSession(KernelCore& kernel, KLightServerSession* session);
|
||||||
|
|
||||||
KClientPort& GetClientPort() {
|
KClientPort& GetClientPort() {
|
||||||
return m_client;
|
return m_client;
|
||||||
|
|||||||
+179
-191
File diff suppressed because it is too large
Load Diff
@@ -141,8 +141,8 @@ private:
|
|||||||
bool m_is_handle_table_initialized : 1 = false;
|
bool m_is_handle_table_initialized : 1 = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Result StartTermination();
|
Result StartTermination(KernelCore& kernel);
|
||||||
void FinishTermination();
|
void FinishTermination(KernelCore& kernel);
|
||||||
|
|
||||||
void PinThread(s32 core_id, KThread* thread) {
|
void PinThread(s32 core_id, KThread* thread) {
|
||||||
ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES));
|
ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES));
|
||||||
@@ -162,16 +162,16 @@ public:
|
|||||||
explicit KProcess(KernelCore& kernel);
|
explicit KProcess(KernelCore& kernel);
|
||||||
~KProcess() override;
|
~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);
|
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,
|
std::span<const u32> caps, KResourceLimit* res_limit,
|
||||||
KMemoryManager::Pool pool, bool immortal);
|
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,
|
KResourceLimit* res_limit, KMemoryManager::Pool pool,
|
||||||
KProcessAddress aslr_space_start);
|
KProcessAddress aslr_space_start);
|
||||||
void Exit();
|
void Exit(KernelCore& kernel);
|
||||||
|
|
||||||
const char* GetName() const {
|
const char* GetName() const {
|
||||||
return m_name.data();
|
return m_name.data();
|
||||||
@@ -267,7 +267,7 @@ public:
|
|||||||
m_pointer_buffer_size = size;
|
m_pointer_buffer_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Terminate();
|
Result Terminate(KernelCore& kernel);
|
||||||
|
|
||||||
bool IsTerminated() const {
|
bool IsTerminated() const {
|
||||||
return m_state == State::Terminated;
|
return m_state == State::Terminated;
|
||||||
@@ -300,9 +300,9 @@ public:
|
|||||||
return m_thread_list;
|
return m_thread_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EnterUserException();
|
bool EnterUserException(KernelCore& kernel);
|
||||||
bool LeaveUserException();
|
bool LeaveUserException(KernelCore& kernel);
|
||||||
bool ReleaseUserException(KThread* thread);
|
bool ReleaseUserException(KernelCore& kernel, KThread* thread);
|
||||||
|
|
||||||
KThread* GetPinnedThread(s32 core_id) const {
|
KThread* GetPinnedThread(s32 core_id) const {
|
||||||
ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES));
|
ASSERT(0 <= core_id && core_id < static_cast<s32>(Core::Hardware::NUM_CPU_CORES));
|
||||||
@@ -317,10 +317,10 @@ public:
|
|||||||
return m_resource_limit;
|
return m_resource_limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReserveResource(Svc::LimitableResource which, s64 value);
|
bool ReserveResource(KernelCore& kernel, Svc::LimitableResource which, s64 value);
|
||||||
bool ReserveResource(Svc::LimitableResource which, s64 value, s64 timeout);
|
bool ReserveResource(KernelCore& kernel, Svc::LimitableResource which, s64 value, s64 timeout);
|
||||||
void ReleaseResource(Svc::LimitableResource which, s64 value);
|
void ReleaseResource(KernelCore& kernel, Svc::LimitableResource which, s64 value);
|
||||||
void ReleaseResource(Svc::LimitableResource which, s64 value, s64 hint);
|
void ReleaseResource(KernelCore& kernel, Svc::LimitableResource which, s64 value, s64 hint);
|
||||||
|
|
||||||
KLightLock& GetStateLock() {
|
KLightLock& GetStateLock() {
|
||||||
return m_state_lock;
|
return m_state_lock;
|
||||||
@@ -343,16 +343,16 @@ public:
|
|||||||
return m_handle_table;
|
return m_handle_table;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t GetUsedUserPhysicalMemorySize() const;
|
size_t GetUsedUserPhysicalMemorySize(KernelCore& kernel) const;
|
||||||
size_t GetTotalUserPhysicalMemorySize() const;
|
size_t GetTotalUserPhysicalMemorySize(KernelCore& kernel) const;
|
||||||
size_t GetUsedNonSystemUserPhysicalMemorySize() const;
|
size_t GetUsedNonSystemUserPhysicalMemorySize(KernelCore& kernel) const;
|
||||||
size_t GetTotalNonSystemUserPhysicalMemorySize() const;
|
size_t GetTotalNonSystemUserPhysicalMemorySize(KernelCore& kernel) const;
|
||||||
|
|
||||||
Result AddSharedMemory(KSharedMemory* shmem, KProcessAddress address, size_t size);
|
Result AddSharedMemory(KernelCore& kernel, KSharedMemory* shmem, KProcessAddress address, size_t size);
|
||||||
void RemoveSharedMemory(KSharedMemory* shmem, KProcessAddress address, size_t size);
|
void RemoveSharedMemory(KernelCore& kernel, KSharedMemory* shmem, KProcessAddress address, size_t size);
|
||||||
|
|
||||||
Result CreateThreadLocalRegion(KProcessAddress* out);
|
Result CreateThreadLocalRegion(KernelCore& kernel, KProcessAddress* out);
|
||||||
Result DeleteThreadLocalRegion(KProcessAddress addr);
|
Result DeleteThreadLocalRegion(KernelCore& kernel, KProcessAddress addr);
|
||||||
|
|
||||||
KProcessAddress GetProcessLocalRegionAddress() const {
|
KProcessAddress GetProcessLocalRegionAddress() const {
|
||||||
return m_plr_address;
|
return m_plr_address;
|
||||||
@@ -376,8 +376,8 @@ public:
|
|||||||
++m_schedule_count;
|
++m_schedule_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IncrementRunningThreadCount();
|
void IncrementRunningThreadCount(KernelCore& kernel);
|
||||||
void DecrementRunningThreadCount();
|
void DecrementRunningThreadCount(KernelCore& kernel);
|
||||||
|
|
||||||
size_t GetRequiredSecureMemorySizeNonDefault() const {
|
size_t GetRequiredSecureMemorySizeNonDefault() const {
|
||||||
if (!this->IsDefaultApplicationSystemResource() && m_system_resource->IsSecureResource()) {
|
if (!this->IsDefaultApplicationSystemResource() && m_system_resource->IsSecureResource()) {
|
||||||
@@ -422,11 +422,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ClearRunningThread(KThread* thread) {
|
void ClearRunningThread(KThread* thread) {
|
||||||
for (size_t i = 0; i < m_running_threads.size(); ++i) {
|
for (size_t i = 0; i < m_running_threads.size(); ++i)
|
||||||
if (m_running_threads[i] == thread) {
|
if (m_running_threads[i] == thread)
|
||||||
m_running_threads[i] = nullptr;
|
m_running_threads[i] = nullptr;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const KSystemResource& GetSystemResource() const {
|
const KSystemResource& GetSystemResource() const {
|
||||||
@@ -453,30 +451,27 @@ public:
|
|||||||
return m_running_thread_switch_counts[core];
|
return m_running_thread_switch_counts[core];
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterThread(KThread* thread);
|
void RegisterThread(KernelCore& kernel, KThread* thread);
|
||||||
void UnregisterThread(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);
|
void SetDebugBreak(KernelCore& kernel) {
|
||||||
|
|
||||||
Result Reset();
|
|
||||||
|
|
||||||
void SetDebugBreak() {
|
|
||||||
if (m_state == State::RunningAttached) {
|
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) {
|
if (m_state == State::DebugBreak) {
|
||||||
this->ChangeState(State::RunningAttached);
|
this->ChangeState(kernel, State::RunningAttached);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SetActivity(Svc::ProcessActivity activity);
|
Result SetActivity(KernelCore& kernel, Svc::ProcessActivity activity);
|
||||||
|
void PinCurrentThread(KernelCore& kernel);
|
||||||
void PinCurrentThread();
|
void UnpinCurrentThread(KernelCore& kernel);
|
||||||
void UnpinCurrentThread();
|
void UnpinThread(KernelCore& kernel, KThread* thread);
|
||||||
void UnpinThread(KThread* thread);
|
|
||||||
|
|
||||||
void SignalConditionVariable(uintptr_t cv_key, int32_t count) {
|
void SignalConditionVariable(uintptr_t cv_key, int32_t count) {
|
||||||
return m_cond_var.Signal(cv_key, count);
|
return m_cond_var.Signal(cv_key, count);
|
||||||
@@ -486,19 +481,17 @@ public:
|
|||||||
R_RETURN(m_cond_var.Wait(address, cv_key, tag, ns));
|
R_RETURN(m_cond_var.Wait(address, cv_key, tag, ns));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SignalAddressArbiter(uintptr_t address, Svc::SignalType signal_type, s32 value,
|
Result SignalAddressArbiter(uintptr_t address, Svc::SignalType signal_type, s32 value, s32 count) {
|
||||||
s32 count) {
|
|
||||||
R_RETURN(m_address_arbiter.SignalToAddress(address, signal_type, value, count));
|
R_RETURN(m_address_arbiter.SignalToAddress(address, signal_type, value, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result WaitAddressArbiter(uintptr_t address, Svc::ArbitrationType arb_type, s32 value,
|
Result WaitAddressArbiter(uintptr_t address, Svc::ArbitrationType arb_type, s32 value, s64 timeout) {
|
||||||
s64 timeout) {
|
|
||||||
R_RETURN(m_address_arbiter.WaitForAddress(address, arb_type, value, 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
|
#ifdef HAS_NCE
|
||||||
ankerl::unordered_dense::map<u64, u64>& GetPostHandlers() noexcept {
|
ankerl::unordered_dense::map<u64, u64>& GetPostHandlers() noexcept {
|
||||||
@@ -512,21 +505,21 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Attempts to insert a watchpoint into a free slot. Returns false if none are available.
|
// 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.
|
// 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 {
|
const std::array<DebugWatchpoint, Core::Hardware::NUM_WATCHPOINTS>& GetWatchpoints() const {
|
||||||
return m_watchpoints;
|
return m_watchpoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Result LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std::size_t code_size, KProcessAddress aslr_space_start, size_t aslr_space_offset);
|
Result LoadFromMetadata(KernelCore& kernel, const FileSys::ProgramMetadata& metadata, std::size_t code_size, KProcessAddress aslr_space_start, size_t aslr_space_offset);
|
||||||
|
|
||||||
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() {
|
Core::Memory::Memory& GetMemory() {
|
||||||
return m_memory;
|
return m_memory;
|
||||||
@@ -542,9 +535,9 @@ public:
|
|||||||
return m_is_initialized;
|
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 {
|
u64 GetIdImpl() const {
|
||||||
return this->GetProcessId();
|
return this->GetProcessId();
|
||||||
@@ -553,34 +546,34 @@ public:
|
|||||||
return this->GetIdImpl();
|
return this->GetIdImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool IsSignaled() const override {
|
virtual bool IsSignaled(KernelCore& kernel) const override {
|
||||||
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(m_kernel));
|
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
|
||||||
return m_is_signaled;
|
return m_is_signaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoWorkerTaskImpl();
|
void DoWorkerTaskImpl(KernelCore& kernel);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ChangeState(State new_state) {
|
void ChangeState(KernelCore& kernel, State new_state) {
|
||||||
if (m_state != new_state) {
|
if (m_state != new_state) {
|
||||||
m_state = new_state;
|
m_state = new_state;
|
||||||
m_is_signaled = true;
|
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.
|
// Try to initialize the handle table.
|
||||||
R_TRY(m_handle_table.Initialize(size));
|
R_TRY(m_handle_table.Initialize(kernel, size));
|
||||||
|
|
||||||
// We succeeded, so note that we did.
|
// We succeeded, so note that we did.
|
||||||
m_is_handle_table_initialized = true;
|
m_is_handle_table_initialized = true;
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FinalizeHandleTable() {
|
void FinalizeHandleTable(KernelCore& kernel) {
|
||||||
// Finalize the table.
|
// Finalize the table.
|
||||||
m_handle_table.Finalize();
|
m_handle_table.Finalize(kernel);
|
||||||
|
|
||||||
// Note that the table is finalized.
|
// Note that the table is finalized.
|
||||||
m_is_handle_table_initialized = false;
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -15,50 +18,45 @@ KReadableEvent::KReadableEvent(KernelCore& kernel) : KSynchronizationObject{kern
|
|||||||
|
|
||||||
KReadableEvent::~KReadableEvent() = default;
|
KReadableEvent::~KReadableEvent() = default;
|
||||||
|
|
||||||
void KReadableEvent::Initialize(KEvent* parent) {
|
void KReadableEvent::Initialize(KernelCore& kernel, KEvent* parent) {
|
||||||
m_is_signaled = false;
|
m_is_signaled = false;
|
||||||
m_parent = parent;
|
m_parent = parent;
|
||||||
|
|
||||||
if (m_parent != nullptr) {
|
if (m_parent != nullptr) {
|
||||||
m_parent->Open();
|
m_parent->Open(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KReadableEvent::IsSignaled() const {
|
bool KReadableEvent::IsSignaled(KernelCore& kernel) const {
|
||||||
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(m_kernel));
|
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
|
||||||
|
|
||||||
return m_is_signaled;
|
return m_is_signaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KReadableEvent::Destroy() {
|
void KReadableEvent::Destroy(KernelCore& kernel) {
|
||||||
if (m_parent) {
|
if (m_parent) {
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
m_parent->OnReadableEventDestroyed();
|
m_parent->OnReadableEventDestroyed();
|
||||||
}
|
}
|
||||||
m_parent->Close();
|
m_parent->Close(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KReadableEvent::Signal() {
|
Result KReadableEvent::Signal(KernelCore& kernel) {
|
||||||
KScopedSchedulerLock lk{m_kernel};
|
KScopedSchedulerLock lk{kernel};
|
||||||
|
|
||||||
if (!m_is_signaled) {
|
if (!m_is_signaled) {
|
||||||
m_is_signaled = true;
|
m_is_signaled = true;
|
||||||
this->NotifyAvailable();
|
this->NotifyAvailable(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KReadableEvent::Clear() {
|
Result KReadableEvent::Clear(KernelCore& kernel) {
|
||||||
this->Reset();
|
this->Reset(kernel);
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KReadableEvent::Reset() {
|
Result KReadableEvent::Reset(KernelCore& kernel) {
|
||||||
KScopedSchedulerLock lk{m_kernel};
|
KScopedSchedulerLock lk{kernel};
|
||||||
|
|
||||||
R_UNLESS(m_is_signaled, ResultInvalidState);
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -20,19 +23,17 @@ public:
|
|||||||
explicit KReadableEvent(KernelCore& kernel);
|
explicit KReadableEvent(KernelCore& kernel);
|
||||||
~KReadableEvent() override;
|
~KReadableEvent() override;
|
||||||
|
|
||||||
void Initialize(KEvent* parent);
|
void Initialize(KernelCore& kernel, KEvent* parent);
|
||||||
|
|
||||||
KEvent* GetParent() const {
|
KEvent* GetParent() const {
|
||||||
return m_parent;
|
return m_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Signal();
|
Result Signal(KernelCore& kernel);
|
||||||
Result Clear();
|
Result Clear(KernelCore& kernel);
|
||||||
|
bool IsSignaled(KernelCore& kernel) const override;
|
||||||
bool IsSignaled() const override;
|
void Destroy(KernelCore& kernel) override;
|
||||||
void Destroy() override;
|
Result Reset(KernelCore& kernel);
|
||||||
|
|
||||||
Result Reset();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_is_signaled{};
|
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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
@@ -16,12 +16,15 @@ namespace Kernel {
|
|||||||
constexpr s64 DefaultTimeout = 10000000000; // 10 seconds
|
constexpr s64 DefaultTimeout = 10000000000; // 10 seconds
|
||||||
|
|
||||||
KResourceLimit::KResourceLimit(KernelCore& kernel)
|
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;
|
KResourceLimit::~KResourceLimit() = default;
|
||||||
|
|
||||||
void KResourceLimit::Initialize() {}
|
void KResourceLimit::Initialize() {}
|
||||||
|
|
||||||
void KResourceLimit::Finalize() {}
|
void KResourceLimit::Finalize(KernelCore& kernel) {}
|
||||||
|
|
||||||
s64 KResourceLimit::GetLimitValue(LimitableResource which) const {
|
s64 KResourceLimit::GetLimitValue(LimitableResource which) const {
|
||||||
const auto index = static_cast<std::size_t>(which);
|
const auto index = static_cast<std::size_t>(which);
|
||||||
@@ -87,11 +90,11 @@ Result KResourceLimit::SetLimitValue(LimitableResource which, s64 value) {
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KResourceLimit::Reserve(LimitableResource which, s64 value) {
|
bool KResourceLimit::Reserve(KernelCore& kernel, LimitableResource which, s64 value) {
|
||||||
return Reserve(which, value, m_kernel.HardwareTimer().GetTick() + DefaultTimeout);
|
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);
|
ASSERT(value >= 0);
|
||||||
const auto index = static_cast<std::size_t>(which);
|
const auto index = static_cast<std::size_t>(which);
|
||||||
KScopedLightLock lk(m_lock);
|
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] &&
|
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_waiter_count++;
|
||||||
m_cond_var.Wait(std::addressof(m_lock), timeout, false);
|
m_cond_var.Wait(std::addressof(m_lock), timeout, false);
|
||||||
m_waiter_count--;
|
m_waiter_count--;
|
||||||
@@ -131,11 +134,11 @@ bool KResourceLimit::Reserve(LimitableResource which, s64 value, s64 timeout) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KResourceLimit::Release(LimitableResource which, s64 value) {
|
void KResourceLimit::Release(KernelCore& kernel, LimitableResource which, s64 value) {
|
||||||
Release(which, value, 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(value >= 0);
|
||||||
ASSERT(hint >= 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-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -32,7 +35,7 @@ public:
|
|||||||
~KResourceLimit() override;
|
~KResourceLimit() override;
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void Finalize() override;
|
void Finalize(KernelCore& kernel) override;
|
||||||
|
|
||||||
s64 GetLimitValue(LimitableResource which) const;
|
s64 GetLimitValue(LimitableResource which) const;
|
||||||
s64 GetCurrentValue(LimitableResource which) const;
|
s64 GetCurrentValue(LimitableResource which) const;
|
||||||
@@ -41,12 +44,12 @@ public:
|
|||||||
|
|
||||||
Result SetLimitValue(LimitableResource which, s64 value);
|
Result SetLimitValue(LimitableResource which, s64 value);
|
||||||
|
|
||||||
bool Reserve(LimitableResource which, s64 value);
|
bool Reserve(KernelCore& kernel, LimitableResource which, s64 value);
|
||||||
bool Reserve(LimitableResource which, s64 value, s64 timeout);
|
bool Reserve(KernelCore& kernel, LimitableResource which, s64 value, s64 timeout);
|
||||||
void Release(LimitableResource which, s64 value);
|
void Release(KernelCore& kernel, LimitableResource which, s64 value);
|
||||||
void Release(LimitableResource which, s64 value, s64 hint);
|
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:
|
private:
|
||||||
using ResourceArray = std::array<s64, static_cast<std::size_t>(LimitableResource::Count)>;
|
using ResourceArray = std::array<s64, static_cast<std::size_t>(LimitableResource::Count)>;
|
||||||
|
|||||||
@@ -30,34 +30,32 @@ static void IncrementScheduledCount(Kernel::KThread* thread) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KScheduler::KScheduler(KernelCore& kernel) : m_kernel{kernel} {
|
KScheduler::KScheduler(KernelCore& kernel) {
|
||||||
m_switch_fiber = std::make_shared<Common::Fiber>([this] {
|
m_switch_fiber = std::make_shared<Common::Fiber>([this, &kernel] {
|
||||||
while (true) {
|
while (true) {
|
||||||
ScheduleImplFiber();
|
ScheduleImplFiber(kernel);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
m_state.needs_scheduling = true;
|
m_state.needs_scheduling = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
KScheduler::~KScheduler() = default;
|
KScheduler::~KScheduler() = default;
|
||||||
|
|
||||||
void KScheduler::SetInterruptTaskRunnable() {
|
void KScheduler::SetInterruptTaskRunnable(KernelCore& kernel) {
|
||||||
m_state.interrupt_task_runnable = true;
|
m_state.interrupt_task_runnable = true;
|
||||||
m_state.needs_scheduling = true;
|
m_state.needs_scheduling = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::RequestScheduleOnInterrupt() {
|
void KScheduler::RequestScheduleOnInterrupt(KernelCore& kernel) {
|
||||||
m_state.needs_scheduling = true;
|
m_state.needs_scheduling = true;
|
||||||
|
if (CanSchedule(kernel)) {
|
||||||
if (CanSchedule(m_kernel)) {
|
ScheduleOnInterrupt(kernel);
|
||||||
ScheduleOnInterrupt();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::DisableScheduling(KernelCore& kernel) {
|
void KScheduler::DisableScheduling(KernelCore& kernel) {
|
||||||
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() >= 0);
|
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() >= 0);
|
||||||
GetCurrentThread(kernel).DisableDispatch();
|
GetCurrentThread(kernel).DisableDispatch(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::EnableScheduling(KernelCore& kernel, u64 cores_needing_scheduling) {
|
void KScheduler::EnableScheduling(KernelCore& kernel, u64 cores_needing_scheduling) {
|
||||||
@@ -71,12 +69,12 @@ void KScheduler::EnableScheduling(KernelCore& kernel, u64 cores_needing_scheduli
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduler->RescheduleOtherCores(cores_needing_scheduling);
|
scheduler->RescheduleOtherCores(kernel, cores_needing_scheduling);
|
||||||
|
|
||||||
if (GetCurrentThread(kernel).GetDisableDispatchCount() > 1) {
|
if (GetCurrentThread(kernel).GetDisableDispatchCount() > 1) {
|
||||||
GetCurrentThread(kernel).EnableDispatch();
|
GetCurrentThread(kernel).EnableDispatch(kernel);
|
||||||
} else {
|
} else {
|
||||||
scheduler->RescheduleCurrentCore();
|
scheduler->RescheduleCurrentCore(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,10 +83,10 @@ void KScheduler::RescheduleCurrentHLEThread(KernelCore& kernel) {
|
|||||||
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() == 1);
|
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() == 1);
|
||||||
|
|
||||||
// Ensure dummy threads that are waiting block.
|
// Ensure dummy threads that are waiting block.
|
||||||
GetCurrentThread(kernel).DummyThreadBeginWait();
|
GetCurrentThread(kernel).DummyThreadBeginWait(kernel);
|
||||||
|
|
||||||
ASSERT(GetCurrentThread(kernel).GetState() != ThreadState::Waiting);
|
ASSERT(GetCurrentThread(kernel).GetState() != ThreadState::Waiting);
|
||||||
GetCurrentThread(kernel).EnableDispatch();
|
GetCurrentThread(kernel).EnableDispatch(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 KScheduler::UpdateHighestPriorityThreads(KernelCore& kernel) {
|
u64 KScheduler::UpdateHighestPriorityThreads(KernelCore& kernel) {
|
||||||
@@ -99,55 +97,55 @@ u64 KScheduler::UpdateHighestPriorityThreads(KernelCore& kernel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::Schedule() {
|
void KScheduler::Schedule(KernelCore& kernel) {
|
||||||
ASSERT(GetCurrentThread(m_kernel).GetDisableDispatchCount() == 1);
|
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() == 1);
|
||||||
ASSERT(m_core_id == GetCurrentCoreId(m_kernel));
|
ASSERT(m_core_id == GetCurrentCoreId(kernel));
|
||||||
|
|
||||||
ScheduleImpl();
|
ScheduleImpl(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::ScheduleOnInterrupt() {
|
void KScheduler::ScheduleOnInterrupt(KernelCore& kernel) {
|
||||||
GetCurrentThread(m_kernel).DisableDispatch();
|
GetCurrentThread(kernel).DisableDispatch(kernel);
|
||||||
Schedule();
|
Schedule(kernel);
|
||||||
GetCurrentThread(m_kernel).EnableDispatch();
|
GetCurrentThread(kernel).EnableDispatch(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::PreemptSingleCore() {
|
void KScheduler::PreemptSingleCore(KernelCore& kernel) {
|
||||||
GetCurrentThread(m_kernel).DisableDispatch();
|
GetCurrentThread(kernel).DisableDispatch(kernel);
|
||||||
|
|
||||||
auto* thread = GetCurrentThreadPointer(m_kernel);
|
auto* thread = GetCurrentThreadPointer(kernel);
|
||||||
auto& previous_scheduler = m_kernel.Scheduler(thread->GetCurrentCore());
|
auto& previous_scheduler = kernel.Scheduler(thread->GetCurrentCore());
|
||||||
previous_scheduler.Unload(thread);
|
previous_scheduler.Unload(kernel, thread);
|
||||||
|
|
||||||
Common::Fiber::YieldTo(thread->GetHostContext(), *m_switch_fiber);
|
Common::Fiber::YieldTo(thread->GetHostContext(), *m_switch_fiber);
|
||||||
|
|
||||||
GetCurrentThread(m_kernel).EnableDispatch();
|
GetCurrentThread(kernel).EnableDispatch(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::RescheduleCurrentCore() {
|
void KScheduler::RescheduleCurrentCore(KernelCore& kernel) {
|
||||||
ASSERT(!m_kernel.IsPhantomModeForSingleCore());
|
ASSERT(!kernel.IsPhantomModeForSingleCore());
|
||||||
ASSERT(GetCurrentThread(m_kernel).GetDisableDispatchCount() == 1);
|
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() == 1);
|
||||||
|
|
||||||
GetCurrentThread(m_kernel).EnableDispatch();
|
GetCurrentThread(kernel).EnableDispatch(kernel);
|
||||||
|
|
||||||
if (m_state.needs_scheduling.load()) {
|
if (m_state.needs_scheduling.load()) {
|
||||||
// Disable interrupts, and then check again if rescheduling is needed.
|
// Disable interrupts, and then check again if rescheduling is needed.
|
||||||
// KScopedInterruptDisable intr_disable;
|
// KScopedInterruptDisable intr_disable;
|
||||||
|
|
||||||
m_kernel.CurrentScheduler()->RescheduleCurrentCoreImpl();
|
kernel.CurrentScheduler()->RescheduleCurrentCoreImpl(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::RescheduleCurrentCoreImpl() {
|
void KScheduler::RescheduleCurrentCoreImpl(KernelCore& kernel) {
|
||||||
// Check that scheduling is needed.
|
// Check that scheduling is needed.
|
||||||
if (m_state.needs_scheduling.load()) [[likely]] {
|
if (m_state.needs_scheduling.load()) [[likely]] {
|
||||||
GetCurrentThread(m_kernel).DisableDispatch();
|
GetCurrentThread(kernel).DisableDispatch(kernel);
|
||||||
Schedule();
|
Schedule(kernel);
|
||||||
GetCurrentThread(m_kernel).EnableDispatch();
|
GetCurrentThread(kernel).EnableDispatch(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::Initialize(KThread* main_thread, KThread* idle_thread, s32 core_id) {
|
void KScheduler::Initialize(KernelCore& kernel, KThread* main_thread, KThread* idle_thread, s32 core_id) {
|
||||||
// Set core ID/idle thread/interrupt task manager.
|
// Set core ID/idle thread/interrupt task manager.
|
||||||
m_core_id = core_id;
|
m_core_id = core_id;
|
||||||
m_idle_thread = idle_thread;
|
m_idle_thread = idle_thread;
|
||||||
@@ -156,39 +154,39 @@ void KScheduler::Initialize(KThread* main_thread, KThread* idle_thread, s32 core
|
|||||||
|
|
||||||
// Insert the main thread into the priority queue.
|
// Insert the main thread into the priority queue.
|
||||||
// {
|
// {
|
||||||
// KScopedSchedulerLock lk{m_kernel};
|
// KScopedSchedulerLock lk{kernel};
|
||||||
// GetPriorityQueue(m_kernel).PushBack(GetCurrentThreadPointer(m_kernel));
|
// GetPriorityQueue(kernel).PushBack(GetCurrentThreadPointer(kernel));
|
||||||
// SetSchedulerUpdateNeeded(m_kernel);
|
// SetSchedulerUpdateNeeded(kernel);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Bind interrupt handler.
|
// Bind interrupt handler.
|
||||||
// kernel.GetInterruptManager().BindHandler(
|
// kernel.GetInterruptManager().BindHandler(
|
||||||
// GetSchedulerInterruptHandler(m_kernel), KInterruptName::Scheduler, m_core_id,
|
// GetSchedulerInterruptHandler(kernel), KInterruptName::Scheduler, m_core_id,
|
||||||
// KInterruptController::PriorityLevel::Scheduler, false, false);
|
// KInterruptController::PriorityLevel::Scheduler, false, false);
|
||||||
|
|
||||||
// Set the current thread.
|
// Set the current thread.
|
||||||
m_current_thread = main_thread;
|
m_current_thread = main_thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::Activate() {
|
void KScheduler::Activate(KernelCore& kernel) {
|
||||||
ASSERT(GetCurrentThread(m_kernel).GetDisableDispatchCount() == 1);
|
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() == 1);
|
||||||
|
|
||||||
// m_state.should_count_idle = KTargetSystem::IsDebugMode();
|
// m_state.should_count_idle = KTargetSystem::IsDebugMode();
|
||||||
m_is_active = true;
|
m_is_active = true;
|
||||||
RescheduleCurrentCore();
|
RescheduleCurrentCore(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::OnThreadStart() {
|
void KScheduler::OnThreadStart(KernelCore& kernel) {
|
||||||
GetCurrentThread(m_kernel).EnableDispatch();
|
GetCurrentThread(kernel).EnableDispatch(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 KScheduler::UpdateHighestPriorityThread(KThread* highest_thread) {
|
u64 KScheduler::UpdateHighestPriorityThread(KernelCore& kernel, KThread* highest_thread) {
|
||||||
if (KThread* prev_highest_thread = m_state.highest_priority_thread;
|
if (KThread* prev_highest_thread = m_state.highest_priority_thread;
|
||||||
prev_highest_thread != highest_thread) [[likely]] {
|
prev_highest_thread != highest_thread) [[likely]] {
|
||||||
if (prev_highest_thread != nullptr) [[likely]] {
|
if (prev_highest_thread != nullptr) [[likely]] {
|
||||||
IncrementScheduledCount(prev_highest_thread);
|
IncrementScheduledCount(prev_highest_thread);
|
||||||
prev_highest_thread->SetLastScheduledTick(
|
prev_highest_thread->SetLastScheduledTick(
|
||||||
m_kernel.System().CoreTiming().GetClockTicks());
|
kernel.System().CoreTiming().GetClockTicks());
|
||||||
}
|
}
|
||||||
if (m_state.should_count_idle) {
|
if (m_state.should_count_idle) {
|
||||||
if (highest_thread != nullptr) [[likely]] {
|
if (highest_thread != nullptr) [[likely]] {
|
||||||
@@ -245,8 +243,7 @@ u64 KScheduler::UpdateHighestPriorityThreadsImpl(KernelCore& kernel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
top_threads[core_id] = top_thread;
|
top_threads[core_id] = top_thread;
|
||||||
cores_needing_scheduling |=
|
cores_needing_scheduling |= kernel.Scheduler(core_id).UpdateHighestPriorityThread(kernel, top_threads[core_id]);
|
||||||
kernel.Scheduler(core_id).UpdateHighestPriorityThread(top_threads[core_id]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Idle cores are bad. We're going to try to migrate threads to each idle core in turn.
|
// Idle cores are bad. We're going to try to migrate threads to each idle core in turn.
|
||||||
@@ -274,8 +271,7 @@ u64 KScheduler::UpdateHighestPriorityThreadsImpl(KernelCore& kernel) {
|
|||||||
suggested->SetActiveCore(core_id);
|
suggested->SetActiveCore(core_id);
|
||||||
priority_queue.ChangeCore(suggested_core, suggested);
|
priority_queue.ChangeCore(suggested_core, suggested);
|
||||||
top_threads[core_id] = suggested;
|
top_threads[core_id] = suggested;
|
||||||
cores_needing_scheduling |=
|
cores_needing_scheduling |= kernel.Scheduler(core_id).UpdateHighestPriorityThread(kernel, top_threads[core_id]);
|
||||||
kernel.Scheduler(core_id).UpdateHighestPriorityThread(top_threads[core_id]);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,17 +294,13 @@ u64 KScheduler::UpdateHighestPriorityThreadsImpl(KernelCore& kernel) {
|
|||||||
// The candidate core can run some other thread! We'll migrate its current
|
// The candidate core can run some other thread! We'll migrate its current
|
||||||
// top thread to us.
|
// top thread to us.
|
||||||
top_threads[candidate_core] = next_on_candidate_core;
|
top_threads[candidate_core] = next_on_candidate_core;
|
||||||
cores_needing_scheduling |=
|
cores_needing_scheduling |= kernel.Scheduler(candidate_core).UpdateHighestPriorityThread(kernel, top_threads[candidate_core]);
|
||||||
kernel.Scheduler(candidate_core)
|
|
||||||
.UpdateHighestPriorityThread(top_threads[candidate_core]);
|
|
||||||
|
|
||||||
// Perform the migration.
|
// Perform the migration.
|
||||||
suggested->SetActiveCore(core_id);
|
suggested->SetActiveCore(core_id);
|
||||||
priority_queue.ChangeCore(candidate_core, suggested);
|
priority_queue.ChangeCore(candidate_core, suggested);
|
||||||
top_threads[core_id] = suggested;
|
top_threads[core_id] = suggested;
|
||||||
cores_needing_scheduling |=
|
cores_needing_scheduling |= kernel.Scheduler(core_id).UpdateHighestPriorityThread(kernel, top_threads[core_id]);
|
||||||
kernel.Scheduler(core_id).UpdateHighestPriorityThread(
|
|
||||||
top_threads[core_id]);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -319,21 +311,21 @@ u64 KScheduler::UpdateHighestPriorityThreadsImpl(KernelCore& kernel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HACK: any waiting dummy threads can wake up now.
|
// 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
|
// HACK: if we are a dummy thread, and we need to go sleep, indicate
|
||||||
// that for when the lock is released.
|
// that for when the lock is released.
|
||||||
KThread* const cur_thread = GetCurrentThreadPointer(kernel);
|
KThread* const cur_thread = GetCurrentThreadPointer(kernel);
|
||||||
if (cur_thread->IsDummyThread() && cur_thread->GetState() != ThreadState::Runnable) {
|
if (cur_thread->IsDummyThread() && cur_thread->GetState() != ThreadState::Runnable) {
|
||||||
cur_thread->RequestDummyThreadWait();
|
cur_thread->RequestDummyThreadWait(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cores_needing_scheduling;
|
return cores_needing_scheduling;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::SwitchThread(KThread* next_thread) {
|
void KScheduler::SwitchThread(KernelCore& kernel, KThread* next_thread) {
|
||||||
KProcess* const cur_process = GetCurrentProcessPointer(m_kernel);
|
KProcess* const cur_process = GetCurrentProcessPointer(kernel);
|
||||||
KThread* const cur_thread = GetCurrentThreadPointer(m_kernel);
|
KThread* const cur_thread = GetCurrentThreadPointer(kernel);
|
||||||
|
|
||||||
// We never want to schedule a null thread, so use the idle thread if we don't have a next.
|
// We never want to schedule a null thread, so use the idle thread if we don't have a next.
|
||||||
if (next_thread == nullptr) {
|
if (next_thread == nullptr) {
|
||||||
@@ -355,7 +347,7 @@ void KScheduler::SwitchThread(KThread* next_thread) {
|
|||||||
|
|
||||||
// Update the CPU time tracking variables.
|
// Update the CPU time tracking variables.
|
||||||
const s64 prev_tick = m_last_context_switch_time;
|
const s64 prev_tick = m_last_context_switch_time;
|
||||||
const s64 cur_tick = m_kernel.System().CoreTiming().GetClockTicks();
|
const s64 cur_tick = kernel.System().CoreTiming().GetClockTicks();
|
||||||
const s64 tick_diff = cur_tick - prev_tick;
|
const s64 tick_diff = cur_tick - prev_tick;
|
||||||
cur_thread->AddCpuTime(m_core_id, tick_diff);
|
cur_thread->AddCpuTime(m_core_id, tick_diff);
|
||||||
if (cur_process != nullptr) {
|
if (cur_process != nullptr) {
|
||||||
@@ -379,23 +371,23 @@ void KScheduler::SwitchThread(KThread* next_thread) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// Set the new thread.
|
// Set the new thread.
|
||||||
SetCurrentThread(m_kernel, next_thread);
|
SetCurrentThread(kernel, next_thread);
|
||||||
m_current_thread = next_thread;
|
m_current_thread = next_thread;
|
||||||
|
|
||||||
// Set the new Thread Local region.
|
// Set the new Thread Local region.
|
||||||
// cpu::SwitchThreadLocalRegion(GetInteger(next_thread->GetThreadLocalRegionAddress()));
|
// cpu::SwitchThreadLocalRegion(GetInteger(next_thread->GetThreadLocalRegionAddress()));
|
||||||
|
|
||||||
// Update the thread's cpu time differential in TLS, if relevant.
|
// Update the thread's cpu time differential in TLS, if relevant.
|
||||||
next_thread->UpdateTlsThreadCpuTime(cur_tick);
|
next_thread->UpdateTlsThreadCpuTime(kernel, cur_tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::ScheduleImpl() {
|
void KScheduler::ScheduleImpl(KernelCore& kernel) {
|
||||||
// First, clear the needs scheduling bool.
|
// First, clear the needs scheduling bool.
|
||||||
m_state.needs_scheduling.store(false, std::memory_order_relaxed);
|
m_state.needs_scheduling.store(false, std::memory_order_relaxed);
|
||||||
std::atomic_thread_fence(std::memory_order_seq_cst);
|
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||||
|
|
||||||
// Load the appropriate thread pointers for scheduling.
|
// Load the appropriate thread pointers for scheduling.
|
||||||
KThread* const cur_thread{GetCurrentThreadPointer(m_kernel)};
|
KThread* const cur_thread{GetCurrentThreadPointer(kernel)};
|
||||||
KThread* highest_priority_thread{m_state.highest_priority_thread};
|
KThread* highest_priority_thread{m_state.highest_priority_thread};
|
||||||
|
|
||||||
// Check whether there are runnable interrupt tasks.
|
// Check whether there are runnable interrupt tasks.
|
||||||
@@ -423,7 +415,7 @@ void KScheduler::ScheduleImpl() {
|
|||||||
// Returning from ScheduleImpl occurs after this thread has been scheduled again.
|
// Returning from ScheduleImpl occurs after this thread has been scheduled again.
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::ScheduleImplFiber() {
|
void KScheduler::ScheduleImplFiber(KernelCore& kernel) {
|
||||||
KThread* const cur_thread{m_switch_cur_thread};
|
KThread* const cur_thread{m_switch_cur_thread};
|
||||||
KThread* highest_priority_thread{m_switch_highest_priority_thread};
|
KThread* highest_priority_thread{m_switch_highest_priority_thread};
|
||||||
|
|
||||||
@@ -437,7 +429,7 @@ void KScheduler::ScheduleImplFiber() {
|
|||||||
m_switch_from_schedule = false;
|
m_switch_from_schedule = false;
|
||||||
|
|
||||||
// Save the original thread context.
|
// Save the original thread context.
|
||||||
Unload(cur_thread);
|
Unload(kernel, cur_thread);
|
||||||
|
|
||||||
// The current thread's context has been entirely taken care of.
|
// The current thread's context has been entirely taken care of.
|
||||||
// Now we want to loop until we successfully switch the thread context.
|
// Now we want to loop until we successfully switch the thread context.
|
||||||
@@ -468,7 +460,7 @@ void KScheduler::ScheduleImplFiber() {
|
|||||||
|
|
||||||
// It's time to switch the thread.
|
// It's time to switch the thread.
|
||||||
// Switch to the highest priority thread.
|
// Switch to the highest priority thread.
|
||||||
SwitchThread(highest_priority_thread);
|
SwitchThread(kernel, highest_priority_thread);
|
||||||
|
|
||||||
// Check if we need scheduling. If we do, then we can't complete the switch and should
|
// Check if we need scheduling. If we do, then we can't complete the switch and should
|
||||||
// retry.
|
// retry.
|
||||||
@@ -493,14 +485,14 @@ void KScheduler::ScheduleImplFiber() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reload the guest thread context.
|
// Reload the guest thread context.
|
||||||
Reload(highest_priority_thread);
|
Reload(kernel, highest_priority_thread);
|
||||||
|
|
||||||
// Reload the host thread.
|
// Reload the host thread.
|
||||||
Common::Fiber::YieldTo(m_switch_fiber, *highest_priority_thread->m_host_context);
|
Common::Fiber::YieldTo(m_switch_fiber, *highest_priority_thread->m_host_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::Unload(KThread* thread) {
|
void KScheduler::Unload(KernelCore& kernel, KThread* thread) {
|
||||||
m_kernel.PhysicalCore(m_core_id).SaveContext(thread);
|
kernel.PhysicalCore(m_core_id).SaveContext(thread);
|
||||||
|
|
||||||
// Check if the thread is terminated by checking the DPC flags.
|
// Check if the thread is terminated by checking the DPC flags.
|
||||||
if ((thread->GetStackParameters().dpc_flags & static_cast<u32>(DpcFlag::Terminated)) == 0) {
|
if ((thread->GetStackParameters().dpc_flags & static_cast<u32>(DpcFlag::Terminated)) == 0) {
|
||||||
@@ -509,8 +501,8 @@ void KScheduler::Unload(KThread* thread) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::Reload(KThread* thread) {
|
void KScheduler::Reload(KernelCore& kernel, KThread* thread) {
|
||||||
m_kernel.PhysicalCore(m_core_id).LoadContext(thread);
|
kernel.PhysicalCore(m_core_id).LoadContext(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::ClearPreviousThread(KernelCore& kernel, KThread* thread) {
|
void KScheduler::ClearPreviousThread(KernelCore& kernel, KThread* thread) {
|
||||||
@@ -877,9 +869,9 @@ void KScheduler::YieldToAnyThread(KernelCore& kernel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::RescheduleOtherCores(u64 cores_needing_scheduling) {
|
void KScheduler::RescheduleOtherCores(KernelCore& kernel, u64 cores_needing_scheduling) {
|
||||||
if (const u64 core_mask = cores_needing_scheduling & ~(1ULL << m_core_id); core_mask != 0) {
|
if (const u64 core_mask = cores_needing_scheduling & ~(1ULL << m_core_id); core_mask != 0) {
|
||||||
RescheduleCores(m_kernel, core_mask);
|
RescheduleCores(kernel, core_mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -41,15 +44,15 @@ public:
|
|||||||
explicit KScheduler(KernelCore& kernel);
|
explicit KScheduler(KernelCore& kernel);
|
||||||
~KScheduler();
|
~KScheduler();
|
||||||
|
|
||||||
void Initialize(KThread* main_thread, KThread* idle_thread, s32 core_id);
|
void Initialize(KernelCore& kernel, KThread* main_thread, KThread* idle_thread, s32 core_id);
|
||||||
void Activate();
|
void Activate(KernelCore& kernel);
|
||||||
void OnThreadStart();
|
void OnThreadStart(KernelCore& kernel);
|
||||||
void Unload(KThread* thread);
|
void Unload(KernelCore& kernel, KThread* thread);
|
||||||
void Reload(KThread* thread);
|
void Reload(KernelCore& kernel, KThread* thread);
|
||||||
|
|
||||||
void SetInterruptTaskRunnable();
|
void SetInterruptTaskRunnable(KernelCore& kernel);
|
||||||
void RequestScheduleOnInterrupt();
|
void RequestScheduleOnInterrupt(KernelCore& kernel);
|
||||||
void PreemptSingleCore();
|
void PreemptSingleCore(KernelCore& kernel);
|
||||||
|
|
||||||
u64 GetIdleCount() {
|
u64 GetIdleCount() {
|
||||||
return m_state.idle_count;
|
return m_state.idle_count;
|
||||||
@@ -122,18 +125,18 @@ private:
|
|||||||
static void RescheduleCurrentHLEThread(KernelCore& kernel);
|
static void RescheduleCurrentHLEThread(KernelCore& kernel);
|
||||||
|
|
||||||
// Instanced private API.
|
// Instanced private API.
|
||||||
void ScheduleImpl();
|
void ScheduleImpl(KernelCore& kernel);
|
||||||
void ScheduleImplFiber();
|
void ScheduleImplFiber(KernelCore& kernel);
|
||||||
void SwitchThread(KThread* next_thread);
|
void SwitchThread(KernelCore& kernel, KThread* next_thread);
|
||||||
|
|
||||||
void Schedule();
|
void Schedule(KernelCore& kernel);
|
||||||
void ScheduleOnInterrupt();
|
void ScheduleOnInterrupt(KernelCore& kernel);
|
||||||
|
|
||||||
void RescheduleOtherCores(u64 cores_needing_scheduling);
|
void RescheduleOtherCores(KernelCore& kernel, u64 cores_needing_scheduling);
|
||||||
void RescheduleCurrentCore();
|
void RescheduleCurrentCore(KernelCore& kernel);
|
||||||
void RescheduleCurrentCoreImpl();
|
void RescheduleCurrentCoreImpl(KernelCore& kernel);
|
||||||
|
|
||||||
u64 UpdateHighestPriorityThread(KThread* thread);
|
u64 UpdateHighestPriorityThread(KernelCore& kernel, KThread* thread);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class KScopedDisableDispatch;
|
friend class KScopedDisableDispatch;
|
||||||
@@ -149,14 +152,12 @@ private:
|
|||||||
KInterruptTaskManager* interrupt_task_manager{nullptr};
|
KInterruptTaskManager* interrupt_task_manager{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
KernelCore& m_kernel;
|
|
||||||
SchedulingState m_state;
|
SchedulingState m_state;
|
||||||
bool m_is_active{false};
|
bool m_is_active{false};
|
||||||
s32 m_core_id{0};
|
s32 m_core_id{0};
|
||||||
s64 m_last_context_switch_time{0};
|
s64 m_last_context_switch_time{0};
|
||||||
KThread* m_idle_thread{nullptr};
|
KThread* m_idle_thread{nullptr};
|
||||||
std::atomic<KThread*> m_current_thread{nullptr};
|
std::atomic<KThread*> m_current_thread{nullptr};
|
||||||
|
|
||||||
std::shared_ptr<Common::Fiber> m_switch_fiber{};
|
std::shared_ptr<Common::Fiber> m_switch_fiber{};
|
||||||
KThread* m_switch_cur_thread{};
|
KThread* m_switch_cur_thread{};
|
||||||
KThread* m_switch_highest_priority_thread{};
|
KThread* m_switch_highest_priority_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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -11,34 +14,42 @@ namespace Kernel {
|
|||||||
|
|
||||||
class KScopedResourceReservation {
|
class KScopedResourceReservation {
|
||||||
public:
|
public:
|
||||||
explicit KScopedResourceReservation(KResourceLimit* l, LimitableResource r, s64 v, s64 timeout)
|
explicit KScopedResourceReservation(KernelCore& kernel, KResourceLimit* l, LimitableResource r, s64 v, s64 timeout)
|
||||||
: m_limit(l), m_value(v), m_resource(r) {
|
: m_kernel{kernel}
|
||||||
|
, m_limit(l)
|
||||||
|
, m_value(v)
|
||||||
|
, m_resource(r)
|
||||||
|
{
|
||||||
if (m_limit && m_value) {
|
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 {
|
} else {
|
||||||
m_succeeded = true;
|
m_succeeded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit KScopedResourceReservation(KResourceLimit* l, LimitableResource r, s64 v = 1)
|
explicit KScopedResourceReservation(KernelCore& kernel, KResourceLimit* l, LimitableResource r, s64 v = 1)
|
||||||
: m_limit(l), m_value(v), m_resource(r) {
|
: m_kernel{kernel}
|
||||||
|
, m_limit(l)
|
||||||
|
, m_value(v)
|
||||||
|
, m_resource(r)
|
||||||
|
{
|
||||||
if (m_limit && m_value) {
|
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 {
|
} else {
|
||||||
m_succeeded = true;
|
m_succeeded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit KScopedResourceReservation(const KProcess* p, LimitableResource r, s64 v, s64 t)
|
explicit KScopedResourceReservation(KernelCore& kernel, const KProcess* p, LimitableResource r, s64 v, s64 t)
|
||||||
: KScopedResourceReservation(p->GetResourceLimit(), r, v, t) {}
|
: KScopedResourceReservation(kernel, p->GetResourceLimit(), r, v, t) {}
|
||||||
|
|
||||||
explicit KScopedResourceReservation(const KProcess* p, LimitableResource r, s64 v = 1)
|
explicit KScopedResourceReservation(KernelCore& kernel, const KProcess* p, LimitableResource r, s64 v = 1)
|
||||||
: KScopedResourceReservation(p->GetResourceLimit(), r, v) {}
|
: KScopedResourceReservation(kernel, p->GetResourceLimit(), r, v) {}
|
||||||
|
|
||||||
~KScopedResourceReservation() noexcept {
|
~KScopedResourceReservation() noexcept {
|
||||||
if (m_limit && m_value && m_succeeded) {
|
if (m_limit && m_value && m_succeeded) {
|
||||||
// Resource was not committed, release the reservation.
|
// 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:
|
private:
|
||||||
|
KernelCore& m_kernel;
|
||||||
KResourceLimit* m_limit{};
|
KResourceLimit* m_limit{};
|
||||||
s64 m_value{};
|
s64 m_value{};
|
||||||
LimitableResource m_resource{};
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -15,18 +18,18 @@ namespace Kernel {
|
|||||||
KServerPort::KServerPort(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
KServerPort::KServerPort(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
||||||
KServerPort::~KServerPort() = default;
|
KServerPort::~KServerPort() = default;
|
||||||
|
|
||||||
void KServerPort::Initialize(KPort* parent) {
|
void KServerPort::Initialize(KernelCore& kernel, KPort* parent) {
|
||||||
// Set member variables.
|
// Set member variables.
|
||||||
m_parent = parent;
|
m_parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KServerPort::IsLight() const {
|
bool KServerPort::IsLight(KernelCore& kernel) const {
|
||||||
return this->GetParent()->IsLight();
|
return this->GetParent()->IsLight();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KServerPort::CleanupSessions() {
|
void KServerPort::CleanupSessions(KernelCore& kernel) {
|
||||||
// Ensure our preconditions are met.
|
// Ensure our preconditions are met.
|
||||||
if (this->IsLight()) {
|
if (this->IsLight(kernel)) {
|
||||||
ASSERT(m_session_list.empty());
|
ASSERT(m_session_list.empty());
|
||||||
} else {
|
} else {
|
||||||
ASSERT(m_light_session_list.empty());
|
ASSERT(m_light_session_list.empty());
|
||||||
@@ -37,7 +40,7 @@ void KServerPort::CleanupSessions() {
|
|||||||
// Get the last session in the list.
|
// Get the last session in the list.
|
||||||
KServerSession* session = nullptr;
|
KServerSession* session = nullptr;
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
if (!m_session_list.empty()) {
|
if (!m_session_list.empty()) {
|
||||||
session = std::addressof(m_session_list.front());
|
session = std::addressof(m_session_list.front());
|
||||||
m_session_list.pop_front();
|
m_session_list.pop_front();
|
||||||
@@ -46,7 +49,7 @@ void KServerPort::CleanupSessions() {
|
|||||||
|
|
||||||
// Close the session.
|
// Close the session.
|
||||||
if (session != nullptr) {
|
if (session != nullptr) {
|
||||||
session->Close();
|
session->Close(kernel);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -57,7 +60,7 @@ void KServerPort::CleanupSessions() {
|
|||||||
// Get the last session in the list.
|
// Get the last session in the list.
|
||||||
KLightServerSession* session = nullptr;
|
KLightServerSession* session = nullptr;
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
if (!m_light_session_list.empty()) {
|
if (!m_light_session_list.empty()) {
|
||||||
session = std::addressof(m_light_session_list.front());
|
session = std::addressof(m_light_session_list.front());
|
||||||
m_light_session_list.pop_front();
|
m_light_session_list.pop_front();
|
||||||
@@ -66,60 +69,60 @@ void KServerPort::CleanupSessions() {
|
|||||||
|
|
||||||
// Close the session.
|
// Close the session.
|
||||||
if (session != nullptr) {
|
if (session != nullptr) {
|
||||||
session->Close();
|
session->Close(kernel);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KServerPort::Destroy() {
|
void KServerPort::Destroy(KernelCore& kernel) {
|
||||||
// Note with our parent that we're closed.
|
// Note with our parent that we're closed.
|
||||||
m_parent->OnServerClosed();
|
m_parent->OnServerClosed(kernel);
|
||||||
|
|
||||||
// Perform necessary cleanup of our session lists.
|
// Perform necessary cleanup of our session lists.
|
||||||
this->CleanupSessions();
|
this->CleanupSessions(kernel);
|
||||||
|
|
||||||
// Close our reference to our parent.
|
// Close our reference to our parent.
|
||||||
m_parent->Close();
|
m_parent->Close(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KServerPort::IsSignaled() const {
|
bool KServerPort::IsSignaled(KernelCore& kernel) const {
|
||||||
if (this->IsLight()) {
|
if (this->IsLight(kernel)) {
|
||||||
return !m_light_session_list.empty();
|
return !m_light_session_list.empty();
|
||||||
} else {
|
} else {
|
||||||
return !m_session_list.empty();
|
return !m_session_list.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KServerPort::EnqueueSession(KServerSession* session) {
|
void KServerPort::EnqueueSession(KernelCore& kernel, KServerSession* session) {
|
||||||
ASSERT(!this->IsLight());
|
ASSERT(!this->IsLight(kernel));
|
||||||
|
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
// Add the session to our queue.
|
// Add the session to our queue.
|
||||||
m_session_list.push_back(*session);
|
m_session_list.push_back(*session);
|
||||||
if (m_session_list.size() == 1) {
|
if (m_session_list.size() == 1) {
|
||||||
this->NotifyAvailable();
|
this->NotifyAvailable(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KServerPort::EnqueueSession(KLightServerSession* session) {
|
void KServerPort::EnqueueSession(KernelCore& kernel, KLightServerSession* session) {
|
||||||
ASSERT(this->IsLight());
|
ASSERT(this->IsLight(kernel));
|
||||||
|
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
// Add the session to our queue.
|
// Add the session to our queue.
|
||||||
m_light_session_list.push_back(*session);
|
m_light_session_list.push_back(*session);
|
||||||
if (m_light_session_list.size() == 1) {
|
if (m_light_session_list.size() == 1) {
|
||||||
this->NotifyAvailable();
|
this->NotifyAvailable(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KServerSession* KServerPort::AcceptSession() {
|
KServerSession* KServerPort::AcceptSession(KernelCore& kernel) {
|
||||||
ASSERT(!this->IsLight());
|
ASSERT(!this->IsLight(kernel));
|
||||||
|
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
// Return the first session in the list.
|
// Return the first session in the list.
|
||||||
if (m_session_list.empty()) {
|
if (m_session_list.empty()) {
|
||||||
@@ -131,10 +134,10 @@ KServerSession* KServerPort::AcceptSession() {
|
|||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
KLightServerSession* KServerPort::AcceptLightSession() {
|
KLightServerSession* KServerPort::AcceptLightSession(KernelCore& kernel) {
|
||||||
ASSERT(this->IsLight());
|
ASSERT(this->IsLight(kernel));
|
||||||
|
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
// Return the first session in the list.
|
// Return the first session in the list.
|
||||||
if (m_light_session_list.empty()) {
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -26,29 +29,29 @@ public:
|
|||||||
explicit KServerPort(KernelCore& kernel);
|
explicit KServerPort(KernelCore& kernel);
|
||||||
~KServerPort() override;
|
~KServerPort() override;
|
||||||
|
|
||||||
void Initialize(KPort* parent);
|
void Initialize(KernelCore& kernel, KPort* parent);
|
||||||
|
|
||||||
void EnqueueSession(KServerSession* session);
|
void EnqueueSession(KernelCore& kernel, KServerSession* session);
|
||||||
void EnqueueSession(KLightServerSession* session);
|
void EnqueueSession(KernelCore& kernel, KLightServerSession* session);
|
||||||
|
|
||||||
KServerSession* AcceptSession();
|
KServerSession* AcceptSession(KernelCore& kernel);
|
||||||
KLightServerSession* AcceptLightSession();
|
KLightServerSession* AcceptLightSession(KernelCore& kernel);
|
||||||
|
|
||||||
const KPort* GetParent() const {
|
const KPort* GetParent() const {
|
||||||
return m_parent;
|
return m_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsLight() const;
|
bool IsLight(KernelCore& kernel) const;
|
||||||
|
|
||||||
// Overridden virtual functions.
|
// Overridden virtual functions.
|
||||||
void Destroy() override;
|
void Destroy(KernelCore& kernel) override;
|
||||||
bool IsSignaled() const override;
|
bool IsSignaled(KernelCore& kernel) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using SessionList = Common::IntrusiveListBaseTraits<KServerSession>::ListType;
|
using SessionList = Common::IntrusiveListBaseTraits<KServerSession>::ListType;
|
||||||
using LightSessionList = Common::IntrusiveListBaseTraits<KLightServerSession>::ListType;
|
using LightSessionList = Common::IntrusiveListBaseTraits<KLightServerSession>::ListType;
|
||||||
|
|
||||||
void CleanupSessions();
|
void CleanupSessions(KernelCore& kernel);
|
||||||
|
|
||||||
SessionList m_session_list{};
|
SessionList m_session_list{};
|
||||||
LightSessionList m_light_session_list{};
|
LightSessionList m_light_session_list{};
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <bool MoveHandleAllowed>
|
template <bool MoveHandleAllowed>
|
||||||
Result ProcessMessageSpecialData(s32& offset, KProcess& dst_process, KProcess& src_process,
|
Result ProcessMessageSpecialData(KernelCore& kernel, s32& offset, KProcess& dst_process, KProcess& src_process,
|
||||||
KThread& src_thread, const MessageBuffer& dst_msg,
|
KThread& src_thread, const MessageBuffer& dst_msg,
|
||||||
const MessageBuffer& src_msg,
|
const MessageBuffer& src_msg,
|
||||||
const MessageBuffer::SpecialHeader& src_special_header) {
|
const MessageBuffer::SpecialHeader& src_special_header) {
|
||||||
@@ -185,10 +185,9 @@ Result ProcessMessageSpecialData(s32& offset, KProcess& dst_process, KProcess& s
|
|||||||
// If we're in a success state, try to move the handle to the new table.
|
// If we're in a success state, try to move the handle to the new table.
|
||||||
if (R_SUCCEEDED(result) && src_handle != Svc::InvalidHandle) {
|
if (R_SUCCEEDED(result) && src_handle != Svc::InvalidHandle) {
|
||||||
KScopedAutoObject obj =
|
KScopedAutoObject obj =
|
||||||
src_handle_table.GetObjectForIpc(src_handle, std::addressof(src_thread));
|
src_handle_table.GetObjectForIpc(kernel, src_handle, std::addressof(src_thread));
|
||||||
if (obj.IsNotNull()) {
|
if (obj.IsNotNull()) {
|
||||||
Result add_result =
|
Result add_result = dst_handle_table.Add(kernel, std::addressof(dst_handle), obj.GetPointerUnsafe());
|
||||||
dst_handle_table.Add(std::addressof(dst_handle), obj.GetPointerUnsafe());
|
|
||||||
if (R_FAILED(add_result)) {
|
if (R_FAILED(add_result)) {
|
||||||
result = add_result;
|
result = add_result;
|
||||||
dst_handle = Svc::InvalidHandle;
|
dst_handle = Svc::InvalidHandle;
|
||||||
@@ -213,12 +212,10 @@ Result ProcessMessageSpecialData(s32& offset, KProcess& dst_process, KProcess& s
|
|||||||
if (src_handle != Svc::InvalidHandle) {
|
if (src_handle != Svc::InvalidHandle) {
|
||||||
if (R_SUCCEEDED(result)) {
|
if (R_SUCCEEDED(result)) {
|
||||||
KScopedAutoObject obj =
|
KScopedAutoObject obj =
|
||||||
src_handle_table.GetObjectForIpcWithoutPseudoHandle(src_handle);
|
src_handle_table.GetObjectForIpcWithoutPseudoHandle(kernel, src_handle);
|
||||||
if (obj.IsNotNull()) {
|
if (obj.IsNotNull()) {
|
||||||
Result add_result = dst_handle_table.Add(std::addressof(dst_handle),
|
Result add_result = dst_handle_table.Add(kernel, std::addressof(dst_handle), obj.GetPointerUnsafe());
|
||||||
obj.GetPointerUnsafe());
|
src_handle_table.Remove(kernel, src_handle);
|
||||||
|
|
||||||
src_handle_table.Remove(src_handle);
|
|
||||||
|
|
||||||
if (R_FAILED(add_result)) {
|
if (R_FAILED(add_result)) {
|
||||||
result = add_result;
|
result = add_result;
|
||||||
@@ -228,7 +225,7 @@ Result ProcessMessageSpecialData(s32& offset, KProcess& dst_process, KProcess& s
|
|||||||
result = ResultInvalidHandle;
|
result = ResultInvalidHandle;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
src_handle_table.Remove(src_handle);
|
src_handle_table.Remove(kernel, src_handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,7 +333,7 @@ constexpr Result GetMapAliasTestStateAndAttributeMask(KMemoryState& out_state,
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CleanupSpecialData(KProcess& dst_process, u32* dst_msg_ptr, size_t dst_buffer_size) {
|
void CleanupSpecialData(KernelCore& kernel, KProcess& dst_process, u32* dst_msg_ptr, size_t dst_buffer_size) {
|
||||||
// Parse the message.
|
// Parse the message.
|
||||||
const MessageBuffer dst_msg(dst_msg_ptr, dst_buffer_size);
|
const MessageBuffer dst_msg(dst_msg_ptr, dst_buffer_size);
|
||||||
const MessageBuffer::MessageHeader dst_header(dst_msg);
|
const MessageBuffer::MessageHeader dst_header(dst_msg);
|
||||||
@@ -363,15 +360,14 @@ void CleanupSpecialData(KProcess& dst_process, u32* dst_msg_ptr, size_t dst_buff
|
|||||||
const Handle handle = dst_msg.GetHandle(offset);
|
const Handle handle = dst_msg.GetHandle(offset);
|
||||||
|
|
||||||
if (handle != Svc::InvalidHandle) {
|
if (handle != Svc::InvalidHandle) {
|
||||||
dst_handle_table.Remove(handle);
|
dst_handle_table.Remove(kernel, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = dst_msg.SetHandle(offset, Svc::InvalidHandle);
|
offset = dst_msg.SetHandle(offset, Svc::InvalidHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result CleanupServerHandles(KernelCore& kernel, uint64_t message, size_t buffer_size,
|
Result CleanupServerHandles(KernelCore& kernel, uint64_t message, size_t buffer_size, KPhysicalAddress message_paddr) {
|
||||||
KPhysicalAddress message_paddr) {
|
|
||||||
// Server is assumed to be current thread.
|
// Server is assumed to be current thread.
|
||||||
KThread& thread = GetCurrentThread(kernel);
|
KThread& thread = GetCurrentThread(kernel);
|
||||||
|
|
||||||
@@ -410,7 +406,7 @@ Result CleanupServerHandles(KernelCore& kernel, uint64_t message, size_t buffer_
|
|||||||
|
|
||||||
// Close the handles.
|
// Close the handles.
|
||||||
for (auto i = 0; i < special_header.GetMoveHandleCount(); ++i) {
|
for (auto i = 0; i < special_header.GetMoveHandleCount(); ++i) {
|
||||||
handle_table.Remove(msg.GetHandle(offset));
|
handle_table.Remove(kernel, msg.GetHandle(offset));
|
||||||
offset += static_cast<int>(sizeof(Svc::Handle) / sizeof(u32));
|
offset += static_cast<int>(sizeof(Svc::Handle) / sizeof(u32));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -558,7 +554,7 @@ Result ReceiveMessage(KernelCore& kernel, bool& recv_list_broken, uint64_t dst_m
|
|||||||
recv_list_broken = false;
|
recv_list_broken = false;
|
||||||
|
|
||||||
// Set the server process for the request.
|
// Set the server process for the request.
|
||||||
request->SetServerProcess(std::addressof(dst_process));
|
request->SetServerProcess(kernel, std::addressof(dst_process));
|
||||||
|
|
||||||
// Determine the message buffers.
|
// Determine the message buffers.
|
||||||
u32 *dst_msg_ptr, *src_msg_ptr;
|
u32 *dst_msg_ptr, *src_msg_ptr;
|
||||||
@@ -639,7 +635,7 @@ Result ReceiveMessage(KernelCore& kernel, bool& recv_list_broken, uint64_t dst_m
|
|||||||
|
|
||||||
// Cleanup special data.
|
// Cleanup special data.
|
||||||
if (src_header.GetHasSpecialHeader()) {
|
if (src_header.GetHasSpecialHeader()) {
|
||||||
CleanupSpecialData(dst_process, dst_msg_ptr, dst_buffer_size);
|
CleanupSpecialData(kernel, dst_process, dst_msg_ptr, dst_buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup the header if the receive list isn't broken.
|
// Cleanup the header if the receive list isn't broken.
|
||||||
@@ -661,7 +657,7 @@ Result ReceiveMessage(KernelCore& kernel, bool& recv_list_broken, uint64_t dst_m
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Process special data.
|
// Process special data.
|
||||||
R_TRY(ProcessMessageSpecialData<false>(offset, dst_process, src_process, src_thread,
|
R_TRY(ProcessMessageSpecialData<false>(kernel, offset, dst_process, src_process, src_thread,
|
||||||
dst_msg, src_msg, src_special_header));
|
dst_msg, src_msg, src_special_header));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -922,7 +918,7 @@ Result SendMessage(KernelCore& kernel, uint64_t src_message_buffer, size_t src_b
|
|||||||
// Cleanup special data.
|
// Cleanup special data.
|
||||||
if (processed_special_data) {
|
if (processed_special_data) {
|
||||||
if (src_header.GetHasSpecialHeader()) {
|
if (src_header.GetHasSpecialHeader()) {
|
||||||
CleanupSpecialData(dst_process, dst_msg_ptr, dst_buffer_size);
|
CleanupSpecialData(kernel, dst_process, dst_msg_ptr, dst_buffer_size);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CleanupServerHandles(kernel, src_user ? src_message_buffer : 0, src_buffer_size,
|
CleanupServerHandles(kernel, src_user ? src_message_buffer : 0, src_buffer_size,
|
||||||
@@ -987,7 +983,7 @@ Result SendMessage(KernelCore& kernel, uint64_t src_message_buffer, size_t src_b
|
|||||||
ASSERT(GetCurrentThreadPointer(kernel) == std::addressof(src_thread));
|
ASSERT(GetCurrentThreadPointer(kernel) == std::addressof(src_thread));
|
||||||
processed_special_data = true;
|
processed_special_data = true;
|
||||||
if (src_header.GetHasSpecialHeader()) {
|
if (src_header.GetHasSpecialHeader()) {
|
||||||
R_TRY(ProcessMessageSpecialData<true>(offset, dst_process, src_process, src_thread,
|
R_TRY(ProcessMessageSpecialData<true>(kernel, offset, dst_process, src_process, src_thread,
|
||||||
dst_msg, src_msg, src_special_header));
|
dst_msg, src_msg, src_special_header));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1080,19 +1076,17 @@ void ReplyAsyncError(KProcess* to_process, uint64_t to_msg_buf, size_t to_msg_bu
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
KServerSession::KServerSession(KernelCore& kernel)
|
KServerSession::KServerSession(KernelCore& kernel)
|
||||||
: KSynchronizationObject{kernel}, m_lock{m_kernel} {}
|
: KSynchronizationObject{kernel}, m_lock{kernel} {}
|
||||||
|
|
||||||
KServerSession::~KServerSession() = default;
|
KServerSession::~KServerSession() = default;
|
||||||
|
|
||||||
void KServerSession::Destroy() {
|
void KServerSession::Destroy(KernelCore& kernel) {
|
||||||
m_parent->OnServerClosed();
|
m_parent->OnServerClosed(kernel);
|
||||||
|
this->CleanupRequests(kernel);
|
||||||
this->CleanupRequests();
|
m_parent->Close(kernel);
|
||||||
|
|
||||||
m_parent->Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
KPhysicalAddress server_message_paddr,
|
||||||
std::shared_ptr<Service::HLERequestContext>* out_context,
|
std::shared_ptr<Service::HLERequestContext>* out_context,
|
||||||
std::weak_ptr<Service::SessionRequestManager> manager) {
|
std::weak_ptr<Service::SessionRequestManager> manager) {
|
||||||
@@ -1104,7 +1098,7 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||||||
KThread* client_thread;
|
KThread* client_thread;
|
||||||
|
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
// Ensure that we can service the request.
|
// Ensure that we can service the request.
|
||||||
R_UNLESS(!m_parent->IsClientClosed(), ResultSessionClosed);
|
R_UNLESS(!m_parent->IsClientClosed(), ResultSessionClosed);
|
||||||
@@ -1124,11 +1118,11 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||||||
R_UNLESS(client_thread != nullptr, ResultSessionClosed);
|
R_UNLESS(client_thread != nullptr, ResultSessionClosed);
|
||||||
|
|
||||||
// Open the client thread.
|
// Open the client thread.
|
||||||
client_thread->Open();
|
client_thread->Open(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
client_thread->Close();
|
client_thread->Close(kernel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set the request as our current.
|
// Set the request as our current.
|
||||||
@@ -1150,13 +1144,13 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||||||
Core::Memory::Memory& memory{client_thread->GetOwnerProcess()->GetMemory()};
|
Core::Memory::Memory& memory{client_thread->GetOwnerProcess()->GetMemory()};
|
||||||
u32* cmd_buf{reinterpret_cast<u32*>(memory.GetPointer(client_message))};
|
u32* cmd_buf{reinterpret_cast<u32*>(memory.GetPointer(client_message))};
|
||||||
*out_context =
|
*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)->SetSessionRequestManager(manager);
|
||||||
(*out_context)->PopulateFromIncomingCommandBuffer(cmd_buf);
|
(*out_context)->PopulateFromIncomingCommandBuffer(cmd_buf);
|
||||||
// We succeeded.
|
// We succeeded.
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
} else {
|
} 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,
|
server_message_paddr, *client_thread, client_message,
|
||||||
client_buffer_size, this, request);
|
client_buffer_size, this, request);
|
||||||
}
|
}
|
||||||
@@ -1168,11 +1162,11 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||||||
|
|
||||||
// Clear the current request.
|
// Clear the current request.
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl(m_kernel);
|
KScopedSchedulerLock sl(kernel);
|
||||||
ASSERT(m_current_request == request);
|
ASSERT(m_current_request == request);
|
||||||
m_current_request = nullptr;
|
m_current_request = nullptr;
|
||||||
if (!m_request_list.empty()) {
|
if (!m_request_list.empty()) {
|
||||||
this->NotifyAvailable();
|
this->NotifyAvailable(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1180,7 +1174,7 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||||||
{
|
{
|
||||||
// After we reply, close our reference to the request.
|
// After we reply, close our reference to the request.
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
request->Close();
|
request->Close(kernel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get the event to check whether the request is async.
|
// Get the event to check whether the request is async.
|
||||||
@@ -1199,13 +1193,13 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||||||
client_pt.UnlockForIpcUserBuffer(client_message, client_buffer_size);
|
client_pt.UnlockForIpcUserBuffer(client_message, client_buffer_size);
|
||||||
|
|
||||||
// Signal the event.
|
// Signal the event.
|
||||||
event->Signal();
|
event->Signal(kernel);
|
||||||
} else {
|
} else {
|
||||||
// End the client thread's wait.
|
// End the client thread's wait.
|
||||||
KScopedSchedulerLock sl(m_kernel);
|
KScopedSchedulerLock sl(kernel);
|
||||||
|
|
||||||
if (!client_thread->IsTerminationRequested()) {
|
if (!client_thread->IsTerminationRequested()) {
|
||||||
client_thread->EndWait(result_for_client);
|
client_thread->EndWait(kernel, result_for_client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1221,7 +1215,7 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
|
|||||||
R_RETURN(result);
|
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) {
|
KPhysicalAddress server_message_paddr, bool is_hle) {
|
||||||
// Lock the session.
|
// Lock the session.
|
||||||
KScopedLightLock lk{m_lock};
|
KScopedLightLock lk{m_lock};
|
||||||
@@ -1229,7 +1223,7 @@ Result KServerSession::SendReply(uintptr_t server_message, uintptr_t server_buff
|
|||||||
// Get the request.
|
// Get the request.
|
||||||
KSessionRequest* request;
|
KSessionRequest* request;
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
// Get the current request.
|
// Get the current request.
|
||||||
request = m_current_request;
|
request = m_current_request;
|
||||||
@@ -1238,13 +1232,13 @@ Result KServerSession::SendReply(uintptr_t server_message, uintptr_t server_buff
|
|||||||
// Clear the current request, since we're processing it.
|
// Clear the current request, since we're processing it.
|
||||||
m_current_request = nullptr;
|
m_current_request = nullptr;
|
||||||
if (!m_request_list.empty()) {
|
if (!m_request_list.empty()) {
|
||||||
this->NotifyAvailable();
|
this->NotifyAvailable(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close reference to the request once we're done processing it.
|
// Close reference to the request once we're done processing it.
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
request->Close();
|
request->Close(kernel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Extract relevant information from the request.
|
// Extract relevant information from the request.
|
||||||
@@ -1263,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
|
// HLE servers write directly to a pointer to the thread command buffer. Therefore
|
||||||
// the reply has already been written in this case.
|
// the reply has already been written in this case.
|
||||||
} else {
|
} 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);
|
*client_thread, client_message, client_buffer_size, this, request);
|
||||||
}
|
}
|
||||||
} else if (!is_hle) {
|
} else if (!is_hle) {
|
||||||
@@ -1275,7 +1269,7 @@ Result KServerSession::SendReply(uintptr_t server_message, uintptr_t server_buff
|
|||||||
(client_process != nullptr) ? std::addressof(client_process->GetPageTable()) : nullptr;
|
(client_process != nullptr) ? std::addressof(client_process->GetPageTable()) : nullptr;
|
||||||
|
|
||||||
// Cleanup server handles.
|
// Cleanup server handles.
|
||||||
result = CleanupServerHandles(m_kernel, server_message, server_buffer_size,
|
result = CleanupServerHandles(kernel, server_message, server_buffer_size,
|
||||||
server_message_paddr);
|
server_message_paddr);
|
||||||
|
|
||||||
// Cleanup mappings.
|
// Cleanup mappings.
|
||||||
@@ -1313,13 +1307,13 @@ Result KServerSession::SendReply(uintptr_t server_message, uintptr_t server_buff
|
|||||||
client_page_table->UnlockForIpcUserBuffer(client_message, client_buffer_size);
|
client_page_table->UnlockForIpcUserBuffer(client_message, client_buffer_size);
|
||||||
|
|
||||||
// Signal the event.
|
// Signal the event.
|
||||||
event->Signal();
|
event->Signal(kernel);
|
||||||
} else {
|
} else {
|
||||||
// End the client thread's wait.
|
// End the client thread's wait.
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
if (!client_thread->IsTerminationRequested()) {
|
if (!client_thread->IsTerminationRequested()) {
|
||||||
client_thread->EndWait(client_result);
|
client_thread->EndWait(kernel, client_result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1327,45 +1321,45 @@ Result KServerSession::SendReply(uintptr_t server_message, uintptr_t server_buff
|
|||||||
R_RETURN(result);
|
R_RETURN(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KServerSession::OnRequest(KSessionRequest* request) {
|
Result KServerSession::OnRequest(KernelCore& kernel, KSessionRequest* request) {
|
||||||
// Create the wait queue.
|
// Create the wait queue.
|
||||||
ThreadQueueImplForKServerSessionRequest wait_queue{m_kernel};
|
ThreadQueueImplForKServerSessionRequest wait_queue{kernel};
|
||||||
|
|
||||||
{
|
{
|
||||||
// Lock the scheduler.
|
// Lock the scheduler.
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
// Ensure that we can handle new requests.
|
// Ensure that we can handle new requests.
|
||||||
R_UNLESS(!m_parent->IsServerClosed(), ResultSessionClosed);
|
R_UNLESS(!m_parent->IsServerClosed(), ResultSessionClosed);
|
||||||
|
|
||||||
// Check that we're not terminating.
|
// Check that we're not terminating.
|
||||||
R_UNLESS(!GetCurrentThread(m_kernel).IsTerminationRequested(), ResultTerminationRequested);
|
R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(), ResultTerminationRequested);
|
||||||
|
|
||||||
// Get whether we're empty.
|
// Get whether we're empty.
|
||||||
const bool was_empty = m_request_list.empty();
|
const bool was_empty = m_request_list.empty();
|
||||||
|
|
||||||
// Add the request to the list.
|
// Add the request to the list.
|
||||||
request->Open();
|
request->Open(kernel);
|
||||||
m_request_list.push_back(*request);
|
m_request_list.push_back(*request);
|
||||||
|
|
||||||
// If we were empty, signal.
|
// If we were empty, signal.
|
||||||
if (was_empty) {
|
if (was_empty) {
|
||||||
this->NotifyAvailable();
|
this->NotifyAvailable(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have a request event, this is asynchronous, and we don't need to wait.
|
// If we have a request event, this is asynchronous, and we don't need to wait.
|
||||||
R_SUCCEED_IF(request->GetEvent() != nullptr);
|
R_SUCCEED_IF(request->GetEvent() != nullptr);
|
||||||
|
|
||||||
// This is a synchronous request, so we should wait for our request to complete.
|
// This is a synchronous request, so we should wait for our request to complete.
|
||||||
GetCurrentThread(m_kernel).SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::IPC);
|
GetCurrentThread(kernel).SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::IPC);
|
||||||
GetCurrentThread(m_kernel).BeginWait(std::addressof(wait_queue));
|
GetCurrentThread(kernel).BeginWait(kernel, std::addressof(wait_queue));
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetCurrentThread(m_kernel).GetWaitResult();
|
return GetCurrentThread(kernel).GetWaitResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KServerSession::IsSignaled() const {
|
bool KServerSession::IsSignaled(KernelCore& kernel) const {
|
||||||
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(m_kernel));
|
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
|
||||||
|
|
||||||
// If the client is closed, we're always signaled.
|
// If the client is closed, we're always signaled.
|
||||||
if (m_parent->IsClientClosed()) {
|
if (m_parent->IsClientClosed()) {
|
||||||
@@ -1376,7 +1370,7 @@ bool KServerSession::IsSignaled() const {
|
|||||||
return !m_request_list.empty() && m_current_request == nullptr;
|
return !m_request_list.empty() && m_current_request == nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KServerSession::CleanupRequests() {
|
void KServerSession::CleanupRequests(KernelCore& kernel) {
|
||||||
KScopedLightLock lk(m_lock);
|
KScopedLightLock lk(m_lock);
|
||||||
|
|
||||||
// Clean up any pending requests.
|
// Clean up any pending requests.
|
||||||
@@ -1384,7 +1378,7 @@ void KServerSession::CleanupRequests() {
|
|||||||
// Get the next request.
|
// Get the next request.
|
||||||
KSessionRequest* request = nullptr;
|
KSessionRequest* request = nullptr;
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
if (m_current_request) {
|
if (m_current_request) {
|
||||||
// Choose the current request if we have one.
|
// Choose the current request if we have one.
|
||||||
@@ -1404,7 +1398,7 @@ void KServerSession::CleanupRequests() {
|
|||||||
|
|
||||||
// Close a reference to the request once it's cleaned up.
|
// Close a reference to the request once it's cleaned up.
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
request->Close();
|
request->Close(kernel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Extract relevant information from the request.
|
// Extract relevant information from the request.
|
||||||
@@ -1434,20 +1428,20 @@ void KServerSession::CleanupRequests() {
|
|||||||
client_page_table->UnlockForIpcUserBuffer(client_message, client_buffer_size);
|
client_page_table->UnlockForIpcUserBuffer(client_message, client_buffer_size);
|
||||||
|
|
||||||
// Signal the event.
|
// Signal the event.
|
||||||
event->Signal();
|
event->Signal(kernel);
|
||||||
} else {
|
} else {
|
||||||
// End the client thread's wait.
|
// End the client thread's wait.
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
if (!client_thread->IsTerminationRequested()) {
|
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};
|
KScopedLightLock lk{m_lock};
|
||||||
|
|
||||||
// Handle any pending requests.
|
// Handle any pending requests.
|
||||||
@@ -1462,12 +1456,12 @@ void KServerSession::OnClientClosed() {
|
|||||||
|
|
||||||
// Get the next request.
|
// Get the next request.
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock sl{m_kernel};
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
if (m_current_request != nullptr && m_current_request != prev_request) {
|
if (m_current_request != nullptr && m_current_request != prev_request) {
|
||||||
// Set the request, open a reference as we process it.
|
// Set the request, open a reference as we process it.
|
||||||
request = m_current_request;
|
request = m_current_request;
|
||||||
request->Open();
|
request->Open(kernel);
|
||||||
cur_request = true;
|
cur_request = true;
|
||||||
|
|
||||||
// Get thread and event for the request.
|
// Get thread and event for the request.
|
||||||
@@ -1503,14 +1497,14 @@ void KServerSession::OnClientClosed() {
|
|||||||
|
|
||||||
// Ensure that we close the request when done.
|
// Ensure that we close the request when done.
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
request->Close();
|
request->Close(kernel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// If we're terminating, close a reference to the thread and event.
|
// If we're terminating, close a reference to the thread and event.
|
||||||
if (terminate) {
|
if (terminate) {
|
||||||
thread->Close();
|
thread->Close(kernel);
|
||||||
if (event != nullptr) {
|
if (event != nullptr) {
|
||||||
event->Close();
|
event->Close(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1534,12 +1528,12 @@ void KServerSession::OnClientClosed() {
|
|||||||
client_pt.UnlockForIpcUserBuffer(request->GetAddress(), request->GetSize());
|
client_pt.UnlockForIpcUserBuffer(request->GetAddress(), request->GetSize());
|
||||||
|
|
||||||
// Signal the event.
|
// Signal the event.
|
||||||
event->Signal();
|
event->Signal(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify.
|
// Notify.
|
||||||
this->NotifyAvailable(ResultSessionClosed);
|
this->NotifyAvailable(kernel, ResultSessionClosed);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace 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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -36,7 +39,7 @@ public:
|
|||||||
explicit KServerSession(KernelCore& kernel);
|
explicit KServerSession(KernelCore& kernel);
|
||||||
~KServerSession() override;
|
~KServerSession() override;
|
||||||
|
|
||||||
void Destroy() override;
|
void Destroy(KernelCore& kernel) override;
|
||||||
|
|
||||||
void Initialize(KSession* p) {
|
void Initialize(KSession* p) {
|
||||||
m_parent = p;
|
m_parent = p;
|
||||||
@@ -46,29 +49,29 @@ public:
|
|||||||
return m_parent;
|
return m_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsSignaled() const override;
|
bool IsSignaled(KernelCore& kernel) const override;
|
||||||
void OnClientClosed();
|
void OnClientClosed(KernelCore& kernel);
|
||||||
|
|
||||||
Result OnRequest(KSessionRequest* request);
|
Result OnRequest(KernelCore& kernel, KSessionRequest* request);
|
||||||
Result SendReply(uintptr_t server_message, uintptr_t server_buffer_size,
|
Result SendReply(KernelCore& kernel, uintptr_t server_message, uintptr_t server_buffer_size,
|
||||||
KPhysicalAddress server_message_paddr, bool is_hle = false);
|
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,
|
KPhysicalAddress server_message_paddr,
|
||||||
std::shared_ptr<Service::HLERequestContext>* out_context = nullptr,
|
std::shared_ptr<Service::HLERequestContext>* out_context = nullptr,
|
||||||
std::weak_ptr<Service::SessionRequestManager> manager = {});
|
std::weak_ptr<Service::SessionRequestManager> manager = {});
|
||||||
|
|
||||||
Result SendReplyHLE() {
|
Result SendReplyHLE(KernelCore& kernel) {
|
||||||
R_RETURN(this->SendReply(0, 0, 0, true));
|
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) {
|
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:
|
private:
|
||||||
/// Frees up waiting client sessions when this server session is about to die
|
/// 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 that owns this KServerSession
|
||||||
KSession* m_parent{};
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -13,12 +16,12 @@ KSession::KSession(KernelCore& kernel)
|
|||||||
: KAutoObjectWithSlabHeapAndContainer{kernel}, m_server{kernel}, m_client{kernel} {}
|
: KAutoObjectWithSlabHeapAndContainer{kernel}, m_server{kernel}, m_client{kernel} {}
|
||||||
KSession::~KSession() = default;
|
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.
|
// Increment reference count.
|
||||||
// Because reference count is one on creation, this will result
|
// Because reference count is one on creation, this will result
|
||||||
// in a reference count of two. Thus, when both server and client are closed
|
// in a reference count of two. Thus, when both server and client are closed
|
||||||
// this object will be destroyed.
|
// this object will be destroyed.
|
||||||
this->Open();
|
this->Open(kernel);
|
||||||
|
|
||||||
// Create our sub sessions.
|
// Create our sub sessions.
|
||||||
KAutoObject::Create(std::addressof(m_server));
|
KAutoObject::Create(std::addressof(m_server));
|
||||||
@@ -33,45 +36,45 @@ void KSession::Initialize(KClientPort* client_port, uintptr_t name) {
|
|||||||
m_name = name;
|
m_name = name;
|
||||||
|
|
||||||
// Set our owner process.
|
// Set our owner process.
|
||||||
m_process = GetCurrentProcessPointer(m_kernel);
|
m_process = GetCurrentProcessPointer(kernel);
|
||||||
m_process->Open();
|
m_process->Open(kernel);
|
||||||
|
|
||||||
// Set our port.
|
// Set our port.
|
||||||
m_port = client_port;
|
m_port = client_port;
|
||||||
if (m_port != nullptr) {
|
if (m_port != nullptr) {
|
||||||
m_port->Open();
|
m_port->Open(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark initialized.
|
// Mark initialized.
|
||||||
m_initialized = true;
|
m_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KSession::Finalize() {
|
void KSession::Finalize(KernelCore& kernel) {
|
||||||
if (m_port != nullptr) {
|
if (m_port != nullptr) {
|
||||||
m_port->OnSessionFinalized();
|
m_port->OnSessionFinalized(kernel);
|
||||||
m_port->Close();
|
m_port->Close(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KSession::OnServerClosed() {
|
void KSession::OnServerClosed(KernelCore& kernel) {
|
||||||
if (this->GetState() == State::Normal) {
|
if (this->GetState() == State::Normal) {
|
||||||
this->SetState(State::ServerClosed);
|
this->SetState(State::ServerClosed);
|
||||||
m_client.OnServerClosed();
|
m_client.OnServerClosed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KSession::OnClientClosed() {
|
void KSession::OnClientClosed(KernelCore& kernel) {
|
||||||
if (this->GetState() == State::Normal) {
|
if (this->GetState() == State::Normal) {
|
||||||
SetState(State::ClientClosed);
|
this->SetState(State::ClientClosed);
|
||||||
m_server.OnClientClosed();
|
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.
|
// Release the session count resource the owner process holds.
|
||||||
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
||||||
owner->GetResourceLimit()->Release(LimitableResource::SessionCountMax, 1);
|
owner->GetResourceLimit()->Release(kernel, LimitableResource::SessionCountMax, 1);
|
||||||
owner->Close();
|
owner->Close(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace 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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -21,8 +24,8 @@ public:
|
|||||||
explicit KSession(KernelCore& kernel);
|
explicit KSession(KernelCore& kernel);
|
||||||
~KSession() override;
|
~KSession() override;
|
||||||
|
|
||||||
void Initialize(KClientPort* port, uintptr_t name);
|
void Initialize(KernelCore& kernel, KClientPort* port, uintptr_t name);
|
||||||
void Finalize() override;
|
void Finalize(KernelCore& kernel) override;
|
||||||
|
|
||||||
bool IsInitialized() const override {
|
bool IsInitialized() const override {
|
||||||
return m_initialized;
|
return m_initialized;
|
||||||
@@ -32,11 +35,9 @@ public:
|
|||||||
return reinterpret_cast<uintptr_t>(m_process);
|
return reinterpret_cast<uintptr_t>(m_process);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PostDestroy(uintptr_t arg);
|
static void PostDestroy(KernelCore& kernel, uintptr_t arg);
|
||||||
|
void OnServerClosed(KernelCore& kernel);
|
||||||
void OnServerClosed();
|
void OnClientClosed(KernelCore& kernel);
|
||||||
|
|
||||||
void OnClientClosed();
|
|
||||||
|
|
||||||
bool IsServerClosed() const {
|
bool IsServerClosed() const {
|
||||||
return this->GetState() != State::Normal;
|
return this->GetState() != State::Normal;
|
||||||
@@ -46,8 +47,8 @@ public:
|
|||||||
return this->GetState() != State::Normal;
|
return this->GetState() != State::Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OnRequest(KSessionRequest* request) {
|
Result OnRequest(KernelCore& kernel, KSessionRequest* request) {
|
||||||
R_RETURN(m_server.OnRequest(request));
|
R_RETURN(m_server.OnRequest(kernel, request));
|
||||||
}
|
}
|
||||||
|
|
||||||
KClientSession& GetClientSession() {
|
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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -18,7 +21,7 @@ Result KSessionRequest::SessionMappings::PushMap(KProcessAddress client, KProces
|
|||||||
} else {
|
} else {
|
||||||
// Allocate a page for the extra mappings.
|
// Allocate a page for the extra mappings.
|
||||||
if (m_mappings == nullptr) {
|
if (m_mappings == nullptr) {
|
||||||
KPageBuffer* page_buffer = KPageBuffer::Allocate(m_kernel);
|
KPageBuffer* page_buffer = KPageBuffer::Allocate(kernel);
|
||||||
R_UNLESS(page_buffer != nullptr, ResultOutOfMemory);
|
R_UNLESS(page_buffer != nullptr, ResultOutOfMemory);
|
||||||
|
|
||||||
m_mappings = reinterpret_cast<Mapping*>(page_buffer);
|
m_mappings = reinterpret_cast<Mapping*>(page_buffer);
|
||||||
@@ -54,7 +57,7 @@ Result KSessionRequest::SessionMappings::PushExchange(KProcessAddress client,
|
|||||||
|
|
||||||
void KSessionRequest::SessionMappings::Finalize() {
|
void KSessionRequest::SessionMappings::Finalize() {
|
||||||
if (m_mappings) {
|
if (m_mappings) {
|
||||||
KPageBuffer::Free(m_kernel, reinterpret_cast<KPageBuffer*>(m_mappings));
|
KPageBuffer::Free(kernel, reinterpret_cast<KPageBuffer*>(m_mappings));
|
||||||
m_mappings = nullptr;
|
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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -56,7 +59,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SessionMappings(KernelCore& kernel) : m_kernel(kernel) {}
|
explicit SessionMappings(KernelCore& kernel_) : kernel(kernel_) {}
|
||||||
|
|
||||||
void Initialize() {}
|
void Initialize() {}
|
||||||
void Finalize();
|
void Finalize();
|
||||||
@@ -155,7 +158,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KernelCore& m_kernel;
|
KernelCore& kernel;
|
||||||
std::array<Mapping, NumStaticMappings> m_static_mappings{};
|
std::array<Mapping, NumStaticMappings> m_static_mappings{};
|
||||||
Mapping* m_mappings{};
|
Mapping* m_mappings{};
|
||||||
u8 m_num_send{};
|
u8 m_num_send{};
|
||||||
@@ -174,26 +177,26 @@ public:
|
|||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Destroy() override {
|
void Destroy(KernelCore& kernel) override {
|
||||||
this->Finalize();
|
this->Finalize(kernel);
|
||||||
KSessionRequest::Free(m_kernel, this);
|
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_mappings.Initialize();
|
||||||
|
|
||||||
m_thread = GetCurrentThreadPointer(m_kernel);
|
m_thread = GetCurrentThreadPointer(kernel);
|
||||||
m_event = event;
|
m_event = event;
|
||||||
m_address = address;
|
m_address = address;
|
||||||
m_size = size;
|
m_size = size;
|
||||||
|
|
||||||
m_thread->Open();
|
m_thread->Open(kernel);
|
||||||
if (m_event != nullptr) {
|
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 {
|
KThread* GetThread() const {
|
||||||
return m_thread;
|
return m_thread;
|
||||||
@@ -211,9 +214,9 @@ public:
|
|||||||
return m_server;
|
return m_server;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetServerProcess(KProcess* process) {
|
void SetServerProcess(KernelCore& kernel, KProcess* process) {
|
||||||
m_server = process;
|
m_server = process;
|
||||||
m_server->Open();
|
m_server->Open(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClearThread() {
|
void ClearThread() {
|
||||||
@@ -289,17 +292,16 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// NOTE: This is public and virtual in Nintendo's kernel.
|
// NOTE: This is public and virtual in Nintendo's kernel.
|
||||||
void Finalize() override {
|
void Finalize(KernelCore& kernel) override {
|
||||||
m_mappings.Finalize();
|
m_mappings.Finalize();
|
||||||
|
|
||||||
if (m_thread) {
|
if (m_thread) {
|
||||||
m_thread->Close();
|
m_thread->Close(kernel);
|
||||||
}
|
}
|
||||||
if (m_event) {
|
if (m_event) {
|
||||||
m_event->Close();
|
m_event->Close(kernel);
|
||||||
}
|
}
|
||||||
if (m_server) {
|
if (m_server) {
|
||||||
m_server->Close();
|
m_server->Close(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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-FileCopyrightText: 2014 Citra Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -15,7 +18,7 @@ namespace Kernel {
|
|||||||
KSharedMemory::KSharedMemory(KernelCore& kernel) : KAutoObjectWithSlabHeapAndContainer{kernel} {}
|
KSharedMemory::KSharedMemory(KernelCore& kernel) : KAutoObjectWithSlabHeapAndContainer{kernel} {}
|
||||||
KSharedMemory::~KSharedMemory() = default;
|
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 owner_permission,
|
||||||
Svc::MemoryPermission user_permission, std::size_t size) {
|
Svc::MemoryPermission user_permission, std::size_t size) {
|
||||||
// Set members.
|
// Set members.
|
||||||
@@ -28,11 +31,10 @@ Result KSharedMemory::Initialize(Core::DeviceMemory& device_memory, KProcess* ow
|
|||||||
const size_t num_pages = Common::DivideUp(size, PageSize);
|
const size_t num_pages = Common::DivideUp(size, PageSize);
|
||||||
|
|
||||||
// Get the resource limit.
|
// Get the resource limit.
|
||||||
KResourceLimit* reslimit = m_kernel.GetSystemResourceLimit();
|
KResourceLimit* reslimit = kernel.GetSystemResourceLimit();
|
||||||
|
|
||||||
// Reserve memory for ourselves.
|
// Reserve memory for ourselves.
|
||||||
KScopedResourceReservation memory_reservation(reslimit, LimitableResource::PhysicalMemoryMax,
|
KScopedResourceReservation memory_reservation(kernel, reslimit, LimitableResource::PhysicalMemoryMax, size);
|
||||||
size);
|
|
||||||
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
||||||
|
|
||||||
// Allocate the memory.
|
// Allocate the memory.
|
||||||
@@ -40,12 +42,11 @@ Result KSharedMemory::Initialize(Core::DeviceMemory& device_memory, KProcess* ow
|
|||||||
//! HACK: Open continuous mapping from sysmodule pool.
|
//! HACK: Open continuous mapping from sysmodule pool.
|
||||||
auto option = KMemoryManager::EncodeOption(KMemoryManager::Pool::Secure,
|
auto option = KMemoryManager::EncodeOption(KMemoryManager::Pool::Secure,
|
||||||
KMemoryManager::Direction::FromBack);
|
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);
|
R_UNLESS(m_physical_address != 0, ResultOutOfMemory);
|
||||||
|
|
||||||
//! Insert the result into our page group.
|
//! Insert the result into our page group.
|
||||||
m_page_group.emplace(m_kernel,
|
m_page_group.emplace(kernel, std::addressof(kernel.GetSystemSystemResource().GetBlockInfoManager()));
|
||||||
std::addressof(m_kernel.GetSystemSystemResource().GetBlockInfoManager()));
|
|
||||||
m_page_group->AddBlock(m_physical_address, num_pages);
|
m_page_group->AddBlock(m_physical_address, num_pages);
|
||||||
|
|
||||||
// Commit our reservation.
|
// Commit our reservation.
|
||||||
@@ -53,7 +54,7 @@ Result KSharedMemory::Initialize(Core::DeviceMemory& device_memory, KProcess* ow
|
|||||||
|
|
||||||
// Set our resource limit.
|
// Set our resource limit.
|
||||||
m_resource_limit = reslimit;
|
m_resource_limit = reslimit;
|
||||||
m_resource_limit->Open();
|
m_resource_limit->Open(kernel);
|
||||||
|
|
||||||
// Mark initialized.
|
// Mark initialized.
|
||||||
m_is_initialized = true;
|
m_is_initialized = true;
|
||||||
@@ -66,14 +67,14 @@ Result KSharedMemory::Initialize(Core::DeviceMemory& device_memory, KProcess* ow
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KSharedMemory::Finalize() {
|
void KSharedMemory::Finalize(KernelCore& kernel) {
|
||||||
// Close and finalize the page group.
|
// Close and finalize the page group.
|
||||||
m_page_group->Close();
|
m_page_group->Close(kernel);
|
||||||
m_page_group->Finalize();
|
m_page_group->Finalize();
|
||||||
|
|
||||||
// Release the memory reservation.
|
// Release the memory reservation.
|
||||||
m_resource_limit->Release(LimitableResource::PhysicalMemoryMax, m_size);
|
m_resource_limit->Release(kernel, LimitableResource::PhysicalMemoryMax, m_size);
|
||||||
m_resource_limit->Close();
|
m_resource_limit->Close(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KSharedMemory::Map(KProcess& target_process, KProcessAddress address, std::size_t map_size,
|
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-FileCopyrightText: 2014 Citra Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -26,7 +29,7 @@ public:
|
|||||||
explicit KSharedMemory(KernelCore& kernel);
|
explicit KSharedMemory(KernelCore& kernel);
|
||||||
~KSharedMemory() override;
|
~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 owner_permission_,
|
||||||
Svc::MemoryPermission user_permission_, std::size_t size_);
|
Svc::MemoryPermission user_permission_, std::size_t size_);
|
||||||
|
|
||||||
@@ -66,12 +69,12 @@ public:
|
|||||||
return m_device_memory->GetPointer<u8>(m_physical_address + offset);
|
return m_device_memory->GetPointer<u8>(m_physical_address + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Finalize() override;
|
void Finalize(KernelCore& kernel) override;
|
||||||
|
|
||||||
bool IsInitialized() const override {
|
bool IsInitialized() const override {
|
||||||
return m_is_initialized;
|
return m_is_initialized;
|
||||||
}
|
}
|
||||||
static void PostDestroy(uintptr_t arg) {}
|
static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::DeviceMemory* m_device_memory{};
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -18,12 +21,10 @@ namespace {
|
|||||||
|
|
||||||
class ThreadQueueImplForKSynchronizationObjectWait final : public KThreadQueueWithoutEndWait {
|
class ThreadQueueImplForKSynchronizationObjectWait final : public KThreadQueueWithoutEndWait {
|
||||||
public:
|
public:
|
||||||
ThreadQueueImplForKSynchronizationObjectWait(KernelCore& kernel, KSynchronizationObject** o,
|
ThreadQueueImplForKSynchronizationObjectWait(KernelCore& kernel, KSynchronizationObject** o, KSynchronizationObject::ThreadListNode* n, s32 c)
|
||||||
KSynchronizationObject::ThreadListNode* n, s32 c)
|
|
||||||
: KThreadQueueWithoutEndWait(kernel), m_objects(o), m_nodes(n), m_count(c) {}
|
: KThreadQueueWithoutEndWait(kernel), m_objects(o), m_nodes(n), m_count(c) {}
|
||||||
|
|
||||||
void NotifyAvailable(KThread* waiting_thread, KSynchronizationObject* signaled_object,
|
void NotifyAvailable(KernelCore& kernel, KThread* waiting_thread, KSynchronizationObject* signaled_object, Result wait_result) override {
|
||||||
Result wait_result) override {
|
|
||||||
// Determine the sync index, and unlink all nodes.
|
// Determine the sync index, and unlink all nodes.
|
||||||
s32 sync_index = -1;
|
s32 sync_index = -1;
|
||||||
for (auto i = 0; i < m_count; ++i) {
|
for (auto i = 0; i < m_count; ++i) {
|
||||||
@@ -43,10 +44,10 @@ public:
|
|||||||
waiting_thread->ClearCancellable();
|
waiting_thread->ClearCancellable();
|
||||||
|
|
||||||
// Invoke the base end wait handler.
|
// 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.
|
// Remove all nodes from our list.
|
||||||
for (auto i = 0; i < m_count; ++i) {
|
for (auto i = 0; i < m_count; ++i) {
|
||||||
m_objects[i]->UnlinkNode(std::addressof(m_nodes[i]));
|
m_objects[i]->UnlinkNode(std::addressof(m_nodes[i]));
|
||||||
@@ -56,7 +57,7 @@ public:
|
|||||||
waiting_thread->ClearCancellable();
|
waiting_thread->ClearCancellable();
|
||||||
|
|
||||||
// Invoke the base cancel wait handler.
|
// 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:
|
private:
|
||||||
@@ -67,9 +68,9 @@ private:
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void KSynchronizationObject::Finalize() {
|
void KSynchronizationObject::Finalize(KernelCore& kernel) {
|
||||||
this->OnFinalizeSynchronizationObject();
|
this->OnFinalizeSynchronizationObject();
|
||||||
KAutoObject::Finalize();
|
KAutoObject::Finalize(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KSynchronizationObject::Wait(KernelCore& kernel, s32* out_index,
|
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) {
|
for (auto i = 0; i < num_objects; ++i) {
|
||||||
ASSERT(objects[i] != nullptr);
|
ASSERT(objects[i] != nullptr);
|
||||||
|
|
||||||
if (objects[i]->IsSignaled()) {
|
if (objects[i]->IsSignaled(kernel)) {
|
||||||
*out_index = i;
|
*out_index = i;
|
||||||
slp.CancelSleep();
|
slp.CancelSleep();
|
||||||
R_THROW(ResultSuccess);
|
R_THROW(ResultSuccess);
|
||||||
@@ -134,7 +135,7 @@ Result KSynchronizationObject::Wait(KernelCore& kernel, s32* out_index,
|
|||||||
|
|
||||||
// Wait for an object to be signaled.
|
// Wait for an object to be signaled.
|
||||||
wait_queue.SetHardwareTimer(timer);
|
wait_queue.SetHardwareTimer(timer);
|
||||||
thread->BeginWait(std::addressof(wait_queue));
|
thread->BeginWait(kernel, std::addressof(wait_queue));
|
||||||
thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::Synchronization);
|
thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::Synchronization);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,26 +150,26 @@ KSynchronizationObject::KSynchronizationObject(KernelCore& kernel) : KAutoObject
|
|||||||
|
|
||||||
KSynchronizationObject::~KSynchronizationObject() = default;
|
KSynchronizationObject::~KSynchronizationObject() = default;
|
||||||
|
|
||||||
void KSynchronizationObject::NotifyAvailable(Result result) {
|
void KSynchronizationObject::NotifyAvailable(KernelCore& kernel, Result result) {
|
||||||
KScopedSchedulerLock sl(m_kernel);
|
KScopedSchedulerLock sl(kernel);
|
||||||
|
|
||||||
// If we're not signaled, we've nothing to notify.
|
// If we're not signaled, we've nothing to notify.
|
||||||
if (!this->IsSignaled()) {
|
if (!this->IsSignaled(kernel)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over each thread.
|
// Iterate over each thread.
|
||||||
for (auto* cur_node = m_thread_list_head; cur_node != nullptr; cur_node = cur_node->next) {
|
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;
|
std::vector<KThread*> threads;
|
||||||
|
|
||||||
// If debugging, dump the list of waiters.
|
// 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) {
|
for (auto* cur_node = m_thread_list_head; cur_node != nullptr; cur_node = cur_node->next) {
|
||||||
threads.emplace_back(cur_node->thread);
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -24,14 +27,13 @@ public:
|
|||||||
KThread* thread{};
|
KThread* thread{};
|
||||||
};
|
};
|
||||||
|
|
||||||
static Result Wait(KernelCore& kernel, s32* out_index, KSynchronizationObject** objects,
|
static Result Wait(KernelCore& kernel, s32* out_index, KSynchronizationObject** objects, const s32 num_objects, s64 timeout);
|
||||||
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_) {
|
void LinkNode(ThreadListNode* node_) {
|
||||||
// Link the node to the list.
|
// Link the node to the list.
|
||||||
@@ -71,9 +73,9 @@ protected:
|
|||||||
|
|
||||||
virtual void OnFinalizeSynchronizationObject() {}
|
virtual void OnFinalizeSynchronizationObject() {}
|
||||||
|
|
||||||
void NotifyAvailable(Result result);
|
void NotifyAvailable(KernelCore& kernel, Result result);
|
||||||
void NotifyAvailable() {
|
void NotifyAvailable(KernelCore& kernel) {
|
||||||
return this->NotifyAvailable(ResultSuccess);
|
return this->NotifyAvailable(kernel, ResultSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -7,8 +10,7 @@
|
|||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
Result KSecureSystemResource::Initialize(size_t size, KResourceLimit* resource_limit,
|
Result KSecureSystemResource::Initialize(KernelCore& kernel, size_t size, KResourceLimit* resource_limit, KMemoryManager::Pool pool) {
|
||||||
KMemoryManager::Pool pool) {
|
|
||||||
// Set members.
|
// Set members.
|
||||||
m_resource_limit = resource_limit;
|
m_resource_limit = resource_limit;
|
||||||
m_resource_size = size;
|
m_resource_size = size;
|
||||||
@@ -18,18 +20,17 @@ Result KSecureSystemResource::Initialize(size_t size, KResourceLimit* resource_l
|
|||||||
const size_t secure_size = this->CalculateRequiredSecureMemorySize();
|
const size_t secure_size = this->CalculateRequiredSecureMemorySize();
|
||||||
|
|
||||||
// Reserve memory for our secure resource.
|
// Reserve memory for our secure resource.
|
||||||
KScopedResourceReservation memory_reservation(
|
KScopedResourceReservation memory_reservation(kernel, m_resource_limit, Svc::LimitableResource::PhysicalMemoryMax, secure_size);
|
||||||
m_resource_limit, Svc::LimitableResource::PhysicalMemoryMax, secure_size);
|
|
||||||
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
||||||
|
|
||||||
// Allocate secure memory.
|
// 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)));
|
m_resource_size, static_cast<u32>(m_resource_pool)));
|
||||||
ASSERT(m_resource_address != 0);
|
ASSERT(m_resource_address != 0);
|
||||||
|
|
||||||
// Ensure we clean up the secure memory, if we fail past this point.
|
// Ensure we clean up the secure memory, if we fail past this point.
|
||||||
ON_RESULT_FAILURE {
|
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));
|
static_cast<u32>(m_resource_pool));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -40,9 +41,9 @@ Result KSecureSystemResource::Initialize(size_t size, KResourceLimit* resource_l
|
|||||||
|
|
||||||
// Get resource pointer.
|
// Get resource pointer.
|
||||||
KPhysicalAddress resource_paddr =
|
KPhysicalAddress resource_paddr =
|
||||||
KPageTable::GetHeapPhysicalAddress(m_kernel, m_resource_address);
|
KPageTable::GetHeapPhysicalAddress(kernel, m_resource_address);
|
||||||
auto* resource =
|
auto* resource =
|
||||||
m_kernel.System().DeviceMemory().GetPointer<KPageTableManager::RefCount>(resource_paddr);
|
kernel.System().DeviceMemory().GetPointer<KPageTableManager::RefCount>(resource_paddr);
|
||||||
|
|
||||||
// Initialize slab heaps.
|
// Initialize slab heaps.
|
||||||
m_dynamic_page_manager.Initialize(m_resource_address + rc_size, m_resource_size - rc_size,
|
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();
|
memory_reservation.Commit();
|
||||||
|
|
||||||
// Open reference to our resource limit.
|
// Open reference to our resource limit.
|
||||||
m_resource_limit->Open();
|
m_resource_limit->Open(kernel);
|
||||||
|
|
||||||
// Set ourselves as initialized.
|
// Set ourselves as initialized.
|
||||||
m_is_initialized = true;
|
m_is_initialized = true;
|
||||||
@@ -74,26 +75,25 @@ Result KSecureSystemResource::Initialize(size_t size, KResourceLimit* resource_l
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KSecureSystemResource::Finalize() {
|
void KSecureSystemResource::Finalize(KernelCore& kernel) {
|
||||||
// Check that we have no outstanding allocations.
|
// Check that we have no outstanding allocations.
|
||||||
ASSERT(m_memory_block_slab_manager.GetUsed() == 0);
|
ASSERT(m_memory_block_slab_manager.GetUsed() == 0);
|
||||||
ASSERT(m_block_info_manager.GetUsed() == 0);
|
ASSERT(m_block_info_manager.GetUsed() == 0);
|
||||||
ASSERT(m_page_table_manager.GetUsed() == 0);
|
ASSERT(m_page_table_manager.GetUsed() == 0);
|
||||||
|
|
||||||
// Free our secure memory.
|
// 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));
|
static_cast<u32>(m_resource_pool));
|
||||||
|
|
||||||
// Release the memory reservation.
|
// Release the memory reservation.
|
||||||
m_resource_limit->Release(Svc::LimitableResource::PhysicalMemoryMax,
|
m_resource_limit->Release(kernel, Svc::LimitableResource::PhysicalMemoryMax,
|
||||||
this->CalculateRequiredSecureMemorySize());
|
this->CalculateRequiredSecureMemorySize());
|
||||||
|
|
||||||
// Close reference to our resource limit.
|
// Close reference to our resource limit.
|
||||||
m_resource_limit->Close();
|
m_resource_limit->Close(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t KSecureSystemResource::CalculateRequiredSecureMemorySize(size_t size,
|
size_t KSecureSystemResource::CalculateRequiredSecureMemorySize(size_t size, KMemoryManager::Pool pool) {
|
||||||
KMemoryManager::Pool pool) {
|
|
||||||
return KSystemControl::CalculateRequiredSecureMemorySize(size, static_cast<u32>(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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -29,7 +32,7 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void Destroy() override {
|
virtual void Destroy(KernelCore& kernel) override {
|
||||||
UNREACHABLE_MSG("KSystemResource::Destroy() was called");
|
UNREACHABLE_MSG("KSystemResource::Destroy() was called");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,13 +96,13 @@ public:
|
|||||||
this->SetSecureResource();
|
this->SetSecureResource();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Initialize(size_t size, KResourceLimit* resource_limit, KMemoryManager::Pool pool);
|
Result Initialize(KernelCore& kernel, size_t size, KResourceLimit* resource_limit, KMemoryManager::Pool pool);
|
||||||
void Finalize();
|
void Finalize(KernelCore& kernel);
|
||||||
|
|
||||||
bool IsInitialized() const {
|
bool IsInitialized() const {
|
||||||
return m_is_initialized;
|
return m_is_initialized;
|
||||||
}
|
}
|
||||||
static void PostDestroy(uintptr_t arg) {}
|
static void PostDestroy(KernelCore& kernel, uintptr_t arg) {}
|
||||||
|
|
||||||
size_t CalculateRequiredSecureMemorySize() const {
|
size_t CalculateRequiredSecureMemorySize() const {
|
||||||
return CalculateRequiredSecureMemorySize(m_resource_size, m_resource_pool);
|
return CalculateRequiredSecureMemorySize(m_resource_size, m_resource_pool);
|
||||||
|
|||||||
+209
-229
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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
@@ -181,21 +181,17 @@ public:
|
|||||||
return m_thread_id;
|
return m_thread_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContinueIfHasKernelWaiters() {
|
void ContinueIfHasKernelWaiters(KernelCore& kernel) {
|
||||||
if (GetNumKernelWaiters() > 0) {
|
if (GetNumKernelWaiters() > 0) {
|
||||||
Continue();
|
Continue(kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetBasePriority(s32 value);
|
void SetBasePriority(KernelCore& kernel, s32 value);
|
||||||
|
Result Run(KernelCore& kernel);
|
||||||
Result Run();
|
void Exit(KernelCore& kernel);
|
||||||
|
Result Terminate(KernelCore& kernel);
|
||||||
void Exit();
|
ThreadState RequestTerminate(KernelCore& kernel);
|
||||||
|
|
||||||
Result Terminate();
|
|
||||||
|
|
||||||
ThreadState RequestTerminate();
|
|
||||||
|
|
||||||
u32 GetSuspendFlags() const {
|
u32 GetSuspendFlags() const {
|
||||||
return m_suspend_allowed_flags & m_suspend_request_flags;
|
return m_suspend_allowed_flags & m_suspend_request_flags;
|
||||||
@@ -215,15 +211,11 @@ public:
|
|||||||
return m_suspend_request_flags != 0;
|
return m_suspend_request_flags != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestSuspend(SuspendType type);
|
void RequestSuspend(KernelCore& kernel, SuspendType type);
|
||||||
|
void Resume(KernelCore& kernel, SuspendType type);
|
||||||
void Resume(SuspendType type);
|
void TrySuspend(KernelCore& kernel);
|
||||||
|
void UpdateState(KernelCore& kernel);
|
||||||
void TrySuspend();
|
void Continue(KernelCore& kernel);
|
||||||
|
|
||||||
void UpdateState();
|
|
||||||
|
|
||||||
void Continue();
|
|
||||||
|
|
||||||
constexpr void SetSyncedIndex(s32 index) {
|
constexpr void SetSyncedIndex(s32 index) {
|
||||||
m_synced_index = index;
|
m_synced_index = index;
|
||||||
@@ -262,7 +254,7 @@ public:
|
|||||||
m_thread_context.tpidr = value;
|
m_thread_context.tpidr = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloneFpuStatus();
|
void CloneFpuStatus(KernelCore& kernel);
|
||||||
|
|
||||||
Svc::ThreadContext& GetContext() {
|
Svc::ThreadContext& GetContext() {
|
||||||
return m_thread_context;
|
return m_thread_context;
|
||||||
@@ -282,7 +274,7 @@ public:
|
|||||||
return m_thread_state.load(std::memory_order_relaxed);
|
return m_thread_state.load(std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetState(ThreadState state);
|
void SetState(KernelCore& kernel, ThreadState state);
|
||||||
|
|
||||||
StepState GetStepState() const {
|
StepState GetStepState() const {
|
||||||
return m_step_state;
|
return m_step_state;
|
||||||
@@ -342,27 +334,27 @@ public:
|
|||||||
Svc::ArgumentHandleCountMax};
|
Svc::ArgumentHandleCountMax};
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 GetUserDisableCount() const;
|
u16 GetUserDisableCount(KernelCore& kernel) const;
|
||||||
void SetInterruptFlag();
|
void SetInterruptFlag(KernelCore& kernel);
|
||||||
void ClearInterruptFlag();
|
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 {
|
const KAffinityMask& GetAffinityMask() const {
|
||||||
return m_physical_affinity_mask;
|
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 {
|
s64 GetYieldScheduleCount() const {
|
||||||
return m_schedule_count;
|
return m_schedule_count;
|
||||||
@@ -372,7 +364,7 @@ public:
|
|||||||
m_schedule_count = count;
|
m_schedule_count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaitCancel();
|
void WaitCancel(KernelCore& kernel);
|
||||||
|
|
||||||
bool IsWaitCancelled() const {
|
bool IsWaitCancelled() const {
|
||||||
return m_wait_cancelled;
|
return m_wait_cancelled;
|
||||||
@@ -417,17 +409,17 @@ public:
|
|||||||
return reinterpret_cast<uintptr_t>(m_parent) | (m_resource_limit_release_hint ? 1 : 0);
|
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);
|
static Result InitializeMainThread(Core::System& system, KThread* thread, s32 virt_core);
|
||||||
|
|
||||||
@@ -514,19 +506,18 @@ public:
|
|||||||
return this->GetStackParameters().disable_count;
|
return this->GetStackParameters().disable_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisableDispatch() {
|
void DisableDispatch(KernelCore& kernel) {
|
||||||
ASSERT(GetCurrentThread(m_kernel).GetDisableDispatchCount() >= 0);
|
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() >= 0);
|
||||||
this->GetStackParameters().disable_count++;
|
this->GetStackParameters().disable_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnableDispatch() {
|
void EnableDispatch(KernelCore& kernel) {
|
||||||
ASSERT(GetCurrentThread(m_kernel).GetDisableDispatchCount() > 0);
|
ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() > 0);
|
||||||
this->GetStackParameters().disable_count--;
|
this->GetStackParameters().disable_count--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pin(s32 current_core);
|
void Pin(KernelCore& kernel, s32 current_core);
|
||||||
|
void Unpin(KernelCore& kernel);
|
||||||
void Unpin();
|
|
||||||
|
|
||||||
void SetInExceptionHandler() {
|
void SetInExceptionHandler() {
|
||||||
this->GetStackParameters().is_in_exception_handler = true;
|
this->GetStackParameters().is_in_exception_handler = true;
|
||||||
@@ -592,18 +583,18 @@ public:
|
|||||||
return this->GetThreadType() == ThreadType::Dummy;
|
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) {
|
KThread* RemoveUserWaiterByKey(KernelCore& kernel, bool* out_has_waiters, KProcessAddress key) {
|
||||||
return this->RemoveWaiterByKey(out_has_waiters, key, false);
|
return this->RemoveWaiterByKey(kernel, out_has_waiters, key, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
KThread* RemoveKernelWaiterByKey(bool* out_has_waiters, KProcessAddress key) {
|
KThread* RemoveKernelWaiterByKey(KernelCore& kernel, bool* out_has_waiters, KProcessAddress key) {
|
||||||
return this->RemoveWaiterByKey(out_has_waiters, key, true);
|
return this->RemoveWaiterByKey(kernel, out_has_waiters, key, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
KProcessAddress GetAddressKey() const {
|
KProcessAddress GetAddressKey() const {
|
||||||
@@ -641,10 +632,10 @@ public:
|
|||||||
m_wait_queue = nullptr;
|
m_wait_queue = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BeginWait(KThreadQueue* queue);
|
void BeginWait(KernelCore& kernel, KThreadQueue* queue);
|
||||||
void NotifyAvailable(KSynchronizationObject* signaled_object, Result wait_result);
|
void NotifyAvailable(KernelCore& kernel, KSynchronizationObject* signaled_object, Result wait_result);
|
||||||
void EndWait(Result wait_result);
|
void EndWait(KernelCore& kernel, Result wait_result);
|
||||||
void CancelWait(Result wait_result, bool cancel_timer_task);
|
void CancelWait(KernelCore& kernel, Result wait_result, bool cancel_timer_task);
|
||||||
|
|
||||||
s32 GetNumKernelWaiters() const {
|
s32 GetNumKernelWaiters() const {
|
||||||
return m_num_kernel_waiters;
|
return m_num_kernel_waiters;
|
||||||
@@ -662,9 +653,9 @@ public:
|
|||||||
// therefore will not block on guest kernel synchronization primitives. These methods handle
|
// therefore will not block on guest kernel synchronization primitives. These methods handle
|
||||||
// blocking as needed.
|
// blocking as needed.
|
||||||
|
|
||||||
void RequestDummyThreadWait();
|
void RequestDummyThreadWait(KernelCore& kernel);
|
||||||
void DummyThreadBeginWait();
|
void DummyThreadBeginWait(KernelCore& kernel);
|
||||||
void DummyThreadEndWait();
|
void DummyThreadEndWait(KernelCore& kernel);
|
||||||
|
|
||||||
uintptr_t GetArgument() const {
|
uintptr_t GetArgument() const {
|
||||||
return m_argument;
|
return m_argument;
|
||||||
@@ -690,8 +681,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KThread* RemoveWaiterByKey(bool* out_has_waiters, KProcessAddress key,
|
KThread* RemoveWaiterByKey(KernelCore& kernel, bool* out_has_waiters, KProcessAddress key, bool is_kernel_address_key);
|
||||||
bool is_kernel_address_key);
|
|
||||||
|
|
||||||
static constexpr size_t PriorityInheritanceCountMax = 10;
|
static constexpr size_t PriorityInheritanceCountMax = 10;
|
||||||
union SyncObjectBuffer {
|
union SyncObjectBuffer {
|
||||||
@@ -735,19 +725,19 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void AddWaiterImpl(KThread* thread);
|
void AddWaiterImpl(KernelCore& kernel, KThread* thread);
|
||||||
void RemoveWaiterImpl(KThread* thread);
|
void RemoveWaiterImpl(KernelCore& kernel, KThread* thread);
|
||||||
static void RestorePriority(KernelCore& kernel, KThread* thread);
|
static void RestorePriority(KernelCore& kernel, KThread* thread);
|
||||||
|
|
||||||
void StartTermination();
|
void StartTermination(KernelCore& kernel);
|
||||||
void FinishTermination();
|
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);
|
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,
|
KProcessAddress user_stack_top, s32 prio, s32 core,
|
||||||
KProcess* owner, ThreadType type,
|
KProcess* owner, ThreadType type,
|
||||||
std::function<void()>&& init_func);
|
std::function<void()>&& init_func);
|
||||||
@@ -878,9 +868,8 @@ public:
|
|||||||
return m_waiting_lock_info;
|
return m_waiting_lock_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddHeldLock(LockWithPriorityInheritanceInfo* lock_info);
|
void AddHeldLock(KernelCore& kernel, LockWithPriorityInheritanceInfo* lock_info);
|
||||||
LockWithPriorityInheritanceInfo* FindHeldLock(KProcessAddress address_key,
|
LockWithPriorityInheritanceInfo* FindHeldLock(KernelCore& kernel, KProcessAddress address_key, bool is_kernel_address_key);
|
||||||
bool is_kernel_address_key);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using LockWithPriorityInheritanceInfoList =
|
using LockWithPriorityInheritanceInfoList =
|
||||||
@@ -996,7 +985,7 @@ public:
|
|||||||
if (m_kernel.IsShuttingDown()) {
|
if (m_kernel.IsShuttingDown()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GetCurrentThread(kernel).DisableDispatch();
|
GetCurrentThread(kernel).DisableDispatch(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
~KScopedDisableDispatch();
|
~KScopedDisableDispatch();
|
||||||
@@ -1005,8 +994,8 @@ private:
|
|||||||
KernelCore& m_kernel;
|
KernelCore& m_kernel;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void KTimerTask::OnTimer() {
|
inline void KTimerTask::OnTimer(KernelCore& kernel) {
|
||||||
static_cast<KThread*>(this)->OnTimer();
|
static_cast<KThread*>(this)->OnTimer(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace 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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -7,17 +10,16 @@
|
|||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
void KThreadQueue::NotifyAvailable(KThread* waiting_thread, KSynchronizationObject* signaled_object,
|
void KThreadQueue::NotifyAvailable(KernelCore& kernel, KThread* waiting_thread, KSynchronizationObject* signaled_object, Result wait_result) {
|
||||||
Result wait_result) {
|
|
||||||
UNREACHABLE();
|
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.
|
// Set the thread's wait result.
|
||||||
waiting_thread->SetWaitResult(wait_result);
|
waiting_thread->SetWaitResult(wait_result);
|
||||||
|
|
||||||
// Set the thread as runnable.
|
// Set the thread as runnable.
|
||||||
waiting_thread->SetState(ThreadState::Runnable);
|
waiting_thread->SetState(kernel, ThreadState::Runnable);
|
||||||
|
|
||||||
// Clear the thread's wait queue.
|
// Clear the thread's wait queue.
|
||||||
waiting_thread->ClearWaitQueue();
|
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.
|
// Set the thread's wait result.
|
||||||
waiting_thread->SetWaitResult(wait_result);
|
waiting_thread->SetWaitResult(wait_result);
|
||||||
|
|
||||||
// Set the thread as runnable.
|
// Set the thread as runnable.
|
||||||
waiting_thread->SetState(ThreadState::Runnable);
|
waiting_thread->SetState(kernel, ThreadState::Runnable);
|
||||||
|
|
||||||
// Clear the thread's wait queue.
|
// Clear the thread's wait queue.
|
||||||
waiting_thread->ClearWaitQueue();
|
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();
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -12,28 +15,25 @@ class KHardwareTimer;
|
|||||||
|
|
||||||
class KThreadQueue {
|
class KThreadQueue {
|
||||||
public:
|
public:
|
||||||
explicit KThreadQueue(KernelCore& kernel) : m_kernel{kernel}, m_hardware_timer{} {}
|
explicit KThreadQueue(KernelCore& kernel) : m_hardware_timer{} {}
|
||||||
virtual ~KThreadQueue() = default;
|
virtual ~KThreadQueue() = default;
|
||||||
|
|
||||||
void SetHardwareTimer(KHardwareTimer* timer) {
|
void SetHardwareTimer(KHardwareTimer* timer) {
|
||||||
m_hardware_timer = timer;
|
m_hardware_timer = timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void NotifyAvailable(KThread* waiting_thread, KSynchronizationObject* signaled_object,
|
virtual void NotifyAvailable(KernelCore& kernel, KThread* waiting_thread, KSynchronizationObject* signaled_object, Result wait_result);
|
||||||
Result wait_result);
|
virtual void EndWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result);
|
||||||
virtual void EndWait(KThread* waiting_thread, Result wait_result);
|
virtual void CancelWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result, bool cancel_timer_task);
|
||||||
virtual void CancelWait(KThread* waiting_thread, Result wait_result, bool cancel_timer_task);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KernelCore& m_kernel;
|
|
||||||
KHardwareTimer* m_hardware_timer{};
|
KHardwareTimer* m_hardware_timer{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class KThreadQueueWithoutEndWait : public KThreadQueue {
|
class KThreadQueueWithoutEndWait : public KThreadQueue {
|
||||||
public:
|
public:
|
||||||
explicit KThreadQueueWithoutEndWait(KernelCore& kernel) : KThreadQueue(kernel) {}
|
explicit KThreadQueueWithoutEndWait(KernelCore& kernel) : KThreadQueue(kernel) {}
|
||||||
|
void EndWait(KernelCore& kernel, KThread* waiting_thread, Result wait_result) override final;
|
||||||
void EndWait(KThread* waiting_thread, Result wait_result) override final;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace 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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -7,6 +10,7 @@
|
|||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
|
class KernelCore;
|
||||||
class KTimerTask : public Common::IntrusiveRedBlackTreeBaseNode<KTimerTask> {
|
class KTimerTask : public Common::IntrusiveRedBlackTreeBaseNode<KTimerTask> {
|
||||||
public:
|
public:
|
||||||
static constexpr int Compare(const KTimerTask& lhs, const KTimerTask& rhs) {
|
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
|
// 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
|
// 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).
|
// devirtualized (see inline declaration for this inside k_thread.h).
|
||||||
void OnTimer();
|
void OnTimer(KernelCore& kernel);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Absolute time in nanoseconds
|
// 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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/literals.h"
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
using namespace Common::Literals;
|
using namespace Common::Literals;
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -14,16 +17,15 @@ KTransferMemory::KTransferMemory(KernelCore& kernel)
|
|||||||
|
|
||||||
KTransferMemory::~KTransferMemory() = default;
|
KTransferMemory::~KTransferMemory() = default;
|
||||||
|
|
||||||
Result KTransferMemory::Initialize(KProcessAddress addr, std::size_t size,
|
Result KTransferMemory::Initialize(KernelCore& kernel, KProcessAddress addr, std::size_t size, Svc::MemoryPermission own_perm) {
|
||||||
Svc::MemoryPermission own_perm) {
|
|
||||||
// Set members.
|
// Set members.
|
||||||
m_owner = GetCurrentProcessPointer(m_kernel);
|
m_owner = GetCurrentProcessPointer(kernel);
|
||||||
|
|
||||||
// Get the owner page table.
|
// Get the owner page table.
|
||||||
auto& page_table = m_owner->GetPageTable();
|
auto& page_table = m_owner->GetPageTable();
|
||||||
|
|
||||||
// Construct the page group, guarding to make sure our state is valid on exit.
|
// 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 {
|
auto pg_guard = SCOPE_GUARD {
|
||||||
m_page_group.reset();
|
m_page_group.reset();
|
||||||
};
|
};
|
||||||
@@ -33,7 +35,7 @@ Result KTransferMemory::Initialize(KProcessAddress addr, std::size_t size,
|
|||||||
ConvertToKMemoryPermission(own_perm)));
|
ConvertToKMemoryPermission(own_perm)));
|
||||||
|
|
||||||
// Set remaining tracking members.
|
// Set remaining tracking members.
|
||||||
m_owner->Open();
|
m_owner->Open(kernel);
|
||||||
m_owner_perm = own_perm;
|
m_owner_perm = own_perm;
|
||||||
m_address = addr;
|
m_address = addr;
|
||||||
m_is_initialized = true;
|
m_is_initialized = true;
|
||||||
@@ -44,7 +46,7 @@ Result KTransferMemory::Initialize(KProcessAddress addr, std::size_t size,
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KTransferMemory::Finalize() {
|
void KTransferMemory::Finalize(KernelCore& kernel) {
|
||||||
// Unlock.
|
// Unlock.
|
||||||
if (!m_is_mapped) {
|
if (!m_is_mapped) {
|
||||||
const size_t size = m_page_group->GetNumPages() * PageSize;
|
const size_t size = m_page_group->GetNumPages() * PageSize;
|
||||||
@@ -53,17 +55,17 @@ void KTransferMemory::Finalize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close the page group.
|
// Close the page group.
|
||||||
m_page_group->Close();
|
m_page_group->Close(kernel);
|
||||||
m_page_group->Finalize();
|
m_page_group->Finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KTransferMemory::PostDestroy(uintptr_t arg) {
|
void KTransferMemory::PostDestroy(KernelCore& kernel, uintptr_t arg) {
|
||||||
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
KProcess* owner = reinterpret_cast<KProcess*>(arg);
|
||||||
owner->GetResourceLimit()->Release(LimitableResource::TransferMemoryCountMax, 1);
|
owner->GetResourceLimit()->Release(kernel, LimitableResource::TransferMemoryCountMax, 1);
|
||||||
owner->Close();
|
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.
|
// Validate the size.
|
||||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||||
|
|
||||||
@@ -80,7 +82,7 @@ Result KTransferMemory::Map(KProcessAddress address, size_t size, Svc::MemoryPer
|
|||||||
const KMemoryState state = (m_owner_perm == Svc::MemoryPermission::None)
|
const KMemoryState state = (m_owner_perm == Svc::MemoryPermission::None)
|
||||||
? KMemoryState::Transferred
|
? KMemoryState::Transferred
|
||||||
: KMemoryState::SharedTransferred;
|
: KMemoryState::SharedTransferred;
|
||||||
R_TRY(GetCurrentProcess(m_kernel).GetPageTable().MapPageGroup(
|
R_TRY(GetCurrentProcess(kernel).GetPageTable().MapPageGroup(
|
||||||
address, *m_page_group, state, KMemoryPermission::UserReadWrite));
|
address, *m_page_group, state, KMemoryPermission::UserReadWrite));
|
||||||
|
|
||||||
// Mark ourselves as mapped.
|
// Mark ourselves as mapped.
|
||||||
@@ -89,7 +91,7 @@ Result KTransferMemory::Map(KProcessAddress address, size_t size, Svc::MemoryPer
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KTransferMemory::Unmap(KProcessAddress address, size_t size) {
|
Result KTransferMemory::Unmap(KernelCore& kernel, KProcessAddress address, size_t size) {
|
||||||
// Validate the size.
|
// Validate the size.
|
||||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||||
|
|
||||||
@@ -100,7 +102,7 @@ Result KTransferMemory::Unmap(KProcessAddress address, size_t size) {
|
|||||||
const KMemoryState state = (m_owner_perm == Svc::MemoryPermission::None)
|
const KMemoryState state = (m_owner_perm == Svc::MemoryPermission::None)
|
||||||
? KMemoryState::Transferred
|
? KMemoryState::Transferred
|
||||||
: KMemoryState::SharedTransferred;
|
: 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.
|
// Mark ourselves as unmapped.
|
||||||
ASSERT(m_is_mapped);
|
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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -30,9 +33,9 @@ public:
|
|||||||
explicit KTransferMemory(KernelCore& kernel);
|
explicit KTransferMemory(KernelCore& kernel);
|
||||||
~KTransferMemory() override;
|
~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 {
|
bool IsInitialized() const override {
|
||||||
return m_is_initialized;
|
return m_is_initialized;
|
||||||
@@ -42,7 +45,7 @@ public:
|
|||||||
return reinterpret_cast<uintptr_t>(m_owner);
|
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 {
|
KProcess* GetOwner() const override {
|
||||||
return m_owner;
|
return m_owner;
|
||||||
@@ -54,8 +57,8 @@ public:
|
|||||||
|
|
||||||
size_t GetSize() const;
|
size_t GetSize() const;
|
||||||
|
|
||||||
Result Map(KProcessAddress address, size_t size, Svc::MemoryPermission map_perm);
|
Result Map(KernelCore& kernel, KProcessAddress address, size_t size, Svc::MemoryPermission map_perm);
|
||||||
Result Unmap(KProcessAddress address, size_t size);
|
Result Unmap(KernelCore& kernel, KProcessAddress address, size_t size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::optional<KPageGroup> m_page_group{};
|
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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -10,8 +13,7 @@ namespace Kernel {
|
|||||||
class KWorkerTask : public KSynchronizationObject {
|
class KWorkerTask : public KSynchronizationObject {
|
||||||
public:
|
public:
|
||||||
explicit KWorkerTask(KernelCore& kernel);
|
explicit KWorkerTask(KernelCore& kernel);
|
||||||
|
void DoWorkerTask(KernelCore& kernel);
|
||||||
void DoWorkerTask();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace 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-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -12,14 +15,14 @@ namespace Kernel {
|
|||||||
|
|
||||||
KWorkerTask::KWorkerTask(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
KWorkerTask::KWorkerTask(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
||||||
|
|
||||||
void KWorkerTask::DoWorkerTask() {
|
void KWorkerTask::DoWorkerTask(KernelCore& kernel) {
|
||||||
if (auto* const thread = this->DynamicCast<KThread*>(); thread != nullptr) {
|
if (auto* const thread = this->DynamicCast<KThread*>(); thread != nullptr) {
|
||||||
return thread->DoWorkerTaskImpl();
|
return thread->DoWorkerTaskImpl(kernel);
|
||||||
} else {
|
} else {
|
||||||
auto* const process = this->DynamicCast<KProcess*>();
|
auto* const process = this->DynamicCast<KProcess*>();
|
||||||
ASSERT(process != nullptr);
|
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) {
|
void KWorkerTaskManager::AddTask(KernelCore& kernel, KWorkerTask* task) {
|
||||||
KScopedSchedulerLock sl(kernel);
|
KScopedSchedulerLock sl(kernel);
|
||||||
m_waiting_thread.QueueWork([task]() {
|
m_waiting_thread.QueueWork([&kernel, task]() {
|
||||||
// Do the task.
|
// Do the task.
|
||||||
task->DoWorkerTask();
|
task->DoWorkerTask(kernel);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,14 +121,14 @@ struct KernelCore::Impl {
|
|||||||
void TerminateAllProcesses() {
|
void TerminateAllProcesses() {
|
||||||
std::scoped_lock lk{process_list_lock};
|
std::scoped_lock lk{process_list_lock};
|
||||||
for (auto& process : process_list) {
|
for (auto& process : process_list) {
|
||||||
process->Terminate();
|
process->Terminate(system.Kernel());
|
||||||
process->Close();
|
process->Close(system.Kernel());
|
||||||
process = nullptr;
|
process = nullptr;
|
||||||
}
|
}
|
||||||
process_list.clear();
|
process_list.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown() {
|
void Shutdown(KernelCore& kernel) {
|
||||||
is_shutting_down.store(true, std::memory_order_relaxed);
|
is_shutting_down.store(true, std::memory_order_relaxed);
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
is_shutting_down.store(false, std::memory_order_relaxed);
|
is_shutting_down.store(false, std::memory_order_relaxed);
|
||||||
@@ -137,7 +137,7 @@ struct KernelCore::Impl {
|
|||||||
CloseServices();
|
CloseServices();
|
||||||
|
|
||||||
if (application_process) {
|
if (application_process) {
|
||||||
application_process->Close();
|
application_process->Close(system.Kernel());
|
||||||
application_process = nullptr;
|
application_process = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,9 +149,9 @@ struct KernelCore::Impl {
|
|||||||
preemption_event = nullptr;
|
preemption_event = nullptr;
|
||||||
|
|
||||||
// Cleanup persistent kernel objects
|
// Cleanup persistent kernel objects
|
||||||
auto CleanupObject = [](KAutoObject* obj) {
|
auto CleanupObject = [&kernel](KAutoObject* obj) {
|
||||||
if (obj) {
|
if (obj) {
|
||||||
obj->Close();
|
obj->Close(kernel);
|
||||||
obj = nullptr;
|
obj = nullptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -163,7 +163,7 @@ struct KernelCore::Impl {
|
|||||||
|
|
||||||
for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) {
|
for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) {
|
||||||
if (shutdown_threads[core_id]) {
|
if (shutdown_threads[core_id]) {
|
||||||
shutdown_threads[core_id]->Close();
|
shutdown_threads[core_id]->Close(kernel);
|
||||||
shutdown_threads[core_id] = nullptr;
|
shutdown_threads[core_id] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ struct KernelCore::Impl {
|
|||||||
std::scoped_lock lk{registered_in_use_objects_lock};
|
std::scoped_lock lk{registered_in_use_objects_lock};
|
||||||
if (registered_in_use_objects.size()) {
|
if (registered_in_use_objects.size()) {
|
||||||
for (auto& object : registered_in_use_objects) {
|
for (auto& object : registered_in_use_objects) {
|
||||||
object->Close();
|
object->Close(kernel);
|
||||||
}
|
}
|
||||||
registered_in_use_objects.clear();
|
registered_in_use_objects.clear();
|
||||||
}
|
}
|
||||||
@@ -226,7 +226,7 @@ struct KernelCore::Impl {
|
|||||||
ASSERT(Kernel::KThread::InitializeIdleThread(system, idle_thread, core).IsSuccess());
|
ASSERT(Kernel::KThread::InitializeIdleThread(system, idle_thread, core).IsSuccess());
|
||||||
KThread::Register(system.Kernel(), idle_thread);
|
KThread::Register(system.Kernel(), idle_thread);
|
||||||
|
|
||||||
schedulers[i]->Initialize(main_thread, idle_thread, core);
|
schedulers[i]->Initialize(system.Kernel(), main_thread, idle_thread, core);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,19 +247,18 @@ struct KernelCore::Impl {
|
|||||||
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::EventCountMax, 900).IsSuccess());
|
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::EventCountMax, 900).IsSuccess());
|
||||||
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::TransferMemoryCountMax, 200).IsSuccess());
|
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::TransferMemoryCountMax, 200).IsSuccess());
|
||||||
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::SessionCountMax, 1133).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
|
// Reserve secure applet memory, introduced in firmware 5.0.0
|
||||||
constexpr u64 secure_applet_memory_size{4_MiB};
|
constexpr u64 secure_applet_memory_size{4_MiB};
|
||||||
ASSERT(system_resource_limit->Reserve(LimitableResource::PhysicalMemoryMax,
|
ASSERT(system_resource_limit->Reserve(kernel, LimitableResource::PhysicalMemoryMax, secure_applet_memory_size));
|
||||||
secure_applet_memory_size));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitializePreemption(KernelCore& kernel) {
|
void InitializePreemption(KernelCore& kernel) {
|
||||||
preemption_event = Core::Timing::CreateEvent("PreemptionCallback", [this, &kernel](s64 time, std::chrono::nanoseconds) -> std::optional<std::chrono::nanoseconds> {
|
preemption_event = Core::Timing::CreateEvent("PreemptionCallback", [this, &kernel](s64 time, std::chrono::nanoseconds) -> std::optional<std::chrono::nanoseconds> {
|
||||||
{
|
{
|
||||||
KScopedSchedulerLock lock(kernel);
|
KScopedSchedulerLock lock(kernel);
|
||||||
global_scheduler_context->PreemptThreads();
|
global_scheduler_context->PreemptThreads(kernel);
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
});
|
});
|
||||||
@@ -350,9 +349,9 @@ struct KernelCore::Impl {
|
|||||||
object_name_global_data.emplace(kernel);
|
object_name_global_data.emplace(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MakeApplicationProcess(KProcess* process) {
|
void MakeApplicationProcess(KernelCore& kernel, KProcess* process) {
|
||||||
application_process = process;
|
application_process = process;
|
||||||
application_process->Open();
|
application_process->Open(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the host thread ID for the caller.
|
/// 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
|
// Gets the dummy KThread for the caller, allocating a new one if this is the first time
|
||||||
KThread* GetHostDummyThread(ThreadLocalData& t, KThread* existing_thread) {
|
KThread* GetHostDummyThread(ThreadLocalData& t, KThread* existing_thread) {
|
||||||
if (t.thread == nullptr) {
|
if (t.thread == nullptr) {
|
||||||
auto const initialize{[](KThread* thread) {
|
auto const initialize = [this](KThread* thread) {
|
||||||
ASSERT(KThread::InitializeDummyThread(thread, nullptr).IsSuccess());
|
ASSERT(KThread::InitializeDummyThread(system, thread, nullptr).IsSuccess());
|
||||||
return thread;
|
return thread;
|
||||||
}};
|
};
|
||||||
t.raw_thread.emplace(system.Kernel());
|
t.raw_thread.emplace(system.Kernel());
|
||||||
t.thread = existing_thread ? existing_thread : initialize(&*t.raw_thread);
|
t.thread = existing_thread ? existing_thread : initialize(&*t.raw_thread);
|
||||||
ASSERT(t.thread != nullptr);
|
ASSERT(t.thread != nullptr);
|
||||||
@@ -418,8 +417,7 @@ struct KernelCore::Impl {
|
|||||||
return is_shutting_down.load(std::memory_order_relaxed);
|
return is_shutting_down.load(std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
KThread* GetCurrentEmuThread() {
|
KThread* GetCurrentEmuThread(ThreadLocalData& t) {
|
||||||
auto& t = tls_data;
|
|
||||||
return t.current_thread ? t.current_thread : (t.current_thread = GetHostDummyThread(t, nullptr));
|
return t.current_thread ? t.current_thread : (t.current_thread = GetHostDummyThread(t, nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -742,19 +740,19 @@ struct KernelCore::Impl {
|
|||||||
time_shared_mem = KSharedMemory::Create(system.Kernel());
|
time_shared_mem = KSharedMemory::Create(system.Kernel());
|
||||||
hidbus_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);
|
Svc::MemoryPermission::Read, font_size);
|
||||||
KSharedMemory::Register(kernel, font_shared_mem);
|
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);
|
Svc::MemoryPermission::Read, irs_size);
|
||||||
KSharedMemory::Register(kernel, irs_shared_mem);
|
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);
|
Svc::MemoryPermission::Read, time_size);
|
||||||
KSharedMemory::Register(kernel, time_shared_mem);
|
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);
|
Svc::MemoryPermission::Read, hidbus_size);
|
||||||
KSharedMemory::Register(kernel, hidbus_shared_mem);
|
KSharedMemory::Register(kernel, hidbus_shared_mem);
|
||||||
}
|
}
|
||||||
@@ -852,7 +850,7 @@ void KernelCore::Initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void KernelCore::Shutdown() {
|
void KernelCore::Shutdown() {
|
||||||
impl->Shutdown();
|
impl->Shutdown(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KernelCore::CloseServices() {
|
void KernelCore::CloseServices() {
|
||||||
@@ -868,7 +866,7 @@ KResourceLimit* KernelCore::GetSystemResourceLimit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void KernelCore::AppendNewProcess(KProcess* process) {
|
void KernelCore::AppendNewProcess(KProcess* process) {
|
||||||
process->Open();
|
process->Open(*this);
|
||||||
|
|
||||||
std::scoped_lock lk{impl->process_list_lock};
|
std::scoped_lock lk{impl->process_list_lock};
|
||||||
impl->process_list.push_back(process);
|
impl->process_list.push_back(process);
|
||||||
@@ -877,12 +875,12 @@ void KernelCore::AppendNewProcess(KProcess* process) {
|
|||||||
void KernelCore::RemoveProcess(KProcess* process) {
|
void KernelCore::RemoveProcess(KProcess* process) {
|
||||||
std::scoped_lock lk{impl->process_list_lock};
|
std::scoped_lock lk{impl->process_list_lock};
|
||||||
if (std::erase(impl->process_list, process)) {
|
if (std::erase(impl->process_list, process)) {
|
||||||
process->Close();
|
process->Close(*this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KernelCore::MakeApplicationProcess(KProcess* process) {
|
void KernelCore::MakeApplicationProcess(KProcess* process) {
|
||||||
impl->MakeApplicationProcess(process);
|
impl->MakeApplicationProcess(*this, process);
|
||||||
}
|
}
|
||||||
|
|
||||||
KProcess* KernelCore::ApplicationProcess() {
|
KProcess* KernelCore::ApplicationProcess() {
|
||||||
@@ -896,11 +894,8 @@ const KProcess* KernelCore::ApplicationProcess() const {
|
|||||||
std::list<KScopedAutoObject<KProcess>> KernelCore::GetProcessList() {
|
std::list<KScopedAutoObject<KProcess>> KernelCore::GetProcessList() {
|
||||||
std::list<KScopedAutoObject<KProcess>> processes;
|
std::list<KScopedAutoObject<KProcess>> processes;
|
||||||
std::scoped_lock lk{impl->process_list_lock};
|
std::scoped_lock lk{impl->process_list_lock};
|
||||||
|
for (auto* const process : impl->process_list)
|
||||||
for (auto* const process : impl->process_list) {
|
processes.emplace_back(*this, process);
|
||||||
processes.emplace_back(process);
|
|
||||||
}
|
|
||||||
|
|
||||||
return processes;
|
return processes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1029,15 +1024,14 @@ void KernelCore::RegisterHostThread(KThread* existing_thread) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::jthread RunHostThreadFunc(KernelCore& kernel, KProcess* process,
|
static std::jthread RunHostThreadFunc(KernelCore& kernel, KProcess* process, std::string&& thread_name, std::function<void()>&& func) {
|
||||||
std::string&& thread_name, std::function<void()>&& func) {
|
|
||||||
// Reserve a new thread from the process resource limit.
|
// 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());
|
ASSERT(thread_reservation.Succeeded());
|
||||||
|
|
||||||
// Initialize the thread.
|
// Initialize the thread.
|
||||||
KThread* thread = KThread::Create(kernel);
|
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.
|
// Commit the thread reservation.
|
||||||
thread_reservation.Commit();
|
thread_reservation.Commit();
|
||||||
@@ -1057,7 +1051,7 @@ static std::jthread RunHostThreadFunc(KernelCore& kernel, KProcess* process,
|
|||||||
|
|
||||||
// Close the thread.
|
// Close the thread.
|
||||||
// This will free the process if it is the last reference.
|
// This will free the process if it is the last reference.
|
||||||
thread->Close();
|
thread->Close(kernel);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1066,11 +1060,11 @@ std::jthread KernelCore::RunOnHostCoreProcess(std::string&& process_name,
|
|||||||
// Make a new process.
|
// Make a new process.
|
||||||
KProcess* process = KProcess::Create(*this);
|
KProcess* process = KProcess::Create(*this);
|
||||||
ASSERT(R_SUCCEEDED(
|
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.
|
// Ensure that we don't hold onto any extra references.
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
process->Close();
|
process->Close(*this);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Register the new process.
|
// Register the new process.
|
||||||
@@ -1096,18 +1090,18 @@ void KernelCore::RunOnGuestCoreProcess(std::string&& process_name, std::function
|
|||||||
// Make a new process.
|
// Make a new process.
|
||||||
KProcess* process = KProcess::Create(*this);
|
KProcess* process = KProcess::Create(*this);
|
||||||
ASSERT(R_SUCCEEDED(
|
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.
|
// Ensure that we don't hold onto any extra references.
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
process->Close();
|
process->Close(*this);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Register the new process.
|
// Register the new process.
|
||||||
KProcess::Register(*this, process);
|
KProcess::Register(*this, process);
|
||||||
|
|
||||||
// Reserve a new thread from the process resource limit.
|
// 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());
|
ASSERT(thread_reservation.Succeeded());
|
||||||
|
|
||||||
// Initialize the thread.
|
// Initialize the thread.
|
||||||
@@ -1122,7 +1116,7 @@ void KernelCore::RunOnGuestCoreProcess(std::string&& process_name, std::function
|
|||||||
KThread::Register(*this, thread);
|
KThread::Register(*this, thread);
|
||||||
|
|
||||||
// Begin running the thread.
|
// Begin running the thread.
|
||||||
ASSERT(R_SUCCEEDED(thread->Run()));
|
ASSERT(R_SUCCEEDED(thread->Run(*this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 KernelCore::GetCurrentHostThreadID() const {
|
u32 KernelCore::GetCurrentHostThreadID() const {
|
||||||
@@ -1130,7 +1124,7 @@ u32 KernelCore::GetCurrentHostThreadID() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
KThread* KernelCore::GetCurrentEmuThread() const {
|
KThread* KernelCore::GetCurrentEmuThread() const {
|
||||||
return impl->GetCurrentEmuThread();
|
return impl->GetCurrentEmuThread(Impl::tls_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KernelCore::SetCurrentEmuThread(KThread* thread) {
|
void KernelCore::SetCurrentEmuThread(KThread* thread) {
|
||||||
@@ -1206,9 +1200,9 @@ void KernelCore::SuspendEmulation(bool suspended) {
|
|||||||
|
|
||||||
for (auto& thread : process->GetThreadList()) {
|
for (auto& thread : process->GetThreadList()) {
|
||||||
if (should_suspend) {
|
if (should_suspend) {
|
||||||
thread.RequestSuspend(SuspendType::System);
|
thread.RequestSuspend(*this, SuspendType::System);
|
||||||
} else {
|
} else {
|
||||||
thread.Resume(SuspendType::System);
|
thread.Resume(*this, SuspendType::System);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1244,12 +1238,9 @@ void KernelCore::SuspendEmulation(bool suspended) {
|
|||||||
|
|
||||||
void KernelCore::ShutdownCores() {
|
void KernelCore::ShutdownCores() {
|
||||||
impl->TerminateAllProcesses();
|
impl->TerminateAllProcesses();
|
||||||
|
|
||||||
KScopedSchedulerLock lk{*this};
|
KScopedSchedulerLock lk{*this};
|
||||||
|
for (auto* thread : impl->shutdown_threads)
|
||||||
for (auto* thread : impl->shutdown_threads) {
|
void(thread->Run(*this));
|
||||||
void(thread->Run());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KernelCore::IsMulticore() const {
|
bool KernelCore::IsMulticore() const {
|
||||||
|
|||||||
@@ -17,14 +17,15 @@
|
|||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
PhysicalCore::PhysicalCore(KernelCore& kernel, std::size_t core_index)
|
PhysicalCore::PhysicalCore(KernelCore& kernel, std::size_t core_index)
|
||||||
: m_kernel{kernel}, m_core_index{core_index} {
|
: m_core_index{core_index}
|
||||||
|
{
|
||||||
m_is_single_core = !kernel.IsMulticore();
|
m_is_single_core = !kernel.IsMulticore();
|
||||||
}
|
}
|
||||||
PhysicalCore::~PhysicalCore() = default;
|
PhysicalCore::~PhysicalCore() = default;
|
||||||
|
|
||||||
void PhysicalCore::RunThread(Kernel::KThread* thread) {
|
void PhysicalCore::RunThread(KernelCore& kernel, Kernel::KThread* thread) {
|
||||||
auto* process = thread->GetOwnerProcess();
|
auto* process = thread->GetOwnerProcess();
|
||||||
auto& system = m_kernel.System();
|
auto& system = kernel.System();
|
||||||
auto* interface = process->GetArmInterface(m_core_index);
|
auto* interface = process->GetArmInterface(m_core_index);
|
||||||
|
|
||||||
interface->Initialize();
|
interface->Initialize();
|
||||||
@@ -72,14 +73,14 @@ void PhysicalCore::RunThread(Kernel::KThread* thread) {
|
|||||||
while (true) {
|
while (true) {
|
||||||
// If the thread is scheduled for termination, exit.
|
// If the thread is scheduled for termination, exit.
|
||||||
if (thread->HasDpc() && thread->IsTerminationRequested()) {
|
if (thread->HasDpc() && thread->IsTerminationRequested()) {
|
||||||
thread->Exit();
|
thread->Exit(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the debugger and go to sleep if a step was performed
|
// Notify the debugger and go to sleep if a step was performed
|
||||||
// and this thread has been scheduled again.
|
// and this thread has been scheduled again.
|
||||||
if (thread->GetStepState() == StepState::StepPerformed) {
|
if (thread->GetStepState() == StepState::StepPerformed) {
|
||||||
system.GetDebugger().NotifyThreadStopped(thread);
|
system.GetDebugger().NotifyThreadStopped(thread);
|
||||||
thread->RequestSuspend(SuspendType::Debug);
|
thread->RequestSuspend(kernel, SuspendType::Debug);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +136,7 @@ void PhysicalCore::RunThread(Kernel::KThread* thread) {
|
|||||||
} else {
|
} else {
|
||||||
interface->LogBacktrace(process);
|
interface->LogBacktrace(process);
|
||||||
}
|
}
|
||||||
thread->RequestSuspend(SuspendType::Debug);
|
thread->RequestSuspend(kernel, SuspendType::Debug);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +145,7 @@ void PhysicalCore::RunThread(Kernel::KThread* thread) {
|
|||||||
if (system.DebuggerEnabled()) {
|
if (system.DebuggerEnabled()) {
|
||||||
system.GetDebugger().NotifyThreadWatchpoint(thread, *interface->HaltedWatchpoint());
|
system.GetDebugger().NotifyThreadWatchpoint(thread, *interface->HaltedWatchpoint());
|
||||||
}
|
}
|
||||||
thread->RequestSuspend(SuspendType::Debug);
|
thread->RequestSuspend(kernel, SuspendType::Debug);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,8 +209,8 @@ void PhysicalCore::CloneFpuStatus(KThread* dst) const {
|
|||||||
dst->GetContext().fpsr = ctx.fpsr;
|
dst->GetContext().fpsr = ctx.fpsr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicalCore::LogBacktrace() {
|
void PhysicalCore::LogBacktrace(KernelCore& kernel) {
|
||||||
auto* process = GetCurrentProcessPointer(m_kernel);
|
auto* process = GetCurrentProcessPointer(kernel);
|
||||||
if (!process) {
|
if (!process) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -30,7 +33,7 @@ public:
|
|||||||
YUZU_NON_MOVEABLE(PhysicalCore);
|
YUZU_NON_MOVEABLE(PhysicalCore);
|
||||||
|
|
||||||
// Execute guest code running on the given thread.
|
// Execute guest code running on the given thread.
|
||||||
void RunThread(KThread* thread);
|
void RunThread(KernelCore& kernel, KThread* thread);
|
||||||
|
|
||||||
// Copy context from thread to current core.
|
// Copy context from thread to current core.
|
||||||
void LoadContext(const KThread* thread);
|
void LoadContext(const KThread* thread);
|
||||||
@@ -44,7 +47,7 @@ public:
|
|||||||
void CloneFpuStatus(KThread* dst) const;
|
void CloneFpuStatus(KThread* dst) const;
|
||||||
|
|
||||||
// Log backtrace of current processor state.
|
// Log backtrace of current processor state.
|
||||||
void LogBacktrace();
|
void LogBacktrace(KernelCore& kernel);
|
||||||
|
|
||||||
// Wait for an interrupt.
|
// Wait for an interrupt.
|
||||||
void Idle();
|
void Idle();
|
||||||
@@ -63,9 +66,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KernelCore& m_kernel;
|
|
||||||
const std::size_t m_core_index;
|
const std::size_t m_core_index;
|
||||||
|
|
||||||
std::mutex m_guard;
|
std::mutex m_guard;
|
||||||
std::condition_variable m_on_interrupt;
|
std::condition_variable m_on_interrupt;
|
||||||
Core::ArmInterface* m_arm_interface{};
|
Core::ArmInterface* m_arm_interface{};
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -69,16 +72,16 @@ public:
|
|||||||
explicit KAutoObjectWithSlabHeap(KernelCore& kernel) : Base(kernel) {}
|
explicit KAutoObjectWithSlabHeap(KernelCore& kernel) : Base(kernel) {}
|
||||||
virtual ~KAutoObjectWithSlabHeap() = default;
|
virtual ~KAutoObjectWithSlabHeap() = default;
|
||||||
|
|
||||||
virtual void Destroy() override {
|
virtual void Destroy(KernelCore& kernel) override {
|
||||||
const bool is_initialized = this->IsInitialized();
|
const bool is_initialized = this->IsInitialized();
|
||||||
uintptr_t arg = 0;
|
uintptr_t arg = 0;
|
||||||
if (is_initialized) {
|
if (is_initialized) {
|
||||||
arg = this->GetPostDestroyArgument();
|
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) {
|
if (is_initialized) {
|
||||||
Derived::PostDestroy(arg);
|
Derived::PostDestroy(kernel, arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,8 +92,8 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t GetSlabIndex() const {
|
size_t GetSlabIndex(KernelCore& kernel) const {
|
||||||
return SlabHeap<Derived>(Base::m_kernel).GetObjectIndex(static_cast<const Derived*>(this));
|
return SlabHeap<Derived>(kernel).GetObjectIndex(static_cast<const Derived*>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -144,17 +147,17 @@ public:
|
|||||||
KAutoObjectWithSlabHeapAndContainer(KernelCore& kernel) : Base(kernel) {}
|
KAutoObjectWithSlabHeapAndContainer(KernelCore& kernel) : Base(kernel) {}
|
||||||
virtual ~KAutoObjectWithSlabHeapAndContainer() {}
|
virtual ~KAutoObjectWithSlabHeapAndContainer() {}
|
||||||
|
|
||||||
virtual void Destroy() override {
|
virtual void Destroy(KernelCore& kernel) override {
|
||||||
const bool is_initialized = this->IsInitialized();
|
const bool is_initialized = this->IsInitialized();
|
||||||
uintptr_t arg = 0;
|
uintptr_t arg = 0;
|
||||||
if (is_initialized) {
|
if (is_initialized) {
|
||||||
Base::m_kernel.ObjectListContainer().Unregister(this);
|
kernel.ObjectListContainer().Unregister(this);
|
||||||
arg = this->GetPostDestroyArgument();
|
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) {
|
if (is_initialized) {
|
||||||
Derived::PostDestroy(arg);
|
Derived::PostDestroy(kernel, arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,8 +168,8 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t GetSlabIndex() const {
|
size_t GetSlabIndex(KernelCore& kernel) const {
|
||||||
return SlabHeap<Derived>(Base::m_kernel).GetObjectIndex(static_cast<const Derived*>(this));
|
return SlabHeap<Derived>(kernel).GetObjectIndex(static_cast<const Derived*>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -177,9 +180,8 @@ public:
|
|||||||
|
|
||||||
static Derived* Create(KernelCore& kernel) {
|
static Derived* Create(KernelCore& kernel) {
|
||||||
Derived* obj = Allocate(kernel);
|
Derived* obj = Allocate(kernel);
|
||||||
if (obj != nullptr) {
|
if (obj != nullptr)
|
||||||
KAutoObject::Create(obj);
|
KAutoObject::Create(obj);
|
||||||
}
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -22,17 +25,15 @@ Result SetThreadActivity(Core::System& system, Handle thread_handle,
|
|||||||
R_UNLESS(IsValidThreadActivity(thread_activity), ResultInvalidEnumValue);
|
R_UNLESS(IsValidThreadActivity(thread_activity), ResultInvalidEnumValue);
|
||||||
|
|
||||||
// Get the thread from its handle.
|
// Get the thread from its handle.
|
||||||
KScopedAutoObject thread =
|
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
|
||||||
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
|
|
||||||
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
// Check that the activity is being set on a non-current thread for the current process.
|
// Check that the activity is being set on a non-current thread for the current process.
|
||||||
R_UNLESS(thread->GetOwnerProcess() == GetCurrentProcessPointer(system.Kernel()),
|
R_UNLESS(thread->GetOwnerProcess() == GetCurrentProcessPointer(system.Kernel()), ResultInvalidHandle);
|
||||||
ResultInvalidHandle);
|
|
||||||
R_UNLESS(thread.GetPointerUnsafe() != GetCurrentThreadPointer(system.Kernel()), ResultBusy);
|
R_UNLESS(thread.GetPointerUnsafe() != GetCurrentThreadPointer(system.Kernel()), ResultBusy);
|
||||||
|
|
||||||
// Set the activity.
|
// Set the activity.
|
||||||
R_TRY(thread->SetActivity(thread_activity));
|
R_TRY(thread->SetActivity(system.Kernel(), thread_activity));
|
||||||
|
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -37,8 +40,7 @@ Result FlushProcessDataCache(Core::System& system, Handle process_handle, u64 ad
|
|||||||
R_UNLESS(size == static_cast<uint64_t>(size), ResultInvalidCurrentMemory);
|
R_UNLESS(size == static_cast<uint64_t>(size), ResultInvalidCurrentMemory);
|
||||||
|
|
||||||
// Get the process from its handle.
|
// Get the process from its handle.
|
||||||
KScopedAutoObject process =
|
KScopedAutoObject process = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(system.Kernel(), process_handle);
|
||||||
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
|
|
||||||
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
// Verify the region is within range.
|
// Verify the region is within range.
|
||||||
|
|||||||
@@ -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-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
@@ -35,9 +35,6 @@ constexpr bool IsValidUnmapFromOwnerCodeMemoryPermission(MemoryPermission perm)
|
|||||||
Result CreateCodeMemory(Core::System& system, Handle* out, u64 address, uint64_t size) {
|
Result CreateCodeMemory(Core::System& system, Handle* out, u64 address, uint64_t size) {
|
||||||
LOG_TRACE(Kernel_SVC, "called, address={:#X}, size=0x{:X}", address, size);
|
LOG_TRACE(Kernel_SVC, "called, address={:#X}, size=0x{:X}", address, size);
|
||||||
|
|
||||||
// Get kernel instance.
|
|
||||||
auto& kernel = system.Kernel();
|
|
||||||
|
|
||||||
// Validate address / size.
|
// Validate address / size.
|
||||||
R_UNLESS(Common::IsAligned(address, PageSize), ResultInvalidAddress);
|
R_UNLESS(Common::IsAligned(address, PageSize), ResultInvalidAddress);
|
||||||
R_UNLESS(Common::IsAligned(size, PageSize), ResultInvalidSize);
|
R_UNLESS(Common::IsAligned(size, PageSize), ResultInvalidSize);
|
||||||
@@ -46,24 +43,23 @@ Result CreateCodeMemory(Core::System& system, Handle* out, u64 address, uint64_t
|
|||||||
|
|
||||||
// Create the code memory.
|
// Create the code memory.
|
||||||
|
|
||||||
KCodeMemory* code_mem = KCodeMemory::Create(kernel);
|
KCodeMemory* code_mem = KCodeMemory::Create(system.Kernel());
|
||||||
R_UNLESS(code_mem != nullptr, ResultOutOfResource);
|
R_UNLESS(code_mem != nullptr, ResultOutOfResource);
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
code_mem->Close();
|
code_mem->Close(system.Kernel());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Verify that the region is in range.
|
// Verify that the region is in range.
|
||||||
R_UNLESS(GetCurrentProcess(system.Kernel()).GetPageTable().Contains(address, size),
|
R_UNLESS(GetCurrentProcess(system.Kernel()).GetPageTable().Contains(address, size), ResultInvalidCurrentMemory);
|
||||||
ResultInvalidCurrentMemory);
|
|
||||||
|
|
||||||
// Initialize the code memory.
|
// 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.
|
// Register the code memory.
|
||||||
KCodeMemory::Register(kernel, code_mem);
|
KCodeMemory::Register(system.Kernel(), code_mem);
|
||||||
|
|
||||||
// Add the code memory to the handle table.
|
// Add the code memory to the handle table.
|
||||||
R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(out, code_mem));
|
R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(system.Kernel(), out, code_mem));
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
@@ -85,8 +81,8 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
|
|||||||
|
|
||||||
// Get the code memory from its handle.
|
// Get the code memory from its handle.
|
||||||
KScopedAutoObject code_mem = GetCurrentProcess(system.Kernel())
|
KScopedAutoObject code_mem = GetCurrentProcess(system.Kernel())
|
||||||
.GetHandleTable()
|
.GetHandleTable()
|
||||||
.GetObject<KCodeMemory>(code_memory_handle);
|
.GetObject<KCodeMemory>(system.Kernel(), code_memory_handle);
|
||||||
R_UNLESS(code_mem.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(code_mem.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
// NOTE: Here, Atmosphere extends the SVC to allow code memory operations on one's own process.
|
// NOTE: Here, Atmosphere extends the SVC to allow code memory operations on one's own process.
|
||||||
@@ -96,29 +92,23 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
|
|||||||
switch (operation) {
|
switch (operation) {
|
||||||
case CodeMemoryOperation::Map: {
|
case CodeMemoryOperation::Map: {
|
||||||
// Check that the region is in range.
|
// Check that the region is in range.
|
||||||
R_UNLESS(GetCurrentProcess(system.Kernel())
|
R_UNLESS(GetCurrentProcess(system.Kernel()).GetPageTable().CanContain(address, size, KMemoryState::CodeOut), ResultInvalidMemoryRegion);
|
||||||
.GetPageTable()
|
|
||||||
.CanContain(address, size, KMemoryState::CodeOut),
|
|
||||||
ResultInvalidMemoryRegion);
|
|
||||||
|
|
||||||
// Check the memory permission.
|
// Check the memory permission.
|
||||||
R_UNLESS(IsValidMapCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission);
|
R_UNLESS(IsValidMapCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission);
|
||||||
|
|
||||||
// Map the memory.
|
// Map the memory.
|
||||||
R_TRY(code_mem->Map(address, size));
|
R_TRY(code_mem->Map(system.Kernel(), address, size));
|
||||||
} break;
|
} break;
|
||||||
case CodeMemoryOperation::Unmap: {
|
case CodeMemoryOperation::Unmap: {
|
||||||
// Check that the region is in range.
|
// Check that the region is in range.
|
||||||
R_UNLESS(GetCurrentProcess(system.Kernel())
|
R_UNLESS(GetCurrentProcess(system.Kernel()).GetPageTable().CanContain(address, size, KMemoryState::CodeOut), ResultInvalidMemoryRegion);
|
||||||
.GetPageTable()
|
|
||||||
.CanContain(address, size, KMemoryState::CodeOut),
|
|
||||||
ResultInvalidMemoryRegion);
|
|
||||||
|
|
||||||
// Check the memory permission.
|
// Check the memory permission.
|
||||||
R_UNLESS(IsValidUnmapCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission);
|
R_UNLESS(IsValidUnmapCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission);
|
||||||
|
|
||||||
// Unmap the memory.
|
// Unmap the memory.
|
||||||
R_TRY(code_mem->Unmap(address, size));
|
R_TRY(code_mem->Unmap(system.Kernel(), address, size));
|
||||||
} break;
|
} break;
|
||||||
case CodeMemoryOperation::MapToOwner: {
|
case CodeMemoryOperation::MapToOwner: {
|
||||||
// Check that the region is in range.
|
// 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);
|
R_UNLESS(IsValidMapToOwnerCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission);
|
||||||
|
|
||||||
// Map the memory to its owner.
|
// 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;
|
} break;
|
||||||
case CodeMemoryOperation::UnmapFromOwner: {
|
case CodeMemoryOperation::UnmapFromOwner: {
|
||||||
// Check that the region is in range.
|
// 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);
|
R_UNLESS(IsValidUnmapFromOwnerCodeMemoryPermission(perm), ResultInvalidNewMemoryPermission);
|
||||||
|
|
||||||
// Unmap the memory from its owner.
|
// Unmap the memory from its owner.
|
||||||
R_TRY(code_mem->UnmapFromOwner(address, size));
|
R_TRY(code_mem->UnmapFromOwner(system.Kernel(), address, size));
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
R_THROW(ResultInvalidEnumValue);
|
R_THROW(ResultInvalidEnumValue);
|
||||||
|
|||||||
@@ -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-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -29,17 +32,17 @@ Result CreateDeviceAddressSpace(Core::System& system, Handle* out, uint64_t das_
|
|||||||
KDeviceAddressSpace* das = KDeviceAddressSpace::Create(system.Kernel());
|
KDeviceAddressSpace* das = KDeviceAddressSpace::Create(system.Kernel());
|
||||||
R_UNLESS(das != nullptr, ResultOutOfResource);
|
R_UNLESS(das != nullptr, ResultOutOfResource);
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
das->Close();
|
das->Close(system.Kernel());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize the device address space.
|
// 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.
|
// Register the device address space.
|
||||||
KDeviceAddressSpace::Register(system.Kernel(), das);
|
KDeviceAddressSpace::Register(system.Kernel(), das);
|
||||||
|
|
||||||
// Add to the handle table.
|
// Add to the handle table.
|
||||||
R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(out, das));
|
R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(system.Kernel(), out, das));
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
@@ -47,8 +50,8 @@ Result CreateDeviceAddressSpace(Core::System& system, Handle* out, uint64_t das_
|
|||||||
Result AttachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) {
|
Result AttachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) {
|
||||||
// Get the device address space.
|
// Get the device address space.
|
||||||
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
|
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
|
||||||
.GetHandleTable()
|
.GetHandleTable()
|
||||||
.GetObject<KDeviceAddressSpace>(das_handle);
|
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
|
||||||
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
// Attach.
|
// Attach.
|
||||||
@@ -58,8 +61,8 @@ Result AttachDeviceAddressSpace(Core::System& system, DeviceName device_name, Ha
|
|||||||
Result DetachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) {
|
Result DetachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) {
|
||||||
// Get the device address space.
|
// Get the device address space.
|
||||||
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
|
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
|
||||||
.GetHandleTable()
|
.GetHandleTable()
|
||||||
.GetObject<KDeviceAddressSpace>(das_handle);
|
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
|
||||||
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
// Detach.
|
// Detach.
|
||||||
@@ -99,13 +102,13 @@ Result MapDeviceAddressSpaceByForce(Core::System& system, Handle das_handle, Han
|
|||||||
|
|
||||||
// Get the device address space.
|
// Get the device address space.
|
||||||
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
|
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
|
||||||
.GetHandleTable()
|
.GetHandleTable()
|
||||||
.GetObject<KDeviceAddressSpace>(das_handle);
|
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
|
||||||
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
// Get the process.
|
// Get the process.
|
||||||
KScopedAutoObject process =
|
KScopedAutoObject process =
|
||||||
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
|
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(system.Kernel(), process_handle);
|
||||||
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
// Validate that the process address is within range.
|
// Validate that the process address is within range.
|
||||||
@@ -140,13 +143,13 @@ Result MapDeviceAddressSpaceAligned(Core::System& system, Handle das_handle, Han
|
|||||||
|
|
||||||
// Get the device address space.
|
// Get the device address space.
|
||||||
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
|
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
|
||||||
.GetHandleTable()
|
.GetHandleTable()
|
||||||
.GetObject<KDeviceAddressSpace>(das_handle);
|
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
|
||||||
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
// Get the process.
|
// Get the process.
|
||||||
KScopedAutoObject process =
|
KScopedAutoObject process =
|
||||||
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
|
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(system.Kernel(), process_handle);
|
||||||
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
// Validate that the process address is within range.
|
// Validate that the process address is within range.
|
||||||
@@ -172,13 +175,12 @@ Result UnmapDeviceAddressSpace(Core::System& system, Handle das_handle, Handle p
|
|||||||
|
|
||||||
// Get the device address space.
|
// Get the device address space.
|
||||||
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
|
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
|
||||||
.GetHandleTable()
|
.GetHandleTable()
|
||||||
.GetObject<KDeviceAddressSpace>(das_handle);
|
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
|
||||||
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
// Get the process.
|
// Get the process.
|
||||||
KScopedAutoObject process =
|
KScopedAutoObject process = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(system.Kernel(), process_handle);
|
||||||
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
|
|
||||||
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
// Validate that the process address is within range.
|
// Validate that the process address is within range.
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ Result SignalEvent(Core::System& system, Handle event_handle) {
|
|||||||
// Fail-safe for system applets
|
// Fail-safe for system applets
|
||||||
const auto program_id = GetCurrentProcess(system.Kernel()).GetProgramId();
|
const auto program_id = GetCurrentProcess(system.Kernel()).GetProgramId();
|
||||||
if ((program_id & 0xFFFFFFFFFFFFFF00ull) == 0x0100000000001000ull) {
|
if ((program_id & 0xFFFFFFFFFFFFFF00ull) == 0x0100000000001000ull) {
|
||||||
KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle);
|
KScopedAutoObject event = handle_table.GetObject<KEvent>(system.Kernel(), event_handle);
|
||||||
if (event.IsNotNull()) {
|
if (event.IsNotNull()) {
|
||||||
event->Signal();
|
event->Signal(system.Kernel());
|
||||||
} else {
|
} else {
|
||||||
LOG_WARNING(Kernel_SVC, "SignalEvent best-effort unknown handle=0x{:08X} (ignored)",
|
LOG_WARNING(Kernel_SVC, "SignalEvent best-effort unknown handle=0x{:08X} (ignored)",
|
||||||
event_handle);
|
event_handle);
|
||||||
@@ -34,10 +34,10 @@ Result SignalEvent(Core::System& system, Handle event_handle) {
|
|||||||
|
|
||||||
|
|
||||||
// Get the event.
|
// Get the event.
|
||||||
KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle);
|
KScopedAutoObject event = handle_table.GetObject<KEvent>(system.Kernel(), event_handle);
|
||||||
R_UNLESS(event.IsNotNull(), ResultInvalidHandle);
|
R_UNLESS(event.IsNotNull(), ResultInvalidHandle);
|
||||||
|
|
||||||
R_RETURN(event->Signal());
|
R_RETURN(event->Signal(system.Kernel()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ClearEvent(Core::System& system, Handle event_handle) {
|
Result ClearEvent(Core::System& system, Handle event_handle) {
|
||||||
@@ -48,18 +48,18 @@ Result ClearEvent(Core::System& system, Handle event_handle) {
|
|||||||
|
|
||||||
// Try to clear the writable event.
|
// Try to clear the writable event.
|
||||||
{
|
{
|
||||||
KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle);
|
KScopedAutoObject event = handle_table.GetObject<KEvent>(system.Kernel(), event_handle);
|
||||||
if (event.IsNotNull()) {
|
if (event.IsNotNull()) {
|
||||||
event->Clear();
|
event->Clear(system.Kernel());
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to clear the readable event.
|
// Try to clear the readable event.
|
||||||
{
|
{
|
||||||
KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(event_handle);
|
KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(system.Kernel(), event_handle);
|
||||||
if (readable_event.IsNotNull()) {
|
if (readable_event.IsNotNull()) {
|
||||||
readable_event->Clear();
|
readable_event->Clear(system.Kernel());
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,43 +71,42 @@ Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) {
|
|||||||
LOG_DEBUG(Kernel_SVC, "called");
|
LOG_DEBUG(Kernel_SVC, "called");
|
||||||
|
|
||||||
// Get the kernel reference and handle table.
|
// Get the kernel reference and handle table.
|
||||||
auto& kernel = system.Kernel();
|
auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
|
||||||
auto& handle_table = GetCurrentProcess(kernel).GetHandleTable();
|
|
||||||
|
|
||||||
// Reserve a new event from the process resource limit
|
// Reserve a new event from the process resource limit
|
||||||
KScopedResourceReservation event_reservation(GetCurrentProcessPointer(kernel),
|
KScopedResourceReservation event_reservation(system.Kernel(), GetCurrentProcessPointer(system.Kernel()),
|
||||||
LimitableResource::EventCountMax);
|
LimitableResource::EventCountMax);
|
||||||
R_UNLESS(event_reservation.Succeeded(), ResultLimitReached);
|
R_UNLESS(event_reservation.Succeeded(), ResultLimitReached);
|
||||||
|
|
||||||
// Create a new event.
|
// Create a new event.
|
||||||
KEvent* event = KEvent::Create(kernel);
|
KEvent* event = KEvent::Create(system.Kernel());
|
||||||
R_UNLESS(event != nullptr, ResultOutOfResource);
|
R_UNLESS(event != nullptr, ResultOutOfResource);
|
||||||
|
|
||||||
// Initialize the event.
|
// Initialize the event.
|
||||||
event->Initialize(GetCurrentProcessPointer(kernel));
|
event->Initialize(system.Kernel(), GetCurrentProcessPointer(system.Kernel()));
|
||||||
|
|
||||||
// Commit the thread reservation.
|
// Commit the thread reservation.
|
||||||
event_reservation.Commit();
|
event_reservation.Commit();
|
||||||
|
|
||||||
// Ensure that we clean up the event (and its only references are handle table) on function end.
|
// Ensure that we clean up the event (and its only references are handle table) on function end.
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
event->GetReadableEvent().Close();
|
event->GetReadableEvent().Close(system.Kernel());
|
||||||
event->Close();
|
event->Close(system.Kernel());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Register the event.
|
// Register the event.
|
||||||
KEvent::Register(kernel, event);
|
KEvent::Register(system.Kernel(), event);
|
||||||
|
|
||||||
// Add the event to the handle table.
|
// Add the event to the handle table.
|
||||||
R_TRY(handle_table.Add(out_write, event));
|
R_TRY(handle_table.Add(system.Kernel(), out_write, event));
|
||||||
|
|
||||||
// Ensure that we maintain a clean handle state on exit.
|
// Ensure that we maintain a clean handle state on exit.
|
||||||
ON_RESULT_FAILURE {
|
ON_RESULT_FAILURE {
|
||||||
handle_table.Remove(*out_write);
|
handle_table.Remove(system.Kernel(), *out_write);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add the readable event to the handle table.
|
// Add the readable event to the handle table.
|
||||||
R_RETURN(handle_table.Add(out_read, std::addressof(event->GetReadableEvent())));
|
R_RETURN(handle_table.Add(system.Kernel(), out_read, std::addressof(event->GetReadableEvent())));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SignalEvent64(Core::System& system, Handle event_handle) {
|
Result SignalEvent64(Core::System& system, Handle event_handle) {
|
||||||
|
|||||||
@@ -106,14 +106,14 @@ void Break(Core::System& system, BreakReason reason, u64 info1, u64 info2) {
|
|||||||
|
|
||||||
handle_debug_buffer(info1, info2);
|
handle_debug_buffer(info1, info2);
|
||||||
|
|
||||||
system.CurrentPhysicalCore().LogBacktrace();
|
system.CurrentPhysicalCore().LogBacktrace(system.Kernel());
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool should_break = !notification_only;
|
const bool should_break = !notification_only;
|
||||||
if (system.DebuggerEnabled() && should_break) {
|
if (system.DebuggerEnabled() && should_break) {
|
||||||
auto* thread = system.Kernel().GetCurrentEmuThread();
|
auto* thread = system.Kernel().GetCurrentEmuThread();
|
||||||
system.GetDebugger().NotifyThreadStopped(thread);
|
system.GetDebugger().NotifyThreadStopped(thread);
|
||||||
thread->RequestSuspend(Kernel::SuspendType::Debug);
|
thread->RequestSuspend(system.Kernel(), Kernel::SuspendType::Debug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user