Compare commits

...

34 commits

Author SHA1 Message Date
lizzie
331348da3d fixups 2026-06-05 09:02:58 +00:00
lizzie
77b8e9c532 license + fix stuffs 2026-06-05 08:01:51 +00:00
lizzie
f6f79aaf7b remove m_kernel reference from global scheduler 2026-06-05 07:27:53 +00:00
lizzie
080ebb1760 fixups 2026-06-05 07:27:31 +00:00
lizzie
f14aa02243 fix license 2026-06-05 07:27:31 +00:00
lizzie
50474508d4 case stupidity in windows 2026-06-05 07:27:31 +00:00
lizzie
3890984588 correct defines for d3d9 2026-06-05 07:27:31 +00:00
lizzie
bc6348afd4 fs 2026-06-05 07:27:31 +00:00
lizzie
7e9ad47207 fix msvc 2026-06-05 07:27:31 +00:00
lizzie
0b557964d7 public 2026-06-05 07:27:31 +00:00
lizzie
62334622a5 Trigger Build 2026-06-05 07:27:31 +00:00
lizzie
9629573caf better inlining 2026-06-05 07:27:31 +00:00
lizzie
47186b6a16 maxwell macros 2026-06-05 07:27:31 +00:00
lizzie
d5a06a4889 remove implicit system saved in struct, pass as first param 2026-06-05 07:27:31 +00:00
lizzie
b64ebc71f7 ffs 2026-06-05 07:27:31 +00:00
lizzie
83feb9ac8a extra 2026-06-05 07:27:31 +00:00
lizzie
64247068f7 extra fixups 2026-06-05 07:27:31 +00:00
lizzie
9ee484b375 less load, fix nv01 timer being kepler 2026-06-05 07:27:31 +00:00
lizzie
02d16582f8 fx 2026-06-05 07:27:31 +00:00
lizzie
83581f8df2 [video_core] Remove redundant references in GPU engine structs
Signed-off-by: lizzie <lizzie@eden-emu.dev>
2026-06-05 07:27:31 +00:00
maufeat
82463a1550 [kernel, hle] Initial 22.0.0 kernel changes and cmd stubs (#3761)
- KProcess::Run() and CreateThread() SVC now write the current thread handle to TLS+0x110
- KPageTableBase::LockForMapDeviceAddressSpace now checks for a new KPageTableBase boolean, m_allowed_exec_device_mapping
- Stub `am` + `acc` + `settings` cmd module that needs to work for qlaunch

Thanks to: @alula and @yellows8
Source for changes: https://github.com/Atmosphere-NX/Atmosphere/pull/2744, https://switchbrew.org/, https://yls8.mtheall.com/

Co-authored-by: PavelBARABANOV <pavelbarabanov94@gmail.com>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3761
Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
2026-06-05 07:27:30 +00:00
lizzie
88dcbb05b2 llicense fix 2026-06-05 07:27:30 +00:00
lizzie
cada2d4e76 fx 2026-06-05 07:27:30 +00:00
lizzie
0da996528a [audio_core, hle/services, video_core/compute] Inline std::unique_ptr<> allocs into std::optional<>
Signed-off-by: lizzie <lizzie@eden-emu.dev>
2026-06-05 07:27:30 +00:00
Yang Liu
48219f348c
[dynarmic, loongarch64] Add minimal toy implementation enough to execute LSLS (#4054)
Some checks are pending
tx-src / sources (push) Waiting to run
Check Strings / check-strings (push) Waiting to run
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4054
Reviewed-by: Lizzie <lizzie@eden-emu.dev>
Reviewed-by: crueter <crueter@eden-emu.dev>
2026-06-05 02:32:06 +02:00
crueter
661346503b
[net] Add support for future macOS PGO shenanigans (#4050)
Rudimentary tests showed that using PGO on macOS *does* have an
appreciable impact on performance. So we're probably going to introduce
it soon.

Signed-off-by: crueter <crueter@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4050
Reviewed-by: Lizzie <lizzie@eden-emu.dev>
2026-06-05 02:24:26 +02:00
lizzie
a4e9b08fe7
[docs] clang-cl with MSVC, misc docs updates (#4034)
Some checks are pending
tx-src / sources (push) Waiting to run
Check Strings / check-strings (push) Waiting to run
- vtable bounce is all gone
- factual corrections to HosKernel.md

Signed-off-by: lizzie <lizzie@eden-emu.dev>

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4034
Reviewed-by: crueter <crueter@eden-emu.dev>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
2026-06-04 19:39:21 +02:00
lizzie
ce9c7c196d
[cmake] fix OpenSSL not using <openssl/cert.h> when applicable because it tries to use the system one instead of being explicitly linked (#4053)
should fix hiccups with self-built OpenSSL

Signed-off-by: lizzie <lizzie@eden-emu.dev>

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4053
Reviewed-by: crueter <crueter@eden-emu.dev>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
2026-06-04 19:39:09 +02:00
crueter
efc7472330
[cmake] Bump minimum version to 3.31 (#4055)
Ubuntu 24.04 can't hurt us anymore.

Some other deps may have their versions raised, but there's not much of
an incentive so we'll keep it as is for now.

Signed-off-by: crueter <crueter@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4055
Reviewed-by: Lizzie <lizzie@eden-emu.dev>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
2026-06-04 15:28:39 +02:00
Duncan Ogilvie
aadcc24aac
[core/debugger] Protocol-compliant vCont support (#3896)
Some checks are pending
tx-src / sources (push) Waiting to run
Check Strings / check-strings (push) Waiting to run
(gdb) set scheduler-locking on
(gdb) continue

As discussed in #3848, follow-up to implement vCont support according to spec.

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3896
Reviewed-by: Lizzie <lizzie@eden-emu.dev>
Reviewed-by: crueter <crueter@eden-emu.dev>
2026-06-04 05:49:23 +02:00
lizzie
89199f4d27
[*] basic in-house cpp linting (#4039)
- add `#pragma once` to remainder files
- "correcter" defines (ANDROID), see https://groups.google.com/g/android-ndk/c/cf9_f1SLXls
- extra miscelly fixups

Signed-off-by: lizzie <lizzie@eden-emu.dev>

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4039
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Reviewed-by: crueter <crueter@eden-emu.dev>
2026-06-04 05:49:07 +02:00
lizzie
978d9d935d
[vk/vma] force ANV to have HOST_CACHED stream buffers (#3792)
Signed-off-by: lizzie <lizzie@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3792
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Reviewed-by: crueter <crueter@eden-emu.dev>
2026-06-04 05:48:41 +02:00
lizzie
ad9af25027
[dynarmic] fix pre-SSE4.1 having errors on CMHI/CMLO, fix extra nuisances and add INTERP testcase (#4025)
does a bit of code dedup
fixes pre-SSE4.1 having horrific CMHI/CMLO

Signed-off-by: lizzie <lizzie@eden-emu.dev>

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4025
Reviewed-by: crueter <crueter@eden-emu.dev>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
2026-06-03 22:53:21 +02:00
lizzie
f729dbb3c3
[common] use abi::__cxa_demangle for demangling using the system's glibcxx/libc++ (#3894)
most stdlibc++ already provide this functionality out of the box, very consistently and well implemented (usually)

my main irk is that the llvm itanium demangle is totally unescesary when there is a perfectly stable, tested and well documented equivalent functionality in the standard stdc++ provided in most UNIX oses

its mostly to reduce binary size by a very thin margin, but he stdc++ is more than capable of doing he same behaviour we use a dpeendency for

for mingw or such howeger,, demangling becomies trickier so we have to exclude windows entirely because well windows likes to do things differently dont they

Signed-off-by: lizzie <lizzie@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3894
Reviewed-by: crueter <crueter@eden-emu.dev>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
2026-06-03 22:53:09 +02:00
202 changed files with 3376 additions and 1981 deletions

View file

@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
# SPDX-License-Identifier: GPL-3.0-or-later
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.31)
project(yuzu)
@ -306,7 +306,7 @@ if (YUZU_ROOM)
add_compile_definitions(YUZU_ROOM)
endif()
if ((ANDROID OR APPLE OR UNIX) AND (NOT PLATFORM_LINUX OR ANDROID) AND NOT WIN32)
if (UNIX AND NOT (PLATFORM_LINUX OR WIN32))
if(CXX_APPLE OR CXX_CLANG)
# libc++ has stop_token and jthread as experimental
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexperimental-library")
@ -524,6 +524,8 @@ elseif (WIN32)
# PSAPI is the Process Status API
set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} psapi imm32 version crypt32 rpcrt4 gdi32 wldap32 mswsock)
endif()
elseif (PLATFORM_MANAGARM)
set(PLATFORM_LIBRARIES iconv intl)
elseif (PLATFORM_HAIKU)
# Haiku is so special :)
set(PLATFORM_LIBRARIES bsd /boot/system/lib/libnetwork.so)

View file

@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2023 Alexandre Bouvier <contact@amb.tf>
#
# SPDX-License-Identifier: GPL-3.0-or-later
@ -13,7 +16,8 @@ endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LLVM HANDLE_COMPONENTS CONFIG_MODE)
if (LLVM_FOUND AND LLVM_Demangle_FOUND AND NOT TARGET LLVM::Demangle)
# Demangle only for Windows targets
if (WIN32 AND LLVM_FOUND AND LLVM_Demangle_FOUND AND NOT TARGET LLVM::Demangle)
add_library(LLVM::Demangle INTERFACE IMPORTED)
target_compile_definitions(LLVM::Demangle INTERFACE ${LLVM_DEFINITIONS})
target_include_directories(LLVM::Demangle INTERFACE ${LLVM_INCLUDE_DIRS})

View file

@ -136,6 +136,16 @@ cmake -S . -B build -G "<GENERATOR>" -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COM
<img src="https://user-images.githubusercontent.com/42481638/216899275-d514ec6a-e563-470e-81e2-3e04f0429b68.png" width="500">
</details>
#### Option D: Visual Studio with clang-cl
<details>
1. Install `"x64 Native Tools Command Prompt"` for VS from the installer and also install `cmake-gui`.
2. Open `"x64 Native Tools Command Prompt"` and type `cmake-gui`.
3. Click configure choose ninja generator > specify native compilers.
4. Put `"C:/Program Files/Microsoft Visual Studio/18/Community/VC/Tools/Llvm/x64/bin/clang-cl.exe"` as your C/C++ compiler path.
5. Open `Visual studio > Open project` or Solution > Change to search for the CMake project file (`CMakeList.txt`) file on the cloned directory, and then build.
</details>
## Troubleshooting
If your initial configure failed:

View file

@ -16,7 +16,7 @@ To build Eden, you MUST have a C++ compiler.
The following additional tools are also required:
* **[CMake](https://www.cmake.org/)** 3.22+ - already included with the Android SDK
* **[CMake](https://www.cmake.org/)** 3.31+ - already included with the Android SDK
* **[Git](https://git-scm.com/)** for version control
* **[Windows installer](https://gitforwindows.org)**
* **[Python3](https://www.python.org/downloads/)** 3.10+ - necessary to download external repositories

View file

@ -1,6 +1,6 @@
# HOS Kernel
In brief, the HOS kernel is a microkernel, some services and programs run in userspace, the primary way to do communication between these is via `HIPC` (not covered here); otherwise most of the primitives reside in the forms of syscalls invoked via `svc #imm`. The kernel supports both 32-bit and 64-bit programs, and has the capacity to use 32, 36 and 39 bits of address space for spawned processes. Most of the networking stack is based off FreeBSD's network stack.
In brief, the HOS kernel is a microkernel, all services and programs run in userspace, the primary way to do communication between these is via `HIPC` (not covered here); otherwise most of the primitives reside in the forms of syscalls invoked via `svc #imm`. The kernel supports both 32-bit and 64-bit programs, and has the capacity to use 32, 36 and 39 bits of address space for spawned processes. Most of the networking stack is based off FreeBSD's network stack.
The emulator implements the majority of the syscalls pertaining to the HOS kernel itself. When we talk about the HOS Kernel (in the context of the emulator) we are strictly speaking about the mechanisms from which syscalls are handled (and it's subsequent side effects, such as the page table book-keeping). The emulator at it's current state is unable to load a custom low-level kernel and do supervisor-level emulation.
@ -28,4 +28,4 @@ Every process keeps it's own tracking of the following structures:
The emulator willingly restricts itself to only use 4 threads (to emulate 4 cores), this is because most existing applications do not benefit greatly from the added core count, and in fact can be detrimental due to extra contention. This translates equitatively to about 4 `ArmInterface` slots for each process, these are then redirected to whatever is the last `pc` of the last thread running on the core is meant to be; proceed to run it, then when returning (due to halt or interruption), proceed to reschedule the thread.
The scheduler as-is isn't 100% faithful to the original, and has great timing variance (especially due to the fact the emulator can run in systems with wildly different timings).
The scheduler as-is isn't 100% faithful to the original (for example the original is cooperative and not preemptive), and has great timing variance (especially due to the fact the emulator can run in systems with wildly different timings).

View file

@ -30,7 +30,6 @@ Before touching the settings, please see the game boots with stock options. We t
## CPU
- `CPU/Virtual table bouncing`: Some games have the tendency to crash on loading due to an indirect bad jump (Pokemon ZA being the worst offender); this option lies to the game and tells it to just pretend it never executed a given function. This is fine for most casual users, but developers of switch applications **must** disable this. This temporary "hack" should hopefully be gone in 6-7 months from now on.
- `Fastmem`, aka. `CPU/Enable Host MMU`: Enables "fastmem"; a detailed description of fastmem can be found [here](../dynarmic/Design.md#fast-memory-fastmem).
- `CPU/Unsafe FMA`: Enables deliberate innacurate FMA behaviour which may affect how FMA returns any given operation - this may introduce tiny floating point errors which can cascade in sensitive code (i.e FFmpeg).
- `CPU/Faster FRSQRTE and FRECPE`: Introduces accuracy errors on square root and reciprocals in exchange for less checks - this introduces inaccuracies with some cases but it's mostly safe.

View file

@ -49,8 +49,8 @@ if (NOT TARGET stb::headers)
add_library(stb::headers ALIAS stb)
endif()
# ItaniumDemangle
if (NOT TARGET LLVM::Demangle)
# ItaniumDemangle (Windows only)
if (WIN32 AND NOT TARGET LLVM::Demangle)
add_library(demangle demangle/ItaniumDemangle.cpp)
target_include_directories(demangle PUBLIC ./demangle)
if (NOT MSVC)

View file

@ -256,7 +256,7 @@ android {
externalNativeBuild {
cmake {
version = "3.22.1"
version = "3.31.6"
path = file("${edenDir}/CMakeLists.txt")
}
}

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -8,10 +11,11 @@
namespace AudioCore {
AudioCore::AudioCore(Core::System& system) : audio_manager{std::make_unique<AudioManager>()} {
AudioCore::AudioCore(Core::System& system) {
audio_manager.emplace();
CreateSinks();
// Must be created after the sinks
adsp = std::make_unique<ADSP::ADSP>(system, *output_sink);
adsp.emplace(system, *output_sink);
}
AudioCore ::~AudioCore() {

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -15,10 +18,7 @@ class System;
namespace AudioCore {
class AudioManager;
/**
* Main audio class, stored inside the core, and holding the audio manager, all sinks, and the ADSP.
*/
/// @brief Main audio class, stored inside the core, and holding the audio manager, all sinks, and the ADSP.
class AudioCore {
public:
explicit AudioCore(Core::System& system);
@ -50,27 +50,22 @@ public:
*/
Sink::Sink& GetInputSink();
/**
* Get the ADSP.
*
* @return Ref to the ADSP.
*/
/// @brief Get the ADSP.
/// @return Ref to the ADSP.
ADSP::ADSP& ADSP();
private:
/**
* Create the sinks on startup.
*/
/// @brief Create the sinks on startup.
void CreateSinks();
/// 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
std::unique_ptr<Sink::Sink> output_sink;
/// Sink used for audio input
std::unique_ptr<Sink::Sink> input_sink;
/// The ADSP in the sysmodule
std::unique_ptr<ADSP::ADSP> adsp;
std::optional<ADSP::ADSP> adsp;
};
} // namespace AudioCore

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -41,8 +44,7 @@ void Manager::ReleaseSessionId(const size_t session_id) {
Result Manager::LinkToManager() {
std::scoped_lock l{mutex};
if (!linked_to_manager) {
AudioManager& manager{system.AudioCore().GetAudioManager()};
manager.SetInManager(std::bind(&Manager::BufferReleaseAndRegister, this));
system.AudioCore().GetAudioManager().SetInManager(std::bind(&Manager::BufferReleaseAndRegister, this));
linked_to_manager = true;
}

View file

@ -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-License-Identifier: GPL-2.0-or-later
#include "audio_core/audio_manager.h"
#include "common/thread.h"
#include "core/core.h"
#include "core/hle/service/audio/errors.h"
namespace AudioCore {
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() {
running = false;
events.SetAudioEvent(Event::Type::Max, true);
thread.join();
if (thread.joinable()) {
thread.request_stop();
thread.join();
}
}
Result AudioManager::SetOutManager(BufferEventFunc buffer_func) {
if (!running) {
return Service::Audio::ResultOperationFailed;
if (thread.joinable()) {
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;
}
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;
}
Result AudioManager::SetInManager(BufferEventFunc buffer_func) {
if (!running) {
return Service::Audio::ResultOperationFailed;
if (thread.joinable()) {
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;
}
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;
}
void AudioManager::SetEvent(const Event::Type type, const bool 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

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -66,13 +69,6 @@ public:
void SetEvent(Event::Type type, bool signalled);
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
bool needs_update{};
/// Events to be set and signalled

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -40,8 +43,7 @@ void Manager::ReleaseSessionId(const size_t session_id) {
Result Manager::LinkToManager() {
std::scoped_lock l{mutex};
if (!linked_to_manager) {
AudioManager& manager{system.AudioCore().GetAudioManager()};
manager.SetOutManager(std::bind(&Manager::BufferReleaseAndRegister, this));
system.AudioCore().GetAudioManager().SetOutManager(std::bind(&Manager::BufferReleaseAndRegister, this));
linked_to_manager = true;
}

View file

@ -235,7 +235,7 @@ if (BOOST_NO_HEADERS)
else()
target_link_libraries(common PUBLIC Boost::headers)
endif()
target_link_libraries(common PRIVATE OpenSSL::SSL)
target_link_libraries(common PUBLIC Boost::filesystem Boost::context httplib::httplib nlohmann_json::nlohmann_json)
if (lz4_ADDED)
@ -243,7 +243,12 @@ if (lz4_ADDED)
endif()
target_link_libraries(common PUBLIC fmt::fmt stb::headers Threads::Threads unordered_dense::unordered_dense)
target_link_libraries(common PRIVATE lz4::lz4 LLVM::Demangle zstd::zstd)
target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd)
# Please refer to src/common/demangle.cpp
if (WIN32)
target_link_libraries(common PRIVATE LLVM::Demangle)
endif()
if(ANDROID)
# For ASharedMemory_create

View file

@ -303,7 +303,7 @@ namespace {
}
[[nodiscard]] s64 GetHostCNTFRQ() noexcept {
u64 cntfrq_el0 = 0;
#ifdef ANDROID
#ifdef __ANDROID__
std::string_view board{""};
char buffer[PROP_VALUE_MAX];
int len{__system_property_get("ro.product.board", buffer)};

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
@ -6,30 +6,44 @@
#include <string>
#include <string_view>
#ifdef _WIN32
#include <llvm/Demangle/Demangle.h>
#else
#include <cxxabi.h>
#endif
#include "common/demangle.h"
#include "common/scope_exit.h"
static bool IsItanium(std::string_view name) {
// A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'.
auto const pos = name.find_first_not_of('_');
return pos > 0 && pos <= 4 && pos < name.size() && name[pos] == 'Z';
}
namespace Common {
std::string DemangleSymbol(const std::string& mangled) {
if (mangled.size() > 0) {
auto const is_itanium = [](std::string_view name) -> bool {
// A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'.
auto const pos = name.find_first_not_of('_');
return pos > 0 && pos <= 4 && pos < name.size() && name[pos] == 'Z';
};
std::string ret = mangled;
if (is_itanium(mangled)) {
if (IsItanium(mangled)) {
#ifdef _WIN32
// requires the use of llvm
if (char* p = llvm::itaniumDemangle(mangled); p != nullptr) {
ret = std::string{p};
std::string ret = std::string{p};
std::free(p);
return ret;
}
#else
// can safely use libc++ and glibcxx provided demangling functions
// it's available since 2008(!) so no system should have issues with it
// see https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.3/a01696.html
int status;
if (char* p = abi::__cxa_demangle(mangled.c_str(), NULL, NULL, &status); p != nullptr) {
std::string ret = std::string{p};
std::free(p);
return ret;
}
#endif
}
return ret;
return mangled;
}
return std::string{};
}
} // namespace Common

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2013 Dolphin Emulator Project
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -30,7 +33,7 @@ std::string NativeErrorToString(int e) {
return ret;
#else
char err_str[255];
#if defined(ANDROID) || \
#if defined(__ANDROID__) || \
(defined(__GLIBC__) && (_GNU_SOURCE || (_POSIX_C_SOURCE < 200112L && _XOPEN_SOURCE < 600)))
// Thread safe (GNU-specific)
const char* str = strerror_r(e, err_str, sizeof(err_str));

View file

@ -9,7 +9,7 @@
#include "common/assert.h"
#include "common/fs/file.h"
#include "common/fs/fs.h"
#ifdef ANDROID
#ifdef __ANDROID__
#include "common/fs/fs_android.h"
#endif
#include "common/logging.h"
@ -259,7 +259,7 @@ void IOFile::Open(const fs::path& path, FileAccessMode mode, FileType type, File
} else {
_wfopen_s(&file, path.c_str(), AccessModeToWStr(mode, type));
}
#elif ANDROID
#elif __ANDROID__
if (Android::IsContentUri(path)) {
ASSERT_MSG(mode == FileAccessMode::Read, "Content URI file access is for read-only!");
const auto fd = Android::OpenContentUri(path, Android::OpenMode::Read);
@ -396,7 +396,7 @@ u64 IOFile::GetSize() const {
// Flush any unwritten buffered data into the file prior to retrieving the file size.
std::fflush(file);
#if ANDROID
#ifdef __ANDROID__
u64 file_size = 0;
if (Android::IsContentUri(file_path)) {
file_size = Android::GetSize(file_path);

View file

@ -6,7 +6,7 @@
#include "common/fs/file.h"
#include "common/fs/fs.h"
#ifdef ANDROID
#ifdef __ANDROID__
#include "common/fs/fs_android.h"
#endif
#include "common/fs/path_util.h"
@ -532,7 +532,7 @@ void IterateDirEntriesRecursively(const std::filesystem::path& path,
bool Exists(const fs::path& path) {
std::error_code ec;
#ifdef ANDROID
#ifdef __ANDROID__
if (Android::IsContentUri(path)) {
return Android::Exists(path);
} else {
@ -545,7 +545,7 @@ bool Exists(const fs::path& path) {
bool IsFile(const fs::path& path) {
std::error_code ec;
#ifdef ANDROID
#ifdef __ANDROID__
if (Android::IsContentUri(path)) {
return !Android::IsDirectory(path);
} else {
@ -558,7 +558,7 @@ bool IsFile(const fs::path& path) {
bool IsDir(const fs::path& path) {
std::error_code ec;
#ifdef ANDROID
#ifdef __ANDROID__
if (Android::IsContentUri(path)) {
return Android::IsDirectory(path);
} else {
@ -611,7 +611,7 @@ fs::file_type GetEntryType(const fs::path& path) {
}
u64 GetSize(const fs::path& path) {
#ifdef ANDROID
#ifdef __ANDROID__
if (Android::IsContentUri(path)) {
return Android::GetSize(path);
}

View file

@ -11,7 +11,7 @@
#include "common/assert.h"
#include "common/fs/fs.h"
#ifdef ANDROID
#ifdef __ANDROID__
#include "common/fs/fs_android.h"
#endif
#include "common/fs/fs_paths.h"
@ -126,7 +126,7 @@ public:
LEGACY_PATH(Yuzu, YUZU)
LEGACY_PATH(Suyu, SUYU)
#undef LEGACY_PATH
#elif ANDROID
#elif __ANDROID__
ASSERT(!eden_path.empty());
eden_path_cache = eden_path / CACHE_DIR;
eden_path_config = eden_path / CONFIG_DIR;
@ -447,11 +447,11 @@ std::vector<std::string> SplitPathComponentsCopy(std::string_view filename) {
std::string SanitizePath(std::string_view path_, DirectorySeparator directory_separator) {
std::string path(path_);
#ifdef ANDROID
#ifdef __ANDROID__
if (Android::IsContentUri(path)) {
return path;
}
#endif // ANDROID
#endif // __ANDROID__
char type1 = directory_separator == DirectorySeparator::BackwardSlash ? '/' : '\\';
char type2 = directory_separator == DirectorySeparator::BackwardSlash ? '\\' : '/';
@ -482,7 +482,7 @@ std::string GetParentPath(std::string_view path) {
return std::string(path);
}
#ifdef ANDROID
#ifdef __ANDROID__
if (path[0] != '/') {
std::string path_string{path};
return FS::Android::GetParentDirectory(path_string);

View file

@ -320,7 +320,7 @@ struct DebuggerBackend final : public Backend {
void Flush() noexcept override {}
};
#endif
#ifdef ANDROID
#ifdef __ANDROID__
/// @brief Backend that writes to the Android logcat
struct LogcatBackend : public Backend {
explicit LogcatBackend() noexcept = default;
@ -359,7 +359,7 @@ struct Impl {
#ifdef _WIN32
lambda(static_cast<Backend&>(debugger_backend));
#endif
#ifdef ANDROID
#ifdef __ANDROID__
lambda(static_cast<Backend&>(lc_backend));
#endif
}
@ -372,7 +372,7 @@ struct Impl {
#ifdef _WIN32
DebuggerBackend debugger_backend{};
#endif
#ifdef ANDROID
#ifdef __ANDROID__
LogcatBackend lc_backend{};
#endif
std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()};

View file

@ -74,7 +74,8 @@ std::vector<Asset> Release::GetPlatformAssets() const {
#endif // ARCHITECTURE_arm64
#elif defined(__APPLE__)
#ifdef ARCHITECTURE_arm64
find_asset("Standard", {".dmg", ".tar.gz"});
find_asset("Standard", {"standard.dmg", "standard.tar.gz", ".dmg", ".tar.gz"});
find_asset("PGO", {"pgo.dmg", "pgo.tar.gz"});
#endif // ARCHITECTURE_arm64
#elif defined(__ANDROID__)
#ifdef ARCHITECTURE_x86_64

View file

@ -359,7 +359,7 @@ struct Values {
true,
true};
SwitchableSetting<int, true> fsr_sharpening_slider{linkage,
#ifdef ANDROID
#ifdef __ANDROID__
0,
#else
25,
@ -417,7 +417,7 @@ struct Values {
linkage, 0, "bg_blue", Category::Renderer, Specialization::Default, true, true};
SwitchableSetting<GpuAccuracy, true> gpu_accuracy{linkage,
#ifdef ANDROID
#ifdef __ANDROID__
GpuAccuracy::Low,
#else
GpuAccuracy::Medium,
@ -447,7 +447,7 @@ struct Values {
"nvdec_emulation", Category::RendererAdvanced};
SwitchableSetting<AnisotropyMode, true> max_anisotropy{linkage,
#ifdef ANDROID
#ifdef __ANDROID__
AnisotropyMode::Default,
#else
AnisotropyMode::Automatic,
@ -500,7 +500,7 @@ struct Values {
Category::RendererAdvanced};
SwitchableSetting<bool> use_reactive_flushing{linkage,
#ifdef ANDROID
#ifdef __ANDROID__
false,
#else
true,
@ -519,7 +519,7 @@ struct Values {
true,
true};
#ifdef ANDROID
#ifdef __ANDROID__
SwitchableSetting<bool> use_optimized_vertex_buffers{linkage,
false,
"use_optimized_vertex_buffers",
@ -553,7 +553,7 @@ struct Values {
true,
true};
SwitchableSetting<bool> async_presentation{linkage,
#ifdef ANDROID
#ifdef __ANDROID__
false,
#else
false,
@ -599,7 +599,7 @@ struct Values {
Category::RendererHacks};
SwitchableSetting<ExtendedDynamicState> dyna_state{linkage,
#if defined(ANDROID)
#if defined(__ANDROID__)
ExtendedDynamicState::Disabled,
#elif defined(__APPLE__)
ExtendedDynamicState::Disabled,
@ -618,7 +618,7 @@ struct Values {
Specialization::Scalar};
SwitchableSetting<bool> vertex_input_dynamic_state{linkage,
#if defined (ANDROID)
#ifdef __ANDROID__
false,
#else
true,
@ -634,7 +634,7 @@ struct Values {
linkage, false, "disable_shader_loop_safety_checks", Category::RendererDebug};
Setting<bool> enable_renderdoc_hotkey{linkage, false, "renderdoc_hotkey",
Category::RendererDebug};
#if defined(ANDROID) && defined(ARCHITECTURE_arm64)
#if defined(__ANDROID__) && defined(ARCHITECTURE_arm64)
// Debug override for automatic BCn patching detection
Setting<bool> patch_old_qcom_drivers{linkage, false, "patch_old_qcom_drivers",
Category::RendererDebug};
@ -679,7 +679,7 @@ struct Values {
Setting<s32> current_user{linkage, 0, "current_user", Category::System};
SwitchableSetting<ConsoleMode> use_docked_mode{linkage,
#ifdef ANDROID
#ifdef __ANDROID__
ConsoleMode::Handheld,
#else
ConsoleMode::Docked,

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2013 Dolphin Emulator Project
@ -18,7 +18,7 @@
#include <windows.h>
#endif
#ifdef ANDROID
#ifdef __ANDROID__
#include <common/fs/fs_android.h>
#endif
@ -45,7 +45,7 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _
if (full_path.empty())
return false;
#ifdef ANDROID
#ifdef __ANDROID__
if (full_path[0] != '/') {
*_pPath = Common::FS::Android::GetParentDirectory(full_path);
*_pFilename = Common::FS::Android::GetFilename(full_path);

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2012 PPSSPP Project
@ -10,12 +10,10 @@
#pragma once
#if defined(_MSC_VER)
#include <cstdlib>
#endif
#include <bit>
#include <cstring>
#include <type_traits>
#include <bit>
#include "common/common_types.h"
namespace Common {

View file

@ -262,20 +262,16 @@ enum {
CMP_ORD = 7,
};
constexpr bool IsWithin2G(uintptr_t ref, uintptr_t target) {
const u64 distance = target - (ref + 5);
return !(distance >= 0x8000'0000ULL && distance <= ~0x8000'0000ULL);
}
inline bool IsWithin2G(const Xbyak::CodeGenerator& code, uintptr_t target) {
return IsWithin2G(reinterpret_cast<uintptr_t>(code.getCurr()), target);
constexpr bool IsWithin2G(uintptr_t ref, uintptr_t target) noexcept {
u64 const distance = target - (ref + 5);
return (distance & 0xffff'ffff) == distance;
}
template <typename T>
inline void CallFarFunction(Xbyak::CodeGenerator& code, const T f) {
static_assert(std::is_pointer_v<T>, "Argument must be a (function) pointer.");
size_t addr = reinterpret_cast<size_t>(f);
if (IsWithin2G(code, addr)) {
uintptr_t addr = uintptr_t(f);
if (IsWithin2G(uintptr_t(code.getCurr()), addr)) {
code.call(f);
} else {
// ABI_RETURN is a safe temp register to use before a call

View file

@ -1215,6 +1215,7 @@ else()
endif()
target_link_libraries(core PRIVATE
OpenSSL::SSL
fmt::fmt
nlohmann_json::nlohmann_json
RenderDoc::API

View file

@ -271,7 +271,7 @@ struct System::Impl {
SystemResultStatus SetupForApplicationProcess(System& system, Frontend::EmuWindow& emu_window) {
host1x_core.emplace(system);
gpu_core = VideoCore::CreateGPU(emu_window, system);
VideoCore::CreateGPU(gpu_core, emu_window, system);
if (!gpu_core)
return SystemResultStatus::ErrorVideoCore;
@ -347,7 +347,7 @@ struct System::Impl {
// Register with applet manager
// 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_current_game) {
@ -391,10 +391,8 @@ struct System::Impl {
is_powered_on = false;
exit_locked = false;
exit_requested = false;
if (gpu_core != nullptr) {
if (gpu_core)
gpu_core->NotifyShutdown();
}
stop_event.request_stop();
core_timing.SyncPause(false);
@ -478,6 +476,7 @@ struct System::Impl {
std::optional<Memory::CheatEngine> cheat_engine;
std::optional<Tools::Freezer> memory_freezer;
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::vector<std::vector<u8>> user_channel;
@ -492,7 +491,6 @@ struct System::Impl {
std::unique_ptr<FileSys::ContentProviderUnion> content_provider;
/// AppLoader used to load the current executing application
std::unique_ptr<Loader::AppLoader> app_loader;
std::unique_ptr<Tegra::GPU> gpu_core;
std::stop_source stop_event;
mutable std::mutex suspend_guard;

View file

@ -25,9 +25,11 @@ CpuManager::~CpuManager() = default;
void CpuManager::Initialize() {
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++)
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() {
@ -63,7 +65,7 @@ void CpuManager::HandleInterrupt() {
auto& kernel = system.Kernel();
auto core_index = kernel.CurrentPhysicalCoreIndex();
Kernel::KInterruptManager::HandleInterrupt(kernel, static_cast<s32>(core_index));
Kernel::KInterruptManager::HandleInterrupt(kernel, s32(core_index));
}
///////////////////////////////////////////////////////////////////////////////
@ -79,7 +81,7 @@ void CpuManager::MultiCoreRunGuestThread() {
while (true) {
auto* physical_core = &kernel.CurrentPhysicalCore();
while (!physical_core->IsInterrupted()) {
physical_core->RunThread(thread);
physical_core->RunThread(kernel, thread);
physical_core = &kernel.CurrentPhysicalCore();
}
@ -117,7 +119,7 @@ void CpuManager::SingleCoreRunGuestThread() {
while (true) {
auto* physical_core = &kernel.CurrentPhysicalCore();
if (!physical_core->IsInterrupted()) {
physical_core->RunThread(thread);
physical_core->RunThread(kernel, thread);
physical_core = &kernel.CurrentPhysicalCore();
}

View file

@ -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-License-Identifier: GPL-2.0-or-later
@ -86,22 +89,20 @@ private:
void ShutdownThread();
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 {
std::shared_ptr<Common::Fiber> host_context;
std::jthread host_thread;
};
std::unique_ptr<Common::Barrier> gpu_barrier{};
std::array<CoreData, Core::Hardware::NUM_CPU_CORES> core_data{};
bool is_async_gpu{};
bool is_multicore{};
System& system;
std::atomic<std::size_t> current_core{};
std::size_t idle_count{};
std::size_t num_cores{};
static constexpr std::size_t max_cycle_runs = 5;
System& system;
bool is_async_gpu{};
bool is_multicore{};
};
} // namespace Core

View file

@ -9,7 +9,7 @@
#include <boost/asio.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION > 108400 && (!defined(_WINDOWS) && !defined(ANDROID)) || defined(YUZU_BOOST_v1)
#if BOOST_VERSION > 108400 && (!defined(_WINDOWS) && !defined(__ANDROID__)) || defined(YUZU_BOOST_v1)
#define USE_BOOST_v1
#endif
@ -247,17 +247,19 @@ private:
case DebuggerAction::Continue:
MarkResumed([&] { ResumeEmulation(); });
break;
case DebuggerAction::StepThreadUnlocked:
MarkResumed([&] {
state->active_thread->SetStepState(Kernel::StepState::StepPending);
state->active_thread->Resume(Kernel::SuspendType::Debug);
ResumeEmulation(state->active_thread.GetPointerUnsafe());
case DebuggerAction::ContinueThreads: {
auto* gdb = static_cast<GDBStub*>(frontend.get());
MarkResumed([this, threads = std::move(gdb->resume_threads)] {
ResumeThreads(threads);
});
break;
case DebuggerAction::StepThreadLocked: {
MarkResumed([&] {
}
case DebuggerAction::StepThread: {
auto* gdb = static_cast<GDBStub*>(frontend.get());
MarkResumed([this, threads = std::move(gdb->resume_threads)] {
state->active_thread->SetStepState(Kernel::StepState::StepPending);
state->active_thread->Resume(Kernel::SuspendType::Debug);
ResumeThreads(threads, state->active_thread.GetPointerUnsafe());
});
break;
}
@ -298,6 +300,22 @@ private:
}
}
void ResumeThreads(const std::vector<Kernel::KThread*>& threads,
Kernel::KThread* except = nullptr) {
Kernel::KScopedLightLock ll{debug_process->GetListLock()};
Kernel::KScopedSchedulerLock sl{system.Kernel()};
// Wake up only the specified threads.
for (auto* thread : threads) {
if (!thread || thread == except) {
continue;
}
thread->SetStepState(Kernel::StepState::NotStepping);
thread->Resume(Kernel::SuspendType::Debug);
}
}
template <typename Callback>
void MarkResumed(Callback&& cb) {
stopped = false;

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
@ -20,11 +20,11 @@ struct DebugWatchpoint;
namespace Core {
enum class DebuggerAction {
Interrupt, ///< Stop emulation as soon as possible.
Continue, ///< Resume emulation.
StepThreadLocked, ///< Step the currently-active thread without resuming others.
StepThreadUnlocked, ///< Step the currently-active thread and resume others.
ShutdownEmulation, ///< Shut down the emulator.
Interrupt, ///< Stop emulation as soon as possible.
Continue, ///< Resume emulation.
ContinueThreads, ///< Resume only specific threads (listed in frontend).
StepThread, ///< Step the active thread and resume only threads listed in frontend.
ShutdownEmulation, ///< Shut down the emulator.
};
class DebuggerBackend {

View file

@ -4,15 +4,15 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm>
#include <atomic>
#include <cctype>
#include <codecvt>
#include <locale>
#include <numeric>
#include <optional>
#include <thread>
#include <boost/algorithm/string.hpp>
#include "common/hex_util.h"
#include "common/logging.h"
#include "common/scope_exit.h"
@ -273,10 +273,12 @@ void GDBStub::ExecuteCommand(std::string_view packet, std::vector<DebuggerAction
break;
}
case 's':
actions.push_back(DebuggerAction::StepThreadLocked);
resume_threads.clear();
actions.push_back(DebuggerAction::StepThread);
break;
case 'C':
case 'c':
resume_threads.clear();
actions.push_back(DebuggerAction::Continue);
break;
case 'Z':
@ -467,29 +469,142 @@ void GDBStub::HandleQuery(std::string_view sv) {
}
void GDBStub::HandleVCont(std::string_view sv, std::vector<DebuggerAction>& actions) {
// Continuing and stepping are supported (signal is ignored, but required for GDB to use vCont)
// Continuing and stepping are supported (signal is ignored, but required for GDB to use vCont).
// Reference: https://sourceware.org/gdb/current/onlinedocs/gdb.html/Packets.html#vCont-packet
if (sv == "?") {
SendReply("vCont;c;C;s;S");
} else {
Kernel::KThread* stepped_thread = nullptr;
bool lock_execution = true;
std::vector<std::string> entries;
boost::split(entries, sv.substr(1), boost::is_any_of(";"));
for (auto const& thread_action : entries) {
std::vector<std::string> parts;
boost::split(parts, thread_action, boost::is_any_of(":"));
if (parts.size() == 1 && (parts[0] == "c" || parts[0].starts_with("C")))
lock_execution = false;
if (parts.size() == 2 && (parts[0] == "s" || parts[0].starts_with("S")))
stepped_thread = GetThreadByID(strtoll(parts[1].data(), nullptr, 16));
return;
}
if (sv.empty() || sv.front() != ';') {
SendReply(GDB_STUB_REPLY_ERR);
return;
}
enum class VContAction {
Continue,
Step,
};
struct VContDirective {
VContAction action;
Kernel::KThread* thread{};
bool all_threads{};
bool Matches(Kernel::KThread* candidate) const {
return all_threads || thread == candidate;
}
};
const auto is_hex_byte = [](std::string_view value) {
return value.size() == 2 && std::isxdigit(static_cast<unsigned char>(value[0])) &&
std::isxdigit(static_cast<unsigned char>(value[1]));
};
const auto is_hex_string = [](std::string_view value) {
return std::ranges::all_of(value, [](auto const c) { return std::isxdigit(int(c)); });
};
resume_threads.clear();
std::vector<VContDirective> directives;
std::string_view remaining = sv.substr(1);
while (!remaining.empty()) {
const auto entry_end = remaining.find(';');
const auto entry = remaining.substr(0, entry_end);
remaining = entry_end == std::string_view::npos ? std::string_view{} : remaining.substr(entry_end + 1);
if (entry.empty()) {
SendReply(GDB_STUB_REPLY_ERR);
return;
}
if (stepped_thread) {
backend.SetActiveThread(stepped_thread);
actions.push_back(lock_execution ? DebuggerAction::StepThreadLocked : DebuggerAction::StepThreadUnlocked);
} else {
actions.push_back(DebuggerAction::Continue);
const auto thread_sep = entry.find(':');
const auto action_token = entry.substr(0, thread_sep);
const auto thread_token = thread_sep == std::string_view::npos ? std::string_view{} : entry.substr(thread_sep + 1);
if (action_token.empty()) {
SendReply(GDB_STUB_REPLY_ERR);
return;
}
VContDirective directive;
if (action_token == "c") {
directive.action = VContAction::Continue;
} else if (action_token.front() == 'C' && is_hex_byte(action_token.substr(1))) {
directive.action = VContAction::Continue;
} else if (action_token == "s") {
directive.action = VContAction::Step;
} else if (action_token.front() == 'S' && is_hex_byte(action_token.substr(1))) {
directive.action = VContAction::Step;
} else {
SendReply(GDB_STUB_REPLY_ERR);
return;
}
if (thread_sep == std::string_view::npos || thread_token == "-1") {
directive.all_threads = true;
} else if (thread_token == "0") {
// A thread-id of 0 selects an arbitrary thread. While stopped, use the
// current active thread as that arbitrary choice.
directive.thread = backend.GetActiveThread();
} else if (thread_token.starts_with('p')) {
// We do not currently support multiprocess thread selectors.
SendReply(GDB_STUB_REPLY_ERR);
return;
} else if (is_hex_string(thread_token)) {
directive.thread = GetThreadByID(strtoull(std::string(thread_token).c_str(), nullptr, 16));
} else {
SendReply(GDB_STUB_REPLY_ERR);
return;
}
directives.push_back(directive);
}
if (directives.empty()) {
SendReply(GDB_STUB_REPLY_ERR);
return;
}
// Resolve the packet exactly as specified by the protocol: for each thread,
// the leftmost action with a matching thread-id wins.
Kernel::KThread* stepped_thread = nullptr;
std::vector<Kernel::KThread*> continue_threads;
auto& thread_list = debug_process->GetThreadList();
for (auto& thread : thread_list) {
const auto directive = std::find_if(directives.begin(), directives.end(),
[&](const VContDirective& candidate) {
return candidate.Matches(std::addressof(thread));
});
if (directive == directives.end()) {
continue;
}
switch (directive->action) {
case VContAction::Continue:
continue_threads.push_back(std::addressof(thread));
break;
case VContAction::Step:
if (stepped_thread) {
// The core can step at most one thread at a time.
SendReply(GDB_STUB_REPLY_ERR);
return;
}
stepped_thread = std::addressof(thread);
break;
}
}
if (stepped_thread) {
backend.SetActiveThread(stepped_thread);
resume_threads = std::move(continue_threads);
actions.push_back(DebuggerAction::StepThread);
} else if (continue_threads.size() == thread_list.size()) {
actions.push_back(DebuggerAction::Continue);
} else if (!continue_threads.empty()) {
resume_threads = std::move(continue_threads);
actions.push_back(DebuggerAction::ContinueThreads);
} else {
// A resume packet that leaves all threads stopped is not useful to execute.
SendReply(GDB_STUB_REPLY_ERR);
}
}

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
@ -52,6 +52,7 @@ struct GDBStub : public DebuggerFrontend {
std::unique_ptr<GDBStubArch> arch;
std::vector<char> current_command;
std::map<VAddr, u32> replaced_instructions;
std::vector<Kernel::KThread*> resume_threads;
bool no_ack{};
};

View file

@ -23,7 +23,7 @@
#define stat _stat64
#endif
#ifdef ANDROID
#ifdef __ANDROID__
#include "common/fs/fs_android.h"
#endif
@ -288,7 +288,7 @@ RealVfsFile::~RealVfsFile() {
}
std::string RealVfsFile::GetName() const {
#ifdef ANDROID
#ifdef __ANDROID__
if (path[0] != '/') {
return FS::Android::GetFilename(path);
}

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
@ -17,7 +17,8 @@
namespace Kernel {
GlobalSchedulerContext::GlobalSchedulerContext(KernelCore& kernel)
: m_kernel{kernel}, m_scheduler_lock{kernel} {}
: m_scheduler_lock{kernel}
{}
GlobalSchedulerContext::~GlobalSchedulerContext() = default;
@ -37,7 +38,7 @@ void GlobalSchedulerContext::RemoveThread(KThread* thread) noexcept {
/// and then does some core rebalancing. Preemption priorities can be found
/// in the array 'preemption_priorities'.
/// @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
// ordered from Core 0 to Core 3.
static constexpr std::array<u32, Core::Hardware::NUM_CPU_CORES> per_core{
@ -46,9 +47,9 @@ void GlobalSchedulerContext::PreemptThreads() noexcept {
59,
63,
};
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(m_kernel));
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
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

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
@ -50,7 +50,7 @@ public:
}
void AddThread(KThread* thread) noexcept;
void RemoveThread(KThread* thread) noexcept;
void PreemptThreads() noexcept;
void PreemptThreads(KernelCore& kernel) noexcept;
bool IsLocked() const noexcept;
void UnregisterDummyThreadForWakeup(KThread* thread) noexcept;
void RegisterDummyThreadForWakeup(KThread* thread) noexcept;
@ -60,7 +60,6 @@ private:
friend class KScopedSchedulerLock;
friend class KScopedSchedulerLockAndSleep;
KernelCore& m_kernel;
std::atomic_bool m_scheduler_update_needed{};
KSchedulerPriorityQueue m_priority_queue;
LockType m_scheduler_lock;

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -57,7 +60,7 @@ void KCodeMemory::Finalize() {
}
// Close the page group.
m_page_group->Close();
m_page_group->Close(m_kernel);
m_page_group->Finalize();
// Close our reference to our owner.

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
@ -106,7 +106,8 @@ public:
} // namespace
KConditionVariable::KConditionVariable(Core::System& system)
: m_system{system}, m_kernel{system.Kernel()} {}
: m_system{system}
{}
KConditionVariable::~KConditionVariable() = default;
@ -173,9 +174,9 @@ Result KConditionVariable::WaitForAddress(KernelCore& kernel, Handle handle, KPr
// Get the lock owner thread.
owner_thread = GetCurrentProcess(kernel)
.GetHandleTable()
.GetObjectWithoutPseudoHandle<KThread>(handle)
.ReleasePointerUnsafe();
.GetHandleTable()
.GetObjectWithoutPseudoHandle<KThread>(kernel, handle)
.ReleasePointerUnsafe();
R_UNLESS(owner_thread != nullptr, ResultInvalidHandle);
// Update the lock.
@ -194,9 +195,9 @@ Result KConditionVariable::WaitForAddress(KernelCore& kernel, Handle handle, KPr
R_RETURN(cur_thread->GetWaitResult());
}
void KConditionVariable::SignalImpl(KThread* thread) {
void KConditionVariable::SignalImpl(KernelCore& kernel, KThread* thread) {
// Check pre-conditions.
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(m_kernel));
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
// Update the tag.
KProcessAddress address = thread->GetAddressKey();
@ -211,8 +212,7 @@ void KConditionVariable::SignalImpl(KThread* thread) {
// TODO(bunnei): We should call CanAccessAtomic(..) here.
can_access = true;
if (can_access) {
UpdateLockAtomic(m_kernel, std::addressof(prev_tag), address, own_tag,
Svc::HandleWaitMask);
UpdateLockAtomic(kernel, std::addressof(prev_tag), address, own_tag, Svc::HandleWaitMask);
}
}
@ -222,11 +222,10 @@ void KConditionVariable::SignalImpl(KThread* thread) {
thread->EndWait(ResultSuccess);
} else {
// Get the previous owner.
KThread* owner_thread = GetCurrentProcess(m_kernel)
.GetHandleTable()
.GetObjectWithoutPseudoHandle<KThread>(
static_cast<Handle>(prev_tag & ~Svc::HandleWaitMask))
.ReleasePointerUnsafe();
KThread* owner_thread = GetCurrentProcess(kernel)
.GetHandleTable()
.GetObjectWithoutPseudoHandle<KThread>(kernel, Handle(prev_tag & ~Svc::HandleWaitMask))
.ReleasePointerUnsafe();
if (owner_thread) {
// Add the thread as a waiter on the owner.
@ -247,17 +246,16 @@ void KConditionVariable::Signal(u64 cv_key, s32 count) {
// Perform signaling.
s32 num_waiters{};
{
KScopedSchedulerLock sl(m_kernel);
KScopedSchedulerLock sl(m_system.Kernel());
auto it = m_tree.nfind_key({cv_key, -1});
while ((it != m_tree.end()) && (count <= 0 || num_waiters < count) &&
(it->GetConditionVariableKey() == cv_key)) {
while ((it != m_tree.end()) && (count <= 0 || num_waiters < count) && (it->GetConditionVariableKey() == cv_key)) {
KThread* target_thread = std::addressof(*it);
it = m_tree.erase(it);
target_thread->ClearConditionVariable();
this->SignalImpl(target_thread);
this->SignalImpl(m_system.Kernel(), target_thread);
++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 (it == m_tree.end() || it->GetConditionVariableKey() != cv_key) {
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) {
// Prepare to wait.
KThread* cur_thread = GetCurrentThreadPointer(m_kernel);
KThread* cur_thread = GetCurrentThreadPointer(m_system.Kernel());
KHardwareTimer* timer{};
ThreadQueueImplForKConditionVariableWaitConditionVariable wait_queue(m_kernel,
ThreadQueueImplForKConditionVariableWaitConditionVariable wait_queue(m_system.Kernel(),
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.
if (cur_thread->IsTerminationRequested()) {
@ -309,12 +307,12 @@ Result KConditionVariable::Wait(KProcessAddress addr, u64 key, u32 value, s64 ti
// Write to the cv key.
{
constexpr u32 HasWaiterFlag = 1;
WriteToUser(m_kernel, key, HasWaiterFlag);
WriteToUser(m_system.Kernel(), key, HasWaiterFlag);
std::atomic_thread_fence(std::memory_order_seq_cst);
}
// Write the value to userspace.
if (!WriteToUser(m_kernel, addr, next_value)) {
if (!WriteToUser(m_system.Kernel(), addr, next_value)) {
slp.CancelSleep();
R_THROW(ResultInvalidCurrentMemory);
}

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -26,19 +29,17 @@ public:
// Arbitration.
static Result SignalToAddress(KernelCore& kernel, KProcessAddress addr);
static Result WaitForAddress(KernelCore& kernel, Handle handle, KProcessAddress addr,
u32 value);
static Result WaitForAddress(KernelCore& kernel, Handle handle, KProcessAddress addr, u32 value);
// Condition variable.
void Signal(u64 cv_key, s32 count);
Result Wait(KProcessAddress addr, u64 key, u32 value, s64 timeout);
private:
void SignalImpl(KThread* thread);
void SignalImpl(KernelCore& kernel, KThread* thread);
private:
Core::System& m_system;
KernelCore& m_kernel;
ThreadTree m_tree{};
};

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
@ -6,14 +6,15 @@
#include "core/hle/kernel/k_handle_table.h"
#include "core/hle/kernel/k_process.h"
#include "core/hle/kernel/kernel.h"
namespace Kernel {
void KHandleTable::Finalize() {
void KHandleTable::Finalize(KernelCore& kernel) {
// Get the table and clear our record of it.
u16 saved_table_size = 0;
{
KScopedDisableDispatch dd{m_kernel};
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
std::swap(m_table_size, saved_table_size);
@ -27,7 +28,7 @@ void KHandleTable::Finalize() {
}
}
bool KHandleTable::Remove(Handle handle) {
bool KHandleTable::Remove(KernelCore& kernel, Handle handle) {
// Don't allow removal of a pseudo-handle.
if (Svc::IsPseudoHandle(handle)) [[unlikely]] {
return false;
@ -42,7 +43,7 @@ bool KHandleTable::Remove(Handle handle) {
// Find the object and free the entry.
KAutoObject* obj = nullptr;
{
KScopedDisableDispatch dd{m_kernel};
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
if (this->IsValidHandle(handle)) [[likely]] {
@ -56,13 +57,13 @@ bool KHandleTable::Remove(Handle handle) {
}
// Close the object.
m_kernel.UnregisterInUseObject(obj);
kernel.UnregisterInUseObject(obj);
obj->Close();
return true;
}
Result KHandleTable::Add(Handle* out_handle, KAutoObject* obj) {
KScopedDisableDispatch dd{m_kernel};
Result KHandleTable::Add(KernelCore& kernel, Handle* out_handle, KAutoObject* obj) {
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
// Never exceed our capacity.
@ -84,8 +85,7 @@ Result KHandleTable::Add(Handle* out_handle, KAutoObject* obj) {
R_SUCCEED();
}
KScopedAutoObject<KAutoObject> KHandleTable::GetObjectForIpc(Handle handle,
KThread* cur_thread) const {
KScopedAutoObject<KAutoObject> KHandleTable::GetObjectForIpc(KernelCore& kernel, Handle handle, KThread* cur_thread) const {
// Handle pseudo-handles.
ASSERT(cur_thread != nullptr);
if (handle == Svc::PseudoHandle::CurrentProcess) {
@ -96,12 +96,11 @@ KScopedAutoObject<KAutoObject> KHandleTable::GetObjectForIpc(Handle handle,
if (handle == Svc::PseudoHandle::CurrentThread) {
return cur_thread;
}
return GetObjectForIpcWithoutPseudoHandle(handle);
return GetObjectForIpcWithoutPseudoHandle(kernel, handle);
}
Result KHandleTable::Reserve(Handle* out_handle) {
KScopedDisableDispatch dd{m_kernel};
Result KHandleTable::Reserve(KernelCore& kernel, Handle* out_handle) {
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
// Never exceed our capacity.
@ -111,8 +110,8 @@ Result KHandleTable::Reserve(Handle* out_handle) {
R_SUCCEED();
}
void KHandleTable::Unreserve(Handle handle) {
KScopedDisableDispatch dd{m_kernel};
void KHandleTable::Unreserve(KernelCore& kernel, Handle handle) {
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
// Unpack the handle.
@ -130,8 +129,8 @@ void KHandleTable::Unreserve(Handle handle) {
}
}
void KHandleTable::Register(Handle handle, KAutoObject* obj) {
KScopedDisableDispatch dd{m_kernel};
void KHandleTable::Register(KernelCore& kernel, Handle handle, KAutoObject* obj) {
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
// Unpack the handle.

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
@ -31,14 +31,14 @@ public:
static constexpr size_t MaxTableSize = 1024;
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.
R_UNLESS(size <= static_cast<s32>(MaxTableSize), ResultOutOfMemory);
// Lock.
KScopedDisableDispatch dd{m_kernel};
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
// Initialize all fields.
@ -68,13 +68,13 @@ public:
return m_max_count;
}
void Finalize();
bool Remove(Handle handle);
void Finalize(KernelCore& kernel);
bool Remove(KernelCore& kernel, Handle handle);
template <typename T = KAutoObject>
KScopedAutoObject<T> GetObjectWithoutPseudoHandle(Handle handle) const {
KScopedAutoObject<T> GetObjectWithoutPseudoHandle(KernelCore& kernel, Handle handle) const {
// Lock and look up in table.
KScopedDisableDispatch dd{m_kernel};
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
if constexpr (std::is_same_v<T, KAutoObject>) {
@ -89,55 +89,52 @@ public:
}
template <typename T = KAutoObject>
KScopedAutoObject<T> GetObject(Handle handle) const {
KScopedAutoObject<T> GetObject(KernelCore& kernel, Handle handle) const {
// Handle pseudo-handles.
if constexpr (std::derived_from<KProcess, T>) {
if (handle == Svc::PseudoHandle::CurrentProcess) {
auto* const cur_process = GetCurrentProcessPointer(m_kernel);
auto* const cur_process = GetCurrentProcessPointer(kernel);
ASSERT(cur_process != nullptr);
return cur_process;
}
} else if constexpr (std::derived_from<KThread, T>) {
if (handle == Svc::PseudoHandle::CurrentThread) {
auto* const cur_thread = GetCurrentThreadPointer(m_kernel);
auto* const cur_thread = GetCurrentThreadPointer(kernel);
ASSERT(cur_thread != nullptr);
return cur_thread;
}
}
return this->template GetObjectWithoutPseudoHandle<T>(handle);
return this->template GetObjectWithoutPseudoHandle<T>(kernel, handle);
}
KScopedAutoObject<KAutoObject> GetObjectForIpcWithoutPseudoHandle(Handle handle) const {
KScopedAutoObject<KAutoObject> GetObjectForIpcWithoutPseudoHandle(KernelCore& kernel, Handle handle) const {
// Lock and look up in table.
KScopedDisableDispatch dd{m_kernel};
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
return this->GetObjectImpl(handle);
}
KScopedAutoObject<KAutoObject> GetObjectForIpc(Handle handle, KThread* cur_thread) const;
KScopedAutoObject<KAutoObject> GetObjectByIndex(Handle* out_handle, size_t index) const {
KScopedDisableDispatch dd{m_kernel};
KScopedAutoObject<KAutoObject> GetObjectForIpc(KernelCore& kernel, Handle handle, KThread* cur_thread) const;
KScopedAutoObject<KAutoObject> GetObjectByIndex(KernelCore& kernel, Handle* out_handle, size_t index) const {
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
return this->GetObjectByIndexImpl(out_handle, index);
}
Result Reserve(Handle* out_handle);
void Unreserve(Handle handle);
Result Reserve(KernelCore& kernel, Handle* out_handle);
void Unreserve(KernelCore& kernel, Handle handle);
Result Add(Handle* out_handle, KAutoObject* obj);
void Register(Handle handle, KAutoObject* obj);
Result Add(KernelCore& kernel, Handle* out_handle, KAutoObject* obj);
void Register(KernelCore& kernel, Handle handle, KAutoObject* obj);
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.
size_t num_opened;
{
// Lock the table.
KScopedDisableDispatch dd{m_kernel};
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
for (num_opened = 0; num_opened < num_handles; num_opened++) {
// Get the current handle.
@ -177,13 +174,9 @@ public:
private:
s32 AllocateEntry() {
ASSERT(m_count < m_table_size);
const auto index = m_free_head_index;
m_free_head_index = m_entry_infos[index].GetNextFreeIndex();
m_max_count = (std::max)(m_max_count, ++m_count);
return index;
}
@ -302,7 +295,6 @@ private:
};
private:
KernelCore& m_kernel;
std::array<EntryInfo, MaxTableSize> m_entry_infos{};
std::array<KAutoObject*, MaxTableSize> m_objects{};
mutable KSpinLock m_lock;

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -21,8 +24,8 @@ void KPageGroup::Finalize() {
m_last_block = nullptr;
}
void KPageGroup::CloseAndReset() {
auto& mm = m_kernel.MemoryManager();
void KPageGroup::CloseAndReset(KernelCore& kernel) {
auto& mm = kernel.MemoryManager();
KBlockInfo* cur = m_first_block;
while (cur != nullptr) {
@ -76,28 +79,22 @@ Result KPageGroup::AddBlock(KPhysicalAddress addr, size_t num_pages) {
R_SUCCEED();
}
void KPageGroup::Open() const {
auto& mm = m_kernel.MemoryManager();
for (const auto& it : *this) {
void KPageGroup::Open(KernelCore& kernel) const {
auto& mm = kernel.MemoryManager();
for (const auto& it : *this)
mm.Open(it.GetAddress(), it.GetNumPages());
}
}
void KPageGroup::OpenFirst() const {
auto& mm = m_kernel.MemoryManager();
for (const auto& it : *this) {
void KPageGroup::OpenFirst(KernelCore& kernel) const {
auto& mm = kernel.MemoryManager();
for (const auto& it : *this)
mm.OpenFirst(it.GetAddress(), it.GetNumPages());
}
}
void KPageGroup::Close() const {
auto& mm = m_kernel.MemoryManager();
for (const auto& it : *this) {
void KPageGroup::Close(KernelCore& kernel) const {
auto& mm = kernel.MemoryManager();
for (const auto& it : *this)
mm.Close(it.GetAddress(), it.GetNumPages());
}
}
bool KPageGroup::IsEquivalentTo(const KPageGroup& rhs) const {

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -139,12 +142,12 @@ public:
};
explicit KPageGroup(KernelCore& kernel, KBlockInfoManager* m)
: m_kernel{kernel}, m_manager{m} {}
: m_manager{m} {}
~KPageGroup() {
this->Finalize();
}
void CloseAndReset();
void CloseAndReset(KernelCore& kernel);
void Finalize();
Iterator begin() const {
@ -158,9 +161,9 @@ public:
}
Result AddBlock(KPhysicalAddress addr, size_t num_pages);
void Open() const;
void OpenFirst() const;
void Close() const;
void Open(KernelCore& kernel) const;
void OpenFirst(KernelCore& kernel) const;
void Close(KernelCore& kernel) const;
size_t GetNumPages() const;
@ -175,7 +178,6 @@ public:
}
private:
KernelCore& m_kernel;
KBlockInfo* m_first_block{};
KBlockInfo* m_last_block{};
KBlockInfoManager* m_manager{};
@ -183,21 +185,24 @@ private:
class KScopedPageGroup {
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 (not_first) {
m_pg->Open();
m_pg->Open(kernel);
} else {
m_pg->OpenFirst();
m_pg->OpenFirst(kernel);
}
}
}
explicit KScopedPageGroup(const KPageGroup& gp, bool not_first = true)
: KScopedPageGroup(std::addressof(gp), not_first) {}
explicit KScopedPageGroup(KernelCore& kernel, const KPageGroup& gp, bool not_first = true)
: KScopedPageGroup(kernel, std::addressof(gp), not_first) {}
~KScopedPageGroup() {
if (m_pg) {
m_pg->Close();
}
if (m_pg)
m_pg->Close(m_kernel);
}
void CancelClose() {
@ -205,6 +210,7 @@ public:
}
private:
KernelCore& m_kernel;
const KPageGroup* m_pg{};
};

View file

@ -127,22 +127,22 @@ constexpr Common::MemoryPermission ConvertToMemoryPermission(KMemoryPermission p
} // namespace
void KPageTableBase::MemoryRange::Open() {
void KPageTableBase::MemoryRange::Open(KernelCore& kernel) {
// If the range contains heap pages, open them.
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 (this->IsHeap()) {
m_kernel.MemoryManager().Close(this->GetAddress(), this->GetSize() / PageSize);
kernel.MemoryManager().Close(this->GetAddress(), this->GetSize() / PageSize);
}
}
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) {}
KPageTableBase::~KPageTableBase() = default;
@ -177,9 +177,9 @@ Result KPageTableBase::InitializeForKernel(bool is_64_bit, KVirtualAddress start
m_mapped_ipc_server_memory = 0;
m_memory_block_slab_manager =
m_kernel.GetSystemSystemResource().GetMemoryBlockSlabManagerPointer();
m_block_info_manager = m_kernel.GetSystemSystemResource().GetBlockInfoManagerPointer();
m_resource_limit = m_kernel.GetSystemResourceLimit();
m_system.Kernel().GetSystemSystemResource().GetMemoryBlockSlabManagerPointer();
m_block_info_manager = m_system.Kernel().GetSystemSystemResource().GetBlockInfoManagerPointer();
m_resource_limit = m_system.Kernel().GetSystemResourceLimit();
m_allocate_option = KMemoryManager::EncodeOption(KMemoryManager::Pool::System,
KMemoryManager::Direction::FromFront);
@ -469,11 +469,11 @@ void KPageTableBase::Finalize() {
}
// 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);
// Free the pages.
pg.CloseAndReset();
pg.CloseAndReset(m_system.Kernel());
};
// Finalize memory blocks.
@ -490,7 +490,7 @@ void KPageTableBase::Finalize() {
// Release any insecure mapped memory.
if (m_mapped_insecure_memory) {
if (auto* const insecure_resource_limit =
KSystemControl::GetInsecureMemoryResourceLimit(m_kernel);
KSystemControl::GetInsecureMemoryResourceLimit(m_system.Kernel());
insecure_resource_limit != nullptr) {
insecure_resource_limit->Release(Svc::LimitableResource::PhysicalMemoryMax,
m_mapped_insecure_memory);
@ -833,7 +833,7 @@ Result KPageTableBase::LockMemoryAndOpen(KPageGroup* out_pg, KPhysicalAddress* o
// If we have an output group, open.
if (out_pg) {
out_pg->Open();
out_pg->Open(m_system.Kernel());
}
R_SUCCEED();
@ -1041,7 +1041,7 @@ Result KPageTableBase::MapMemory(KProcessAddress dst_address, KProcessAddress sr
const size_t num_pages = size / PageSize;
// 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.
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;
// 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.
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;
// 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.
R_TRY(this->MakePageGroup(pg, src_address, num_pages));
@ -1312,7 +1312,7 @@ Result KPageTableBase::UnmapCodeMemory(KProcessAddress dst_address, KProcessAddr
bool reprotected_pages = false;
SCOPE_EXIT {
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;
// 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.
R_TRY(this->MakePageGroup(pg, dst_address, num_pages));
@ -1383,7 +1383,7 @@ Result KPageTableBase::UnmapCodeMemory(KProcessAddress dst_address, KProcessAddr
Result KPageTableBase::MapInsecureMemory(KProcessAddress address, size_t size) {
// 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 =
static_cast<KMemoryManager::Pool>(KSystemControl::GetInsecureMemoryPool());
@ -1394,8 +1394,8 @@ Result KPageTableBase::MapInsecureMemory(KProcessAddress address, size_t size) {
R_UNLESS(memory_reservation.Succeeded(), ResultOutOfMemory);
// Allocate pages for the insecure memory.
KPageGroup pg(m_kernel, m_block_info_manager);
R_TRY(m_kernel.MemoryManager().AllocateAndOpen(
KPageGroup pg(m_system.Kernel(), m_block_info_manager);
R_TRY(m_system.Kernel().MemoryManager().AllocateAndOpen(
std::addressof(pg), size / PageSize,
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
// automatically.
SCOPE_EXIT {
pg.Close();
pg.Close(m_system.Kernel());
};
// Clear all the newly allocated pages.
@ -1491,7 +1491,7 @@ Result KPageTableBase::UnmapInsecureMemory(KProcessAddress address, size_t size)
// Release the insecure memory from the insecure limit.
if (auto* const insecure_resource_limit =
KSystemControl::GetInsecureMemoryResourceLimit(m_kernel);
KSystemControl::GetInsecureMemoryResourceLimit(m_system.Kernel());
insecure_resource_limit != nullptr) {
insecure_resource_limit->Release(Svc::LimitableResource::PhysicalMemoryMax, size);
}
@ -1603,15 +1603,15 @@ Result KPageTableBase::AllocateAndMapPagesImpl(PageLinkedList* page_list, KProce
ASSERT(this->IsLockedByCurrentThread());
// 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.
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.
SCOPE_EXIT {
pg.Close();
pg.Close(m_system.Kernel());
};
// Clear all pages.
@ -1992,7 +1992,7 @@ Result KPageTableBase::SetProcessMemoryPermission(KProcessAddress addr, size_t s
KMemoryAttribute::All, KMemoryAttribute::None));
// 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.
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.
if (is_x) {
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();
@ -2193,15 +2193,15 @@ Result KPageTableBase::SetHeapSize(KProcessAddress* out, size_t size) {
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
// Allocate pages for the heap extension.
KPageGroup pg(m_kernel, m_block_info_manager);
R_TRY(m_kernel.MemoryManager().AllocateAndOpen(std::addressof(pg), allocation_size / PageSize,
KPageGroup pg(m_system.Kernel(), m_block_info_manager);
R_TRY(m_system.Kernel().MemoryManager().AllocateAndOpen(std::addressof(pg), allocation_size / PageSize,
m_allocate_option));
// 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
// automatically.
SCOPE_EXIT {
pg.Close();
pg.Close(m_system.Kernel());
};
// 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));
// 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);
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;
// 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);
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) {
// Get the memory region.
const KMemoryRegion* region =
m_kernel.MemoryLayout().GetPhysicalMemoryRegionTree().FindFirstDerived(region_type);
m_system.Kernel().MemoryLayout().GetPhysicalMemoryRegionTree().FindFirstDerived(region_type);
R_UNLESS(region != nullptr, ResultOutOfRange);
// 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));
// Open a new reference to the pages in the group.
out->Open();
out->Open(m_system.Kernel());
R_SUCCEED();
}
@ -3051,7 +3051,7 @@ Result KPageTableBase::InvalidateProcessDataCache(KProcessAddress address, size_
// Invalidate the block.
if (cur_size > 0) {
// 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.
@ -3075,7 +3075,7 @@ Result KPageTableBase::InvalidateProcessDataCache(KProcessAddress address, size_
// Invalidate the last block.
if (cur_size > 0) {
// 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();
@ -3083,7 +3083,7 @@ Result KPageTableBase::InvalidateProcessDataCache(KProcessAddress address, size_
Result KPageTableBase::InvalidateCurrentProcessDataCache(KProcessAddress address, size_t size) {
// 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.
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.
if (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);
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.
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);
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.
if (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),
ResultInvalidCurrentMemory);
StoreDataCache(GetLinearMappedVirtualPointer(m_kernel, cur_addr), copy_size);
StoreDataCache(GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr), copy_size);
src_address += copy_size;
cur_addr += copy_size;
@ -3253,11 +3253,11 @@ Result KPageTableBase::WriteDebugMemory(KProcessAddress dst_address, KProcessAdd
// Copy remaining data.
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),
ResultInvalidCurrentMemory);
StoreDataCache(GetLinearMappedVirtualPointer(m_kernel, cur_addr), cur_size);
StoreDataCache(GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr), cur_size);
}
R_SUCCEED();
@ -3295,7 +3295,7 @@ Result KPageTableBase::WriteDebugMemory(KProcessAddress dst_address, KProcessAdd
R_TRY(PerformCopy());
// 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();
}
@ -3311,7 +3311,7 @@ Result KPageTableBase::ReadIoMemoryImpl(KProcessAddress dst_addr, KPhysicalAddre
const size_t map_size = map_end - map_start;
// 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.
KScopedPageTableUpdater updater(this);
@ -3347,7 +3347,7 @@ Result KPageTableBase::WriteIoMemoryImpl(KPhysicalAddress phys_addr, KProcessAdd
const size_t map_size = map_end - map_start;
// 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.
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.
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.
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.
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.
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));
// We got the range, so open it.
out->Open();
out->Open(m_system.Kernel());
R_SUCCEED();
}
@ -3624,7 +3624,7 @@ Result KPageTableBase::OpenMemoryRangeForUnmapDeviceAddressSpace(MemoryRange* ou
KMemoryAttribute::DeviceShared | KMemoryAttribute::Locked, KMemoryAttribute::DeviceShared));
// We got the range, so open it.
out->Open();
out->Open(m_system.Kernel());
R_SUCCEED();
}
@ -3697,7 +3697,7 @@ Result KPageTableBase::OpenMemoryRangeForProcessCacheOperation(MemoryRange* out,
KMemoryAttribute::None));
// We got the range, so open it.
out->Open();
out->Open(m_system.Kernel());
R_SUCCEED();
}
@ -3710,7 +3710,7 @@ Result KPageTableBase::CopyMemoryFromLinearToUser(
R_UNLESS(this->Contains(src_addr, size), ResultInvalidCurrentMemory);
// Get the destination memory reference.
auto& dst_memory = GetCurrentMemory(m_kernel);
auto& dst_memory = GetCurrentMemory(m_system.Kernel());
// Copy the memory.
{
@ -3745,7 +3745,7 @@ Result KPageTableBase::CopyMemoryFromLinearToUser(
if (cur_size >= sizeof(u32)) {
const size_t copy_size = Common::AlignDown(cur_size, sizeof(u32));
R_UNLESS(dst_memory.WriteBlock(dst_addr,
GetLinearMappedVirtualPointer(m_kernel, cur_addr),
GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr),
copy_size),
ResultInvalidCurrentMemory);
@ -3757,7 +3757,7 @@ Result KPageTableBase::CopyMemoryFromLinearToUser(
// Copy remaining data.
if (cur_size > 0) {
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);
}
@ -3836,7 +3836,7 @@ Result KPageTableBase::CopyMemoryFromLinearToKernel(
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), ResultInvalidCurrentMemory);
// 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();
};
@ -3884,7 +3884,7 @@ Result KPageTableBase::CopyMemoryFromUserToLinear(
R_UNLESS(this->Contains(dst_addr, size), ResultInvalidCurrentMemory);
// Get the source memory reference.
auto& src_memory = GetCurrentMemory(m_kernel);
auto& src_memory = GetCurrentMemory(m_system.Kernel());
// Copy the memory.
{
@ -3919,7 +3919,7 @@ Result KPageTableBase::CopyMemoryFromUserToLinear(
if (cur_size >= sizeof(u32)) {
const size_t copy_size = Common::AlignDown(cur_size, sizeof(u32));
R_UNLESS(src_memory.ReadBlock(src_addr,
GetLinearMappedVirtualPointer(m_kernel, cur_addr),
GetLinearMappedVirtualPointer(m_system.Kernel(), cur_addr),
copy_size),
ResultInvalidCurrentMemory);
src_addr += copy_size;
@ -3930,7 +3930,7 @@ Result KPageTableBase::CopyMemoryFromUserToLinear(
// Copy remaining data.
if (cur_size > 0) {
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);
}
@ -4011,7 +4011,7 @@ Result KPageTableBase::CopyMemoryFromKernelToLinear(KProcessAddress dst_addr, si
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), ResultInvalidCurrentMemory);
// 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();
};
@ -4162,8 +4162,8 @@ Result KPageTableBase::CopyMemoryFromHeapToHeap(
R_UNLESS(IsHeapPhysicalAddress(cur_dst_addr), ResultInvalidCurrentMemory);
// Copy the data.
std::memcpy(GetHeapVirtualPointer(m_kernel, cur_dst_addr),
GetHeapVirtualPointer(m_kernel, cur_src_addr), cur_copy_size);
std::memcpy(GetHeapVirtualPointer(m_system.Kernel(), cur_dst_addr),
GetHeapVirtualPointer(m_system.Kernel(), cur_src_addr), cur_copy_size);
// Update.
cur_src_block_addr = src_next_entry.phys_addr;
@ -4296,8 +4296,8 @@ Result KPageTableBase::CopyMemoryFromHeapToHeapWithoutCheckDestination(
R_UNLESS(IsHeapPhysicalAddress(cur_dst_addr), ResultInvalidCurrentMemory);
// Copy the data.
std::memcpy(GetHeapVirtualPointer(m_kernel, cur_dst_addr),
GetHeapVirtualPointer(m_kernel, cur_src_addr), cur_copy_size);
std::memcpy(GetHeapVirtualPointer(m_system.Kernel(), cur_dst_addr),
GetHeapVirtualPointer(m_system.Kernel(), cur_src_addr), cur_copy_size);
// Update.
cur_src_block_addr = src_next_entry.phys_addr;
@ -4506,10 +4506,10 @@ Result KPageTableBase::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
// free on scope exit.
SCOPE_EXIT {
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) {
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.
if (aligned_src_start < mapping_src_start) {
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);
}
@ -4534,7 +4534,7 @@ Result KPageTableBase::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
if (mapping_src_end < aligned_src_end &&
(aligned_src_start < mapping_src_end || aligned_src_start == mapping_src_start)) {
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);
}
@ -4560,7 +4560,7 @@ Result KPageTableBase::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
// Map the start page, if we have one.
if (start_partial_page != 0) {
// 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) {
const size_t partial_offset = src_start - aligned_src_start;
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::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);
if (clear_size > 0) {
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.
if (end_partial_page != 0) {
// 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) {
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);
std::memset(end_partial_virt + copy_size, fill_val, PageSize - copy_size);
} else {
@ -5173,15 +5173,15 @@ Result KPageTableBase::MapPhysicalMemory(KProcessAddress address, size_t size) {
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
// Allocate pages for the new memory.
KPageGroup pg(m_kernel, m_block_info_manager);
R_TRY(m_kernel.MemoryManager().AllocateForProcess(
KPageGroup pg(m_system.Kernel(), m_block_info_manager);
R_TRY(m_system.Kernel().MemoryManager().AllocateForProcess(
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.
auto pg_guard = SCOPE_GUARD {
pg.OpenFirst();
pg.Close();
pg.OpenFirst(m_system.Kernel());
pg.Close(m_system.Kernel());
};
// Map the memory.
@ -5304,12 +5304,12 @@ Result KPageTableBase::MapPhysicalMemory(KProcessAddress address, size_t size) {
}
// Release any remaining unmapped memory.
m_kernel.MemoryManager().OpenFirst(pg_phys_addr, pg_pages);
m_kernel.MemoryManager().Close(pg_phys_addr, pg_pages);
m_system.Kernel().MemoryManager().OpenFirst(pg_phys_addr, pg_pages);
m_system.Kernel().MemoryManager().Close(pg_phys_addr, pg_pages);
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());
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.
{
// 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 {
cur_pg.OpenFirst();
cur_pg.Close();
cur_pg.OpenFirst(m_system.Kernel());
cur_pg.Close(m_system.Kernel());
};
size_t remain_pages = map_pages;
@ -5706,9 +5706,9 @@ Result KPageTableBase::Operate(PageLinkedList* page_list, KProcessAddress virt_a
const bool separate_heap = operation == OperationType::UnmapPhysical;
// 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 {
pages_to_close.CloseAndReset();
pages_to_close.CloseAndReset(m_system.Kernel());
};
// 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.
if (this->IsHeapPhysicalAddress(phys_addr)) {
m_kernel.MemoryManager().Open(phys_addr, num_pages);
m_system.Kernel().MemoryManager().Open(phys_addr, num_pages);
}
R_SUCCEED();
@ -5767,7 +5767,7 @@ Result KPageTableBase::Operate(PageLinkedList* page_list, KProcessAddress virt_a
const bool separate_heap = operation == OperationType::MapFirstGroupPhysical;
// 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) {
const size_t size{node.GetNumPages() * PageSize};

View file

@ -61,14 +61,12 @@ public:
class MemoryRange {
private:
KernelCore& m_kernel;
KPhysicalAddress m_address;
size_t m_size;
bool m_heap;
KPhysicalAddress m_address = 0;
size_t m_size = 0;
bool m_heap = false;
public:
explicit MemoryRange(KernelCore& kernel)
: m_kernel(kernel), m_address(0), m_size(0), m_heap(false) {}
explicit MemoryRange() : m_address(0), m_size(0), m_heap(false) {}
void Set(KPhysicalAddress address, size_t size, bool heap) {
m_address = address;
@ -86,8 +84,8 @@ public:
return m_heap;
}
void Open();
void Close();
void Open(KernelCore& kernel);
void Close(KernelCore& kernel);
};
protected:
@ -189,7 +187,6 @@ private:
};
private:
KernelCore& m_kernel;
Core::System& m_system;
KProcessAddress m_address_space_start{};
KProcessAddress m_address_space_end{};
@ -329,35 +326,35 @@ protected:
bool IsLinearMappedPhysicalAddress(KPhysicalAddress phys_addr) {
ASSERT(this->IsLockedByCurrentThread());
return m_kernel.MemoryLayout().IsLinearMappedPhysicalAddress(
return m_system.Kernel().MemoryLayout().IsLinearMappedPhysicalAddress(
m_cached_physical_linear_region, phys_addr);
}
bool IsLinearMappedPhysicalAddress(KPhysicalAddress phys_addr, size_t size) {
ASSERT(this->IsLockedByCurrentThread());
return m_kernel.MemoryLayout().IsLinearMappedPhysicalAddress(
return m_system.Kernel().MemoryLayout().IsLinearMappedPhysicalAddress(
m_cached_physical_linear_region, phys_addr, size);
}
bool IsHeapPhysicalAddress(KPhysicalAddress phys_addr) {
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);
}
bool IsHeapPhysicalAddress(KPhysicalAddress phys_addr, size_t size) {
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);
}
bool IsHeapPhysicalAddressForFinalize(KPhysicalAddress phys_addr) {
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);
}
@ -744,15 +741,15 @@ public:
// Member heap
u8* GetHeapVirtualPointer(KPhysicalAddress addr) {
return GetHeapVirtualPointer(m_kernel, addr);
return GetHeapVirtualPointer(m_system.Kernel(), addr);
}
KPhysicalAddress GetHeapPhysicalAddress(KVirtualAddress addr) {
return GetHeapPhysicalAddress(m_kernel, addr);
return GetHeapPhysicalAddress(m_system.Kernel(), addr);
}
KVirtualAddress GetHeapVirtualAddress(KPhysicalAddress addr) {
return GetHeapVirtualAddress(m_kernel, addr);
return GetHeapVirtualAddress(m_system.Kernel(), addr);
}
// TODO: GetPageTableVirtualAddress

View file

@ -993,7 +993,7 @@ Result KProcess::Run(s32 priority, size_t stack_size) {
// Add the thread to our handle table.
Handle thread_handle;
R_TRY(m_handle_table.Add(std::addressof(thread_handle), main_thread));
R_TRY(m_handle_table.Add(m_kernel, std::addressof(thread_handle), main_thread));
// Set the thread arguments.
main_thread->GetContext().r[0] = 0;

View file

@ -564,7 +564,7 @@ private:
Result InitializeHandleTable(s32 size) {
// Try to initialize the handle table.
R_TRY(m_handle_table.Initialize(size));
R_TRY(m_handle_table.Initialize(m_kernel, size));
// We succeeded, so note that we did.
m_is_handle_table_initialized = true;
@ -573,7 +573,7 @@ private:
void FinalizeHandleTable() {
// Finalize the table.
m_handle_table.Finalize();
m_handle_table.Finalize(m_kernel);
// Note that the table is finalized.
m_is_handle_table_initialized = false;

View file

@ -159,7 +159,7 @@ private:
};
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,
const MessageBuffer& src_msg,
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 (R_SUCCEEDED(result) && src_handle != Svc::InvalidHandle) {
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()) {
Result add_result =
dst_handle_table.Add(std::addressof(dst_handle), obj.GetPointerUnsafe());
Result add_result = dst_handle_table.Add(kernel, std::addressof(dst_handle), obj.GetPointerUnsafe());
if (R_FAILED(add_result)) {
result = add_result;
dst_handle = Svc::InvalidHandle;
@ -213,12 +212,10 @@ Result ProcessMessageSpecialData(s32& offset, KProcess& dst_process, KProcess& s
if (src_handle != Svc::InvalidHandle) {
if (R_SUCCEEDED(result)) {
KScopedAutoObject obj =
src_handle_table.GetObjectForIpcWithoutPseudoHandle(src_handle);
src_handle_table.GetObjectForIpcWithoutPseudoHandle(kernel, src_handle);
if (obj.IsNotNull()) {
Result add_result = dst_handle_table.Add(std::addressof(dst_handle),
obj.GetPointerUnsafe());
src_handle_table.Remove(src_handle);
Result add_result = dst_handle_table.Add(kernel, std::addressof(dst_handle), obj.GetPointerUnsafe());
src_handle_table.Remove(kernel, src_handle);
if (R_FAILED(add_result)) {
result = add_result;
@ -228,7 +225,7 @@ Result ProcessMessageSpecialData(s32& offset, KProcess& dst_process, KProcess& s
result = ResultInvalidHandle;
}
} 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();
}
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.
const MessageBuffer dst_msg(dst_msg_ptr, dst_buffer_size);
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);
if (handle != Svc::InvalidHandle) {
dst_handle_table.Remove(handle);
dst_handle_table.Remove(kernel, handle);
}
offset = dst_msg.SetHandle(offset, Svc::InvalidHandle);
}
}
Result CleanupServerHandles(KernelCore& kernel, uint64_t message, size_t buffer_size,
KPhysicalAddress message_paddr) {
Result CleanupServerHandles(KernelCore& kernel, uint64_t message, size_t buffer_size, KPhysicalAddress message_paddr) {
// Server is assumed to be current thread.
KThread& thread = GetCurrentThread(kernel);
@ -410,7 +406,7 @@ Result CleanupServerHandles(KernelCore& kernel, uint64_t message, size_t buffer_
// Close the handles.
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));
}
}
@ -639,7 +635,7 @@ Result ReceiveMessage(KernelCore& kernel, bool& recv_list_broken, uint64_t dst_m
// Cleanup special data.
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.
@ -661,7 +657,7 @@ Result ReceiveMessage(KernelCore& kernel, bool& recv_list_broken, uint64_t dst_m
};
// 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));
}
@ -922,7 +918,7 @@ Result SendMessage(KernelCore& kernel, uint64_t src_message_buffer, size_t src_b
// Cleanup special data.
if (processed_special_data) {
if (src_header.GetHasSpecialHeader()) {
CleanupSpecialData(dst_process, dst_msg_ptr, dst_buffer_size);
CleanupSpecialData(kernel, dst_process, dst_msg_ptr, dst_buffer_size);
}
} else {
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));
processed_special_data = true;
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));
}

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -68,7 +71,7 @@ Result KSharedMemory::Initialize(Core::DeviceMemory& device_memory, KProcess* ow
void KSharedMemory::Finalize() {
// Close and finalize the page group.
m_page_group->Close();
m_page_group->Close(m_kernel);
m_page_group->Finalize();
// Release the memory reservation.

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -53,7 +56,7 @@ void KTransferMemory::Finalize() {
}
// Close the page group.
m_page_group->Close();
m_page_group->Close(m_kernel);
m_page_group->Finalize();
}

View file

@ -259,7 +259,7 @@ struct KernelCore::Impl {
preemption_event = Core::Timing::CreateEvent("PreemptionCallback", [this, &kernel](s64 time, std::chrono::nanoseconds) -> std::optional<std::chrono::nanoseconds> {
{
KScopedSchedulerLock lock(kernel);
global_scheduler_context->PreemptThreads();
global_scheduler_context->PreemptThreads(kernel);
}
return std::nullopt;
});

View file

@ -17,14 +17,15 @@
namespace Kernel {
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();
}
PhysicalCore::~PhysicalCore() = default;
void PhysicalCore::RunThread(Kernel::KThread* thread) {
void PhysicalCore::RunThread(KernelCore& kernel, Kernel::KThread* thread) {
auto* process = thread->GetOwnerProcess();
auto& system = m_kernel.System();
auto& system = kernel.System();
auto* interface = process->GetArmInterface(m_core_index);
interface->Initialize();
@ -208,8 +209,8 @@ void PhysicalCore::CloneFpuStatus(KThread* dst) const {
dst->GetContext().fpsr = ctx.fpsr;
}
void PhysicalCore::LogBacktrace() {
auto* process = GetCurrentProcessPointer(m_kernel);
void PhysicalCore::LogBacktrace(KernelCore& kernel) {
auto* process = GetCurrentProcessPointer(kernel);
if (!process) {
return;
}

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -30,7 +33,7 @@ public:
YUZU_NON_MOVEABLE(PhysicalCore);
// 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.
void LoadContext(const KThread* thread);
@ -44,7 +47,7 @@ public:
void CloneFpuStatus(KThread* dst) const;
// Log backtrace of current processor state.
void LogBacktrace();
void LogBacktrace(KernelCore& kernel);
// Wait for an interrupt.
void Idle();
@ -63,9 +66,7 @@ public:
}
private:
KernelCore& m_kernel;
const std::size_t m_core_index;
std::mutex m_guard;
std::condition_variable m_on_interrupt;
Core::ArmInterface* m_arm_interface{};

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -22,13 +25,11 @@ Result SetThreadActivity(Core::System& system, Handle thread_handle,
R_UNLESS(IsValidThreadActivity(thread_activity), ResultInvalidEnumValue);
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Check that the activity is being set on a non-current thread for the current process.
R_UNLESS(thread->GetOwnerProcess() == GetCurrentProcessPointer(system.Kernel()),
ResultInvalidHandle);
R_UNLESS(thread->GetOwnerProcess() == GetCurrentProcessPointer(system.Kernel()), ResultInvalidHandle);
R_UNLESS(thread.GetPointerUnsafe() != GetCurrentThreadPointer(system.Kernel()), ResultBusy);
// Set the activity.

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -37,8 +40,7 @@ Result FlushProcessDataCache(Core::System& system, Handle process_handle, u64 ad
R_UNLESS(size == static_cast<uint64_t>(size), ResultInvalidCurrentMemory);
// Get the process from its handle.
KScopedAutoObject process =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
KScopedAutoObject process = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(system.Kernel(), process_handle);
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
// Verify the region is within range.

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
@ -63,7 +63,7 @@ Result CreateCodeMemory(Core::System& system, Handle* out, u64 address, uint64_t
KCodeMemory::Register(kernel, code_mem);
// 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();
}
@ -85,8 +85,8 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
// Get the code memory from its handle.
KScopedAutoObject code_mem = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KCodeMemory>(code_memory_handle);
.GetHandleTable()
.GetObject<KCodeMemory>(system.Kernel(), code_memory_handle);
R_UNLESS(code_mem.IsNotNull(), ResultInvalidHandle);
// NOTE: Here, Atmosphere extends the SVC to allow code memory operations on one's own process.

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -39,7 +42,7 @@ Result CreateDeviceAddressSpace(Core::System& system, Handle* out, uint64_t das_
KDeviceAddressSpace::Register(system.Kernel(), das);
// 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();
}
@ -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) {
// Get the device address space.
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// 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) {
// Get the device address space.
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Detach.
@ -99,13 +102,13 @@ Result MapDeviceAddressSpaceByForce(Core::System& system, Handle das_handle, Han
// Get the device address space.
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Get the 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);
// 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.
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Get the 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);
// 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.
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Get the process.
KScopedAutoObject process =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
KScopedAutoObject process = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(system.Kernel(), process_handle);
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
// Validate that the process address is within range.

View file

@ -22,7 +22,7 @@ Result SignalEvent(Core::System& system, Handle event_handle) {
// Fail-safe for system applets
const auto program_id = GetCurrentProcess(system.Kernel()).GetProgramId();
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()) {
event->Signal();
} else {
@ -34,7 +34,7 @@ Result SignalEvent(Core::System& system, Handle event_handle) {
// 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_RETURN(event->Signal());
@ -48,7 +48,7 @@ Result ClearEvent(Core::System& system, Handle event_handle) {
// 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()) {
event->Clear();
R_SUCCEED();
@ -57,7 +57,7 @@ Result ClearEvent(Core::System& system, Handle event_handle) {
// 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()) {
readable_event->Clear();
R_SUCCEED();
@ -99,15 +99,15 @@ Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) {
KEvent::Register(kernel, event);
// 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.
ON_RESULT_FAILURE {
handle_table.Remove(*out_write);
handle_table.Remove(system.Kernel(), *out_write);
};
// 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) {

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -103,7 +106,7 @@ void Break(Core::System& system, BreakReason reason, u64 info1, u64 info2) {
handle_debug_buffer(info1, info2);
system.CurrentPhysicalCore().LogBacktrace();
system.CurrentPhysicalCore().LogBacktrace(system.Kernel());
}
const bool is_hbl = GetCurrentProcess(system.Kernel()).IsHbl();

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
@ -46,7 +46,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
R_UNLESS(info_sub_id == 0, ResultInvalidEnumValue);
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(handle);
KScopedAutoObject process = handle_table.GetObject<KProcess>(system.Kernel(), handle);
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
switch (info_id_type) {
@ -175,7 +175,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
}
Handle resource_handle{};
R_TRY(handle_table.Add(std::addressof(resource_handle), resource_limit));
R_TRY(handle_table.Add(system.Kernel(), std::addressof(resource_handle), resource_limit));
*result = resource_handle;
R_SUCCEED();
@ -203,8 +203,8 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
}
KScopedAutoObject thread = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KThread>(static_cast<Handle>(handle));
.GetHandleTable()
.GetObject<KThread>(system.Kernel(), Handle(handle));
if (thread.IsNull()) {
LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}",
static_cast<Handle>(handle));
@ -256,7 +256,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
// Get a new handle for the current process.
Handle tmp;
R_TRY(handle_table.Add(std::addressof(tmp), current_process));
R_TRY(handle_table.Add(system.Kernel(), std::addressof(tmp), current_process));
// Set the output.
*result = tmp;

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
@ -20,11 +20,9 @@ namespace Kernel::Svc {
namespace {
Result SendSyncRequestImpl(KernelCore& kernel, uintptr_t message, size_t buffer_size,
Handle session_handle) {
Result SendSyncRequestImpl(KernelCore& kernel, uintptr_t message, size_t buffer_size, Handle session_handle) {
// Get the client session.
KScopedAutoObject session =
GetCurrentProcess(kernel).GetHandleTable().GetObject<KClientSession>(session_handle);
KScopedAutoObject session = GetCurrentProcess(kernel).GetHandleTable().GetObject<KClientSession>(kernel, session_handle);
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
// Get the parent, and persist a reference to it until we're done.
@ -41,8 +39,7 @@ Result ReplyAndReceiveImpl(KernelCore& kernel, int32_t* out_index, uintptr_t mes
int64_t timeout_ns) {
// Reply to the target, if one is specified.
if (reply_target != InvalidHandle) {
KScopedAutoObject session =
GetCurrentProcess(kernel).GetHandleTable().GetObject<KServerSession>(reply_target);
KScopedAutoObject session = GetCurrentProcess(kernel).GetHandleTable().GetObject<KServerSession>(kernel, reply_target);
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
// If we fail to reply, we want to set the output index to -1.
@ -127,7 +124,7 @@ Result ReplyAndReceiveImpl(KernelCore& kernel, int32_t* out_index, uintptr_t mes
// Convert the handles to objects.
R_UNLESS(
handle_table.GetMultipleObjects<KSynchronizationObject>(objs, handles, num_handles),
handle_table.GetMultipleObjects<KSynchronizationObject>(kernel, objs, handles, num_handles),
ResultInvalidHandle);
}
@ -193,7 +190,7 @@ Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_ha
R_UNLESS(event_reservation.Succeeded(), ResultLimitReached);
// Get the client session.
KScopedAutoObject session = process.GetHandleTable().GetObject<KClientSession>(session_handle);
KScopedAutoObject session = process.GetHandleTable().GetObject<KClientSession>(system.Kernel(), session_handle);
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
// Get the parent, and persist a reference to it until we're done.
@ -220,11 +217,11 @@ Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_ha
KEvent::Register(system.Kernel(), event);
// Add the readable event to the handle table.
R_TRY(handle_table.Add(out_event_handle, std::addressof(event->GetReadableEvent())));
R_TRY(handle_table.Add(system.Kernel(), out_event_handle, std::addressof(event->GetReadableEvent())));
// Ensure that if we fail to send the request, we close the readable handle.
ON_RESULT_FAILURE {
handle_table.Remove(*out_event_handle);
handle_table.Remove(system.Kernel(), *out_event_handle);
};
// Send the async request.

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -14,8 +17,8 @@ namespace Kernel::Svc {
Result SendSyncRequestLight(Core::System& system, Handle session_handle, u32* args) {
// Get the light client session from its handle.
KScopedAutoObject session = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KLightClientSession>(session_handle);
.GetHandleTable()
.GetObject<KLightClientSession>(system.Kernel(), session_handle);
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
// Send the request.
@ -27,8 +30,8 @@ Result SendSyncRequestLight(Core::System& system, Handle session_handle, u32* ar
Result ReplyAndReceiveLight(Core::System& system, Handle session_handle, u32* args) {
// Get the light server session from its handle.
KScopedAutoObject session = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KLightServerSession>(session_handle);
.GetHandleTable()
.GetObject<KLightServerSession>(system.Kernel(), session_handle);
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
// Handle the request.

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -33,9 +36,9 @@ Result ConnectToNamedPort(Core::System& system, Handle* out, u64 user_name) {
// Reserve a handle for the port.
// NOTE: Nintendo really does write directly to the output handle here.
R_TRY(handle_table.Reserve(out));
R_TRY(handle_table.Reserve(system.Kernel(), out));
ON_RESULT_FAILURE {
handle_table.Unreserve(*out);
handle_table.Unreserve(system.Kernel(), *out);
};
// Create a session.
@ -43,7 +46,7 @@ Result ConnectToNamedPort(Core::System& system, Handle* out, u64 user_name) {
R_TRY(port->CreateSession(std::addressof(session)));
// Register the session in the table, close the extra reference.
handle_table.Register(*out, session);
handle_table.Register(system.Kernel(), *out, session);
session->Close();
// We succeeded.
@ -77,15 +80,15 @@ Result CreatePort(Core::System& system, Handle* out_server, Handle* out_client,
KPort::Register(kernel, port);
// Add the client to the handle table.
R_TRY(handle_table.Add(out_client, std::addressof(port->GetClientPort())));
R_TRY(handle_table.Add(system.Kernel(), out_client, std::addressof(port->GetClientPort())));
// Ensure that we maintain a clean handle state on exit.
ON_RESULT_FAILURE {
handle_table.Remove(*out_client);
handle_table.Remove(system.Kernel(), *out_client);
};
// Add the server to the handle table.
R_RETURN(handle_table.Add(out_server, std::addressof(port->GetServerPort())));
R_RETURN(handle_table.Add(system.Kernel(), out_server, std::addressof(port->GetServerPort())));
}
Result ConnectToPort(Core::System& system, Handle* out, Handle port) {
@ -93,14 +96,14 @@ Result ConnectToPort(Core::System& system, Handle* out, Handle port) {
auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
// Get the client port.
KScopedAutoObject client_port = handle_table.GetObject<KClientPort>(port);
KScopedAutoObject client_port = handle_table.GetObject<KClientPort>(system.Kernel(), port);
R_UNLESS(client_port.IsNotNull(), ResultInvalidHandle);
// Reserve a handle for the port.
// NOTE: Nintendo really does write directly to the output handle here.
R_TRY(handle_table.Reserve(out));
R_TRY(handle_table.Reserve(system.Kernel(), out));
ON_RESULT_FAILURE {
handle_table.Unreserve(*out);
handle_table.Unreserve(system.Kernel(), *out);
};
// Create the session.
@ -114,15 +117,14 @@ Result ConnectToPort(Core::System& system, Handle* out, Handle port) {
}
// Register the session.
handle_table.Register(*out, session);
handle_table.Register(system.Kernel(), *out, session);
session->Close();
// We succeeded.
R_SUCCEED();
}
Result ManageNamedPort(Core::System& system, Handle* out_server_handle, uint64_t user_name,
int32_t max_sessions) {
Result ManageNamedPort(Core::System& system, Handle* out_server_handle, uint64_t user_name, int32_t max_sessions) {
// Copy the provided name from user memory to kernel memory.
auto string_name =
GetCurrentMemory(system.Kernel()).ReadCString(user_name, KObjectName::NameLengthMax);
@ -156,9 +158,9 @@ Result ManageNamedPort(Core::System& system, Handle* out_server_handle, uint64_t
};
// Register the handle in the table.
R_TRY(handle_table.Add(out_server_handle, std::addressof(port->GetServerPort())));
R_TRY(handle_table.Add(system.Kernel(), out_server_handle, std::addressof(port->GetServerPort())));
ON_RESULT_FAILURE {
handle_table.Remove(*out_server_handle);
handle_table.Remove(system.Kernel(), *out_server_handle);
};
// Create a new object name.

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
@ -27,8 +27,8 @@ Result GetProcessId(Core::System& system, u64* out_process_id, Handle handle) {
// Get the object from the handle table.
KScopedAutoObject obj = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KAutoObject>(static_cast<Handle>(handle));
.GetHandleTable()
.GetObject<KAutoObject>(system.Kernel(), Handle(handle));
R_UNLESS(obj.IsNotNull(), ResultInvalidHandle);
// Get the process from the object.
@ -98,7 +98,7 @@ Result GetProcessInfo(Core::System& system, s64* out, Handle process_handle,
LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, type={:#X}", process_handle, info_type);
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle);
KScopedAutoObject process = handle_table.GetObject<KProcess>(system.Kernel(), process_handle);
if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",
process_handle);

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
@ -48,7 +48,7 @@ Result SetProcessMemoryPermission(Core::System& system, Handle process_handle, u
// Get the process from its handle.
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);
// Validate that the address is in range.
@ -76,7 +76,7 @@ Result MapProcessMemory(Core::System& system, u64 dst_address, Handle process_ha
// Get the processes.
KProcess* dst_process = GetCurrentProcessPointer(system.Kernel());
KScopedAutoObject src_process =
dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(process_handle);
dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(system.Kernel(), process_handle);
R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle);
// Get the page tables.
@ -117,7 +117,7 @@ Result UnmapProcessMemory(Core::System& system, u64 dst_address, Handle process_
// Get the processes.
KProcess* dst_process = GetCurrentProcessPointer(system.Kernel());
KScopedAutoObject src_process =
dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(process_handle);
dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(system.Kernel(), process_handle);
R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle);
// Get the page tables.
@ -174,7 +174,7 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst
}
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle);
KScopedAutoObject process = handle_table.GetObject<KProcess>(system.Kernel(), process_handle);
if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).",
process_handle);
@ -234,7 +234,7 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d
}
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle);
KScopedAutoObject process = handle_table.GetObject<KProcess>(system.Kernel(), process_handle);
if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).",
process_handle);

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -23,7 +26,7 @@ Result QueryProcessMemory(Core::System& system, uint64_t out_memory_info, PageIn
Handle process_handle, uint64_t address) {
LOG_TRACE(Kernel_SVC, "called process=0x{:08X} address={:X}", process_handle, address);
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle);
KScopedAutoObject process = handle_table.GetObject<KProcess>(system.Kernel(), process_handle);
if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",
process_handle);

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -29,7 +32,7 @@ Result CreateResourceLimit(Core::System& system, Handle* out_handle) {
KResourceLimit::Register(kernel, resource_limit);
// Add the limit to the handle table.
R_RETURN(GetCurrentProcess(kernel).GetHandleTable().Add(out_handle, resource_limit));
R_RETURN(GetCurrentProcess(kernel).GetHandleTable().Add(system.Kernel(), out_handle, resource_limit));
}
Result GetResourceLimitLimitValue(Core::System& system, s64* out_limit_value,
@ -42,8 +45,8 @@ Result GetResourceLimitLimitValue(Core::System& system, s64* out_limit_value,
// Get the resource limit.
KScopedAutoObject resource_limit = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KResourceLimit>(resource_limit_handle);
.GetHandleTable()
.GetObject<KResourceLimit>(system.Kernel(), resource_limit_handle);
R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle);
// Get the limit value.
@ -62,8 +65,8 @@ Result GetResourceLimitCurrentValue(Core::System& system, s64* out_current_value
// Get the resource limit.
KScopedAutoObject resource_limit = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KResourceLimit>(resource_limit_handle);
.GetHandleTable()
.GetObject<KResourceLimit>(system.Kernel(), resource_limit_handle);
R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle);
// Get the current value.
@ -83,7 +86,7 @@ Result SetResourceLimitLimitValue(Core::System& system, Handle resource_limit_ha
// Get the resource limit.
KScopedAutoObject resource_limit = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KResourceLimit>(resource_limit_handle);
.GetObject<KResourceLimit>(system.Kernel(), resource_limit_handle);
R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle);
// Set the limit value.

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -78,15 +81,15 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien
T::Register(system.Kernel(), session);
// Add the server session to the handle table.
R_TRY(handle_table.Add(out_server, std::addressof(session->GetServerSession())));
R_TRY(handle_table.Add(system.Kernel(), out_server, std::addressof(session->GetServerSession())));
// Ensure that we maintain a clean handle state on exit.
ON_RESULT_FAILURE {
handle_table.Remove(*out_server);
handle_table.Remove(system.Kernel(), *out_server);
};
// Add the client session to the handle table.
R_RETURN(handle_table.Add(out_client, std::addressof(session->GetClientSession())));
R_RETURN(handle_table.Add(system.Kernel(), out_client, std::addressof(session->GetClientSession())));
}
} // namespace
@ -105,13 +108,13 @@ Result AcceptSession(Core::System& system, Handle* out, Handle port_handle) {
auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
// Get the server port.
KScopedAutoObject port = handle_table.GetObject<KServerPort>(port_handle);
KScopedAutoObject port = handle_table.GetObject<KServerPort>(system.Kernel(), port_handle);
R_UNLESS(port.IsNotNull(), ResultInvalidHandle);
// Reserve an entry for the new session.
R_TRY(handle_table.Reserve(out));
R_TRY(handle_table.Reserve(system.Kernel(), out));
ON_RESULT_FAILURE {
handle_table.Unreserve(*out);
handle_table.Unreserve(system.Kernel(), *out);
};
// Accept the session.
@ -126,7 +129,7 @@ Result AcceptSession(Core::System& system, Handle* out, Handle port_handle) {
R_UNLESS(session != nullptr, ResultNotFound);
// Register the session.
handle_table.Register(*out, session);
handle_table.Register(system.Kernel(), *out, session);
session->Close();
R_SUCCEED();

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
@ -49,7 +49,7 @@ Result MapSharedMemory(Core::System& system, Handle shmem_handle, u64 address, u
auto& page_table = process.GetPageTable();
// Get the shared memory.
KScopedAutoObject shmem = process.GetHandleTable().GetObject<KSharedMemory>(shmem_handle);
KScopedAutoObject shmem = process.GetHandleTable().GetObject<KSharedMemory>(system.Kernel(), shmem_handle);
R_UNLESS(shmem.IsNotNull(), ResultInvalidHandle);
// Verify that the mapping is in range.
@ -79,7 +79,7 @@ Result UnmapSharedMemory(Core::System& system, Handle shmem_handle, u64 address,
auto& page_table = process.GetPageTable();
// Get the shared memory.
KScopedAutoObject shmem = process.GetHandleTable().GetObject<KSharedMemory>(shmem_handle);
KScopedAutoObject shmem = process.GetHandleTable().GetObject<KSharedMemory>(system.Kernel(), shmem_handle);
R_UNLESS(shmem.IsNotNull(), ResultInvalidHandle);
// Verify that the mapping is in range.

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
@ -20,7 +20,7 @@ Result CloseHandle(Core::System& system, Handle handle) {
LOG_TRACE(Kernel_SVC, "Closing handle 0x{:08X}", handle);
// Remove the handle.
R_UNLESS(GetCurrentProcess(system.Kernel()).GetHandleTable().Remove(handle),
R_UNLESS(GetCurrentProcess(system.Kernel()).GetHandleTable().Remove(system.Kernel(), handle),
ResultInvalidHandle);
R_SUCCEED();
@ -35,7 +35,7 @@ Result ResetSignal(Core::System& system, Handle handle) {
// Try to reset as readable event.
{
KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(handle);
KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(system.Kernel(), handle);
if (readable_event.IsNotNull()) {
R_RETURN(readable_event->Reset());
}
@ -43,7 +43,7 @@ Result ResetSignal(Core::System& system, Handle handle) {
// Try to reset as process.
{
KScopedAutoObject process = handle_table.GetObject<KProcess>(handle);
KScopedAutoObject process = handle_table.GetObject<KProcess>(system.Kernel(), handle);
if (process.IsNotNull()) {
R_RETURN(process->Reset());
}
@ -75,9 +75,7 @@ Result WaitSynchronization(Core::System& system, int32_t* out_index, u64 user_ha
ResultInvalidPointer);
// Convert the handles to objects.
R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(
objs.data(), handles.data(), num_handles),
ResultInvalidHandle);
R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(system.Kernel(), objs.data(), handles.data(), num_handles), ResultInvalidHandle);
}
// Ensure handles are closed when we're done.
@ -112,7 +110,7 @@ Result CancelSynchronization(Core::System& system, Handle handle) {
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(handle);
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Cancel the thread's wait.

View file

@ -75,7 +75,7 @@ Result CreateThread(Core::System& system, Handle* out_handle, u64 entry_point, u
KThread::Register(kernel, thread);
// Add the thread to the handle table.
R_TRY(process.GetHandleTable().Add(out_handle, thread));
R_TRY(process.GetHandleTable().Add(system.Kernel(), out_handle, thread));
// Pass the thread handle to the thread local region.
process.GetMemory().Write32(GetInteger(thread->GetTlsAddress()) + 0x110, *out_handle);
@ -88,8 +88,7 @@ Result StartThread(Core::System& system, Handle thread_handle) {
LOG_DEBUG(Kernel_SVC, "called thread=0x{:08X}", thread_handle);
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Try to start the thread.
@ -150,8 +149,7 @@ Result GetThreadContext3(Core::System& system, u64 out_context, Handle thread_ha
auto& kernel = system.Kernel();
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(kernel).GetHandleTable().GetObject<KThread>(thread_handle);
KScopedAutoObject thread = GetCurrentProcess(kernel).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Require the handle be to a non-current thread in the current process.
@ -175,8 +173,7 @@ Result GetThreadPriority(Core::System& system, s32* out_priority, Handle handle)
LOG_TRACE(Kernel_SVC, "called");
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(handle);
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Get the thread's priority.
@ -195,7 +192,7 @@ Result SetThreadPriority(Core::System& system, Handle thread_handle, s32 priorit
R_UNLESS(process.CheckThreadPriority(priority), ResultInvalidPriority);
// Get the thread from its handle.
KScopedAutoObject thread = process.GetHandleTable().GetObject<KThread>(thread_handle);
KScopedAutoObject thread = process.GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Set the thread priority.
@ -248,8 +245,7 @@ Result GetThreadCoreMask(Core::System& system, s32* out_core_id, u64* out_affini
LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle);
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Get the core mask.
@ -279,7 +275,7 @@ Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Set the core mask.
@ -289,8 +285,7 @@ Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id
/// Get the ID for the specified thread.
Result GetThreadId(Core::System& system, u64* out_thread_id, Handle thread_handle) {
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Get the thread's id.

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -69,7 +72,7 @@ Result CreateTransferMemory(Core::System& system, Handle* out, u64 address, u64
KTransferMemory::Register(kernel, trmem);
// Add the transfer memory to the handle table.
R_RETURN(handle_table.Add(out, trmem));
R_RETURN(handle_table.Add(system.Kernel(), out, trmem));
}
Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t address, uint64_t size,
@ -86,7 +89,7 @@ Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t add
// Get the transfer memory.
KScopedAutoObject trmem = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KTransferMemory>(trmem_handle);
.GetObject<KTransferMemory>(system.Kernel(), trmem_handle);
R_UNLESS(trmem.IsNotNull(), ResultInvalidHandle);
// Verify that the mapping is in range.
@ -113,7 +116,7 @@ Result UnmapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t a
// Get the transfer memory.
KScopedAutoObject trmem = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KTransferMemory>(trmem_handle);
.GetObject<KTransferMemory>(system.Kernel(), trmem_handle);
R_UNLESS(trmem.IsNotNull(), ResultInvalidHandle);
// Verify that the mapping is in range.

View file

@ -268,7 +268,7 @@ void AppletManager::SetWindowSystem(WindowSystem* window_system) {
if (Settings::values.enable_overlay && m_window_system->GetOverlayDisplayApplet() == nullptr) {
if (auto overlay_process = CreateProcess(m_system, static_cast<u64>(AppletProgramId::OverlayDisplay), 0, 0)) {
auto overlay_applet = std::make_shared<Applet>(m_system, std::move(overlay_process), false);
auto overlay_applet = std::make_shared<Applet>(m_system, std::make_unique<Service::Process>(*std::move(overlay_process)), false);
overlay_applet->program_id = static_cast<u64>(AppletProgramId::OverlayDisplay);
overlay_applet->applet_id = AppletId::OverlayDisplay;
overlay_applet->type = AppletType::OverlayApplet;

View file

@ -1,9 +1,11 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <thread>
#include "common/thread.h"
#include "core/core.h"
#include "core/hle/service/am/am_types.h"
#include "core/hle/service/am/button_poller.h"
@ -34,16 +36,15 @@ ButtonPressDuration ClassifyPressDuration(std::chrono::steady_clock::time_point
} // namespace
ButtonPoller::ButtonPoller(Core::System& system, WindowSystem& window_system)
: m_window_system(window_system) {
ButtonPoller::ButtonPoller(Core::System& system, WindowSystem& window_system) {
// TODO: am reads this from the home button state in hid, which is controller-agnostic.
Core::HID::ControllerUpdateCallback engine_callback{
.on_change =
[this](Core::HID::ControllerTriggerType type) {
if (type == Core::HID::ControllerTriggerType::Button) {
this->OnButtonStateChanged();
}
},
.on_change = [this, &window_system](Core::HID::ControllerTriggerType type) {
if (type == Core::HID::ControllerTriggerType::Button) {
std::unique_lock lk{m_mutex};
OnButtonStateChanged(window_system);
}
},
.is_npad_service = true,
};
@ -52,25 +53,35 @@ ButtonPoller::ButtonPoller(Core::System& system, WindowSystem& window_system)
m_player1 = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);
m_player1_key = m_player1->SetCallback(engine_callback);
m_thread = std::thread([this] { this->ThreadLoop(); });
m_thread = std::jthread([this, &window_system](std::stop_token stop_token) {
Common::SetCurrentThreadName("ButtonPoller");
while (!stop_token.stop_requested()) {
using namespace std::chrono_literals;
std::unique_lock lk{m_mutex};
m_cv.wait_for(lk, 50ms);
if (stop_token.stop_requested())
break;
OnButtonStateChanged(window_system);
std::this_thread::sleep_for(5ms);
}
});
}
ButtonPoller::~ButtonPoller() {
m_handheld->DeleteCallback(m_handheld_key);
m_player1->DeleteCallback(m_player1_key);
m_stop = true;
m_cv.notify_all();
if (m_thread.joinable()) {
m_thread.request_stop();
m_thread.join();
}
}
void ButtonPoller::OnButtonStateChanged() {
std::lock_guard lk{m_mutex};
const bool home_button =
m_handheld->GetHomeButtons().home.Value() || m_player1->GetHomeButtons().home.Value();
const bool capture_button = m_handheld->GetCaptureButtons().capture.Value() ||
m_player1->GetCaptureButtons().capture.Value();
void ButtonPoller::OnButtonStateChanged(WindowSystem& window_system) {
auto const home_button = m_handheld->GetHomeButtons().home.Value()
|| m_player1->GetHomeButtons().home.Value();
auto const capture_button = m_handheld->GetCaptureButtons().capture.Value()
|| m_player1->GetCaptureButtons().capture.Value();
// Buttons pressed which were not previously pressed
if (home_button && !m_home_button_press_start) {
@ -90,7 +101,7 @@ void ButtonPoller::OnButtonStateChanged() {
if (home_button && m_home_button_press_start && !m_home_button_long_sent) {
const auto duration = ClassifyPressDuration(*m_home_button_press_start);
if (duration != ButtonPressDuration::ShortPressing) {
m_window_system.OnSystemButtonPress(SystemButtonType::HomeButtonLongPressing);
window_system.OnSystemButtonPress(SystemButtonType::HomeButtonLongPressing);
m_home_button_long_sent = true;
}
}
@ -98,7 +109,7 @@ void ButtonPoller::OnButtonStateChanged() {
if (capture_button && m_capture_button_press_start && !m_capture_button_long_sent) {
const auto duration = ClassifyPressDuration(*m_capture_button_press_start);
if (duration != ButtonPressDuration::ShortPressing) {
m_window_system.OnSystemButtonPress(SystemButtonType::CaptureButtonLongPressing);
window_system.OnSystemButtonPress(SystemButtonType::CaptureButtonLongPressing);
m_capture_button_long_sent = true;
}
}
@ -107,9 +118,8 @@ void ButtonPoller::OnButtonStateChanged() {
if (!home_button && m_home_button_press_start) {
if(!m_home_button_long_sent) {
const auto duration = ClassifyPressDuration(*m_home_button_press_start);
m_window_system.OnSystemButtonPress(
duration == ButtonPressDuration::ShortPressing ? SystemButtonType::HomeButtonShortPressing
: SystemButtonType::HomeButtonLongPressing);
window_system.OnSystemButtonPress(duration == ButtonPressDuration::ShortPressing
? SystemButtonType::HomeButtonShortPressing : SystemButtonType::HomeButtonLongPressing);
}
m_home_button_press_start = std::nullopt;
m_home_button_long_sent = false;
@ -117,9 +127,8 @@ void ButtonPoller::OnButtonStateChanged() {
if (!capture_button && m_capture_button_press_start) {
if (!m_capture_button_long_sent) {
const auto duration = ClassifyPressDuration(*m_capture_button_press_start);
m_window_system.OnSystemButtonPress(
duration == ButtonPressDuration::ShortPressing ? SystemButtonType::CaptureButtonShortPressing
: SystemButtonType::CaptureButtonLongPressing);
window_system.OnSystemButtonPress(duration == ButtonPressDuration::ShortPressing
? SystemButtonType::CaptureButtonShortPressing : SystemButtonType::CaptureButtonLongPressing);
}
m_capture_button_press_start = std::nullopt;
m_capture_button_long_sent = false;
@ -130,16 +139,4 @@ void ButtonPoller::OnButtonStateChanged() {
// }
}
void ButtonPoller::ThreadLoop() {
using namespace std::chrono_literals;
std::unique_lock lk{m_mutex};
while (!m_stop) {
m_cv.wait_for(lk, 50ms);
if (m_stop) break;
lk.unlock();
OnButtonStateChanged();
lk.lock();
}
}
} // namespace Service::AM

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
@ -30,31 +30,23 @@ class ButtonPoller {
public:
explicit ButtonPoller(Core::System& system, WindowSystem& window_system);
~ButtonPoller();
void OnButtonStateChanged(WindowSystem& window_system);
private:
void OnButtonStateChanged();
void ThreadLoop();
private:
WindowSystem& m_window_system;
Core::HID::EmulatedController* m_handheld{};
int m_handheld_key{};
Core::HID::EmulatedController* m_player1{};
int m_player1_key{};
std::mutex m_mutex;
std::condition_variable m_cv;
std::jthread m_thread;
std::optional<std::chrono::steady_clock::time_point> m_home_button_press_start{};
std::optional<std::chrono::steady_clock::time_point> m_capture_button_press_start{};
std::optional<std::chrono::steady_clock::time_point> m_power_button_press_start{};
bool m_home_button_long_sent{};
bool m_capture_button_long_sent{};
bool m_power_button_long_sent{};
std::thread m_thread;
std::atomic<bool> m_stop{false};
std::condition_variable m_cv;
std::mutex m_mutex;
Core::HID::EmulatedController* m_handheld{};
Core::HID::EmulatedController* m_player1{};
int32_t m_handheld_key{};
int32_t m_player1_key{};
bool m_home_button_long_sent : 1 = false;
bool m_capture_button_long_sent : 1 = false;
bool m_power_button_long_sent : 1 = false;
};
} // namespace Service::AM

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -15,12 +18,24 @@ enum class UserDataTag : u32 {
};
EventObserver::EventObserver(Core::System& system, WindowSystem& window_system)
: m_system(system), m_context(system, "am:EventObserver"), m_window_system(window_system),
m_wakeup_event(m_context), m_wakeup_holder(m_wakeup_event.GetHandle()) {
: m_system(system), m_context(system, "am:EventObserver")
, m_window_system(window_system)
, m_wakeup_event(m_context)
, m_wakeup_holder(m_wakeup_event.GetHandle())
{
m_window_system.SetEventObserver(this);
m_wakeup_holder.SetUserData(static_cast<uintptr_t>(UserDataTag::WakeupEvent));
m_wakeup_holder.LinkToMultiWait(std::addressof(m_multi_wait));
m_thread = std::thread([&] { this->ThreadFunc(); });
m_thread = std::thread([this] {
Common::SetCurrentThreadName("am:EventObserver");
while (true) {
auto* signaled_holder = this->WaitSignaled();
if (!signaled_holder) {
break;
}
this->Process(signaled_holder);
}
});
}
EventObserver::~EventObserver() {
@ -146,17 +161,4 @@ void EventObserver::DestroyAppletProcessHolderLocked(ProcessHolder* holder) {
delete holder;
}
void EventObserver::ThreadFunc() {
Common::SetCurrentThreadName("am:EventObserver");
while (true) {
auto* signaled_holder = this->WaitSignaled();
if (!signaled_holder) {
break;
}
this->Process(signaled_holder);
}
}
} // namespace Service::AM

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -41,9 +44,6 @@ private:
private:
void DestroyAppletProcessHolderLocked(ProcessHolder* holder);
private:
void ThreadFunc();
private:
// System reference and context.
Core::System& m_system;

View file

@ -1,6 +1,10 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <optional>
#include "core/core.h"
#include "core/file_sys/content_archive.h"
#include "core/file_sys/nca_metadata.h"
@ -16,7 +20,7 @@ namespace Service::AM {
namespace {
FileSys::StorageId GetStorageIdForFrontendSlot(
[[nodiscard]] FileSys::StorageId GetStorageIdForFrontendSlot(
std::optional<FileSys::ContentProviderUnionSlot> slot) {
if (!slot.has_value()) {
return FileSys::StorageId::None;
@ -36,31 +40,23 @@ FileSys::StorageId GetStorageIdForFrontendSlot(
}
}
std::unique_ptr<Process> CreateProcessImpl(std::unique_ptr<Loader::AppLoader>& out_loader,
Loader::ResultStatus& out_load_result,
Core::System& system, FileSys::VirtualFile file,
u64 program_id, u64 program_index) {
[[nodiscard]] inline std::optional<Process> CreateProcessImpl(std::unique_ptr<Loader::AppLoader>& out_loader, Loader::ResultStatus& out_load_result, Core::System& system, FileSys::VirtualFile file, u64 program_id, u64 program_index) {
// Get the appropriate loader to parse this NCA.
out_loader = Loader::GetLoader(system, file, program_id, program_index);
// Ensure we have a loader which can parse the NCA.
if (!out_loader) {
return nullptr;
if (out_loader) {
// Try to load the process.
auto process = std::make_optional<Process>(system);
if (process->Initialize(*out_loader, out_load_result)) {
return process;
}
}
// Try to load the process.
auto process = std::make_unique<Process>(system);
if (process->Initialize(*out_loader, out_load_result)) {
return process;
}
return nullptr;
return std::nullopt;
}
} // Anonymous namespace
std::unique_ptr<Process> CreateProcess(Core::System& system, u64 program_id,
u8 minimum_key_generation, u8 maximum_key_generation) {
std::optional<Process> CreateProcess(Core::System& system, u64 program_id, u8 minimum_key_generation, u8 maximum_key_generation) {
// Attempt to load program NCA.
FileSys::VirtualFile nca_raw{};
@ -70,7 +66,7 @@ std::unique_ptr<Process> CreateProcess(Core::System& system, u64 program_id,
// Ensure we retrieved a program NCA.
if (!nca_raw) {
return nullptr;
return std::nullopt;
}
// Ensure we have a suitable version.
@ -79,9 +75,8 @@ std::unique_ptr<Process> CreateProcess(Core::System& system, u64 program_id,
if (nca.GetStatus() == Loader::ResultStatus::Success &&
(nca.GetKeyGeneration() < minimum_key_generation ||
nca.GetKeyGeneration() > maximum_key_generation)) {
LOG_WARNING(Service_LDR, "Skipping program {:016X} with generation {}", program_id,
nca.GetKeyGeneration());
return nullptr;
LOG_WARNING(Service_LDR, "Skipping program {:016X} with generation {}", program_id, nca.GetKeyGeneration());
return std::nullopt;
}
}
@ -90,42 +85,32 @@ std::unique_ptr<Process> CreateProcess(Core::System& system, u64 program_id,
return CreateProcessImpl(loader, status, system, nca_raw, program_id, 0);
}
std::unique_ptr<Process> CreateApplicationProcess(std::vector<u8>& out_control,
std::unique_ptr<Loader::AppLoader>& out_loader,
Loader::ResultStatus& out_load_result,
Core::System& system, FileSys::VirtualFile file,
u64 program_id, u64 program_index) {
auto process =
CreateProcessImpl(out_loader, out_load_result, system, file, program_id, program_index);
if (!process) {
return nullptr;
std::optional<Process> CreateApplicationProcess(std::vector<u8>& out_control, std::unique_ptr<Loader::AppLoader>& out_loader, Loader::ResultStatus& out_load_result, Core::System& system, FileSys::VirtualFile file, u64 program_id, u64 program_index) {
if (auto process = CreateProcessImpl(out_loader, out_load_result, system, file, program_id, program_index); process) {
FileSys::NACP nacp;
if (out_loader->ReadControlData(nacp) == Loader::ResultStatus::Success) {
out_control = nacp.GetRawBytes();
} else {
out_control.resize(sizeof(FileSys::RawNACP));
std::fill(out_control.begin(), out_control.end(), (u8) 0);
}
auto& storage = system.GetContentProviderUnion();
Service::Glue::ApplicationLaunchProperty launch{};
launch.title_id = process->GetProgramId();
FileSys::PatchManager pm{launch.title_id, system.GetFileSystemController(), storage};
launch.version = pm.GetGameVersion().value_or(0);
// TODO(DarkLordZach): When FSController/Game Card Support is added, if
// current_process_game_card use correct StorageId
launch.base_game_storage_id = GetStorageIdForFrontendSlot(storage.GetSlotForEntry(launch.title_id, FileSys::ContentRecordType::Program));
launch.update_storage_id = GetStorageIdForFrontendSlot(storage.GetSlotForEntry(FileSys::GetUpdateTitleID(launch.title_id), FileSys::ContentRecordType::Program));
system.GetARPManager().Register(launch.title_id, launch, out_control);
return process;
}
FileSys::NACP nacp;
if (out_loader->ReadControlData(nacp) == Loader::ResultStatus::Success) {
out_control = nacp.GetRawBytes();
} else {
out_control.resize(sizeof(FileSys::RawNACP));
std::fill(out_control.begin(), out_control.end(), (u8) 0);
}
auto& storage = system.GetContentProviderUnion();
Service::Glue::ApplicationLaunchProperty launch{};
launch.title_id = process->GetProgramId();
FileSys::PatchManager pm{launch.title_id, system.GetFileSystemController(), storage};
launch.version = pm.GetGameVersion().value_or(0);
// TODO(DarkLordZach): When FSController/Game Card Support is added, if
// current_process_game_card use correct StorageId
launch.base_game_storage_id = GetStorageIdForFrontendSlot(
storage.GetSlotForEntry(launch.title_id, FileSys::ContentRecordType::Program));
launch.update_storage_id = GetStorageIdForFrontendSlot(storage.GetSlotForEntry(
FileSys::GetUpdateTitleID(launch.title_id), FileSys::ContentRecordType::Program));
system.GetARPManager().Register(launch.title_id, launch, out_control);
return process;
return std::nullopt;
}
} // namespace Service::AM

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -24,12 +27,7 @@ class Process;
namespace Service::AM {
std::unique_ptr<Process> CreateProcess(Core::System& system, u64 program_id,
u8 minimum_key_generation, u8 maximum_key_generation);
std::unique_ptr<Process> CreateApplicationProcess(std::vector<u8>& out_control,
std::unique_ptr<Loader::AppLoader>& out_loader,
Loader::ResultStatus& out_load_result,
Core::System& system, FileSys::VirtualFile file,
u64 program_id, u64 program_index);
std::optional<Process> CreateProcess(Core::System& system, u64 program_id, u8 minimum_key_generation, u8 maximum_key_generation);
std::optional<Process> CreateApplicationProcess(std::vector<u8>& out_control, std::unique_ptr<Loader::AppLoader>& out_loader, Loader::ResultStatus& out_load_result, Core::System& system, FileSys::VirtualFile file, u64 program_id, u64 program_index);
} // namespace Service::AM

View file

@ -21,8 +21,7 @@ namespace Service::AM {
namespace {
Result CreateGuestApplication(SharedPointer<IApplicationAccessor>* out_application_accessor,
Core::System& system, WindowSystem& window_system, u64 program_id) {
Result CreateGuestApplication(SharedPointer<IApplicationAccessor>* out_application_accessor, Core::System& system, WindowSystem& window_system, u64 program_id) {
FileSys::VirtualFile nca_raw{};
// Get the program NCA from storage.
@ -35,11 +34,10 @@ Result CreateGuestApplication(SharedPointer<IApplicationAccessor>* out_applicati
std::vector<u8> control;
std::unique_ptr<Loader::AppLoader> loader;
Loader::ResultStatus result;
auto process =
CreateApplicationProcess(control, loader, result, system, nca_raw, program_id, 0);
R_UNLESS(process != nullptr, ResultUnknown);
auto process = CreateApplicationProcess(control, loader, result, system, nca_raw, program_id, 0);
R_UNLESS(process != std::nullopt, ResultUnknown);
const auto applet = std::make_shared<Applet>(system, std::move(process), true);
const auto applet = std::make_shared<Applet>(system, std::make_unique<Service::Process>(*std::move(process)), true);
applet->program_id = program_id;
applet->applet_id = AppletId::Application;
applet->type = AppletType::Application;
@ -47,8 +45,7 @@ Result CreateGuestApplication(SharedPointer<IApplicationAccessor>* out_applicati
window_system.TrackApplet(applet, true);
*out_application_accessor =
std::make_shared<IApplicationAccessor>(system, applet, window_system);
*out_application_accessor = std::make_shared<IApplicationAccessor>(system, applet, window_system);
R_SUCCEED();
}
@ -90,12 +87,10 @@ Result IApplicationCreator::CreateSystemApplication(
std::vector<u8> control;
std::unique_ptr<Loader::AppLoader> loader;
auto process = CreateProcess(system, application_id, 1, 22);
R_UNLESS(process != std::nullopt, ResultUnknown);
auto process =
CreateProcess(system, application_id, 1, 22);
R_UNLESS(process != nullptr, ResultUnknown);
const auto applet = std::make_shared<Applet>(system, std::move(process), true);
const auto applet = std::make_shared<Applet>(system, std::make_unique<Service::Process>(*std::move(process)), true);
applet->program_id = application_id;
applet->applet_id = AppletId::Starter;
applet->type = AppletType::LibraryApplet;
@ -103,8 +98,7 @@ Result IApplicationCreator::CreateSystemApplication(
m_window_system.TrackApplet(applet, true);
*out_application_accessor =
std::make_shared<IApplicationAccessor>(system, applet, m_window_system);
*out_application_accessor = std::make_shared<IApplicationAccessor>(system, applet, m_window_system);
Core::LaunchTimestampCache::SaveLaunchTimestamp(application_id);
R_SUCCEED();
}

View file

@ -122,26 +122,23 @@ std::shared_ptr<ILibraryAppletAccessor> CreateGuestApplet(Core::System& system,
};
auto process = CreateProcess(system, program_id, Firmware1400, Firmware2200);
if (!process) {
// Couldn't initialize the guest process
return {};
if (process) {
const auto applet = std::make_shared<Applet>(system, std::make_unique<Service::Process>(*std::move(process)), false);
applet->program_id = program_id;
applet->applet_id = applet_id;
applet->type = AppletType::LibraryApplet;
applet->library_applet_mode = mode;
applet->window_visible = mode != LibraryAppletMode::AllForegroundInitiallyHidden;
auto broker = std::make_shared<AppletDataBroker>(system);
applet->caller_applet = caller_applet;
applet->caller_applet_broker = broker;
caller_applet->child_applets.push_back(applet);
window_system.TrackApplet(applet, false);
return std::make_shared<ILibraryAppletAccessor>(system, broker, applet);
}
const auto applet = std::make_shared<Applet>(system, std::move(process), false);
applet->program_id = program_id;
applet->applet_id = applet_id;
applet->type = AppletType::LibraryApplet;
applet->library_applet_mode = mode;
applet->window_visible = mode != LibraryAppletMode::AllForegroundInitiallyHidden;
auto broker = std::make_shared<AppletDataBroker>(system);
applet->caller_applet = caller_applet;
applet->caller_applet_broker = broker;
caller_applet->child_applets.push_back(applet);
window_system.TrackApplet(applet, false);
return std::make_shared<ILibraryAppletAccessor>(system, broker, applet);
// Couldn't initialize the guest process
return {};
}
std::shared_ptr<ILibraryAppletAccessor> CreateFrontendApplet(Core::System& system,

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
@ -14,7 +14,9 @@ namespace Service::Audio {
using namespace AudioCore::AudioOut;
IAudioOutManager::IAudioOutManager(Core::System& system_)
: ServiceFramework{system_, "audout:u"}, impl{std::make_unique<Manager>(system_)} {
: ServiceFramework{system_, "audout:u"}
, impl(system_)
{
// clang-format off
static const FunctionInfo functions[] = {
{0, D<&IAudioOutManager::ListAudioOuts>, "ListAudioOuts"},

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
@ -43,7 +43,7 @@ private:
AudioCore::AudioOut::AudioOutParameter parameter,
InCopyHandle<Kernel::KProcess> process_handle, ClientAppletResourceUserId aruid);
std::unique_ptr<AudioCore::AudioOut::Manager> impl;
std::optional<AudioCore::AudioOut::Manager> impl;
};
} // namespace Service::Audio

View file

@ -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-License-Identifier: GPL-2.0-or-later
@ -15,7 +18,9 @@ namespace Service::Audio {
using namespace AudioCore::Renderer;
IAudioRendererManager::IAudioRendererManager(Core::System& system_)
: ServiceFramework{system_, "audren:u"}, impl{std::make_unique<Manager>(system_)} {
: ServiceFramework{system_, "audren:u"}
, impl(system_)
{
// clang-format off
static const FunctionInfo functions[] = {
{0, D<&IAudioRendererManager::OpenAudioRenderer>, "OpenAudioRenderer"},

View file

@ -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-License-Identifier: GPL-2.0-or-later
@ -30,7 +33,7 @@ private:
Result GetAudioDeviceServiceWithRevisionInfo(Out<SharedPointer<IAudioDevice>> out_audio_device,
u32 revision, ClientAppletResourceUserId aruid);
std::unique_ptr<AudioCore::Renderer::Manager> impl;
std::optional<AudioCore::Renderer::Manager> impl;
u32 num_audio_devices{0};
};

View file

@ -275,14 +275,14 @@ Result HLERequestContext::WriteToOutgoingCommandBuffer() {
for (auto& object : outgoing_copy_objects) {
Handle handle{};
if (object) {
R_TRY(handle_table.Add(&handle, object));
R_TRY(handle_table.Add(kernel, &handle, object));
}
cmd_buf[current_offset++] = handle;
}
for (auto& object : outgoing_move_objects) {
Handle handle{};
if (object) {
R_TRY(handle_table.Add(&handle, object));
R_TRY(handle_table.Add(kernel, &handle, object));
// Close our reference to the object, as it is being moved to the caller.
object->Close();

View file

@ -373,7 +373,7 @@ public:
template <typename T>
Kernel::KScopedAutoObject<T> GetObjectFromHandle(u32 handle) {
auto obj = client_handle_table->GetObjectForIpc(handle, thread);
auto obj = client_handle_table->GetObjectForIpc(kernel, handle, thread);
if (obj.IsNotNull()) {
return obj->DynamicCast<T*>();
}

View file

@ -138,8 +138,7 @@ NvResult nvhost_as_gpu::AllocAsEx(IoctlAllocAsEx& params) {
static_cast<u32>((vm.va_range_end - vm.va_range_split) >> vm.big_page_size_bits)};
vm.big_page_allocator.emplace(start_big_pages, end_big_pages);
gmmu = std::make_shared<Tegra::MemoryManager>(system, max_big_page_bits, vm.va_range_split,
vm.big_page_size_bits, VM::PAGE_SIZE_BITS);
gmmu = std::make_unique<Tegra::MemoryManager>(system, max_big_page_bits, vm.va_range_split, vm.big_page_size_bits, VM::PAGE_SIZE_BITS);
system.GPU().InitAddressSpace(*gmmu);
vm.initialised = true;
@ -416,7 +415,7 @@ NvResult nvhost_as_gpu::BindChannel(IoctlBindChannel& params) {
LOG_DEBUG(Service_NVDRV, "called, fd={:X}", params.fd);
auto gpu_channel_device = module.GetDevice<nvhost_gpu>(params.fd);
gpu_channel_device->channel_state->memory_manager = gmmu;
gpu_channel_device->channel_state->memory_manager = gmmu.get();
return NvResult::Success;
}

View file

@ -219,7 +219,7 @@ private:
bool initialised{};
} vm;
std::shared_ptr<Tegra::MemoryManager> gmmu;
std::unique_ptr<Tegra::MemoryManager> gmmu;
};
} // namespace Service::Nvidia::Devices

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -10,14 +13,6 @@
namespace Service {
Process::Process(Core::System& system)
: m_system(system), m_process(), m_main_thread_priority(), m_main_thread_stack_size(),
m_process_started() {}
Process::~Process() {
this->Finalize();
}
bool Process::Initialize(Loader::AppLoader& loader, Loader::ResultStatus& out_load_result) {
// First, ensure we are not holding another process.
this->Finalize();

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -22,8 +25,8 @@ namespace Service {
class Process {
public:
explicit Process(Core::System& system);
~Process();
inline explicit Process(Core::System& system) noexcept : m_system(system) {}
inline ~Process() { this->Finalize(); }
bool Initialize(Loader::AppLoader& loader, Loader::ResultStatus& out_load_result);
void Finalize();
@ -50,8 +53,8 @@ public:
private:
Core::System& m_system;
Kernel::KProcess* m_process{};
s32 m_main_thread_priority{};
u64 m_main_thread_stack_size{};
s32 m_main_thread_priority{};
bool m_process_started{};
};

View file

@ -31,7 +31,7 @@ RenderdocAPI::RenderdocAPI() {
#elif defined(__HAIKU__)
// no rtld on haiku
#else
#ifdef ANDROID
#ifdef __ANDROID__
static constexpr const char RENDERDOC_LIB[] = "libVkLayer_GLES_RenderDoc.so";
#else
static constexpr const char RENDERDOC_LIB[] = "librenderdoc.so";

View file

@ -299,10 +299,24 @@ if ("loongarch64" IN_LIST ARCHITECTURE)
target_link_libraries(dynarmic PRIVATE lagoon::lagoon)
target_sources(dynarmic PRIVATE
backend/loongarch64/exclusive_monitor.cpp
backend/loongarch64/abi.h
backend/loongarch64/a32_jitstate.cpp
backend/loongarch64/a32_jitstate.h
backend/loongarch64/code_block.h
backend/loongarch64/emit_context.h
backend/loongarch64/emit_loongarch64.cpp
backend/loongarch64/emit_loongarch64.h
backend/loongarch64/emit_loongarch64_a32.cpp
backend/loongarch64/emit_loongarch64_data_processing.cpp
backend/loongarch64/a32_address_space.cpp
backend/loongarch64/a32_address_space.h
backend/loongarch64/a32_interface.cpp
backend/loongarch64/a64_interface.cpp
backend/loongarch64/code_block.h
backend/loongarch64/exclusive_monitor.cpp
backend/loongarch64/reg_alloc.cpp
backend/loongarch64/reg_alloc.h
backend/loongarch64/stack_layout.h
backend/loongarch64/lagoon_cpp.h
common/spin_lock_loongarch64.cpp
)

View file

@ -0,0 +1,123 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "dynarmic/backend/loongarch64/a32_address_space.h"
#include "common/assert.h"
#include "dynarmic/backend/loongarch64/a32_jitstate.h"
#include "dynarmic/backend/loongarch64/abi.h"
#include "dynarmic/backend/loongarch64/emit_loongarch64.h"
#include "dynarmic/frontend/A32/a32_location_descriptor.h"
#include "dynarmic/frontend/A32/translate/a32_translate.h"
#include "dynarmic/ir/opt_passes.h"
namespace Dynarmic::Backend::LoongArch64 {
A32AddressSpace::A32AddressSpace(const A32::UserConfig& conf)
: conf(conf)
, cb(conf.code_cache_size) {
EmitPrelude();
}
void A32AddressSpace::GenerateIR(IR::Block& ir_block, IR::LocationDescriptor descriptor) const {
A32::Translate(ir_block, A32::LocationDescriptor{descriptor}, conf.callbacks, {conf.arch_version, conf.define_unpredictable_behaviour, conf.hook_hint_instructions});
Optimization::Optimize(ir_block, conf, {.sha256 = true});
}
CodePtr A32AddressSpace::Get(IR::LocationDescriptor descriptor) {
if (const auto iter = block_entries.find(descriptor.Value()); iter != block_entries.end()) {
return iter->second;
}
return nullptr;
}
CodePtr A32AddressSpace::GetOrEmit(IR::LocationDescriptor descriptor) {
if (CodePtr block_entry = Get(descriptor)) {
return block_entry;
}
IR::Block ir_block{descriptor};
GenerateIR(ir_block, descriptor);
const EmittedBlockInfo block_info = Emit(std::move(ir_block));
block_infos.insert_or_assign(descriptor.Value(), block_info);
block_entries.insert_or_assign(descriptor.Value(), block_info.entry_point);
return block_info.entry_point;
}
void A32AddressSpace::ClearCache() {
block_entries.clear();
block_infos.clear();
SetCursorPtr(prelude_info.end_of_prelude);
}
void A32AddressSpace::EmitPrelude() {
prelude_info.run_code = GetCursorPtr<PreludeInfo::RunCodeFuncType>();
// Save all GPRs except sp (r3) and tp (r2)
la_addi_d(&cb.as, LA_SP, LA_SP, -64 * 8);
for (u32 i = 1; i < 32; i++) {
if (i == LA_SP || i == LA_TP)
continue;
la_st_d(&cb.as, static_cast<la_gpr_t>(i), LA_SP, static_cast<int32_t>(i * 8));
}
// Set up reserved registers and jump to block entry
la_move(&cb.as, Xstate, LA_A1); // Xstate = state ptr
la_move(&cb.as, Xhalt, LA_A2); // Xhalt = halt reason ptr
la_jr(&cb.as, LA_A0); // jump to block_entry
prelude_info.return_from_run_code = GetCursorPtr<CodePtr>();
// Restore all GPRs except sp and tp
for (u32 i = 1; i < 32; i++) {
if (i == LA_SP || i == LA_TP)
continue;
la_ld_d(&cb.as, static_cast<la_gpr_t>(i), LA_SP, static_cast<int32_t>(i * 8));
}
la_addi_d(&cb.as, LA_SP, LA_SP, 64 * 8);
la_ret(&cb.as);
prelude_info.end_of_prelude = GetCursorPtr<CodePtr>();
}
void A32AddressSpace::SetCursorPtr(CodePtr ptr) {
cb.as.cursor = reinterpret_cast<uint8_t*>(ptr);
}
size_t A32AddressSpace::GetRemainingSize() {
return la_get_remaining_buffer_size(&cb.as);
}
EmittedBlockInfo A32AddressSpace::Emit(IR::Block block) {
if (GetRemainingSize() < 1024 * 1024) {
ClearCache();
}
EmitConfig emit_conf{};
EmittedBlockInfo block_info = EmitLoongArch64(cb.as, std::move(block), emit_conf);
Link(block_info);
return block_info;
}
void A32AddressSpace::Link(EmittedBlockInfo& block_info) {
for (const auto& reloc : block_info.relocations) {
uint8_t* patch_location = reinterpret_cast<uint8_t*>(block_info.entry_point) + reloc.code_offset;
switch (reloc.target) {
case LinkTarget::ReturnFromRunCode: {
std::ptrdiff_t off = reinterpret_cast<uint8_t*>(prelude_info.return_from_run_code) - patch_location;
lagoon_assembler_t patch_as;
la_init_assembler(&patch_as, patch_location, 4);
la_b(&patch_as, static_cast<int32_t>(off));
break;
}
default:
ASSERT(false && "Invalid relocation target");
}
}
}
} // namespace Dynarmic::Backend::LoongArch64

View file

@ -0,0 +1,68 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include "dynarmic/backend/loongarch64/lagoon_cpp.h"
#include <ankerl/unordered_dense.h>
#include "dynarmic/backend/loongarch64/code_block.h"
#include "dynarmic/backend/loongarch64/emit_loongarch64.h"
#include "dynarmic/interface/A32/config.h"
#include "dynarmic/interface/halt_reason.h"
#include "dynarmic/ir/basic_block.h"
#include "dynarmic/ir/location_descriptor.h"
namespace Dynarmic::Backend::LoongArch64 {
struct A32JitState;
class A32AddressSpace final {
public:
explicit A32AddressSpace(const A32::UserConfig& conf);
void GenerateIR(IR::Block& ir_block, IR::LocationDescriptor descriptor) const;
CodePtr Get(IR::LocationDescriptor descriptor);
CodePtr GetOrEmit(IR::LocationDescriptor descriptor);
void ClearCache();
private:
void EmitPrelude();
template<typename T>
T GetCursorPtr() {
return reinterpret_cast<T>(cb.as.cursor);
}
template<typename T>
T GetCursorPtr() const {
return reinterpret_cast<T>(cb.as.cursor);
}
template<typename T>
T GetMemPtr() const {
return cb.ptr<T>();
}
void SetCursorPtr(CodePtr ptr);
size_t GetRemainingSize();
EmittedBlockInfo Emit(IR::Block block);
void Link(EmittedBlockInfo& block_info);
const A32::UserConfig conf;
CodeBlock cb;
ankerl::unordered_dense::map<u64, CodePtr> block_entries;
ankerl::unordered_dense::map<u64, EmittedBlockInfo> block_infos;
public:
struct PreludeInfo {
CodePtr end_of_prelude;
using RunCodeFuncType = HaltReason (*)(CodePtr entry_point, A32JitState* context, volatile u32* halt_reason);
RunCodeFuncType run_code;
CodePtr return_from_run_code;
} prelude_info;
};
} // namespace Dynarmic::Backend::LoongArch64

View file

@ -1,101 +1,134 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include <array>
#include <memory>
#include <string>
#include <utility>
#include <mutex>
#include <boost/icl/interval_set.hpp>
#include "common/assert.h"
#include "common/common_types.h"
#include "dynarmic/backend/loongarch64/a32_address_space.h"
#include "dynarmic/backend/loongarch64/a32_jitstate.h"
#include "dynarmic/common/atomic.h"
#include "dynarmic/frontend/A32/a32_location_descriptor.h"
#include "dynarmic/interface/A32/a32.h"
namespace Dynarmic::A32 {
using namespace Backend::LoongArch64;
struct Jit::Impl final {
explicit Impl(UserConfig conf_) : conf(std::move(conf_)) {}
Impl(Jit* jit_interface, A32::UserConfig conf)
: jit_interface(jit_interface)
, conf(conf)
, current_address_space(conf) {}
HaltReason Run() {
UNIMPLEMENTED();
return halt_reason;
ASSERT(!jit_interface->is_executing);
jit_interface->is_executing = true;
const auto location_descriptor = current_state.GetLocationDescriptor();
const auto entry_point = current_address_space.GetOrEmit(location_descriptor);
current_address_space.prelude_info.run_code(entry_point, &current_state, &halt_reason);
HaltReason hr = static_cast<HaltReason>(Atomic::Exchange(&halt_reason, 0));
jit_interface->is_executing = false;
return hr;
}
HaltReason Step() {
UNIMPLEMENTED();
return halt_reason | HaltReason::Step;
ASSERT(!jit_interface->is_executing);
jit_interface->is_executing = true;
const auto location_descriptor = A32::LocationDescriptor{current_state.GetLocationDescriptor()}.SetSingleStepping(true);
const auto entry_point = current_address_space.GetOrEmit(location_descriptor);
current_address_space.prelude_info.run_code(entry_point, &current_state, &halt_reason);
HaltReason hr = static_cast<HaltReason>(Atomic::Exchange(&halt_reason, 0));
jit_interface->is_executing = false;
return hr;
}
void ClearCache() {
std::unique_lock lock{invalidation_mutex};
invalidate_entire_cache = true;
HaltExecution(HaltReason::CacheInvalidation);
}
void InvalidateCacheRange(u32, std::size_t) {
void InvalidateCacheRange(u32 start_address, size_t length) {
std::unique_lock lock{invalidation_mutex};
invalid_cache_ranges.add(boost::icl::discrete_interval<u32>::closed(start_address, static_cast<u32>(start_address + length - 1)));
HaltExecution(HaltReason::CacheInvalidation);
}
void Reset() {
regs = {};
ext_regs = {};
cpsr = 0;
fpscr = 0;
halt_reason = {};
current_state = {};
}
void HaltExecution(HaltReason hr) {
halt_reason |= hr;
Atomic::Or(&halt_reason, static_cast<u32>(hr));
}
void ClearHalt(HaltReason hr) {
halt_reason &= ~hr;
Atomic::And(&halt_reason, ~static_cast<u32>(hr));
}
std::array<u32, 16>& Regs() {
return regs;
return current_state.regs;
}
const std::array<u32, 16>& Regs() const {
return regs;
return current_state.regs;
}
std::array<u32, 64>& ExtRegs() {
return ext_regs;
return current_state.ext_regs;
}
const std::array<u32, 64>& ExtRegs() const {
return ext_regs;
return current_state.ext_regs;
}
u32 Cpsr() const {
return cpsr;
return current_state.Cpsr();
}
void SetCpsr(u32 value) {
cpsr = value;
current_state.SetCpsr(value);
}
u32 Fpscr() const {
return fpscr;
return current_state.Fpscr();
}
void SetFpscr(u32 value) {
fpscr = value;
current_state.SetFpscr(value);
}
void ClearExclusiveState() {}
void ClearExclusiveState() {
current_state.exclusive_state = false;
}
std::string Disassemble() const {
return {};
}
UserConfig conf;
std::array<u32, 16> regs{};
std::array<u32, 64> ext_regs{};
u32 cpsr = 0;
u32 fpscr = 0;
HaltReason halt_reason{};
private:
Jit* jit_interface;
A32::UserConfig conf;
A32JitState current_state{};
A32AddressSpace current_address_space;
volatile u32 halt_reason = 0;
std::mutex invalidation_mutex;
boost::icl::interval_set<u32> invalid_cache_ranges;
bool invalidate_entire_cache = false;
};
Jit::Jit(UserConfig conf) : impl(std::make_unique<Impl>(std::move(conf))) {}
Jit::Jit(UserConfig conf)
: impl(std::make_unique<Impl>(this, conf)) {}
Jit::~Jit() = default;
@ -111,7 +144,7 @@ void Jit::ClearCache() {
impl->ClearCache();
}
void Jit::InvalidateCacheRange(u32 start_address, std::size_t length) {
void Jit::InvalidateCacheRange(u32 start_address, size_t length) {
impl->InvalidateCacheRange(start_address, length);
}

View file

@ -0,0 +1,57 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "dynarmic/backend/loongarch64/a32_jitstate.h"
#include "dynarmic/mcl/bit.hpp"
#include "common/common_types.h"
namespace Dynarmic::Backend::LoongArch64 {
u32 A32JitState::Cpsr() const {
u32 cpsr = 0;
cpsr |= cpsr_nzcv;
cpsr |= cpsr_q;
cpsr |= mcl::bit::get_bit<31>(cpsr_ge) ? 1 << 19 : 0;
cpsr |= mcl::bit::get_bit<23>(cpsr_ge) ? 1 << 18 : 0;
cpsr |= mcl::bit::get_bit<15>(cpsr_ge) ? 1 << 17 : 0;
cpsr |= mcl::bit::get_bit<7>(cpsr_ge) ? 1 << 16 : 0;
cpsr |= mcl::bit::get_bit<1>(upper_location_descriptor) ? 1 << 9 : 0;
cpsr |= mcl::bit::get_bit<0>(upper_location_descriptor) ? 1 << 5 : 0;
cpsr |= static_cast<u32>(upper_location_descriptor & 0b11111100'00000000);
cpsr |= static_cast<u32>(upper_location_descriptor & 0b00000011'00000000) << 17;
cpsr |= cpsr_jaifm;
return cpsr;
}
void A32JitState::SetCpsr(u32 cpsr) {
cpsr_nzcv = cpsr & 0xF0000000;
cpsr_q = cpsr & (1 << 27);
cpsr_ge = 0;
cpsr_ge |= mcl::bit::get_bit<19>(cpsr) ? 0xFF000000 : 0;
cpsr_ge |= mcl::bit::get_bit<18>(cpsr) ? 0x00FF0000 : 0;
cpsr_ge |= mcl::bit::get_bit<17>(cpsr) ? 0x0000FF00 : 0;
cpsr_ge |= mcl::bit::get_bit<16>(cpsr) ? 0x000000FF : 0;
upper_location_descriptor &= 0xFFFF0000;
upper_location_descriptor |= mcl::bit::get_bit<9>(cpsr) ? 2 : 0;
upper_location_descriptor |= mcl::bit::get_bit<5>(cpsr) ? 1 : 0;
upper_location_descriptor |= (cpsr >> 0) & 0b11111100'00000000;
upper_location_descriptor |= (cpsr >> 17) & 0b00000011'00000000;
cpsr_jaifm = cpsr & 0x010001DF;
}
constexpr u32 FPCR_MASK = A32::LocationDescriptor::FPSCR_MODE_MASK;
constexpr u32 FPSR_MASK = 0x0800009F;
u32 A32JitState::Fpscr() const {
return (upper_location_descriptor & FPCR_MASK) | fpsr | fpsr_nzcv;
}
void A32JitState::SetFpscr(u32 fpscr) {
fpsr = fpscr & FPSR_MASK;
fpsr_nzcv = fpscr & 0xF0000000;
upper_location_descriptor = (upper_location_descriptor & 0x0000ffff) | (fpscr & FPCR_MASK);
}
} // namespace Dynarmic::Backend::LoongArch64

Some files were not shown because too many files have changed in this diff Show more