diff options
Diffstat (limited to 'src/core/hle')
278 files changed, 4305 insertions, 3686 deletions
diff --git a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp index c10b7bf30..5b8a248c8 100644 --- a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp +++ b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp @@ -14,9 +14,12 @@ namespace Kernel::Board::Nintendo::Nx { namespace impl { -constexpr const std::size_t RequiredNonSecureSystemMemorySizeVi = 0x2238 * 4 * 1024; -constexpr const std::size_t RequiredNonSecureSystemMemorySizeNvservices = 0x710 * 4 * 1024; -constexpr const std::size_t RequiredNonSecureSystemMemorySizeMisc = 0x80 * 4 * 1024; +using namespace Common::Literals; + +constexpr const std::size_t RequiredNonSecureSystemMemorySizeVi = 0x2280 * 4_KiB; +constexpr const std::size_t RequiredNonSecureSystemMemorySizeViFatal = 0x200 * 4_KiB; +constexpr const std::size_t RequiredNonSecureSystemMemorySizeNvservices = 0x704 * 4_KiB; +constexpr const std::size_t RequiredNonSecureSystemMemorySizeMisc = 0x80 * 4_KiB; } // namespace impl @@ -24,6 +27,9 @@ constexpr const std::size_t RequiredNonSecureSystemMemorySize = impl::RequiredNonSecureSystemMemorySizeVi + impl::RequiredNonSecureSystemMemorySizeNvservices + impl::RequiredNonSecureSystemMemorySizeMisc; +constexpr const std::size_t RequiredNonSecureSystemMemorySizeWithFatal = + RequiredNonSecureSystemMemorySize + impl::RequiredNonSecureSystemMemorySizeViFatal; + namespace { using namespace Common::Literals; @@ -120,10 +126,13 @@ size_t KSystemControl::Init::GetAppletPoolSize() { size_t KSystemControl::Init::GetMinimumNonSecureSystemPoolSize() { // Verify that our minimum is at least as large as Nintendo's. - constexpr size_t MinimumSize = RequiredNonSecureSystemMemorySize; - static_assert(MinimumSize >= 0x29C8000); + constexpr size_t MinimumSizeWithFatal = RequiredNonSecureSystemMemorySizeWithFatal; + static_assert(MinimumSizeWithFatal >= 0x2C04000); + + constexpr size_t MinimumSizeWithoutFatal = RequiredNonSecureSystemMemorySize; + static_assert(MinimumSizeWithoutFatal >= 0x2A00000); - return MinimumSize; + return MinimumSizeWithFatal; } namespace { diff --git a/src/core/hle/kernel/init/init_slab_setup.cpp b/src/core/hle/kernel/init/init_slab_setup.cpp index abdb5639f..5e4090e2b 100644 --- a/src/core/hle/kernel/init/init_slab_setup.cpp +++ b/src/core/hle/kernel/init/init_slab_setup.cpp @@ -33,6 +33,9 @@ namespace Kernel::Init { +// For macro convenience. +using KThreadLockInfo = KThread::LockWithPriorityInheritanceInfo; + #define SLAB_COUNT(CLASS) kernel.SlabResourceCounts().num_##CLASS #define FOREACH_SLAB_TYPE(HANDLER, ...) \ @@ -54,7 +57,8 @@ namespace Kernel::Init { HANDLER(KResourceLimit, (SLAB_COUNT(KResourceLimit)), ##__VA_ARGS__) \ HANDLER(KEventInfo, (SLAB_COUNT(KThread) + SLAB_COUNT(KDebug)), ##__VA_ARGS__) \ HANDLER(KDebug, (SLAB_COUNT(KDebug)), ##__VA_ARGS__) \ - HANDLER(KSecureSystemResource, (SLAB_COUNT(KProcess)), ##__VA_ARGS__) + HANDLER(KSecureSystemResource, (SLAB_COUNT(KProcess)), ##__VA_ARGS__) \ + HANDLER(KThreadLockInfo, (SLAB_COUNT(KThread)), ##__VA_ARGS__) namespace { @@ -131,7 +135,7 @@ VAddr InitializeSlabHeap(Core::System& system, KMemoryLayout& memory_layout, VAd } size_t CalculateSlabHeapGapSize() { - constexpr size_t KernelSlabHeapGapSize = 2_MiB - 320_KiB; + constexpr size_t KernelSlabHeapGapSize = 2_MiB - 356_KiB; static_assert(KernelSlabHeapGapSize <= KernelSlabHeapGapsSizeMax); return KernelSlabHeapGapSize; } diff --git a/src/core/hle/kernel/k_address_arbiter.cpp b/src/core/hle/kernel/k_address_arbiter.cpp index a442a3b98..fb86451ea 100644 --- a/src/core/hle/kernel/k_address_arbiter.cpp +++ b/src/core/hle/kernel/k_address_arbiter.cpp @@ -29,7 +29,9 @@ bool DecrementIfLessThan(Core::System& system, s32* out, VAddr address, s32 valu auto& monitor = system.Monitor(); const auto current_core = system.Kernel().CurrentPhysicalCoreIndex(); - // TODO(bunnei): We should disable interrupts here via KScopedInterruptDisable. + // NOTE: If scheduler lock is not held here, interrupt disable is required. + // KScopedInterruptDisable di; + // TODO(bunnei): We should call CanAccessAtomic(..) here. // Load the value from the address. @@ -59,7 +61,9 @@ bool UpdateIfEqual(Core::System& system, s32* out, VAddr address, s32 value, s32 auto& monitor = system.Monitor(); const auto current_core = system.Kernel().CurrentPhysicalCoreIndex(); - // TODO(bunnei): We should disable interrupts here via KScopedInterruptDisable. + // NOTE: If scheduler lock is not held here, interrupt disable is required. + // KScopedInterruptDisable di; + // TODO(bunnei): We should call CanAccessAtomic(..) here. // Load the value from the address. diff --git a/src/core/hle/kernel/k_address_space_info.cpp b/src/core/hle/kernel/k_address_space_info.cpp index 3e612a207..c36eb5dc4 100644 --- a/src/core/hle/kernel/k_address_space_info.cpp +++ b/src/core/hle/kernel/k_address_space_info.cpp @@ -23,86 +23,33 @@ constexpr std::array<KAddressSpaceInfo, 13> AddressSpaceInfos{{ { .bit_width = 32, .address = Size_Invalid, .size = 1_GiB , .type = KAddressSpaceInfo::Type::Heap, }, { .bit_width = 36, .address = 128_MiB , .size = 2_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::MapSmall, }, { .bit_width = 36, .address = 2_GiB , .size = 64_GiB - 2_GiB , .type = KAddressSpaceInfo::Type::MapLarge, }, - { .bit_width = 36, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Heap, }, + { .bit_width = 36, .address = Size_Invalid, .size = 8_GiB , .type = KAddressSpaceInfo::Type::Heap, }, { .bit_width = 36, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Alias, }, { .bit_width = 39, .address = 128_MiB , .size = 512_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::Map39Bit, }, { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::MapSmall }, - { .bit_width = 39, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Heap, }, + { .bit_width = 39, .address = Size_Invalid, .size = 8_GiB , .type = KAddressSpaceInfo::Type::Heap, }, { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::Alias, }, { .bit_width = 39, .address = Size_Invalid, .size = 2_GiB , .type = KAddressSpaceInfo::Type::Stack, }, }}; // clang-format on -constexpr bool IsAllowedIndexForAddress(std::size_t index) { - return index < AddressSpaceInfos.size() && AddressSpaceInfos[index].address != Size_Invalid; -} - -using IndexArray = - std::array<std::size_t, static_cast<std::size_t>(KAddressSpaceInfo::Type::Count)>; - -constexpr IndexArray AddressSpaceIndices32Bit{ - 0, 1, 0, 2, 0, 3, -}; - -constexpr IndexArray AddressSpaceIndices36Bit{ - 4, 5, 4, 6, 4, 7, -}; - -constexpr IndexArray AddressSpaceIndices39Bit{ - 9, 8, 8, 10, 12, 11, -}; - -constexpr bool IsAllowed32BitType(KAddressSpaceInfo::Type type) { - return type < KAddressSpaceInfo::Type::Count && type != KAddressSpaceInfo::Type::Map39Bit && - type != KAddressSpaceInfo::Type::Stack; -} - -constexpr bool IsAllowed36BitType(KAddressSpaceInfo::Type type) { - return type < KAddressSpaceInfo::Type::Count && type != KAddressSpaceInfo::Type::Map39Bit && - type != KAddressSpaceInfo::Type::Stack; -} - -constexpr bool IsAllowed39BitType(KAddressSpaceInfo::Type type) { - return type < KAddressSpaceInfo::Type::Count && type != KAddressSpaceInfo::Type::MapLarge; +const KAddressSpaceInfo& GetAddressSpaceInfo(size_t width, KAddressSpaceInfo::Type type) { + for (auto& info : AddressSpaceInfos) { + if (info.bit_width == width && info.type == type) { + return info; + } + } + UNREACHABLE_MSG("Could not find AddressSpaceInfo"); } } // namespace -u64 KAddressSpaceInfo::GetAddressSpaceStart(std::size_t width, Type type) { - const std::size_t index{static_cast<std::size_t>(type)}; - switch (width) { - case 32: - ASSERT(IsAllowed32BitType(type)); - ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices32Bit[index])); - return AddressSpaceInfos[AddressSpaceIndices32Bit[index]].address; - case 36: - ASSERT(IsAllowed36BitType(type)); - ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices36Bit[index])); - return AddressSpaceInfos[AddressSpaceIndices36Bit[index]].address; - case 39: - ASSERT(IsAllowed39BitType(type)); - ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices39Bit[index])); - return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].address; - } - ASSERT(false); - return 0; +std::size_t KAddressSpaceInfo::GetAddressSpaceStart(size_t width, KAddressSpaceInfo::Type type) { + return GetAddressSpaceInfo(width, type).address; } -std::size_t KAddressSpaceInfo::GetAddressSpaceSize(std::size_t width, Type type) { - const std::size_t index{static_cast<std::size_t>(type)}; - switch (width) { - case 32: - ASSERT(IsAllowed32BitType(type)); - return AddressSpaceInfos[AddressSpaceIndices32Bit[index]].size; - case 36: - ASSERT(IsAllowed36BitType(type)); - return AddressSpaceInfos[AddressSpaceIndices36Bit[index]].size; - case 39: - ASSERT(IsAllowed39BitType(type)); - return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].size; - } - ASSERT(false); - return 0; +std::size_t KAddressSpaceInfo::GetAddressSpaceSize(size_t width, KAddressSpaceInfo::Type type) { + return GetAddressSpaceInfo(width, type).size; } } // namespace Kernel diff --git a/src/core/hle/kernel/k_address_space_info.h b/src/core/hle/kernel/k_address_space_info.h index 69e9d77f2..9a26f6b90 100644 --- a/src/core/hle/kernel/k_address_space_info.h +++ b/src/core/hle/kernel/k_address_space_info.h @@ -18,7 +18,7 @@ struct KAddressSpaceInfo final { Count, }; - static u64 GetAddressSpaceStart(std::size_t width, Type type); + static std::size_t GetAddressSpaceStart(std::size_t width, Type type); static std::size_t GetAddressSpaceSize(std::size_t width, Type type); const std::size_t bit_width{}; diff --git a/src/core/hle/kernel/k_client_port.cpp b/src/core/hle/kernel/k_client_port.cpp index c72a91a76..700ae71e3 100644 --- a/src/core/hle/kernel/k_client_port.cpp +++ b/src/core/hle/kernel/k_client_port.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/scope_exit.h" -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_client_port.h" #include "core/hle/kernel/k_port.h" #include "core/hle/kernel/k_scheduler.h" diff --git a/src/core/hle/kernel/k_client_port.h b/src/core/hle/kernel/k_client_port.h index 81046fb86..a757cf9cd 100644 --- a/src/core/hle/kernel/k_client_port.h +++ b/src/core/hle/kernel/k_client_port.h @@ -15,7 +15,6 @@ namespace Kernel { class KClientSession; class KernelCore; class KPort; -class SessionRequestManager; class KClientPort final : public KSynchronizationObject { KERNEL_AUTOOBJECT_TRAITS(KClientPort, KSynchronizationObject); diff --git a/src/core/hle/kernel/k_client_session.cpp b/src/core/hle/kernel/k_client_session.cpp index b4197a8d5..da0c9ac8c 100644 --- a/src/core/hle/kernel/k_client_session.cpp +++ b/src/core/hle/kernel/k_client_session.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/scope_exit.h" -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_client_session.h" #include "core/hle/kernel/k_server_session.h" #include "core/hle/kernel/k_session.h" diff --git a/src/core/hle/kernel/k_condition_variable.cpp b/src/core/hle/kernel/k_condition_variable.cpp index 3f0be1c3f..f40cf92b1 100644 --- a/src/core/hle/kernel/k_condition_variable.cpp +++ b/src/core/hle/kernel/k_condition_variable.cpp @@ -111,36 +111,36 @@ Result KConditionVariable::SignalToAddress(VAddr addr) { KScopedSchedulerLock sl(kernel); // Remove waiter thread. - s32 num_waiters{}; - KThread* next_owner_thread = - owner_thread->RemoveWaiterByKey(std::addressof(num_waiters), addr); + bool has_waiters{}; + KThread* const next_owner_thread = + owner_thread->RemoveUserWaiterByKey(std::addressof(has_waiters), addr); // Determine the next tag. u32 next_value{}; if (next_owner_thread != nullptr) { next_value = next_owner_thread->GetAddressKeyValue(); - if (num_waiters > 1) { + if (has_waiters) { next_value |= Svc::HandleWaitMask; } + } - // Write the value to userspace. - Result result{ResultSuccess}; - if (WriteToUser(system, addr, std::addressof(next_value))) [[likely]] { - result = ResultSuccess; - } else { - result = ResultInvalidCurrentMemory; - } + // Synchronize memory before proceeding. + std::atomic_thread_fence(std::memory_order_seq_cst); - // Signal the next owner thread. - next_owner_thread->EndWait(result); - return result; + // Write the value to userspace. + Result result{ResultSuccess}; + if (WriteToUser(system, addr, std::addressof(next_value))) [[likely]] { + result = ResultSuccess; } else { - // Just write the value to userspace. - R_UNLESS(WriteToUser(system, addr, std::addressof(next_value)), - ResultInvalidCurrentMemory); + result = ResultInvalidCurrentMemory; + } - return ResultSuccess; + // If necessary, signal the next owner thread. + if (next_owner_thread != nullptr) { + next_owner_thread->EndWait(result); } + + R_RETURN(result); } } @@ -198,7 +198,9 @@ void KConditionVariable::SignalImpl(KThread* thread) { u32 prev_tag{}; bool can_access{}; { - // TODO(bunnei): We should disable interrupts here via KScopedInterruptDisable. + // NOTE: If scheduler lock is not held here, interrupt disable is required. + // KScopedInterruptDisable di; + // TODO(bunnei): We should call CanAccessAtomic(..) here. can_access = true; if (can_access) [[likely]] { @@ -245,9 +247,11 @@ void KConditionVariable::Signal(u64 cv_key, s32 count) { (it->GetConditionVariableKey() == cv_key)) { KThread* target_thread = std::addressof(*it); - this->SignalImpl(target_thread); it = thread_tree.erase(it); target_thread->ClearConditionVariable(); + + this->SignalImpl(target_thread); + ++num_waiters; } @@ -277,16 +281,16 @@ Result KConditionVariable::Wait(VAddr addr, u64 key, u32 value, s64 timeout) { // Update the value and process for the next owner. { // Remove waiter thread. - s32 num_waiters{}; + bool has_waiters{}; KThread* next_owner_thread = - cur_thread->RemoveWaiterByKey(std::addressof(num_waiters), addr); + cur_thread->RemoveUserWaiterByKey(std::addressof(has_waiters), addr); // Update for the next owner thread. u32 next_value{}; if (next_owner_thread != nullptr) { // Get the next tag value. next_value = next_owner_thread->GetAddressKeyValue(); - if (num_waiters > 1) { + if (has_waiters) { next_value |= Svc::HandleWaitMask; } diff --git a/src/core/hle/kernel/k_device_address_space.h b/src/core/hle/kernel/k_device_address_space.h index 4709df995..b4a014c38 100644 --- a/src/core/hle/kernel/k_device_address_space.h +++ b/src/core/hle/kernel/k_device_address_space.h @@ -21,9 +21,9 @@ public: ~KDeviceAddressSpace(); Result Initialize(u64 address, u64 size); - void Finalize(); + void Finalize() override; - bool IsInitialized() const { + bool IsInitialized() const override { return m_is_initialized; } static void PostDestroy(uintptr_t arg) {} diff --git a/src/core/hle/kernel/k_light_lock.cpp b/src/core/hle/kernel/k_light_lock.cpp index d791acbe3..14cb615da 100644 --- a/src/core/hle/kernel/k_light_lock.cpp +++ b/src/core/hle/kernel/k_light_lock.cpp @@ -90,15 +90,15 @@ void KLightLock::UnlockSlowPath(uintptr_t _cur_thread) { KScopedSchedulerLock sl(kernel); // Get the next owner. - s32 num_waiters; - KThread* next_owner = owner_thread->RemoveWaiterByKey( - std::addressof(num_waiters), reinterpret_cast<uintptr_t>(std::addressof(tag))); + bool has_waiters; + KThread* next_owner = owner_thread->RemoveKernelWaiterByKey( + std::addressof(has_waiters), reinterpret_cast<uintptr_t>(std::addressof(tag))); // Pass the lock to the next owner. uintptr_t next_tag = 0; if (next_owner != nullptr) { next_tag = - reinterpret_cast<uintptr_t>(next_owner) | static_cast<uintptr_t>(num_waiters > 1); + reinterpret_cast<uintptr_t>(next_owner) | static_cast<uintptr_t>(has_waiters); next_owner->EndWait(ResultSuccess); diff --git a/src/core/hle/kernel/k_port.cpp b/src/core/hle/kernel/k_port.cpp index 77d00ae2c..0a45ffd57 100644 --- a/src/core/hle/kernel/k_port.cpp +++ b/src/core/hle/kernel/k_port.cpp @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_port.h" #include "core/hle/kernel/k_scheduler.h" #include "core/hle/kernel/svc_results.h" diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp index 0e4283a0c..d44f6e921 100644 --- a/src/core/hle/kernel/k_process.cpp +++ b/src/core/hle/kernel/k_process.cpp @@ -119,7 +119,6 @@ void KProcess::DecrementRunningThreadCount() { if (const auto prev = num_running_threads--; prev == 1) { // TODO(bunnei): Process termination to be implemented when multiprocess is supported. - UNIMPLEMENTED_MSG("KProcess termination is not implemennted!"); } } @@ -157,9 +156,9 @@ bool KProcess::ReleaseUserException(KThread* thread) { exception_thread = nullptr; // Remove waiter thread. - s32 num_waiters{}; - if (KThread* next = thread->RemoveWaiterByKey( - std::addressof(num_waiters), + bool has_waiters{}; + if (KThread* next = thread->RemoveKernelWaiterByKey( + std::addressof(has_waiters), reinterpret_cast<uintptr_t>(std::addressof(exception_thread))); next != nullptr) { next->EndWait(ResultSuccess); @@ -357,9 +356,6 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std: system_resource_size = metadata.GetSystemResourceSize(); image_size = code_size; - // We currently do not support process-specific system resource - UNIMPLEMENTED_IF(system_resource_size != 0); - KScopedResourceReservation memory_reservation( resource_limit, LimitableResource::PhysicalMemoryMax, code_size + system_resource_size); if (!memory_reservation.Succeeded()) { diff --git a/src/core/hle/kernel/k_process.h b/src/core/hle/kernel/k_process.h index 09bf2f1d0..549809000 100644 --- a/src/core/hle/kernel/k_process.h +++ b/src/core/hle/kernel/k_process.h @@ -310,10 +310,10 @@ public: /// Clears the signaled state of the process if and only if it's signaled. /// /// @pre The process must not be already terminated. If this is called on a - /// terminated process, then ERR_INVALID_STATE will be returned. + /// terminated process, then ResultInvalidState will be returned. /// /// @pre The process must be in a signaled state. If this is called on a - /// process instance that is not signaled, ERR_INVALID_STATE will be + /// process instance that is not signaled, ResultInvalidState will be /// returned. Result Reset(); diff --git a/src/core/hle/kernel/k_resource_limit.cpp b/src/core/hle/kernel/k_resource_limit.cpp index b9d22b414..626517619 100644 --- a/src/core/hle/kernel/k_resource_limit.cpp +++ b/src/core/hle/kernel/k_resource_limit.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/assert.h" +#include "common/overflow.h" #include "core/core.h" #include "core/core_timing.h" #include "core/hle/kernel/k_resource_limit.h" @@ -104,7 +105,7 @@ bool KResourceLimit::Reserve(LimitableResource which, s64 value, s64 timeout) { ASSERT(current_hints[index] <= current_values[index]); // If we would overflow, don't allow to succeed. - if (current_values[index] + value <= current_values[index]) { + if (Common::WrappingAdd(current_values[index], value) <= current_values[index]) { break; } diff --git a/src/core/hle/kernel/k_scheduler_lock.h b/src/core/hle/kernel/k_scheduler_lock.h index 129d60472..13463717f 100644 --- a/src/core/hle/kernel/k_scheduler_lock.h +++ b/src/core/hle/kernel/k_scheduler_lock.h @@ -31,22 +31,23 @@ public: } if (IsLockedByCurrentThread()) { - // If we already own the lock, we can just increment the count. + // If we already own the lock, the lock count should be > 0. + // For debug, ensure this is true. ASSERT(lock_count > 0); - lock_count++; } else { // Otherwise, we want to disable scheduling and acquire the spinlock. SchedulerType::DisableScheduling(kernel); spin_lock.Lock(); - // For debug, ensure that our state is valid. ASSERT(lock_count == 0); ASSERT(owner_thread == nullptr); - // Increment count, take ownership. - lock_count = 1; + // Take ownership of the lock. owner_thread = GetCurrentThreadPointer(kernel); } + + // Increment the lock count. + lock_count++; } void Unlock() { diff --git a/src/core/hle/kernel/k_scoped_lock.h b/src/core/hle/kernel/k_scoped_lock.h index 59b3e32ae..a15640fd2 100644 --- a/src/core/hle/kernel/k_scoped_lock.h +++ b/src/core/hle/kernel/k_scoped_lock.h @@ -4,6 +4,7 @@ #pragma once #include <concepts> +#include <memory> #include <type_traits> namespace Kernel { diff --git a/src/core/hle/kernel/k_server_session.cpp b/src/core/hle/kernel/k_server_session.cpp index aa1941f01..01591af5b 100644 --- a/src/core/hle/kernel/k_server_session.cpp +++ b/src/core/hle/kernel/k_server_session.cpp @@ -10,8 +10,6 @@ #include "common/scope_exit.h" #include "core/core.h" #include "core/core_timing.h" -#include "core/hle/ipc_helpers.h" -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_client_port.h" #include "core/hle/kernel/k_handle_table.h" #include "core/hle/kernel/k_process.h" @@ -22,6 +20,8 @@ #include "core/hle/kernel/k_thread.h" #include "core/hle/kernel/k_thread_queue.h" #include "core/hle/kernel/kernel.h" +#include "core/hle/service/hle_ipc.h" +#include "core/hle/service/ipc_helpers.h" #include "core/memory.h" namespace Kernel { @@ -281,8 +281,8 @@ Result KServerSession::SendReply(bool is_hle) { return result; } -Result KServerSession::ReceiveRequest(std::shared_ptr<HLERequestContext>* out_context, - std::weak_ptr<SessionRequestManager> manager) { +Result KServerSession::ReceiveRequest(std::shared_ptr<Service::HLERequestContext>* out_context, + std::weak_ptr<Service::SessionRequestManager> manager) { // Lock the session. KScopedLightLock lk{m_lock}; @@ -329,7 +329,8 @@ Result KServerSession::ReceiveRequest(std::shared_ptr<HLERequestContext>* out_co if (out_context != nullptr) { // HLE request. u32* cmd_buf{reinterpret_cast<u32*>(memory.GetPointer(client_message))}; - *out_context = std::make_shared<HLERequestContext>(kernel, memory, this, client_thread); + *out_context = + std::make_shared<Service::HLERequestContext>(kernel, memory, this, client_thread); (*out_context)->SetSessionRequestManager(manager); (*out_context) ->PopulateFromIncomingCommandBuffer(client_thread->GetOwnerProcess()->GetHandleTable(), diff --git a/src/core/hle/kernel/k_server_session.h b/src/core/hle/kernel/k_server_session.h index 6e189af8b..33f380352 100644 --- a/src/core/hle/kernel/k_server_session.h +++ b/src/core/hle/kernel/k_server_session.h @@ -10,18 +10,20 @@ #include <boost/intrusive/list.hpp> -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_light_lock.h" #include "core/hle/kernel/k_session_request.h" #include "core/hle/kernel/k_synchronization_object.h" #include "core/hle/result.h" +namespace Service { +class HLERequestContext; +class SessionRequestManager; +} // namespace Service + namespace Kernel { -class HLERequestContext; class KernelCore; class KSession; -class SessionRequestManager; class KThread; class KServerSession final : public KSynchronizationObject, @@ -52,8 +54,8 @@ public: /// TODO: flesh these out to match the real kernel Result OnRequest(KSessionRequest* request); Result SendReply(bool is_hle = false); - Result ReceiveRequest(std::shared_ptr<HLERequestContext>* out_context = nullptr, - std::weak_ptr<SessionRequestManager> manager = {}); + Result ReceiveRequest(std::shared_ptr<Service::HLERequestContext>* out_context = nullptr, + std::weak_ptr<Service::SessionRequestManager> manager = {}); Result SendReplyHLE() { return SendReply(true); diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp index 2d3da9d66..8c403f5fd 100644 --- a/src/core/hle/kernel/k_thread.cpp +++ b/src/core/hle/kernel/k_thread.cpp @@ -29,6 +29,7 @@ #include "core/hle/kernel/k_thread_queue.h" #include "core/hle/kernel/k_worker_task_manager.h" #include "core/hle/kernel/kernel.h" +#include "core/hle/kernel/svc.h" #include "core/hle/kernel/svc_results.h" #include "core/hle/kernel/svc_types.h" #include "core/hle/result.h" @@ -190,7 +191,7 @@ Result KThread::Initialize(KThreadFunction func, uintptr_t arg, VAddr user_stack light_ipc_data = nullptr; // We're not waiting for a lock, and we haven't disabled migration. - lock_owner = nullptr; + waiting_lock_info = nullptr; num_core_migration_disables = 0; // We have no waiters, but we do have an entrypoint. @@ -298,6 +299,25 @@ Result KThread::InitializeUserThread(Core::System& system, KThread* thread, KThr ThreadType::User, system.GetCpuManager().GetGuestThreadFunc())); } +Result KThread::InitializeServiceThread(Core::System& system, KThread* thread, + std::function<void()>&& func, s32 prio, s32 virt_core, + KProcess* owner) { + system.Kernel().GlobalSchedulerContext().AddThread(thread); + std::function<void()> func2{[&system, func{std::move(func)}] { + // Similar to UserModeThreadStarter. + system.Kernel().CurrentScheduler()->OnThreadStart(); + + // Run the guest function. + func(); + + // Exit. + Svc::ExitThread(system); + }}; + + R_RETURN(InitializeThread(thread, {}, {}, {}, prio, virt_core, owner, ThreadType::HighPriority, + std::move(func2))); +} + void KThread::PostDestroy(uintptr_t arg) { KProcess* owner = reinterpret_cast<KProcess*>(arg & ~1ULL); const bool resource_limit_release_hint = (arg & 1); @@ -321,25 +341,39 @@ void KThread::Finalize() { // Release any waiters. { - ASSERT(lock_owner == nullptr); + ASSERT(waiting_lock_info == nullptr); KScopedSchedulerLock sl{kernel}; - auto it = waiter_list.begin(); - while (it != waiter_list.end()) { - // Get the thread. - KThread* const waiter = std::addressof(*it); + // Check that we have no kernel waiters. + ASSERT(num_kernel_waiters == 0); + + auto it = held_lock_info_list.begin(); + while (it != held_lock_info_list.end()) { + // Get the lock info. + auto* const lock_info = std::addressof(*it); + + // The lock shouldn't have a kernel waiter. + ASSERT(!lock_info->GetIsKernelAddressKey()); - // The thread shouldn't be a kernel waiter. - ASSERT(!waiter->GetAddressKeyIsKernel()); + // Remove all waiters. + while (lock_info->GetWaiterCount() != 0) { + // Get the front waiter. + KThread* const waiter = lock_info->GetHighestPriorityWaiter(); + + // Remove it from the lock. + if (lock_info->RemoveWaiter(waiter)) { + ASSERT(lock_info->GetWaiterCount() == 0); + } - // Clear the lock owner. - waiter->SetLockOwner(nullptr); + // Cancel the thread's wait. + waiter->CancelWait(ResultInvalidState, true); + } - // Erase the waiter from our list. - it = waiter_list.erase(it); + // Remove the held lock from our list. + it = held_lock_info_list.erase(it); - // Cancel the thread's wait. - waiter->CancelWait(ResultInvalidState, true); + // Free the lock info. + LockWithPriorityInheritanceInfo::Free(kernel, lock_info); } } @@ -688,6 +722,24 @@ void KThread::SetBasePriority(s32 value) { RestorePriority(kernel, this); } +KThread* KThread::GetLockOwner() const { + return waiting_lock_info != nullptr ? waiting_lock_info->GetOwner() : nullptr; +} + +void KThread::IncreaseBasePriority(s32 priority_) { + ASSERT(Svc::HighestThreadPriority <= priority_ && priority_ <= Svc::LowestThreadPriority); + ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel)); + ASSERT(!this->GetStackParameters().is_pinned); + + // Set our base priority. + if (base_priority > priority_) { + base_priority = priority_; + + // Perform a priority restoration. + RestorePriority(kernel, this); + } +} + void KThread::RequestSuspend(SuspendType type) { KScopedSchedulerLock sl{kernel}; @@ -871,51 +923,89 @@ Result KThread::GetThreadContext3(std::vector<u8>& out) { R_SUCCEED(); } -void KThread::AddWaiterImpl(KThread* thread) { - ASSERT(kernel.GlobalSchedulerContext().IsLocked()); +void KThread::AddHeldLock(LockWithPriorityInheritanceInfo* lock_info) { + ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel)); + + // Set ourselves as the lock's owner. + lock_info->SetOwner(this); + + // Add the lock to our held list. + held_lock_info_list.push_front(*lock_info); +} + +KThread::LockWithPriorityInheritanceInfo* KThread::FindHeldLock(VAddr address_key_, + bool is_kernel_address_key_) { + ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel)); - // Find the right spot to insert the waiter. - auto it = waiter_list.begin(); - while (it != waiter_list.end()) { - if (it->GetPriority() > thread->GetPriority()) { - break; + // Try to find an existing held lock. + for (auto& held_lock : held_lock_info_list) { + if (held_lock.GetAddressKey() == address_key_ && + held_lock.GetIsKernelAddressKey() == is_kernel_address_key_) { + return std::addressof(held_lock); } - it++; } + return nullptr; +} + +void KThread::AddWaiterImpl(KThread* thread) { + ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel)); + ASSERT(thread->GetConditionVariableTree() == nullptr); + + // Get the thread's address key. + const auto address_key_ = thread->GetAddressKey(); + const auto is_kernel_address_key_ = thread->GetIsKernelAddressKey(); + // Keep track of how many kernel waiters we have. - if (thread->GetAddressKeyIsKernel()) { + if (is_kernel_address_key_) { ASSERT((num_kernel_waiters++) >= 0); KScheduler::SetSchedulerUpdateNeeded(kernel); } - // Insert the waiter. - waiter_list.insert(it, *thread); - thread->SetLockOwner(this); + // Get the relevant lock info. + auto* lock_info = this->FindHeldLock(address_key_, is_kernel_address_key_); + if (lock_info == nullptr) { + // Create a new lock for the address key. + lock_info = + LockWithPriorityInheritanceInfo::Create(kernel, address_key_, is_kernel_address_key_); + + // Add the new lock to our list. + this->AddHeldLock(lock_info); + } + + // Add the thread as waiter to the lock info. + lock_info->AddWaiter(thread); } void KThread::RemoveWaiterImpl(KThread* thread) { - ASSERT(kernel.GlobalSchedulerContext().IsLocked()); + ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel)); // Keep track of how many kernel waiters we have. - if (thread->GetAddressKeyIsKernel()) { + if (thread->GetIsKernelAddressKey()) { ASSERT((num_kernel_waiters--) > 0); KScheduler::SetSchedulerUpdateNeeded(kernel); } + // Get the info for the lock the thread is waiting on. + auto* lock_info = thread->GetWaitingLockInfo(); + ASSERT(lock_info->GetOwner() == this); + // Remove the waiter. - waiter_list.erase(waiter_list.iterator_to(*thread)); - thread->SetLockOwner(nullptr); + if (lock_info->RemoveWaiter(thread)) { + held_lock_info_list.erase(held_lock_info_list.iterator_to(*lock_info)); + LockWithPriorityInheritanceInfo::Free(kernel, lock_info); + } } -void KThread::RestorePriority(KernelCore& kernel_ctx, KThread* thread) { - ASSERT(kernel_ctx.GlobalSchedulerContext().IsLocked()); +void KThread::RestorePriority(KernelCore& kernel, KThread* thread) { + ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel)); - while (true) { + while (thread != nullptr) { // We want to inherit priority where possible. s32 new_priority = thread->GetBasePriority(); - if (thread->HasWaiters()) { - new_priority = std::min(new_priority, thread->waiter_list.front().GetPriority()); + for (const auto& held_lock : thread->held_lock_info_list) { + new_priority = + std::min(new_priority, held_lock.GetHighestPriorityWaiter()->GetPriority()); } // If the priority we would inherit is not different from ours, don't do anything. @@ -923,9 +1013,18 @@ void KThread::RestorePriority(KernelCore& kernel_ctx, KThread* thread) { return; } + // Get the owner of whatever lock this thread is waiting on. + KThread* const lock_owner = thread->GetLockOwner(); + + // If the thread is waiting on some lock, remove it as a waiter to prevent violating red + // black tree invariants. + if (lock_owner != nullptr) { + lock_owner->RemoveWaiterImpl(thread); + } + // Ensure we don't violate condition variable red black tree invariants. if (auto* cv_tree = thread->GetConditionVariableTree(); cv_tree != nullptr) { - BeforeUpdatePriority(kernel_ctx, cv_tree, thread); + BeforeUpdatePriority(kernel, cv_tree, thread); } // Change the priority. @@ -934,73 +1033,99 @@ void KThread::RestorePriority(KernelCore& kernel_ctx, KThread* thread) { // Restore the condition variable, if relevant. if (auto* cv_tree = thread->GetConditionVariableTree(); cv_tree != nullptr) { - AfterUpdatePriority(kernel_ctx, cv_tree, thread); + AfterUpdatePriority(kernel, cv_tree, thread); } - // Update the scheduler. - KScheduler::OnThreadPriorityChanged(kernel_ctx, thread, old_priority); - - // Keep the lock owner up to date. - KThread* lock_owner = thread->GetLockOwner(); - if (lock_owner == nullptr) { - return; + // If we removed the thread from some lock's waiting list, add it back. + if (lock_owner != nullptr) { + lock_owner->AddWaiterImpl(thread); } - // Update the thread in the lock owner's sorted list, and continue inheriting. - lock_owner->RemoveWaiterImpl(thread); - lock_owner->AddWaiterImpl(thread); + // Update the scheduler. + KScheduler::OnThreadPriorityChanged(kernel, thread, old_priority); + + // Continue inheriting priority. thread = lock_owner; } } void KThread::AddWaiter(KThread* thread) { - AddWaiterImpl(thread); - RestorePriority(kernel, this); + this->AddWaiterImpl(thread); + + // If the thread has a higher priority than us, we should inherit. + if (thread->GetPriority() < this->GetPriority()) { + RestorePriority(kernel, this); + } } void KThread::RemoveWaiter(KThread* thread) { - RemoveWaiterImpl(thread); - RestorePriority(kernel, this); + this->RemoveWaiterImpl(thread); + + // If our priority is the same as the thread's (and we've inherited), we may need to restore to + // lower priority. + if (this->GetPriority() == thread->GetPriority() && + this->GetPriority() < this->GetBasePriority()) { + RestorePriority(kernel, this); + } } -KThread* KThread::RemoveWaiterByKey(s32* out_num_waiters, VAddr key) { - ASSERT(kernel.GlobalSchedulerContext().IsLocked()); +KThread* KThread::RemoveWaiterByKey(bool* out_has_waiters, VAddr key, bool is_kernel_address_key_) { + ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel)); - s32 num_waiters{}; - KThread* next_lock_owner{}; - auto it = waiter_list.begin(); - while (it != waiter_list.end()) { - if (it->GetAddressKey() == key) { - KThread* thread = std::addressof(*it); - - // Keep track of how many kernel waiters we have. - if (thread->GetAddressKeyIsKernel()) { - ASSERT((num_kernel_waiters--) > 0); - KScheduler::SetSchedulerUpdateNeeded(kernel); - } - it = waiter_list.erase(it); + // Get the relevant lock info. + auto* lock_info = this->FindHeldLock(key, is_kernel_address_key_); + if (lock_info == nullptr) { + *out_has_waiters = false; + return nullptr; + } - // Update the next lock owner. - if (next_lock_owner == nullptr) { - next_lock_owner = thread; - next_lock_owner->SetLockOwner(nullptr); - } else { - next_lock_owner->AddWaiterImpl(thread); - } - num_waiters++; - } else { - it++; + // Remove the lock info from our held list. + held_lock_info_list.erase(held_lock_info_list.iterator_to(*lock_info)); + + // Keep track of how many kernel waiters we have. + if (lock_info->GetIsKernelAddressKey()) { + num_kernel_waiters -= lock_info->GetWaiterCount(); + ASSERT(num_kernel_waiters >= 0); + KScheduler::SetSchedulerUpdateNeeded(kernel); + } + + ASSERT(lock_info->GetWaiterCount() > 0); + + // Remove the highest priority waiter from the lock to be the next owner. + KThread* next_lock_owner = lock_info->GetHighestPriorityWaiter(); + if (lock_info->RemoveWaiter(next_lock_owner)) { + // The new owner was the only waiter. + *out_has_waiters = false; + + // Free the lock info, since it has no waiters. + LockWithPriorityInheritanceInfo::Free(kernel, lock_info); + } else { + // There are additional waiters on the lock. + *out_has_waiters = true; + + // Add the lock to the new owner's held list. + next_lock_owner->AddHeldLock(lock_info); + + // Keep track of any kernel waiters for the new owner. + if (lock_info->GetIsKernelAddressKey()) { + next_lock_owner->num_kernel_waiters += lock_info->GetWaiterCount(); + ASSERT(next_lock_owner->num_kernel_waiters > 0); + + // NOTE: No need to set scheduler update needed, because we will have already done so + // when removing earlier. } } - // Do priority updates, if we have a next owner. - if (next_lock_owner) { + // If our priority is the same as the next owner's (and we've inherited), we may need to restore + // to lower priority. + if (this->GetPriority() == next_lock_owner->GetPriority() && + this->GetPriority() < this->GetBasePriority()) { RestorePriority(kernel, this); - RestorePriority(kernel, next_lock_owner); + // NOTE: No need to restore priority on the next lock owner, because it was already the + // highest priority waiter on the lock. } - // Return output. - *out_num_waiters = num_waiters; + // Return the next lock owner. return next_lock_owner; } @@ -1117,9 +1242,7 @@ ThreadState KThread::RequestTerminate() { } // Change the thread's priority to be higher than any system thread's. - if (this->GetBasePriority() >= Svc::SystemThreadPriorityHighest) { - this->SetBasePriority(TerminatingThreadPriority); - } + this->IncreaseBasePriority(TerminatingThreadPriority); // If the thread is runnable, send a termination interrupt to other cores. if (this->GetState() == ThreadState::Runnable) { diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h index ca82ce3b6..bd125f5f1 100644 --- a/src/core/hle/kernel/k_thread.h +++ b/src/core/hle/kernel/k_thread.h @@ -339,13 +339,7 @@ public: void SetInterruptFlag(); void ClearInterruptFlag(); - [[nodiscard]] KThread* GetLockOwner() const { - return lock_owner; - } - - void SetLockOwner(KThread* owner) { - lock_owner = owner; - } + KThread* GetLockOwner() const; [[nodiscard]] const KAffinityMask& GetAffinityMask() const { return physical_affinity_mask; @@ -434,6 +428,10 @@ public: VAddr user_stack_top, s32 prio, s32 virt_core, KProcess* owner); + [[nodiscard]] static Result InitializeServiceThread(Core::System& system, KThread* thread, + std::function<void()>&& thread_func, + s32 prio, s32 virt_core, KProcess* owner); + public: struct StackParameters { u8 svc_permission[0x10]; @@ -597,7 +595,13 @@ public: [[nodiscard]] Result GetThreadContext3(std::vector<u8>& out); - [[nodiscard]] KThread* RemoveWaiterByKey(s32* out_num_waiters, VAddr key); + [[nodiscard]] KThread* RemoveUserWaiterByKey(bool* out_has_waiters, VAddr key) { + return this->RemoveWaiterByKey(out_has_waiters, key, false); + } + + [[nodiscard]] KThread* RemoveKernelWaiterByKey(bool* out_has_waiters, VAddr key) { + return this->RemoveWaiterByKey(out_has_waiters, key, true); + } [[nodiscard]] VAddr GetAddressKey() const { return address_key; @@ -607,8 +611,8 @@ public: return address_key_value; } - [[nodiscard]] bool GetAddressKeyIsKernel() const { - return address_key_is_kernel; + [[nodiscard]] bool GetIsKernelAddressKey() const { + return is_kernel_address_key; } //! NB: intentional deviation from official kernel. @@ -617,20 +621,17 @@ public: // to cope with arbitrary host pointers making their way // into things. - void SetUserAddressKey(VAddr key) { - address_key = key; - address_key_is_kernel = false; - } - void SetUserAddressKey(VAddr key, u32 val) { + ASSERT(waiting_lock_info == nullptr); address_key = key; address_key_value = val; - address_key_is_kernel = false; + is_kernel_address_key = false; } void SetKernelAddressKey(VAddr key) { + ASSERT(waiting_lock_info == nullptr); address_key = key; - address_key_is_kernel = true; + is_kernel_address_key = true; } void ClearWaitQueue() { @@ -642,10 +643,6 @@ public: void EndWait(Result wait_result_); void CancelWait(Result wait_result_, bool cancel_timer_task); - [[nodiscard]] bool HasWaiters() const { - return !waiter_list.empty(); - } - [[nodiscard]] s32 GetNumKernelWaiters() const { return num_kernel_waiters; } @@ -675,6 +672,9 @@ public: } private: + [[nodiscard]] KThread* RemoveWaiterByKey(bool* out_has_waiters, VAddr key, + bool is_kernel_address_key); + static constexpr size_t PriorityInheritanceCountMax = 10; union SyncObjectBuffer { std::array<KSynchronizationObject*, Svc::ArgumentHandleCountMax> sync_objects{}; @@ -718,13 +718,14 @@ private: }; void AddWaiterImpl(KThread* thread); - void RemoveWaiterImpl(KThread* thread); + static void RestorePriority(KernelCore& kernel, KThread* thread); void StartTermination(); - void FinishTermination(); + void IncreaseBasePriority(s32 priority); + [[nodiscard]] Result Initialize(KThreadFunction func, uintptr_t arg, VAddr user_stack_top, s32 prio, s32 virt_core, KProcess* owner, ThreadType type); @@ -733,8 +734,6 @@ private: s32 core, KProcess* owner, ThreadType type, std::function<void()>&& init_func); - static void RestorePriority(KernelCore& kernel_ctx, KThread* thread); - // For core KThread implementation ThreadContext32 thread_context_32{}; ThreadContext64 thread_context_64{}; @@ -745,6 +744,127 @@ private: &KThread::condvar_arbiter_tree_node>; using ConditionVariableThreadTree = ConditionVariableThreadTreeTraits::TreeType<ConditionVariableComparator>; + +private: + struct LockWithPriorityInheritanceComparator { + struct RedBlackKeyType { + s32 m_priority; + + constexpr s32 GetPriority() const { + return m_priority; + } + }; + + template <typename T> + requires(std::same_as<T, KThread> || std::same_as<T, RedBlackKeyType>) + static constexpr int Compare(const T& lhs, const KThread& rhs) { + if (lhs.GetPriority() < rhs.GetPriority()) { + // Sort by priority. + return -1; + } else { + return 1; + } + } + }; + static_assert(std::same_as<Common::RedBlackKeyType<LockWithPriorityInheritanceComparator, void>, + LockWithPriorityInheritanceComparator::RedBlackKeyType>); + + using LockWithPriorityInheritanceThreadTreeTraits = + Common::IntrusiveRedBlackTreeMemberTraitsDeferredAssert< + &KThread::condvar_arbiter_tree_node>; + using LockWithPriorityInheritanceThreadTree = + ConditionVariableThreadTreeTraits::TreeType<LockWithPriorityInheritanceComparator>; + +public: + class LockWithPriorityInheritanceInfo : public KSlabAllocated<LockWithPriorityInheritanceInfo>, + public boost::intrusive::list_base_hook<> { + public: + explicit LockWithPriorityInheritanceInfo(KernelCore&) {} + + static LockWithPriorityInheritanceInfo* Create(KernelCore& kernel, VAddr address_key, + bool is_kernel_address_key) { + // Create a new lock info. + auto* new_lock = LockWithPriorityInheritanceInfo::Allocate(kernel); + ASSERT(new_lock != nullptr); + + // Set the new lock's address key. + new_lock->m_address_key = address_key; + new_lock->m_is_kernel_address_key = is_kernel_address_key; + + return new_lock; + } + + void SetOwner(KThread* new_owner) { + // Set new owner. + m_owner = new_owner; + } + + void AddWaiter(KThread* waiter) { + // Insert the waiter. + m_tree.insert(*waiter); + m_waiter_count++; + + waiter->SetWaitingLockInfo(this); + } + + [[nodiscard]] bool RemoveWaiter(KThread* waiter) { + m_tree.erase(m_tree.iterator_to(*waiter)); + + waiter->SetWaitingLockInfo(nullptr); + + return (--m_waiter_count) == 0; + } + + KThread* GetHighestPriorityWaiter() { + return std::addressof(m_tree.front()); + } + const KThread* GetHighestPriorityWaiter() const { + return std::addressof(m_tree.front()); + } + + LockWithPriorityInheritanceThreadTree& GetThreadTree() { + return m_tree; + } + const LockWithPriorityInheritanceThreadTree& GetThreadTree() const { + return m_tree; + } + + VAddr GetAddressKey() const { + return m_address_key; + } + bool GetIsKernelAddressKey() const { + return m_is_kernel_address_key; + } + KThread* GetOwner() const { + return m_owner; + } + u32 GetWaiterCount() const { + return m_waiter_count; + } + + private: + LockWithPriorityInheritanceThreadTree m_tree{}; + VAddr m_address_key{}; + KThread* m_owner{}; + u32 m_waiter_count{}; + bool m_is_kernel_address_key{}; + }; + + void SetWaitingLockInfo(LockWithPriorityInheritanceInfo* lock) { + waiting_lock_info = lock; + } + + LockWithPriorityInheritanceInfo* GetWaitingLockInfo() { + return waiting_lock_info; + } + + void AddHeldLock(LockWithPriorityInheritanceInfo* lock_info); + LockWithPriorityInheritanceInfo* FindHeldLock(VAddr address_key, bool is_kernel_address_key); + +private: + using LockWithPriorityInheritanceInfoList = + boost::intrusive::list<LockWithPriorityInheritanceInfo>; + ConditionVariableThreadTree* condvar_tree{}; u64 condvar_key{}; u64 virtual_affinity_mask{}; @@ -761,9 +881,9 @@ private: s64 last_scheduled_tick{}; std::array<QueueEntry, Core::Hardware::NUM_CPU_CORES> per_core_priority_queue_entry{}; KThreadQueue* wait_queue{}; - WaiterList waiter_list{}; + LockWithPriorityInheritanceInfoList held_lock_info_list{}; + LockWithPriorityInheritanceInfo* waiting_lock_info{}; WaiterList pinned_waiter_list{}; - KThread* lock_owner{}; u32 address_key_value{}; u32 suspend_request_flags{}; u32 suspend_allowed_flags{}; @@ -787,7 +907,7 @@ private: bool debug_attached{}; s8 priority_inheritance_count{}; bool resource_limit_release_hint{}; - bool address_key_is_kernel{}; + bool is_kernel_address_key{}; StackParameters stack_parameters{}; Common::SpinLock context_guard{}; @@ -810,10 +930,12 @@ public: void SetConditionVariable(ConditionVariableThreadTree* tree, VAddr address, u64 cv_key, u32 value) { + ASSERT(waiting_lock_info == nullptr); condvar_tree = tree; condvar_key = cv_key; address_key = address; address_key_value = value; + is_kernel_address_key = false; } void ClearConditionVariable() { @@ -825,6 +947,7 @@ public: } void SetAddressArbiter(ConditionVariableThreadTree* tree, u64 address) { + ASSERT(waiting_lock_info == nullptr); condvar_tree = tree; condvar_key = address; } diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 2ff253183..ef7057ff7 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -34,14 +34,15 @@ #include "core/hle/kernel/k_process.h" #include "core/hle/kernel/k_resource_limit.h" #include "core/hle/kernel/k_scheduler.h" +#include "core/hle/kernel/k_scoped_resource_reservation.h" #include "core/hle/kernel/k_shared_memory.h" #include "core/hle/kernel/k_system_resource.h" #include "core/hle/kernel/k_thread.h" #include "core/hle/kernel/k_worker_task_manager.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/physical_core.h" -#include "core/hle/kernel/service_thread.h" #include "core/hle/result.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/sm/sm.h" #include "core/memory.h" @@ -55,9 +56,7 @@ struct KernelCore::Impl { static constexpr size_t BlockInfoSlabHeapSize = 4000; static constexpr size_t ReservedDynamicPageCount = 64; - explicit Impl(Core::System& system_, KernelCore& kernel_) - : service_threads_manager{1, "ServiceThreadsManager"}, - service_thread_barrier{2}, system{system_} {} + explicit Impl(Core::System& system_, KernelCore& kernel_) : system{system_} {} void SetMulticore(bool is_multi) { is_multicore = is_multi; @@ -98,8 +97,6 @@ struct KernelCore::Impl { InitializeHackSharedMemory(); RegisterHostThread(nullptr); - - default_service_thread = &CreateServiceThread(kernel, "DefaultServiceThread"); } void InitializeCores() { @@ -140,11 +137,6 @@ struct KernelCore::Impl { preemption_event = nullptr; - for (auto& iter : named_ports) { - iter.second->Close(); - } - named_ports.clear(); - exclusive_monitor.reset(); // Cleanup persistent kernel objects @@ -207,8 +199,9 @@ struct KernelCore::Impl { } void CloseServices() { - // Ensures all service threads gracefully shutdown. - ClearServiceThreads(); + // Ensures all servers gracefully shutdown. + std::scoped_lock lk{server_lock}; + server_managers.clear(); } void InitializePhysicalCores() { @@ -761,55 +754,6 @@ struct KernelCore::Impl { "HidBus:SharedMemory"); } - KClientPort* CreateNamedServicePort(std::string name) { - auto search = service_interface_factory.find(name); - if (search == service_interface_factory.end()) { - UNIMPLEMENTED(); - return {}; - } - - return &search->second(system.ServiceManager(), system); - } - - void RegisterNamedServiceHandler(std::string name, KServerPort* server_port) { - auto search = service_interface_handlers.find(name); - if (search == service_interface_handlers.end()) { - return; - } - - search->second(system.ServiceManager(), server_port); - } - - Kernel::ServiceThread& CreateServiceThread(KernelCore& kernel, const std::string& name) { - auto* ptr = new ServiceThread(kernel, name); - - service_threads_manager.QueueWork( - [this, ptr]() { service_threads.emplace(ptr, std::unique_ptr<ServiceThread>(ptr)); }); - - return *ptr; - } - - void ReleaseServiceThread(Kernel::ServiceThread& service_thread) { - auto* ptr = &service_thread; - - if (ptr == default_service_thread) { - // Nothing to do here, the service is using default_service_thread, which will be - // released on shutdown. - return; - } - - service_threads_manager.QueueWork([this, ptr]() { service_threads.erase(ptr); }); - } - - void ClearServiceThreads() { - service_threads_manager.QueueWork([this] { - service_threads.clear(); - default_service_thread = nullptr; - service_thread_barrier.Sync(); - }); - service_thread_barrier.Sync(); - } - std::mutex registered_objects_lock; std::mutex registered_in_use_objects_lock; @@ -839,14 +783,12 @@ struct KernelCore::Impl { std::unique_ptr<KObjectNameGlobalData> object_name_global_data; - /// Map of named ports managed by the kernel, which can be retrieved using - /// the ConnectToPort SVC. - std::unordered_map<std::string, ServiceInterfaceFactory> service_interface_factory; - std::unordered_map<std::string, ServiceInterfaceHandlerFn> service_interface_handlers; - NamedPortTable named_ports; std::unordered_set<KAutoObject*> registered_objects; std::unordered_set<KAutoObject*> registered_in_use_objects; + std::mutex server_lock; + std::vector<std::unique_ptr<Service::ServerManager>> server_managers; + std::unique_ptr<Core::ExclusiveMonitor> exclusive_monitor; std::array<std::unique_ptr<Kernel::PhysicalCore>, Core::Hardware::NUM_CPU_CORES> cores; @@ -881,12 +823,6 @@ struct KernelCore::Impl { // Memory layout std::unique_ptr<KMemoryLayout> memory_layout; - // Threads used for services - std::unordered_map<ServiceThread*, std::unique_ptr<ServiceThread>> service_threads; - ServiceThread* default_service_thread{}; - Common::ThreadWorker service_threads_manager; - Common::Barrier service_thread_barrier; - std::array<KThread*, Core::Hardware::NUM_CPU_CORES> shutdown_threads{}; std::array<std::unique_ptr<Kernel::KScheduler>, Core::Hardware::NUM_CPU_CORES> schedulers{}; @@ -1050,23 +986,6 @@ void KernelCore::PrepareReschedule(std::size_t id) { // TODO: Reimplement, this } -void KernelCore::RegisterNamedService(std::string name, ServiceInterfaceFactory&& factory) { - impl->service_interface_factory.emplace(std::move(name), factory); -} - -void KernelCore::RegisterInterfaceForNamedService(std::string name, - ServiceInterfaceHandlerFn&& handler) { - impl->service_interface_handlers.emplace(std::move(name), handler); -} - -KClientPort* KernelCore::CreateNamedServicePort(std::string name) { - return impl->CreateNamedServicePort(std::move(name)); -} - -void KernelCore::RegisterNamedServiceHandler(std::string name, KServerPort* server_port) { - impl->RegisterNamedServiceHandler(std::move(name), server_port); -} - void KernelCore::RegisterKernelObject(KAutoObject* object) { std::scoped_lock lk{impl->registered_objects_lock}; impl->registered_objects.insert(object); @@ -1087,8 +1006,19 @@ void KernelCore::UnregisterInUseObject(KAutoObject* object) { impl->registered_in_use_objects.erase(object); } -bool KernelCore::IsValidNamedPort(NamedPortTable::const_iterator port) const { - return port != impl->named_ports.cend(); +void KernelCore::RunServer(std::unique_ptr<Service::ServerManager>&& server_manager) { + auto* manager = server_manager.get(); + + { + std::scoped_lock lk{impl->server_lock}; + if (impl->is_shutting_down) { + return; + } + + impl->server_managers.emplace_back(std::move(server_manager)); + } + + manager->LoopProcess(); } u32 KernelCore::CreateNewObjectID() { @@ -1127,6 +1057,87 @@ void KernelCore::RegisterHostThread(KThread* existing_thread) { } } +static std::jthread RunHostThreadFunc(KernelCore& kernel, KProcess* process, + std::string&& thread_name, std::function<void()>&& func) { + // Reserve a new thread from the process resource limit. + KScopedResourceReservation thread_reservation(process, LimitableResource::ThreadCountMax); + ASSERT(thread_reservation.Succeeded()); + + // Initialize the thread. + KThread* thread = KThread::Create(kernel); + ASSERT(R_SUCCEEDED(KThread::InitializeDummyThread(thread, process))); + + // Commit the thread reservation. + thread_reservation.Commit(); + + return std::jthread( + [&kernel, thread, thread_name{std::move(thread_name)}, func{std::move(func)}] { + // Set the thread name. + Common::SetCurrentThreadName(thread_name.c_str()); + + // Register the thread. + kernel.RegisterHostThread(thread); + + // Run the callback. + func(); + + // Close the thread. + // This will free the process if it is the last reference. + thread->Close(); + }); +} + +std::jthread KernelCore::RunOnHostCoreProcess(std::string&& process_name, + std::function<void()> func) { + // Make a new process. + KProcess* process = KProcess::Create(*this); + ASSERT(R_SUCCEEDED(KProcess::Initialize(process, System(), "", KProcess::ProcessType::Userland, + GetSystemResourceLimit()))); + + // Ensure that we don't hold onto any extra references. + SCOPE_EXIT({ process->Close(); }); + + // Run the host thread. + return RunHostThreadFunc(*this, process, std::move(process_name), std::move(func)); +} + +std::jthread KernelCore::RunOnHostCoreThread(std::string&& thread_name, + std::function<void()> func) { + // Get the current process. + KProcess* process = GetCurrentProcessPointer(*this); + + // Run the host thread. + return RunHostThreadFunc(*this, process, std::move(thread_name), std::move(func)); +} + +void KernelCore::RunOnGuestCoreProcess(std::string&& process_name, std::function<void()> func) { + constexpr s32 ServiceThreadPriority = 16; + constexpr s32 ServiceThreadCore = 3; + + // Make a new process. + KProcess* process = KProcess::Create(*this); + ASSERT(R_SUCCEEDED(KProcess::Initialize(process, System(), "", KProcess::ProcessType::Userland, + GetSystemResourceLimit()))); + + // Ensure that we don't hold onto any extra references. + SCOPE_EXIT({ process->Close(); }); + + // Reserve a new thread from the process resource limit. + KScopedResourceReservation thread_reservation(process, LimitableResource::ThreadCountMax); + ASSERT(thread_reservation.Succeeded()); + + // Initialize the thread. + KThread* thread = KThread::Create(*this); + ASSERT(R_SUCCEEDED(KThread::InitializeServiceThread( + System(), thread, std::move(func), ServiceThreadPriority, ServiceThreadCore, process))); + + // Commit the thread reservation. + thread_reservation.Commit(); + + // Begin running the thread. + ASSERT(R_SUCCEEDED(thread->Run())); +} + u32 KernelCore::GetCurrentHostThreadID() const { return impl->GetCurrentHostThreadID(); } @@ -1271,18 +1282,6 @@ void KernelCore::ExitSVCProfile() { MicroProfileLeave(MICROPROFILE_TOKEN(Kernel_SVC), impl->svc_ticks[CurrentPhysicalCoreIndex()]); } -Kernel::ServiceThread& KernelCore::CreateServiceThread(const std::string& name) { - return impl->CreateServiceThread(*this, name); -} - -Kernel::ServiceThread& KernelCore::GetDefaultServiceThread() const { - return *impl->default_service_thread; -} - -void KernelCore::ReleaseServiceThread(Kernel::ServiceThread& service_thread) { - impl->ReleaseServiceThread(service_thread); -} - Init::KSlabResourceCounts& KernelCore::SlabResourceCounts() { return impl->slab_resource_counts; } @@ -1319,4 +1318,97 @@ const Core::System& KernelCore::System() const { return impl->system; } +struct KernelCore::SlabHeapContainer { + KSlabHeap<KClientSession> client_session; + KSlabHeap<KEvent> event; + KSlabHeap<KLinkedListNode> linked_list_node; + KSlabHeap<KPort> port; + KSlabHeap<KProcess> process; + KSlabHeap<KResourceLimit> resource_limit; + KSlabHeap<KSession> session; + KSlabHeap<KSharedMemory> shared_memory; + KSlabHeap<KSharedMemoryInfo> shared_memory_info; + KSlabHeap<KThread> thread; + KSlabHeap<KTransferMemory> transfer_memory; + KSlabHeap<KCodeMemory> code_memory; + KSlabHeap<KDeviceAddressSpace> device_address_space; + KSlabHeap<KPageBuffer> page_buffer; + KSlabHeap<KThreadLocalPage> thread_local_page; + KSlabHeap<KObjectName> object_name; + KSlabHeap<KSessionRequest> session_request; + KSlabHeap<KSecureSystemResource> secure_system_resource; + KSlabHeap<KThread::LockWithPriorityInheritanceInfo> lock_info; + KSlabHeap<KEventInfo> event_info; + KSlabHeap<KDebug> debug; +}; + +template <typename T> +KSlabHeap<T>& KernelCore::SlabHeap() { + if constexpr (std::is_same_v<T, KClientSession>) { + return slab_heap_container->client_session; + } else if constexpr (std::is_same_v<T, KEvent>) { + return slab_heap_container->event; + } else if constexpr (std::is_same_v<T, KLinkedListNode>) { + return slab_heap_container->linked_list_node; + } else if constexpr (std::is_same_v<T, KPort>) { + return slab_heap_container->port; + } else if constexpr (std::is_same_v<T, KProcess>) { + return slab_heap_container->process; + } else if constexpr (std::is_same_v<T, KResourceLimit>) { + return slab_heap_container->resource_limit; + } else if constexpr (std::is_same_v<T, KSession>) { + return slab_heap_container->session; + } else if constexpr (std::is_same_v<T, KSharedMemory>) { + return slab_heap_container->shared_memory; + } else if constexpr (std::is_same_v<T, KSharedMemoryInfo>) { + return slab_heap_container->shared_memory_info; + } else if constexpr (std::is_same_v<T, KThread>) { + return slab_heap_container->thread; + } else if constexpr (std::is_same_v<T, KTransferMemory>) { + return slab_heap_container->transfer_memory; + } else if constexpr (std::is_same_v<T, KCodeMemory>) { + return slab_heap_container->code_memory; + } else if constexpr (std::is_same_v<T, KDeviceAddressSpace>) { + return slab_heap_container->device_address_space; + } else if constexpr (std::is_same_v<T, KPageBuffer>) { + return slab_heap_container->page_buffer; + } else if constexpr (std::is_same_v<T, KThreadLocalPage>) { + return slab_heap_container->thread_local_page; + } else if constexpr (std::is_same_v<T, KObjectName>) { + return slab_heap_container->object_name; + } else if constexpr (std::is_same_v<T, KSessionRequest>) { + return slab_heap_container->session_request; + } else if constexpr (std::is_same_v<T, KSecureSystemResource>) { + return slab_heap_container->secure_system_resource; + } else if constexpr (std::is_same_v<T, KThread::LockWithPriorityInheritanceInfo>) { + return slab_heap_container->lock_info; + } else if constexpr (std::is_same_v<T, KEventInfo>) { + return slab_heap_container->event_info; + } else if constexpr (std::is_same_v<T, KDebug>) { + return slab_heap_container->debug; + } +} + +template KSlabHeap<KClientSession>& KernelCore::SlabHeap(); +template KSlabHeap<KEvent>& KernelCore::SlabHeap(); +template KSlabHeap<KLinkedListNode>& KernelCore::SlabHeap(); +template KSlabHeap<KPort>& KernelCore::SlabHeap(); +template KSlabHeap<KProcess>& KernelCore::SlabHeap(); +template KSlabHeap<KResourceLimit>& KernelCore::SlabHeap(); +template KSlabHeap<KSession>& KernelCore::SlabHeap(); +template KSlabHeap<KSharedMemory>& KernelCore::SlabHeap(); +template KSlabHeap<KSharedMemoryInfo>& KernelCore::SlabHeap(); +template KSlabHeap<KThread>& KernelCore::SlabHeap(); +template KSlabHeap<KTransferMemory>& KernelCore::SlabHeap(); +template KSlabHeap<KCodeMemory>& KernelCore::SlabHeap(); +template KSlabHeap<KDeviceAddressSpace>& KernelCore::SlabHeap(); +template KSlabHeap<KPageBuffer>& KernelCore::SlabHeap(); +template KSlabHeap<KThreadLocalPage>& KernelCore::SlabHeap(); +template KSlabHeap<KObjectName>& KernelCore::SlabHeap(); +template KSlabHeap<KSessionRequest>& KernelCore::SlabHeap(); +template KSlabHeap<KSecureSystemResource>& KernelCore::SlabHeap(); +template KSlabHeap<KThread::LockWithPriorityInheritanceInfo>& KernelCore::SlabHeap(); +template KSlabHeap<KEventInfo>& KernelCore::SlabHeap(); +template KSlabHeap<KDebug>& KernelCore::SlabHeap(); + } // namespace Kernel diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 6e0668f7f..1b380a07b 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -9,6 +9,8 @@ #include <string> #include <unordered_map> #include <vector> + +#include "common/polyfill_thread.h" #include "core/hardware_properties.h" #include "core/hle/kernel/k_auto_object.h" #include "core/hle/kernel/k_slab_heap.h" @@ -24,6 +26,10 @@ class CoreTiming; struct EventType; } // namespace Core::Timing +namespace Service { +class ServerManager; +} + namespace Service::SM { class ServiceManager; } @@ -65,13 +71,6 @@ class KTransferMemory; class KWorkerTaskManager; class KCodeMemory; class PhysicalCore; -class ServiceThread; -class Synchronization; - -using ServiceInterfaceFactory = - std::function<KClientPort&(Service::SM::ServiceManager&, Core::System&)>; - -using ServiceInterfaceHandlerFn = std::function<void(Service::SM::ServiceManager&, KServerPort*)>; namespace Init { struct KSlabResourceCounts; @@ -80,15 +79,8 @@ struct KSlabResourceCounts; template <typename T> class KSlabHeap; -using EmuThreadHandle = uintptr_t; -constexpr EmuThreadHandle EmuThreadHandleInvalid{}; -constexpr EmuThreadHandle EmuThreadHandleReserved{1ULL << 63}; - /// Represents a single instance of the kernel. class KernelCore { -private: - using NamedPortTable = std::unordered_map<std::string, KClientPort*>; - public: /// Constructs an instance of the kernel using the given System /// instance as a context for any necessary system-related state, @@ -196,18 +188,6 @@ public: void InvalidateCpuInstructionCacheRange(VAddr addr, std::size_t size); - /// Registers a named HLE service, passing a factory used to open a port to that service. - void RegisterNamedService(std::string name, ServiceInterfaceFactory&& factory); - - /// Registers a setup function for the named HLE service. - void RegisterInterfaceForNamedService(std::string name, ServiceInterfaceHandlerFn&& handler); - - /// Opens a port to a service previously registered with RegisterNamedService. - KClientPort* CreateNamedServicePort(std::string name); - - /// Accepts a session on a port created by CreateNamedServicePort. - void RegisterNamedServiceHandler(std::string name, KServerPort* server_port); - /// Registers all kernel objects with the global emulation state, this is purely for tracking /// leaks after emulation has been shutdown. void RegisterKernelObject(KAutoObject* object); @@ -224,8 +204,8 @@ public: /// destroyed during the current emulation session. void UnregisterInUseObject(KAutoObject* object); - /// Determines whether or not the given port is a valid named port. - bool IsValidNamedPort(NamedPortTable::const_iterator port) const; + // Runs the given server manager until shutdown. + void RunServer(std::unique_ptr<Service::ServerManager>&& server_manager); /// Gets the current host_thread/guest_thread pointer. KThread* GetCurrentEmuThread() const; @@ -242,6 +222,12 @@ public: /// Register the current thread as a non CPU core thread. void RegisterHostThread(KThread* existing_thread = nullptr); + void RunOnGuestCoreProcess(std::string&& process_name, std::function<void()> func); + + std::jthread RunOnHostCoreProcess(std::string&& process_name, std::function<void()> func); + + std::jthread RunOnHostCoreThread(std::string&& thread_name, std::function<void()> func); + /// Gets global data for KObjectName. KObjectNameGlobalData& ObjectNameGlobalData(); @@ -310,33 +296,6 @@ public: void ExitSVCProfile(); - /** - * Creates a host thread to execute HLE service requests, which are used to execute service - * routines asynchronously. While these are allocated per ServerSession, these need to be owned - * and managed outside of ServerSession to avoid a circular dependency. In general, most - * services can just use the default service thread, and not need their own host service thread. - * See GetDefaultServiceThread. - * @param name String name for the ServerSession creating this thread, used for debug - * purposes. - * @returns A reference to the newly created service thread. - */ - Kernel::ServiceThread& CreateServiceThread(const std::string& name); - - /** - * Gets the default host service thread, which executes HLE service requests. Unless service - * requests need to block on the host, the default service thread should be used in favor of - * creating a new service thread. - * @returns A reference to the default service thread. - */ - Kernel::ServiceThread& GetDefaultServiceThread() const; - - /** - * Releases a HLE service thread, instructing KernelCore to free it. This should be called when - * the ServerSession associated with the thread is destroyed. - * @param service_thread Service thread to release. - */ - void ReleaseServiceThread(Kernel::ServiceThread& service_thread); - /// Workaround for single-core mode when preempting threads while idle. bool IsPhantomModeForSingleCore() const; void SetIsPhantomModeForSingleCore(bool value); @@ -346,49 +305,7 @@ public: /// Gets the slab heap for the specified kernel object type. template <typename T> - KSlabHeap<T>& SlabHeap() { - if constexpr (std::is_same_v<T, KClientSession>) { - return slab_heap_container->client_session; - } else if constexpr (std::is_same_v<T, KEvent>) { - return slab_heap_container->event; - } else if constexpr (std::is_same_v<T, KLinkedListNode>) { - return slab_heap_container->linked_list_node; - } else if constexpr (std::is_same_v<T, KPort>) { - return slab_heap_container->port; - } else if constexpr (std::is_same_v<T, KProcess>) { - return slab_heap_container->process; - } else if constexpr (std::is_same_v<T, KResourceLimit>) { - return slab_heap_container->resource_limit; - } else if constexpr (std::is_same_v<T, KSession>) { - return slab_heap_container->session; - } else if constexpr (std::is_same_v<T, KSharedMemory>) { - return slab_heap_container->shared_memory; - } else if constexpr (std::is_same_v<T, KSharedMemoryInfo>) { - return slab_heap_container->shared_memory_info; - } else if constexpr (std::is_same_v<T, KThread>) { - return slab_heap_container->thread; - } else if constexpr (std::is_same_v<T, KTransferMemory>) { - return slab_heap_container->transfer_memory; - } else if constexpr (std::is_same_v<T, KCodeMemory>) { - return slab_heap_container->code_memory; - } else if constexpr (std::is_same_v<T, KDeviceAddressSpace>) { - return slab_heap_container->device_address_space; - } else if constexpr (std::is_same_v<T, KPageBuffer>) { - return slab_heap_container->page_buffer; - } else if constexpr (std::is_same_v<T, KThreadLocalPage>) { - return slab_heap_container->thread_local_page; - } else if constexpr (std::is_same_v<T, KObjectName>) { - return slab_heap_container->object_name; - } else if constexpr (std::is_same_v<T, KSessionRequest>) { - return slab_heap_container->session_request; - } else if constexpr (std::is_same_v<T, KSecureSystemResource>) { - return slab_heap_container->secure_system_resource; - } else if constexpr (std::is_same_v<T, KEventInfo>) { - return slab_heap_container->event_info; - } else if constexpr (std::is_same_v<T, KDebug>) { - return slab_heap_container->debug; - } - } + KSlabHeap<T>& SlabHeap(); /// Gets the current slab resource counts. Init::KSlabResourceCounts& SlabResourceCounts(); @@ -434,28 +351,7 @@ private: private: /// Helper to encapsulate all slab heaps in a single heap allocated container - struct SlabHeapContainer { - KSlabHeap<KClientSession> client_session; - KSlabHeap<KEvent> event; - KSlabHeap<KLinkedListNode> linked_list_node; - KSlabHeap<KPort> port; - KSlabHeap<KProcess> process; - KSlabHeap<KResourceLimit> resource_limit; - KSlabHeap<KSession> session; - KSlabHeap<KSharedMemory> shared_memory; - KSlabHeap<KSharedMemoryInfo> shared_memory_info; - KSlabHeap<KThread> thread; - KSlabHeap<KTransferMemory> transfer_memory; - KSlabHeap<KCodeMemory> code_memory; - KSlabHeap<KDeviceAddressSpace> device_address_space; - KSlabHeap<KPageBuffer> page_buffer; - KSlabHeap<KThreadLocalPage> thread_local_page; - KSlabHeap<KObjectName> object_name; - KSlabHeap<KSessionRequest> session_request; - KSlabHeap<KSecureSystemResource> secure_system_resource; - KSlabHeap<KEventInfo> event_info; - KSlabHeap<KDebug> debug; - }; + struct SlabHeapContainer; std::unique_ptr<SlabHeapContainer> slab_heap_container; }; diff --git a/src/core/hle/kernel/service_thread.cpp b/src/core/hle/kernel/service_thread.cpp deleted file mode 100644 index 38afa720b..000000000 --- a/src/core/hle/kernel/service_thread.cpp +++ /dev/null @@ -1,206 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include <functional> -#include <map> -#include <mutex> -#include <thread> -#include <vector> - -#include "common/polyfill_thread.h" -#include "common/scope_exit.h" -#include "common/thread.h" -#include "core/hle/ipc_helpers.h" -#include "core/hle/kernel/hle_ipc.h" -#include "core/hle/kernel/k_event.h" -#include "core/hle/kernel/k_scoped_resource_reservation.h" -#include "core/hle/kernel/k_session.h" -#include "core/hle/kernel/k_thread.h" -#include "core/hle/kernel/kernel.h" -#include "core/hle/kernel/service_thread.h" - -namespace Kernel { - -class ServiceThread::Impl final { -public: - explicit Impl(KernelCore& kernel, const std::string& service_name); - ~Impl(); - - void WaitAndProcessImpl(); - void SessionClosed(KServerSession* server_session, - std::shared_ptr<SessionRequestManager> manager); - void LoopProcess(); - - void RegisterServerSession(KServerSession* session, - std::shared_ptr<SessionRequestManager> manager); - -private: - KernelCore& kernel; - const std::string m_service_name; - - std::jthread m_host_thread{}; - std::mutex m_session_mutex{}; - std::map<KServerSession*, std::shared_ptr<SessionRequestManager>> m_sessions{}; - KEvent* m_wakeup_event{}; - KThread* m_thread{}; - std::atomic<bool> m_shutdown_requested{}; -}; - -void ServiceThread::Impl::WaitAndProcessImpl() { - // Create local list of waitable sessions. - std::vector<KSynchronizationObject*> objs; - std::vector<std::shared_ptr<SessionRequestManager>> managers; - - { - // Lock to get the set. - std::scoped_lock lk{m_session_mutex}; - - // Reserve the needed quantity. - objs.reserve(m_sessions.size() + 1); - managers.reserve(m_sessions.size()); - - // Copy to our local list. - for (const auto& [session, manager] : m_sessions) { - objs.push_back(session); - managers.push_back(manager); - } - - // Insert the wakeup event at the end. - objs.push_back(&m_wakeup_event->GetReadableEvent()); - } - - // Wait on the list of sessions. - s32 index{-1}; - Result rc = KSynchronizationObject::Wait(kernel, &index, objs.data(), - static_cast<s32>(objs.size()), -1); - ASSERT(!rc.IsFailure()); - - // If this was the wakeup event, clear it and finish. - if (index >= static_cast<s64>(objs.size() - 1)) { - m_wakeup_event->Clear(); - return; - } - - // This event is from a server session. - auto* server_session = static_cast<KServerSession*>(objs[index]); - auto& manager = managers[index]; - - // Fetch the HLE request context. - std::shared_ptr<HLERequestContext> context; - rc = server_session->ReceiveRequest(&context, manager); - - // If the session was closed, handle that. - if (rc == ResultSessionClosed) { - SessionClosed(server_session, manager); - - // Finish. - return; - } - - // TODO: handle other cases - ASSERT(rc == ResultSuccess); - - // Perform the request. - Result service_rc = manager->CompleteSyncRequest(server_session, *context); - - // Reply to the client. - rc = server_session->SendReplyHLE(); - - if (rc == ResultSessionClosed || service_rc == IPC::ERR_REMOTE_PROCESS_DEAD) { - SessionClosed(server_session, manager); - return; - } - - // TODO: handle other cases - ASSERT(rc == ResultSuccess); - ASSERT(service_rc == ResultSuccess); -} - -void ServiceThread::Impl::SessionClosed(KServerSession* server_session, - std::shared_ptr<SessionRequestManager> manager) { - { - // Lock to get the set. - std::scoped_lock lk{m_session_mutex}; - - // Erase the session. - ASSERT(m_sessions.erase(server_session) == 1); - } - - // Close our reference to the server session. - server_session->Close(); -} - -void ServiceThread::Impl::LoopProcess() { - Common::SetCurrentThreadName(m_service_name.c_str()); - - kernel.RegisterHostThread(m_thread); - - while (!m_shutdown_requested.load()) { - WaitAndProcessImpl(); - } -} - -void ServiceThread::Impl::RegisterServerSession(KServerSession* server_session, - std::shared_ptr<SessionRequestManager> manager) { - // Open the server session. - server_session->Open(); - - { - // Lock to get the set. - std::scoped_lock lk{m_session_mutex}; - - // Insert the session and manager. - m_sessions[server_session] = manager; - } - - // Signal the wakeup event. - m_wakeup_event->Signal(); -} - -ServiceThread::Impl::~Impl() { - // Shut down the processing thread. - m_shutdown_requested.store(true); - m_wakeup_event->Signal(); - m_host_thread.join(); - - // Close all remaining sessions. - for (const auto& [server_session, manager] : m_sessions) { - server_session->Close(); - } - - // Destroy remaining managers. - m_sessions.clear(); - - // Close event. - m_wakeup_event->GetReadableEvent().Close(); - m_wakeup_event->Close(); - - // Close thread. - m_thread->Close(); -} - -ServiceThread::Impl::Impl(KernelCore& kernel_, const std::string& service_name) - : kernel{kernel_}, m_service_name{service_name} { - // Initialize event. - m_wakeup_event = KEvent::Create(kernel); - m_wakeup_event->Initialize(nullptr); - - // Initialize thread. - m_thread = KThread::Create(kernel); - ASSERT(KThread::InitializeDummyThread(m_thread, nullptr).IsSuccess()); - - // Start thread. - m_host_thread = std::jthread([this] { LoopProcess(); }); -} - -ServiceThread::ServiceThread(KernelCore& kernel, const std::string& name) - : impl{std::make_unique<Impl>(kernel, name)} {} - -ServiceThread::~ServiceThread() = default; - -void ServiceThread::RegisterServerSession(KServerSession* session, - std::shared_ptr<SessionRequestManager> manager) { - impl->RegisterServerSession(session, manager); -} - -} // namespace Kernel diff --git a/src/core/hle/kernel/service_thread.h b/src/core/hle/kernel/service_thread.h deleted file mode 100644 index fb4325531..000000000 --- a/src/core/hle/kernel/service_thread.h +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include <memory> -#include <string> - -namespace Kernel { - -class HLERequestContext; -class KernelCore; -class KSession; -class SessionRequestManager; - -class ServiceThread final { -public: - explicit ServiceThread(KernelCore& kernel, const std::string& name); - ~ServiceThread(); - - void RegisterServerSession(KServerSession* session, - std::shared_ptr<SessionRequestManager> manager); - -private: - class Impl; - std::unique_ptr<Impl> impl; -}; - -} // namespace Kernel diff --git a/src/core/hle/kernel/svc/svc_info.cpp b/src/core/hle/kernel/svc/svc_info.cpp index 58dc47508..cbed4dc8c 100644 --- a/src/core/hle/kernel/svc/svc_info.cpp +++ b/src/core/hle/kernel/svc/svc_info.cpp @@ -126,6 +126,11 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle *result = process->GetTotalPhysicalMemoryUsedWithoutSystemResource(); return ResultSuccess; + case InfoType::IsApplication: + LOG_WARNING(Kernel_SVC, "(STUBBED) Assuming process is application"); + *result = true; + return ResultSuccess; + case InfoType::FreeThreadCount: *result = process->GetFreeThreadCount(); return ResultSuccess; diff --git a/src/core/hle/kernel/svc/svc_port.cpp b/src/core/hle/kernel/svc/svc_port.cpp index 0b5b4ba2b..78c2a8d17 100644 --- a/src/core/hle/kernel/svc/svc_port.cpp +++ b/src/core/hle/kernel/svc/svc_port.cpp @@ -12,56 +12,40 @@ namespace Kernel::Svc { -/// Connect to an OS service given the port name, returns the handle to the port to out -Result ConnectToNamedPort(Core::System& system, Handle* out, VAddr port_name_address) { - auto& memory = system.Memory(); - if (!memory.IsValidVirtualAddress(port_name_address)) { - LOG_ERROR(Kernel_SVC, - "Port Name Address is not a valid virtual address, port_name_address=0x{:016X}", - port_name_address); - return ResultNotFound; - } +Result ConnectToNamedPort(Core::System& system, Handle* out, VAddr user_name) { + // Copy the provided name from user memory to kernel memory. + auto string_name = system.Memory().ReadCString(user_name, KObjectName::NameLengthMax); - static constexpr std::size_t PortNameMaxLength = 11; - // Read 1 char beyond the max allowed port name to detect names that are too long. - const std::string port_name = memory.ReadCString(port_name_address, PortNameMaxLength + 1); - if (port_name.size() > PortNameMaxLength) { - LOG_ERROR(Kernel_SVC, "Port name is too long, expected {} but got {}", PortNameMaxLength, - port_name.size()); - return ResultOutOfRange; - } + std::array<char, KObjectName::NameLengthMax> name{}; + std::strncpy(name.data(), string_name.c_str(), KObjectName::NameLengthMax - 1); - LOG_TRACE(Kernel_SVC, "called port_name={}", port_name); + // Validate that the name is valid. + R_UNLESS(name[sizeof(name) - 1] == '\x00', ResultOutOfRange); // Get the current handle table. - auto& kernel = system.Kernel(); - auto& handle_table = GetCurrentProcess(kernel).GetHandleTable(); + auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable(); // Find the client port. - auto port = kernel.CreateNamedServicePort(port_name); - if (!port) { - LOG_ERROR(Kernel_SVC, "tried to connect to unknown port: {}", port_name); - return ResultNotFound; - } + auto port = KObjectName::Find<KClientPort>(system.Kernel(), name.data()); + R_UNLESS(port.IsNotNull(), ResultNotFound); // Reserve a handle for the port. // NOTE: Nintendo really does write directly to the output handle here. R_TRY(handle_table.Reserve(out)); - auto handle_guard = SCOPE_GUARD({ handle_table.Unreserve(*out); }); + ON_RESULT_FAILURE { + handle_table.Unreserve(*out); + }; // Create a session. - KClientSession* session{}; + KClientSession* session; R_TRY(port->CreateSession(std::addressof(session))); - kernel.RegisterNamedServiceHandler(port_name, &port->GetParent()->GetServerPort()); - // Register the session in the table, close the extra reference. handle_table.Register(*out, session); session->Close(); // We succeeded. - handle_guard.Cancel(); - return ResultSuccess; + R_SUCCEED(); } Result CreatePort(Core::System& system, Handle* out_server, Handle* out_client, @@ -78,8 +62,11 @@ Result ConnectToPort(Core::System& system, Handle* out_handle, Handle port) { 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 = system.Memory().ReadCString(user_name, KObjectName::NameLengthMax); + + // Copy the provided name from user memory to kernel memory. std::array<char, KObjectName::NameLengthMax> name{}; - system.Memory().ReadBlock(user_name, name.data(), sizeof(name)); + std::strncpy(name.data(), string_name.c_str(), KObjectName::NameLengthMax - 1); // Validate that sessions and name are valid. R_UNLESS(max_sessions >= 0, ResultOutOfRange); diff --git a/src/core/hle/kernel/svc/svc_synchronization.cpp b/src/core/hle/kernel/svc/svc_synchronization.cpp index 1a8f7e191..9e7bf9530 100644 --- a/src/core/hle/kernel/svc/svc_synchronization.cpp +++ b/src/core/hle/kernel/svc/svc_synchronization.cpp @@ -48,19 +48,15 @@ Result ResetSignal(Core::System& system, Handle handle) { return ResultInvalidHandle; } -/// Wait for the given handles to synchronize, timeout after the specified nanoseconds -Result WaitSynchronization(Core::System& system, s32* index, VAddr handles_address, s32 num_handles, - s64 nano_seconds) { - LOG_TRACE(Kernel_SVC, "called handles_address=0x{:X}, num_handles={}, nano_seconds={}", - handles_address, num_handles, nano_seconds); - +static Result WaitSynchronization(Core::System& system, int32_t* out_index, const Handle* handles, + int32_t num_handles, int64_t timeout_ns) { // Ensure number of handles is valid. - R_UNLESS(0 <= num_handles && num_handles <= ArgumentHandleCountMax, ResultOutOfRange); + R_UNLESS(0 <= num_handles && num_handles <= Svc::ArgumentHandleCountMax, ResultOutOfRange); + // Get the synchronization context. auto& kernel = system.Kernel(); + auto& handle_table = GetCurrentProcess(kernel).GetHandleTable(); std::vector<KSynchronizationObject*> objs(num_handles); - const auto& handle_table = GetCurrentProcess(kernel).GetHandleTable(); - Handle* handles = system.Memory().GetPointer<Handle>(handles_address); // Copy user handles. if (num_handles > 0) { @@ -68,21 +64,38 @@ Result WaitSynchronization(Core::System& system, s32* index, VAddr handles_addre R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(objs.data(), handles, num_handles), ResultInvalidHandle); - for (const auto& obj : objs) { - kernel.RegisterInUseObject(obj); - } } // Ensure handles are closed when we're done. SCOPE_EXIT({ - for (s32 i = 0; i < num_handles; ++i) { - kernel.UnregisterInUseObject(objs[i]); + for (auto i = 0; i < num_handles; ++i) { objs[i]->Close(); } }); - return KSynchronizationObject::Wait(kernel, index, objs.data(), static_cast<s32>(objs.size()), - nano_seconds); + // Wait on the objects. + Result res = KSynchronizationObject::Wait(kernel, out_index, objs.data(), + static_cast<s32>(objs.size()), timeout_ns); + + R_SUCCEED_IF(res == ResultSessionClosed); + R_RETURN(res); +} + +/// Wait for the given handles to synchronize, timeout after the specified nanoseconds +Result WaitSynchronization(Core::System& system, int32_t* out_index, VAddr user_handles, + int32_t num_handles, int64_t timeout_ns) { + LOG_TRACE(Kernel_SVC, "called user_handles={:#x}, num_handles={}, timeout_ns={}", user_handles, + num_handles, timeout_ns); + + // Ensure number of handles is valid. + R_UNLESS(0 <= num_handles && num_handles <= Svc::ArgumentHandleCountMax, ResultOutOfRange); + + std::vector<Handle> handles(num_handles); + if (num_handles > 0) { + system.Memory().ReadBlock(user_handles, handles.data(), num_handles * sizeof(Handle)); + } + + R_RETURN(WaitSynchronization(system, out_index, handles.data(), num_handles, timeout_ns)); } /// Resumes a thread waiting on WaitSynchronization diff --git a/src/core/hle/kernel/svc_types.h b/src/core/hle/kernel/svc_types.h index 542c13461..39355d9c4 100644 --- a/src/core/hle/kernel/svc_types.h +++ b/src/core/hle/kernel/svc_types.h @@ -151,6 +151,7 @@ enum class InfoType : u32 { FreeThreadCount = 24, ThreadTickCount = 25, IsSvcPermitted = 26, + IoRegionHint = 27, MesosphereMeta = 65000, MesosphereCurrentProcess = 65001, diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 1241fcdff..120282aa4 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp @@ -15,7 +15,6 @@ #include "core/core_timing.h" #include "core/file_sys/control_metadata.h" #include "core/file_sys/patch_manager.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/acc/acc.h" #include "core/hle/service/acc/acc_aa.h" #include "core/hle/service/acc/acc_su.h" @@ -25,16 +24,12 @@ #include "core/hle/service/acc/errors.h" #include "core/hle/service/acc/profile_manager.h" #include "core/hle/service/glue/glue_manager.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/loader/loader.h" namespace Service::Account { -constexpr Result ERR_INVALID_USER_ID{ErrorModule::Account, 20}; -constexpr Result ERR_INVALID_APPLICATION_ID{ErrorModule::Account, 22}; -constexpr Result ERR_INVALID_BUFFER{ErrorModule::Account, 30}; -constexpr Result ERR_INVALID_BUFFER_SIZE{ErrorModule::Account, 31}; -constexpr Result ERR_FAILED_SAVE_DATA{ErrorModule::Account, 100}; - // Thumbnails are hard coded to be at least this size constexpr std::size_t THUMBNAIL_SIZE = 0x24000; @@ -294,7 +289,7 @@ public: } protected: - void Get(Kernel::HLERequestContext& ctx) { + void Get(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.RawString()); ProfileBase profile_base{}; UserData data{}; @@ -311,7 +306,7 @@ protected: } } - void GetBase(Kernel::HLERequestContext& ctx) { + void GetBase(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.RawString()); ProfileBase profile_base{}; if (profile_manager.GetProfileBase(user_id, profile_base)) { @@ -325,7 +320,7 @@ protected: } } - void LoadImage(Kernel::HLERequestContext& ctx) { + void LoadImage(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -352,7 +347,7 @@ protected: rb.Push<u32>(size); } - void GetImageSize(Kernel::HLERequestContext& ctx) { + void GetImageSize(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); @@ -369,7 +364,7 @@ protected: } } - void Store(Kernel::HLERequestContext& ctx) { + void Store(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto base = rp.PopRaw<ProfileBase>(); @@ -383,7 +378,7 @@ protected: if (user_data.size() < sizeof(UserData)) { LOG_ERROR(Service_ACC, "UserData buffer too small!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_INVALID_BUFFER); + rb.Push(Account::ResultInvalidArrayLength); return; } @@ -393,7 +388,7 @@ protected: if (!profile_manager.SetProfileBaseAndData(user_id, base, data)) { LOG_ERROR(Service_ACC, "Failed to update user data and base!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_FAILED_SAVE_DATA); + rb.Push(Account::ResultAccountUpdateFailed); return; } @@ -401,7 +396,7 @@ protected: rb.Push(ResultSuccess); } - void StoreWithImage(Kernel::HLERequestContext& ctx) { + void StoreWithImage(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto base = rp.PopRaw<ProfileBase>(); @@ -416,7 +411,7 @@ protected: if (user_data.size() < sizeof(UserData)) { LOG_ERROR(Service_ACC, "UserData buffer too small!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_INVALID_BUFFER); + rb.Push(Account::ResultInvalidArrayLength); return; } @@ -431,7 +426,7 @@ protected: !profile_manager.SetProfileBaseAndData(user_id, base, data)) { LOG_ERROR(Service_ACC, "Failed to update profile data, base, and image!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_FAILED_SAVE_DATA); + rb.Push(Account::ResultAccountUpdateFailed); return; } @@ -498,7 +493,7 @@ public: } ~EnsureTokenIdCacheAsyncInterface() = default; - void LoadIdTokenCache(Kernel::HLERequestContext& ctx) { + void LoadIdTokenCache(HLERequestContext& ctx) { LOG_WARNING(Service_ACC, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -541,14 +536,14 @@ public: } private: - void CheckAvailability(Kernel::HLERequestContext& ctx) { + void CheckAvailability(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); rb.Push(false); // TODO: Check when this is supposed to return true and when not } - void GetAccountId(Kernel::HLERequestContext& ctx) { + void GetAccountId(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); IPC::ResponseBuilder rb{ctx, 4}; @@ -556,7 +551,7 @@ private: rb.PushRaw<u64>(profile_manager->GetLastOpenedUser().Hash()); } - void EnsureIdTokenCacheAsync(Kernel::HLERequestContext& ctx) { + void EnsureIdTokenCacheAsync(HLERequestContext& ctx) { LOG_WARNING(Service_ACC, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -564,13 +559,13 @@ private: rb.PushIpcInterface(ensure_token_id); } - void LoadIdTokenCache(Kernel::HLERequestContext& ctx) { + void LoadIdTokenCache(HLERequestContext& ctx) { LOG_WARNING(Service_ACC, "(STUBBED) called"); ensure_token_id->LoadIdTokenCache(ctx); } - void GetNintendoAccountUserResourceCacheForApplication(Kernel::HLERequestContext& ctx) { + void GetNintendoAccountUserResourceCacheForApplication(HLERequestContext& ctx) { LOG_WARNING(Service_ACC, "(STUBBED) called"); std::vector<u8> nas_user_base_for_application(0x68); @@ -586,7 +581,7 @@ private: rb.PushRaw<u64>(profile_manager->GetLastOpenedUser().Hash()); } - void StoreOpenContext(Kernel::HLERequestContext& ctx) { + void StoreOpenContext(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); profile_manager->StoreOpenedUsers(); @@ -688,14 +683,14 @@ public: } }; -void Module::Interface::GetUserCount(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetUserCount(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); rb.Push<u32>(static_cast<u32>(profile_manager->GetUserCount())); } -void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetUserExistence(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; Common::UUID user_id = rp.PopRaw<Common::UUID>(); LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.RawString()); @@ -705,28 +700,28 @@ void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) { rb.Push(profile_manager->UserExists(user_id)); } -void Module::Interface::ListAllUsers(Kernel::HLERequestContext& ctx) { +void Module::Interface::ListAllUsers(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); ctx.WriteBuffer(profile_manager->GetAllUsers()); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Module::Interface::ListOpenUsers(Kernel::HLERequestContext& ctx) { +void Module::Interface::ListOpenUsers(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); ctx.WriteBuffer(profile_manager->GetOpenUsers()); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Module::Interface::GetLastOpenedUser(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetLastOpenedUser(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); IPC::ResponseBuilder rb{ctx, 6}; rb.Push(ResultSuccess); rb.PushRaw<Common::UUID>(profile_manager->GetLastOpenedUser()); } -void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetProfile(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; Common::UUID user_id = rp.PopRaw<Common::UUID>(); LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.RawString()); @@ -736,20 +731,20 @@ void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IProfile>(system, user_id, *profile_manager); } -void Module::Interface::IsUserRegistrationRequestPermitted(Kernel::HLERequestContext& ctx) { +void Module::Interface::IsUserRegistrationRequestPermitted(HLERequestContext& ctx) { LOG_WARNING(Service_ACC, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); rb.Push(profile_manager->CanSystemRegisterUser()); } -void Module::Interface::InitializeApplicationInfo(Kernel::HLERequestContext& ctx) { +void Module::Interface::InitializeApplicationInfo(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(InitializeApplicationInfoBase()); } -void Module::Interface::InitializeApplicationInfoRestricted(Kernel::HLERequestContext& ctx) { +void Module::Interface::InitializeApplicationInfoRestricted(HLERequestContext& ctx) { LOG_WARNING(Service_ACC, "(Partial implementation) called"); // TODO(ogniK): We require checking if the user actually owns the title and what not. As of @@ -763,7 +758,7 @@ void Module::Interface::InitializeApplicationInfoRestricted(Kernel::HLERequestCo Result Module::Interface::InitializeApplicationInfoBase() { if (application_info) { LOG_ERROR(Service_ACC, "Application already initialized"); - return ERR_ACCOUNTINFO_ALREADY_INITIALIZED; + return Account::ResultApplicationInfoAlreadyInitialized; } // TODO(ogniK): This should be changed to reflect the target process for when we have multiple @@ -774,7 +769,7 @@ Result Module::Interface::InitializeApplicationInfoBase() { if (launch_property.Failed()) { LOG_ERROR(Service_ACC, "Failed to get launch property"); - return ERR_ACCOUNTINFO_BAD_APPLICATION; + return Account::ResultInvalidApplication; } switch (launch_property->base_game_storage_id) { @@ -790,7 +785,7 @@ Result Module::Interface::InitializeApplicationInfoBase() { default: LOG_ERROR(Service_ACC, "Invalid game storage ID! storage_id={}", launch_property->base_game_storage_id); - return ERR_ACCOUNTINFO_BAD_APPLICATION; + return Account::ResultInvalidApplication; } LOG_WARNING(Service_ACC, "ApplicationInfo init required"); @@ -799,14 +794,14 @@ Result Module::Interface::InitializeApplicationInfoBase() { return ResultSuccess; } -void Module::Interface::GetBaasAccountManagerForApplication(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetBaasAccountManagerForApplication(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface<IManagerForApplication>(system, profile_manager); } -void Module::Interface::IsUserAccountSwitchLocked(Kernel::HLERequestContext& ctx) { +void Module::Interface::IsUserAccountSwitchLocked(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); FileSys::NACP nacp; const auto res = system.GetAppLoader().ReadControlData(nacp); @@ -833,14 +828,14 @@ void Module::Interface::IsUserAccountSwitchLocked(Kernel::HLERequestContext& ctx rb.Push(is_locked); } -void Module::Interface::InitializeApplicationInfoV2(Kernel::HLERequestContext& ctx) { +void Module::Interface::InitializeApplicationInfoV2(HLERequestContext& ctx) { LOG_WARNING(Service_ACC, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Module::Interface::GetProfileEditor(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetProfileEditor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; Common::UUID user_id = rp.PopRaw<Common::UUID>(); @@ -851,7 +846,7 @@ void Module::Interface::GetProfileEditor(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IProfileEditor>(system, user_id, *profile_manager); } -void Module::Interface::ListQualifiedUsers(Kernel::HLERequestContext& ctx) { +void Module::Interface::ListQualifiedUsers(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); // All users should be qualified. We don't actually have parental control or anything to do with @@ -862,7 +857,7 @@ void Module::Interface::ListQualifiedUsers(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Module::Interface::ListOpenContextStoredUsers(Kernel::HLERequestContext& ctx) { +void Module::Interface::ListOpenContextStoredUsers(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); ctx.WriteBuffer(profile_manager->GetStoredOpenedUsers()); @@ -870,7 +865,7 @@ void Module::Interface::ListOpenContextStoredUsers(Kernel::HLERequestContext& ct rb.Push(ResultSuccess); } -void Module::Interface::StoreSaveDataThumbnailApplication(Kernel::HLERequestContext& ctx) { +void Module::Interface::StoreSaveDataThumbnailApplication(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto uuid = rp.PopRaw<Common::UUID>(); @@ -883,7 +878,7 @@ void Module::Interface::StoreSaveDataThumbnailApplication(Kernel::HLERequestCont StoreSaveDataThumbnail(ctx, uuid, tid); } -void Module::Interface::StoreSaveDataThumbnailSystem(Kernel::HLERequestContext& ctx) { +void Module::Interface::StoreSaveDataThumbnailSystem(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto uuid = rp.PopRaw<Common::UUID>(); const auto tid = rp.Pop<u64_le>(); @@ -892,26 +887,26 @@ void Module::Interface::StoreSaveDataThumbnailSystem(Kernel::HLERequestContext& StoreSaveDataThumbnail(ctx, uuid, tid); } -void Module::Interface::StoreSaveDataThumbnail(Kernel::HLERequestContext& ctx, - const Common::UUID& uuid, const u64 tid) { +void Module::Interface::StoreSaveDataThumbnail(HLERequestContext& ctx, const Common::UUID& uuid, + const u64 tid) { IPC::ResponseBuilder rb{ctx, 2}; if (tid == 0) { LOG_ERROR(Service_ACC, "TitleID is not valid!"); - rb.Push(ERR_INVALID_APPLICATION_ID); + rb.Push(Account::ResultInvalidApplication); return; } if (uuid.IsInvalid()) { LOG_ERROR(Service_ACC, "User ID is not valid!"); - rb.Push(ERR_INVALID_USER_ID); + rb.Push(Account::ResultInvalidUserId); return; } const auto thumbnail_size = ctx.GetReadBufferSize(); if (thumbnail_size != THUMBNAIL_SIZE) { LOG_ERROR(Service_ACC, "Buffer size is empty! size={:X} expecting {:X}", thumbnail_size, THUMBNAIL_SIZE); - rb.Push(ERR_INVALID_BUFFER_SIZE); + rb.Push(Account::ResultInvalidArrayLength); return; } @@ -919,7 +914,7 @@ void Module::Interface::StoreSaveDataThumbnail(Kernel::HLERequestContext& ctx, rb.Push(ResultSuccess); } -void Module::Interface::TrySelectUserWithoutInteraction(Kernel::HLERequestContext& ctx) { +void Module::Interface::TrySelectUserWithoutInteraction(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); // A u8 is passed into this function which we can safely ignore. It's to determine if we have // access to use the network or not by the looks of it @@ -950,18 +945,20 @@ Module::Interface::Interface(std::shared_ptr<Module> module_, Module::Interface::~Interface() = default; -void InstallInterfaces(Core::System& system) { +void LoopProcess(Core::System& system) { auto module = std::make_shared<Module>(); auto profile_manager = std::make_shared<ProfileManager>(); - - std::make_shared<ACC_AA>(module, profile_manager, system) - ->InstallAsService(system.ServiceManager()); - std::make_shared<ACC_SU>(module, profile_manager, system) - ->InstallAsService(system.ServiceManager()); - std::make_shared<ACC_U0>(module, profile_manager, system) - ->InstallAsService(system.ServiceManager()); - std::make_shared<ACC_U1>(module, profile_manager, system) - ->InstallAsService(system.ServiceManager()); + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("acc:aa", + std::make_shared<ACC_AA>(module, profile_manager, system)); + server_manager->RegisterNamedService("acc:su", + std::make_shared<ACC_SU>(module, profile_manager, system)); + server_manager->RegisterNamedService("acc:u0", + std::make_shared<ACC_U0>(module, profile_manager, system)); + server_manager->RegisterNamedService("acc:u1", + std::make_shared<ACC_U1>(module, profile_manager, system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::Account diff --git a/src/core/hle/service/acc/acc.h b/src/core/hle/service/acc/acc.h index 9411b0b92..6b4735c2f 100644 --- a/src/core/hle/service/acc/acc.h +++ b/src/core/hle/service/acc/acc.h @@ -20,28 +20,28 @@ public: const char* name); ~Interface() override; - void GetUserCount(Kernel::HLERequestContext& ctx); - void GetUserExistence(Kernel::HLERequestContext& ctx); - void ListAllUsers(Kernel::HLERequestContext& ctx); - void ListOpenUsers(Kernel::HLERequestContext& ctx); - void GetLastOpenedUser(Kernel::HLERequestContext& ctx); - void GetProfile(Kernel::HLERequestContext& ctx); - void InitializeApplicationInfo(Kernel::HLERequestContext& ctx); - void InitializeApplicationInfoRestricted(Kernel::HLERequestContext& ctx); - void GetBaasAccountManagerForApplication(Kernel::HLERequestContext& ctx); - void IsUserRegistrationRequestPermitted(Kernel::HLERequestContext& ctx); - void TrySelectUserWithoutInteraction(Kernel::HLERequestContext& ctx); - void IsUserAccountSwitchLocked(Kernel::HLERequestContext& ctx); - void InitializeApplicationInfoV2(Kernel::HLERequestContext& ctx); - void GetProfileEditor(Kernel::HLERequestContext& ctx); - void ListQualifiedUsers(Kernel::HLERequestContext& ctx); - void ListOpenContextStoredUsers(Kernel::HLERequestContext& ctx); - void StoreSaveDataThumbnailApplication(Kernel::HLERequestContext& ctx); - void StoreSaveDataThumbnailSystem(Kernel::HLERequestContext& ctx); + void GetUserCount(HLERequestContext& ctx); + void GetUserExistence(HLERequestContext& ctx); + void ListAllUsers(HLERequestContext& ctx); + void ListOpenUsers(HLERequestContext& ctx); + void GetLastOpenedUser(HLERequestContext& ctx); + void GetProfile(HLERequestContext& ctx); + void InitializeApplicationInfo(HLERequestContext& ctx); + void InitializeApplicationInfoRestricted(HLERequestContext& ctx); + void GetBaasAccountManagerForApplication(HLERequestContext& ctx); + void IsUserRegistrationRequestPermitted(HLERequestContext& ctx); + void TrySelectUserWithoutInteraction(HLERequestContext& ctx); + void IsUserAccountSwitchLocked(HLERequestContext& ctx); + void InitializeApplicationInfoV2(HLERequestContext& ctx); + void GetProfileEditor(HLERequestContext& ctx); + void ListQualifiedUsers(HLERequestContext& ctx); + void ListOpenContextStoredUsers(HLERequestContext& ctx); + void StoreSaveDataThumbnailApplication(HLERequestContext& ctx); + void StoreSaveDataThumbnailSystem(HLERequestContext& ctx); private: Result InitializeApplicationInfoBase(); - void StoreSaveDataThumbnail(Kernel::HLERequestContext& ctx, const Common::UUID& uuid, + void StoreSaveDataThumbnail(HLERequestContext& ctx, const Common::UUID& uuid, const u64 tid); enum class ApplicationType : u32_le { @@ -67,7 +67,6 @@ public: }; }; -/// Registers all ACC services with the specified service manager. -void InstallInterfaces(Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::Account diff --git a/src/core/hle/service/acc/async_context.cpp b/src/core/hle/service/acc/async_context.cpp index 713689d8f..c9e0af90c 100644 --- a/src/core/hle/service/acc/async_context.cpp +++ b/src/core/hle/service/acc/async_context.cpp @@ -2,9 +2,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" #include "core/hle/service/acc/async_context.h" +#include "core/hle/service/ipc_helpers.h" namespace Service::Account { IAsyncContext::IAsyncContext(Core::System& system_) @@ -27,7 +27,7 @@ IAsyncContext::~IAsyncContext() { service_context.CloseEvent(completion_event); } -void IAsyncContext::GetSystemEvent(Kernel::HLERequestContext& ctx) { +void IAsyncContext::GetSystemEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -35,7 +35,7 @@ void IAsyncContext::GetSystemEvent(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(completion_event->GetReadableEvent()); } -void IAsyncContext::Cancel(Kernel::HLERequestContext& ctx) { +void IAsyncContext::Cancel(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); Cancel(); @@ -45,7 +45,7 @@ void IAsyncContext::Cancel(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IAsyncContext::HasDone(Kernel::HLERequestContext& ctx) { +void IAsyncContext::HasDone(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); is_complete.store(IsComplete()); @@ -55,7 +55,7 @@ void IAsyncContext::HasDone(Kernel::HLERequestContext& ctx) { rb.Push(is_complete.load()); } -void IAsyncContext::GetResult(Kernel::HLERequestContext& ctx) { +void IAsyncContext::GetResult(HLERequestContext& ctx) { LOG_DEBUG(Service_ACC, "called"); IPC::ResponseBuilder rb{ctx, 3}; diff --git a/src/core/hle/service/acc/async_context.h b/src/core/hle/service/acc/async_context.h index 26332d241..d7bffc055 100644 --- a/src/core/hle/service/acc/async_context.h +++ b/src/core/hle/service/acc/async_context.h @@ -18,10 +18,10 @@ public: explicit IAsyncContext(Core::System& system_); ~IAsyncContext() override; - void GetSystemEvent(Kernel::HLERequestContext& ctx); - void Cancel(Kernel::HLERequestContext& ctx); - void HasDone(Kernel::HLERequestContext& ctx); - void GetResult(Kernel::HLERequestContext& ctx); + void GetSystemEvent(HLERequestContext& ctx); + void Cancel(HLERequestContext& ctx); + void HasDone(HLERequestContext& ctx); + void GetResult(HLERequestContext& ctx); protected: virtual bool IsComplete() const = 0; diff --git a/src/core/hle/service/acc/errors.h b/src/core/hle/service/acc/errors.h index e9c16b951..433ebfe9d 100644 --- a/src/core/hle/service/acc/errors.h +++ b/src/core/hle/service/acc/errors.h @@ -7,7 +7,13 @@ namespace Service::Account { -constexpr Result ERR_ACCOUNTINFO_BAD_APPLICATION{ErrorModule::Account, 22}; -constexpr Result ERR_ACCOUNTINFO_ALREADY_INITIALIZED{ErrorModule::Account, 41}; +constexpr Result ResultCancelledByUser{ErrorModule::Account, 1}; +constexpr Result ResultNoNotifications{ErrorModule::Account, 15}; +constexpr Result ResultInvalidUserId{ErrorModule::Account, 20}; +constexpr Result ResultInvalidApplication{ErrorModule::Account, 22}; +constexpr Result ResultNullptr{ErrorModule::Account, 30}; +constexpr Result ResultInvalidArrayLength{ErrorModule::Account, 32}; +constexpr Result ResultApplicationInfoAlreadyInitialized{ErrorModule::Account, 41}; +constexpr Result ResultAccountUpdateFailed{ErrorModule::Account, 100}; } // namespace Service::Account diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 26af499d2..f17df5124 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -11,7 +11,6 @@ #include "core/file_sys/patch_manager.h" #include "core/file_sys/registered_cache.h" #include "core/file_sys/savedata_factory.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" #include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/service/acc/profile_manager.h" @@ -29,18 +28,20 @@ #include "core/hle/service/bcat/backend/backend.h" #include "core/hle/service/caps/caps.h" #include "core/hle/service/filesystem/filesystem.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ns/ns.h" -#include "core/hle/service/nvflinger/nvflinger.h" +#include "core/hle/service/nvnflinger/nvnflinger.h" #include "core/hle/service/pm/pm.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/sm/sm.h" #include "core/hle/service/vi/vi.h" #include "core/memory.h" namespace Service::AM { -constexpr Result ERR_NO_DATA_IN_CHANNEL{ErrorModule::AM, 2}; -constexpr Result ERR_NO_MESSAGES{ErrorModule::AM, 3}; -constexpr Result ERR_SIZE_OUT_OF_BOUNDS{ErrorModule::AM, 503}; +constexpr Result ResultNoDataInChannel{ErrorModule::AM, 2}; +constexpr Result ResultNoMessages{ErrorModule::AM, 3}; +constexpr Result ResultInvalidOffset{ErrorModule::AM, 503}; enum class LaunchParameterKind : u32 { ApplicationSpecific = 1, @@ -77,7 +78,7 @@ IWindowController::IWindowController(Core::System& system_) IWindowController::~IWindowController() = default; -void IWindowController::GetAppletResourceUserId(Kernel::HLERequestContext& ctx) { +void IWindowController::GetAppletResourceUserId(HLERequestContext& ctx) { const u64 process_id = system.ApplicationProcess()->GetProcessID(); LOG_DEBUG(Service_AM, "called. Process ID=0x{:016X}", process_id); @@ -87,7 +88,7 @@ void IWindowController::GetAppletResourceUserId(Kernel::HLERequestContext& ctx) rb.Push<u64>(process_id); } -void IWindowController::AcquireForegroundRights(Kernel::HLERequestContext& ctx) { +void IWindowController::AcquireForegroundRights(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -110,7 +111,7 @@ IAudioController::IAudioController(Core::System& system_) IAudioController::~IAudioController() = default; -void IAudioController::SetExpectedMasterVolume(Kernel::HLERequestContext& ctx) { +void IAudioController::SetExpectedMasterVolume(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const float main_applet_volume_tmp = rp.Pop<float>(); const float library_applet_volume_tmp = rp.Pop<float>(); @@ -127,21 +128,21 @@ void IAudioController::SetExpectedMasterVolume(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IAudioController::GetMainAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx) { +void IAudioController::GetMainAppletExpectedMasterVolume(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called. main_applet_volume={}", main_applet_volume); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); rb.Push(main_applet_volume); } -void IAudioController::GetLibraryAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx) { +void IAudioController::GetLibraryAppletExpectedMasterVolume(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called. library_applet_volume={}", library_applet_volume); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); rb.Push(library_applet_volume); } -void IAudioController::ChangeMainAppletMasterVolume(Kernel::HLERequestContext& ctx) { +void IAudioController::ChangeMainAppletMasterVolume(HLERequestContext& ctx) { struct Parameters { float volume; s64 fade_time_ns; @@ -161,7 +162,7 @@ void IAudioController::ChangeMainAppletMasterVolume(Kernel::HLERequestContext& c rb.Push(ResultSuccess); } -void IAudioController::SetTransparentAudioRate(Kernel::HLERequestContext& ctx) { +void IAudioController::SetTransparentAudioRate(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const float transparent_volume_rate_tmp = rp.Pop<float>(); @@ -250,10 +251,9 @@ IDebugFunctions::IDebugFunctions(Core::System& system_) IDebugFunctions::~IDebugFunctions() = default; -ISelfController::ISelfController(Core::System& system_, NVFlinger::NVFlinger& nvflinger_) - : ServiceFramework{system_, "ISelfController"}, nvflinger{nvflinger_}, service_context{ - system, - "ISelfController"} { +ISelfController::ISelfController(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger_) + : ServiceFramework{system_, "ISelfController"}, nvnflinger{nvnflinger_}, + service_context{system, "ISelfController"} { // clang-format off static const FunctionInfo functions[] = { {0, &ISelfController::Exit, "Exit"}, @@ -327,7 +327,7 @@ ISelfController::~ISelfController() { service_context.CloseEvent(accumulated_suspended_tick_changed_event); } -void ISelfController::Exit(Kernel::HLERequestContext& ctx) { +void ISelfController::Exit(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -336,7 +336,7 @@ void ISelfController::Exit(Kernel::HLERequestContext& ctx) { system.Exit(); } -void ISelfController::LockExit(Kernel::HLERequestContext& ctx) { +void ISelfController::LockExit(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); system.SetExitLock(true); @@ -345,7 +345,7 @@ void ISelfController::LockExit(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void ISelfController::UnlockExit(Kernel::HLERequestContext& ctx) { +void ISelfController::UnlockExit(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); system.SetExitLock(false); @@ -354,7 +354,7 @@ void ISelfController::UnlockExit(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void ISelfController::EnterFatalSection(Kernel::HLERequestContext& ctx) { +void ISelfController::EnterFatalSection(HLERequestContext& ctx) { ++num_fatal_sections_entered; LOG_DEBUG(Service_AM, "called. Num fatal sections entered: {}", num_fatal_sections_entered); @@ -362,7 +362,7 @@ void ISelfController::EnterFatalSection(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void ISelfController::LeaveFatalSection(Kernel::HLERequestContext& ctx) { +void ISelfController::LeaveFatalSection(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called."); // Entry and exit of fatal sections must be balanced. @@ -378,7 +378,7 @@ void ISelfController::LeaveFatalSection(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void ISelfController::GetLibraryAppletLaunchableEvent(Kernel::HLERequestContext& ctx) { +void ISelfController::GetLibraryAppletLaunchableEvent(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); launchable_event->Signal(); @@ -388,7 +388,7 @@ void ISelfController::GetLibraryAppletLaunchableEvent(Kernel::HLERequestContext& rb.PushCopyObjects(launchable_event->GetReadableEvent()); } -void ISelfController::SetScreenShotPermission(Kernel::HLERequestContext& ctx) { +void ISelfController::SetScreenShotPermission(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto permission = rp.PopEnum<ScreenshotPermission>(); LOG_DEBUG(Service_AM, "called, permission={}", permission); @@ -399,7 +399,7 @@ void ISelfController::SetScreenShotPermission(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void ISelfController::SetOperationModeChangedNotification(Kernel::HLERequestContext& ctx) { +void ISelfController::SetOperationModeChangedNotification(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; bool flag = rp.Pop<bool>(); @@ -409,7 +409,7 @@ void ISelfController::SetOperationModeChangedNotification(Kernel::HLERequestCont rb.Push(ResultSuccess); } -void ISelfController::SetPerformanceModeChangedNotification(Kernel::HLERequestContext& ctx) { +void ISelfController::SetPerformanceModeChangedNotification(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; bool flag = rp.Pop<bool>(); @@ -419,7 +419,7 @@ void ISelfController::SetPerformanceModeChangedNotification(Kernel::HLERequestCo rb.Push(ResultSuccess); } -void ISelfController::SetFocusHandlingMode(Kernel::HLERequestContext& ctx) { +void ISelfController::SetFocusHandlingMode(HLERequestContext& ctx) { // Takes 3 input u8s with each field located immediately after the previous // u8, these are bool flags. No output. IPC::RequestParser rp{ctx}; @@ -438,14 +438,14 @@ void ISelfController::SetFocusHandlingMode(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void ISelfController::SetRestartMessageEnabled(Kernel::HLERequestContext& ctx) { +void ISelfController::SetRestartMessageEnabled(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void ISelfController::SetOutOfFocusSuspendingEnabled(Kernel::HLERequestContext& ctx) { +void ISelfController::SetOutOfFocusSuspendingEnabled(HLERequestContext& ctx) { // Takes 3 input u8s with each field located immediately after the previous // u8, these are bool flags. No output. IPC::RequestParser rp{ctx}; @@ -457,27 +457,27 @@ void ISelfController::SetOutOfFocusSuspendingEnabled(Kernel::HLERequestContext& rb.Push(ResultSuccess); } -void ISelfController::SetAlbumImageOrientation(Kernel::HLERequestContext& ctx) { +void ISelfController::SetAlbumImageOrientation(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void ISelfController::CreateManagedDisplayLayer(Kernel::HLERequestContext& ctx) { +void ISelfController::CreateManagedDisplayLayer(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); // TODO(Subv): Find out how AM determines the display to use, for now just // create the layer in the Default display. - const auto display_id = nvflinger.OpenDisplay("Default"); - const auto layer_id = nvflinger.CreateLayer(*display_id); + const auto display_id = nvnflinger.OpenDisplay("Default"); + const auto layer_id = nvnflinger.CreateLayer(*display_id); IPC::ResponseBuilder rb{ctx, 4}; rb.Push(ResultSuccess); rb.Push(*layer_id); } -void ISelfController::CreateManagedDisplaySeparableLayer(Kernel::HLERequestContext& ctx) { +void ISelfController::CreateManagedDisplaySeparableLayer(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); // TODO(Subv): Find out how AM determines the display to use, for now just @@ -487,22 +487,22 @@ void ISelfController::CreateManagedDisplaySeparableLayer(Kernel::HLERequestConte // Outputting 1 layer id instead of the expected 2 has not been observed to cause any adverse // side effects. // TODO: Support multiple layers - const auto display_id = nvflinger.OpenDisplay("Default"); - const auto layer_id = nvflinger.CreateLayer(*display_id); + const auto display_id = nvnflinger.OpenDisplay("Default"); + const auto layer_id = nvnflinger.CreateLayer(*display_id); IPC::ResponseBuilder rb{ctx, 4}; rb.Push(ResultSuccess); rb.Push(*layer_id); } -void ISelfController::SetHandlesRequestToDisplay(Kernel::HLERequestContext& ctx) { +void ISelfController::SetHandlesRequestToDisplay(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void ISelfController::SetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx) { +void ISelfController::SetIdleTimeDetectionExtension(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; idle_time_detection_extension = rp.Pop<u32>(); LOG_WARNING(Service_AM, "(STUBBED) called idle_time_detection_extension={}", @@ -512,7 +512,7 @@ void ISelfController::SetIdleTimeDetectionExtension(Kernel::HLERequestContext& c rb.Push(ResultSuccess); } -void ISelfController::GetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx) { +void ISelfController::GetIdleTimeDetectionExtension(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -520,14 +520,14 @@ void ISelfController::GetIdleTimeDetectionExtension(Kernel::HLERequestContext& c rb.Push<u32>(idle_time_detection_extension); } -void ISelfController::ReportUserIsActive(Kernel::HLERequestContext& ctx) { +void ISelfController::ReportUserIsActive(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void ISelfController::SetAutoSleepDisabled(Kernel::HLERequestContext& ctx) { +void ISelfController::SetAutoSleepDisabled(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; is_auto_sleep_disabled = rp.Pop<bool>(); @@ -547,7 +547,7 @@ void ISelfController::SetAutoSleepDisabled(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void ISelfController::IsAutoSleepDisabled(Kernel::HLERequestContext& ctx) { +void ISelfController::IsAutoSleepDisabled(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called."); IPC::ResponseBuilder rb{ctx, 3}; @@ -555,7 +555,7 @@ void ISelfController::IsAutoSleepDisabled(Kernel::HLERequestContext& ctx) { rb.Push(is_auto_sleep_disabled); } -void ISelfController::GetAccumulatedSuspendedTickValue(Kernel::HLERequestContext& ctx) { +void ISelfController::GetAccumulatedSuspendedTickValue(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called."); // This command returns the total number of system ticks since ISelfController creation @@ -566,7 +566,7 @@ void ISelfController::GetAccumulatedSuspendedTickValue(Kernel::HLERequestContext rb.Push<u64>(0); } -void ISelfController::GetAccumulatedSuspendedTickChangedEvent(Kernel::HLERequestContext& ctx) { +void ISelfController::GetAccumulatedSuspendedTickChangedEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called."); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -574,7 +574,7 @@ void ISelfController::GetAccumulatedSuspendedTickChangedEvent(Kernel::HLERequest rb.PushCopyObjects(accumulated_suspended_tick_changed_event->GetReadableEvent()); } -void ISelfController::SetAlbumImageTakenNotificationEnabled(Kernel::HLERequestContext& ctx) { +void ISelfController::SetAlbumImageTakenNotificationEnabled(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; // This service call sets an internal flag whether a notification is shown when an image is @@ -589,7 +589,7 @@ void ISelfController::SetAlbumImageTakenNotificationEnabled(Kernel::HLERequestCo rb.Push(ResultSuccess); } -void ISelfController::SaveCurrentScreenshot(Kernel::HLERequestContext& ctx) { +void ISelfController::SaveCurrentScreenshot(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto album_report_option = rp.PopEnum<Capture::AlbumReportOption>(); @@ -600,7 +600,7 @@ void ISelfController::SaveCurrentScreenshot(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void ISelfController::SetRecordVolumeMuted(Kernel::HLERequestContext& ctx) { +void ISelfController::SetRecordVolumeMuted(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto is_record_volume_muted = rp.Pop<bool>(); @@ -734,7 +734,7 @@ ICommonStateGetter::ICommonStateGetter(Core::System& system_, ICommonStateGetter::~ICommonStateGetter() = default; -void ICommonStateGetter::GetBootMode(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::GetBootMode(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -742,7 +742,7 @@ void ICommonStateGetter::GetBootMode(Kernel::HLERequestContext& ctx) { rb.Push<u8>(static_cast<u8>(Service::PM::SystemBootMode::Normal)); // Normal boot mode } -void ICommonStateGetter::GetEventHandle(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::GetEventHandle(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -750,7 +750,7 @@ void ICommonStateGetter::GetEventHandle(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(msg_queue->GetMessageReceiveEvent()); } -void ICommonStateGetter::ReceiveMessage(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::ReceiveMessage(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); const auto message = msg_queue->PopMessage(); @@ -758,7 +758,7 @@ void ICommonStateGetter::ReceiveMessage(Kernel::HLERequestContext& ctx) { if (message == AppletMessageQueue::AppletMessage::None) { LOG_ERROR(Service_AM, "Message queue is empty"); - rb.Push(ERR_NO_MESSAGES); + rb.Push(AM::ResultNoMessages); rb.PushEnum<AppletMessageQueue::AppletMessage>(message); return; } @@ -767,7 +767,7 @@ void ICommonStateGetter::ReceiveMessage(Kernel::HLERequestContext& ctx) { rb.PushEnum<AppletMessageQueue::AppletMessage>(message); } -void ICommonStateGetter::GetCurrentFocusState(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::GetCurrentFocusState(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -775,7 +775,7 @@ void ICommonStateGetter::GetCurrentFocusState(Kernel::HLERequestContext& ctx) { rb.Push(static_cast<u8>(FocusState::InFocus)); } -void ICommonStateGetter::IsVrModeEnabled(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::IsVrModeEnabled(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -783,7 +783,7 @@ void ICommonStateGetter::IsVrModeEnabled(Kernel::HLERequestContext& ctx) { rb.Push(vr_mode_state); } -void ICommonStateGetter::SetVrModeEnabled(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::SetVrModeEnabled(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; vr_mode_state = rp.Pop<bool>(); @@ -793,7 +793,7 @@ void ICommonStateGetter::SetVrModeEnabled(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void ICommonStateGetter::SetLcdBacklighOffEnabled(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::SetLcdBacklighOffEnabled(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto is_lcd_backlight_off_enabled = rp.Pop<bool>(); @@ -804,21 +804,21 @@ void ICommonStateGetter::SetLcdBacklighOffEnabled(Kernel::HLERequestContext& ctx rb.Push(ResultSuccess); } -void ICommonStateGetter::BeginVrModeEx(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::BeginVrModeEx(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void ICommonStateGetter::EndVrModeEx(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::EndVrModeEx(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -826,7 +826,7 @@ void ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent(Kernel::HLEReque rb.PushCopyObjects(msg_queue->GetOperationModeChangedEvent()); } -void ICommonStateGetter::GetDefaultDisplayResolution(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::GetDefaultDisplayResolution(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 4}; @@ -841,7 +841,7 @@ void ICommonStateGetter::GetDefaultDisplayResolution(Kernel::HLERequestContext& } } -void ICommonStateGetter::SetCpuBoostMode(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::SetCpuBoostMode(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called, forwarding to APM:SYS"); const auto& sm = system.ServiceManager(); @@ -851,7 +851,7 @@ void ICommonStateGetter::SetCpuBoostMode(Kernel::HLERequestContext& ctx) { apm_sys->SetCpuBoostMode(ctx); } -void ICommonStateGetter::PerformSystemButtonPressingIfInFocus(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::PerformSystemButtonPressingIfInFocus(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto system_button{rp.PopEnum<SystemButtonType>()}; @@ -862,7 +862,7 @@ void ICommonStateGetter::PerformSystemButtonPressingIfInFocus(Kernel::HLERequest } void ICommonStateGetter::SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled( - Kernel::HLERequestContext& ctx) { + HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -910,7 +910,7 @@ void IStorage::Register() { IStorage::~IStorage() = default; -void IStorage::Open(Kernel::HLERequestContext& ctx) { +void IStorage::Open(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -919,7 +919,7 @@ void IStorage::Open(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IStorageAccessor>(system, *this); } -void ICommonStateGetter::GetOperationMode(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::GetOperationMode(HLERequestContext& ctx) { const bool use_docked_mode{Settings::values.use_docked_mode.GetValue()}; LOG_DEBUG(Service_AM, "called, use_docked_mode={}", use_docked_mode); @@ -928,7 +928,7 @@ void ICommonStateGetter::GetOperationMode(Kernel::HLERequestContext& ctx) { rb.Push(static_cast<u8>(use_docked_mode ? OperationMode::Docked : OperationMode::Handheld)); } -void ICommonStateGetter::GetPerformanceMode(Kernel::HLERequestContext& ctx) { +void ICommonStateGetter::GetPerformanceMode(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -968,7 +968,7 @@ public: } private: - void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) { + void GetAppletStateChangedEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -976,7 +976,7 @@ private: rb.PushCopyObjects(applet->GetBroker().GetStateChangedEvent()); } - void IsCompleted(Kernel::HLERequestContext& ctx) { + void IsCompleted(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -984,21 +984,21 @@ private: rb.Push<u32>(applet->TransactionComplete()); } - void GetResult(Kernel::HLERequestContext& ctx) { + void GetResult(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(applet->GetStatus()); } - void PresetLibraryAppletGpuTimeSliceZero(Kernel::HLERequestContext& ctx) { + void PresetLibraryAppletGpuTimeSliceZero(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void Start(Kernel::HLERequestContext& ctx) { + void Start(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); ASSERT(applet != nullptr); @@ -1010,7 +1010,7 @@ private: rb.Push(ResultSuccess); } - void PushInData(Kernel::HLERequestContext& ctx) { + void PushInData(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::RequestParser rp{ctx}; @@ -1020,7 +1020,7 @@ private: rb.Push(ResultSuccess); } - void PopOutData(Kernel::HLERequestContext& ctx) { + void PopOutData(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); auto storage = applet->GetBroker().PopNormalDataToGame(); @@ -1028,7 +1028,7 @@ private: LOG_DEBUG(Service_AM, "storage is a nullptr. There is no data in the current normal channel"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_NO_DATA_IN_CHANNEL); + rb.Push(AM::ResultNoDataInChannel); return; } @@ -1037,7 +1037,7 @@ private: rb.PushIpcInterface<IStorage>(std::move(storage)); } - void PushInteractiveInData(Kernel::HLERequestContext& ctx) { + void PushInteractiveInData(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::RequestParser rp{ctx}; @@ -1051,7 +1051,7 @@ private: rb.Push(ResultSuccess); } - void PopInteractiveOutData(Kernel::HLERequestContext& ctx) { + void PopInteractiveOutData(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); auto storage = applet->GetBroker().PopInteractiveDataToGame(); @@ -1059,7 +1059,7 @@ private: LOG_DEBUG(Service_AM, "storage is a nullptr. There is no data in the current interactive channel"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_NO_DATA_IN_CHANNEL); + rb.Push(AM::ResultNoDataInChannel); return; } @@ -1068,7 +1068,7 @@ private: rb.PushIpcInterface<IStorage>(std::move(storage)); } - void GetPopOutDataEvent(Kernel::HLERequestContext& ctx) { + void GetPopOutDataEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -1076,7 +1076,7 @@ private: rb.PushCopyObjects(applet->GetBroker().GetNormalDataEvent()); } - void GetPopInteractiveOutDataEvent(Kernel::HLERequestContext& ctx) { + void GetPopInteractiveOutDataEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -1084,7 +1084,7 @@ private: rb.PushCopyObjects(applet->GetBroker().GetInteractiveDataEvent()); } - void GetIndirectLayerConsumerHandle(Kernel::HLERequestContext& ctx) { + void GetIndirectLayerConsumerHandle(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); // We require a non-zero handle to be valid. Using 0xdeadbeef allows us to trace if this is @@ -1114,7 +1114,7 @@ IStorageAccessor::IStorageAccessor(Core::System& system_, IStorage& backing_) IStorageAccessor::~IStorageAccessor() = default; -void IStorageAccessor::GetSize(Kernel::HLERequestContext& ctx) { +void IStorageAccessor::GetSize(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 4}; @@ -1123,7 +1123,7 @@ void IStorageAccessor::GetSize(Kernel::HLERequestContext& ctx) { rb.Push(static_cast<u64>(backing.GetSize())); } -void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) { +void IStorageAccessor::Write(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 offset{rp.Pop<u64>()}; @@ -1138,7 +1138,7 @@ void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) { backing.GetSize(), size, offset); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_SIZE_OUT_OF_BOUNDS); + rb.Push(AM::ResultInvalidOffset); return; } @@ -1148,7 +1148,7 @@ void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IStorageAccessor::Read(Kernel::HLERequestContext& ctx) { +void IStorageAccessor::Read(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 offset{rp.Pop<u64>()}; @@ -1161,7 +1161,7 @@ void IStorageAccessor::Read(Kernel::HLERequestContext& ctx) { backing.GetSize(), size, offset); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_SIZE_OUT_OF_BOUNDS); + rb.Push(AM::ResultInvalidOffset); return; } @@ -1186,7 +1186,7 @@ ILibraryAppletCreator::ILibraryAppletCreator(Core::System& system_) ILibraryAppletCreator::~ILibraryAppletCreator() = default; -void ILibraryAppletCreator::CreateLibraryApplet(Kernel::HLERequestContext& ctx) { +void ILibraryAppletCreator::CreateLibraryApplet(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_id = rp.PopRaw<Applets::AppletId>(); @@ -1212,7 +1212,7 @@ void ILibraryAppletCreator::CreateLibraryApplet(Kernel::HLERequestContext& ctx) rb.PushIpcInterface<ILibraryAppletAccessor>(system, applet); } -void ILibraryAppletCreator::CreateStorage(Kernel::HLERequestContext& ctx) { +void ILibraryAppletCreator::CreateStorage(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s64 size{rp.Pop<s64>()}; @@ -1233,7 +1233,7 @@ void ILibraryAppletCreator::CreateStorage(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IStorage>(system, std::move(buffer)); } -void ILibraryAppletCreator::CreateTransferMemoryStorage(Kernel::HLERequestContext& ctx) { +void ILibraryAppletCreator::CreateTransferMemoryStorage(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { @@ -1264,16 +1264,15 @@ void ILibraryAppletCreator::CreateTransferMemoryStorage(Kernel::HLERequestContex return; } - const u8* const mem_begin = system.Memory().GetPointer(transfer_mem->GetSourceAddress()); - const u8* const mem_end = mem_begin + transfer_mem->GetSize(); - std::vector<u8> memory{mem_begin, mem_end}; + std::vector<u8> memory(transfer_mem->GetSize()); + system.Memory().ReadBlock(transfer_mem->GetSourceAddress(), memory.data(), memory.size()); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface<IStorage>(system, std::move(memory)); } -void ILibraryAppletCreator::CreateHandleStorage(Kernel::HLERequestContext& ctx) { +void ILibraryAppletCreator::CreateHandleStorage(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s64 size{rp.Pop<s64>()}; @@ -1298,9 +1297,8 @@ void ILibraryAppletCreator::CreateHandleStorage(Kernel::HLERequestContext& ctx) return; } - const u8* const mem_begin = system.Memory().GetPointer(transfer_mem->GetSourceAddress()); - const u8* const mem_end = mem_begin + transfer_mem->GetSize(); - std::vector<u8> memory{mem_begin, mem_end}; + std::vector<u8> memory(transfer_mem->GetSize()); + system.Memory().ReadBlock(transfer_mem->GetSourceAddress(), memory.data(), memory.size()); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -1396,29 +1394,28 @@ IApplicationFunctions::~IApplicationFunctions() { service_context.CloseEvent(health_warning_disappeared_system_event); } -void IApplicationFunctions::EnableApplicationCrashReport(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::EnableApplicationCrashReport(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IApplicationFunctions::InitializeApplicationCopyrightFrameBuffer( - Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::InitializeApplicationCopyrightFrameBuffer(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IApplicationFunctions::SetApplicationCopyrightImage(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::SetApplicationCopyrightImage(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IApplicationFunctions::SetApplicationCopyrightVisibility(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::SetApplicationCopyrightVisibility(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto is_visible = rp.Pop<bool>(); @@ -1428,37 +1425,35 @@ void IApplicationFunctions::SetApplicationCopyrightVisibility(Kernel::HLERequest rb.Push(ResultSuccess); } -void IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed( - Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed( - Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IApplicationFunctions::BeginBlockingHomeButton(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::BeginBlockingHomeButton(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IApplicationFunctions::EndBlockingHomeButton(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::EndBlockingHomeButton(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::PopLaunchParameter(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto kind = rp.PopEnum<LaunchParameterKind>(); @@ -1507,18 +1502,17 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) { LOG_ERROR(Service_AM, "Attempted to load launch parameter but none was found!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_NO_DATA_IN_CHANNEL); + rb.Push(AM::ResultNoDataInChannel); } -void IApplicationFunctions::CreateApplicationAndRequestToStartForQuest( - Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::CreateApplicationAndRequestToStartForQuest(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::EnsureSaveData(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; u128 user_id = rp.PopRaw<u128>(); @@ -1536,7 +1530,7 @@ void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) { rb.Push<u64>(0); } -void IApplicationFunctions::SetTerminateResult(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::SetTerminateResult(HLERequestContext& ctx) { // Takes an input u32 Result, no output. // For example, in some cases official apps use this with error 0x2A2 then // uses svcBreak. @@ -1549,7 +1543,7 @@ void IApplicationFunctions::SetTerminateResult(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IApplicationFunctions::GetDisplayVersion(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::GetDisplayVersion(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); std::array<u8, 0x10> version_string{}; @@ -1583,7 +1577,7 @@ void IApplicationFunctions::GetDisplayVersion(Kernel::HLERequestContext& ctx) { rb.PushRaw(version_string); } -void IApplicationFunctions::GetDesiredLanguage(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::GetDesiredLanguage(HLERequestContext& ctx) { // TODO(bunnei): This should be configurable LOG_DEBUG(Service_AM, "called"); @@ -1639,7 +1633,7 @@ void IApplicationFunctions::GetDesiredLanguage(Kernel::HLERequestContext& ctx) { rb.Push(*res_code); } -void IApplicationFunctions::IsGamePlayRecordingSupported(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::IsGamePlayRecordingSupported(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); constexpr bool gameplay_recording_supported = false; @@ -1649,21 +1643,21 @@ void IApplicationFunctions::IsGamePlayRecordingSupported(Kernel::HLERequestConte rb.Push(gameplay_recording_supported); } -void IApplicationFunctions::InitializeGamePlayRecording(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::InitializeGamePlayRecording(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IApplicationFunctions::SetGamePlayRecordingState(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::SetGamePlayRecordingState(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IApplicationFunctions::NotifyRunning(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::NotifyRunning(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -1671,7 +1665,7 @@ void IApplicationFunctions::NotifyRunning(Kernel::HLERequestContext& ctx) { rb.Push<u8>(0); // Unknown, seems to be ignored by official processes } -void IApplicationFunctions::GetPseudoDeviceId(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::GetPseudoDeviceId(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 6}; @@ -1682,7 +1676,7 @@ void IApplicationFunctions::GetPseudoDeviceId(Kernel::HLERequestContext& ctx) { rb.Push<u64>(0); } -void IApplicationFunctions::ExtendSaveData(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::ExtendSaveData(HLERequestContext& ctx) { struct Parameters { FileSys::SaveDataType type; u128 user_id; @@ -1711,7 +1705,7 @@ void IApplicationFunctions::ExtendSaveData(Kernel::HLERequestContext& ctx) { rb.Push<u64>(0); } -void IApplicationFunctions::GetSaveDataSize(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::GetSaveDataSize(HLERequestContext& ctx) { struct Parameters { FileSys::SaveDataType type; u128 user_id; @@ -1733,7 +1727,7 @@ void IApplicationFunctions::GetSaveDataSize(Kernel::HLERequestContext& ctx) { rb.Push(size.journal); } -void IApplicationFunctions::QueryApplicationPlayStatistics(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::QueryApplicationPlayStatistics(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -1741,7 +1735,7 @@ void IApplicationFunctions::QueryApplicationPlayStatistics(Kernel::HLERequestCon rb.Push<u32>(0); } -void IApplicationFunctions::QueryApplicationPlayStatisticsByUid(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::QueryApplicationPlayStatisticsByUid(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -1749,7 +1743,7 @@ void IApplicationFunctions::QueryApplicationPlayStatisticsByUid(Kernel::HLEReque rb.Push<u32>(0); } -void IApplicationFunctions::ExecuteProgram(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::ExecuteProgram(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::RequestParser rp{ctx}; @@ -1763,21 +1757,21 @@ void IApplicationFunctions::ExecuteProgram(Kernel::HLERequestContext& ctx) { system.ExecuteProgram(program_index); } -void IApplicationFunctions::ClearUserChannel(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::ClearUserChannel(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IApplicationFunctions::UnpopToUserChannel(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::UnpopToUserChannel(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IApplicationFunctions::GetPreviousProgramIndex(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::GetPreviousProgramIndex(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -1785,7 +1779,7 @@ void IApplicationFunctions::GetPreviousProgramIndex(Kernel::HLERequestContext& c rb.Push<s32>(previous_program_index); } -void IApplicationFunctions::GetGpuErrorDetectedSystemEvent(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::GetGpuErrorDetectedSystemEvent(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -1793,7 +1787,7 @@ void IApplicationFunctions::GetGpuErrorDetectedSystemEvent(Kernel::HLERequestCon rb.PushCopyObjects(gpu_error_detected_event->GetReadableEvent()); } -void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -1801,15 +1795,14 @@ void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(Kernel::HLERe rb.PushCopyObjects(friend_invitation_storage_channel_event->GetReadableEvent()); } -void IApplicationFunctions::TryPopFromFriendInvitationStorageChannel( - Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::TryPopFromFriendInvitationStorageChannel(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_NO_DATA_IN_CHANNEL); + rb.Push(AM::ResultNoDataInChannel); } -void IApplicationFunctions::GetNotificationStorageChannelEvent(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::GetNotificationStorageChannelEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -1817,7 +1810,7 @@ void IApplicationFunctions::GetNotificationStorageChannelEvent(Kernel::HLEReques rb.PushCopyObjects(notification_storage_channel_event->GetReadableEvent()); } -void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -1825,24 +1818,28 @@ void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(Kernel::HLERe rb.PushCopyObjects(health_warning_disappeared_system_event->GetReadableEvent()); } -void IApplicationFunctions::PrepareForJit(Kernel::HLERequestContext& ctx) { +void IApplicationFunctions::PrepareForJit(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger, - Core::System& system) { +void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system) { auto message_queue = std::make_shared<AppletMessageQueue>(system); // Needed on game boot message_queue->PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); - std::make_shared<AppletAE>(nvflinger, message_queue, system)->InstallAsService(service_manager); - std::make_shared<AppletOE>(nvflinger, message_queue, system)->InstallAsService(service_manager); - std::make_shared<IdleSys>(system)->InstallAsService(service_manager); - std::make_shared<OMM>(system)->InstallAsService(service_manager); - std::make_shared<SPSM>(system)->InstallAsService(service_manager); + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService( + "appletAE", std::make_shared<AppletAE>(nvnflinger, message_queue, system)); + server_manager->RegisterNamedService( + "appletOE", std::make_shared<AppletOE>(nvnflinger, message_queue, system)); + server_manager->RegisterNamedService("idle:sys", std::make_shared<IdleSys>(system)); + server_manager->RegisterNamedService("omm", std::make_shared<OMM>(system)); + server_manager->RegisterNamedService("spsm", std::make_shared<SPSM>(system)); + ServerManager::RunServer(std::move(server_manager)); } IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_) @@ -1878,14 +1875,14 @@ IHomeMenuFunctions::~IHomeMenuFunctions() { service_context.CloseEvent(pop_from_general_channel_event); } -void IHomeMenuFunctions::RequestToGetForeground(Kernel::HLERequestContext& ctx) { +void IHomeMenuFunctions::RequestToGetForeground(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IHomeMenuFunctions::GetPopFromGeneralChannelEvent(Kernel::HLERequestContext& ctx) { +void IHomeMenuFunctions::GetPopFromGeneralChannelEvent(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 1}; diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index a0fbfcfc5..0dbc6485e 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -12,11 +12,12 @@ namespace Kernel { class KernelCore; +class KReadableEvent; class KTransferMemory; } // namespace Kernel -namespace Service::NVFlinger { -class NVFlinger; +namespace Service::Nvnflinger { +class Nvnflinger; } namespace Service::AM { @@ -109,8 +110,8 @@ public: ~IWindowController() override; private: - void GetAppletResourceUserId(Kernel::HLERequestContext& ctx); - void AcquireForegroundRights(Kernel::HLERequestContext& ctx); + void GetAppletResourceUserId(HLERequestContext& ctx); + void AcquireForegroundRights(HLERequestContext& ctx); }; class IAudioController final : public ServiceFramework<IAudioController> { @@ -119,11 +120,11 @@ public: ~IAudioController() override; private: - void SetExpectedMasterVolume(Kernel::HLERequestContext& ctx); - void GetMainAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx); - void GetLibraryAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx); - void ChangeMainAppletMasterVolume(Kernel::HLERequestContext& ctx); - void SetTransparentAudioRate(Kernel::HLERequestContext& ctx); + void SetExpectedMasterVolume(HLERequestContext& ctx); + void GetMainAppletExpectedMasterVolume(HLERequestContext& ctx); + void GetLibraryAppletExpectedMasterVolume(HLERequestContext& ctx); + void ChangeMainAppletMasterVolume(HLERequestContext& ctx); + void SetTransparentAudioRate(HLERequestContext& ctx); static constexpr float min_allowed_volume = 0.0f; static constexpr float max_allowed_volume = 1.0f; @@ -153,36 +154,36 @@ public: class ISelfController final : public ServiceFramework<ISelfController> { public: - explicit ISelfController(Core::System& system_, NVFlinger::NVFlinger& nvflinger_); + explicit ISelfController(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger_); ~ISelfController() override; private: - void Exit(Kernel::HLERequestContext& ctx); - void LockExit(Kernel::HLERequestContext& ctx); - void UnlockExit(Kernel::HLERequestContext& ctx); - void EnterFatalSection(Kernel::HLERequestContext& ctx); - void LeaveFatalSection(Kernel::HLERequestContext& ctx); - void GetLibraryAppletLaunchableEvent(Kernel::HLERequestContext& ctx); - void SetScreenShotPermission(Kernel::HLERequestContext& ctx); - void SetOperationModeChangedNotification(Kernel::HLERequestContext& ctx); - void SetPerformanceModeChangedNotification(Kernel::HLERequestContext& ctx); - void SetFocusHandlingMode(Kernel::HLERequestContext& ctx); - void SetRestartMessageEnabled(Kernel::HLERequestContext& ctx); - void SetOutOfFocusSuspendingEnabled(Kernel::HLERequestContext& ctx); - void SetAlbumImageOrientation(Kernel::HLERequestContext& ctx); - void CreateManagedDisplayLayer(Kernel::HLERequestContext& ctx); - void CreateManagedDisplaySeparableLayer(Kernel::HLERequestContext& ctx); - void SetHandlesRequestToDisplay(Kernel::HLERequestContext& ctx); - void SetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx); - void GetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx); - void ReportUserIsActive(Kernel::HLERequestContext& ctx); - void SetAutoSleepDisabled(Kernel::HLERequestContext& ctx); - void IsAutoSleepDisabled(Kernel::HLERequestContext& ctx); - void GetAccumulatedSuspendedTickValue(Kernel::HLERequestContext& ctx); - void GetAccumulatedSuspendedTickChangedEvent(Kernel::HLERequestContext& ctx); - void SetAlbumImageTakenNotificationEnabled(Kernel::HLERequestContext& ctx); - void SaveCurrentScreenshot(Kernel::HLERequestContext& ctx); - void SetRecordVolumeMuted(Kernel::HLERequestContext& ctx); + void Exit(HLERequestContext& ctx); + void LockExit(HLERequestContext& ctx); + void UnlockExit(HLERequestContext& ctx); + void EnterFatalSection(HLERequestContext& ctx); + void LeaveFatalSection(HLERequestContext& ctx); + void GetLibraryAppletLaunchableEvent(HLERequestContext& ctx); + void SetScreenShotPermission(HLERequestContext& ctx); + void SetOperationModeChangedNotification(HLERequestContext& ctx); + void SetPerformanceModeChangedNotification(HLERequestContext& ctx); + void SetFocusHandlingMode(HLERequestContext& ctx); + void SetRestartMessageEnabled(HLERequestContext& ctx); + void SetOutOfFocusSuspendingEnabled(HLERequestContext& ctx); + void SetAlbumImageOrientation(HLERequestContext& ctx); + void CreateManagedDisplayLayer(HLERequestContext& ctx); + void CreateManagedDisplaySeparableLayer(HLERequestContext& ctx); + void SetHandlesRequestToDisplay(HLERequestContext& ctx); + void SetIdleTimeDetectionExtension(HLERequestContext& ctx); + void GetIdleTimeDetectionExtension(HLERequestContext& ctx); + void ReportUserIsActive(HLERequestContext& ctx); + void SetAutoSleepDisabled(HLERequestContext& ctx); + void IsAutoSleepDisabled(HLERequestContext& ctx); + void GetAccumulatedSuspendedTickValue(HLERequestContext& ctx); + void GetAccumulatedSuspendedTickChangedEvent(HLERequestContext& ctx); + void SetAlbumImageTakenNotificationEnabled(HLERequestContext& ctx); + void SaveCurrentScreenshot(HLERequestContext& ctx); + void SetRecordVolumeMuted(HLERequestContext& ctx); enum class ScreenshotPermission : u32 { Inherit = 0, @@ -190,7 +191,7 @@ private: Disable = 2, }; - NVFlinger::NVFlinger& nvflinger; + Nvnflinger::Nvnflinger& nvnflinger; KernelHelpers::ServiceContext service_context; @@ -235,22 +236,22 @@ private: CaptureButtonLongPressing, }; - void GetEventHandle(Kernel::HLERequestContext& ctx); - void ReceiveMessage(Kernel::HLERequestContext& ctx); - void GetCurrentFocusState(Kernel::HLERequestContext& ctx); - void GetDefaultDisplayResolutionChangeEvent(Kernel::HLERequestContext& ctx); - void GetOperationMode(Kernel::HLERequestContext& ctx); - void GetPerformanceMode(Kernel::HLERequestContext& ctx); - void GetBootMode(Kernel::HLERequestContext& ctx); - void IsVrModeEnabled(Kernel::HLERequestContext& ctx); - void SetVrModeEnabled(Kernel::HLERequestContext& ctx); - void SetLcdBacklighOffEnabled(Kernel::HLERequestContext& ctx); - void BeginVrModeEx(Kernel::HLERequestContext& ctx); - void EndVrModeEx(Kernel::HLERequestContext& ctx); - void GetDefaultDisplayResolution(Kernel::HLERequestContext& ctx); - void SetCpuBoostMode(Kernel::HLERequestContext& ctx); - void PerformSystemButtonPressingIfInFocus(Kernel::HLERequestContext& ctx); - void SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled(Kernel::HLERequestContext& ctx); + void GetEventHandle(HLERequestContext& ctx); + void ReceiveMessage(HLERequestContext& ctx); + void GetCurrentFocusState(HLERequestContext& ctx); + void GetDefaultDisplayResolutionChangeEvent(HLERequestContext& ctx); + void GetOperationMode(HLERequestContext& ctx); + void GetPerformanceMode(HLERequestContext& ctx); + void GetBootMode(HLERequestContext& ctx); + void IsVrModeEnabled(HLERequestContext& ctx); + void SetVrModeEnabled(HLERequestContext& ctx); + void SetLcdBacklighOffEnabled(HLERequestContext& ctx); + void BeginVrModeEx(HLERequestContext& ctx); + void EndVrModeEx(HLERequestContext& ctx); + void GetDefaultDisplayResolution(HLERequestContext& ctx); + void SetCpuBoostMode(HLERequestContext& ctx); + void PerformSystemButtonPressingIfInFocus(HLERequestContext& ctx); + void SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled(HLERequestContext& ctx); std::shared_ptr<AppletMessageQueue> msg_queue; bool vr_mode_state{}; @@ -283,7 +284,7 @@ public: private: void Register(); - void Open(Kernel::HLERequestContext& ctx); + void Open(HLERequestContext& ctx); std::shared_ptr<IStorageImpl> impl; }; @@ -294,9 +295,9 @@ public: ~IStorageAccessor() override; private: - void GetSize(Kernel::HLERequestContext& ctx); - void Write(Kernel::HLERequestContext& ctx); - void Read(Kernel::HLERequestContext& ctx); + void GetSize(HLERequestContext& ctx); + void Write(HLERequestContext& ctx); + void Read(HLERequestContext& ctx); IStorage& backing; }; @@ -307,10 +308,10 @@ public: ~ILibraryAppletCreator() override; private: - void CreateLibraryApplet(Kernel::HLERequestContext& ctx); - void CreateStorage(Kernel::HLERequestContext& ctx); - void CreateTransferMemoryStorage(Kernel::HLERequestContext& ctx); - void CreateHandleStorage(Kernel::HLERequestContext& ctx); + void CreateLibraryApplet(HLERequestContext& ctx); + void CreateStorage(HLERequestContext& ctx); + void CreateTransferMemoryStorage(HLERequestContext& ctx); + void CreateHandleStorage(HLERequestContext& ctx); }; class IApplicationFunctions final : public ServiceFramework<IApplicationFunctions> { @@ -319,39 +320,39 @@ public: ~IApplicationFunctions() override; private: - void PopLaunchParameter(Kernel::HLERequestContext& ctx); - void CreateApplicationAndRequestToStartForQuest(Kernel::HLERequestContext& ctx); - void EnsureSaveData(Kernel::HLERequestContext& ctx); - void SetTerminateResult(Kernel::HLERequestContext& ctx); - void GetDisplayVersion(Kernel::HLERequestContext& ctx); - void GetDesiredLanguage(Kernel::HLERequestContext& ctx); - void IsGamePlayRecordingSupported(Kernel::HLERequestContext& ctx); - void InitializeGamePlayRecording(Kernel::HLERequestContext& ctx); - void SetGamePlayRecordingState(Kernel::HLERequestContext& ctx); - void NotifyRunning(Kernel::HLERequestContext& ctx); - void GetPseudoDeviceId(Kernel::HLERequestContext& ctx); - void ExtendSaveData(Kernel::HLERequestContext& ctx); - void GetSaveDataSize(Kernel::HLERequestContext& ctx); - void BeginBlockingHomeButtonShortAndLongPressed(Kernel::HLERequestContext& ctx); - void EndBlockingHomeButtonShortAndLongPressed(Kernel::HLERequestContext& ctx); - void BeginBlockingHomeButton(Kernel::HLERequestContext& ctx); - void EndBlockingHomeButton(Kernel::HLERequestContext& ctx); - void EnableApplicationCrashReport(Kernel::HLERequestContext& ctx); - void InitializeApplicationCopyrightFrameBuffer(Kernel::HLERequestContext& ctx); - void SetApplicationCopyrightImage(Kernel::HLERequestContext& ctx); - void SetApplicationCopyrightVisibility(Kernel::HLERequestContext& ctx); - void QueryApplicationPlayStatistics(Kernel::HLERequestContext& ctx); - void QueryApplicationPlayStatisticsByUid(Kernel::HLERequestContext& ctx); - void ExecuteProgram(Kernel::HLERequestContext& ctx); - void ClearUserChannel(Kernel::HLERequestContext& ctx); - void UnpopToUserChannel(Kernel::HLERequestContext& ctx); - void GetPreviousProgramIndex(Kernel::HLERequestContext& ctx); - void GetGpuErrorDetectedSystemEvent(Kernel::HLERequestContext& ctx); - void GetFriendInvitationStorageChannelEvent(Kernel::HLERequestContext& ctx); - void TryPopFromFriendInvitationStorageChannel(Kernel::HLERequestContext& ctx); - void GetNotificationStorageChannelEvent(Kernel::HLERequestContext& ctx); - void GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx); - void PrepareForJit(Kernel::HLERequestContext& ctx); + void PopLaunchParameter(HLERequestContext& ctx); + void CreateApplicationAndRequestToStartForQuest(HLERequestContext& ctx); + void EnsureSaveData(HLERequestContext& ctx); + void SetTerminateResult(HLERequestContext& ctx); + void GetDisplayVersion(HLERequestContext& ctx); + void GetDesiredLanguage(HLERequestContext& ctx); + void IsGamePlayRecordingSupported(HLERequestContext& ctx); + void InitializeGamePlayRecording(HLERequestContext& ctx); + void SetGamePlayRecordingState(HLERequestContext& ctx); + void NotifyRunning(HLERequestContext& ctx); + void GetPseudoDeviceId(HLERequestContext& ctx); + void ExtendSaveData(HLERequestContext& ctx); + void GetSaveDataSize(HLERequestContext& ctx); + void BeginBlockingHomeButtonShortAndLongPressed(HLERequestContext& ctx); + void EndBlockingHomeButtonShortAndLongPressed(HLERequestContext& ctx); + void BeginBlockingHomeButton(HLERequestContext& ctx); + void EndBlockingHomeButton(HLERequestContext& ctx); + void EnableApplicationCrashReport(HLERequestContext& ctx); + void InitializeApplicationCopyrightFrameBuffer(HLERequestContext& ctx); + void SetApplicationCopyrightImage(HLERequestContext& ctx); + void SetApplicationCopyrightVisibility(HLERequestContext& ctx); + void QueryApplicationPlayStatistics(HLERequestContext& ctx); + void QueryApplicationPlayStatisticsByUid(HLERequestContext& ctx); + void ExecuteProgram(HLERequestContext& ctx); + void ClearUserChannel(HLERequestContext& ctx); + void UnpopToUserChannel(HLERequestContext& ctx); + void GetPreviousProgramIndex(HLERequestContext& ctx); + void GetGpuErrorDetectedSystemEvent(HLERequestContext& ctx); + void GetFriendInvitationStorageChannelEvent(HLERequestContext& ctx); + void TryPopFromFriendInvitationStorageChannel(HLERequestContext& ctx); + void GetNotificationStorageChannelEvent(HLERequestContext& ctx); + void GetHealthWarningDisappearedSystemEvent(HLERequestContext& ctx); + void PrepareForJit(HLERequestContext& ctx); KernelHelpers::ServiceContext service_context; @@ -370,8 +371,8 @@ public: ~IHomeMenuFunctions() override; private: - void RequestToGetForeground(Kernel::HLERequestContext& ctx); - void GetPopFromGeneralChannelEvent(Kernel::HLERequestContext& ctx); + void RequestToGetForeground(HLERequestContext& ctx); + void GetPopFromGeneralChannelEvent(HLERequestContext& ctx); KernelHelpers::ServiceContext service_context; @@ -396,8 +397,6 @@ public: ~IProcessWindingController() override; }; -/// Registers all AM services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger, - Core::System& system); +void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system); } // namespace Service::AM diff --git a/src/core/hle/service/am/applet_ae.cpp b/src/core/hle/service/am/applet_ae.cpp index d7719da35..2764f7ceb 100644 --- a/src/core/hle/service/am/applet_ae.cpp +++ b/src/core/hle/service/am/applet_ae.cpp @@ -3,20 +3,20 @@ #include "common/logging/log.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/am/am.h" #include "core/hle/service/am/applet_ae.h" -#include "core/hle/service/nvflinger/nvflinger.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/nvnflinger/nvnflinger.h" namespace Service::AM { class ILibraryAppletProxy final : public ServiceFramework<ILibraryAppletProxy> { public: - explicit ILibraryAppletProxy(NVFlinger::NVFlinger& nvflinger_, + explicit ILibraryAppletProxy(Nvnflinger::Nvnflinger& nvnflinger_, std::shared_ptr<AppletMessageQueue> msg_queue_, Core::System& system_) - : ServiceFramework{system_, "ILibraryAppletProxy"}, nvflinger{nvflinger_}, - msg_queue{std::move(msg_queue_)} { + : ServiceFramework{system_, "ILibraryAppletProxy"}, + nvnflinger{nvnflinger_}, msg_queue{std::move(msg_queue_)} { // clang-format off static const FunctionInfo functions[] = { {0, &ILibraryAppletProxy::GetCommonStateGetter, "GetCommonStateGetter"}, @@ -36,7 +36,7 @@ public: } private: - void GetCommonStateGetter(Kernel::HLERequestContext& ctx) { + void GetCommonStateGetter(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -44,15 +44,15 @@ private: rb.PushIpcInterface<ICommonStateGetter>(system, msg_queue); } - void GetSelfController(Kernel::HLERequestContext& ctx) { + void GetSelfController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface<ISelfController>(system, nvflinger); + rb.PushIpcInterface<ISelfController>(system, nvnflinger); } - void GetWindowController(Kernel::HLERequestContext& ctx) { + void GetWindowController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -60,7 +60,7 @@ private: rb.PushIpcInterface<IWindowController>(system); } - void GetAudioController(Kernel::HLERequestContext& ctx) { + void GetAudioController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -68,7 +68,7 @@ private: rb.PushIpcInterface<IAudioController>(system); } - void GetDisplayController(Kernel::HLERequestContext& ctx) { + void GetDisplayController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -76,7 +76,7 @@ private: rb.PushIpcInterface<IDisplayController>(system); } - void GetProcessWindingController(Kernel::HLERequestContext& ctx) { + void GetProcessWindingController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -84,7 +84,7 @@ private: rb.PushIpcInterface<IProcessWindingController>(system); } - void GetDebugFunctions(Kernel::HLERequestContext& ctx) { + void GetDebugFunctions(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -92,7 +92,7 @@ private: rb.PushIpcInterface<IDebugFunctions>(system); } - void GetLibraryAppletCreator(Kernel::HLERequestContext& ctx) { + void GetLibraryAppletCreator(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -100,7 +100,7 @@ private: rb.PushIpcInterface<ILibraryAppletCreator>(system); } - void GetApplicationFunctions(Kernel::HLERequestContext& ctx) { + void GetApplicationFunctions(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -108,17 +108,17 @@ private: rb.PushIpcInterface<IApplicationFunctions>(system); } - NVFlinger::NVFlinger& nvflinger; + Nvnflinger::Nvnflinger& nvnflinger; std::shared_ptr<AppletMessageQueue> msg_queue; }; class ISystemAppletProxy final : public ServiceFramework<ISystemAppletProxy> { public: - explicit ISystemAppletProxy(NVFlinger::NVFlinger& nvflinger_, + explicit ISystemAppletProxy(Nvnflinger::Nvnflinger& nvnflinger_, std::shared_ptr<AppletMessageQueue> msg_queue_, Core::System& system_) - : ServiceFramework{system_, "ISystemAppletProxy"}, nvflinger{nvflinger_}, - msg_queue{std::move(msg_queue_)} { + : ServiceFramework{system_, "ISystemAppletProxy"}, + nvnflinger{nvnflinger_}, msg_queue{std::move(msg_queue_)} { // clang-format off static const FunctionInfo functions[] = { {0, &ISystemAppletProxy::GetCommonStateGetter, "GetCommonStateGetter"}, @@ -140,7 +140,7 @@ public: } private: - void GetCommonStateGetter(Kernel::HLERequestContext& ctx) { + void GetCommonStateGetter(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -148,15 +148,15 @@ private: rb.PushIpcInterface<ICommonStateGetter>(system, msg_queue); } - void GetSelfController(Kernel::HLERequestContext& ctx) { + void GetSelfController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface<ISelfController>(system, nvflinger); + rb.PushIpcInterface<ISelfController>(system, nvnflinger); } - void GetWindowController(Kernel::HLERequestContext& ctx) { + void GetWindowController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -164,7 +164,7 @@ private: rb.PushIpcInterface<IWindowController>(system); } - void GetAudioController(Kernel::HLERequestContext& ctx) { + void GetAudioController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -172,7 +172,7 @@ private: rb.PushIpcInterface<IAudioController>(system); } - void GetDisplayController(Kernel::HLERequestContext& ctx) { + void GetDisplayController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -180,7 +180,7 @@ private: rb.PushIpcInterface<IDisplayController>(system); } - void GetDebugFunctions(Kernel::HLERequestContext& ctx) { + void GetDebugFunctions(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -188,7 +188,7 @@ private: rb.PushIpcInterface<IDebugFunctions>(system); } - void GetLibraryAppletCreator(Kernel::HLERequestContext& ctx) { + void GetLibraryAppletCreator(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -196,7 +196,7 @@ private: rb.PushIpcInterface<ILibraryAppletCreator>(system); } - void GetHomeMenuFunctions(Kernel::HLERequestContext& ctx) { + void GetHomeMenuFunctions(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -204,7 +204,7 @@ private: rb.PushIpcInterface<IHomeMenuFunctions>(system); } - void GetGlobalStateController(Kernel::HLERequestContext& ctx) { + void GetGlobalStateController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -212,7 +212,7 @@ private: rb.PushIpcInterface<IGlobalStateController>(system); } - void GetApplicationCreator(Kernel::HLERequestContext& ctx) { + void GetApplicationCreator(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -220,38 +220,38 @@ private: rb.PushIpcInterface<IApplicationCreator>(system); } - NVFlinger::NVFlinger& nvflinger; + Nvnflinger::Nvnflinger& nvnflinger; std::shared_ptr<AppletMessageQueue> msg_queue; }; -void AppletAE::OpenSystemAppletProxy(Kernel::HLERequestContext& ctx) { +void AppletAE::OpenSystemAppletProxy(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface<ISystemAppletProxy>(nvflinger, msg_queue, system); + rb.PushIpcInterface<ISystemAppletProxy>(nvnflinger, msg_queue, system); } -void AppletAE::OpenLibraryAppletProxy(Kernel::HLERequestContext& ctx) { +void AppletAE::OpenLibraryAppletProxy(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface<ILibraryAppletProxy>(nvflinger, msg_queue, system); + rb.PushIpcInterface<ILibraryAppletProxy>(nvnflinger, msg_queue, system); } -void AppletAE::OpenLibraryAppletProxyOld(Kernel::HLERequestContext& ctx) { +void AppletAE::OpenLibraryAppletProxyOld(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface<ILibraryAppletProxy>(nvflinger, msg_queue, system); + rb.PushIpcInterface<ILibraryAppletProxy>(nvnflinger, msg_queue, system); } -AppletAE::AppletAE(NVFlinger::NVFlinger& nvflinger_, std::shared_ptr<AppletMessageQueue> msg_queue_, - Core::System& system_) - : ServiceFramework{system_, "appletAE"}, nvflinger{nvflinger_}, msg_queue{ - std::move(msg_queue_)} { +AppletAE::AppletAE(Nvnflinger::Nvnflinger& nvnflinger_, + std::shared_ptr<AppletMessageQueue> msg_queue_, Core::System& system_) + : ServiceFramework{system_, "appletAE"}, nvnflinger{nvnflinger_}, msg_queue{ + std::move(msg_queue_)} { // clang-format off static const FunctionInfo functions[] = { {100, &AppletAE::OpenSystemAppletProxy, "OpenSystemAppletProxy"}, diff --git a/src/core/hle/service/am/applet_ae.h b/src/core/hle/service/am/applet_ae.h index 2147976a6..538ce2903 100644 --- a/src/core/hle/service/am/applet_ae.h +++ b/src/core/hle/service/am/applet_ae.h @@ -12,8 +12,8 @@ namespace FileSystem { class FileSystemController; } -namespace NVFlinger { -class NVFlinger; +namespace Nvnflinger { +class Nvnflinger; } namespace AM { @@ -22,18 +22,18 @@ class AppletMessageQueue; class AppletAE final : public ServiceFramework<AppletAE> { public: - explicit AppletAE(NVFlinger::NVFlinger& nvflinger_, + explicit AppletAE(Nvnflinger::Nvnflinger& nvnflinger_, std::shared_ptr<AppletMessageQueue> msg_queue_, Core::System& system_); ~AppletAE() override; const std::shared_ptr<AppletMessageQueue>& GetMessageQueue() const; private: - void OpenSystemAppletProxy(Kernel::HLERequestContext& ctx); - void OpenLibraryAppletProxy(Kernel::HLERequestContext& ctx); - void OpenLibraryAppletProxyOld(Kernel::HLERequestContext& ctx); + void OpenSystemAppletProxy(HLERequestContext& ctx); + void OpenLibraryAppletProxy(HLERequestContext& ctx); + void OpenLibraryAppletProxyOld(HLERequestContext& ctx); - NVFlinger::NVFlinger& nvflinger; + Nvnflinger::Nvnflinger& nvnflinger; std::shared_ptr<AppletMessageQueue> msg_queue; }; diff --git a/src/core/hle/service/am/applet_oe.cpp b/src/core/hle/service/am/applet_oe.cpp index 00fc4202c..d6c565d85 100644 --- a/src/core/hle/service/am/applet_oe.cpp +++ b/src/core/hle/service/am/applet_oe.cpp @@ -2,20 +2,20 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/am/am.h" #include "core/hle/service/am/applet_oe.h" -#include "core/hle/service/nvflinger/nvflinger.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/nvnflinger/nvnflinger.h" namespace Service::AM { class IApplicationProxy final : public ServiceFramework<IApplicationProxy> { public: - explicit IApplicationProxy(NVFlinger::NVFlinger& nvflinger_, + explicit IApplicationProxy(Nvnflinger::Nvnflinger& nvnflinger_, std::shared_ptr<AppletMessageQueue> msg_queue_, Core::System& system_) - : ServiceFramework{system_, "IApplicationProxy"}, nvflinger{nvflinger_}, - msg_queue{std::move(msg_queue_)} { + : ServiceFramework{system_, "IApplicationProxy"}, + nvnflinger{nvnflinger_}, msg_queue{std::move(msg_queue_)} { // clang-format off static const FunctionInfo functions[] = { {0, &IApplicationProxy::GetCommonStateGetter, "GetCommonStateGetter"}, @@ -34,7 +34,7 @@ public: } private: - void GetAudioController(Kernel::HLERequestContext& ctx) { + void GetAudioController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -42,7 +42,7 @@ private: rb.PushIpcInterface<IAudioController>(system); } - void GetDisplayController(Kernel::HLERequestContext& ctx) { + void GetDisplayController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -50,7 +50,7 @@ private: rb.PushIpcInterface<IDisplayController>(system); } - void GetDebugFunctions(Kernel::HLERequestContext& ctx) { + void GetDebugFunctions(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -58,7 +58,7 @@ private: rb.PushIpcInterface<IDebugFunctions>(system); } - void GetWindowController(Kernel::HLERequestContext& ctx) { + void GetWindowController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -66,15 +66,15 @@ private: rb.PushIpcInterface<IWindowController>(system); } - void GetSelfController(Kernel::HLERequestContext& ctx) { + void GetSelfController(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface<ISelfController>(system, nvflinger); + rb.PushIpcInterface<ISelfController>(system, nvnflinger); } - void GetCommonStateGetter(Kernel::HLERequestContext& ctx) { + void GetCommonStateGetter(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -82,7 +82,7 @@ private: rb.PushIpcInterface<ICommonStateGetter>(system, msg_queue); } - void GetLibraryAppletCreator(Kernel::HLERequestContext& ctx) { + void GetLibraryAppletCreator(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -90,7 +90,7 @@ private: rb.PushIpcInterface<ILibraryAppletCreator>(system); } - void GetApplicationFunctions(Kernel::HLERequestContext& ctx) { + void GetApplicationFunctions(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -98,22 +98,22 @@ private: rb.PushIpcInterface<IApplicationFunctions>(system); } - NVFlinger::NVFlinger& nvflinger; + Nvnflinger::Nvnflinger& nvnflinger; std::shared_ptr<AppletMessageQueue> msg_queue; }; -void AppletOE::OpenApplicationProxy(Kernel::HLERequestContext& ctx) { +void AppletOE::OpenApplicationProxy(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface<IApplicationProxy>(nvflinger, msg_queue, system); + rb.PushIpcInterface<IApplicationProxy>(nvnflinger, msg_queue, system); } -AppletOE::AppletOE(NVFlinger::NVFlinger& nvflinger_, std::shared_ptr<AppletMessageQueue> msg_queue_, - Core::System& system_) - : ServiceFramework{system_, "appletOE"}, nvflinger{nvflinger_}, msg_queue{ - std::move(msg_queue_)} { +AppletOE::AppletOE(Nvnflinger::Nvnflinger& nvnflinger_, + std::shared_ptr<AppletMessageQueue> msg_queue_, Core::System& system_) + : ServiceFramework{system_, "appletOE"}, nvnflinger{nvnflinger_}, msg_queue{ + std::move(msg_queue_)} { static const FunctionInfo functions[] = { {0, &AppletOE::OpenApplicationProxy, "OpenApplicationProxy"}, }; diff --git a/src/core/hle/service/am/applet_oe.h b/src/core/hle/service/am/applet_oe.h index 8fea249f1..39eccc4ab 100644 --- a/src/core/hle/service/am/applet_oe.h +++ b/src/core/hle/service/am/applet_oe.h @@ -12,8 +12,8 @@ namespace FileSystem { class FileSystemController; } -namespace NVFlinger { -class NVFlinger; +namespace Nvnflinger { +class Nvnflinger; } namespace AM { @@ -22,16 +22,16 @@ class AppletMessageQueue; class AppletOE final : public ServiceFramework<AppletOE> { public: - explicit AppletOE(NVFlinger::NVFlinger& nvflinger_, + explicit AppletOE(Nvnflinger::Nvnflinger& nvnflinger_, std::shared_ptr<AppletMessageQueue> msg_queue_, Core::System& system_); ~AppletOE() override; const std::shared_ptr<AppletMessageQueue>& GetMessageQueue() const; private: - void OpenApplicationProxy(Kernel::HLERequestContext& ctx); + void OpenApplicationProxy(HLERequestContext& ctx); - NVFlinger::NVFlinger& nvflinger; + Nvnflinger::Nvnflinger& nvnflinger; std::shared_ptr<AppletMessageQueue> msg_queue; }; diff --git a/src/core/hle/service/am/applets/applet_controller.cpp b/src/core/hle/service/am/applets/applet_controller.cpp index b418031de..58484519b 100644 --- a/src/core/hle/service/am/applets/applet_controller.cpp +++ b/src/core/hle/service/am/applets/applet_controller.cpp @@ -19,10 +19,9 @@ namespace Service::AM::Applets { -// This error code (0x183ACA) is thrown when the applet fails to initialize. -[[maybe_unused]] constexpr Result ERR_CONTROLLER_APPLET_3101{ErrorModule::HID, 3101}; -// This error code (0x183CCA) is thrown when the u32 result in ControllerSupportResultInfo is 2. -[[maybe_unused]] constexpr Result ERR_CONTROLLER_APPLET_3102{ErrorModule::HID, 3102}; +[[maybe_unused]] constexpr Result ResultControllerSupportCanceled{ErrorModule::HID, 3101}; +[[maybe_unused]] constexpr Result ResultControllerSupportNotSupportedNpadStyle{ErrorModule::HID, + 3102}; static Core::Frontend::ControllerParameters ConvertToFrontendParameters( ControllerSupportArgPrivate private_arg, ControllerSupportArgHeader header, bool enable_text, diff --git a/src/core/hle/service/am/applets/applet_profile_select.cpp b/src/core/hle/service/am/applets/applet_profile_select.cpp index c738db028..1d69f5447 100644 --- a/src/core/hle/service/am/applets/applet_profile_select.cpp +++ b/src/core/hle/service/am/applets/applet_profile_select.cpp @@ -7,13 +7,12 @@ #include "common/string_util.h" #include "core/core.h" #include "core/frontend/applets/profile_select.h" +#include "core/hle/service/acc/errors.h" #include "core/hle/service/am/am.h" #include "core/hle/service/am/applets/applet_profile_select.h" namespace Service::AM::Applets { -constexpr Result ERR_USER_CANCELLED_SELECTION{ErrorModule::Account, 1}; - ProfileSelect::ProfileSelect(Core::System& system_, LibraryAppletMode applet_mode_, const Core::Frontend::ProfileSelectApplet& frontend_) : Applet{system_, applet_mode_}, frontend{frontend_}, system{system_} {} @@ -63,8 +62,8 @@ void ProfileSelect::SelectionComplete(std::optional<Common::UUID> uuid) { output.result = 0; output.uuid_selected = *uuid; } else { - status = ERR_USER_CANCELLED_SELECTION; - output.result = ERR_USER_CANCELLED_SELECTION.raw; + status = Account::ResultCancelledByUser; + output.result = Account::ResultCancelledByUser.raw; output.uuid_selected = Common::InvalidUUID; } diff --git a/src/core/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp index 1bbf057cb..38c2138e8 100644 --- a/src/core/hle/service/aoc/aoc_u.cpp +++ b/src/core/hle/service/aoc/aoc_u.cpp @@ -14,9 +14,10 @@ #include "core/file_sys/nca_metadata.h" #include "core/file_sys/patch_manager.h" #include "core/file_sys/registered_cache.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" #include "core/hle/service/aoc/aoc_u.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/loader/loader.h" namespace Service::AOC { @@ -68,7 +69,7 @@ public: } private: - void SetDefaultDeliveryTarget(Kernel::HLERequestContext& ctx) { + void SetDefaultDeliveryTarget(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto unknown_1 = rp.Pop<u64>(); @@ -80,7 +81,7 @@ private: rb.Push(ResultSuccess); } - void SetDeliveryTarget(Kernel::HLERequestContext& ctx) { + void SetDeliveryTarget(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto unknown_1 = rp.Pop<u64>(); @@ -92,7 +93,7 @@ private: rb.Push(ResultSuccess); } - void GetPurchasedEventReadableHandle(Kernel::HLERequestContext& ctx) { + void GetPurchasedEventReadableHandle(HLERequestContext& ctx) { LOG_WARNING(Service_AOC, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -144,7 +145,7 @@ AOC_U::~AOC_U() { service_context.CloseEvent(aoc_change_event); } -void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) { +void AOC_U::CountAddOnContent(HLERequestContext& ctx) { struct Parameters { u64 process_id; }; @@ -171,7 +172,7 @@ void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) { [current](u64 tid) { return CheckAOCTitleIDMatchesBase(tid, current); }))); } -void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) { +void AOC_U::ListAddOnContent(HLERequestContext& ctx) { struct Parameters { u32 offset; u32 count; @@ -217,7 +218,7 @@ void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) { rb.Push(out_count); } -void AOC_U::GetAddOnContentBaseId(Kernel::HLERequestContext& ctx) { +void AOC_U::GetAddOnContentBaseId(HLERequestContext& ctx) { struct Parameters { u64 process_id; }; @@ -244,7 +245,7 @@ void AOC_U::GetAddOnContentBaseId(Kernel::HLERequestContext& ctx) { rb.Push(res.first->GetDLCBaseTitleId()); } -void AOC_U::PrepareAddOnContent(Kernel::HLERequestContext& ctx) { +void AOC_U::PrepareAddOnContent(HLERequestContext& ctx) { struct Parameters { s32 addon_index; u64 process_id; @@ -261,7 +262,7 @@ void AOC_U::PrepareAddOnContent(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void AOC_U::GetAddOnContentListChangedEvent(Kernel::HLERequestContext& ctx) { +void AOC_U::GetAddOnContentListChangedEvent(HLERequestContext& ctx) { LOG_WARNING(Service_AOC, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -269,7 +270,7 @@ void AOC_U::GetAddOnContentListChangedEvent(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(aoc_change_event->GetReadableEvent()); } -void AOC_U::GetAddOnContentListChangedEventWithProcessId(Kernel::HLERequestContext& ctx) { +void AOC_U::GetAddOnContentListChangedEventWithProcessId(HLERequestContext& ctx) { LOG_WARNING(Service_AOC, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -277,28 +278,28 @@ void AOC_U::GetAddOnContentListChangedEventWithProcessId(Kernel::HLERequestConte rb.PushCopyObjects(aoc_change_event->GetReadableEvent()); } -void AOC_U::NotifyMountAddOnContent(Kernel::HLERequestContext& ctx) { +void AOC_U::NotifyMountAddOnContent(HLERequestContext& ctx) { LOG_WARNING(Service_AOC, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void AOC_U::NotifyUnmountAddOnContent(Kernel::HLERequestContext& ctx) { +void AOC_U::NotifyUnmountAddOnContent(HLERequestContext& ctx) { LOG_WARNING(Service_AOC, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void AOC_U::CheckAddOnContentMountStatus(Kernel::HLERequestContext& ctx) { +void AOC_U::CheckAddOnContentMountStatus(HLERequestContext& ctx) { LOG_WARNING(Service_AOC, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void AOC_U::CreateEcPurchasedEventManager(Kernel::HLERequestContext& ctx) { +void AOC_U::CreateEcPurchasedEventManager(HLERequestContext& ctx) { LOG_WARNING(Service_AOC, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -306,7 +307,7 @@ void AOC_U::CreateEcPurchasedEventManager(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IPurchaseEventManager>(system); } -void AOC_U::CreatePermanentEcPurchasedEventManager(Kernel::HLERequestContext& ctx) { +void AOC_U::CreatePermanentEcPurchasedEventManager(HLERequestContext& ctx) { LOG_WARNING(Service_AOC, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -314,8 +315,10 @@ void AOC_U::CreatePermanentEcPurchasedEventManager(Kernel::HLERequestContext& ct rb.PushIpcInterface<IPurchaseEventManager>(system); } -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<AOC_U>(system)->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + server_manager->RegisterNamedService("aoc:u", std::make_shared<AOC_U>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::AOC diff --git a/src/core/hle/service/aoc/aoc_u.h b/src/core/hle/service/aoc/aoc_u.h index 6c1ce601a..12ccfeb6a 100644 --- a/src/core/hle/service/aoc/aoc_u.h +++ b/src/core/hle/service/aoc/aoc_u.h @@ -22,17 +22,17 @@ public: ~AOC_U() override; private: - void CountAddOnContent(Kernel::HLERequestContext& ctx); - void ListAddOnContent(Kernel::HLERequestContext& ctx); - void GetAddOnContentBaseId(Kernel::HLERequestContext& ctx); - void PrepareAddOnContent(Kernel::HLERequestContext& ctx); - void GetAddOnContentListChangedEvent(Kernel::HLERequestContext& ctx); - void GetAddOnContentListChangedEventWithProcessId(Kernel::HLERequestContext& ctx); - void NotifyMountAddOnContent(Kernel::HLERequestContext& ctx); - void NotifyUnmountAddOnContent(Kernel::HLERequestContext& ctx); - void CheckAddOnContentMountStatus(Kernel::HLERequestContext& ctx); - void CreateEcPurchasedEventManager(Kernel::HLERequestContext& ctx); - void CreatePermanentEcPurchasedEventManager(Kernel::HLERequestContext& ctx); + void CountAddOnContent(HLERequestContext& ctx); + void ListAddOnContent(HLERequestContext& ctx); + void GetAddOnContentBaseId(HLERequestContext& ctx); + void PrepareAddOnContent(HLERequestContext& ctx); + void GetAddOnContentListChangedEvent(HLERequestContext& ctx); + void GetAddOnContentListChangedEventWithProcessId(HLERequestContext& ctx); + void NotifyMountAddOnContent(HLERequestContext& ctx); + void NotifyUnmountAddOnContent(HLERequestContext& ctx); + void CheckAddOnContentMountStatus(HLERequestContext& ctx); + void CreateEcPurchasedEventManager(HLERequestContext& ctx); + void CreatePermanentEcPurchasedEventManager(HLERequestContext& ctx); std::vector<u64> add_on_content; KernelHelpers::ServiceContext service_context; @@ -40,7 +40,6 @@ private: Kernel::KEvent* aoc_change_event; }; -/// Registers all AOC services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::AOC diff --git a/src/core/hle/service/apm/apm.cpp b/src/core/hle/service/apm/apm.cpp index 44b2927a6..c23ff293d 100644 --- a/src/core/hle/service/apm/apm.cpp +++ b/src/core/hle/service/apm/apm.cpp @@ -4,20 +4,24 @@ #include "core/core.h" #include "core/hle/service/apm/apm.h" #include "core/hle/service/apm/apm_interface.h" +#include "core/hle/service/server_manager.h" namespace Service::APM { Module::Module() = default; Module::~Module() = default; -void InstallInterfaces(Core::System& system) { - auto module_ = std::make_shared<Module>(); - std::make_shared<APM>(system, module_, system.GetAPMController(), "apm") - ->InstallAsService(system.ServiceManager()); - std::make_shared<APM>(system, module_, system.GetAPMController(), "apm:am") - ->InstallAsService(system.ServiceManager()); - std::make_shared<APM_Sys>(system, system.GetAPMController()) - ->InstallAsService(system.ServiceManager()); +void LoopProcess(Core::System& system) { + auto module = std::make_shared<Module>(); + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService( + "apm", std::make_shared<APM>(system, module, system.GetAPMController(), "apm")); + server_manager->RegisterNamedService( + "apm:am", std::make_shared<APM>(system, module, system.GetAPMController(), "apm:am")); + server_manager->RegisterNamedService( + "apm:sys", std::make_shared<APM_Sys>(system, system.GetAPMController())); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::APM diff --git a/src/core/hle/service/apm/apm.h b/src/core/hle/service/apm/apm.h index 0fecc766a..e188b4e44 100644 --- a/src/core/hle/service/apm/apm.h +++ b/src/core/hle/service/apm/apm.h @@ -15,7 +15,6 @@ public: ~Module(); }; -/// Registers all AM services with the specified service manager. -void InstallInterfaces(Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::APM diff --git a/src/core/hle/service/apm/apm_interface.cpp b/src/core/hle/service/apm/apm_interface.cpp index 041fc16bd..d29051ee7 100644 --- a/src/core/hle/service/apm/apm_interface.cpp +++ b/src/core/hle/service/apm/apm_interface.cpp @@ -2,10 +2,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/apm/apm.h" #include "core/hle/service/apm/apm_controller.h" #include "core/hle/service/apm/apm_interface.h" +#include "core/hle/service/ipc_helpers.h" namespace Service::APM { @@ -22,7 +22,7 @@ public: } private: - void SetPerformanceConfiguration(Kernel::HLERequestContext& ctx) { + void SetPerformanceConfiguration(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto mode = rp.PopEnum<PerformanceMode>(); @@ -35,7 +35,7 @@ private: rb.Push(ResultSuccess); } - void GetPerformanceConfiguration(Kernel::HLERequestContext& ctx) { + void GetPerformanceConfiguration(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto mode = rp.PopEnum<PerformanceMode>(); @@ -46,7 +46,7 @@ private: rb.PushEnum(controller.GetCurrentPerformanceConfiguration(mode)); } - void SetCpuOverclockEnabled(Kernel::HLERequestContext& ctx) { + void SetCpuOverclockEnabled(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto cpu_overclock_enabled = rp.Pop<bool>(); @@ -74,7 +74,7 @@ APM::APM(Core::System& system_, std::shared_ptr<Module> apm_, Controller& contro APM::~APM() = default; -void APM::OpenSession(Kernel::HLERequestContext& ctx) { +void APM::OpenSession(HLERequestContext& ctx) { LOG_DEBUG(Service_APM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -82,14 +82,14 @@ void APM::OpenSession(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<ISession>(system, controller); } -void APM::GetPerformanceMode(Kernel::HLERequestContext& ctx) { +void APM::GetPerformanceMode(HLERequestContext& ctx) { LOG_DEBUG(Service_APM, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.PushEnum(controller.GetCurrentPerformanceMode()); } -void APM::IsCpuOverclockEnabled(Kernel::HLERequestContext& ctx) { +void APM::IsCpuOverclockEnabled(HLERequestContext& ctx) { LOG_WARNING(Service_APM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -117,7 +117,7 @@ APM_Sys::APM_Sys(Core::System& system_, Controller& controller_) APM_Sys::~APM_Sys() = default; -void APM_Sys::GetPerformanceEvent(Kernel::HLERequestContext& ctx) { +void APM_Sys::GetPerformanceEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_APM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -125,7 +125,7 @@ void APM_Sys::GetPerformanceEvent(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<ISession>(system, controller); } -void APM_Sys::SetCpuBoostMode(Kernel::HLERequestContext& ctx) { +void APM_Sys::SetCpuBoostMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto mode = rp.PopEnum<CpuBoostMode>(); @@ -137,7 +137,7 @@ void APM_Sys::SetCpuBoostMode(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void APM_Sys::GetCurrentPerformanceConfiguration(Kernel::HLERequestContext& ctx) { +void APM_Sys::GetCurrentPerformanceConfiguration(HLERequestContext& ctx) { LOG_DEBUG(Service_APM, "called"); IPC::ResponseBuilder rb{ctx, 3}; diff --git a/src/core/hle/service/apm/apm_interface.h b/src/core/hle/service/apm/apm_interface.h index 0740fd4ba..58718453b 100644 --- a/src/core/hle/service/apm/apm_interface.h +++ b/src/core/hle/service/apm/apm_interface.h @@ -17,9 +17,9 @@ public: ~APM() override; private: - void OpenSession(Kernel::HLERequestContext& ctx); - void GetPerformanceMode(Kernel::HLERequestContext& ctx); - void IsCpuOverclockEnabled(Kernel::HLERequestContext& ctx); + void OpenSession(HLERequestContext& ctx); + void GetPerformanceMode(HLERequestContext& ctx); + void IsCpuOverclockEnabled(HLERequestContext& ctx); std::shared_ptr<Module> apm; Controller& controller; @@ -30,11 +30,11 @@ public: explicit APM_Sys(Core::System& system_, Controller& controller); ~APM_Sys() override; - void SetCpuBoostMode(Kernel::HLERequestContext& ctx); + void SetCpuBoostMode(HLERequestContext& ctx); private: - void GetPerformanceEvent(Kernel::HLERequestContext& ctx); - void GetCurrentPerformanceConfiguration(Kernel::HLERequestContext& ctx); + void GetPerformanceEvent(HLERequestContext& ctx); + void GetCurrentPerformanceConfiguration(HLERequestContext& ctx); Controller& controller; }; diff --git a/src/core/hle/service/audio/audctl.cpp b/src/core/hle/service/audio/audctl.cpp index 5abf22ba4..7ad93be6b 100644 --- a/src/core/hle/service/audio/audctl.cpp +++ b/src/core/hle/service/audio/audctl.cpp @@ -2,8 +2,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/audio/audctl.h" +#include "core/hle/service/ipc_helpers.h" namespace Service::Audio { @@ -72,7 +72,7 @@ AudCtl::AudCtl(Core::System& system_) : ServiceFramework{system_, "audctl"} { AudCtl::~AudCtl() = default; -void AudCtl::GetTargetVolumeMin(Kernel::HLERequestContext& ctx) { +void AudCtl::GetTargetVolumeMin(HLERequestContext& ctx) { LOG_DEBUG(Audio, "called."); // This service function is currently hardcoded on the @@ -84,7 +84,7 @@ void AudCtl::GetTargetVolumeMin(Kernel::HLERequestContext& ctx) { rb.Push(target_min_volume); } -void AudCtl::GetTargetVolumeMax(Kernel::HLERequestContext& ctx) { +void AudCtl::GetTargetVolumeMax(HLERequestContext& ctx) { LOG_DEBUG(Audio, "called."); // This service function is currently hardcoded on the diff --git a/src/core/hle/service/audio/audctl.h b/src/core/hle/service/audio/audctl.h index a27ff6cfe..8e31ac237 100644 --- a/src/core/hle/service/audio/audctl.h +++ b/src/core/hle/service/audio/audctl.h @@ -17,8 +17,8 @@ public: ~AudCtl() override; private: - void GetTargetVolumeMin(Kernel::HLERequestContext& ctx); - void GetTargetVolumeMax(Kernel::HLERequestContext& ctx); + void GetTargetVolumeMin(HLERequestContext& ctx); + void GetTargetVolumeMax(HLERequestContext& ctx); }; } // namespace Service::Audio diff --git a/src/core/hle/service/audio/audin_u.cpp b/src/core/hle/service/audio/audin_u.cpp index 053e8f9dd..f0640c64f 100644 --- a/src/core/hle/service/audio/audin_u.cpp +++ b/src/core/hle/service/audio/audin_u.cpp @@ -7,9 +7,9 @@ #include "common/logging/log.h" #include "common/string_util.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" #include "core/hle/service/audio/audin_u.h" +#include "core/hle/service/ipc_helpers.h" namespace Service::Audio { using namespace AudioCore::AudioIn; @@ -61,7 +61,7 @@ public: } private: - void GetAudioInState(Kernel::HLERequestContext& ctx) { + void GetAudioInState(HLERequestContext& ctx) { const auto state = static_cast<u32>(impl->GetState()); LOG_DEBUG(Service_Audio, "called. State={}", state); @@ -71,7 +71,7 @@ private: rb.Push(state); } - void Start(Kernel::HLERequestContext& ctx) { + void Start(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); auto result = impl->StartSystem(); @@ -80,7 +80,7 @@ private: rb.Push(result); } - void Stop(Kernel::HLERequestContext& ctx) { + void Stop(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); auto result = impl->StopSystem(); @@ -89,7 +89,7 @@ private: rb.Push(result); } - void AppendAudioInBuffer(Kernel::HLERequestContext& ctx) { + void AppendAudioInBuffer(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; u64 tag = rp.PopRaw<u64>(); @@ -111,7 +111,7 @@ private: rb.Push(result); } - void RegisterBufferEvent(Kernel::HLERequestContext& ctx) { + void RegisterBufferEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); auto& buffer_event = impl->GetBufferEvent(); @@ -121,7 +121,7 @@ private: rb.PushCopyObjects(buffer_event); } - void GetReleasedAudioInBuffer(Kernel::HLERequestContext& ctx) { + void GetReleasedAudioInBuffer(HLERequestContext& ctx) { const auto write_buffer_size = ctx.GetWriteBufferNumElements<u64>(); std::vector<u64> released_buffers(write_buffer_size); @@ -141,7 +141,7 @@ private: rb.Push(count); } - void ContainsAudioInBuffer(Kernel::HLERequestContext& ctx) { + void ContainsAudioInBuffer(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 tag{rp.Pop<u64>()}; @@ -154,7 +154,7 @@ private: rb.Push(buffer_queued); } - void GetAudioInBufferCount(Kernel::HLERequestContext& ctx) { + void GetAudioInBufferCount(HLERequestContext& ctx) { const auto buffer_count = impl->GetBufferCount(); LOG_DEBUG(Service_Audio, "called. Buffer count={}", buffer_count); @@ -165,7 +165,7 @@ private: rb.Push(buffer_count); } - void SetDeviceGain(Kernel::HLERequestContext& ctx) { + void SetDeviceGain(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto volume{rp.Pop<f32>()}; @@ -177,7 +177,7 @@ private: rb.Push(ResultSuccess); } - void GetDeviceGain(Kernel::HLERequestContext& ctx) { + void GetDeviceGain(HLERequestContext& ctx) { auto volume{impl->GetVolume()}; LOG_DEBUG(Service_Audio, "called. Gain {}", volume); @@ -187,7 +187,7 @@ private: rb.Push(volume); } - void FlushAudioInBuffers(Kernel::HLERequestContext& ctx) { + void FlushAudioInBuffers(HLERequestContext& ctx) { bool flushed{impl->FlushAudioInBuffers()}; LOG_DEBUG(Service_Audio, "called. Were any buffers flushed? {}", flushed); @@ -203,9 +203,8 @@ private: }; AudInU::AudInU(Core::System& system_) - : ServiceFramework{system_, "audin:u", ServiceThreadType::CreateNew}, - service_context{system_, "AudInU"}, impl{std::make_unique<AudioCore::AudioIn::Manager>( - system_)} { + : ServiceFramework{system_, "audin:u"}, service_context{system_, "AudInU"}, + impl{std::make_unique<AudioCore::AudioIn::Manager>(system_)} { // clang-format off static const FunctionInfo functions[] = { {0, &AudInU::ListAudioIns, "ListAudioIns"}, @@ -222,7 +221,7 @@ AudInU::AudInU(Core::System& system_) AudInU::~AudInU() = default; -void AudInU::ListAudioIns(Kernel::HLERequestContext& ctx) { +void AudInU::ListAudioIns(HLERequestContext& ctx) { using namespace AudioCore::AudioRenderer; LOG_DEBUG(Service_Audio, "called"); @@ -242,7 +241,7 @@ void AudInU::ListAudioIns(Kernel::HLERequestContext& ctx) { rb.Push(out_count); } -void AudInU::ListAudioInsAutoFiltered(Kernel::HLERequestContext& ctx) { +void AudInU::ListAudioInsAutoFiltered(HLERequestContext& ctx) { using namespace AudioCore::AudioRenderer; LOG_DEBUG(Service_Audio, "called"); @@ -262,7 +261,7 @@ void AudInU::ListAudioInsAutoFiltered(Kernel::HLERequestContext& ctx) { rb.Push(out_count); } -void AudInU::OpenAudioIn(Kernel::HLERequestContext& ctx) { +void AudInU::OpenAudioIn(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; auto in_params{rp.PopRaw<AudioInParameter>()}; auto applet_resource_user_id{rp.PopRaw<u64>()}; @@ -312,7 +311,7 @@ void AudInU::OpenAudioIn(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IAudioIn>(audio_in); } -void AudInU::OpenAudioInProtocolSpecified(Kernel::HLERequestContext& ctx) { +void AudInU::OpenAudioInProtocolSpecified(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; auto protocol_specified{rp.PopRaw<u64>()}; auto in_params{rp.PopRaw<AudioInParameter>()}; diff --git a/src/core/hle/service/audio/audin_u.h b/src/core/hle/service/audio/audin_u.h index b45fda78a..51e770ff9 100644 --- a/src/core/hle/service/audio/audin_u.h +++ b/src/core/hle/service/audio/audin_u.h @@ -12,10 +12,6 @@ namespace Core { class System; } -namespace Kernel { -class HLERequestContext; -} - namespace AudioCore::AudioOut { class Manager; class In; @@ -29,11 +25,11 @@ public: ~AudInU() override; private: - void ListAudioIns(Kernel::HLERequestContext& ctx); - void ListAudioInsAutoFiltered(Kernel::HLERequestContext& ctx); - void OpenInOutImpl(Kernel::HLERequestContext& ctx); - void OpenAudioIn(Kernel::HLERequestContext& ctx); - void OpenAudioInProtocolSpecified(Kernel::HLERequestContext& ctx); + void ListAudioIns(HLERequestContext& ctx); + void ListAudioInsAutoFiltered(HLERequestContext& ctx); + void OpenInOutImpl(HLERequestContext& ctx); + void OpenAudioIn(HLERequestContext& ctx); + void OpenAudioInProtocolSpecified(HLERequestContext& ctx); KernelHelpers::ServiceContext service_context; std::unique_ptr<AudioCore::AudioIn::Manager> impl; diff --git a/src/core/hle/service/audio/audio.cpp b/src/core/hle/service/audio/audio.cpp index ed36e3448..dccd16309 100644 --- a/src/core/hle/service/audio/audio.cpp +++ b/src/core/hle/service/audio/audio.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "core/core.h" #include "core/hle/service/audio/audctl.h" #include "core/hle/service/audio/audin_u.h" #include "core/hle/service/audio/audio.h" @@ -9,18 +10,22 @@ #include "core/hle/service/audio/audrec_u.h" #include "core/hle/service/audio/audren_u.h" #include "core/hle/service/audio/hwopus.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" namespace Service::Audio { -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<AudCtl>(system)->InstallAsService(service_manager); - std::make_shared<AudOutU>(system)->InstallAsService(service_manager); - std::make_shared<AudInU>(system)->InstallAsService(service_manager); - std::make_shared<AudRecA>(system)->InstallAsService(service_manager); - std::make_shared<AudRecU>(system)->InstallAsService(service_manager); - std::make_shared<AudRenU>(system)->InstallAsService(service_manager); - std::make_shared<HwOpus>(system)->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("audctl", std::make_shared<AudCtl>(system)); + server_manager->RegisterNamedService("audout:u", std::make_shared<AudOutU>(system)); + server_manager->RegisterNamedService("audin:u", std::make_shared<AudInU>(system)); + server_manager->RegisterNamedService("audrec:a", std::make_shared<AudRecA>(system)); + server_manager->RegisterNamedService("audrec:u", std::make_shared<AudRecU>(system)); + server_manager->RegisterNamedService("audren:u", std::make_shared<AudRenU>(system)); + server_manager->RegisterNamedService("hwopus", std::make_shared<HwOpus>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::Audio diff --git a/src/core/hle/service/audio/audio.h b/src/core/hle/service/audio/audio.h index bbb2214e4..d70f022c7 100644 --- a/src/core/hle/service/audio/audio.h +++ b/src/core/hle/service/audio/audio.h @@ -13,7 +13,6 @@ class ServiceManager; namespace Service::Audio { -/// Registers all Audio services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::Audio diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index 29751f075..23b8be993 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp @@ -12,10 +12,10 @@ #include "common/string_util.h" #include "common/swap.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" #include "core/hle/service/audio/audout_u.h" #include "core/hle/service/audio/errors.h" +#include "core/hle/service/ipc_helpers.h" #include "core/memory.h" namespace Service::Audio { @@ -26,9 +26,8 @@ public: explicit IAudioOut(Core::System& system_, AudioCore::AudioOut::Manager& manager, size_t session_id, const std::string& device_name, const AudioOutParameter& in_params, u32 handle, u64 applet_resource_user_id) - : ServiceFramework{system_, "IAudioOut", ServiceThreadType::CreateNew}, - service_context{system_, "IAudioOut"}, event{service_context.CreateEvent( - "AudioOutEvent")}, + : ServiceFramework{system_, "IAudioOut"}, service_context{system_, "IAudioOut"}, + event{service_context.CreateEvent("AudioOutEvent")}, impl{std::make_shared<AudioCore::AudioOut::Out>(system_, manager, event, session_id)} { // clang-format off @@ -68,7 +67,7 @@ public: } private: - void GetAudioOutState(Kernel::HLERequestContext& ctx) { + void GetAudioOutState(HLERequestContext& ctx) { const auto state = static_cast<u32>(impl->GetState()); LOG_DEBUG(Service_Audio, "called. State={}", state); @@ -78,7 +77,7 @@ private: rb.Push(state); } - void Start(Kernel::HLERequestContext& ctx) { + void Start(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); auto result = impl->StartSystem(); @@ -87,7 +86,7 @@ private: rb.Push(result); } - void Stop(Kernel::HLERequestContext& ctx) { + void Stop(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); auto result = impl->StopSystem(); @@ -96,7 +95,7 @@ private: rb.Push(result); } - void AppendAudioOutBuffer(Kernel::HLERequestContext& ctx) { + void AppendAudioOutBuffer(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; u64 tag = rp.PopRaw<u64>(); @@ -118,7 +117,7 @@ private: rb.Push(result); } - void RegisterBufferEvent(Kernel::HLERequestContext& ctx) { + void RegisterBufferEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); auto& buffer_event = impl->GetBufferEvent(); @@ -128,7 +127,7 @@ private: rb.PushCopyObjects(buffer_event); } - void GetReleasedAudioOutBuffers(Kernel::HLERequestContext& ctx) { + void GetReleasedAudioOutBuffers(HLERequestContext& ctx) { const auto write_buffer_size = ctx.GetWriteBufferNumElements<u64>(); std::vector<u64> released_buffers(write_buffer_size); @@ -148,7 +147,7 @@ private: rb.Push(count); } - void ContainsAudioOutBuffer(Kernel::HLERequestContext& ctx) { + void ContainsAudioOutBuffer(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 tag{rp.Pop<u64>()}; @@ -161,7 +160,7 @@ private: rb.Push(buffer_queued); } - void GetAudioOutBufferCount(Kernel::HLERequestContext& ctx) { + void GetAudioOutBufferCount(HLERequestContext& ctx) { const auto buffer_count = impl->GetBufferCount(); LOG_DEBUG(Service_Audio, "called. Buffer count={}", buffer_count); @@ -172,7 +171,7 @@ private: rb.Push(buffer_count); } - void GetAudioOutPlayedSampleCount(Kernel::HLERequestContext& ctx) { + void GetAudioOutPlayedSampleCount(HLERequestContext& ctx) { const auto samples_played = impl->GetPlayedSampleCount(); LOG_DEBUG(Service_Audio, "called. Played samples={}", samples_played); @@ -183,7 +182,7 @@ private: rb.Push(samples_played); } - void FlushAudioOutBuffers(Kernel::HLERequestContext& ctx) { + void FlushAudioOutBuffers(HLERequestContext& ctx) { bool flushed{impl->FlushAudioOutBuffers()}; LOG_DEBUG(Service_Audio, "called. Were any buffers flushed? {}", flushed); @@ -193,7 +192,7 @@ private: rb.Push(flushed); } - void SetAudioOutVolume(Kernel::HLERequestContext& ctx) { + void SetAudioOutVolume(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto volume = rp.Pop<f32>(); @@ -205,7 +204,7 @@ private: rb.Push(ResultSuccess); } - void GetAudioOutVolume(Kernel::HLERequestContext& ctx) { + void GetAudioOutVolume(HLERequestContext& ctx) { const auto volume = impl->GetVolume(); LOG_DEBUG(Service_Audio, "called. Volume={}", volume); @@ -221,9 +220,8 @@ private: }; AudOutU::AudOutU(Core::System& system_) - : ServiceFramework{system_, "audout:u", ServiceThreadType::CreateNew}, - service_context{system_, "AudOutU"}, impl{std::make_unique<AudioCore::AudioOut::Manager>( - system_)} { + : ServiceFramework{system_, "audout:u"}, service_context{system_, "AudOutU"}, + impl{std::make_unique<AudioCore::AudioOut::Manager>(system_)} { // clang-format off static const FunctionInfo functions[] = { {0, &AudOutU::ListAudioOuts, "ListAudioOuts"}, @@ -238,7 +236,7 @@ AudOutU::AudOutU(Core::System& system_) AudOutU::~AudOutU() = default; -void AudOutU::ListAudioOuts(Kernel::HLERequestContext& ctx) { +void AudOutU::ListAudioOuts(HLERequestContext& ctx) { using namespace AudioCore::AudioRenderer; std::scoped_lock l{impl->mutex}; @@ -260,7 +258,7 @@ void AudOutU::ListAudioOuts(Kernel::HLERequestContext& ctx) { rb.Push<u32>(static_cast<u32>(device_names.size())); } -void AudOutU::OpenAudioOut(Kernel::HLERequestContext& ctx) { +void AudOutU::OpenAudioOut(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; auto in_params{rp.PopRaw<AudioOutParameter>()}; auto applet_resource_user_id{rp.PopRaw<u64>()}; diff --git a/src/core/hle/service/audio/audout_u.h b/src/core/hle/service/audio/audout_u.h index fdc0ee754..8f288c6e0 100644 --- a/src/core/hle/service/audio/audout_u.h +++ b/src/core/hle/service/audio/audout_u.h @@ -12,10 +12,6 @@ namespace Core { class System; } -namespace Kernel { -class HLERequestContext; -} - namespace AudioCore::AudioOut { class Manager; class Out; @@ -31,8 +27,8 @@ public: ~AudOutU() override; private: - void ListAudioOuts(Kernel::HLERequestContext& ctx); - void OpenAudioOut(Kernel::HLERequestContext& ctx); + void ListAudioOuts(HLERequestContext& ctx); + void OpenAudioOut(HLERequestContext& ctx); KernelHelpers::ServiceContext service_context; std::unique_ptr<AudioCore::AudioOut::Manager> impl; diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index 7d730421d..7086d4750 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp @@ -17,12 +17,12 @@ #include "common/polyfill_ranges.h" #include "common/string_util.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" #include "core/hle/kernel/k_process.h" #include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/service/audio/audren_u.h" #include "core/hle/service/audio/errors.h" +#include "core/hle/service/ipc_helpers.h" #include "core/memory.h" using namespace AudioCore::AudioRenderer; @@ -35,10 +35,9 @@ public: AudioCore::AudioRendererParameterInternal& params, Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size, u32 process_handle, u64 applet_resource_user_id, s32 session_id) - : ServiceFramework{system_, "IAudioRenderer", ServiceThreadType::CreateNew}, - service_context{system_, "IAudioRenderer"}, rendered_event{service_context.CreateEvent( - "IAudioRendererEvent")}, - manager{manager_}, impl{std::make_unique<Renderer>(system_, manager, rendered_event)} { + : ServiceFramework{system_, "IAudioRenderer"}, service_context{system_, "IAudioRenderer"}, + rendered_event{service_context.CreateEvent("IAudioRendererEvent")}, manager{manager_}, + impl{std::make_unique<Renderer>(system_, manager, rendered_event)} { // clang-format off static const FunctionInfo functions[] = { {0, &IAudioRenderer::GetSampleRate, "GetSampleRate"}, @@ -69,7 +68,7 @@ public: } private: - void GetSampleRate(Kernel::HLERequestContext& ctx) { + void GetSampleRate(HLERequestContext& ctx) { const auto sample_rate{impl->GetSystem().GetSampleRate()}; LOG_DEBUG(Service_Audio, "called. Sample rate {}", sample_rate); @@ -79,7 +78,7 @@ private: rb.Push(sample_rate); } - void GetSampleCount(Kernel::HLERequestContext& ctx) { + void GetSampleCount(HLERequestContext& ctx) { const auto sample_count{impl->GetSystem().GetSampleCount()}; LOG_DEBUG(Service_Audio, "called. Sample count {}", sample_count); @@ -89,7 +88,7 @@ private: rb.Push(sample_count); } - void GetState(Kernel::HLERequestContext& ctx) { + void GetState(HLERequestContext& ctx) { const u32 state{!impl->GetSystem().IsActive()}; LOG_DEBUG(Service_Audio, "called, state {}", state); @@ -99,7 +98,7 @@ private: rb.Push(state); } - void GetMixBufferCount(Kernel::HLERequestContext& ctx) { + void GetMixBufferCount(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); const auto buffer_count{impl->GetSystem().GetMixBufferCount()}; @@ -109,7 +108,7 @@ private: rb.Push(buffer_count); } - void RequestUpdate(Kernel::HLERequestContext& ctx) { + void RequestUpdate(HLERequestContext& ctx) { LOG_TRACE(Service_Audio, "called"); const auto input{ctx.ReadBuffer(0)}; @@ -148,7 +147,7 @@ private: rb.Push(result); } - void Start(Kernel::HLERequestContext& ctx) { + void Start(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); impl->Start(); @@ -157,7 +156,7 @@ private: rb.Push(ResultSuccess); } - void Stop(Kernel::HLERequestContext& ctx) { + void Stop(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); impl->Stop(); @@ -166,12 +165,12 @@ private: rb.Push(ResultSuccess); } - void QuerySystemEvent(Kernel::HLERequestContext& ctx) { + void QuerySystemEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); if (impl->GetSystem().GetExecutionMode() == AudioCore::ExecutionMode::Manual) { IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_NOT_SUPPORTED); + rb.Push(Audio::ResultNotSupported); return; } @@ -180,7 +179,7 @@ private: rb.PushCopyObjects(rendered_event->GetReadableEvent()); } - void SetRenderingTimeLimit(Kernel::HLERequestContext& ctx) { + void SetRenderingTimeLimit(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); IPC::RequestParser rp{ctx}; @@ -193,7 +192,7 @@ private: rb.Push(ResultSuccess); } - void GetRenderingTimeLimit(Kernel::HLERequestContext& ctx) { + void GetRenderingTimeLimit(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); auto& system_ = impl->GetSystem(); @@ -204,11 +203,11 @@ private: rb.Push(time); } - void ExecuteAudioRendererRendering(Kernel::HLERequestContext& ctx) { + void ExecuteAudioRendererRendering(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); } - void SetVoiceDropParameter(Kernel::HLERequestContext& ctx) { + void SetVoiceDropParameter(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); IPC::RequestParser rp{ctx}; @@ -221,7 +220,7 @@ private: rb.Push(ResultSuccess); } - void GetVoiceDropParameter(Kernel::HLERequestContext& ctx) { + void GetVoiceDropParameter(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); auto& system_ = impl->GetSystem(); @@ -243,10 +242,8 @@ class IAudioDevice final : public ServiceFramework<IAudioDevice> { public: explicit IAudioDevice(Core::System& system_, u64 applet_resource_user_id, u32 revision, u32 device_num) - : ServiceFramework{system_, "IAudioDevice", ServiceThreadType::CreateNew}, - service_context{system_, "IAudioDevice"}, impl{std::make_unique<AudioDevice>( - system_, applet_resource_user_id, - revision)}, + : ServiceFramework{system_, "IAudioDevice"}, service_context{system_, "IAudioDevice"}, + impl{std::make_unique<AudioDevice>(system_, applet_resource_user_id, revision)}, event{service_context.CreateEvent(fmt::format("IAudioDeviceEvent-{}", device_num))} { static const FunctionInfo functions[] = { {0, &IAudioDevice::ListAudioDeviceName, "ListAudioDeviceName"}, @@ -274,7 +271,7 @@ public: } private: - void ListAudioDeviceName(Kernel::HLERequestContext& ctx) { + void ListAudioDeviceName(HLERequestContext& ctx) { const size_t in_count = ctx.GetWriteBufferNumElements<AudioDevice::AudioDeviceName>(); std::vector<AudioDevice::AudioDeviceName> out_names{}; @@ -302,7 +299,7 @@ private: rb.Push(out_count); } - void SetAudioDeviceOutputVolume(Kernel::HLERequestContext& ctx) { + void SetAudioDeviceOutputVolume(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const f32 volume = rp.Pop<f32>(); @@ -319,7 +316,7 @@ private: rb.Push(ResultSuccess); } - void GetAudioDeviceOutputVolume(Kernel::HLERequestContext& ctx) { + void GetAudioDeviceOutputVolume(HLERequestContext& ctx) { const auto device_name_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(device_name_buffer); @@ -335,7 +332,7 @@ private: rb.Push(volume); } - void GetActiveAudioDeviceName(Kernel::HLERequestContext& ctx) { + void GetActiveAudioDeviceName(HLERequestContext& ctx) { const auto write_size = ctx.GetWriteBufferSize(); std::string out_name{"AudioTvOutput"}; @@ -349,7 +346,7 @@ private: rb.Push(ResultSuccess); } - void QueryAudioDeviceSystemEvent(Kernel::HLERequestContext& ctx) { + void QueryAudioDeviceSystemEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "(STUBBED) called"); event->Signal(); @@ -359,7 +356,7 @@ private: rb.PushCopyObjects(event->GetReadableEvent()); } - void GetActiveChannelCount(Kernel::HLERequestContext& ctx) { + void GetActiveChannelCount(HLERequestContext& ctx) { const auto& sink{system.AudioCore().GetOutputSink()}; u32 channel_count{sink.GetDeviceChannels()}; @@ -371,7 +368,7 @@ private: rb.Push<u32>(channel_count); } - void QueryAudioDeviceInputEvent(Kernel::HLERequestContext& ctx) { + void QueryAudioDeviceInputEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -379,7 +376,7 @@ private: rb.PushCopyObjects(event->GetReadableEvent()); } - void QueryAudioDeviceOutputEvent(Kernel::HLERequestContext& ctx) { + void QueryAudioDeviceOutputEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -387,7 +384,7 @@ private: rb.PushCopyObjects(event->GetReadableEvent()); } - void ListAudioOutputDeviceName(Kernel::HLERequestContext& ctx) { + void ListAudioOutputDeviceName(HLERequestContext& ctx) { const size_t in_count = ctx.GetWriteBufferNumElements<AudioDevice::AudioDeviceName>(); std::vector<AudioDevice::AudioDeviceName> out_names{}; @@ -421,7 +418,7 @@ private: }; AudRenU::AudRenU(Core::System& system_) - : ServiceFramework{system_, "audren:u", ServiceThreadType::CreateNew}, + : ServiceFramework{system_, "audren:u"}, service_context{system_, "audren:u"}, impl{std::make_unique<Manager>(system_)} { // clang-format off static const FunctionInfo functions[] = { @@ -438,7 +435,7 @@ AudRenU::AudRenU(Core::System& system_) AudRenU::~AudRenU() = default; -void AudRenU::OpenAudioRenderer(Kernel::HLERequestContext& ctx) { +void AudRenU::OpenAudioRenderer(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; AudioCore::AudioRendererParameterInternal params; @@ -451,7 +448,7 @@ void AudRenU::OpenAudioRenderer(Kernel::HLERequestContext& ctx) { if (impl->GetSessionCount() + 1 > AudioCore::MaxRendererSessions) { LOG_ERROR(Service_Audio, "Too many AudioRenderer sessions open!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_MAXIMUM_SESSIONS_REACHED); + rb.Push(Audio::ResultOutOfSessions); return; } @@ -464,7 +461,7 @@ void AudRenU::OpenAudioRenderer(Kernel::HLERequestContext& ctx) { if (session_id == -1) { LOG_ERROR(Service_Audio, "Tried to open a session that's already in use!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_MAXIMUM_SESSIONS_REACHED); + rb.Push(Audio::ResultOutOfSessions); return; } @@ -478,7 +475,7 @@ void AudRenU::OpenAudioRenderer(Kernel::HLERequestContext& ctx) { applet_resource_user_id, session_id); } -void AudRenU::GetWorkBufferSize(Kernel::HLERequestContext& ctx) { +void AudRenU::GetWorkBufferSize(HLERequestContext& ctx) { AudioCore::AudioRendererParameterInternal params; IPC::RequestParser rp{ctx}; @@ -509,7 +506,7 @@ void AudRenU::GetWorkBufferSize(Kernel::HLERequestContext& ctx) { rb.Push<u64>(size); } -void AudRenU::GetAudioDeviceService(Kernel::HLERequestContext& ctx) { +void AudRenU::GetAudioDeviceService(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id = rp.Pop<u64>(); @@ -523,11 +520,11 @@ void AudRenU::GetAudioDeviceService(Kernel::HLERequestContext& ctx) { ::Common::MakeMagic('R', 'E', 'V', '1'), num_audio_devices++); } -void AudRenU::OpenAudioRendererForManualExecution(Kernel::HLERequestContext& ctx) { +void AudRenU::OpenAudioRendererForManualExecution(HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); } -void AudRenU::GetAudioDeviceServiceWithRevisionInfo(Kernel::HLERequestContext& ctx) { +void AudRenU::GetAudioDeviceServiceWithRevisionInfo(HLERequestContext& ctx) { struct Parameters { u32 revision; u64 applet_resource_user_id; diff --git a/src/core/hle/service/audio/audren_u.h b/src/core/hle/service/audio/audren_u.h index 4384a9b3c..24ce37e87 100644 --- a/src/core/hle/service/audio/audren_u.h +++ b/src/core/hle/service/audio/audren_u.h @@ -11,10 +11,6 @@ namespace Core { class System; } -namespace Kernel { -class HLERequestContext; -} - namespace Service::Audio { class IAudioRenderer; @@ -24,11 +20,11 @@ public: ~AudRenU() override; private: - void OpenAudioRenderer(Kernel::HLERequestContext& ctx); - void GetWorkBufferSize(Kernel::HLERequestContext& ctx); - void GetAudioDeviceService(Kernel::HLERequestContext& ctx); - void OpenAudioRendererForManualExecution(Kernel::HLERequestContext& ctx); - void GetAudioDeviceServiceWithRevisionInfo(Kernel::HLERequestContext& ctx); + void OpenAudioRenderer(HLERequestContext& ctx); + void GetWorkBufferSize(HLERequestContext& ctx); + void GetAudioDeviceService(HLERequestContext& ctx); + void OpenAudioRendererForManualExecution(HLERequestContext& ctx); + void GetAudioDeviceServiceWithRevisionInfo(HLERequestContext& ctx); KernelHelpers::ServiceContext service_context; std::unique_ptr<AudioCore::AudioRenderer::Manager> impl; diff --git a/src/core/hle/service/audio/errors.h b/src/core/hle/service/audio/errors.h index d706978cb..3d3d3d97a 100644 --- a/src/core/hle/service/audio/errors.h +++ b/src/core/hle/service/audio/errors.h @@ -7,17 +7,17 @@ namespace Service::Audio { -constexpr Result ERR_INVALID_DEVICE_NAME{ErrorModule::Audio, 1}; -constexpr Result ERR_OPERATION_FAILED{ErrorModule::Audio, 2}; -constexpr Result ERR_INVALID_SAMPLE_RATE{ErrorModule::Audio, 3}; -constexpr Result ERR_INSUFFICIENT_BUFFER_SIZE{ErrorModule::Audio, 4}; -constexpr Result ERR_MAXIMUM_SESSIONS_REACHED{ErrorModule::Audio, 5}; -constexpr Result ERR_BUFFER_COUNT_EXCEEDED{ErrorModule::Audio, 8}; -constexpr Result ERR_INVALID_CHANNEL_COUNT{ErrorModule::Audio, 10}; -constexpr Result ERR_INVALID_UPDATE_DATA{ErrorModule::Audio, 41}; -constexpr Result ERR_POOL_MAPPING_FAILED{ErrorModule::Audio, 42}; -constexpr Result ERR_NOT_SUPPORTED{ErrorModule::Audio, 513}; -constexpr Result ERR_INVALID_PROCESS_HANDLE{ErrorModule::Audio, 1536}; -constexpr Result ERR_INVALID_REVISION{ErrorModule::Audio, 1537}; +constexpr Result ResultNotFound{ErrorModule::Audio, 1}; +constexpr Result ResultOperationFailed{ErrorModule::Audio, 2}; +constexpr Result ResultInvalidSampleRate{ErrorModule::Audio, 3}; +constexpr Result ResultInsufficientBuffer{ErrorModule::Audio, 4}; +constexpr Result ResultOutOfSessions{ErrorModule::Audio, 5}; +constexpr Result ResultBufferCountReached{ErrorModule::Audio, 8}; +constexpr Result ResultInvalidChannelCount{ErrorModule::Audio, 10}; +constexpr Result ResultInvalidUpdateInfo{ErrorModule::Audio, 41}; +constexpr Result ResultInvalidAddressInfo{ErrorModule::Audio, 42}; +constexpr Result ResultNotSupported{ErrorModule::Audio, 513}; +constexpr Result ResultInvalidHandle{ErrorModule::Audio, 1536}; +constexpr Result ResultInvalidRevision{ErrorModule::Audio, 1537}; } // namespace Service::Audio diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp index 3db3fe188..451ac224a 100644 --- a/src/core/hle/service/audio/hwopus.cpp +++ b/src/core/hle/service/audio/hwopus.cpp @@ -11,8 +11,8 @@ #include "common/assert.h" #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/audio/hwopus.h" +#include "core/hle/service/ipc_helpers.h" namespace Service::Audio { namespace { @@ -53,7 +53,7 @@ public: // Decodes interleaved Opus packets. Optionally allows reporting time taken to // perform the decoding, as well as any relevant extra behavior. - void DecodeInterleaved(Kernel::HLERequestContext& ctx, PerfTime perf_time, + void DecodeInterleaved(HLERequestContext& ctx, PerfTime perf_time, ExtraBehavior extra_behavior) { if (perf_time == PerfTime::Disabled) { DecodeInterleavedHelper(ctx, nullptr, extra_behavior); @@ -64,7 +64,7 @@ public: } private: - void DecodeInterleavedHelper(Kernel::HLERequestContext& ctx, u64* performance, + void DecodeInterleavedHelper(HLERequestContext& ctx, u64* performance, ExtraBehavior extra_behavior) { u32 consumed = 0; u32 sample_count = 0; @@ -180,21 +180,21 @@ public: } private: - void DecodeInterleavedOld(Kernel::HLERequestContext& ctx) { + void DecodeInterleavedOld(HLERequestContext& ctx) { LOG_DEBUG(Audio, "called"); decoder_state.DecodeInterleaved(ctx, OpusDecoderState::PerfTime::Disabled, OpusDecoderState::ExtraBehavior::None); } - void DecodeInterleavedWithPerfOld(Kernel::HLERequestContext& ctx) { + void DecodeInterleavedWithPerfOld(HLERequestContext& ctx) { LOG_DEBUG(Audio, "called"); decoder_state.DecodeInterleaved(ctx, OpusDecoderState::PerfTime::Enabled, OpusDecoderState::ExtraBehavior::None); } - void DecodeInterleaved(Kernel::HLERequestContext& ctx) { + void DecodeInterleaved(HLERequestContext& ctx) { LOG_DEBUG(Audio, "called"); IPC::RequestParser rp{ctx}; @@ -231,7 +231,7 @@ std::array<u8, 2> CreateMappingTable(u32 channel_count) { } } // Anonymous namespace -void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) { +void HwOpus::GetWorkBufferSize(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto sample_rate = rp.Pop<u32>(); const auto channel_count = rp.Pop<u32>(); @@ -251,11 +251,11 @@ void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) { rb.Push<u32>(worker_buffer_sz); } -void HwOpus::GetWorkBufferSizeEx(Kernel::HLERequestContext& ctx) { +void HwOpus::GetWorkBufferSizeEx(HLERequestContext& ctx) { GetWorkBufferSize(ctx); } -void HwOpus::GetWorkBufferSizeForMultiStreamEx(Kernel::HLERequestContext& ctx) { +void HwOpus::GetWorkBufferSizeForMultiStreamEx(HLERequestContext& ctx) { OpusMultiStreamParametersEx param; std::memcpy(¶m, ctx.ReadBuffer().data(), ctx.GetReadBufferSize()); @@ -281,7 +281,7 @@ void HwOpus::GetWorkBufferSizeForMultiStreamEx(Kernel::HLERequestContext& ctx) { rb.Push<u32>(worker_buffer_sz); } -void HwOpus::OpenHardwareOpusDecoder(Kernel::HLERequestContext& ctx) { +void HwOpus::OpenHardwareOpusDecoder(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto sample_rate = rp.Pop<u32>(); const auto channel_count = rp.Pop<u32>(); @@ -319,7 +319,7 @@ void HwOpus::OpenHardwareOpusDecoder(Kernel::HLERequestContext& ctx) { system, OpusDecoderState{std::move(decoder), sample_rate, channel_count}); } -void HwOpus::OpenHardwareOpusDecoderEx(Kernel::HLERequestContext& ctx) { +void HwOpus::OpenHardwareOpusDecoderEx(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto sample_rate = rp.Pop<u32>(); const auto channel_count = rp.Pop<u32>(); diff --git a/src/core/hle/service/audio/hwopus.h b/src/core/hle/service/audio/hwopus.h index e6092e290..ece65c02c 100644 --- a/src/core/hle/service/audio/hwopus.h +++ b/src/core/hle/service/audio/hwopus.h @@ -27,11 +27,11 @@ public: ~HwOpus() override; private: - void OpenHardwareOpusDecoder(Kernel::HLERequestContext& ctx); - void OpenHardwareOpusDecoderEx(Kernel::HLERequestContext& ctx); - void GetWorkBufferSize(Kernel::HLERequestContext& ctx); - void GetWorkBufferSizeEx(Kernel::HLERequestContext& ctx); - void GetWorkBufferSizeForMultiStreamEx(Kernel::HLERequestContext& ctx); + void OpenHardwareOpusDecoder(HLERequestContext& ctx); + void OpenHardwareOpusDecoderEx(HLERequestContext& ctx); + void GetWorkBufferSize(HLERequestContext& ctx); + void GetWorkBufferSizeEx(HLERequestContext& ctx); + void GetWorkBufferSizeForMultiStreamEx(HLERequestContext& ctx); }; } // namespace Service::Audio diff --git a/src/core/hle/service/bcat/bcat_module.cpp b/src/core/hle/service/bcat/bcat_module.cpp index 6e6fed227..a6281913a 100644 --- a/src/core/hle/service/bcat/bcat_module.cpp +++ b/src/core/hle/service/bcat/bcat_module.cpp @@ -9,12 +9,13 @@ #include "common/string_util.h" #include "core/core.h" #include "core/file_sys/vfs.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_readable_event.h" #include "core/hle/service/bcat/backend/backend.h" #include "core/hle/service/bcat/bcat.h" #include "core/hle/service/bcat/bcat_module.h" #include "core/hle/service/filesystem/filesystem.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" namespace Service::BCAT { @@ -50,8 +51,7 @@ BCATDigest DigestFile(const FileSys::VirtualFile& file) { // For a name to be valid it must be non-empty, must have a null terminating character as the final // char, can only contain numbers, letters, underscores and a hyphen if directory and a period if // file. -bool VerifyNameValidInternal(Kernel::HLERequestContext& ctx, std::array<char, 0x20> name, - char match_char) { +bool VerifyNameValidInternal(HLERequestContext& ctx, std::array<char, 0x20> name, char match_char) { const auto null_chars = std::count(name.begin(), name.end(), 0); const auto bad_chars = std::count_if(name.begin(), name.end(), [match_char](char c) { return !std::isalnum(static_cast<u8>(c)) && c != '_' && c != match_char && c != '\0'; @@ -66,11 +66,11 @@ bool VerifyNameValidInternal(Kernel::HLERequestContext& ctx, std::array<char, 0x return true; } -bool VerifyNameValidDir(Kernel::HLERequestContext& ctx, DirectoryName name) { +bool VerifyNameValidDir(HLERequestContext& ctx, DirectoryName name) { return VerifyNameValidInternal(ctx, name, '-'); } -bool VerifyNameValidFile(Kernel::HLERequestContext& ctx, FileName name) { +bool VerifyNameValidFile(HLERequestContext& ctx, FileName name) { return VerifyNameValidInternal(ctx, name, '.'); } @@ -98,7 +98,7 @@ public: } private: - void GetEvent(Kernel::HLERequestContext& ctx) { + void GetEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_BCAT, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -106,7 +106,7 @@ private: rb.PushCopyObjects(event); } - void GetImpl(Kernel::HLERequestContext& ctx) { + void GetImpl(HLERequestContext& ctx) { LOG_DEBUG(Service_BCAT, "called"); ctx.WriteBuffer(impl); @@ -173,7 +173,7 @@ private: progress_backend.GetImpl()); } - void RequestSyncDeliveryCache(Kernel::HLERequestContext& ctx) { + void RequestSyncDeliveryCache(HLERequestContext& ctx) { LOG_DEBUG(Service_BCAT, "called"); backend.Synchronize({system.GetApplicationProcessProgramID(), @@ -185,7 +185,7 @@ private: rb.PushIpcInterface(CreateProgressService(SyncType::Normal)); } - void RequestSyncDeliveryCacheWithDirectoryName(Kernel::HLERequestContext& ctx) { + void RequestSyncDeliveryCacheWithDirectoryName(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto name_raw = rp.PopRaw<DirectoryName>(); const auto name = @@ -202,7 +202,7 @@ private: rb.PushIpcInterface(CreateProgressService(SyncType::Directory)); } - void SetPassphrase(Kernel::HLERequestContext& ctx) { + void SetPassphrase(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto title_id = rp.PopRaw<u64>(); @@ -234,7 +234,7 @@ private: rb.Push(ResultSuccess); } - void ClearDeliveryCacheStorage(Kernel::HLERequestContext& ctx) { + void ClearDeliveryCacheStorage(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto title_id = rp.PopRaw<u64>(); @@ -270,7 +270,7 @@ private: std::array<ProgressServiceBackend, static_cast<size_t>(SyncType::Count)> progress; }; -void Module::Interface::CreateBcatService(Kernel::HLERequestContext& ctx) { +void Module::Interface::CreateBcatService(HLERequestContext& ctx) { LOG_DEBUG(Service_BCAT, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -295,7 +295,7 @@ public: } private: - void Open(Kernel::HLERequestContext& ctx) { + void Open(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto dir_name_raw = rp.PopRaw<DirectoryName>(); const auto file_name_raw = rp.PopRaw<FileName>(); @@ -339,7 +339,7 @@ private: rb.Push(ResultSuccess); } - void Read(Kernel::HLERequestContext& ctx) { + void Read(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto offset{rp.PopRaw<u64>()}; @@ -362,7 +362,7 @@ private: rb.Push<u64>(buffer.size()); } - void GetSize(Kernel::HLERequestContext& ctx) { + void GetSize(HLERequestContext& ctx) { LOG_DEBUG(Service_BCAT, "called"); if (current_file == nullptr) { @@ -376,7 +376,7 @@ private: rb.Push<u64>(current_file->GetSize()); } - void GetDigest(Kernel::HLERequestContext& ctx) { + void GetDigest(HLERequestContext& ctx) { LOG_DEBUG(Service_BCAT, "called"); if (current_file == nullptr) { @@ -411,7 +411,7 @@ public: } private: - void Open(Kernel::HLERequestContext& ctx) { + void Open(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto name_raw = rp.PopRaw<DirectoryName>(); const auto name = @@ -442,7 +442,7 @@ private: rb.Push(ResultSuccess); } - void Read(Kernel::HLERequestContext& ctx) { + void Read(HLERequestContext& ctx) { auto write_size = ctx.GetWriteBufferNumElements<DeliveryCacheDirectoryEntry>(); LOG_DEBUG(Service_BCAT, "called, write_size={:016X}", write_size); @@ -472,7 +472,7 @@ private: rb.Push(static_cast<u32>(write_size * sizeof(DeliveryCacheDirectoryEntry))); } - void GetCount(Kernel::HLERequestContext& ctx) { + void GetCount(HLERequestContext& ctx) { LOG_DEBUG(Service_BCAT, "called"); if (current_dir == nullptr) { @@ -516,7 +516,7 @@ public: } private: - void CreateFileService(Kernel::HLERequestContext& ctx) { + void CreateFileService(HLERequestContext& ctx) { LOG_DEBUG(Service_BCAT, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -524,7 +524,7 @@ private: rb.PushIpcInterface<IDeliveryCacheFileService>(system, root); } - void CreateDirectoryService(Kernel::HLERequestContext& ctx) { + void CreateDirectoryService(HLERequestContext& ctx) { LOG_DEBUG(Service_BCAT, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -532,7 +532,7 @@ private: rb.PushIpcInterface<IDeliveryCacheDirectoryService>(system, root); } - void EnumerateDeliveryCacheDirectory(Kernel::HLERequestContext& ctx) { + void EnumerateDeliveryCacheDirectory(HLERequestContext& ctx) { auto size = ctx.GetWriteBufferNumElements<DirectoryName>(); LOG_DEBUG(Service_BCAT, "called, size={:016X}", size); @@ -551,7 +551,7 @@ private: u64 next_read_index = 0; }; -void Module::Interface::CreateDeliveryCacheStorageService(Kernel::HLERequestContext& ctx) { +void Module::Interface::CreateDeliveryCacheStorageService(HLERequestContext& ctx) { LOG_DEBUG(Service_BCAT, "called"); const auto title_id = system.GetApplicationProcessProgramID(); @@ -560,8 +560,7 @@ void Module::Interface::CreateDeliveryCacheStorageService(Kernel::HLERequestCont rb.PushIpcInterface<IDeliveryCacheStorageService>(system, fsc.GetBCATDirectory(title_id)); } -void Module::Interface::CreateDeliveryCacheStorageServiceWithApplicationId( - Kernel::HLERequestContext& ctx) { +void Module::Interface::CreateDeliveryCacheStorageServiceWithApplicationId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto title_id = rp.PopRaw<u64>(); @@ -585,16 +584,23 @@ Module::Interface::Interface(Core::System& system_, std::shared_ptr<Module> modu Module::Interface::~Interface() = default; -void InstallInterfaces(Core::System& system) { +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); auto module = std::make_shared<Module>(); - std::make_shared<BCAT>(system, module, system.GetFileSystemController(), "bcat:a") - ->InstallAsService(system.ServiceManager()); - std::make_shared<BCAT>(system, module, system.GetFileSystemController(), "bcat:m") - ->InstallAsService(system.ServiceManager()); - std::make_shared<BCAT>(system, module, system.GetFileSystemController(), "bcat:u") - ->InstallAsService(system.ServiceManager()); - std::make_shared<BCAT>(system, module, system.GetFileSystemController(), "bcat:s") - ->InstallAsService(system.ServiceManager()); + + server_manager->RegisterNamedService( + "bcat:a", + std::make_shared<BCAT>(system, module, system.GetFileSystemController(), "bcat:a")); + server_manager->RegisterNamedService( + "bcat:m", + std::make_shared<BCAT>(system, module, system.GetFileSystemController(), "bcat:m")); + server_manager->RegisterNamedService( + "bcat:u", + std::make_shared<BCAT>(system, module, system.GetFileSystemController(), "bcat:u")); + server_manager->RegisterNamedService( + "bcat:s", + std::make_shared<BCAT>(system, module, system.GetFileSystemController(), "bcat:s")); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::BCAT diff --git a/src/core/hle/service/bcat/bcat_module.h b/src/core/hle/service/bcat/bcat_module.h index b2fcf9bfb..87576288b 100644 --- a/src/core/hle/service/bcat/bcat_module.h +++ b/src/core/hle/service/bcat/bcat_module.h @@ -27,9 +27,9 @@ public: FileSystem::FileSystemController& fsc_, const char* name); ~Interface() override; - void CreateBcatService(Kernel::HLERequestContext& ctx); - void CreateDeliveryCacheStorageService(Kernel::HLERequestContext& ctx); - void CreateDeliveryCacheStorageServiceWithApplicationId(Kernel::HLERequestContext& ctx); + void CreateBcatService(HLERequestContext& ctx); + void CreateDeliveryCacheStorageService(HLERequestContext& ctx); + void CreateDeliveryCacheStorageServiceWithApplicationId(HLERequestContext& ctx); protected: FileSystem::FileSystemController& fsc; @@ -39,8 +39,7 @@ public: }; }; -/// Registers all BCAT services with the specified service manager. -void InstallInterfaces(Core::System& system); +void LoopProcess(Core::System& system); } // namespace BCAT diff --git a/src/core/hle/service/bpc/bpc.cpp b/src/core/hle/service/bpc/bpc.cpp index 466163538..91b15e256 100644 --- a/src/core/hle/service/bpc/bpc.cpp +++ b/src/core/hle/service/bpc/bpc.cpp @@ -4,8 +4,8 @@ #include <memory> #include "core/hle/service/bpc/bpc.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" namespace Service::BPC { @@ -54,9 +54,12 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<BPC>(system)->InstallAsService(sm); - std::make_shared<BPC_R>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("bpc", std::make_shared<BPC>(system)); + server_manager->RegisterNamedService("bpc:r", std::make_shared<BPC_R>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::BPC diff --git a/src/core/hle/service/bpc/bpc.h b/src/core/hle/service/bpc/bpc.h index 8adc2f962..524391ddb 100644 --- a/src/core/hle/service/bpc/bpc.h +++ b/src/core/hle/service/bpc/bpc.h @@ -13,6 +13,6 @@ class ServiceManager; namespace Service::BPC { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::BPC diff --git a/src/core/hle/service/btdrv/btdrv.cpp b/src/core/hle/service/btdrv/btdrv.cpp index ec7e5320c..38cdd57ad 100644 --- a/src/core/hle/service/btdrv/btdrv.cpp +++ b/src/core/hle/service/btdrv/btdrv.cpp @@ -3,10 +3,11 @@ #include "common/logging/log.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" #include "core/hle/service/btdrv/btdrv.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/kernel_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" #include "core/hle/service/sm/sm.h" @@ -40,7 +41,7 @@ public: } private: - void RegisterBleEvent(Kernel::HLERequestContext& ctx) { + void RegisterBleEvent(HLERequestContext& ctx) { LOG_WARNING(Service_BTM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -196,9 +197,12 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<BtDrv>(system)->InstallAsService(sm); - std::make_shared<Bt>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("btdrv", std::make_shared<BtDrv>(system)); + server_manager->RegisterNamedService("bt", std::make_shared<Bt>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::BtDrv diff --git a/src/core/hle/service/btdrv/btdrv.h b/src/core/hle/service/btdrv/btdrv.h index 9cbe2926f..42713860e 100644 --- a/src/core/hle/service/btdrv/btdrv.h +++ b/src/core/hle/service/btdrv/btdrv.h @@ -13,7 +13,6 @@ class System; namespace Service::BtDrv { -/// Registers all BtDrv services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::BtDrv diff --git a/src/core/hle/service/btm/btm.cpp b/src/core/hle/service/btm/btm.cpp index eebf85e03..8069f75b7 100644 --- a/src/core/hle/service/btm/btm.cpp +++ b/src/core/hle/service/btm/btm.cpp @@ -5,10 +5,11 @@ #include "common/logging/log.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" #include "core/hle/service/btm/btm.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/kernel_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" namespace Service::BTM { @@ -69,35 +70,39 @@ public: } private: - void AcquireBleScanEvent(Kernel::HLERequestContext& ctx) { + void AcquireBleScanEvent(HLERequestContext& ctx) { LOG_WARNING(Service_BTM, "(STUBBED) called"); - IPC::ResponseBuilder rb{ctx, 2, 1}; + IPC::ResponseBuilder rb{ctx, 3, 1}; rb.Push(ResultSuccess); + rb.Push(true); rb.PushCopyObjects(scan_event->GetReadableEvent()); } - void AcquireBleConnectionEvent(Kernel::HLERequestContext& ctx) { + void AcquireBleConnectionEvent(HLERequestContext& ctx) { LOG_WARNING(Service_BTM, "(STUBBED) called"); - IPC::ResponseBuilder rb{ctx, 2, 1}; + IPC::ResponseBuilder rb{ctx, 3, 1}; rb.Push(ResultSuccess); + rb.Push(true); rb.PushCopyObjects(connection_event->GetReadableEvent()); } - void AcquireBleServiceDiscoveryEvent(Kernel::HLERequestContext& ctx) { + void AcquireBleServiceDiscoveryEvent(HLERequestContext& ctx) { LOG_WARNING(Service_BTM, "(STUBBED) called"); - IPC::ResponseBuilder rb{ctx, 2, 1}; + IPC::ResponseBuilder rb{ctx, 3, 1}; rb.Push(ResultSuccess); + rb.Push(true); rb.PushCopyObjects(service_discovery_event->GetReadableEvent()); } - void AcquireBleMtuConfigEvent(Kernel::HLERequestContext& ctx) { + void AcquireBleMtuConfigEvent(HLERequestContext& ctx) { LOG_WARNING(Service_BTM, "(STUBBED) called"); - IPC::ResponseBuilder rb{ctx, 2, 1}; + IPC::ResponseBuilder rb{ctx, 3, 1}; rb.Push(ResultSuccess); + rb.Push(true); rb.PushCopyObjects(config_event->GetReadableEvent()); } @@ -121,7 +126,7 @@ public: } private: - void GetCore(Kernel::HLERequestContext& ctx) { + void GetCore(HLERequestContext& ctx) { LOG_DEBUG(Service_BTM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -302,7 +307,7 @@ public: } private: - void GetCore(Kernel::HLERequestContext& ctx) { + void GetCore(HLERequestContext& ctx) { LOG_DEBUG(Service_BTM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -311,11 +316,14 @@ private: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<BTM>(system)->InstallAsService(sm); - std::make_shared<BTM_DBG>(system)->InstallAsService(sm); - std::make_shared<BTM_SYS>(system)->InstallAsService(sm); - std::make_shared<BTM_USR>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("btm", std::make_shared<BTM>(system)); + server_manager->RegisterNamedService("btm:dbg", std::make_shared<BTM_DBG>(system)); + server_manager->RegisterNamedService("btm:sys", std::make_shared<BTM_SYS>(system)); + server_manager->RegisterNamedService("btm:u", std::make_shared<BTM_USR>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::BTM diff --git a/src/core/hle/service/btm/btm.h b/src/core/hle/service/btm/btm.h index 9dcda1848..a99b34364 100644 --- a/src/core/hle/service/btm/btm.h +++ b/src/core/hle/service/btm/btm.h @@ -13,6 +13,6 @@ class System; namespace Service::BTM { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::BTM diff --git a/src/core/hle/service/caps/caps.cpp b/src/core/hle/service/caps/caps.cpp index 13940a8c9..610fe9940 100644 --- a/src/core/hle/service/caps/caps.cpp +++ b/src/core/hle/service/caps/caps.cpp @@ -8,17 +8,21 @@ #include "core/hle/service/caps/caps_ss.h" #include "core/hle/service/caps/caps_su.h" #include "core/hle/service/caps/caps_u.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" namespace Service::Capture { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<CAPS_A>(system)->InstallAsService(sm); - std::make_shared<CAPS_C>(system)->InstallAsService(sm); - std::make_shared<CAPS_U>(system)->InstallAsService(sm); - std::make_shared<CAPS_SC>(system)->InstallAsService(sm); - std::make_shared<CAPS_SS>(system)->InstallAsService(sm); - std::make_shared<CAPS_SU>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("caps:a", std::make_shared<CAPS_A>(system)); + server_manager->RegisterNamedService("caps:c", std::make_shared<CAPS_C>(system)); + server_manager->RegisterNamedService("caps:u", std::make_shared<CAPS_U>(system)); + server_manager->RegisterNamedService("caps:sc", std::make_shared<CAPS_SC>(system)); + server_manager->RegisterNamedService("caps:ss", std::make_shared<CAPS_SS>(system)); + server_manager->RegisterNamedService("caps:su", std::make_shared<CAPS_SU>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::Capture diff --git a/src/core/hle/service/caps/caps.h b/src/core/hle/service/caps/caps.h index 3e89c82cb..15f0ecfaa 100644 --- a/src/core/hle/service/caps/caps.h +++ b/src/core/hle/service/caps/caps.h @@ -90,7 +90,6 @@ struct ApplicationAlbumFileEntry { static_assert(sizeof(ApplicationAlbumFileEntry) == 0x30, "ApplicationAlbumFileEntry has incorrect size."); -/// Registers all Capture services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::Capture diff --git a/src/core/hle/service/caps/caps_a.h b/src/core/hle/service/caps/caps_a.h index 319c173d8..98a21a5ad 100644 --- a/src/core/hle/service/caps/caps_a.h +++ b/src/core/hle/service/caps/caps_a.h @@ -9,10 +9,6 @@ namespace Core { class System; } -namespace Kernel { -class HLERequestContext; -} - namespace Service::Capture { class CAPS_A final : public ServiceFramework<CAPS_A> { diff --git a/src/core/hle/service/caps/caps_c.cpp b/src/core/hle/service/caps/caps_c.cpp index 725a2e3a7..fc77e35cd 100644 --- a/src/core/hle/service/caps/caps_c.cpp +++ b/src/core/hle/service/caps/caps_c.cpp @@ -2,8 +2,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/caps/caps_c.h" +#include "core/hle/service/ipc_helpers.h" namespace Service::Capture { @@ -74,7 +74,7 @@ CAPS_C::CAPS_C(Core::System& system_) : ServiceFramework{system_, "caps:c"} { CAPS_C::~CAPS_C() = default; -void CAPS_C::SetShimLibraryVersion(Kernel::HLERequestContext& ctx) { +void CAPS_C::SetShimLibraryVersion(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto library_version{rp.Pop<u64>()}; const auto applet_resource_user_id{rp.Pop<u64>()}; diff --git a/src/core/hle/service/caps/caps_c.h b/src/core/hle/service/caps/caps_c.h index 983a4212d..537b3a2e3 100644 --- a/src/core/hle/service/caps/caps_c.h +++ b/src/core/hle/service/caps/caps_c.h @@ -9,10 +9,6 @@ namespace Core { class System; } -namespace Kernel { -class HLERequestContext; -} - namespace Service::Capture { class CAPS_C final : public ServiceFramework<CAPS_C> { @@ -21,7 +17,7 @@ public: ~CAPS_C() override; private: - void SetShimLibraryVersion(Kernel::HLERequestContext& ctx); + void SetShimLibraryVersion(HLERequestContext& ctx); }; } // namespace Service::Capture diff --git a/src/core/hle/service/caps/caps_su.cpp b/src/core/hle/service/caps/caps_su.cpp index fcb496756..3b11cc95c 100644 --- a/src/core/hle/service/caps/caps_su.cpp +++ b/src/core/hle/service/caps/caps_su.cpp @@ -2,8 +2,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/caps/caps_su.h" +#include "core/hle/service/ipc_helpers.h" namespace Service::Capture { @@ -23,7 +23,7 @@ CAPS_SU::CAPS_SU(Core::System& system_) : ServiceFramework{system_, "caps:su"} { CAPS_SU::~CAPS_SU() = default; -void CAPS_SU::SetShimLibraryVersion(Kernel::HLERequestContext& ctx) { +void CAPS_SU::SetShimLibraryVersion(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto library_version{rp.Pop<u64>()}; const auto applet_resource_user_id{rp.Pop<u64>()}; diff --git a/src/core/hle/service/caps/caps_su.h b/src/core/hle/service/caps/caps_su.h index c9a1d507b..c6398858d 100644 --- a/src/core/hle/service/caps/caps_su.h +++ b/src/core/hle/service/caps/caps_su.h @@ -9,10 +9,6 @@ namespace Core { class System; } -namespace Kernel { -class HLERequestContext; -} - namespace Service::Capture { class CAPS_SU final : public ServiceFramework<CAPS_SU> { @@ -21,7 +17,7 @@ public: ~CAPS_SU() override; private: - void SetShimLibraryVersion(Kernel::HLERequestContext& ctx); + void SetShimLibraryVersion(HLERequestContext& ctx); }; } // namespace Service::Capture diff --git a/src/core/hle/service/caps/caps_u.cpp b/src/core/hle/service/caps/caps_u.cpp index 5fbba8673..bffe0f8d0 100644 --- a/src/core/hle/service/caps/caps_u.cpp +++ b/src/core/hle/service/caps/caps_u.cpp @@ -2,9 +2,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/caps/caps.h" #include "core/hle/service/caps/caps_u.h" +#include "core/hle/service/ipc_helpers.h" namespace Service::Capture { @@ -52,7 +52,7 @@ CAPS_U::CAPS_U(Core::System& system_) : ServiceFramework{system_, "caps:u"} { CAPS_U::~CAPS_U() = default; -void CAPS_U::SetShimLibraryVersion(Kernel::HLERequestContext& ctx) { +void CAPS_U::SetShimLibraryVersion(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto library_version{rp.Pop<u64>()}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -64,7 +64,7 @@ void CAPS_U::SetShimLibraryVersion(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void CAPS_U::GetAlbumContentsFileListForApplication(Kernel::HLERequestContext& ctx) { +void CAPS_U::GetAlbumContentsFileListForApplication(HLERequestContext& ctx) { // Takes a type-0x6 output buffer containing an array of ApplicationAlbumFileEntry, a PID, an // u8 ContentType, two s64s, and an u64 AppletResourceUserId. Returns an output u64 for total // output entries (which is copied to a s32 by official SW). @@ -93,7 +93,7 @@ void CAPS_U::GetAlbumContentsFileListForApplication(Kernel::HLERequestContext& c rb.Push(total_entries_2); } -void CAPS_U::GetAlbumFileList3AaeAruid(Kernel::HLERequestContext& ctx) { +void CAPS_U::GetAlbumFileList3AaeAruid(HLERequestContext& ctx) { GetAlbumContentsFileListForApplication(ctx); } diff --git a/src/core/hle/service/caps/caps_u.h b/src/core/hle/service/caps/caps_u.h index c3d4b9cea..e8dd037d7 100644 --- a/src/core/hle/service/caps/caps_u.h +++ b/src/core/hle/service/caps/caps_u.h @@ -9,10 +9,6 @@ namespace Core { class System; } -namespace Kernel { -class HLERequestContext; -} - namespace Service::Capture { class CAPS_U final : public ServiceFramework<CAPS_U> { @@ -21,9 +17,9 @@ public: ~CAPS_U() override; private: - void SetShimLibraryVersion(Kernel::HLERequestContext& ctx); - void GetAlbumContentsFileListForApplication(Kernel::HLERequestContext& ctx); - void GetAlbumFileList3AaeAruid(Kernel::HLERequestContext& ctx); + void SetShimLibraryVersion(HLERequestContext& ctx); + void GetAlbumContentsFileListForApplication(HLERequestContext& ctx); + void GetAlbumFileList3AaeAruid(HLERequestContext& ctx); }; } // namespace Service::Capture diff --git a/src/core/hle/service/erpt/erpt.cpp b/src/core/hle/service/erpt/erpt.cpp index 923c0022a..3ea862fad 100644 --- a/src/core/hle/service/erpt/erpt.cpp +++ b/src/core/hle/service/erpt/erpt.cpp @@ -4,6 +4,7 @@ #include <memory> #include "core/hle/service/erpt/erpt.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" #include "core/hle/service/sm/sm.h" @@ -52,9 +53,13 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<ErrorReportContext>(system)->InstallAsService(sm); - std::make_shared<ErrorReportSession>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("erpt:c", std::make_shared<ErrorReportContext>(system)); + server_manager->RegisterNamedService("erpt:r", std::make_shared<ErrorReportSession>(system)); + + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::ERPT diff --git a/src/core/hle/service/erpt/erpt.h b/src/core/hle/service/erpt/erpt.h index 507d626ec..60094f556 100644 --- a/src/core/hle/service/erpt/erpt.h +++ b/src/core/hle/service/erpt/erpt.h @@ -7,13 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::ERPT { -/// Registers all ERPT services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::ERPT diff --git a/src/core/hle/service/es/es.cpp b/src/core/hle/service/es/es.cpp index fb8686859..446f46b3c 100644 --- a/src/core/hle/service/es/es.cpp +++ b/src/core/hle/service/es/es.cpp @@ -2,8 +2,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "core/crypto/key_manager.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/es/es.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" namespace Service::ES { @@ -109,7 +110,7 @@ public: } private: - bool CheckRightsId(Kernel::HLERequestContext& ctx, const u128& rights_id) { + bool CheckRightsId(HLERequestContext& ctx, const u128& rights_id) { if (rights_id == u128{}) { LOG_ERROR(Service_ETicket, "The rights ID was invalid!"); IPC::ResponseBuilder rb{ctx, 2}; @@ -120,7 +121,7 @@ private: return true; } - void ImportTicket(Kernel::HLERequestContext& ctx) { + void ImportTicket(HLERequestContext& ctx) { const auto ticket = ctx.ReadBuffer(); [[maybe_unused]] const auto cert = ctx.ReadBuffer(1); @@ -145,7 +146,7 @@ private: rb.Push(ResultSuccess); } - void GetTitleKey(Kernel::HLERequestContext& ctx) { + void GetTitleKey(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto rights_id = rp.PopRaw<u128>(); @@ -171,7 +172,7 @@ private: rb.Push(ResultSuccess); } - void CountCommonTicket(Kernel::HLERequestContext& ctx) { + void CountCommonTicket(HLERequestContext& ctx) { LOG_DEBUG(Service_ETicket, "called"); const u32 count = static_cast<u32>(keys.GetCommonTickets().size()); @@ -181,7 +182,7 @@ private: rb.Push<u32>(count); } - void CountPersonalizedTicket(Kernel::HLERequestContext& ctx) { + void CountPersonalizedTicket(HLERequestContext& ctx) { LOG_DEBUG(Service_ETicket, "called"); const u32 count = static_cast<u32>(keys.GetPersonalizedTickets().size()); @@ -191,7 +192,7 @@ private: rb.Push<u32>(count); } - void ListCommonTicketRightsIds(Kernel::HLERequestContext& ctx) { + void ListCommonTicketRightsIds(HLERequestContext& ctx) { size_t out_entries = 0; if (!keys.GetCommonTickets().empty()) { out_entries = ctx.GetWriteBufferNumElements<u128>(); @@ -212,7 +213,7 @@ private: rb.Push<u32>(static_cast<u32>(out_entries)); } - void ListPersonalizedTicketRightsIds(Kernel::HLERequestContext& ctx) { + void ListPersonalizedTicketRightsIds(HLERequestContext& ctx) { size_t out_entries = 0; if (!keys.GetPersonalizedTickets().empty()) { out_entries = ctx.GetWriteBufferNumElements<u128>(); @@ -234,7 +235,7 @@ private: rb.Push<u32>(static_cast<u32>(out_entries)); } - void GetCommonTicketSize(Kernel::HLERequestContext& ctx) { + void GetCommonTicketSize(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto rights_id = rp.PopRaw<u128>(); @@ -250,7 +251,7 @@ private: rb.Push<u64>(ticket.GetSize()); } - void GetPersonalizedTicketSize(Kernel::HLERequestContext& ctx) { + void GetPersonalizedTicketSize(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto rights_id = rp.PopRaw<u128>(); @@ -266,7 +267,7 @@ private: rb.Push<u64>(ticket.GetSize()); } - void GetCommonTicketData(Kernel::HLERequestContext& ctx) { + void GetCommonTicketData(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto rights_id = rp.PopRaw<u128>(); @@ -285,7 +286,7 @@ private: rb.Push<u64>(write_size); } - void GetPersonalizedTicketData(Kernel::HLERequestContext& ctx) { + void GetPersonalizedTicketData(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto rights_id = rp.PopRaw<u128>(); @@ -307,8 +308,11 @@ private: Core::Crypto::KeyManager& keys = Core::Crypto::KeyManager::Instance(); }; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<ETicket>(system)->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("es", std::make_shared<ETicket>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::ES diff --git a/src/core/hle/service/es/es.h b/src/core/hle/service/es/es.h index 530563550..317680625 100644 --- a/src/core/hle/service/es/es.h +++ b/src/core/hle/service/es/es.h @@ -7,13 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::ES { -/// Registers all ES services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::ES diff --git a/src/core/hle/service/eupld/eupld.cpp b/src/core/hle/service/eupld/eupld.cpp index d1553ace0..3cf27513a 100644 --- a/src/core/hle/service/eupld/eupld.cpp +++ b/src/core/hle/service/eupld/eupld.cpp @@ -4,8 +4,8 @@ #include <memory> #include "core/hle/service/eupld/eupld.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" namespace Service::EUPLD { @@ -44,9 +44,12 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<ErrorUploadContext>(system)->InstallAsService(sm); - std::make_shared<ErrorUploadRequest>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("eupld:c", std::make_shared<ErrorUploadContext>(system)); + server_manager->RegisterNamedService("eupld:r", std::make_shared<ErrorUploadRequest>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::EUPLD diff --git a/src/core/hle/service/eupld/eupld.h b/src/core/hle/service/eupld/eupld.h index 5de8219be..8eb0a5b4f 100644 --- a/src/core/hle/service/eupld/eupld.h +++ b/src/core/hle/service/eupld/eupld.h @@ -7,13 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::EUPLD { -/// Registers all EUPLD services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::EUPLD diff --git a/src/core/hle/service/fatal/fatal.cpp b/src/core/hle/service/fatal/fatal.cpp index 2e5919330..fe2ed8df8 100644 --- a/src/core/hle/service/fatal/fatal.cpp +++ b/src/core/hle/service/fatal/fatal.cpp @@ -9,10 +9,11 @@ #include "common/scm_rev.h" #include "common/swap.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/fatal/fatal.h" #include "core/hle/service/fatal/fatal_p.h" #include "core/hle/service/fatal/fatal_u.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/reporter.h" namespace Service::Fatal { @@ -125,7 +126,7 @@ static void ThrowFatalError(Core::System& system, Result error_code, FatalType f } } -void Module::Interface::ThrowFatal(Kernel::HLERequestContext& ctx) { +void Module::Interface::ThrowFatal(HLERequestContext& ctx) { LOG_ERROR(Service_Fatal, "called"); IPC::RequestParser rp{ctx}; const auto error_code = rp.Pop<Result>(); @@ -135,7 +136,7 @@ void Module::Interface::ThrowFatal(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Module::Interface::ThrowFatalWithPolicy(Kernel::HLERequestContext& ctx) { +void Module::Interface::ThrowFatalWithPolicy(HLERequestContext& ctx) { LOG_ERROR(Service_Fatal, "called"); IPC::RequestParser rp(ctx); const auto error_code = rp.Pop<Result>(); @@ -147,7 +148,7 @@ void Module::Interface::ThrowFatalWithPolicy(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Module::Interface::ThrowFatalWithCpuContext(Kernel::HLERequestContext& ctx) { +void Module::Interface::ThrowFatalWithCpuContext(HLERequestContext& ctx) { LOG_ERROR(Service_Fatal, "called"); IPC::RequestParser rp(ctx); const auto error_code = rp.Pop<Result>(); @@ -163,10 +164,13 @@ void Module::Interface::ThrowFatalWithCpuContext(Kernel::HLERequestContext& ctx) rb.Push(ResultSuccess); } -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); auto module = std::make_shared<Module>(); - std::make_shared<Fatal_P>(module, system)->InstallAsService(service_manager); - std::make_shared<Fatal_U>(module, system)->InstallAsService(service_manager); + + server_manager->RegisterNamedService("fatal:p", std::make_shared<Fatal_P>(module, system)); + server_manager->RegisterNamedService("fatal:u", std::make_shared<Fatal_U>(module, system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::Fatal diff --git a/src/core/hle/service/fatal/fatal.h b/src/core/hle/service/fatal/fatal.h index a7a310f7b..f1c110406 100644 --- a/src/core/hle/service/fatal/fatal.h +++ b/src/core/hle/service/fatal/fatal.h @@ -19,15 +19,15 @@ public: const char* name); ~Interface() override; - void ThrowFatal(Kernel::HLERequestContext& ctx); - void ThrowFatalWithPolicy(Kernel::HLERequestContext& ctx); - void ThrowFatalWithCpuContext(Kernel::HLERequestContext& ctx); + void ThrowFatal(HLERequestContext& ctx); + void ThrowFatalWithPolicy(HLERequestContext& ctx); + void ThrowFatalWithCpuContext(HLERequestContext& ctx); protected: std::shared_ptr<Module> module; }; }; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::Fatal diff --git a/src/core/hle/service/fgm/fgm.cpp b/src/core/hle/service/fgm/fgm.cpp index 7e9fb0385..6b3f77be2 100644 --- a/src/core/hle/service/fgm/fgm.cpp +++ b/src/core/hle/service/fgm/fgm.cpp @@ -3,8 +3,9 @@ #include <memory> -#include "core/hle/ipc_helpers.h" #include "core/hle/service/fgm/fgm.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" #include "core/hle/service/sm/sm.h" @@ -39,7 +40,7 @@ public: } private: - void Initialize(Kernel::HLERequestContext& ctx) { + void Initialize(HLERequestContext& ctx) { LOG_DEBUG(Service_FGM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -63,11 +64,14 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<FGM>(system, "fgm")->InstallAsService(sm); - std::make_shared<FGM>(system, "fgm:0")->InstallAsService(sm); - std::make_shared<FGM>(system, "fgm:9")->InstallAsService(sm); - std::make_shared<FGM_DBG>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("fgm", std::make_shared<FGM>(system, "fgm")); + server_manager->RegisterNamedService("fgm:0", std::make_shared<FGM>(system, "fgm:0")); + server_manager->RegisterNamedService("fgm:9", std::make_shared<FGM>(system, "fgm:9")); + server_manager->RegisterNamedService("fgm:dbg", std::make_shared<FGM_DBG>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::FGM diff --git a/src/core/hle/service/fgm/fgm.h b/src/core/hle/service/fgm/fgm.h index 077e48812..9d2465c0f 100644 --- a/src/core/hle/service/fgm/fgm.h +++ b/src/core/hle/service/fgm/fgm.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::FGM { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::FGM diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index 177447bc1..dfcdd3ada 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -23,6 +23,7 @@ #include "core/hle/service/filesystem/fsp_ldr.h" #include "core/hle/service/filesystem/fsp_pr.h" #include "core/hle/service/filesystem/fsp_srv.h" +#include "core/hle/service/server_manager.h" #include "core/loader/loader.h" namespace Service::FileSystem { @@ -796,10 +797,13 @@ void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool ove } } -void InstallInterfaces(Core::System& system) { - std::make_shared<FSP_LDR>(system)->InstallAsService(system.ServiceManager()); - std::make_shared<FSP_PR>(system)->InstallAsService(system.ServiceManager()); - std::make_shared<FSP_SRV>(system)->InstallAsService(system.ServiceManager()); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("fsp-ldr", std::make_shared<FSP_LDR>(system)); + server_manager->RegisterNamedService("fsp:pr", std::make_shared<FSP_PR>(system)); + server_manager->RegisterNamedService("fsp-srv", std::make_shared<FSP_SRV>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::FileSystem diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index 5b27de9fa..a5c1c9d3e 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h @@ -139,7 +139,7 @@ private: Core::System& system; }; -void InstallInterfaces(Core::System& system); +void LoopProcess(Core::System& system); // A class that wraps a VfsDirectory with methods that return ResultVal and Result instead of // pointers and booleans. This makes using a VfsDirectory with switch services much easier and diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index e76346ca9..9e559d97e 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -24,9 +24,9 @@ #include "core/file_sys/savedata_factory.h" #include "core/file_sys/system_archive/system_archive.h" #include "core/file_sys/vfs.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/filesystem/fsp_srv.h" +#include "core/hle/service/ipc_helpers.h" #include "core/reporter.h" namespace Service::FileSystem { @@ -57,8 +57,7 @@ enum class FileSystemType : u8 { class IStorage final : public ServiceFramework<IStorage> { public: explicit IStorage(Core::System& system_, FileSys::VirtualFile backend_) - : ServiceFramework{system_, "IStorage", ServiceThreadType::CreateNew}, - backend(std::move(backend_)) { + : ServiceFramework{system_, "IStorage"}, backend(std::move(backend_)) { static const FunctionInfo functions[] = { {0, &IStorage::Read, "Read"}, {1, nullptr, "Write"}, @@ -73,7 +72,7 @@ public: private: FileSys::VirtualFile backend; - void Read(Kernel::HLERequestContext& ctx) { + void Read(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s64 offset = rp.Pop<s64>(); const s64 length = rp.Pop<s64>(); @@ -103,7 +102,7 @@ private: rb.Push(ResultSuccess); } - void GetSize(Kernel::HLERequestContext& ctx) { + void GetSize(HLERequestContext& ctx) { const u64 size = backend->GetSize(); LOG_DEBUG(Service_FS, "called, size={}", size); @@ -116,8 +115,7 @@ private: class IFile final : public ServiceFramework<IFile> { public: explicit IFile(Core::System& system_, FileSys::VirtualFile backend_) - : ServiceFramework{system_, "IFile", ServiceThreadType::CreateNew}, - backend(std::move(backend_)) { + : ServiceFramework{system_, "IFile"}, backend(std::move(backend_)) { static const FunctionInfo functions[] = { {0, &IFile::Read, "Read"}, {1, &IFile::Write, "Write"}, @@ -133,7 +131,7 @@ public: private: FileSys::VirtualFile backend; - void Read(Kernel::HLERequestContext& ctx) { + void Read(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 option = rp.Pop<u64>(); const s64 offset = rp.Pop<s64>(); @@ -167,7 +165,7 @@ private: rb.Push(static_cast<u64>(output.size())); } - void Write(Kernel::HLERequestContext& ctx) { + void Write(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 option = rp.Pop<u64>(); const s64 offset = rp.Pop<s64>(); @@ -210,7 +208,7 @@ private: rb.Push(ResultSuccess); } - void Flush(Kernel::HLERequestContext& ctx) { + void Flush(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); // Exists for SDK compatibiltity -- No need to flush file. @@ -219,7 +217,7 @@ private: rb.Push(ResultSuccess); } - void SetSize(Kernel::HLERequestContext& ctx) { + void SetSize(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 size = rp.Pop<u64>(); LOG_DEBUG(Service_FS, "called, size={}", size); @@ -230,7 +228,7 @@ private: rb.Push(ResultSuccess); } - void GetSize(Kernel::HLERequestContext& ctx) { + void GetSize(HLERequestContext& ctx) { const u64 size = backend->GetSize(); LOG_DEBUG(Service_FS, "called, size={}", size); @@ -254,8 +252,7 @@ static void BuildEntryIndex(std::vector<FileSys::Entry>& entries, const std::vec class IDirectory final : public ServiceFramework<IDirectory> { public: explicit IDirectory(Core::System& system_, FileSys::VirtualDir backend_) - : ServiceFramework{system_, "IDirectory", ServiceThreadType::CreateNew}, - backend(std::move(backend_)) { + : ServiceFramework{system_, "IDirectory"}, backend(std::move(backend_)) { static const FunctionInfo functions[] = { {0, &IDirectory::Read, "Read"}, {1, &IDirectory::GetEntryCount, "GetEntryCount"}, @@ -273,7 +270,7 @@ private: std::vector<FileSys::Entry> entries; u64 next_entry_index = 0; - void Read(Kernel::HLERequestContext& ctx) { + void Read(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called."); // Calculate how many entries we can fit in the output buffer @@ -297,7 +294,7 @@ private: rb.Push(actual_entries); } - void GetEntryCount(Kernel::HLERequestContext& ctx) { + void GetEntryCount(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); u64 count = entries.size() - next_entry_index; @@ -311,8 +308,8 @@ private: class IFileSystem final : public ServiceFramework<IFileSystem> { public: explicit IFileSystem(Core::System& system_, FileSys::VirtualDir backend_, SizeGetter size_) - : ServiceFramework{system_, "IFileSystem", ServiceThreadType::CreateNew}, - backend{std::move(backend_)}, size{std::move(size_)} { + : ServiceFramework{system_, "IFileSystem"}, backend{std::move(backend_)}, size{std::move( + size_)} { static const FunctionInfo functions[] = { {0, &IFileSystem::CreateFile, "CreateFile"}, {1, &IFileSystem::DeleteFile, "DeleteFile"}, @@ -334,7 +331,7 @@ public: RegisterHandlers(functions); } - void CreateFile(Kernel::HLERequestContext& ctx) { + void CreateFile(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto file_buffer = ctx.ReadBuffer(); @@ -350,7 +347,7 @@ public: rb.Push(backend.CreateFile(name, file_size)); } - void DeleteFile(Kernel::HLERequestContext& ctx) { + void DeleteFile(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); @@ -360,7 +357,7 @@ public: rb.Push(backend.DeleteFile(name)); } - void CreateDirectory(Kernel::HLERequestContext& ctx) { + void CreateDirectory(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); @@ -370,7 +367,7 @@ public: rb.Push(backend.CreateDirectory(name)); } - void DeleteDirectory(Kernel::HLERequestContext& ctx) { + void DeleteDirectory(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); @@ -380,7 +377,7 @@ public: rb.Push(backend.DeleteDirectory(name)); } - void DeleteDirectoryRecursively(Kernel::HLERequestContext& ctx) { + void DeleteDirectoryRecursively(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); @@ -390,7 +387,7 @@ public: rb.Push(backend.DeleteDirectoryRecursively(name)); } - void CleanDirectoryRecursively(Kernel::HLERequestContext& ctx) { + void CleanDirectoryRecursively(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); @@ -400,7 +397,7 @@ public: rb.Push(backend.CleanDirectoryRecursively(name)); } - void RenameFile(Kernel::HLERequestContext& ctx) { + void RenameFile(HLERequestContext& ctx) { const std::string src_name = Common::StringFromBuffer(ctx.ReadBuffer(0)); const std::string dst_name = Common::StringFromBuffer(ctx.ReadBuffer(1)); @@ -410,7 +407,7 @@ public: rb.Push(backend.RenameFile(src_name, dst_name)); } - void OpenFile(Kernel::HLERequestContext& ctx) { + void OpenFile(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto file_buffer = ctx.ReadBuffer(); @@ -434,7 +431,7 @@ public: rb.PushIpcInterface<IFile>(std::move(file)); } - void OpenDirectory(Kernel::HLERequestContext& ctx) { + void OpenDirectory(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto file_buffer = ctx.ReadBuffer(); @@ -459,7 +456,7 @@ public: rb.PushIpcInterface<IDirectory>(std::move(directory)); } - void GetEntryType(Kernel::HLERequestContext& ctx) { + void GetEntryType(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); @@ -477,14 +474,14 @@ public: rb.Push<u32>(static_cast<u32>(*result)); } - void Commit(Kernel::HLERequestContext& ctx) { + void Commit(HLERequestContext& ctx) { LOG_WARNING(Service_FS, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void GetFreeSpaceSize(Kernel::HLERequestContext& ctx) { + void GetFreeSpaceSize(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); IPC::ResponseBuilder rb{ctx, 4}; @@ -492,7 +489,7 @@ public: rb.Push(size.get_free_size()); } - void GetTotalSpaceSize(Kernel::HLERequestContext& ctx) { + void GetTotalSpaceSize(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); IPC::ResponseBuilder rb{ctx, 4}; @@ -500,7 +497,7 @@ public: rb.Push(size.get_total_size()); } - void GetFileTimeStampRaw(Kernel::HLERequestContext& ctx) { + void GetFileTimeStampRaw(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); @@ -536,7 +533,7 @@ public: FindAllSaves(space); } - void ReadSaveDataInfo(Kernel::HLERequestContext& ctx) { + void ReadSaveDataInfo(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); // Calculate how many entries we can fit in the output buffer @@ -814,7 +811,7 @@ FSP_SRV::FSP_SRV(Core::System& system_) FSP_SRV::~FSP_SRV() = default; -void FSP_SRV::SetCurrentProcess(Kernel::HLERequestContext& ctx) { +void FSP_SRV::SetCurrentProcess(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; current_process_id = rp.Pop<u64>(); @@ -824,7 +821,7 @@ void FSP_SRV::SetCurrentProcess(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void FSP_SRV::OpenFileSystemWithPatch(Kernel::HLERequestContext& ctx) { +void FSP_SRV::OpenFileSystemWithPatch(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto type = rp.PopRaw<FileSystemType>(); @@ -835,7 +832,7 @@ void FSP_SRV::OpenFileSystemWithPatch(Kernel::HLERequestContext& ctx) { rb.Push(ResultUnknown); } -void FSP_SRV::OpenSdCardFileSystem(Kernel::HLERequestContext& ctx) { +void FSP_SRV::OpenSdCardFileSystem(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); auto filesystem = @@ -847,7 +844,7 @@ void FSP_SRV::OpenSdCardFileSystem(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IFileSystem>(std::move(filesystem)); } -void FSP_SRV::CreateSaveDataFileSystem(Kernel::HLERequestContext& ctx) { +void FSP_SRV::CreateSaveDataFileSystem(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; auto save_struct = rp.PopRaw<FileSys::SaveDataAttribute>(); @@ -863,7 +860,7 @@ void FSP_SRV::CreateSaveDataFileSystem(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void FSP_SRV::OpenSaveDataFileSystem(Kernel::HLERequestContext& ctx) { +void FSP_SRV::OpenSaveDataFileSystem(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { @@ -908,12 +905,12 @@ void FSP_SRV::OpenSaveDataFileSystem(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IFileSystem>(std::move(filesystem)); } -void FSP_SRV::OpenReadOnlySaveDataFileSystem(Kernel::HLERequestContext& ctx) { +void FSP_SRV::OpenReadOnlySaveDataFileSystem(HLERequestContext& ctx) { LOG_WARNING(Service_FS, "(STUBBED) called, delegating to 51 OpenSaveDataFilesystem"); OpenSaveDataFileSystem(ctx); } -void FSP_SRV::OpenSaveDataInfoReaderBySaveDataSpaceId(Kernel::HLERequestContext& ctx) { +void FSP_SRV::OpenSaveDataInfoReaderBySaveDataSpaceId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto space = rp.PopRaw<FileSys::SaveDataSpaceId>(); LOG_INFO(Service_FS, "called, space={}", space); @@ -924,15 +921,14 @@ void FSP_SRV::OpenSaveDataInfoReaderBySaveDataSpaceId(Kernel::HLERequestContext& std::make_shared<ISaveDataInfoReader>(system, space, fsc)); } -void FSP_SRV::WriteSaveDataFileSystemExtraDataBySaveDataAttribute(Kernel::HLERequestContext& ctx) { +void FSP_SRV::WriteSaveDataFileSystemExtraDataBySaveDataAttribute(HLERequestContext& ctx) { LOG_WARNING(Service_FS, "(STUBBED) called."); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void FSP_SRV::ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute( - Kernel::HLERequestContext& ctx) { +void FSP_SRV::ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { @@ -958,7 +954,7 @@ void FSP_SRV::ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute( rb.Push(flags); } -void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { +void FSP_SRV::OpenDataStorageByCurrentProcess(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); auto current_romfs = fsc.OpenRomFSCurrentProcess(); @@ -977,7 +973,7 @@ void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IStorage>(std::move(storage)); } -void FSP_SRV::OpenDataStorageByDataId(Kernel::HLERequestContext& ctx) { +void FSP_SRV::OpenDataStorageByDataId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto storage_id = rp.PopRaw<FileSys::StorageId>(); const auto unknown = rp.PopRaw<u32>(); @@ -1017,7 +1013,7 @@ void FSP_SRV::OpenDataStorageByDataId(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IStorage>(std::move(storage)); } -void FSP_SRV::OpenPatchDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { +void FSP_SRV::OpenPatchDataStorageByCurrentProcess(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto storage_id = rp.PopRaw<FileSys::StorageId>(); @@ -1029,7 +1025,7 @@ void FSP_SRV::OpenPatchDataStorageByCurrentProcess(Kernel::HLERequestContext& ct rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND); } -void FSP_SRV::OpenDataStorageWithProgramIndex(Kernel::HLERequestContext& ctx) { +void FSP_SRV::OpenDataStorageWithProgramIndex(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto program_index = rp.PopRaw<u8>(); @@ -1056,7 +1052,7 @@ void FSP_SRV::OpenDataStorageWithProgramIndex(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IStorage>(std::move(storage)); } -void FSP_SRV::DisableAutoSaveDataCreation(Kernel::HLERequestContext& ctx) { +void FSP_SRV::DisableAutoSaveDataCreation(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); fsc.SetAutoSaveDataCreation(false); @@ -1065,7 +1061,7 @@ void FSP_SRV::DisableAutoSaveDataCreation(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void FSP_SRV::SetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { +void FSP_SRV::SetGlobalAccessLogMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; access_log_mode = rp.PopEnum<AccessLogMode>(); @@ -1075,7 +1071,7 @@ void FSP_SRV::SetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { +void FSP_SRV::GetGlobalAccessLogMode(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -1083,7 +1079,7 @@ void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { rb.PushEnum(access_log_mode); } -void FSP_SRV::OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx) { +void FSP_SRV::OutputAccessLogToSdCard(HLERequestContext& ctx) { const auto raw = ctx.ReadBufferCopy(); auto log = Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast<const char*>(raw.data()), raw.size()); @@ -1096,7 +1092,7 @@ void FSP_SRV::OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void FSP_SRV::GetProgramIndexForAccessLog(Kernel::HLERequestContext& ctx) { +void FSP_SRV::GetProgramIndexForAccessLog(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); IPC::ResponseBuilder rb{ctx, 4}; @@ -1105,7 +1101,7 @@ void FSP_SRV::GetProgramIndexForAccessLog(Kernel::HLERequestContext& ctx) { rb.Push(access_log_program_index); } -void FSP_SRV::GetCacheStorageSize(Kernel::HLERequestContext& ctx) { +void FSP_SRV::GetCacheStorageSize(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto index{rp.Pop<s32>()}; @@ -1131,14 +1127,14 @@ public: private: FileSys::VirtualFile backend; - void Add(Kernel::HLERequestContext& ctx) { + void Add(HLERequestContext& ctx) { LOG_WARNING(Service_FS, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void Commit(Kernel::HLERequestContext& ctx) { + void Commit(HLERequestContext& ctx) { LOG_WARNING(Service_FS, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -1146,7 +1142,7 @@ private: } }; -void FSP_SRV::OpenMultiCommitManager(Kernel::HLERequestContext& ctx) { +void FSP_SRV::OpenMultiCommitManager(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; diff --git a/src/core/hle/service/filesystem/fsp_srv.h b/src/core/hle/service/filesystem/fsp_srv.h index 3d88b97f9..49f17c7c3 100644 --- a/src/core/hle/service/filesystem/fsp_srv.h +++ b/src/core/hle/service/filesystem/fsp_srv.h @@ -35,26 +35,26 @@ public: ~FSP_SRV() override; private: - void SetCurrentProcess(Kernel::HLERequestContext& ctx); - void OpenFileSystemWithPatch(Kernel::HLERequestContext& ctx); - void OpenSdCardFileSystem(Kernel::HLERequestContext& ctx); - void CreateSaveDataFileSystem(Kernel::HLERequestContext& ctx); - void OpenSaveDataFileSystem(Kernel::HLERequestContext& ctx); - void OpenReadOnlySaveDataFileSystem(Kernel::HLERequestContext& ctx); - void OpenSaveDataInfoReaderBySaveDataSpaceId(Kernel::HLERequestContext& ctx); - void WriteSaveDataFileSystemExtraDataBySaveDataAttribute(Kernel::HLERequestContext& ctx); - void ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(Kernel::HLERequestContext& ctx); - void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); - void OpenDataStorageByDataId(Kernel::HLERequestContext& ctx); - void OpenPatchDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); - void OpenDataStorageWithProgramIndex(Kernel::HLERequestContext& ctx); - void DisableAutoSaveDataCreation(Kernel::HLERequestContext& ctx); - void SetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); - void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); - void OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx); - void GetProgramIndexForAccessLog(Kernel::HLERequestContext& ctx); - void OpenMultiCommitManager(Kernel::HLERequestContext& ctx); - void GetCacheStorageSize(Kernel::HLERequestContext& ctx); + void SetCurrentProcess(HLERequestContext& ctx); + void OpenFileSystemWithPatch(HLERequestContext& ctx); + void OpenSdCardFileSystem(HLERequestContext& ctx); + void CreateSaveDataFileSystem(HLERequestContext& ctx); + void OpenSaveDataFileSystem(HLERequestContext& ctx); + void OpenReadOnlySaveDataFileSystem(HLERequestContext& ctx); + void OpenSaveDataInfoReaderBySaveDataSpaceId(HLERequestContext& ctx); + void WriteSaveDataFileSystemExtraDataBySaveDataAttribute(HLERequestContext& ctx); + void ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(HLERequestContext& ctx); + void OpenDataStorageByCurrentProcess(HLERequestContext& ctx); + void OpenDataStorageByDataId(HLERequestContext& ctx); + void OpenPatchDataStorageByCurrentProcess(HLERequestContext& ctx); + void OpenDataStorageWithProgramIndex(HLERequestContext& ctx); + void DisableAutoSaveDataCreation(HLERequestContext& ctx); + void SetGlobalAccessLogMode(HLERequestContext& ctx); + void GetGlobalAccessLogMode(HLERequestContext& ctx); + void OutputAccessLogToSdCard(HLERequestContext& ctx); + void GetProgramIndexForAccessLog(HLERequestContext& ctx); + void OpenMultiCommitManager(HLERequestContext& ctx); + void GetCacheStorageSize(HLERequestContext& ctx); FileSystemController& fsc; const FileSys::ContentProvider& content_provider; diff --git a/src/core/hle/service/friend/errors.h b/src/core/hle/service/friend/errors.h deleted file mode 100644 index ff525d865..000000000 --- a/src/core/hle/service/friend/errors.h +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include "core/hle/result.h" - -namespace Service::Friend { - -constexpr Result ERR_NO_NOTIFICATIONS{ErrorModule::Account, 15}; -} diff --git a/src/core/hle/service/friend/friend.cpp b/src/core/hle/service/friend/friend.cpp index fad532115..9d05f9801 100644 --- a/src/core/hle/service/friend/friend.cpp +++ b/src/core/hle/service/friend/friend.cpp @@ -5,12 +5,13 @@ #include "common/logging/log.h" #include "common/uuid.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" -#include "core/hle/service/friend/errors.h" +#include "core/hle/service/acc/errors.h" #include "core/hle/service/friend/friend.h" #include "core/hle/service/friend/friend_interface.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/kernel_helpers.h" +#include "core/hle/service/server_manager.h" namespace Service::Friend { @@ -135,7 +136,7 @@ private: }; static_assert(sizeof(SizedFriendFilter) == 0x10, "SizedFriendFilter is an invalid size"); - void GetCompletionEvent(Kernel::HLERequestContext& ctx) { + void GetCompletionEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_Friend, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -143,7 +144,7 @@ private: rb.PushCopyObjects(completion_event->GetReadableEvent()); } - void GetBlockedUserListIds(Kernel::HLERequestContext& ctx) { + void GetBlockedUserListIds(HLERequestContext& ctx) { // This is safe to stub, as there should be no adverse consequences from reporting no // blocked users. LOG_WARNING(Service_Friend, "(STUBBED) called"); @@ -152,21 +153,21 @@ private: rb.Push<u32>(0); // Indicates there are no blocked users } - void DeclareCloseOnlinePlaySession(Kernel::HLERequestContext& ctx) { + void DeclareCloseOnlinePlaySession(HLERequestContext& ctx) { // Stub used by Splatoon 2 LOG_WARNING(Service_Friend, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void UpdateUserPresence(Kernel::HLERequestContext& ctx) { + void UpdateUserPresence(HLERequestContext& ctx) { // Stub used by Retro City Rampage LOG_WARNING(Service_Friend, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void GetPlayHistoryRegistrationKey(Kernel::HLERequestContext& ctx) { + void GetPlayHistoryRegistrationKey(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto local_play = rp.Pop<bool>(); const auto uuid = rp.PopRaw<Common::UUID>(); @@ -178,7 +179,7 @@ private: rb.Push(ResultSuccess); } - void GetFriendList(Kernel::HLERequestContext& ctx) { + void GetFriendList(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto friend_offset = rp.Pop<u32>(); const auto uuid = rp.PopRaw<Common::UUID>(); @@ -194,7 +195,7 @@ private: // TODO(ogniK): Return a buffer of u64s which are the "NetworkServiceAccountId" } - void CheckFriendListAvailability(Kernel::HLERequestContext& ctx) { + void CheckFriendListAvailability(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto uuid{rp.PopRaw<Common::UUID>()}; @@ -233,7 +234,7 @@ public: } private: - void GetEvent(Kernel::HLERequestContext& ctx) { + void GetEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_Friend, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -241,7 +242,7 @@ private: rb.PushCopyObjects(notification_event->GetReadableEvent()); } - void Clear(Kernel::HLERequestContext& ctx) { + void Clear(HLERequestContext& ctx) { LOG_DEBUG(Service_Friend, "called"); while (!notifications.empty()) { notifications.pop(); @@ -252,13 +253,13 @@ private: rb.Push(ResultSuccess); } - void Pop(Kernel::HLERequestContext& ctx) { + void Pop(HLERequestContext& ctx) { LOG_DEBUG(Service_Friend, "called"); if (notifications.empty()) { LOG_ERROR(Service_Friend, "No notifications in queue!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_NO_NOTIFICATIONS); + rb.Push(Account::ResultNoNotifications); return; } @@ -311,14 +312,14 @@ private: States states{}; }; -void Module::Interface::CreateFriendService(Kernel::HLERequestContext& ctx) { +void Module::Interface::CreateFriendService(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface<IFriendService>(system); LOG_DEBUG(Service_Friend, "called"); } -void Module::Interface::CreateNotificationService(Kernel::HLERequestContext& ctx) { +void Module::Interface::CreateNotificationService(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; auto uuid = rp.PopRaw<Common::UUID>(); @@ -335,13 +336,22 @@ Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& syst Module::Interface::~Interface() = default; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); auto module = std::make_shared<Module>(); - std::make_shared<Friend>(module, system, "friend:a")->InstallAsService(service_manager); - std::make_shared<Friend>(module, system, "friend:m")->InstallAsService(service_manager); - std::make_shared<Friend>(module, system, "friend:s")->InstallAsService(service_manager); - std::make_shared<Friend>(module, system, "friend:u")->InstallAsService(service_manager); - std::make_shared<Friend>(module, system, "friend:v")->InstallAsService(service_manager); + + server_manager->RegisterNamedService("friend:a", + std::make_shared<Friend>(module, system, "friend:a")); + server_manager->RegisterNamedService("friend:m", + std::make_shared<Friend>(module, system, "friend:m")); + server_manager->RegisterNamedService("friend:s", + std::make_shared<Friend>(module, system, "friend:s")); + server_manager->RegisterNamedService("friend:u", + std::make_shared<Friend>(module, system, "friend:u")); + server_manager->RegisterNamedService("friend:v", + std::make_shared<Friend>(module, system, "friend:v")); + + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::Friend diff --git a/src/core/hle/service/friend/friend.h b/src/core/hle/service/friend/friend.h index 444da8b35..2824dc786 100644 --- a/src/core/hle/service/friend/friend.h +++ b/src/core/hle/service/friend/friend.h @@ -19,15 +19,14 @@ public: const char* name); ~Interface() override; - void CreateFriendService(Kernel::HLERequestContext& ctx); - void CreateNotificationService(Kernel::HLERequestContext& ctx); + void CreateFriendService(HLERequestContext& ctx); + void CreateNotificationService(HLERequestContext& ctx); protected: std::shared_ptr<Module> module; }; }; -/// Registers all Friend services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::Friend diff --git a/src/core/hle/service/glue/arp.cpp b/src/core/hle/service/glue/arp.cpp index ce21b69e3..929dcca0d 100644 --- a/src/core/hle/service/glue/arp.cpp +++ b/src/core/hle/service/glue/arp.cpp @@ -5,12 +5,12 @@ #include "common/logging/log.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_process.h" #include "core/hle/kernel/kernel.h" #include "core/hle/service/glue/arp.h" #include "core/hle/service/glue/errors.h" #include "core/hle/service/glue/glue_manager.h" +#include "core/hle/service/ipc_helpers.h" namespace Service::Glue { @@ -51,7 +51,7 @@ ARP_R::ARP_R(Core::System& system_, const ARPManager& manager_) ARP_R::~ARP_R() = default; -void ARP_R::GetApplicationLaunchProperty(Kernel::HLERequestContext& ctx) { +void ARP_R::GetApplicationLaunchProperty(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto process_id = rp.PopRaw<u64>(); @@ -61,7 +61,7 @@ void ARP_R::GetApplicationLaunchProperty(Kernel::HLERequestContext& ctx) { if (!title_id.has_value()) { LOG_ERROR(Service_ARP, "Failed to get title ID for process ID!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_NOT_REGISTERED); + rb.Push(Glue::ResultProcessIdNotRegistered); return; } @@ -79,7 +79,7 @@ void ARP_R::GetApplicationLaunchProperty(Kernel::HLERequestContext& ctx) { rb.PushRaw(*res); } -void ARP_R::GetApplicationLaunchPropertyWithApplicationId(Kernel::HLERequestContext& ctx) { +void ARP_R::GetApplicationLaunchPropertyWithApplicationId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto title_id = rp.PopRaw<u64>(); @@ -99,7 +99,7 @@ void ARP_R::GetApplicationLaunchPropertyWithApplicationId(Kernel::HLERequestCont rb.PushRaw(*res); } -void ARP_R::GetApplicationControlProperty(Kernel::HLERequestContext& ctx) { +void ARP_R::GetApplicationControlProperty(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto process_id = rp.PopRaw<u64>(); @@ -109,7 +109,7 @@ void ARP_R::GetApplicationControlProperty(Kernel::HLERequestContext& ctx) { if (!title_id.has_value()) { LOG_ERROR(Service_ARP, "Failed to get title ID for process ID!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_NOT_REGISTERED); + rb.Push(Glue::ResultProcessIdNotRegistered); return; } @@ -128,7 +128,7 @@ void ARP_R::GetApplicationControlProperty(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void ARP_R::GetApplicationControlPropertyWithApplicationId(Kernel::HLERequestContext& ctx) { +void ARP_R::GetApplicationControlPropertyWithApplicationId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto title_id = rp.PopRaw<u64>(); @@ -169,7 +169,7 @@ public: } private: - void Issue(Kernel::HLERequestContext& ctx) { + void Issue(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto process_id = rp.PopRaw<u64>(); @@ -178,7 +178,7 @@ private: if (process_id == 0) { LOG_ERROR(Service_ARP, "Must have non-zero process ID!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_INVALID_PROCESS_ID); + rb.Push(Glue::ResultInvalidProcessId); return; } @@ -186,7 +186,7 @@ private: LOG_ERROR(Service_ARP, "Attempted to issue registrar, but registrar is already issued!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_INVALID_ACCESS); + rb.Push(Glue::ResultAlreadyBound); return; } @@ -197,7 +197,7 @@ private: rb.Push(ResultSuccess); } - void SetApplicationLaunchProperty(Kernel::HLERequestContext& ctx) { + void SetApplicationLaunchProperty(HLERequestContext& ctx) { LOG_DEBUG(Service_ARP, "called"); if (issued) { @@ -205,7 +205,7 @@ private: Service_ARP, "Attempted to set application launch property, but registrar is already issued!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_INVALID_ACCESS); + rb.Push(Glue::ResultAlreadyBound); return; } @@ -216,7 +216,7 @@ private: rb.Push(ResultSuccess); } - void SetApplicationControlProperty(Kernel::HLERequestContext& ctx) { + void SetApplicationControlProperty(HLERequestContext& ctx) { LOG_DEBUG(Service_ARP, "called"); if (issued) { @@ -224,7 +224,7 @@ private: Service_ARP, "Attempted to set application control property, but registrar is already issued!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_INVALID_ACCESS); + rb.Push(Glue::ResultAlreadyBound); return; } @@ -256,14 +256,14 @@ ARP_W::ARP_W(Core::System& system_, ARPManager& manager_) ARP_W::~ARP_W() = default; -void ARP_W::AcquireRegistrar(Kernel::HLERequestContext& ctx) { +void ARP_W::AcquireRegistrar(HLERequestContext& ctx) { LOG_DEBUG(Service_ARP, "called"); registrar = std::make_shared<IRegistrar>( system, [this](u64 process_id, ApplicationLaunchProperty launch, std::vector<u8> control) { const auto res = GetTitleIDForProcessID(system, process_id); if (!res.has_value()) { - return ERR_NOT_REGISTERED; + return Glue::ResultProcessIdNotRegistered; } return manager.Register(*res, launch, std::move(control)); @@ -274,7 +274,7 @@ void ARP_W::AcquireRegistrar(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface(registrar); } -void ARP_W::UnregisterApplicationInstance(Kernel::HLERequestContext& ctx) { +void ARP_W::UnregisterApplicationInstance(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto process_id = rp.PopRaw<u64>(); @@ -283,7 +283,7 @@ void ARP_W::UnregisterApplicationInstance(Kernel::HLERequestContext& ctx) { if (process_id == 0) { LOG_ERROR(Service_ARP, "Must have non-zero process ID!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_INVALID_PROCESS_ID); + rb.Push(Glue::ResultInvalidProcessId); return; } @@ -292,7 +292,7 @@ void ARP_W::UnregisterApplicationInstance(Kernel::HLERequestContext& ctx) { if (!title_id.has_value()) { LOG_ERROR(Service_ARP, "No title ID for process ID!"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_NOT_REGISTERED); + rb.Push(Glue::ResultProcessIdNotRegistered); return; } diff --git a/src/core/hle/service/glue/arp.h b/src/core/hle/service/glue/arp.h index 06c992e88..5bce80175 100644 --- a/src/core/hle/service/glue/arp.h +++ b/src/core/hle/service/glue/arp.h @@ -16,10 +16,10 @@ public: ~ARP_R() override; private: - void GetApplicationLaunchProperty(Kernel::HLERequestContext& ctx); - void GetApplicationLaunchPropertyWithApplicationId(Kernel::HLERequestContext& ctx); - void GetApplicationControlProperty(Kernel::HLERequestContext& ctx); - void GetApplicationControlPropertyWithApplicationId(Kernel::HLERequestContext& ctx); + void GetApplicationLaunchProperty(HLERequestContext& ctx); + void GetApplicationLaunchPropertyWithApplicationId(HLERequestContext& ctx); + void GetApplicationControlProperty(HLERequestContext& ctx); + void GetApplicationControlPropertyWithApplicationId(HLERequestContext& ctx); const ARPManager& manager; }; @@ -30,8 +30,8 @@ public: ~ARP_W() override; private: - void AcquireRegistrar(Kernel::HLERequestContext& ctx); - void UnregisterApplicationInstance(Kernel::HLERequestContext& ctx); + void AcquireRegistrar(HLERequestContext& ctx); + void UnregisterApplicationInstance(HLERequestContext& ctx); ARPManager& manager; std::shared_ptr<IRegistrar> registrar; diff --git a/src/core/hle/service/glue/bgtc.cpp b/src/core/hle/service/glue/bgtc.cpp index 3248091c3..ae22ac4f7 100644 --- a/src/core/hle/service/glue/bgtc.cpp +++ b/src/core/hle/service/glue/bgtc.cpp @@ -3,8 +3,8 @@ #include "common/logging/log.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/glue/bgtc.h" +#include "core/hle/service/ipc_helpers.h" namespace Service::Glue { @@ -20,7 +20,7 @@ BGTC_T::BGTC_T(Core::System& system_) : ServiceFramework{system_, "bgtc:t"} { BGTC_T::~BGTC_T() = default; -void BGTC_T::OpenTaskService(Kernel::HLERequestContext& ctx) { +void BGTC_T::OpenTaskService(HLERequestContext& ctx) { LOG_DEBUG(Service_BGTC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; diff --git a/src/core/hle/service/glue/bgtc.h b/src/core/hle/service/glue/bgtc.h index d6e2baec1..5a5d9c9a7 100644 --- a/src/core/hle/service/glue/bgtc.h +++ b/src/core/hle/service/glue/bgtc.h @@ -16,7 +16,7 @@ public: explicit BGTC_T(Core::System& system_); ~BGTC_T() override; - void OpenTaskService(Kernel::HLERequestContext& ctx); + void OpenTaskService(HLERequestContext& ctx); }; class ITaskService final : public ServiceFramework<ITaskService> { diff --git a/src/core/hle/service/glue/errors.h b/src/core/hle/service/glue/errors.h index d4ce7f44e..30feaa5c0 100644 --- a/src/core/hle/service/glue/errors.h +++ b/src/core/hle/service/glue/errors.h @@ -7,9 +7,8 @@ namespace Service::Glue { -constexpr Result ERR_INVALID_RESOURCE{ErrorModule::ARP, 30}; -constexpr Result ERR_INVALID_PROCESS_ID{ErrorModule::ARP, 31}; -constexpr Result ERR_INVALID_ACCESS{ErrorModule::ARP, 42}; -constexpr Result ERR_NOT_REGISTERED{ErrorModule::ARP, 102}; +constexpr Result ResultInvalidProcessId{ErrorModule::ARP, 31}; +constexpr Result ResultAlreadyBound{ErrorModule::ARP, 42}; +constexpr Result ResultProcessIdNotRegistered{ErrorModule::ARP, 102}; } // namespace Service::Glue diff --git a/src/core/hle/service/glue/glue.cpp b/src/core/hle/service/glue/glue.cpp index 717f2562b..993c3d21d 100644 --- a/src/core/hle/service/glue/glue.cpp +++ b/src/core/hle/service/glue/glue.cpp @@ -8,25 +8,30 @@ #include "core/hle/service/glue/ectx.h" #include "core/hle/service/glue/glue.h" #include "core/hle/service/glue/notif.h" +#include "core/hle/service/server_manager.h" namespace Service::Glue { -void InstallInterfaces(Core::System& system) { +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + // ARP - std::make_shared<ARP_R>(system, system.GetARPManager()) - ->InstallAsService(system.ServiceManager()); - std::make_shared<ARP_W>(system, system.GetARPManager()) - ->InstallAsService(system.ServiceManager()); + server_manager->RegisterNamedService("arp:r", + std::make_shared<ARP_R>(system, system.GetARPManager())); + server_manager->RegisterNamedService("arp:w", + std::make_shared<ARP_W>(system, system.GetARPManager())); // BackGround Task Controller - std::make_shared<BGTC_T>(system)->InstallAsService(system.ServiceManager()); - std::make_shared<BGTC_SC>(system)->InstallAsService(system.ServiceManager()); + server_manager->RegisterNamedService("bgtc:t", std::make_shared<BGTC_T>(system)); + server_manager->RegisterNamedService("bgtc:sc", std::make_shared<BGTC_SC>(system)); // Error Context - std::make_shared<ECTX_AW>(system)->InstallAsService(system.ServiceManager()); + server_manager->RegisterNamedService("ectx:aw", std::make_shared<ECTX_AW>(system)); // Notification Services for application - std::make_shared<NOTIF_A>(system)->InstallAsService(system.ServiceManager()); + server_manager->RegisterNamedService("notif:a", std::make_shared<NOTIF_A>(system)); + + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::Glue diff --git a/src/core/hle/service/glue/glue.h b/src/core/hle/service/glue/glue.h index ae7c6d235..2a906f5ad 100644 --- a/src/core/hle/service/glue/glue.h +++ b/src/core/hle/service/glue/glue.h @@ -9,7 +9,6 @@ class System; namespace Service::Glue { -/// Registers all Glue services with the specified service manager. -void InstallInterfaces(Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::Glue diff --git a/src/core/hle/service/glue/glue_manager.cpp b/src/core/hle/service/glue/glue_manager.cpp index 8a654cdca..4bf67921b 100644 --- a/src/core/hle/service/glue/glue_manager.cpp +++ b/src/core/hle/service/glue/glue_manager.cpp @@ -17,12 +17,12 @@ ARPManager::~ARPManager() = default; ResultVal<ApplicationLaunchProperty> ARPManager::GetLaunchProperty(u64 title_id) const { if (title_id == 0) { - return ERR_INVALID_PROCESS_ID; + return Glue::ResultInvalidProcessId; } const auto iter = entries.find(title_id); if (iter == entries.end()) { - return ERR_NOT_REGISTERED; + return Glue::ResultProcessIdNotRegistered; } return iter->second.launch; @@ -30,12 +30,12 @@ ResultVal<ApplicationLaunchProperty> ARPManager::GetLaunchProperty(u64 title_id) ResultVal<std::vector<u8>> ARPManager::GetControlProperty(u64 title_id) const { if (title_id == 0) { - return ERR_INVALID_PROCESS_ID; + return Glue::ResultInvalidProcessId; } const auto iter = entries.find(title_id); if (iter == entries.end()) { - return ERR_NOT_REGISTERED; + return Glue::ResultProcessIdNotRegistered; } return iter->second.control; @@ -44,12 +44,12 @@ ResultVal<std::vector<u8>> ARPManager::GetControlProperty(u64 title_id) const { Result ARPManager::Register(u64 title_id, ApplicationLaunchProperty launch, std::vector<u8> control) { if (title_id == 0) { - return ERR_INVALID_PROCESS_ID; + return Glue::ResultInvalidProcessId; } const auto iter = entries.find(title_id); if (iter != entries.end()) { - return ERR_INVALID_ACCESS; + return Glue::ResultAlreadyBound; } entries.insert_or_assign(title_id, MapEntry{launch, std::move(control)}); @@ -58,12 +58,12 @@ Result ARPManager::Register(u64 title_id, ApplicationLaunchProperty launch, Result ARPManager::Unregister(u64 title_id) { if (title_id == 0) { - return ERR_INVALID_PROCESS_ID; + return Glue::ResultInvalidProcessId; } const auto iter = entries.find(title_id); if (iter == entries.end()) { - return ERR_NOT_REGISTERED; + return Glue::ResultProcessIdNotRegistered; } entries.erase(iter); diff --git a/src/core/hle/service/glue/glue_manager.h b/src/core/hle/service/glue/glue_manager.h index cd0b092ac..1cf53d9d9 100644 --- a/src/core/hle/service/glue/glue_manager.h +++ b/src/core/hle/service/glue/glue_manager.h @@ -30,23 +30,23 @@ public: ~ARPManager(); // Returns the ApplicationLaunchProperty corresponding to the provided title ID if it was - // previously registered, otherwise ERR_NOT_REGISTERED if it was never registered or - // ERR_INVALID_PROCESS_ID if the title ID is 0. + // previously registered, otherwise ResultProcessIdNotRegistered if it was never registered or + // ResultInvalidProcessId if the title ID is 0. ResultVal<ApplicationLaunchProperty> GetLaunchProperty(u64 title_id) const; // Returns a vector of the raw bytes of NACP data (necessarily 0x4000 in size) corresponding to - // the provided title ID if it was previously registered, otherwise ERR_NOT_REGISTERED if it was - // never registered or ERR_INVALID_PROCESS_ID if the title ID is 0. + // the provided title ID if it was previously registered, otherwise ResultProcessIdNotRegistered + // if it was never registered or ResultInvalidProcessId if the title ID is 0. ResultVal<std::vector<u8>> GetControlProperty(u64 title_id) const; // Adds a new entry to the internal database with the provided parameters, returning - // ERR_INVALID_ACCESS if attempting to re-register a title ID without an intermediate Unregister - // step, and ERR_INVALID_PROCESS_ID if the title ID is 0. + // ResultProcessIdNotRegistered if attempting to re-register a title ID without an intermediate + // Unregister step, and ResultInvalidProcessId if the title ID is 0. Result Register(u64 title_id, ApplicationLaunchProperty launch, std::vector<u8> control); // Removes the registration for the provided title ID from the database, returning - // ERR_NOT_REGISTERED if it doesn't exist in the database and ERR_INVALID_PROCESS_ID if the - // title ID is 0. + // ResultProcessIdNotRegistered if it doesn't exist in the database and ResultInvalidProcessId + // if the title ID is 0. Result Unregister(u64 title_id); // Removes all entries from the database, always succeeds. Should only be used when resetting diff --git a/src/core/hle/service/glue/notif.cpp b/src/core/hle/service/glue/notif.cpp index 3ace2dabd..fec4ad86c 100644 --- a/src/core/hle/service/glue/notif.cpp +++ b/src/core/hle/service/glue/notif.cpp @@ -6,8 +6,8 @@ #include "common/assert.h" #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/glue/notif.h" +#include "core/hle/service/ipc_helpers.h" namespace Service::Glue { @@ -28,7 +28,7 @@ NOTIF_A::NOTIF_A(Core::System& system_) : ServiceFramework{system_, "notif:a"} { NOTIF_A::~NOTIF_A() = default; -void NOTIF_A::RegisterAlarmSetting(Kernel::HLERequestContext& ctx) { +void NOTIF_A::RegisterAlarmSetting(HLERequestContext& ctx) { const auto alarm_setting_buffer_size = ctx.GetReadBufferSize(0); const auto application_parameter_size = ctx.GetReadBufferSize(1); @@ -63,7 +63,7 @@ void NOTIF_A::RegisterAlarmSetting(Kernel::HLERequestContext& ctx) { rb.Push(new_alarm.alarm_setting_id); } -void NOTIF_A::UpdateAlarmSetting(Kernel::HLERequestContext& ctx) { +void NOTIF_A::UpdateAlarmSetting(HLERequestContext& ctx) { const auto alarm_setting_buffer_size = ctx.GetReadBufferSize(0); const auto application_parameter_size = ctx.GetReadBufferSize(1); @@ -91,7 +91,7 @@ void NOTIF_A::UpdateAlarmSetting(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void NOTIF_A::ListAlarmSettings(Kernel::HLERequestContext& ctx) { +void NOTIF_A::ListAlarmSettings(HLERequestContext& ctx) { LOG_INFO(Service_NOTIF, "called, alarm_count={}", alarms.size()); // TODO: Only return alarms of this game id @@ -102,7 +102,7 @@ void NOTIF_A::ListAlarmSettings(Kernel::HLERequestContext& ctx) { rb.Push(static_cast<u32>(alarms.size())); } -void NOTIF_A::LoadApplicationParameter(Kernel::HLERequestContext& ctx) { +void NOTIF_A::LoadApplicationParameter(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto alarm_setting_id{rp.Pop<AlarmSettingId>()}; @@ -126,7 +126,7 @@ void NOTIF_A::LoadApplicationParameter(Kernel::HLERequestContext& ctx) { rb.Push(static_cast<u32>(application_parameter.size())); } -void NOTIF_A::DeleteAlarmSetting(Kernel::HLERequestContext& ctx) { +void NOTIF_A::DeleteAlarmSetting(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto alarm_setting_id{rp.Pop<AlarmSettingId>()}; @@ -140,7 +140,7 @@ void NOTIF_A::DeleteAlarmSetting(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void NOTIF_A::Initialize(Kernel::HLERequestContext& ctx) { +void NOTIF_A::Initialize(HLERequestContext& ctx) { // TODO: Load previous alarms from config LOG_WARNING(Service_NOTIF, "(STUBBED) called"); diff --git a/src/core/hle/service/glue/notif.h b/src/core/hle/service/glue/notif.h index 4467e1f35..b1187f3a3 100644 --- a/src/core/hle/service/glue/notif.h +++ b/src/core/hle/service/glue/notif.h @@ -56,12 +56,12 @@ private: }; static_assert(sizeof(AlarmSetting) == 0x40, "AlarmSetting is an invalid size"); - void RegisterAlarmSetting(Kernel::HLERequestContext& ctx); - void UpdateAlarmSetting(Kernel::HLERequestContext& ctx); - void ListAlarmSettings(Kernel::HLERequestContext& ctx); - void LoadApplicationParameter(Kernel::HLERequestContext& ctx); - void DeleteAlarmSetting(Kernel::HLERequestContext& ctx); - void Initialize(Kernel::HLERequestContext& ctx); + void RegisterAlarmSetting(HLERequestContext& ctx); + void UpdateAlarmSetting(HLERequestContext& ctx); + void ListAlarmSettings(HLERequestContext& ctx); + void LoadApplicationParameter(HLERequestContext& ctx); + void DeleteAlarmSetting(HLERequestContext& ctx); + void Initialize(HLERequestContext& ctx); std::vector<AlarmSetting>::iterator GetAlarmFromId(AlarmSettingId alarm_setting_id); diff --git a/src/core/hle/service/grc/grc.cpp b/src/core/hle/service/grc/grc.cpp index 4b684f6d0..64275da36 100644 --- a/src/core/hle/service/grc/grc.cpp +++ b/src/core/hle/service/grc/grc.cpp @@ -4,8 +4,8 @@ #include <memory> #include "core/hle/service/grc/grc.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" namespace Service::GRC { @@ -26,8 +26,11 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<GRC>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("grc:c", std::make_shared<GRC>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::GRC diff --git a/src/core/hle/service/grc/grc.h b/src/core/hle/service/grc/grc.h index f8c2f8dab..a3f8a5b90 100644 --- a/src/core/hle/service/grc/grc.h +++ b/src/core/hle/service/grc/grc.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::GRC { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::GRC diff --git a/src/core/hle/service/hid/controllers/console_sixaxis.cpp b/src/core/hle/service/hid/controllers/console_sixaxis.cpp index bb3cba910..478d38590 100644 --- a/src/core/hle/service/hid/controllers/console_sixaxis.cpp +++ b/src/core/hle/service/hid/controllers/console_sixaxis.cpp @@ -1,17 +1,18 @@ // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "core/core.h" #include "core/core_timing.h" #include "core/hid/emulated_console.h" #include "core/hid/hid_core.h" #include "core/hle/service/hid/controllers/console_sixaxis.h" +#include "core/memory.h" namespace Service::HID { constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C200; -Controller_ConsoleSixAxis::Controller_ConsoleSixAxis(Core::HID::HIDCore& hid_core_, - u8* raw_shared_memory_) - : ControllerBase{hid_core_} { +Controller_ConsoleSixAxis::Controller_ConsoleSixAxis(Core::System& system_, u8* raw_shared_memory_) + : ControllerBase{system_.HIDCore()}, system{system_} { console = hid_core.GetEmulatedConsole(); static_assert(SHARED_MEMORY_OFFSET + sizeof(ConsoleSharedMemory) < shared_memory_size, "ConsoleSharedMemory is bigger than the shared memory"); @@ -26,7 +27,7 @@ void Controller_ConsoleSixAxis::OnInit() {} void Controller_ConsoleSixAxis::OnRelease() {} void Controller_ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { - if (!IsControllerActivated() || !is_transfer_memory_set) { + if (!IsControllerActivated() || transfer_memory == 0) { seven_sixaxis_lifo.buffer_count = 0; seven_sixaxis_lifo.buffer_tail = 0; return; @@ -59,11 +60,10 @@ void Controller_ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_ti // Update seven six axis transfer memory seven_sixaxis_lifo.WriteNextEntry(next_seven_sixaxis_state); - std::memcpy(transfer_memory, &seven_sixaxis_lifo, sizeof(seven_sixaxis_lifo)); + system.Memory().WriteBlock(transfer_memory, &seven_sixaxis_lifo, sizeof(seven_sixaxis_lifo)); } -void Controller_ConsoleSixAxis::SetTransferMemoryPointer(u8* t_mem) { - is_transfer_memory_set = true; +void Controller_ConsoleSixAxis::SetTransferMemoryAddress(VAddr t_mem) { transfer_memory = t_mem; } diff --git a/src/core/hle/service/hid/controllers/console_sixaxis.h b/src/core/hle/service/hid/controllers/console_sixaxis.h index 2fd11538f..8d3e4081b 100644 --- a/src/core/hle/service/hid/controllers/console_sixaxis.h +++ b/src/core/hle/service/hid/controllers/console_sixaxis.h @@ -10,6 +10,10 @@ #include "core/hle/service/hid/controllers/controller_base.h" #include "core/hle/service/hid/ring_lifo.h" +namespace Core { +class System; +} // namespace Core + namespace Core::HID { class EmulatedConsole; } // namespace Core::HID @@ -17,7 +21,7 @@ class EmulatedConsole; namespace Service::HID { class Controller_ConsoleSixAxis final : public ControllerBase { public: - explicit Controller_ConsoleSixAxis(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); + explicit Controller_ConsoleSixAxis(Core::System& system_, u8* raw_shared_memory_); ~Controller_ConsoleSixAxis() override; // Called when the controller is initialized @@ -30,7 +34,7 @@ public: void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; // Called on InitializeSevenSixAxisSensor - void SetTransferMemoryPointer(u8* t_mem); + void SetTransferMemoryAddress(VAddr t_mem); // Called on ResetSevenSixAxisSensorTimestamp void ResetTimestamp(); @@ -62,12 +66,13 @@ private: static_assert(sizeof(seven_sixaxis_lifo) == 0xA70, "SevenSixAxisState is an invalid size"); SevenSixAxisState next_seven_sixaxis_state{}; - u8* transfer_memory = nullptr; + VAddr transfer_memory{}; ConsoleSharedMemory* shared_memory = nullptr; Core::HID::EmulatedConsole* console = nullptr; - bool is_transfer_memory_set = false; u64 last_saved_timestamp{}; u64 last_global_timestamp{}; + + Core::System& system; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/palma.cpp b/src/core/hle/service/hid/controllers/palma.cpp index 4564ea1e2..bce51285c 100644 --- a/src/core/hle/service/hid/controllers/palma.cpp +++ b/src/core/hle/service/hid/controllers/palma.cpp @@ -152,7 +152,7 @@ Result Controller_Palma::WritePalmaRgbLedPatternEntry(const PalmaConnectionHandl } Result Controller_Palma::WritePalmaWaveEntry(const PalmaConnectionHandle& handle, PalmaWaveSet wave, - u8* t_mem, u64 size) { + VAddr t_mem, u64 size) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } diff --git a/src/core/hle/service/hid/controllers/palma.h b/src/core/hle/service/hid/controllers/palma.h index 1d7fc94e1..cf62f0dbc 100644 --- a/src/core/hle/service/hid/controllers/palma.h +++ b/src/core/hle/service/hid/controllers/palma.h @@ -125,7 +125,7 @@ public: Result ReadPalmaUniqueCode(const PalmaConnectionHandle& handle); Result SetPalmaUniqueCodeInvalid(const PalmaConnectionHandle& handle); Result WritePalmaRgbLedPatternEntry(const PalmaConnectionHandle& handle, u64 unknown); - Result WritePalmaWaveEntry(const PalmaConnectionHandle& handle, PalmaWaveSet wave, u8* t_mem, + Result WritePalmaWaveEntry(const PalmaConnectionHandle& handle, PalmaWaveSet wave, VAddr t_mem, u64 size); Result SetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& handle, s32 database_id_version_); diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 8c99cec06..56c7275df 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -8,7 +8,6 @@ #include "core/core.h" #include "core/core_timing.h" #include "core/hid/hid_core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_readable_event.h" #include "core/hle/kernel/k_shared_memory.h" #include "core/hle/kernel/k_transfer_memory.h" @@ -18,6 +17,8 @@ #include "core/hle/service/hid/hidbus.h" #include "core/hle/service/hid/irs.h" #include "core/hle/service/hid/xcd.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/memory.h" #include "core/hle/service/hid/controllers/console_sixaxis.h" @@ -137,7 +138,7 @@ IAppletResource::~IAppletResource() { system.CoreTiming().UnscheduleEvent(motion_update_event, 0); } -void IAppletResource::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) { +void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -202,7 +203,7 @@ public: } private: - void InitializeVibrationDevice(Kernel::HLERequestContext& ctx) { + void InitializeVibrationDevice(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto vibration_device_handle{rp.PopRaw<Core::HID::VibrationDeviceHandle>()}; @@ -381,7 +382,7 @@ Hid::Hid(Core::System& system_) Hid::~Hid() = default; -void Hid::CreateAppletResource(Kernel::HLERequestContext& ctx) { +void Hid::CreateAppletResource(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -396,7 +397,7 @@ void Hid::CreateAppletResource(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IAppletResource>(applet_resource); } -void Hid::ActivateDebugPad(Kernel::HLERequestContext& ctx) { +void Hid::ActivateDebugPad(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -408,7 +409,7 @@ void Hid::ActivateDebugPad(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::ActivateTouchScreen(Kernel::HLERequestContext& ctx) { +void Hid::ActivateTouchScreen(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -420,7 +421,7 @@ void Hid::ActivateTouchScreen(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::ActivateMouse(Kernel::HLERequestContext& ctx) { +void Hid::ActivateMouse(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -432,7 +433,7 @@ void Hid::ActivateMouse(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::ActivateKeyboard(Kernel::HLERequestContext& ctx) { +void Hid::ActivateKeyboard(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -444,7 +445,7 @@ void Hid::ActivateKeyboard(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::SendKeyboardLockKeyEvent(Kernel::HLERequestContext& ctx) { +void Hid::SendKeyboardLockKeyEvent(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto flags{rp.Pop<u32>()}; @@ -454,7 +455,7 @@ void Hid::SendKeyboardLockKeyEvent(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::ActivateXpad(Kernel::HLERequestContext& ctx) { +void Hid::ActivateXpad(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { u32 basic_xpad_id; @@ -474,7 +475,7 @@ void Hid::ActivateXpad(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::GetXpadIDs(Kernel::HLERequestContext& ctx) { +void Hid::GetXpadIDs(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -485,7 +486,7 @@ void Hid::GetXpadIDs(Kernel::HLERequestContext& ctx) { rb.Push(0); } -void Hid::ActivateSixAxisSensor(Kernel::HLERequestContext& ctx) { +void Hid::ActivateSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { u32 basic_xpad_id; @@ -505,7 +506,7 @@ void Hid::ActivateSixAxisSensor(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::DeactivateSixAxisSensor(Kernel::HLERequestContext& ctx) { +void Hid::DeactivateSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { u32 basic_xpad_id; @@ -525,7 +526,7 @@ void Hid::DeactivateSixAxisSensor(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::StartSixAxisSensor(Kernel::HLERequestContext& ctx) { +void Hid::StartSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -548,7 +549,7 @@ void Hid::StartSixAxisSensor(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::StopSixAxisSensor(Kernel::HLERequestContext& ctx) { +void Hid::StopSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -571,7 +572,7 @@ void Hid::StopSixAxisSensor(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::IsSixAxisSensorFusionEnabled(Kernel::HLERequestContext& ctx) { +void Hid::IsSixAxisSensorFusionEnabled(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -597,7 +598,7 @@ void Hid::IsSixAxisSensorFusionEnabled(Kernel::HLERequestContext& ctx) { rb.Push(is_enabled); } -void Hid::EnableSixAxisSensorFusion(Kernel::HLERequestContext& ctx) { +void Hid::EnableSixAxisSensorFusion(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { bool enable_sixaxis_sensor_fusion; @@ -624,7 +625,7 @@ void Hid::EnableSixAxisSensorFusion(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::SetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { +void Hid::SetSixAxisSensorFusionParameters(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -651,7 +652,7 @@ void Hid::SetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::GetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { +void Hid::GetSixAxisSensorFusionParameters(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -678,7 +679,7 @@ void Hid::GetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { rb.PushRaw(fusion_parameters); } -void Hid::ResetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { +void Hid::ResetSixAxisSensorFusionParameters(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -712,7 +713,7 @@ void Hid::ResetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { rb.Push(result2); } -void Hid::SetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { +void Hid::SetGyroscopeZeroDriftMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto sixaxis_handle{rp.PopRaw<Core::HID::SixAxisSensorHandle>()}; const auto drift_mode{rp.PopEnum<Core::HID::GyroscopeZeroDriftMode>()}; @@ -731,7 +732,7 @@ void Hid::SetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::GetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { +void Hid::GetGyroscopeZeroDriftMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -756,7 +757,7 @@ void Hid::GetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { rb.PushEnum(drift_mode); } -void Hid::ResetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { +void Hid::ResetGyroscopeZeroDriftMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -780,7 +781,7 @@ void Hid::ResetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::IsSixAxisSensorAtRest(Kernel::HLERequestContext& ctx) { +void Hid::IsSixAxisSensorAtRest(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -805,7 +806,7 @@ void Hid::IsSixAxisSensorAtRest(Kernel::HLERequestContext& ctx) { rb.Push(is_at_rest); } -void Hid::IsFirmwareUpdateAvailableForSixAxisSensor(Kernel::HLERequestContext& ctx) { +void Hid::IsFirmwareUpdateAvailableForSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -832,7 +833,7 @@ void Hid::IsFirmwareUpdateAvailableForSixAxisSensor(Kernel::HLERequestContext& c rb.Push(is_firmware_available); } -void Hid::EnableSixAxisSensorUnalteredPassthrough(Kernel::HLERequestContext& ctx) { +void Hid::EnableSixAxisSensorUnalteredPassthrough(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { bool enabled; @@ -858,7 +859,7 @@ void Hid::EnableSixAxisSensorUnalteredPassthrough(Kernel::HLERequestContext& ctx rb.Push(result); } -void Hid::IsSixAxisSensorUnalteredPassthroughEnabled(Kernel::HLERequestContext& ctx) { +void Hid::IsSixAxisSensorUnalteredPassthroughEnabled(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -885,7 +886,7 @@ void Hid::IsSixAxisSensorUnalteredPassthroughEnabled(Kernel::HLERequestContext& rb.Push(is_unaltered_sisxaxis_enabled); } -void Hid::LoadSixAxisSensorCalibrationParameter(Kernel::HLERequestContext& ctx) { +void Hid::LoadSixAxisSensorCalibrationParameter(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -915,7 +916,7 @@ void Hid::LoadSixAxisSensorCalibrationParameter(Kernel::HLERequestContext& ctx) rb.Push(result); } -void Hid::GetSixAxisSensorIcInformation(Kernel::HLERequestContext& ctx) { +void Hid::GetSixAxisSensorIcInformation(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -945,7 +946,7 @@ void Hid::GetSixAxisSensorIcInformation(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::ResetIsSixAxisSensorDeviceNewlyAssigned(Kernel::HLERequestContext& ctx) { +void Hid::ResetIsSixAxisSensorDeviceNewlyAssigned(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::SixAxisSensorHandle sixaxis_handle; @@ -970,7 +971,7 @@ void Hid::ResetIsSixAxisSensorDeviceNewlyAssigned(Kernel::HLERequestContext& ctx rb.Push(result); } -void Hid::ActivateGesture(Kernel::HLERequestContext& ctx) { +void Hid::ActivateGesture(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { u32 unknown; @@ -990,7 +991,7 @@ void Hid::ActivateGesture(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { +void Hid::SetSupportedNpadStyleSet(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::NpadStyleSet supported_styleset; @@ -1011,7 +1012,7 @@ void Hid::SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { +void Hid::GetSupportedNpadStyleSet(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1024,7 +1025,7 @@ void Hid::GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { .raw); } -void Hid::SetSupportedNpadIdType(Kernel::HLERequestContext& ctx) { +void Hid::SetSupportedNpadIdType(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1037,7 +1038,7 @@ void Hid::SetSupportedNpadIdType(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::ActivateNpad(Kernel::HLERequestContext& ctx) { +void Hid::ActivateNpad(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1049,7 +1050,7 @@ void Hid::ActivateNpad(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::DeactivateNpad(Kernel::HLERequestContext& ctx) { +void Hid::DeactivateNpad(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1061,7 +1062,7 @@ void Hid::DeactivateNpad(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::AcquireNpadStyleSetUpdateEventHandle(Kernel::HLERequestContext& ctx) { +void Hid::AcquireNpadStyleSetUpdateEventHandle(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::NpadIdType npad_id; @@ -1086,7 +1087,7 @@ void Hid::AcquireNpadStyleSetUpdateEventHandle(Kernel::HLERequestContext& ctx) { .GetStyleSetChangedEvent(parameters.npad_id)); } -void Hid::DisconnectNpad(Kernel::HLERequestContext& ctx) { +void Hid::DisconnectNpad(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::NpadIdType npad_id; @@ -1107,7 +1108,7 @@ void Hid::DisconnectNpad(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::GetPlayerLedPattern(Kernel::HLERequestContext& ctx) { +void Hid::GetPlayerLedPattern(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto npad_id{rp.PopEnum<Core::HID::NpadIdType>()}; @@ -1122,7 +1123,7 @@ void Hid::GetPlayerLedPattern(Kernel::HLERequestContext& ctx) { rb.Push(pattern.raw); } -void Hid::ActivateNpadWithRevision(Kernel::HLERequestContext& ctx) { +void Hid::ActivateNpadWithRevision(HLERequestContext& ctx) { // Should have no effect with how our npad sets up the data IPC::RequestParser rp{ctx}; struct Parameters { @@ -1143,7 +1144,7 @@ void Hid::ActivateNpadWithRevision(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::SetNpadJoyHoldType(Kernel::HLERequestContext& ctx) { +void Hid::SetNpadJoyHoldType(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; const auto hold_type{rp.PopEnum<Controller_NPad::NpadJoyHoldType>()}; @@ -1157,7 +1158,7 @@ void Hid::SetNpadJoyHoldType(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::GetNpadJoyHoldType(Kernel::HLERequestContext& ctx) { +void Hid::GetNpadJoyHoldType(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1168,7 +1169,7 @@ void Hid::GetNpadJoyHoldType(Kernel::HLERequestContext& ctx) { rb.PushEnum(applet_resource->GetController<Controller_NPad>(HidController::NPad).GetHoldType()); } -void Hid::SetNpadJoyAssignmentModeSingleByDefault(Kernel::HLERequestContext& ctx) { +void Hid::SetNpadJoyAssignmentModeSingleByDefault(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::NpadIdType npad_id; @@ -1190,7 +1191,7 @@ void Hid::SetNpadJoyAssignmentModeSingleByDefault(Kernel::HLERequestContext& ctx rb.Push(ResultSuccess); } -void Hid::SetNpadJoyAssignmentModeSingle(Kernel::HLERequestContext& ctx) { +void Hid::SetNpadJoyAssignmentModeSingle(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::NpadIdType npad_id; @@ -1214,7 +1215,7 @@ void Hid::SetNpadJoyAssignmentModeSingle(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::SetNpadJoyAssignmentModeDual(Kernel::HLERequestContext& ctx) { +void Hid::SetNpadJoyAssignmentModeDual(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::NpadIdType npad_id; @@ -1235,7 +1236,7 @@ void Hid::SetNpadJoyAssignmentModeDual(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::MergeSingleJoyAsDualJoy(Kernel::HLERequestContext& ctx) { +void Hid::MergeSingleJoyAsDualJoy(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto npad_id_1{rp.PopEnum<Core::HID::NpadIdType>()}; const auto npad_id_2{rp.PopEnum<Core::HID::NpadIdType>()}; @@ -1251,7 +1252,7 @@ void Hid::MergeSingleJoyAsDualJoy(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::StartLrAssignmentMode(Kernel::HLERequestContext& ctx) { +void Hid::StartLrAssignmentMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1263,7 +1264,7 @@ void Hid::StartLrAssignmentMode(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::StopLrAssignmentMode(Kernel::HLERequestContext& ctx) { +void Hid::StopLrAssignmentMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1275,7 +1276,7 @@ void Hid::StopLrAssignmentMode(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::SetNpadHandheldActivationMode(Kernel::HLERequestContext& ctx) { +void Hid::SetNpadHandheldActivationMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; const auto activation_mode{rp.PopEnum<Controller_NPad::NpadHandheldActivationMode>()}; @@ -1290,7 +1291,7 @@ void Hid::SetNpadHandheldActivationMode(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::GetNpadHandheldActivationMode(Kernel::HLERequestContext& ctx) { +void Hid::GetNpadHandheldActivationMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1302,7 +1303,7 @@ void Hid::GetNpadHandheldActivationMode(Kernel::HLERequestContext& ctx) { .GetNpadHandheldActivationMode()); } -void Hid::SwapNpadAssignment(Kernel::HLERequestContext& ctx) { +void Hid::SwapNpadAssignment(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto npad_id_1{rp.PopEnum<Core::HID::NpadIdType>()}; const auto npad_id_2{rp.PopEnum<Core::HID::NpadIdType>()}; @@ -1318,7 +1319,7 @@ void Hid::SwapNpadAssignment(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::IsUnintendedHomeButtonInputProtectionEnabled(Kernel::HLERequestContext& ctx) { +void Hid::IsUnintendedHomeButtonInputProtectionEnabled(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::NpadIdType npad_id; @@ -1342,7 +1343,7 @@ void Hid::IsUnintendedHomeButtonInputProtectionEnabled(Kernel::HLERequestContext rb.Push(is_enabled); } -void Hid::EnableUnintendedHomeButtonInputProtection(Kernel::HLERequestContext& ctx) { +void Hid::EnableUnintendedHomeButtonInputProtection(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { bool unintended_home_button_input_protection; @@ -1368,7 +1369,7 @@ void Hid::EnableUnintendedHomeButtonInputProtection(Kernel::HLERequestContext& c rb.Push(result); } -void Hid::SetNpadAnalogStickUseCenterClamp(Kernel::HLERequestContext& ctx) { +void Hid::SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { bool analog_stick_use_center_clamp; @@ -1391,7 +1392,7 @@ void Hid::SetNpadAnalogStickUseCenterClamp(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::SetNpadCaptureButtonAssignment(Kernel::HLERequestContext& ctx) { +void Hid::SetNpadCaptureButtonAssignment(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::NpadStyleSet npad_styleset; @@ -1411,7 +1412,7 @@ void Hid::SetNpadCaptureButtonAssignment(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::ClearNpadCaptureButtonAssignment(Kernel::HLERequestContext& ctx) { +void Hid::ClearNpadCaptureButtonAssignment(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1422,7 +1423,7 @@ void Hid::ClearNpadCaptureButtonAssignment(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::GetVibrationDeviceInfo(Kernel::HLERequestContext& ctx) { +void Hid::GetVibrationDeviceInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto vibration_device_handle{rp.PopRaw<Core::HID::VibrationDeviceHandle>()}; const auto& controller = @@ -1482,7 +1483,7 @@ void Hid::GetVibrationDeviceInfo(Kernel::HLERequestContext& ctx) { rb.PushRaw(vibration_device_info); } -void Hid::SendVibrationValue(Kernel::HLERequestContext& ctx) { +void Hid::SendVibrationValue(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::VibrationDeviceHandle vibration_device_handle; @@ -1507,7 +1508,7 @@ void Hid::SendVibrationValue(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::GetActualVibrationValue(Kernel::HLERequestContext& ctx) { +void Hid::GetActualVibrationValue(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::VibrationDeviceHandle vibration_device_handle; @@ -1530,7 +1531,7 @@ void Hid::GetActualVibrationValue(Kernel::HLERequestContext& ctx) { .GetLastVibration(parameters.vibration_device_handle)); } -void Hid::CreateActiveVibrationDeviceList(Kernel::HLERequestContext& ctx) { +void Hid::CreateActiveVibrationDeviceList(HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -1538,7 +1539,7 @@ void Hid::CreateActiveVibrationDeviceList(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IActiveVibrationDeviceList>(system, applet_resource); } -void Hid::PermitVibration(Kernel::HLERequestContext& ctx) { +void Hid::PermitVibration(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto can_vibrate{rp.Pop<bool>()}; @@ -1552,7 +1553,7 @@ void Hid::PermitVibration(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::IsVibrationPermitted(Kernel::HLERequestContext& ctx) { +void Hid::IsVibrationPermitted(HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called"); // nnSDK checks if a float is greater than zero. We return the bool we stored earlier @@ -1563,7 +1564,7 @@ void Hid::IsVibrationPermitted(Kernel::HLERequestContext& ctx) { rb.Push(is_enabled); } -void Hid::SendVibrationValues(Kernel::HLERequestContext& ctx) { +void Hid::SendVibrationValues(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1587,7 +1588,7 @@ void Hid::SendVibrationValues(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::SendVibrationGcErmCommand(Kernel::HLERequestContext& ctx) { +void Hid::SendVibrationGcErmCommand(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::VibrationDeviceHandle vibration_device_handle; @@ -1648,7 +1649,7 @@ void Hid::SendVibrationGcErmCommand(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::GetActualVibrationGcErmCommand(Kernel::HLERequestContext& ctx) { +void Hid::GetActualVibrationGcErmCommand(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::VibrationDeviceHandle vibration_device_handle; @@ -1690,7 +1691,7 @@ void Hid::GetActualVibrationGcErmCommand(Kernel::HLERequestContext& ctx) { rb.PushEnum(gc_erm_command); } -void Hid::BeginPermitVibrationSession(Kernel::HLERequestContext& ctx) { +void Hid::BeginPermitVibrationSession(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1703,7 +1704,7 @@ void Hid::BeginPermitVibrationSession(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::EndPermitVibrationSession(Kernel::HLERequestContext& ctx) { +void Hid::EndPermitVibrationSession(HLERequestContext& ctx) { applet_resource->GetController<Controller_NPad>(HidController::NPad) .SetPermitVibrationSession(false); @@ -1713,7 +1714,7 @@ void Hid::EndPermitVibrationSession(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::IsVibrationDeviceMounted(Kernel::HLERequestContext& ctx) { +void Hid::IsVibrationDeviceMounted(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::VibrationDeviceHandle vibration_device_handle; @@ -1736,7 +1737,7 @@ void Hid::IsVibrationDeviceMounted(Kernel::HLERequestContext& ctx) { .IsVibrationDeviceMounted(parameters.vibration_device_handle)); } -void Hid::ActivateConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { +void Hid::ActivateConsoleSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1748,7 +1749,7 @@ void Hid::ActivateConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::StartConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { +void Hid::StartConsoleSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle; @@ -1768,7 +1769,7 @@ void Hid::StartConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::StopConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { +void Hid::StopConsoleSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle; @@ -1788,7 +1789,7 @@ void Hid::StopConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::ActivateSevenSixAxisSensor(Kernel::HLERequestContext& ctx) { +void Hid::ActivateSevenSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1800,7 +1801,7 @@ void Hid::ActivateSevenSixAxisSensor(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::StartSevenSixAxisSensor(Kernel::HLERequestContext& ctx) { +void Hid::StartSevenSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1811,7 +1812,7 @@ void Hid::StartSevenSixAxisSensor(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::StopSevenSixAxisSensor(Kernel::HLERequestContext& ctx) { +void Hid::StopSevenSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1822,7 +1823,7 @@ void Hid::StopSevenSixAxisSensor(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::InitializeSevenSixAxisSensor(Kernel::HLERequestContext& ctx) { +void Hid::InitializeSevenSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; const auto t_mem_1_size{rp.Pop<u64>()}; @@ -1861,7 +1862,7 @@ void Hid::InitializeSevenSixAxisSensor(Kernel::HLERequestContext& ctx) { .ActivateController(); applet_resource->GetController<Controller_ConsoleSixAxis>(HidController::ConsoleSixAxisSensor) - .SetTransferMemoryPointer(system.Memory().GetPointer(t_mem_1->GetSourceAddress())); + .SetTransferMemoryAddress(t_mem_1->GetSourceAddress()); LOG_WARNING(Service_HID, "called, t_mem_1_handle=0x{:08X}, t_mem_2_handle=0x{:08X}, " @@ -1872,7 +1873,7 @@ void Hid::InitializeSevenSixAxisSensor(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::FinalizeSevenSixAxisSensor(Kernel::HLERequestContext& ctx) { +void Hid::FinalizeSevenSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1883,7 +1884,7 @@ void Hid::FinalizeSevenSixAxisSensor(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::ResetSevenSixAxisSensorTimestamp(Kernel::HLERequestContext& ctx) { +void Hid::ResetSevenSixAxisSensorTimestamp(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -1896,7 +1897,7 @@ void Hid::ResetSevenSixAxisSensorTimestamp(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::IsUsbFullKeyControllerEnabled(Kernel::HLERequestContext& ctx) { +void Hid::IsUsbFullKeyControllerEnabled(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; LOG_WARNING(Service_HID, "(STUBBED) called"); @@ -1906,7 +1907,7 @@ void Hid::IsUsbFullKeyControllerEnabled(Kernel::HLERequestContext& ctx) { rb.Push(false); } -void Hid::GetPalmaConnectionHandle(Kernel::HLERequestContext& ctx) { +void Hid::GetPalmaConnectionHandle(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::NpadIdType npad_id; @@ -1929,7 +1930,7 @@ void Hid::GetPalmaConnectionHandle(Kernel::HLERequestContext& ctx) { rb.PushRaw(handle); } -void Hid::InitializePalma(Kernel::HLERequestContext& ctx) { +void Hid::InitializePalma(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; @@ -1942,7 +1943,7 @@ void Hid::InitializePalma(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::AcquirePalmaOperationCompleteEvent(Kernel::HLERequestContext& ctx) { +void Hid::AcquirePalmaOperationCompleteEvent(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; @@ -1955,7 +1956,7 @@ void Hid::AcquirePalmaOperationCompleteEvent(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(controller.AcquirePalmaOperationCompleteEvent(connection_handle)); } -void Hid::GetPalmaOperationInfo(Kernel::HLERequestContext& ctx) { +void Hid::GetPalmaOperationInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; @@ -1977,7 +1978,7 @@ void Hid::GetPalmaOperationInfo(Kernel::HLERequestContext& ctx) { rb.Push(static_cast<u64>(operation_type)); } -void Hid::PlayPalmaActivity(Kernel::HLERequestContext& ctx) { +void Hid::PlayPalmaActivity(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; const auto palma_activity{rp.Pop<u64>()}; @@ -1992,7 +1993,7 @@ void Hid::PlayPalmaActivity(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::SetPalmaFrModeType(Kernel::HLERequestContext& ctx) { +void Hid::SetPalmaFrModeType(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; const auto fr_mode{rp.PopEnum<Controller_Palma::PalmaFrModeType>()}; @@ -2007,7 +2008,7 @@ void Hid::SetPalmaFrModeType(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::ReadPalmaStep(Kernel::HLERequestContext& ctx) { +void Hid::ReadPalmaStep(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; @@ -2020,7 +2021,7 @@ void Hid::ReadPalmaStep(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::EnablePalmaStep(Kernel::HLERequestContext& ctx) { +void Hid::EnablePalmaStep(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { bool is_enabled; @@ -2042,7 +2043,7 @@ void Hid::EnablePalmaStep(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::ResetPalmaStep(Kernel::HLERequestContext& ctx) { +void Hid::ResetPalmaStep(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; @@ -2055,21 +2056,21 @@ void Hid::ResetPalmaStep(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::ReadPalmaApplicationSection(Kernel::HLERequestContext& ctx) { +void Hid::ReadPalmaApplicationSection(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Hid::WritePalmaApplicationSection(Kernel::HLERequestContext& ctx) { +void Hid::WritePalmaApplicationSection(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Hid::ReadPalmaUniqueCode(Kernel::HLERequestContext& ctx) { +void Hid::ReadPalmaUniqueCode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; @@ -2082,7 +2083,7 @@ void Hid::ReadPalmaUniqueCode(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::SetPalmaUniqueCodeInvalid(Kernel::HLERequestContext& ctx) { +void Hid::SetPalmaUniqueCodeInvalid(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; @@ -2095,14 +2096,14 @@ void Hid::SetPalmaUniqueCodeInvalid(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::WritePalmaActivityEntry(Kernel::HLERequestContext& ctx) { +void Hid::WritePalmaActivityEntry(HLERequestContext& ctx) { LOG_CRITICAL(Service_HID, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Hid::WritePalmaRgbLedPatternEntry(Kernel::HLERequestContext& ctx) { +void Hid::WritePalmaRgbLedPatternEntry(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; const auto unknown{rp.Pop<u64>()}; @@ -2119,7 +2120,7 @@ void Hid::WritePalmaRgbLedPatternEntry(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::WritePalmaWaveEntry(Kernel::HLERequestContext& ctx) { +void Hid::WritePalmaWaveEntry(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; const auto wave_set{rp.PopEnum<Controller_Palma::PalmaWaveSet>()}; @@ -2148,14 +2149,13 @@ void Hid::WritePalmaWaveEntry(Kernel::HLERequestContext& ctx) { connection_handle.npad_id, wave_set, unknown, t_mem_handle, t_mem_size, size); applet_resource->GetController<Controller_Palma>(HidController::Palma) - .WritePalmaWaveEntry(connection_handle, wave_set, - system.Memory().GetPointer(t_mem->GetSourceAddress()), t_mem_size); + .WritePalmaWaveEntry(connection_handle, wave_set, t_mem->GetSourceAddress(), t_mem_size); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Hid::SetPalmaDataBaseIdentificationVersion(Kernel::HLERequestContext& ctx) { +void Hid::SetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { s32 database_id_version; @@ -2177,7 +2177,7 @@ void Hid::SetPalmaDataBaseIdentificationVersion(Kernel::HLERequestContext& ctx) rb.Push(ResultSuccess); } -void Hid::GetPalmaDataBaseIdentificationVersion(Kernel::HLERequestContext& ctx) { +void Hid::GetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; @@ -2190,14 +2190,14 @@ void Hid::GetPalmaDataBaseIdentificationVersion(Kernel::HLERequestContext& ctx) rb.Push(ResultSuccess); } -void Hid::SuspendPalmaFeature(Kernel::HLERequestContext& ctx) { +void Hid::SuspendPalmaFeature(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Hid::GetPalmaOperationResult(Kernel::HLERequestContext& ctx) { +void Hid::GetPalmaOperationResult(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; @@ -2210,21 +2210,21 @@ void Hid::GetPalmaOperationResult(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void Hid::ReadPalmaPlayLog(Kernel::HLERequestContext& ctx) { +void Hid::ReadPalmaPlayLog(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Hid::ResetPalmaPlayLog(Kernel::HLERequestContext& ctx) { +void Hid::ResetPalmaPlayLog(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Hid::SetIsPalmaAllConnectable(Kernel::HLERequestContext& ctx) { +void Hid::SetIsPalmaAllConnectable(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { bool is_palma_all_connectable; @@ -2246,14 +2246,14 @@ void Hid::SetIsPalmaAllConnectable(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::SetIsPalmaPairedConnectable(Kernel::HLERequestContext& ctx) { +void Hid::SetIsPalmaPairedConnectable(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Hid::PairPalma(Kernel::HLERequestContext& ctx) { +void Hid::PairPalma(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto connection_handle{rp.PopRaw<Controller_Palma::PalmaConnectionHandle>()}; @@ -2266,7 +2266,7 @@ void Hid::PairPalma(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::SetPalmaBoostMode(Kernel::HLERequestContext& ctx) { +void Hid::SetPalmaBoostMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto palma_boost_mode{rp.Pop<bool>()}; @@ -2279,35 +2279,35 @@ void Hid::SetPalmaBoostMode(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::CancelWritePalmaWaveEntry(Kernel::HLERequestContext& ctx) { +void Hid::CancelWritePalmaWaveEntry(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Hid::EnablePalmaBoostMode(Kernel::HLERequestContext& ctx) { +void Hid::EnablePalmaBoostMode(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Hid::GetPalmaBluetoothAddress(Kernel::HLERequestContext& ctx) { +void Hid::GetPalmaBluetoothAddress(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Hid::SetDisallowedPalmaConnection(Kernel::HLERequestContext& ctx) { +void Hid::SetDisallowedPalmaConnection(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void Hid::SetNpadCommunicationMode(Kernel::HLERequestContext& ctx) { +void Hid::SetNpadCommunicationMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; const auto communication_mode{rp.PopEnum<Controller_NPad::NpadCommunicationMode>()}; @@ -2322,7 +2322,7 @@ void Hid::SetNpadCommunicationMode(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::GetNpadCommunicationMode(Kernel::HLERequestContext& ctx) { +void Hid::GetNpadCommunicationMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; LOG_WARNING(Service_HID, "(STUBBED) called"); @@ -2333,7 +2333,7 @@ void Hid::GetNpadCommunicationMode(Kernel::HLERequestContext& ctx) { .GetNpadCommunicationMode()); } -void Hid::SetTouchScreenConfiguration(Kernel::HLERequestContext& ctx) { +void Hid::SetTouchScreenConfiguration(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto touchscreen_mode{rp.PopRaw<Controller_Touchscreen::TouchScreenConfigurationForNx>()}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -2345,7 +2345,7 @@ void Hid::SetTouchScreenConfiguration(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Hid::IsFirmwareUpdateNeededForNotification(Kernel::HLERequestContext& ctx) { +void Hid::IsFirmwareUpdateNeededForNotification(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { s32 unknown; @@ -2719,7 +2719,7 @@ public: } private: - void ApplyNpadSystemCommonPolicy(Kernel::HLERequestContext& ctx) { + void ApplyNpadSystemCommonPolicy(HLERequestContext& ctx) { // We already do this for homebrew so we can just stub it out LOG_WARNING(Service_HID, "called"); @@ -2727,7 +2727,7 @@ private: rb.Push(ResultSuccess); } - void GetUniquePadsFromNpad(Kernel::HLERequestContext& ctx) { + void GetUniquePadsFromNpad(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto npad_id_type{rp.PopEnum<Core::HID::NpadIdType>()}; @@ -2740,16 +2740,20 @@ private: } }; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<Hid>(system)->InstallAsService(service_manager); - std::make_shared<HidBus>(system)->InstallAsService(service_manager); - std::make_shared<HidDbg>(system)->InstallAsService(service_manager); - std::make_shared<HidSys>(system)->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); - std::make_shared<Service::IRS::IRS>(system)->InstallAsService(service_manager); - std::make_shared<Service::IRS::IRS_SYS>(system)->InstallAsService(service_manager); + server_manager->RegisterNamedService("hid", std::make_shared<Hid>(system)); + server_manager->RegisterNamedService("hidbus", std::make_shared<HidBus>(system)); + server_manager->RegisterNamedService("hid:dbg", std::make_shared<HidDbg>(system)); + server_manager->RegisterNamedService("hid:sys", std::make_shared<HidSys>(system)); - std::make_shared<XCD_SYS>(system)->InstallAsService(service_manager); + server_manager->RegisterNamedService("irs", std::make_shared<Service::IRS::IRS>(system)); + server_manager->RegisterNamedService("irs:sys", + std::make_shared<Service::IRS::IRS_SYS>(system)); + + server_manager->RegisterNamedService("xcd:sys", std::make_shared<XCD_SYS>(system)); + system.RunServer(std::move(server_manager)); } } // namespace Service::HID diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 8fc9ed88a..c69e5f3fb 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -61,16 +61,22 @@ public: private: template <typename T> void MakeController(HidController controller, u8* shared_memory) { - controllers[static_cast<std::size_t>(controller)] = - std::make_unique<T>(system.HIDCore(), shared_memory); + if constexpr (std::is_constructible_v<T, Core::System&, u8*>) { + controllers[static_cast<std::size_t>(controller)] = + std::make_unique<T>(system, shared_memory); + } else { + controllers[static_cast<std::size_t>(controller)] = + std::make_unique<T>(system.HIDCore(), shared_memory); + } } + template <typename T> void MakeControllerWithServiceContext(HidController controller, u8* shared_memory) { controllers[static_cast<std::size_t>(controller)] = std::make_unique<T>(system.HIDCore(), shared_memory, service_context); } - void GetSharedMemoryHandle(Kernel::HLERequestContext& ctx); + void GetSharedMemoryHandle(HLERequestContext& ctx); void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); void UpdateNpad(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); void UpdateMouseKeyboard(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); @@ -95,122 +101,121 @@ public: std::shared_ptr<IAppletResource> GetAppletResource(); private: - void CreateAppletResource(Kernel::HLERequestContext& ctx); - void ActivateDebugPad(Kernel::HLERequestContext& ctx); - void ActivateTouchScreen(Kernel::HLERequestContext& ctx); - void ActivateMouse(Kernel::HLERequestContext& ctx); - void ActivateKeyboard(Kernel::HLERequestContext& ctx); - void SendKeyboardLockKeyEvent(Kernel::HLERequestContext& ctx); - void ActivateXpad(Kernel::HLERequestContext& ctx); - void GetXpadIDs(Kernel::HLERequestContext& ctx); - void ActivateSixAxisSensor(Kernel::HLERequestContext& ctx); - void DeactivateSixAxisSensor(Kernel::HLERequestContext& ctx); - void StartSixAxisSensor(Kernel::HLERequestContext& ctx); - void StopSixAxisSensor(Kernel::HLERequestContext& ctx); - void IsSixAxisSensorFusionEnabled(Kernel::HLERequestContext& ctx); - void EnableSixAxisSensorFusion(Kernel::HLERequestContext& ctx); - void SetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx); - void GetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx); - void ResetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx); - void SetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx); - void GetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx); - void ResetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx); - void IsSixAxisSensorAtRest(Kernel::HLERequestContext& ctx); - void IsFirmwareUpdateAvailableForSixAxisSensor(Kernel::HLERequestContext& ctx); - void EnableSixAxisSensorUnalteredPassthrough(Kernel::HLERequestContext& ctx); - void IsSixAxisSensorUnalteredPassthroughEnabled(Kernel::HLERequestContext& ctx); - void LoadSixAxisSensorCalibrationParameter(Kernel::HLERequestContext& ctx); - void GetSixAxisSensorIcInformation(Kernel::HLERequestContext& ctx); - void ResetIsSixAxisSensorDeviceNewlyAssigned(Kernel::HLERequestContext& ctx); - void ActivateGesture(Kernel::HLERequestContext& ctx); - void SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx); - void GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx); - void SetSupportedNpadIdType(Kernel::HLERequestContext& ctx); - void ActivateNpad(Kernel::HLERequestContext& ctx); - void DeactivateNpad(Kernel::HLERequestContext& ctx); - void AcquireNpadStyleSetUpdateEventHandle(Kernel::HLERequestContext& ctx); - void DisconnectNpad(Kernel::HLERequestContext& ctx); - void GetPlayerLedPattern(Kernel::HLERequestContext& ctx); - void ActivateNpadWithRevision(Kernel::HLERequestContext& ctx); - void SetNpadJoyHoldType(Kernel::HLERequestContext& ctx); - void GetNpadJoyHoldType(Kernel::HLERequestContext& ctx); - void SetNpadJoyAssignmentModeSingleByDefault(Kernel::HLERequestContext& ctx); - void SetNpadJoyAssignmentModeSingle(Kernel::HLERequestContext& ctx); - void SetNpadJoyAssignmentModeDual(Kernel::HLERequestContext& ctx); - void MergeSingleJoyAsDualJoy(Kernel::HLERequestContext& ctx); - void StartLrAssignmentMode(Kernel::HLERequestContext& ctx); - void StopLrAssignmentMode(Kernel::HLERequestContext& ctx); - void SetNpadHandheldActivationMode(Kernel::HLERequestContext& ctx); - void GetNpadHandheldActivationMode(Kernel::HLERequestContext& ctx); - void SwapNpadAssignment(Kernel::HLERequestContext& ctx); - void IsUnintendedHomeButtonInputProtectionEnabled(Kernel::HLERequestContext& ctx); - void EnableUnintendedHomeButtonInputProtection(Kernel::HLERequestContext& ctx); - void SetNpadAnalogStickUseCenterClamp(Kernel::HLERequestContext& ctx); - void SetNpadCaptureButtonAssignment(Kernel::HLERequestContext& ctx); - void ClearNpadCaptureButtonAssignment(Kernel::HLERequestContext& ctx); - void GetVibrationDeviceInfo(Kernel::HLERequestContext& ctx); - void SendVibrationValue(Kernel::HLERequestContext& ctx); - void GetActualVibrationValue(Kernel::HLERequestContext& ctx); - void CreateActiveVibrationDeviceList(Kernel::HLERequestContext& ctx); - void PermitVibration(Kernel::HLERequestContext& ctx); - void IsVibrationPermitted(Kernel::HLERequestContext& ctx); - void SendVibrationValues(Kernel::HLERequestContext& ctx); - void SendVibrationGcErmCommand(Kernel::HLERequestContext& ctx); - void GetActualVibrationGcErmCommand(Kernel::HLERequestContext& ctx); - void BeginPermitVibrationSession(Kernel::HLERequestContext& ctx); - void EndPermitVibrationSession(Kernel::HLERequestContext& ctx); - void IsVibrationDeviceMounted(Kernel::HLERequestContext& ctx); - void ActivateConsoleSixAxisSensor(Kernel::HLERequestContext& ctx); - void StartConsoleSixAxisSensor(Kernel::HLERequestContext& ctx); - void StopConsoleSixAxisSensor(Kernel::HLERequestContext& ctx); - void ActivateSevenSixAxisSensor(Kernel::HLERequestContext& ctx); - void StartSevenSixAxisSensor(Kernel::HLERequestContext& ctx); - void StopSevenSixAxisSensor(Kernel::HLERequestContext& ctx); - void InitializeSevenSixAxisSensor(Kernel::HLERequestContext& ctx); - void FinalizeSevenSixAxisSensor(Kernel::HLERequestContext& ctx); - void ResetSevenSixAxisSensorTimestamp(Kernel::HLERequestContext& ctx); - void IsUsbFullKeyControllerEnabled(Kernel::HLERequestContext& ctx); - void GetPalmaConnectionHandle(Kernel::HLERequestContext& ctx); - void InitializePalma(Kernel::HLERequestContext& ctx); - void AcquirePalmaOperationCompleteEvent(Kernel::HLERequestContext& ctx); - void GetPalmaOperationInfo(Kernel::HLERequestContext& ctx); - void PlayPalmaActivity(Kernel::HLERequestContext& ctx); - void SetPalmaFrModeType(Kernel::HLERequestContext& ctx); - void ReadPalmaStep(Kernel::HLERequestContext& ctx); - void EnablePalmaStep(Kernel::HLERequestContext& ctx); - void ResetPalmaStep(Kernel::HLERequestContext& ctx); - void ReadPalmaApplicationSection(Kernel::HLERequestContext& ctx); - void WritePalmaApplicationSection(Kernel::HLERequestContext& ctx); - void ReadPalmaUniqueCode(Kernel::HLERequestContext& ctx); - void SetPalmaUniqueCodeInvalid(Kernel::HLERequestContext& ctx); - void WritePalmaActivityEntry(Kernel::HLERequestContext& ctx); - void WritePalmaRgbLedPatternEntry(Kernel::HLERequestContext& ctx); - void WritePalmaWaveEntry(Kernel::HLERequestContext& ctx); - void SetPalmaDataBaseIdentificationVersion(Kernel::HLERequestContext& ctx); - void GetPalmaDataBaseIdentificationVersion(Kernel::HLERequestContext& ctx); - void SuspendPalmaFeature(Kernel::HLERequestContext& ctx); - void GetPalmaOperationResult(Kernel::HLERequestContext& ctx); - void ReadPalmaPlayLog(Kernel::HLERequestContext& ctx); - void ResetPalmaPlayLog(Kernel::HLERequestContext& ctx); - void SetIsPalmaAllConnectable(Kernel::HLERequestContext& ctx); - void SetIsPalmaPairedConnectable(Kernel::HLERequestContext& ctx); - void PairPalma(Kernel::HLERequestContext& ctx); - void SetPalmaBoostMode(Kernel::HLERequestContext& ctx); - void CancelWritePalmaWaveEntry(Kernel::HLERequestContext& ctx); - void EnablePalmaBoostMode(Kernel::HLERequestContext& ctx); - void GetPalmaBluetoothAddress(Kernel::HLERequestContext& ctx); - void SetDisallowedPalmaConnection(Kernel::HLERequestContext& ctx); - void SetNpadCommunicationMode(Kernel::HLERequestContext& ctx); - void GetNpadCommunicationMode(Kernel::HLERequestContext& ctx); - void SetTouchScreenConfiguration(Kernel::HLERequestContext& ctx); - void IsFirmwareUpdateNeededForNotification(Kernel::HLERequestContext& ctx); + void CreateAppletResource(HLERequestContext& ctx); + void ActivateDebugPad(HLERequestContext& ctx); + void ActivateTouchScreen(HLERequestContext& ctx); + void ActivateMouse(HLERequestContext& ctx); + void ActivateKeyboard(HLERequestContext& ctx); + void SendKeyboardLockKeyEvent(HLERequestContext& ctx); + void ActivateXpad(HLERequestContext& ctx); + void GetXpadIDs(HLERequestContext& ctx); + void ActivateSixAxisSensor(HLERequestContext& ctx); + void DeactivateSixAxisSensor(HLERequestContext& ctx); + void StartSixAxisSensor(HLERequestContext& ctx); + void StopSixAxisSensor(HLERequestContext& ctx); + void IsSixAxisSensorFusionEnabled(HLERequestContext& ctx); + void EnableSixAxisSensorFusion(HLERequestContext& ctx); + void SetSixAxisSensorFusionParameters(HLERequestContext& ctx); + void GetSixAxisSensorFusionParameters(HLERequestContext& ctx); + void ResetSixAxisSensorFusionParameters(HLERequestContext& ctx); + void SetGyroscopeZeroDriftMode(HLERequestContext& ctx); + void GetGyroscopeZeroDriftMode(HLERequestContext& ctx); + void ResetGyroscopeZeroDriftMode(HLERequestContext& ctx); + void IsSixAxisSensorAtRest(HLERequestContext& ctx); + void IsFirmwareUpdateAvailableForSixAxisSensor(HLERequestContext& ctx); + void EnableSixAxisSensorUnalteredPassthrough(HLERequestContext& ctx); + void IsSixAxisSensorUnalteredPassthroughEnabled(HLERequestContext& ctx); + void LoadSixAxisSensorCalibrationParameter(HLERequestContext& ctx); + void GetSixAxisSensorIcInformation(HLERequestContext& ctx); + void ResetIsSixAxisSensorDeviceNewlyAssigned(HLERequestContext& ctx); + void ActivateGesture(HLERequestContext& ctx); + void SetSupportedNpadStyleSet(HLERequestContext& ctx); + void GetSupportedNpadStyleSet(HLERequestContext& ctx); + void SetSupportedNpadIdType(HLERequestContext& ctx); + void ActivateNpad(HLERequestContext& ctx); + void DeactivateNpad(HLERequestContext& ctx); + void AcquireNpadStyleSetUpdateEventHandle(HLERequestContext& ctx); + void DisconnectNpad(HLERequestContext& ctx); + void GetPlayerLedPattern(HLERequestContext& ctx); + void ActivateNpadWithRevision(HLERequestContext& ctx); + void SetNpadJoyHoldType(HLERequestContext& ctx); + void GetNpadJoyHoldType(HLERequestContext& ctx); + void SetNpadJoyAssignmentModeSingleByDefault(HLERequestContext& ctx); + void SetNpadJoyAssignmentModeSingle(HLERequestContext& ctx); + void SetNpadJoyAssignmentModeDual(HLERequestContext& ctx); + void MergeSingleJoyAsDualJoy(HLERequestContext& ctx); + void StartLrAssignmentMode(HLERequestContext& ctx); + void StopLrAssignmentMode(HLERequestContext& ctx); + void SetNpadHandheldActivationMode(HLERequestContext& ctx); + void GetNpadHandheldActivationMode(HLERequestContext& ctx); + void SwapNpadAssignment(HLERequestContext& ctx); + void IsUnintendedHomeButtonInputProtectionEnabled(HLERequestContext& ctx); + void EnableUnintendedHomeButtonInputProtection(HLERequestContext& ctx); + void SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx); + void SetNpadCaptureButtonAssignment(HLERequestContext& ctx); + void ClearNpadCaptureButtonAssignment(HLERequestContext& ctx); + void GetVibrationDeviceInfo(HLERequestContext& ctx); + void SendVibrationValue(HLERequestContext& ctx); + void GetActualVibrationValue(HLERequestContext& ctx); + void CreateActiveVibrationDeviceList(HLERequestContext& ctx); + void PermitVibration(HLERequestContext& ctx); + void IsVibrationPermitted(HLERequestContext& ctx); + void SendVibrationValues(HLERequestContext& ctx); + void SendVibrationGcErmCommand(HLERequestContext& ctx); + void GetActualVibrationGcErmCommand(HLERequestContext& ctx); + void BeginPermitVibrationSession(HLERequestContext& ctx); + void EndPermitVibrationSession(HLERequestContext& ctx); + void IsVibrationDeviceMounted(HLERequestContext& ctx); + void ActivateConsoleSixAxisSensor(HLERequestContext& ctx); + void StartConsoleSixAxisSensor(HLERequestContext& ctx); + void StopConsoleSixAxisSensor(HLERequestContext& ctx); + void ActivateSevenSixAxisSensor(HLERequestContext& ctx); + void StartSevenSixAxisSensor(HLERequestContext& ctx); + void StopSevenSixAxisSensor(HLERequestContext& ctx); + void InitializeSevenSixAxisSensor(HLERequestContext& ctx); + void FinalizeSevenSixAxisSensor(HLERequestContext& ctx); + void ResetSevenSixAxisSensorTimestamp(HLERequestContext& ctx); + void IsUsbFullKeyControllerEnabled(HLERequestContext& ctx); + void GetPalmaConnectionHandle(HLERequestContext& ctx); + void InitializePalma(HLERequestContext& ctx); + void AcquirePalmaOperationCompleteEvent(HLERequestContext& ctx); + void GetPalmaOperationInfo(HLERequestContext& ctx); + void PlayPalmaActivity(HLERequestContext& ctx); + void SetPalmaFrModeType(HLERequestContext& ctx); + void ReadPalmaStep(HLERequestContext& ctx); + void EnablePalmaStep(HLERequestContext& ctx); + void ResetPalmaStep(HLERequestContext& ctx); + void ReadPalmaApplicationSection(HLERequestContext& ctx); + void WritePalmaApplicationSection(HLERequestContext& ctx); + void ReadPalmaUniqueCode(HLERequestContext& ctx); + void SetPalmaUniqueCodeInvalid(HLERequestContext& ctx); + void WritePalmaActivityEntry(HLERequestContext& ctx); + void WritePalmaRgbLedPatternEntry(HLERequestContext& ctx); + void WritePalmaWaveEntry(HLERequestContext& ctx); + void SetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx); + void GetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx); + void SuspendPalmaFeature(HLERequestContext& ctx); + void GetPalmaOperationResult(HLERequestContext& ctx); + void ReadPalmaPlayLog(HLERequestContext& ctx); + void ResetPalmaPlayLog(HLERequestContext& ctx); + void SetIsPalmaAllConnectable(HLERequestContext& ctx); + void SetIsPalmaPairedConnectable(HLERequestContext& ctx); + void PairPalma(HLERequestContext& ctx); + void SetPalmaBoostMode(HLERequestContext& ctx); + void CancelWritePalmaWaveEntry(HLERequestContext& ctx); + void EnablePalmaBoostMode(HLERequestContext& ctx); + void GetPalmaBluetoothAddress(HLERequestContext& ctx); + void SetDisallowedPalmaConnection(HLERequestContext& ctx); + void SetNpadCommunicationMode(HLERequestContext& ctx); + void GetNpadCommunicationMode(HLERequestContext& ctx); + void SetTouchScreenConfiguration(HLERequestContext& ctx); + void IsFirmwareUpdateNeededForNotification(HLERequestContext& ctx); std::shared_ptr<IAppletResource> applet_resource; KernelHelpers::ServiceContext service_context; }; -/// Registers all HID services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::HID diff --git a/src/core/hle/service/hid/hidbus.cpp b/src/core/hle/service/hid/hidbus.cpp index 8dbb2cf50..5604a6fda 100644 --- a/src/core/hle/service/hid/hidbus.cpp +++ b/src/core/hle/service/hid/hidbus.cpp @@ -7,7 +7,6 @@ #include "core/core_timing.h" #include "core/core_timing_util.h" #include "core/hid/hid_types.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" #include "core/hle/kernel/k_readable_event.h" #include "core/hle/kernel/k_shared_memory.h" @@ -16,6 +15,7 @@ #include "core/hle/service/hid/hidbus/ringcon.h" #include "core/hle/service/hid/hidbus/starlink.h" #include "core/hle/service/hid/hidbus/stubbed.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/service.h" #include "core/memory.h" @@ -99,7 +99,7 @@ std::optional<std::size_t> HidBus::GetDeviceIndexFromHandle(BusHandle handle) co return std::nullopt; } -void HidBus::GetBusHandle(Kernel::HLERequestContext& ctx) { +void HidBus::GetBusHandle(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::HID::NpadIdType npad_id; @@ -165,7 +165,7 @@ void HidBus::GetBusHandle(Kernel::HLERequestContext& ctx) { rb.PushRaw(out_data); } -void HidBus::IsExternalDeviceConnected(Kernel::HLERequestContext& ctx) { +void HidBus::IsExternalDeviceConnected(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto bus_handle_{rp.PopRaw<BusHandle>()}; @@ -193,7 +193,7 @@ void HidBus::IsExternalDeviceConnected(Kernel::HLERequestContext& ctx) { return; } -void HidBus::Initialize(Kernel::HLERequestContext& ctx) { +void HidBus::Initialize(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto bus_handle_{rp.PopRaw<BusHandle>()}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -245,7 +245,7 @@ void HidBus::Initialize(Kernel::HLERequestContext& ctx) { return; } -void HidBus::Finalize(Kernel::HLERequestContext& ctx) { +void HidBus::Finalize(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto bus_handle_{rp.PopRaw<BusHandle>()}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -284,7 +284,7 @@ void HidBus::Finalize(Kernel::HLERequestContext& ctx) { return; } -void HidBus::EnableExternalDevice(Kernel::HLERequestContext& ctx) { +void HidBus::EnableExternalDevice(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { bool enable; @@ -322,7 +322,7 @@ void HidBus::EnableExternalDevice(Kernel::HLERequestContext& ctx) { return; } -void HidBus::GetExternalDeviceId(Kernel::HLERequestContext& ctx) { +void HidBus::GetExternalDeviceId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto bus_handle_{rp.PopRaw<BusHandle>()}; @@ -349,7 +349,7 @@ void HidBus::GetExternalDeviceId(Kernel::HLERequestContext& ctx) { return; } -void HidBus::SendCommandAsync(Kernel::HLERequestContext& ctx) { +void HidBus::SendCommandAsync(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto data = ctx.ReadBuffer(); const auto bus_handle_{rp.PopRaw<BusHandle>()}; @@ -377,7 +377,7 @@ void HidBus::SendCommandAsync(Kernel::HLERequestContext& ctx) { return; }; -void HidBus::GetSendCommandAsynceResult(Kernel::HLERequestContext& ctx) { +void HidBus::GetSendCommandAsynceResult(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto bus_handle_{rp.PopRaw<BusHandle>()}; @@ -406,7 +406,7 @@ void HidBus::GetSendCommandAsynceResult(Kernel::HLERequestContext& ctx) { return; }; -void HidBus::SetEventForSendCommandAsycResult(Kernel::HLERequestContext& ctx) { +void HidBus::SetEventForSendCommandAsycResult(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto bus_handle_{rp.PopRaw<BusHandle>()}; @@ -432,7 +432,7 @@ void HidBus::SetEventForSendCommandAsycResult(Kernel::HLERequestContext& ctx) { return; }; -void HidBus::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) { +void HidBus::GetSharedMemoryHandle(HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -440,7 +440,7 @@ void HidBus::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(&system.Kernel().GetHidBusSharedMem()); } -void HidBus::EnableJoyPollingReceiveMode(Kernel::HLERequestContext& ctx) { +void HidBus::EnableJoyPollingReceiveMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto t_mem_size{rp.Pop<u32>()}; const auto t_mem_handle{ctx.GetCopyHandle(0)}; @@ -472,7 +472,7 @@ void HidBus::EnableJoyPollingReceiveMode(Kernel::HLERequestContext& ctx) { if (device_index) { auto& device = devices[device_index.value()].device; device->SetPollingMode(polling_mode_); - device->SetTransferMemoryPointer(system.Memory().GetPointer(t_mem->GetSourceAddress())); + device->SetTransferMemoryAddress(t_mem->GetSourceAddress()); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -485,7 +485,7 @@ void HidBus::EnableJoyPollingReceiveMode(Kernel::HLERequestContext& ctx) { return; } -void HidBus::DisableJoyPollingReceiveMode(Kernel::HLERequestContext& ctx) { +void HidBus::DisableJoyPollingReceiveMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto bus_handle_{rp.PopRaw<BusHandle>()}; @@ -512,7 +512,7 @@ void HidBus::DisableJoyPollingReceiveMode(Kernel::HLERequestContext& ctx) { return; } -void HidBus::SetStatusManagerType(Kernel::HLERequestContext& ctx) { +void HidBus::SetStatusManagerType(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto manager_type{rp.PopEnum<StatusManagerType>()}; diff --git a/src/core/hle/service/hid/hidbus.h b/src/core/hle/service/hid/hidbus.h index 91c99b01f..c29b5e882 100644 --- a/src/core/hle/service/hid/hidbus.h +++ b/src/core/hle/service/hid/hidbus.h @@ -94,19 +94,19 @@ private: std::unique_ptr<HidbusBase> device{nullptr}; }; - void GetBusHandle(Kernel::HLERequestContext& ctx); - void IsExternalDeviceConnected(Kernel::HLERequestContext& ctx); - void Initialize(Kernel::HLERequestContext& ctx); - void Finalize(Kernel::HLERequestContext& ctx); - void EnableExternalDevice(Kernel::HLERequestContext& ctx); - void GetExternalDeviceId(Kernel::HLERequestContext& ctx); - void SendCommandAsync(Kernel::HLERequestContext& ctx); - void GetSendCommandAsynceResult(Kernel::HLERequestContext& ctx); - void SetEventForSendCommandAsycResult(Kernel::HLERequestContext& ctx); - void GetSharedMemoryHandle(Kernel::HLERequestContext& ctx); - void EnableJoyPollingReceiveMode(Kernel::HLERequestContext& ctx); - void DisableJoyPollingReceiveMode(Kernel::HLERequestContext& ctx); - void SetStatusManagerType(Kernel::HLERequestContext& ctx); + void GetBusHandle(HLERequestContext& ctx); + void IsExternalDeviceConnected(HLERequestContext& ctx); + void Initialize(HLERequestContext& ctx); + void Finalize(HLERequestContext& ctx); + void EnableExternalDevice(HLERequestContext& ctx); + void GetExternalDeviceId(HLERequestContext& ctx); + void SendCommandAsync(HLERequestContext& ctx); + void GetSendCommandAsynceResult(HLERequestContext& ctx); + void SetEventForSendCommandAsycResult(HLERequestContext& ctx); + void GetSharedMemoryHandle(HLERequestContext& ctx); + void EnableJoyPollingReceiveMode(HLERequestContext& ctx); + void DisableJoyPollingReceiveMode(HLERequestContext& ctx); + void SetStatusManagerType(HLERequestContext& ctx); void UpdateHidbus(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); std::optional<std::size_t> GetDeviceIndexFromHandle(BusHandle handle) const; @@ -115,8 +115,7 @@ private: void MakeDevice(BusHandle handle) { const auto device_index = GetDeviceIndexFromHandle(handle); if (device_index) { - devices[device_index.value()].device = - std::make_unique<T>(system.HIDCore(), service_context); + devices[device_index.value()].device = std::make_unique<T>(system, service_context); } } diff --git a/src/core/hle/service/hid/hidbus/hidbus_base.cpp b/src/core/hle/service/hid/hidbus/hidbus_base.cpp index b569b3c20..dfd23ec04 100644 --- a/src/core/hle/service/hid/hidbus/hidbus_base.cpp +++ b/src/core/hle/service/hid/hidbus/hidbus_base.cpp @@ -9,8 +9,8 @@ namespace Service::HID { -HidbusBase::HidbusBase(KernelHelpers::ServiceContext& service_context_) - : service_context(service_context_) { +HidbusBase::HidbusBase(Core::System& system_, KernelHelpers::ServiceContext& service_context_) + : system(system_), service_context(service_context_) { send_command_async_event = service_context.CreateEvent("hidbus:SendCommandAsyncEvent"); } HidbusBase::~HidbusBase() = default; @@ -59,8 +59,7 @@ void HidbusBase::DisablePollingMode() { polling_mode_enabled = false; } -void HidbusBase::SetTransferMemoryPointer(u8* t_mem) { - is_transfer_memory_set = true; +void HidbusBase::SetTransferMemoryAddress(VAddr t_mem) { transfer_memory = t_mem; } diff --git a/src/core/hle/service/hid/hidbus/hidbus_base.h b/src/core/hle/service/hid/hidbus/hidbus_base.h index 65e301137..26313264d 100644 --- a/src/core/hle/service/hid/hidbus/hidbus_base.h +++ b/src/core/hle/service/hid/hidbus/hidbus_base.h @@ -8,6 +8,10 @@ #include "common/common_types.h" #include "core/hle/result.h" +namespace Core { +class System; +} + namespace Kernel { class KEvent; class KReadableEvent; @@ -106,7 +110,7 @@ static_assert(sizeof(ButtonOnlyPollingDataAccessor) == 0x2F0, class HidbusBase { public: - explicit HidbusBase(KernelHelpers::ServiceContext& service_context_); + explicit HidbusBase(Core::System& system_, KernelHelpers::ServiceContext& service_context_); virtual ~HidbusBase(); void ActivateDevice(); @@ -134,7 +138,7 @@ public: void DisablePollingMode(); // Called on EnableJoyPollingReceiveMode - void SetTransferMemoryPointer(u8* t_mem); + void SetTransferMemoryAddress(VAddr t_mem); Kernel::KReadableEvent& GetSendCommandAsycEvent() const; @@ -170,9 +174,9 @@ protected: JoyEnableSixAxisDataAccessor enable_sixaxis_data{}; ButtonOnlyPollingDataAccessor button_only_data{}; - u8* transfer_memory{nullptr}; - bool is_transfer_memory_set{}; + VAddr transfer_memory{}; + Core::System& system; Kernel::KEvent* send_command_async_event; KernelHelpers::ServiceContext& service_context; }; diff --git a/src/core/hle/service/hid/hidbus/ringcon.cpp b/src/core/hle/service/hid/hidbus/ringcon.cpp index 35847cbdd..65a2dd521 100644 --- a/src/core/hle/service/hid/hidbus/ringcon.cpp +++ b/src/core/hle/service/hid/hidbus/ringcon.cpp @@ -1,18 +1,20 @@ // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "core/core.h" #include "core/hid/emulated_controller.h" #include "core/hid/hid_core.h" #include "core/hle/kernel/k_event.h" #include "core/hle/kernel/k_readable_event.h" #include "core/hle/service/hid/hidbus/ringcon.h" +#include "core/memory.h" namespace Service::HID { -RingController::RingController(Core::HID::HIDCore& hid_core_, +RingController::RingController(Core::System& system_, KernelHelpers::ServiceContext& service_context_) - : HidbusBase(service_context_) { - input = hid_core_.GetEmulatedController(Core::HID::NpadIdType::Player1); + : HidbusBase(system_, service_context_) { + input = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1); } RingController::~RingController() = default; @@ -38,7 +40,7 @@ void RingController::OnUpdate() { return; } - if (!polling_mode_enabled || !is_transfer_memory_set) { + if (!polling_mode_enabled || transfer_memory == 0) { return; } @@ -62,7 +64,8 @@ void RingController::OnUpdate() { curr_entry.polling_data.out_size = sizeof(ringcon_value); std::memcpy(curr_entry.polling_data.data.data(), &ringcon_value, sizeof(ringcon_value)); - std::memcpy(transfer_memory, &enable_sixaxis_data, sizeof(enable_sixaxis_data)); + system.Memory().WriteBlock(transfer_memory, &enable_sixaxis_data, + sizeof(enable_sixaxis_data)); break; } default: diff --git a/src/core/hle/service/hid/hidbus/ringcon.h b/src/core/hle/service/hid/hidbus/ringcon.h index c2fb386b1..f42f3ea41 100644 --- a/src/core/hle/service/hid/hidbus/ringcon.h +++ b/src/core/hle/service/hid/hidbus/ringcon.h @@ -17,8 +17,7 @@ namespace Service::HID { class RingController final : public HidbusBase { public: - explicit RingController(Core::HID::HIDCore& hid_core_, - KernelHelpers::ServiceContext& service_context_); + explicit RingController(Core::System& system_, KernelHelpers::ServiceContext& service_context_); ~RingController() override; void OnInit() override; diff --git a/src/core/hle/service/hid/hidbus/starlink.cpp b/src/core/hle/service/hid/hidbus/starlink.cpp index d0e760314..36573274e 100644 --- a/src/core/hle/service/hid/hidbus/starlink.cpp +++ b/src/core/hle/service/hid/hidbus/starlink.cpp @@ -8,8 +8,8 @@ namespace Service::HID { constexpr u8 DEVICE_ID = 0x28; -Starlink::Starlink(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_) - : HidbusBase(service_context_) {} +Starlink::Starlink(Core::System& system_, KernelHelpers::ServiceContext& service_context_) + : HidbusBase(system_, service_context_) {} Starlink::~Starlink() = default; void Starlink::OnInit() { @@ -27,7 +27,7 @@ void Starlink::OnUpdate() { if (!device_enabled) { return; } - if (!polling_mode_enabled || !is_transfer_memory_set) { + if (!polling_mode_enabled || transfer_memory == 0) { return; } diff --git a/src/core/hle/service/hid/hidbus/starlink.h b/src/core/hle/service/hid/hidbus/starlink.h index 07c800e6e..a276aa88f 100644 --- a/src/core/hle/service/hid/hidbus/starlink.h +++ b/src/core/hle/service/hid/hidbus/starlink.h @@ -14,8 +14,7 @@ namespace Service::HID { class Starlink final : public HidbusBase { public: - explicit Starlink(Core::HID::HIDCore& hid_core_, - KernelHelpers::ServiceContext& service_context_); + explicit Starlink(Core::System& system_, KernelHelpers::ServiceContext& service_context_); ~Starlink() override; void OnInit() override; diff --git a/src/core/hle/service/hid/hidbus/stubbed.cpp b/src/core/hle/service/hid/hidbus/stubbed.cpp index 07632c872..8160b7218 100644 --- a/src/core/hle/service/hid/hidbus/stubbed.cpp +++ b/src/core/hle/service/hid/hidbus/stubbed.cpp @@ -8,9 +8,8 @@ namespace Service::HID { constexpr u8 DEVICE_ID = 0xFF; -HidbusStubbed::HidbusStubbed(Core::HID::HIDCore& hid_core_, - KernelHelpers::ServiceContext& service_context_) - : HidbusBase(service_context_) {} +HidbusStubbed::HidbusStubbed(Core::System& system_, KernelHelpers::ServiceContext& service_context_) + : HidbusBase(system_, service_context_) {} HidbusStubbed::~HidbusStubbed() = default; void HidbusStubbed::OnInit() { @@ -28,7 +27,7 @@ void HidbusStubbed::OnUpdate() { if (!device_enabled) { return; } - if (!polling_mode_enabled || !is_transfer_memory_set) { + if (!polling_mode_enabled || transfer_memory == 0) { return; } diff --git a/src/core/hle/service/hid/hidbus/stubbed.h b/src/core/hle/service/hid/hidbus/stubbed.h index 38eaa0ecc..2e58d42fc 100644 --- a/src/core/hle/service/hid/hidbus/stubbed.h +++ b/src/core/hle/service/hid/hidbus/stubbed.h @@ -14,8 +14,7 @@ namespace Service::HID { class HidbusStubbed final : public HidbusBase { public: - explicit HidbusStubbed(Core::HID::HIDCore& hid_core_, - KernelHelpers::ServiceContext& service_context_); + explicit HidbusStubbed(Core::System& system_, KernelHelpers::ServiceContext& service_context_); ~HidbusStubbed() override; void OnInit() override; diff --git a/src/core/hle/service/hid/irs.cpp b/src/core/hle/service/hid/irs.cpp index 3bd418e92..221c33b86 100644 --- a/src/core/hle/service/hid/irs.cpp +++ b/src/core/hle/service/hid/irs.cpp @@ -8,7 +8,6 @@ #include "core/core_timing.h" #include "core/hid/emulated_controller.h" #include "core/hid/hid_core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_shared_memory.h" #include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/kernel/kernel.h" @@ -20,6 +19,7 @@ #include "core/hle/service/hid/irsensor/moment_processor.h" #include "core/hle/service/hid/irsensor/pointing_processor.h" #include "core/hle/service/hid/irsensor/tera_plugin_processor.h" +#include "core/hle/service/ipc_helpers.h" #include "core/memory.h" namespace Service::IRS { @@ -56,7 +56,7 @@ IRS::IRS(Core::System& system_) : ServiceFramework{system_, "irs"} { } IRS::~IRS() = default; -void IRS::ActivateIrsensor(Kernel::HLERequestContext& ctx) { +void IRS::ActivateIrsensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -67,7 +67,7 @@ void IRS::ActivateIrsensor(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IRS::DeactivateIrsensor(Kernel::HLERequestContext& ctx) { +void IRS::DeactivateIrsensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -78,7 +78,7 @@ void IRS::DeactivateIrsensor(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IRS::GetIrsensorSharedMemoryHandle(Kernel::HLERequestContext& ctx) { +void IRS::GetIrsensorSharedMemoryHandle(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop<u64>()}; @@ -89,7 +89,7 @@ void IRS::GetIrsensorSharedMemoryHandle(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(&system.Kernel().GetIrsSharedMem()); } -void IRS::StopImageProcessor(Kernel::HLERequestContext& ctx) { +void IRS::StopImageProcessor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::IrSensor::IrCameraHandle camera_handle; @@ -117,7 +117,7 @@ void IRS::StopImageProcessor(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IRS::RunMomentProcessor(Kernel::HLERequestContext& ctx) { +void IRS::RunMomentProcessor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::IrSensor::IrCameraHandle camera_handle; @@ -149,7 +149,7 @@ void IRS::RunMomentProcessor(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IRS::RunClusteringProcessor(Kernel::HLERequestContext& ctx) { +void IRS::RunClusteringProcessor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::IrSensor::IrCameraHandle camera_handle; @@ -182,7 +182,7 @@ void IRS::RunClusteringProcessor(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IRS::RunImageTransferProcessor(Kernel::HLERequestContext& ctx) { +void IRS::RunImageTransferProcessor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::IrSensor::IrCameraHandle camera_handle; @@ -208,8 +208,6 @@ void IRS::RunImageTransferProcessor(Kernel::HLERequestContext& ctx) { ASSERT_MSG(t_mem->GetSize() == parameters.transfer_memory_size, "t_mem has incorrect size"); - u8* transfer_memory = system.Memory().GetPointer(t_mem->GetSourceAddress()); - LOG_INFO(Service_IRS, "called, npad_type={}, npad_id={}, transfer_memory_size={}, transfer_memory_size={}, " "applet_resource_user_id={}", @@ -224,7 +222,7 @@ void IRS::RunImageTransferProcessor(Kernel::HLERequestContext& ctx) { auto& image_transfer_processor = GetProcessor<ImageTransferProcessor>(parameters.camera_handle); image_transfer_processor.SetConfig(parameters.processor_config); - image_transfer_processor.SetTransferMemoryPointer(transfer_memory); + image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress()); npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, Common::Input::PollingMode::IR); } @@ -233,7 +231,7 @@ void IRS::RunImageTransferProcessor(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IRS::GetImageTransferProcessorState(Kernel::HLERequestContext& ctx) { +void IRS::GetImageTransferProcessorState(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::IrSensor::IrCameraHandle camera_handle; @@ -274,7 +272,7 @@ void IRS::GetImageTransferProcessorState(Kernel::HLERequestContext& ctx) { rb.PushRaw(state); } -void IRS::RunTeraPluginProcessor(Kernel::HLERequestContext& ctx) { +void IRS::RunTeraPluginProcessor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::IrSensor::IrCameraHandle camera_handle; @@ -310,7 +308,7 @@ void IRS::RunTeraPluginProcessor(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IRS::GetNpadIrCameraHandle(Kernel::HLERequestContext& ctx) { +void IRS::GetNpadIrCameraHandle(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto npad_id{rp.PopEnum<Core::HID::NpadIdType>()}; @@ -334,7 +332,7 @@ void IRS::GetNpadIrCameraHandle(Kernel::HLERequestContext& ctx) { rb.PushRaw(camera_handle); } -void IRS::RunPointingProcessor(Kernel::HLERequestContext& ctx) { +void IRS::RunPointingProcessor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto camera_handle{rp.PopRaw<Core::IrSensor::IrCameraHandle>()}; const auto processor_config{rp.PopRaw<Core::IrSensor::PackedPointingProcessorConfig>()}; @@ -361,7 +359,7 @@ void IRS::RunPointingProcessor(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IRS::SuspendImageProcessor(Kernel::HLERequestContext& ctx) { +void IRS::SuspendImageProcessor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::IrSensor::IrCameraHandle camera_handle; @@ -387,7 +385,7 @@ void IRS::SuspendImageProcessor(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IRS::CheckFirmwareVersion(Kernel::HLERequestContext& ctx) { +void IRS::CheckFirmwareVersion(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto camera_handle{rp.PopRaw<Core::IrSensor::IrCameraHandle>()}; const auto mcu_version{rp.PopRaw<Core::IrSensor::PackedMcuVersion>()}; @@ -409,7 +407,7 @@ void IRS::CheckFirmwareVersion(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IRS::SetFunctionLevel(Kernel::HLERequestContext& ctx) { +void IRS::SetFunctionLevel(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto camera_handle{rp.PopRaw<Core::IrSensor::IrCameraHandle>()}; const auto function_level{rp.PopRaw<Core::IrSensor::PackedFunctionLevel>()}; @@ -431,7 +429,7 @@ void IRS::SetFunctionLevel(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IRS::RunImageTransferExProcessor(Kernel::HLERequestContext& ctx) { +void IRS::RunImageTransferExProcessor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::IrSensor::IrCameraHandle camera_handle; @@ -448,8 +446,6 @@ void IRS::RunImageTransferExProcessor(Kernel::HLERequestContext& ctx) { auto t_mem = system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>( t_mem_handle); - u8* transfer_memory = system.Memory().GetPointer(t_mem->GetSourceAddress()); - LOG_INFO(Service_IRS, "called, npad_type={}, npad_id={}, transfer_memory_size={}, " "applet_resource_user_id={}", @@ -464,7 +460,7 @@ void IRS::RunImageTransferExProcessor(Kernel::HLERequestContext& ctx) { auto& image_transfer_processor = GetProcessor<ImageTransferProcessor>(parameters.camera_handle); image_transfer_processor.SetConfig(parameters.processor_config); - image_transfer_processor.SetTransferMemoryPointer(transfer_memory); + image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress()); npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, Common::Input::PollingMode::IR); } @@ -473,7 +469,7 @@ void IRS::RunImageTransferExProcessor(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IRS::RunIrLedProcessor(Kernel::HLERequestContext& ctx) { +void IRS::RunIrLedProcessor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto camera_handle{rp.PopRaw<Core::IrSensor::IrCameraHandle>()}; const auto processor_config{rp.PopRaw<Core::IrSensor::PackedIrLedProcessorConfig>()}; @@ -501,7 +497,7 @@ void IRS::RunIrLedProcessor(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IRS::StopImageProcessorAsync(Kernel::HLERequestContext& ctx) { +void IRS::StopImageProcessorAsync(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::IrSensor::IrCameraHandle camera_handle; @@ -529,7 +525,7 @@ void IRS::StopImageProcessorAsync(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IRS::ActivateIrsensorWithFunctionLevel(Kernel::HLERequestContext& ctx) { +void IRS::ActivateIrsensorWithFunctionLevel(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { Core::IrSensor::PackedFunctionLevel function_level; diff --git a/src/core/hle/service/hid/irs.h b/src/core/hle/service/hid/irs.h index 2e6115c73..a8fa19025 100644 --- a/src/core/hle/service/hid/irs.h +++ b/src/core/hle/service/hid/irs.h @@ -38,24 +38,24 @@ private: }; static_assert(sizeof(StatusManager) == 0x8000, "StatusManager is an invalid size"); - void ActivateIrsensor(Kernel::HLERequestContext& ctx); - void DeactivateIrsensor(Kernel::HLERequestContext& ctx); - void GetIrsensorSharedMemoryHandle(Kernel::HLERequestContext& ctx); - void StopImageProcessor(Kernel::HLERequestContext& ctx); - void RunMomentProcessor(Kernel::HLERequestContext& ctx); - void RunClusteringProcessor(Kernel::HLERequestContext& ctx); - void RunImageTransferProcessor(Kernel::HLERequestContext& ctx); - void GetImageTransferProcessorState(Kernel::HLERequestContext& ctx); - void RunTeraPluginProcessor(Kernel::HLERequestContext& ctx); - void GetNpadIrCameraHandle(Kernel::HLERequestContext& ctx); - void RunPointingProcessor(Kernel::HLERequestContext& ctx); - void SuspendImageProcessor(Kernel::HLERequestContext& ctx); - void CheckFirmwareVersion(Kernel::HLERequestContext& ctx); - void SetFunctionLevel(Kernel::HLERequestContext& ctx); - void RunImageTransferExProcessor(Kernel::HLERequestContext& ctx); - void RunIrLedProcessor(Kernel::HLERequestContext& ctx); - void StopImageProcessorAsync(Kernel::HLERequestContext& ctx); - void ActivateIrsensorWithFunctionLevel(Kernel::HLERequestContext& ctx); + void ActivateIrsensor(HLERequestContext& ctx); + void DeactivateIrsensor(HLERequestContext& ctx); + void GetIrsensorSharedMemoryHandle(HLERequestContext& ctx); + void StopImageProcessor(HLERequestContext& ctx); + void RunMomentProcessor(HLERequestContext& ctx); + void RunClusteringProcessor(HLERequestContext& ctx); + void RunImageTransferProcessor(HLERequestContext& ctx); + void GetImageTransferProcessorState(HLERequestContext& ctx); + void RunTeraPluginProcessor(HLERequestContext& ctx); + void GetNpadIrCameraHandle(HLERequestContext& ctx); + void RunPointingProcessor(HLERequestContext& ctx); + void SuspendImageProcessor(HLERequestContext& ctx); + void CheckFirmwareVersion(HLERequestContext& ctx); + void SetFunctionLevel(HLERequestContext& ctx); + void RunImageTransferExProcessor(HLERequestContext& ctx); + void RunIrLedProcessor(HLERequestContext& ctx); + void StopImageProcessorAsync(HLERequestContext& ctx); + void ActivateIrsensorWithFunctionLevel(HLERequestContext& ctx); Result IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const; Core::IrSensor::DeviceFormat& GetIrCameraSharedMemoryDeviceEntry( @@ -80,7 +80,13 @@ private: LOG_CRITICAL(Service_IRS, "Invalid index {}", index); return; } - processors[index] = std::make_unique<T>(system.HIDCore(), device_state, index); + + if constexpr (std::is_constructible_v<T, Core::System&, Core::IrSensor::DeviceFormat&, + std::size_t>) { + processors[index] = std::make_unique<T>(system, device_state, index); + } else { + processors[index] = std::make_unique<T>(system.HIDCore(), device_state, index); + } } template <typename T> diff --git a/src/core/hle/service/hid/irsensor/image_transfer_processor.cpp b/src/core/hle/service/hid/irsensor/image_transfer_processor.cpp index 98f0c579d..bc896a1e3 100644 --- a/src/core/hle/service/hid/irsensor/image_transfer_processor.cpp +++ b/src/core/hle/service/hid/irsensor/image_transfer_processor.cpp @@ -1,16 +1,18 @@ // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later +#include "core/core.h" #include "core/hid/emulated_controller.h" #include "core/hid/hid_core.h" #include "core/hle/service/hid/irsensor/image_transfer_processor.h" +#include "core/memory.h" namespace Service::IRS { -ImageTransferProcessor::ImageTransferProcessor(Core::HID::HIDCore& hid_core_, +ImageTransferProcessor::ImageTransferProcessor(Core::System& system_, Core::IrSensor::DeviceFormat& device_format, std::size_t npad_index) - : device{device_format} { - npad_device = hid_core_.GetEmulatedControllerByIndex(npad_index); + : device{device_format}, system{system_} { + npad_device = system.HIDCore().GetEmulatedControllerByIndex(npad_index); Core::HID::ControllerUpdateCallback engine_callback{ .on_change = [this](Core::HID::ControllerTriggerType type) { OnControllerUpdate(type); }, @@ -43,7 +45,7 @@ void ImageTransferProcessor::OnControllerUpdate(Core::HID::ControllerTriggerType if (type != Core::HID::ControllerTriggerType::IrSensor) { return; } - if (!is_transfer_memory_set) { + if (transfer_memory == 0) { return; } @@ -56,14 +58,16 @@ void ImageTransferProcessor::OnControllerUpdate(Core::HID::ControllerTriggerType if (camera_data.format != current_config.origin_format) { LOG_WARNING(Service_IRS, "Wrong Input format {} expected {}", camera_data.format, current_config.origin_format); - memset(transfer_memory, 0, GetDataSize(current_config.trimming_format)); + system.Memory().ZeroBlock(*system.ApplicationProcess(), transfer_memory, + GetDataSize(current_config.trimming_format)); return; } if (current_config.origin_format > current_config.trimming_format) { LOG_WARNING(Service_IRS, "Origin format {} is smaller than trimming format {}", current_config.origin_format, current_config.trimming_format); - memset(transfer_memory, 0, GetDataSize(current_config.trimming_format)); + system.Memory().ZeroBlock(*system.ApplicationProcess(), transfer_memory, + GetDataSize(current_config.trimming_format)); return; } @@ -80,7 +84,8 @@ void ImageTransferProcessor::OnControllerUpdate(Core::HID::ControllerTriggerType "Trimming area ({}, {}, {}, {}) is outside of origin area ({}, {})", current_config.trimming_start_x, current_config.trimming_start_y, trimming_width, trimming_height, origin_width, origin_height); - memset(transfer_memory, 0, GetDataSize(current_config.trimming_format)); + system.Memory().ZeroBlock(*system.ApplicationProcess(), transfer_memory, + GetDataSize(current_config.trimming_format)); return; } @@ -94,7 +99,8 @@ void ImageTransferProcessor::OnControllerUpdate(Core::HID::ControllerTriggerType } } - memcpy(transfer_memory, window_data.data(), GetDataSize(current_config.trimming_format)); + system.Memory().WriteBlock(transfer_memory, window_data.data(), + GetDataSize(current_config.trimming_format)); if (!IsProcessorActive()) { StartProcessor(); @@ -134,8 +140,7 @@ void ImageTransferProcessor::SetConfig( npad_device->SetCameraFormat(current_config.origin_format); } -void ImageTransferProcessor::SetTransferMemoryPointer(u8* t_mem) { - is_transfer_memory_set = true; +void ImageTransferProcessor::SetTransferMemoryAddress(VAddr t_mem) { transfer_memory = t_mem; } @@ -143,7 +148,7 @@ Core::IrSensor::ImageTransferProcessorState ImageTransferProcessor::GetState( std::vector<u8>& data) const { const auto size = GetDataSize(current_config.trimming_format); data.resize(size); - memcpy(data.data(), transfer_memory, size); + system.Memory().ReadBlock(transfer_memory, data.data(), size); return processor_state; } diff --git a/src/core/hle/service/hid/irsensor/image_transfer_processor.h b/src/core/hle/service/hid/irsensor/image_transfer_processor.h index 393df492d..7cfe04c8c 100644 --- a/src/core/hle/service/hid/irsensor/image_transfer_processor.h +++ b/src/core/hle/service/hid/irsensor/image_transfer_processor.h @@ -7,6 +7,10 @@ #include "core/hid/irs_types.h" #include "core/hle/service/hid/irsensor/processor_base.h" +namespace Core { +class System; +} + namespace Core::HID { class EmulatedController; } // namespace Core::HID @@ -14,7 +18,7 @@ class EmulatedController; namespace Service::IRS { class ImageTransferProcessor final : public ProcessorBase { public: - explicit ImageTransferProcessor(Core::HID::HIDCore& hid_core_, + explicit ImageTransferProcessor(Core::System& system_, Core::IrSensor::DeviceFormat& device_format, std::size_t npad_index); ~ImageTransferProcessor() override; @@ -33,7 +37,7 @@ public: void SetConfig(Core::IrSensor::PackedImageTransferProcessorExConfig config); // Transfer memory where the image data will be stored - void SetTransferMemoryPointer(u8* t_mem); + void SetTransferMemoryAddress(VAddr t_mem); Core::IrSensor::ImageTransferProcessorState GetState(std::vector<u8>& data) const; @@ -67,7 +71,7 @@ private: Core::HID::EmulatedController* npad_device; int callback_key{}; - u8* transfer_memory = nullptr; - bool is_transfer_memory_set = false; + Core::System& system; + VAddr transfer_memory{}; }; } // namespace Service::IRS diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/service/hle_ipc.cpp index 494151eef..c221ffe11 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/service/hle_ipc.cpp @@ -12,8 +12,6 @@ #include "common/common_types.h" #include "common/logging/log.h" #include "common/scratch_buffer.h" -#include "core/hle/ipc_helpers.h" -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_auto_object.h" #include "core/hle/kernel/k_handle_table.h" #include "core/hle/kernel/k_process.h" @@ -21,36 +19,20 @@ #include "core/hle/kernel/k_server_session.h" #include "core/hle/kernel/k_thread.h" #include "core/hle/kernel/kernel.h" -#include "core/hle/kernel/service_thread.h" +#include "core/hle/service/hle_ipc.h" +#include "core/hle/service/ipc_helpers.h" #include "core/memory.h" -namespace Kernel { +namespace Service { -SessionRequestHandler::SessionRequestHandler(KernelCore& kernel_, const char* service_name_, - ServiceThreadType thread_type) - : kernel{kernel_}, service_thread{thread_type == ServiceThreadType::CreateNew - ? kernel.CreateServiceThread(service_name_) - : kernel.GetDefaultServiceThread()} {} +SessionRequestHandler::SessionRequestHandler(Kernel::KernelCore& kernel_, const char* service_name_) + : kernel{kernel_} {} -SessionRequestHandler::~SessionRequestHandler() { - kernel.ReleaseServiceThread(service_thread); -} - -void SessionRequestHandler::AcceptSession(KServerPort* server_port) { - auto* server_session = server_port->AcceptSession(); - ASSERT(server_session != nullptr); - - RegisterSession(server_session, std::make_shared<SessionRequestManager>(kernel)); -} - -void SessionRequestHandler::RegisterSession(KServerSession* server_session, - std::shared_ptr<SessionRequestManager> manager) { - manager->SetSessionHandler(shared_from_this()); - service_thread.RegisterServerSession(server_session, manager); - server_session->Close(); -} +SessionRequestHandler::~SessionRequestHandler() = default; -SessionRequestManager::SessionRequestManager(KernelCore& kernel_) : kernel{kernel_} {} +SessionRequestManager::SessionRequestManager(Kernel::KernelCore& kernel_, + ServerManager& server_manager_) + : kernel{kernel_}, server_manager{server_manager_} {} SessionRequestManager::~SessionRequestManager() = default; @@ -69,7 +51,7 @@ bool SessionRequestManager::HasSessionRequestHandler(const HLERequestContext& co } } -Result SessionRequestManager::CompleteSyncRequest(KServerSession* server_session, +Result SessionRequestManager::CompleteSyncRequest(Kernel::KServerSession* server_session, HLERequestContext& context) { Result result = ResultSuccess; @@ -97,7 +79,7 @@ Result SessionRequestManager::CompleteSyncRequest(KServerSession* server_session return result; } -Result SessionRequestManager::HandleDomainSyncRequest(KServerSession* server_session, +Result SessionRequestManager::HandleDomainSyncRequest(Kernel::KServerSession* server_session, HLERequestContext& context) { if (!context.HasDomainMessageHeader()) { return ResultSuccess; @@ -142,16 +124,17 @@ Result SessionRequestManager::HandleDomainSyncRequest(KServerSession* server_ses return ResultSuccess; } -HLERequestContext::HLERequestContext(KernelCore& kernel_, Core::Memory::Memory& memory_, - KServerSession* server_session_, KThread* thread_) +HLERequestContext::HLERequestContext(Kernel::KernelCore& kernel_, Core::Memory::Memory& memory_, + Kernel::KServerSession* server_session_, + Kernel::KThread* thread_) : server_session(server_session_), thread(thread_), kernel{kernel_}, memory{memory_} { cmd_buf[0] = 0; } HLERequestContext::~HLERequestContext() = default; -void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32_le* src_cmdbuf, - bool incoming) { +void HLERequestContext::ParseCommandBuffer(const Kernel::KHandleTable& handle_table, + u32_le* src_cmdbuf, bool incoming) { IPC::RequestParser rp(src_cmdbuf); command_header = rp.PopRaw<IPC::CommandHeader>(); @@ -271,8 +254,8 @@ void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32 rp.Skip(1, false); // The command is actually an u64, but we don't use the high part. } -Result HLERequestContext::PopulateFromIncomingCommandBuffer(const KHandleTable& handle_table, - u32_le* src_cmdbuf) { +Result HLERequestContext::PopulateFromIncomingCommandBuffer( + const Kernel::KHandleTable& handle_table, u32_le* src_cmdbuf) { ParseCommandBuffer(handle_table, src_cmdbuf, true); if (command_header->IsCloseCommand()) { @@ -285,7 +268,7 @@ Result HLERequestContext::PopulateFromIncomingCommandBuffer(const KHandleTable& return ResultSuccess; } -Result HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_thread) { +Result HLERequestContext::WriteToOutgoingCommandBuffer(Kernel::KThread& requesting_thread) { auto current_offset = handles_offset; auto& owner_process = *requesting_thread.GetOwnerProcess(); auto& handle_table = owner_process.GetHandleTable(); @@ -546,4 +529,4 @@ std::string HLERequestContext::Description() const { return s.str(); } -} // namespace Kernel +} // namespace Service diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/service/hle_ipc.h index 5bf4f171b..4bd24c899 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/service/hle_ipc.h @@ -31,31 +31,22 @@ class ResponseBuilder; namespace Service { class ServiceFrameworkBase; -} - -enum class ServiceThreadType { - Default, - CreateNew, -}; +class ServerManager; +} // namespace Service namespace Kernel { - -class Domain; -class HLERequestContext; class KAutoObject; class KernelCore; -class KEvent; class KHandleTable; -class KServerPort; -class KProcess; class KServerSession; class KThread; -class KReadableEvent; -class KSession; -class SessionRequestManager; -class ServiceThread; +} // namespace Kernel -enum class ThreadWakeupReason; +namespace Service { + +using Handle = Kernel::Handle; + +class HLERequestContext; /** * Interface implemented by HLE Session handlers. @@ -64,8 +55,7 @@ enum class ThreadWakeupReason; */ class SessionRequestHandler : public std::enable_shared_from_this<SessionRequestHandler> { public: - SessionRequestHandler(KernelCore& kernel_, const char* service_name_, - ServiceThreadType thread_type); + SessionRequestHandler(Kernel::KernelCore& kernel_, const char* service_name_); virtual ~SessionRequestHandler(); /** @@ -77,19 +67,10 @@ public: * @returns Result the result code of the translate operation. */ virtual Result HandleSyncRequest(Kernel::KServerSession& session, - Kernel::HLERequestContext& context) = 0; - - void AcceptSession(KServerPort* server_port); - void RegisterSession(KServerSession* server_session, - std::shared_ptr<SessionRequestManager> manager); - - ServiceThread& GetServiceThread() const { - return service_thread; - } + HLERequestContext& context) = 0; protected: - KernelCore& kernel; - ServiceThread& service_thread; + Kernel::KernelCore& kernel; }; using SessionRequestHandlerWeakPtr = std::weak_ptr<SessionRequestHandler>; @@ -102,7 +83,8 @@ using SessionRequestHandlerPtr = std::shared_ptr<SessionRequestHandler>; */ class SessionRequestManager final { public: - explicit SessionRequestManager(KernelCore& kernel); + explicit SessionRequestManager(Kernel::KernelCore& kernel, + Service::ServerManager& server_manager); ~SessionRequestManager(); bool IsDomain() const { @@ -155,48 +137,47 @@ public: session_handler = std::move(handler); } - ServiceThread& GetServiceThread() const { - return session_handler->GetServiceThread(); + bool HasSessionRequestHandler(const HLERequestContext& context) const; + + Result HandleDomainSyncRequest(Kernel::KServerSession* server_session, + HLERequestContext& context); + Result CompleteSyncRequest(Kernel::KServerSession* server_session, HLERequestContext& context); + + Service::ServerManager& GetServerManager() { + return server_manager; } - bool HasSessionRequestHandler(const HLERequestContext& context) const; + // TODO: remove this when sm: is implemented with the proper IUserInterface + // abstraction, creating a new C++ handler object for each session: + + bool GetIsInitializedForSm() const { + return is_initialized_for_sm; + } - Result HandleDomainSyncRequest(KServerSession* server_session, HLERequestContext& context); - Result CompleteSyncRequest(KServerSession* server_session, HLERequestContext& context); + void SetIsInitializedForSm() { + is_initialized_for_sm = true; + } private: bool convert_to_domain{}; bool is_domain{}; + bool is_initialized_for_sm{}; SessionRequestHandlerPtr session_handler; std::vector<SessionRequestHandlerPtr> domain_handlers; private: - KernelCore& kernel; + Kernel::KernelCore& kernel; + Service::ServerManager& server_manager; }; /** * Class containing information about an in-flight IPC request being handled by an HLE service - * implementation. Services should avoid using old global APIs (e.g. Kernel::GetCommandBuffer()) and - * when possible use the APIs in this class to service the request. - * - * HLE handle protocol - * =================== - * - * To avoid needing HLE services to keep a separate handle table, or having to directly modify the - * requester's table, a tweaked protocol is used to receive and send handles in requests. The kernel - * will decode the incoming handles into object pointers and insert a id in the buffer where the - * handle would normally be. The service then calls GetIncomingHandle() with that id to get the - * pointer to the object. Similarly, instead of inserting a handle into the command buffer, the - * service calls AddOutgoingHandle() and stores the returned id where the handle would normally go. - * - * The end result is similar to just giving services their own real handle tables, but since these - * ids are local to a specific context, it avoids requiring services to manage handles for objects - * across multiple calls and ensuring that unneeded handles are cleaned up. + * implementation. */ class HLERequestContext { public: - explicit HLERequestContext(KernelCore& kernel, Core::Memory::Memory& memory, - KServerSession* session, KThread* thread); + explicit HLERequestContext(Kernel::KernelCore& kernel, Core::Memory::Memory& memory, + Kernel::KServerSession* session, Kernel::KThread* thread); ~HLERequestContext(); /// Returns a pointer to the IPC command buffer for this request. @@ -213,10 +194,11 @@ public: } /// Populates this context with data from the requesting process/thread. - Result PopulateFromIncomingCommandBuffer(const KHandleTable& handle_table, u32_le* src_cmdbuf); + Result PopulateFromIncomingCommandBuffer(const Kernel::KHandleTable& handle_table, + u32_le* src_cmdbuf); /// Writes data from this context back to the requesting process/thread. - Result WriteToOutgoingCommandBuffer(KThread& requesting_thread); + Result WriteToOutgoingCommandBuffer(Kernel::KThread& requesting_thread); [[nodiscard]] u32_le GetHipcCommand() const { return command; @@ -343,11 +325,11 @@ public: return incoming_move_handles.at(index); } - void AddMoveObject(KAutoObject* object) { + void AddMoveObject(Kernel::KAutoObject* object) { outgoing_move_objects.emplace_back(object); } - void AddCopyObject(KAutoObject* object) { + void AddCopyObject(Kernel::KAutoObject* object) { outgoing_copy_objects.emplace_back(object); } @@ -366,7 +348,7 @@ public: [[nodiscard]] std::string Description() const; - [[nodiscard]] KThread& GetThread() { + [[nodiscard]] Kernel::KThread& GetThread() { return *thread; } @@ -374,20 +356,29 @@ public: return manager.lock(); } + bool GetIsDeferred() const { + return is_deferred; + } + + void SetIsDeferred(bool is_deferred_ = true) { + is_deferred = is_deferred_; + } + private: friend class IPC::ResponseBuilder; - void ParseCommandBuffer(const KHandleTable& handle_table, u32_le* src_cmdbuf, bool incoming); + void ParseCommandBuffer(const Kernel::KHandleTable& handle_table, u32_le* src_cmdbuf, + bool incoming); std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf; Kernel::KServerSession* server_session{}; - KThread* thread; + Kernel::KThread* thread; std::vector<Handle> incoming_move_handles; std::vector<Handle> incoming_copy_handles; - std::vector<KAutoObject*> outgoing_move_objects; - std::vector<KAutoObject*> outgoing_copy_objects; + std::vector<Kernel::KAutoObject*> outgoing_move_objects; + std::vector<Kernel::KAutoObject*> outgoing_copy_objects; std::vector<SessionRequestHandlerPtr> outgoing_domain_objects; std::optional<IPC::CommandHeader> command_header; @@ -408,9 +399,10 @@ private: u32 domain_offset{}; std::weak_ptr<SessionRequestManager> manager{}; + bool is_deferred{false}; - KernelCore& kernel; + Kernel::KernelCore& kernel; Core::Memory::Memory& memory; }; -} // namespace Kernel +} // namespace Service diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/service/ipc_helpers.h index 38d6cfaff..8703b57ca 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/service/ipc_helpers.h @@ -10,26 +10,27 @@ #include "common/assert.h" #include "common/common_types.h" #include "core/hle/ipc.h" -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_process.h" #include "core/hle/kernel/k_resource_limit.h" #include "core/hle/kernel/k_session.h" #include "core/hle/result.h" +#include "core/hle/service/hle_ipc.h" +#include "core/hle/service/server_manager.h" namespace IPC { -constexpr Result ERR_REMOTE_PROCESS_DEAD{ErrorModule::HIPC, 301}; +constexpr Result ResultSessionClosed{ErrorModule::HIPC, 301}; class RequestHelperBase { protected: - Kernel::HLERequestContext* context = nullptr; + Service::HLERequestContext* context = nullptr; u32* cmdbuf; u32 index = 0; public: explicit RequestHelperBase(u32* command_buffer) : cmdbuf(command_buffer) {} - explicit RequestHelperBase(Kernel::HLERequestContext& ctx) + explicit RequestHelperBase(Service::HLERequestContext& ctx) : context(&ctx), cmdbuf(ctx.CommandBuffer()) {} void Skip(u32 size_in_words, bool set_to_null) { @@ -67,7 +68,7 @@ public: AlwaysMoveHandles = 1, }; - explicit ResponseBuilder(Kernel::HLERequestContext& ctx, u32 normal_params_size_, + explicit ResponseBuilder(Service::HLERequestContext& ctx, u32 normal_params_size_, u32 num_handles_to_copy_ = 0, u32 num_objects_to_move_ = 0, Flags flags = Flags::None) : RequestHelperBase(ctx), normal_params_size(normal_params_size_), @@ -145,7 +146,9 @@ public: template <class T> void PushIpcInterface(std::shared_ptr<T> iface) { - if (context->GetManager()->IsDomain()) { + auto manager{context->GetManager()}; + + if (manager->IsDomain()) { context->AddDomainObject(std::move(iface)); } else { kernel.ApplicationProcess()->GetResourceLimit()->Reserve( @@ -153,8 +156,11 @@ public: auto* session = Kernel::KSession::Create(kernel); session->Initialize(nullptr, iface->GetServiceName()); - iface->RegisterSession(&session->GetServerSession(), - std::make_shared<Kernel::SessionRequestManager>(kernel)); + + auto next_manager = std::make_shared<Service::SessionRequestManager>( + kernel, manager->GetServerManager()); + next_manager->SetSessionHandler(iface); + manager->GetServerManager().RegisterSession(&session->GetServerSession(), next_manager); context->AddMoveObject(&session->GetClientSession()); } @@ -341,7 +347,7 @@ class RequestParser : public RequestHelperBase { public: explicit RequestParser(u32* command_buffer) : RequestHelperBase(command_buffer) {} - explicit RequestParser(Kernel::HLERequestContext& ctx) : RequestHelperBase(ctx) { + explicit RequestParser(Service::HLERequestContext& ctx) : RequestHelperBase(ctx) { // TIPC does not have data payload offset if (!ctx.IsTipc()) { ASSERT_MSG(ctx.GetDataPayloadOffset(), "context is incomplete"); diff --git a/src/core/hle/service/jit/jit.cpp b/src/core/hle/service/jit/jit.cpp index 47a1277ea..46bcfd695 100644 --- a/src/core/hle/service/jit/jit.cpp +++ b/src/core/hle/service/jit/jit.cpp @@ -3,12 +3,13 @@ #include "core/arm/symbols.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_code_memory.h" #include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/result.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/jit/jit.h" #include "core/hle/service/jit/jit_context.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" #include "core/memory.h" @@ -23,8 +24,8 @@ class IJitEnvironment final : public ServiceFramework<IJitEnvironment> { public: explicit IJitEnvironment(Core::System& system_, Kernel::KProcess& process_, CodeRange user_rx, CodeRange user_ro) - : ServiceFramework{system_, "IJitEnvironment", ServiceThreadType::CreateNew}, - process{&process_}, context{system_.Memory()} { + : ServiceFramework{system_, "IJitEnvironment"}, process{&process_}, context{ + system_.Memory()} { // clang-format off static const FunctionInfo functions[] = { {0, &IJitEnvironment::GenerateCode, "GenerateCode"}, @@ -43,7 +44,7 @@ public: configuration.sys_rx_memory = user_rx; } - void GenerateCode(Kernel::HLERequestContext& ctx) { + void GenerateCode(HLERequestContext& ctx) { LOG_DEBUG(Service_JIT, "called"); struct InputParameters { @@ -125,7 +126,7 @@ public: } }; - void Control(Kernel::HLERequestContext& ctx) { + void Control(HLERequestContext& ctx) { LOG_DEBUG(Service_JIT, "called"); IPC::RequestParser rp{ctx}; @@ -170,7 +171,7 @@ public: } } - void LoadPlugin(Kernel::HLERequestContext& ctx) { + void LoadPlugin(HLERequestContext& ctx) { LOG_DEBUG(Service_JIT, "called"); IPC::RequestParser rp{ctx}; @@ -276,7 +277,7 @@ public: rb.Push(ResultSuccess); } - void GetCodeAddress(Kernel::HLERequestContext& ctx) { + void GetCodeAddress(HLERequestContext& ctx) { LOG_DEBUG(Service_JIT, "called"); IPC::ResponseBuilder rb{ctx, 6}; @@ -332,7 +333,7 @@ public: RegisterHandlers(functions); } - void CreateJitEnvironment(Kernel::HLERequestContext& ctx) { + void CreateJitEnvironment(HLERequestContext& ctx) { LOG_DEBUG(Service_JIT, "called"); struct Parameters { @@ -397,8 +398,11 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<JITU>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("jit:u", std::make_shared<JITU>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::JIT diff --git a/src/core/hle/service/jit/jit.h b/src/core/hle/service/jit/jit.h index af0f5b4f3..19014c75a 100644 --- a/src/core/hle/service/jit/jit.h +++ b/src/core/hle/service/jit/jit.h @@ -7,13 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::JIT { -/// Registers all JIT services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::JIT diff --git a/src/core/hle/service/kernel_helpers.cpp b/src/core/hle/service/kernel_helpers.cpp index 42991928e..a39ce5212 100644 --- a/src/core/hle/service/kernel_helpers.cpp +++ b/src/core/hle/service/kernel_helpers.cpp @@ -15,17 +15,24 @@ namespace Service::KernelHelpers { ServiceContext::ServiceContext(Core::System& system_, std::string name_) : kernel(system_.Kernel()) { + if (process = Kernel::GetCurrentProcessPointer(kernel); process != nullptr) { + return; + } + // Create the process. process = Kernel::KProcess::Create(kernel); ASSERT(Kernel::KProcess::Initialize(process, system_, std::move(name_), Kernel::KProcess::ProcessType::KernelInternal, kernel.GetSystemResourceLimit()) .IsSuccess()); + process_created = true; } ServiceContext::~ServiceContext() { - process->Close(); - process = nullptr; + if (process_created) { + process->Close(); + process = nullptr; + } } Kernel::KEvent* ServiceContext::CreateEvent(std::string&& name) { diff --git a/src/core/hle/service/kernel_helpers.h b/src/core/hle/service/kernel_helpers.h index 6415838e5..eca9aefb5 100644 --- a/src/core/hle/service/kernel_helpers.h +++ b/src/core/hle/service/kernel_helpers.h @@ -29,6 +29,7 @@ public: private: Kernel::KernelCore& kernel; Kernel::KProcess* process{}; + bool process_created{false}; }; } // namespace Service::KernelHelpers diff --git a/src/core/hle/service/lbl/lbl.cpp b/src/core/hle/service/lbl/lbl.cpp index c8415e0bf..98a79365d 100644 --- a/src/core/hle/service/lbl/lbl.cpp +++ b/src/core/hle/service/lbl/lbl.cpp @@ -5,8 +5,9 @@ #include <memory> #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/lbl/lbl.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" #include "core/hle/service/sm/sm.h" @@ -59,7 +60,7 @@ private: On = 1, }; - void SetCurrentBrightnessSetting(Kernel::HLERequestContext& ctx) { + void SetCurrentBrightnessSetting(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; auto brightness = rp.Pop<float>(); @@ -77,7 +78,7 @@ private: rb.Push(ResultSuccess); } - void GetCurrentBrightnessSetting(Kernel::HLERequestContext& ctx) { + void GetCurrentBrightnessSetting(HLERequestContext& ctx) { auto brightness = current_brightness; if (!std::isfinite(brightness)) { LOG_ERROR(Service_LBL, "Brightness is infinite!"); @@ -91,7 +92,7 @@ private: rb.Push(brightness); } - void SwitchBacklightOn(Kernel::HLERequestContext& ctx) { + void SwitchBacklightOn(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto fade_time = rp.Pop<u64_le>(); LOG_WARNING(Service_LBL, "(STUBBED) called, fade_time={}", fade_time); @@ -102,7 +103,7 @@ private: rb.Push(ResultSuccess); } - void SwitchBacklightOff(Kernel::HLERequestContext& ctx) { + void SwitchBacklightOff(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto fade_time = rp.Pop<u64_le>(); LOG_WARNING(Service_LBL, "(STUBBED) called, fade_time={}", fade_time); @@ -113,7 +114,7 @@ private: rb.Push(ResultSuccess); } - void GetBacklightSwitchStatus(Kernel::HLERequestContext& ctx) { + void GetBacklightSwitchStatus(HLERequestContext& ctx) { LOG_DEBUG(Service_LBL, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -122,7 +123,7 @@ private: : BacklightSwitchStatus::Off); } - void EnableDimming(Kernel::HLERequestContext& ctx) { + void EnableDimming(HLERequestContext& ctx) { LOG_DEBUG(Service_LBL, "called"); dimming = true; @@ -131,7 +132,7 @@ private: rb.Push(ResultSuccess); } - void DisableDimming(Kernel::HLERequestContext& ctx) { + void DisableDimming(HLERequestContext& ctx) { LOG_DEBUG(Service_LBL, "called"); dimming = false; @@ -140,7 +141,7 @@ private: rb.Push(ResultSuccess); } - void IsDimmingEnabled(Kernel::HLERequestContext& ctx) { + void IsDimmingEnabled(HLERequestContext& ctx) { LOG_DEBUG(Service_LBL, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -148,7 +149,7 @@ private: rb.Push(dimming); } - void EnableAutoBrightnessControl(Kernel::HLERequestContext& ctx) { + void EnableAutoBrightnessControl(HLERequestContext& ctx) { LOG_DEBUG(Service_LBL, "called"); auto_brightness = true; update_instantly = true; @@ -157,7 +158,7 @@ private: rb.Push(ResultSuccess); } - void DisableAutoBrightnessControl(Kernel::HLERequestContext& ctx) { + void DisableAutoBrightnessControl(HLERequestContext& ctx) { LOG_DEBUG(Service_LBL, "called"); auto_brightness = false; @@ -165,7 +166,7 @@ private: rb.Push(ResultSuccess); } - void IsAutoBrightnessControlEnabled(Kernel::HLERequestContext& ctx) { + void IsAutoBrightnessControlEnabled(HLERequestContext& ctx) { LOG_DEBUG(Service_LBL, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -173,7 +174,7 @@ private: rb.Push(auto_brightness); } - void SetAmbientLightSensorValue(Kernel::HLERequestContext& ctx) { + void SetAmbientLightSensorValue(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto light_value = rp.Pop<float>(); @@ -185,7 +186,7 @@ private: rb.Push(ResultSuccess); } - void GetAmbientLightSensorValue(Kernel::HLERequestContext& ctx) { + void GetAmbientLightSensorValue(HLERequestContext& ctx) { LOG_DEBUG(Service_LBL, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -193,7 +194,7 @@ private: rb.Push(ambient_light_value); } - void SetBrightnessReflectionDelayLevel(Kernel::HLERequestContext& ctx) { + void SetBrightnessReflectionDelayLevel(HLERequestContext& ctx) { // This is Intentional, this function does absolutely nothing LOG_DEBUG(Service_LBL, "called"); @@ -201,7 +202,7 @@ private: rb.Push(ResultSuccess); } - void GetBrightnessReflectionDelayLevel(Kernel::HLERequestContext& ctx) { + void GetBrightnessReflectionDelayLevel(HLERequestContext& ctx) { // This is intentional, the function is hard coded to return 0.0f on hardware LOG_DEBUG(Service_LBL, "called"); @@ -210,7 +211,7 @@ private: rb.Push(0.0f); } - void SetCurrentBrightnessMapping(Kernel::HLERequestContext& ctx) { + void SetCurrentBrightnessMapping(HLERequestContext& ctx) { // This is Intentional, this function does absolutely nothing LOG_DEBUG(Service_LBL, "called"); @@ -218,7 +219,7 @@ private: rb.Push(ResultSuccess); } - void GetCurrentBrightnessMapping(Kernel::HLERequestContext& ctx) { + void GetCurrentBrightnessMapping(HLERequestContext& ctx) { // This is Intentional, this function does absolutely nothing LOG_DEBUG(Service_LBL, "called"); @@ -227,7 +228,7 @@ private: // This function is suppose to return something but it seems like it doesn't } - void SetCurrentAmbientLightSensorMapping(Kernel::HLERequestContext& ctx) { + void SetCurrentAmbientLightSensorMapping(HLERequestContext& ctx) { // This is Intentional, this function does absolutely nothing LOG_DEBUG(Service_LBL, "called"); @@ -235,7 +236,7 @@ private: rb.Push(ResultSuccess); } - void GetCurrentAmbientLightSensorMapping(Kernel::HLERequestContext& ctx) { + void GetCurrentAmbientLightSensorMapping(HLERequestContext& ctx) { // This is Intentional, this function does absolutely nothing LOG_DEBUG(Service_LBL, "called"); @@ -244,7 +245,7 @@ private: // This function is suppose to return something but it seems like it doesn't } - void IsAmbientLightSensorAvailable(Kernel::HLERequestContext& ctx) { + void IsAmbientLightSensorAvailable(HLERequestContext& ctx) { LOG_WARNING(Service_LBL, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); @@ -252,7 +253,7 @@ private: rb.Push(true); } - void SetCurrentBrightnessSettingForVrMode(Kernel::HLERequestContext& ctx) { + void SetCurrentBrightnessSettingForVrMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; auto brightness = rp.Pop<float>(); @@ -269,7 +270,7 @@ private: rb.Push(ResultSuccess); } - void GetCurrentBrightnessSettingForVrMode(Kernel::HLERequestContext& ctx) { + void GetCurrentBrightnessSettingForVrMode(HLERequestContext& ctx) { auto brightness = current_vr_brightness; if (!std::isfinite(brightness)) { LOG_ERROR(Service_LBL, "Brightness is infinite!"); @@ -283,7 +284,7 @@ private: rb.Push(brightness); } - void EnableVrMode(Kernel::HLERequestContext& ctx) { + void EnableVrMode(HLERequestContext& ctx) { LOG_DEBUG(Service_LBL, "called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -292,7 +293,7 @@ private: vr_mode_enabled = true; } - void DisableVrMode(Kernel::HLERequestContext& ctx) { + void DisableVrMode(HLERequestContext& ctx) { LOG_DEBUG(Service_LBL, "called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -301,7 +302,7 @@ private: vr_mode_enabled = false; } - void IsVrModeEnabled(Kernel::HLERequestContext& ctx) { + void IsVrModeEnabled(HLERequestContext& ctx) { LOG_DEBUG(Service_LBL, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -319,8 +320,11 @@ private: bool auto_brightness = false; // TODO(ogniK): Move to system settings }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<LBL>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("lbl", std::make_shared<LBL>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::LBL diff --git a/src/core/hle/service/lbl/lbl.h b/src/core/hle/service/lbl/lbl.h index 6484105c2..e47759c01 100644 --- a/src/core/hle/service/lbl/lbl.h +++ b/src/core/hle/service/lbl/lbl.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::LBL { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::LBL diff --git a/src/core/hle/service/ldn/ldn.cpp b/src/core/hle/service/ldn/ldn.cpp index e5099d61f..9d149a7cd 100644 --- a/src/core/hle/service/ldn/ldn.cpp +++ b/src/core/hle/service/ldn/ldn.cpp @@ -8,6 +8,7 @@ #include "core/hle/service/ldn/ldn.h" #include "core/hle/service/ldn/ldn_results.h" #include "core/hle/service/ldn/ldn_types.h" +#include "core/hle/service/server_manager.h" #include "core/internal_network/network.h" #include "core/internal_network/network_interface.h" #include "network/network.h" @@ -49,7 +50,7 @@ public: RegisterHandlers(functions); } - void CreateMonitorService(Kernel::HLERequestContext& ctx) { + void CreateMonitorService(HLERequestContext& ctx) { LOG_DEBUG(Service_LDN, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -106,7 +107,7 @@ class IUserLocalCommunicationService final : public ServiceFramework<IUserLocalCommunicationService> { public: explicit IUserLocalCommunicationService(Core::System& system_) - : ServiceFramework{system_, "IUserLocalCommunicationService", ServiceThreadType::CreateNew}, + : ServiceFramework{system_, "IUserLocalCommunicationService"}, service_context{system, "IUserLocalCommunicationService"}, room_network{system_.GetRoomNetwork()}, lan_discovery{room_network} { // clang-format off @@ -168,7 +169,7 @@ public: state_change_event->Signal(); } - void GetState(Kernel::HLERequestContext& ctx) { + void GetState(HLERequestContext& ctx) { State state = State::Error; if (is_initialized) { @@ -180,7 +181,7 @@ public: rb.PushEnum(state); } - void GetNetworkInfo(Kernel::HLERequestContext& ctx) { + void GetNetworkInfo(HLERequestContext& ctx) { const auto write_buffer_size = ctx.GetWriteBufferSize(); if (write_buffer_size != sizeof(NetworkInfo)) { @@ -204,7 +205,7 @@ public: rb.Push(ResultSuccess); } - void GetIpv4Address(Kernel::HLERequestContext& ctx) { + void GetIpv4Address(HLERequestContext& ctx) { const auto network_interface = Network::GetSelectedNetworkInterface(); if (!network_interface) { @@ -233,13 +234,13 @@ public: rb.PushRaw(subnet_mask); } - void GetDisconnectReason(Kernel::HLERequestContext& ctx) { + void GetDisconnectReason(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); rb.PushEnum(lan_discovery.GetDisconnectReason()); } - void GetSecurityParameter(Kernel::HLERequestContext& ctx) { + void GetSecurityParameter(HLERequestContext& ctx) { SecurityParameter security_parameter{}; NetworkInfo info{}; const Result rc = lan_discovery.GetNetworkInfo(info); @@ -260,7 +261,7 @@ public: rb.PushRaw<SecurityParameter>(security_parameter); } - void GetNetworkConfig(Kernel::HLERequestContext& ctx) { + void GetNetworkConfig(HLERequestContext& ctx) { NetworkConfig config{}; NetworkInfo info{}; const Result rc = lan_discovery.GetNetworkInfo(info); @@ -282,7 +283,7 @@ public: rb.PushRaw<NetworkConfig>(config); } - void AttachStateChangeEvent(Kernel::HLERequestContext& ctx) { + void AttachStateChangeEvent(HLERequestContext& ctx) { LOG_INFO(Service_LDN, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -290,7 +291,7 @@ public: rb.PushCopyObjects(state_change_event->GetReadableEvent()); } - void GetNetworkInfoLatestUpdate(Kernel::HLERequestContext& ctx) { + void GetNetworkInfoLatestUpdate(HLERequestContext& ctx) { const std::size_t network_buffer_size = ctx.GetWriteBufferSize(0); const std::size_t node_buffer_count = ctx.GetWriteBufferNumElements<NodeLatestUpdate>(1); @@ -320,15 +321,15 @@ public: rb.Push(ResultSuccess); } - void Scan(Kernel::HLERequestContext& ctx) { + void Scan(HLERequestContext& ctx) { ScanImpl(ctx); } - void ScanPrivate(Kernel::HLERequestContext& ctx) { + void ScanPrivate(HLERequestContext& ctx) { ScanImpl(ctx, true); } - void ScanImpl(Kernel::HLERequestContext& ctx, bool is_private = false) { + void ScanImpl(HLERequestContext& ctx, bool is_private = false) { IPC::RequestParser rp{ctx}; const auto channel{rp.PopEnum<WifiChannel>()}; const auto scan_filter{rp.PopRaw<ScanFilter>()}; @@ -357,40 +358,40 @@ public: rb.Push<u32>(count); } - void SetWirelessControllerRestriction(Kernel::HLERequestContext& ctx) { + void SetWirelessControllerRestriction(HLERequestContext& ctx) { LOG_WARNING(Service_LDN, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void OpenAccessPoint(Kernel::HLERequestContext& ctx) { + void OpenAccessPoint(HLERequestContext& ctx) { LOG_INFO(Service_LDN, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(lan_discovery.OpenAccessPoint()); } - void CloseAccessPoint(Kernel::HLERequestContext& ctx) { + void CloseAccessPoint(HLERequestContext& ctx) { LOG_INFO(Service_LDN, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(lan_discovery.CloseAccessPoint()); } - void CreateNetwork(Kernel::HLERequestContext& ctx) { + void CreateNetwork(HLERequestContext& ctx) { LOG_INFO(Service_LDN, "called"); CreateNetworkImpl(ctx); } - void CreateNetworkPrivate(Kernel::HLERequestContext& ctx) { + void CreateNetworkPrivate(HLERequestContext& ctx) { LOG_INFO(Service_LDN, "called"); CreateNetworkImpl(ctx, true); } - void CreateNetworkImpl(Kernel::HLERequestContext& ctx, bool is_private = false) { + void CreateNetworkImpl(HLERequestContext& ctx, bool is_private = false) { IPC::RequestParser rp{ctx}; const auto security_config{rp.PopRaw<SecurityConfig>()}; @@ -404,49 +405,49 @@ public: rb.Push(lan_discovery.CreateNetwork(security_config, user_config, network_Config)); } - void DestroyNetwork(Kernel::HLERequestContext& ctx) { + void DestroyNetwork(HLERequestContext& ctx) { LOG_INFO(Service_LDN, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(lan_discovery.DestroyNetwork()); } - void SetAdvertiseData(Kernel::HLERequestContext& ctx) { + void SetAdvertiseData(HLERequestContext& ctx) { const auto read_buffer = ctx.ReadBuffer(); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(lan_discovery.SetAdvertiseData(read_buffer)); } - void SetStationAcceptPolicy(Kernel::HLERequestContext& ctx) { + void SetStationAcceptPolicy(HLERequestContext& ctx) { LOG_WARNING(Service_LDN, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void AddAcceptFilterEntry(Kernel::HLERequestContext& ctx) { + void AddAcceptFilterEntry(HLERequestContext& ctx) { LOG_WARNING(Service_LDN, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void OpenStation(Kernel::HLERequestContext& ctx) { + void OpenStation(HLERequestContext& ctx) { LOG_INFO(Service_LDN, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(lan_discovery.OpenStation()); } - void CloseStation(Kernel::HLERequestContext& ctx) { + void CloseStation(HLERequestContext& ctx) { LOG_INFO(Service_LDN, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(lan_discovery.CloseStation()); } - void Connect(Kernel::HLERequestContext& ctx) { + void Connect(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { SecurityConfig security_config; @@ -480,14 +481,14 @@ public: static_cast<u16>(parameters.local_communication_version))); } - void Disconnect(Kernel::HLERequestContext& ctx) { + void Disconnect(HLERequestContext& ctx) { LOG_INFO(Service_LDN, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(lan_discovery.Disconnect()); } - void Initialize(Kernel::HLERequestContext& ctx) { + void Initialize(HLERequestContext& ctx) { const auto rc = InitializeImpl(ctx); if (rc.IsError()) { LOG_ERROR(Service_LDN, "Network isn't initialized, rc={}", rc.raw); @@ -497,7 +498,7 @@ public: rb.Push(rc); } - void Finalize(Kernel::HLERequestContext& ctx) { + void Finalize(HLERequestContext& ctx) { if (auto room_member = room_network.GetRoomMember().lock()) { room_member->Unbind(ldn_packet_received); } @@ -508,7 +509,7 @@ public: rb.Push(lan_discovery.Finalize()); } - void Initialize2(Kernel::HLERequestContext& ctx) { + void Initialize2(HLERequestContext& ctx) { const auto rc = InitializeImpl(ctx); if (rc.IsError()) { LOG_ERROR(Service_LDN, "Network isn't initialized, rc={}", rc.raw); @@ -518,7 +519,7 @@ public: rb.Push(rc); } - Result InitializeImpl(Kernel::HLERequestContext& ctx) { + Result InitializeImpl(HLERequestContext& ctx) { const auto network_interface = Network::GetSelectedNetworkInterface(); if (!network_interface) { LOG_ERROR(Service_LDN, "No network interface is set"); @@ -561,7 +562,7 @@ public: RegisterHandlers(functions); } - void CreateSystemLocalCommunicationService(Kernel::HLERequestContext& ctx) { + void CreateSystemLocalCommunicationService(HLERequestContext& ctx) { LOG_DEBUG(Service_LDN, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -582,7 +583,7 @@ public: RegisterHandlers(functions); } - void CreateUserLocalCommunicationService(Kernel::HLERequestContext& ctx) { + void CreateUserLocalCommunicationService(HLERequestContext& ctx) { LOG_DEBUG(Service_LDN, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -646,7 +647,7 @@ public: RegisterHandlers(functions); } - void Initialize(Kernel::HLERequestContext& ctx) { + void Initialize(HLERequestContext& ctx) { LOG_WARNING(Service_LDN, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -667,7 +668,7 @@ public: RegisterHandlers(functions); } - void CreateNetworkervice(Kernel::HLERequestContext& ctx) { + void CreateNetworkervice(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 reserved_input = rp.Pop<u64>(); const u32 input = rp.Pop<u32>(); @@ -680,7 +681,7 @@ public: rb.PushIpcInterface<INetworkService>(system); } - void CreateMonitorService(Kernel::HLERequestContext& ctx) { + void CreateMonitorService(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 reserved_input = rp.Pop<u64>(); @@ -705,7 +706,7 @@ public: RegisterHandlers(functions); } - void CreateNetworkervice(Kernel::HLERequestContext& ctx) { + void CreateNetworkervice(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 reserved_input = rp.Pop<u64>(); const u32 input = rp.Pop<u32>(); @@ -718,7 +719,7 @@ public: rb.PushIpcInterface<INetworkService>(system); } - void CreateMonitorService(Kernel::HLERequestContext& ctx) { + void CreateMonitorService(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 reserved_input = rp.Pop<u64>(); @@ -730,12 +731,15 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<LDNM>(system)->InstallAsService(sm); - std::make_shared<LDNS>(system)->InstallAsService(sm); - std::make_shared<LDNU>(system)->InstallAsService(sm); - std::make_shared<LP2PAPP>(system)->InstallAsService(sm); - std::make_shared<LP2PSYS>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("ldn:m", std::make_shared<LDNM>(system)); + server_manager->RegisterNamedService("ldn:s", std::make_shared<LDNS>(system)); + server_manager->RegisterNamedService("ldn:u", std::make_shared<LDNU>(system)); + server_manager->RegisterNamedService("lp2p:app", std::make_shared<LP2PAPP>(system)); + server_manager->RegisterNamedService("lp2p:sys", std::make_shared<LP2PSYS>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::LDN diff --git a/src/core/hle/service/ldn/ldn.h b/src/core/hle/service/ldn/ldn.h index 6afe2ea6f..f4a319168 100644 --- a/src/core/hle/service/ldn/ldn.h +++ b/src/core/hle/service/ldn/ldn.h @@ -3,9 +3,9 @@ #pragma once -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" #include "core/hle/result.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/kernel_helpers.h" #include "core/hle/service/sm/sm.h" @@ -13,13 +13,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::LDN { -/// Registers all LDN services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::LDN diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp index 2d4d6fe3e..6de96ed5b 100644 --- a/src/core/hle/service/ldr/ldr.cpp +++ b/src/core/hle/service/ldr/ldr.cpp @@ -9,11 +9,12 @@ #include "common/hex_util.h" #include "common/scope_exit.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_page_table.h" #include "core/hle/kernel/svc_results.h" #include "core/hle/kernel/svc_types.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ldr/ldr.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" #include "core/loader/nro.h" #include "core/memory.h" @@ -159,8 +160,7 @@ public: class RelocatableObject final : public ServiceFramework<RelocatableObject> { public: - explicit RelocatableObject(Core::System& system_) - : ServiceFramework{system_, "ldr:ro", ServiceThreadType::CreateNew} { + explicit RelocatableObject(Core::System& system_) : ServiceFramework{system_, "ldr:ro"} { // clang-format off static const FunctionInfo functions[] = { {0, &RelocatableObject::LoadModule, "LoadModule"}, @@ -175,7 +175,7 @@ public: RegisterHandlers(functions); } - void RegisterModuleInfo(Kernel::HLERequestContext& ctx) { + void RegisterModuleInfo(HLERequestContext& ctx) { struct Parameters { u64_le process_id; u64_le nrr_address; @@ -272,7 +272,7 @@ public: rb.Push(ResultSuccess); } - void UnregisterModuleInfo(Kernel::HLERequestContext& ctx) { + void UnregisterModuleInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto pid = rp.Pop<u64>(); const auto nrr_address = rp.Pop<VAddr>(); @@ -446,7 +446,7 @@ public: data_start, bss_end_addr - data_start, Kernel::Svc::MemoryPermission::ReadWrite); } - void LoadModule(Kernel::HLERequestContext& ctx) { + void LoadModule(HLERequestContext& ctx) { struct Parameters { u64_le process_id; u64_le image_address; @@ -592,7 +592,7 @@ public: return ResultSuccess; } - void UnloadModule(Kernel::HLERequestContext& ctx) { + void UnloadModule(HLERequestContext& ctx) { if (!initialized) { LOG_ERROR(Service_LDR, "LDR:RO not initialized before use!"); IPC::ResponseBuilder rb{ctx, 2}; @@ -638,7 +638,7 @@ public: rb.Push(result); } - void Initialize(Kernel::HLERequestContext& ctx) { + void Initialize(HLERequestContext& ctx) { LOG_WARNING(Service_LDR, "(STUBBED) called"); initialized = true; @@ -682,11 +682,15 @@ private: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<DebugMonitor>(system)->InstallAsService(sm); - std::make_shared<ProcessManager>(system)->InstallAsService(sm); - std::make_shared<Shell>(system)->InstallAsService(sm); - std::make_shared<RelocatableObject>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("ldr:dmnt", std::make_shared<DebugMonitor>(system)); + server_manager->RegisterNamedService("ldr:pm", std::make_shared<ProcessManager>(system)); + server_manager->RegisterNamedService("ldr:shel", std::make_shared<Shell>(system)); + server_manager->RegisterNamedService("ldr:ro", std::make_shared<RelocatableObject>(system)); + + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::LDR diff --git a/src/core/hle/service/ldr/ldr.h b/src/core/hle/service/ldr/ldr.h index 25ffd8442..c9281dbfb 100644 --- a/src/core/hle/service/ldr/ldr.h +++ b/src/core/hle/service/ldr/ldr.h @@ -7,13 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::LDR { -/// Registers all LDR services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::LDR diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp index ef4b54046..20df00233 100644 --- a/src/core/hle/service/lm/lm.cpp +++ b/src/core/hle/service/lm/lm.cpp @@ -8,8 +8,9 @@ #include <boost/container_hash/hash.hpp> #include "common/logging/log.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/lm/lm.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" namespace Service::LM { @@ -92,7 +93,7 @@ public: } private: - void Log(Kernel::HLERequestContext& ctx) { + void Log(HLERequestContext& ctx) { std::size_t offset{}; const auto data = ctx.ReadBuffer(); @@ -147,7 +148,7 @@ private: } } - void SetDestination(Kernel::HLERequestContext& ctx) { + void SetDestination(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto log_destination = rp.PopEnum<LogDestination>(); @@ -342,7 +343,7 @@ public: } private: - void OpenLogger(Kernel::HLERequestContext& ctx) { + void OpenLogger(HLERequestContext& ctx) { LOG_DEBUG(Service_LM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -351,8 +352,11 @@ private: } }; -void InstallInterfaces(Core::System& system) { - std::make_shared<LM>(system)->InstallAsService(system.ServiceManager()); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("lm", std::make_shared<LM>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::LM diff --git a/src/core/hle/service/lm/lm.h b/src/core/hle/service/lm/lm.h index 266019c30..0d7c39cbc 100644 --- a/src/core/hle/service/lm/lm.h +++ b/src/core/hle/service/lm/lm.h @@ -9,7 +9,6 @@ class System; namespace Service::LM { -/// Registers all LM services with the specified service manager. -void InstallInterfaces(Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::LM diff --git a/src/core/hle/service/mig/mig.cpp b/src/core/hle/service/mig/mig.cpp index b9fe0cecd..082e470ab 100644 --- a/src/core/hle/service/mig/mig.cpp +++ b/src/core/hle/service/mig/mig.cpp @@ -4,8 +4,8 @@ #include <memory> #include "core/hle/service/mig/mig.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" namespace Service::Migration { @@ -32,8 +32,11 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<MIG_USR>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("mig:user", std::make_shared<MIG_USR>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::Migration diff --git a/src/core/hle/service/mig/mig.h b/src/core/hle/service/mig/mig.h index f1641a521..c8ed732a5 100644 --- a/src/core/hle/service/mig/mig.h +++ b/src/core/hle/service/mig/mig.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::Migration { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::Migration diff --git a/src/core/hle/service/mii/mii.cpp b/src/core/hle/service/mii/mii.cpp index 390514fdc..5c7adf97d 100644 --- a/src/core/hle/service/mii/mii.cpp +++ b/src/core/hle/service/mii/mii.cpp @@ -4,11 +4,11 @@ #include <memory> #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/mii/mii.h" #include "core/hle/service/mii/mii_manager.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" namespace Service::Mii { @@ -65,7 +65,7 @@ private: return out; } - void IsUpdated(Kernel::HLERequestContext& ctx) { + void IsUpdated(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto source_flag{rp.PopRaw<SourceFlag>()}; @@ -76,7 +76,7 @@ private: rb.Push(manager.CheckAndResetUpdateCounter(source_flag, current_update_counter)); } - void IsFullDatabase(Kernel::HLERequestContext& ctx) { + void IsFullDatabase(HLERequestContext& ctx) { LOG_DEBUG(Service_Mii, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -84,7 +84,7 @@ private: rb.Push(manager.IsFullDatabase()); } - void GetCount(Kernel::HLERequestContext& ctx) { + void GetCount(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto source_flag{rp.PopRaw<SourceFlag>()}; @@ -95,7 +95,7 @@ private: rb.Push<u32>(manager.GetCount(source_flag)); } - void Get(Kernel::HLERequestContext& ctx) { + void Get(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto source_flag{rp.PopRaw<SourceFlag>()}; @@ -117,7 +117,7 @@ private: rb.Push<u32>(static_cast<u32>(result->size())); } - void Get1(Kernel::HLERequestContext& ctx) { + void Get1(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto source_flag{rp.PopRaw<SourceFlag>()}; @@ -142,7 +142,7 @@ private: rb.Push<u32>(static_cast<u32>(result->size())); } - void UpdateLatest(Kernel::HLERequestContext& ctx) { + void UpdateLatest(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto info{rp.PopRaw<CharInfo>()}; const auto source_flag{rp.PopRaw<SourceFlag>()}; @@ -161,7 +161,7 @@ private: rb.PushRaw<CharInfo>(*result); } - void BuildRandom(Kernel::HLERequestContext& ctx) { + void BuildRandom(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto age{rp.PopRaw<Age>()}; @@ -196,7 +196,7 @@ private: rb.PushRaw<CharInfo>(manager.BuildRandom(age, gender, race)); } - void BuildDefault(Kernel::HLERequestContext& ctx) { + void BuildDefault(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto index{rp.Pop<u32>()}; @@ -215,7 +215,7 @@ private: rb.PushRaw<CharInfo>(manager.BuildDefault(index)); } - void GetIndex(Kernel::HLERequestContext& ctx) { + void GetIndex(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto info{rp.PopRaw<CharInfo>()}; @@ -227,7 +227,7 @@ private: rb.Push(index); } - void SetInterfaceVersion(Kernel::HLERequestContext& ctx) { + void SetInterfaceVersion(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; current_interface_version = rp.PopRaw<u32>(); @@ -239,7 +239,7 @@ private: rb.Push(ResultSuccess); } - void Convert(Kernel::HLERequestContext& ctx) { + void Convert(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto mii_v3{rp.PopRaw<Ver3StoreData>()}; @@ -275,7 +275,7 @@ public: } private: - void GetDatabaseService(Kernel::HLERequestContext& ctx) { + void GetDatabaseService(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface<IDatabaseService>(system); @@ -310,11 +310,13 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<MiiDBModule>(system, "mii:e")->InstallAsService(sm); - std::make_shared<MiiDBModule>(system, "mii:u")->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); - std::make_shared<MiiImg>(system)->InstallAsService(sm); + server_manager->RegisterNamedService("mii:e", std::make_shared<MiiDBModule>(system, "mii:e")); + server_manager->RegisterNamedService("mii:u", std::make_shared<MiiDBModule>(system, "mii:u")); + server_manager->RegisterNamedService("miiimg", std::make_shared<MiiImg>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::Mii diff --git a/src/core/hle/service/mii/mii.h b/src/core/hle/service/mii/mii.h index 009d80d58..ed4e3f62b 100644 --- a/src/core/hle/service/mii/mii.h +++ b/src/core/hle/service/mii/mii.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::Mii { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::Mii diff --git a/src/core/hle/service/mm/mm_u.cpp b/src/core/hle/service/mm/mm_u.cpp index ba8c0e230..6f43b1968 100644 --- a/src/core/hle/service/mm/mm_u.cpp +++ b/src/core/hle/service/mm/mm_u.cpp @@ -2,8 +2,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/mm/mm_u.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/sm/sm.h" namespace Service::MM { @@ -28,21 +29,21 @@ public: } private: - void InitializeOld(Kernel::HLERequestContext& ctx) { + void InitializeOld(HLERequestContext& ctx) { LOG_WARNING(Service_MM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void FinalizeOld(Kernel::HLERequestContext& ctx) { + void FinalizeOld(HLERequestContext& ctx) { LOG_WARNING(Service_MM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void SetAndWaitOld(Kernel::HLERequestContext& ctx) { + void SetAndWaitOld(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; min = rp.Pop<u32>(); max = rp.Pop<u32>(); @@ -53,7 +54,7 @@ private: rb.Push(ResultSuccess); } - void GetOld(Kernel::HLERequestContext& ctx) { + void GetOld(HLERequestContext& ctx) { LOG_DEBUG(Service_MM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -61,7 +62,7 @@ private: rb.Push(current); } - void Initialize(Kernel::HLERequestContext& ctx) { + void Initialize(HLERequestContext& ctx) { LOG_WARNING(Service_MM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -69,14 +70,14 @@ private: rb.Push<u32>(id); // Any non zero value } - void Finalize(Kernel::HLERequestContext& ctx) { + void Finalize(HLERequestContext& ctx) { LOG_WARNING(Service_MM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void SetAndWait(Kernel::HLERequestContext& ctx) { + void SetAndWait(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; u32 input_id = rp.Pop<u32>(); min = rp.Pop<u32>(); @@ -89,7 +90,7 @@ private: rb.Push(ResultSuccess); } - void Get(Kernel::HLERequestContext& ctx) { + void Get(HLERequestContext& ctx) { LOG_DEBUG(Service_MM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -103,8 +104,11 @@ private: u32 id{1}; }; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<MM_U>(system)->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("mm:u", std::make_shared<MM_U>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::MM diff --git a/src/core/hle/service/mm/mm_u.h b/src/core/hle/service/mm/mm_u.h index b40941e35..43117c9b1 100644 --- a/src/core/hle/service/mm/mm_u.h +++ b/src/core/hle/service/mm/mm_u.h @@ -7,13 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::MM { -/// Registers all MM services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::MM diff --git a/src/core/hle/service/mnpp/mnpp_app.cpp b/src/core/hle/service/mnpp/mnpp_app.cpp index c3aad5714..b11a92056 100644 --- a/src/core/hle/service/mnpp/mnpp_app.cpp +++ b/src/core/hle/service/mnpp/mnpp_app.cpp @@ -2,9 +2,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/mnpp/mnpp_app.h" -#include "core/hle/service/sm/sm.h" +#include "core/hle/service/server_manager.h" +#include "core/hle/service/service.h" namespace Service::MNPP { @@ -22,14 +23,14 @@ public: } private: - void Unknown0(Kernel::HLERequestContext& ctx) { + void Unknown0(HLERequestContext& ctx) { LOG_WARNING(Service_MNPP, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void Unknown1(Kernel::HLERequestContext& ctx) { + void Unknown1(HLERequestContext& ctx) { LOG_WARNING(Service_MNPP, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -37,8 +38,11 @@ private: } }; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<MNPP_APP>(system)->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("mnpp:app", std::make_shared<MNPP_APP>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::MNPP diff --git a/src/core/hle/service/mnpp/mnpp_app.h b/src/core/hle/service/mnpp/mnpp_app.h index eec75fe0e..40d0395bd 100644 --- a/src/core/hle/service/mnpp/mnpp_app.h +++ b/src/core/hle/service/mnpp/mnpp_app.h @@ -7,13 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::MNPP { -/// Registers all MNPP services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::MNPP diff --git a/src/core/hle/service/mutex.cpp b/src/core/hle/service/mutex.cpp new file mode 100644 index 000000000..07589a0f0 --- /dev/null +++ b/src/core/hle/service/mutex.cpp @@ -0,0 +1,43 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/core.h" +#include "core/hle/kernel/k_event.h" +#include "core/hle/kernel/k_synchronization_object.h" +#include "core/hle/service/mutex.h" + +namespace Service { + +Mutex::Mutex(Core::System& system) : m_system(system) { + m_event = Kernel::KEvent::Create(system.Kernel()); + m_event->Initialize(nullptr); + + ASSERT(R_SUCCEEDED(m_event->Signal())); +} + +Mutex::~Mutex() { + m_event->GetReadableEvent().Close(); + m_event->Close(); +} + +void Mutex::lock() { + // Infinitely retry until we successfully clear the event. + while (R_FAILED(m_event->GetReadableEvent().Reset())) { + s32 index; + Kernel::KSynchronizationObject* obj = &m_event->GetReadableEvent(); + + // The event was already cleared! + // Wait for it to become signaled again. + ASSERT(R_SUCCEEDED( + Kernel::KSynchronizationObject::Wait(m_system.Kernel(), &index, &obj, 1, -1))); + } + + // We successfully cleared the event, and now have exclusive ownership. +} + +void Mutex::unlock() { + // Unlock. + ASSERT(R_SUCCEEDED(m_event->Signal())); +} + +} // namespace Service diff --git a/src/core/hle/service/mutex.h b/src/core/hle/service/mutex.h new file mode 100644 index 000000000..95ac9b117 --- /dev/null +++ b/src/core/hle/service/mutex.h @@ -0,0 +1,31 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "common/common_types.h" + +namespace Core { +class System; +} + +namespace Kernel { +class KEvent; +} + +namespace Service { + +class Mutex { +public: + explicit Mutex(Core::System& system); + ~Mutex(); + + void lock(); + void unlock(); + +private: + Core::System& m_system; + Kernel::KEvent* m_event{}; +}; + +} // namespace Service diff --git a/src/core/hle/service/ncm/ncm.cpp b/src/core/hle/service/ncm/ncm.cpp index 4c66cfeba..650666d6b 100644 --- a/src/core/hle/service/ncm/ncm.cpp +++ b/src/core/hle/service/ncm/ncm.cpp @@ -4,10 +4,10 @@ #include <memory> #include "core/file_sys/romfs_factory.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ncm/ncm.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" namespace Service::NCM { @@ -132,9 +132,12 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<LR>(system)->InstallAsService(sm); - std::make_shared<NCM>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("lr", std::make_shared<LR>(system)); + server_manager->RegisterNamedService("ncm", std::make_shared<NCM>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::NCM diff --git a/src/core/hle/service/ncm/ncm.h b/src/core/hle/service/ncm/ncm.h index de3971437..b78efdcd7 100644 --- a/src/core/hle/service/ncm/ncm.h +++ b/src/core/hle/service/ncm/ncm.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::NCM { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::NCM diff --git a/src/core/hle/service/nfc/mifare_user.cpp b/src/core/hle/service/nfc/mifare_user.cpp index 51523a3ae..e0bbd46e1 100644 --- a/src/core/hle/service/nfc/mifare_user.cpp +++ b/src/core/hle/service/nfc/mifare_user.cpp @@ -4,8 +4,8 @@ #include "common/logging/log.h" #include "core/core.h" #include "core/hid/hid_types.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nfc/mifare_user.h" #include "core/hle/service/nfc/nfc_device.h" #include "core/hle/service/nfc/nfc_result.h" @@ -45,7 +45,7 @@ MFIUser ::~MFIUser() { availability_change_event->Close(); } -void MFIUser::Initialize(Kernel::HLERequestContext& ctx) { +void MFIUser::Initialize(HLERequestContext& ctx) { LOG_INFO(Service_NFC, "called"); state = State::Initialized; @@ -58,7 +58,7 @@ void MFIUser::Initialize(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void MFIUser::Finalize(Kernel::HLERequestContext& ctx) { +void MFIUser::Finalize(HLERequestContext& ctx) { LOG_INFO(Service_NFC, "called"); state = State::NonInitialized; @@ -71,7 +71,7 @@ void MFIUser::Finalize(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void MFIUser::ListDevices(Kernel::HLERequestContext& ctx) { +void MFIUser::ListDevices(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); if (state == State::NonInitialized) { @@ -117,7 +117,7 @@ void MFIUser::ListDevices(Kernel::HLERequestContext& ctx) { rb.Push(static_cast<s32>(nfp_devices.size())); } -void MFIUser::StartDetection(Kernel::HLERequestContext& ctx) { +void MFIUser::StartDetection(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); @@ -141,7 +141,7 @@ void MFIUser::StartDetection(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void MFIUser::StopDetection(Kernel::HLERequestContext& ctx) { +void MFIUser::StopDetection(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); @@ -165,7 +165,7 @@ void MFIUser::StopDetection(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void MFIUser::Read(Kernel::HLERequestContext& ctx) { +void MFIUser::Read(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; const auto buffer{ctx.ReadBuffer()}; @@ -206,7 +206,7 @@ void MFIUser::Read(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void MFIUser::Write(Kernel::HLERequestContext& ctx) { +void MFIUser::Write(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; const auto buffer{ctx.ReadBuffer()}; @@ -250,7 +250,7 @@ void MFIUser::Write(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void MFIUser::GetTagInfo(Kernel::HLERequestContext& ctx) { +void MFIUser::GetTagInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); @@ -276,7 +276,7 @@ void MFIUser::GetTagInfo(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void MFIUser::GetActivateEventHandle(Kernel::HLERequestContext& ctx) { +void MFIUser::GetActivateEventHandle(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -300,7 +300,7 @@ void MFIUser::GetActivateEventHandle(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(device.value()->GetActivateEvent()); } -void MFIUser::GetDeactivateEventHandle(Kernel::HLERequestContext& ctx) { +void MFIUser::GetDeactivateEventHandle(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -324,7 +324,7 @@ void MFIUser::GetDeactivateEventHandle(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(device.value()->GetDeactivateEvent()); } -void MFIUser::GetState(Kernel::HLERequestContext& ctx) { +void MFIUser::GetState(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -332,7 +332,7 @@ void MFIUser::GetState(Kernel::HLERequestContext& ctx) { rb.PushEnum(state); } -void MFIUser::GetDeviceState(Kernel::HLERequestContext& ctx) { +void MFIUser::GetDeviceState(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -350,7 +350,7 @@ void MFIUser::GetDeviceState(Kernel::HLERequestContext& ctx) { rb.PushEnum(device.value()->GetCurrentState()); } -void MFIUser::GetNpadId(Kernel::HLERequestContext& ctx) { +void MFIUser::GetNpadId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -374,7 +374,7 @@ void MFIUser::GetNpadId(Kernel::HLERequestContext& ctx) { rb.PushEnum(device.value()->GetNpadId()); } -void MFIUser::GetAvailabilityChangeEventHandle(Kernel::HLERequestContext& ctx) { +void MFIUser::GetAvailabilityChangeEventHandle(HLERequestContext& ctx) { LOG_INFO(Service_NFC, "called"); if (state == State::NonInitialized) { diff --git a/src/core/hle/service/nfc/mifare_user.h b/src/core/hle/service/nfc/mifare_user.h index 0e0638cb6..9701f1d7f 100644 --- a/src/core/hle/service/nfc/mifare_user.h +++ b/src/core/hle/service/nfc/mifare_user.h @@ -24,20 +24,20 @@ private: Initialized, }; - void Initialize(Kernel::HLERequestContext& ctx); - void Finalize(Kernel::HLERequestContext& ctx); - void ListDevices(Kernel::HLERequestContext& ctx); - void StartDetection(Kernel::HLERequestContext& ctx); - void StopDetection(Kernel::HLERequestContext& ctx); - void Read(Kernel::HLERequestContext& ctx); - void Write(Kernel::HLERequestContext& ctx); - void GetTagInfo(Kernel::HLERequestContext& ctx); - void GetActivateEventHandle(Kernel::HLERequestContext& ctx); - void GetDeactivateEventHandle(Kernel::HLERequestContext& ctx); - void GetState(Kernel::HLERequestContext& ctx); - void GetDeviceState(Kernel::HLERequestContext& ctx); - void GetNpadId(Kernel::HLERequestContext& ctx); - void GetAvailabilityChangeEventHandle(Kernel::HLERequestContext& ctx); + void Initialize(HLERequestContext& ctx); + void Finalize(HLERequestContext& ctx); + void ListDevices(HLERequestContext& ctx); + void StartDetection(HLERequestContext& ctx); + void StopDetection(HLERequestContext& ctx); + void Read(HLERequestContext& ctx); + void Write(HLERequestContext& ctx); + void GetTagInfo(HLERequestContext& ctx); + void GetActivateEventHandle(HLERequestContext& ctx); + void GetDeactivateEventHandle(HLERequestContext& ctx); + void GetState(HLERequestContext& ctx); + void GetDeviceState(HLERequestContext& ctx); + void GetNpadId(HLERequestContext& ctx); + void GetAvailabilityChangeEventHandle(HLERequestContext& ctx); std::optional<std::shared_ptr<NfcDevice>> GetNfcDevice(u64 handle); diff --git a/src/core/hle/service/nfc/nfc.cpp b/src/core/hle/service/nfc/nfc.cpp index b17b18ab9..6595e34ed 100644 --- a/src/core/hle/service/nfc/nfc.cpp +++ b/src/core/hle/service/nfc/nfc.cpp @@ -5,12 +5,12 @@ #include "common/logging/log.h" #include "common/settings.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nfc/mifare_user.h" #include "core/hle/service/nfc/nfc.h" #include "core/hle/service/nfc/nfc_user.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" namespace Service::NFC { @@ -42,7 +42,7 @@ public: } private: - void CreateAmInterface(Kernel::HLERequestContext& ctx) { + void CreateAmInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -64,7 +64,7 @@ public: } private: - void CreateUserInterface(Kernel::HLERequestContext& ctx) { + void CreateUserInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -86,7 +86,7 @@ public: } private: - void CreateUserInterface(Kernel::HLERequestContext& ctx) { + void CreateUserInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -145,7 +145,7 @@ public: } private: - void CreateSystemInterface(Kernel::HLERequestContext& ctx) { + void CreateSystemInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -154,11 +154,14 @@ private: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<NFC_AM>(system)->InstallAsService(sm); - std::make_shared<NFC_MF_U>(system)->InstallAsService(sm); - std::make_shared<NFC_U>(system)->InstallAsService(sm); - std::make_shared<NFC_SYS>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("nfc:am", std::make_shared<NFC_AM>(system)); + server_manager->RegisterNamedService("nfc:mf:u", std::make_shared<NFC_MF_U>(system)); + server_manager->RegisterNamedService("nfc:user", std::make_shared<NFC_U>(system)); + server_manager->RegisterNamedService("nfc:sys", std::make_shared<NFC_SYS>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::NFC diff --git a/src/core/hle/service/nfc/nfc.h b/src/core/hle/service/nfc/nfc.h index 0107b696c..d15955b75 100644 --- a/src/core/hle/service/nfc/nfc.h +++ b/src/core/hle/service/nfc/nfc.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::NFC { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::NFC diff --git a/src/core/hle/service/nfc/nfc_device.cpp b/src/core/hle/service/nfc/nfc_device.cpp index 9a3234e8c..3f17d0c7a 100644 --- a/src/core/hle/service/nfc/nfc_device.cpp +++ b/src/core/hle/service/nfc/nfc_device.cpp @@ -7,8 +7,8 @@ #include "core/hid/emulated_controller.h" #include "core/hid/hid_core.h" #include "core/hid/hid_types.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nfc/nfc_device.h" #include "core/hle/service/nfc/nfc_result.h" #include "core/hle/service/nfc/nfc_user.h" diff --git a/src/core/hle/service/nfc/nfc_user.cpp b/src/core/hle/service/nfc/nfc_user.cpp index 89aa6b3f5..7c162a4f3 100644 --- a/src/core/hle/service/nfc/nfc_user.cpp +++ b/src/core/hle/service/nfc/nfc_user.cpp @@ -4,8 +4,8 @@ #include "common/logging/log.h" #include "core/core.h" #include "core/hid/hid_types.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nfc/nfc_device.h" #include "core/hle/service/nfc/nfc_result.h" #include "core/hle/service/nfc/nfc_user.h" @@ -54,7 +54,7 @@ IUser ::~IUser() { availability_change_event->Close(); } -void IUser::Initialize(Kernel::HLERequestContext& ctx) { +void IUser::Initialize(HLERequestContext& ctx) { LOG_INFO(Service_NFC, "called"); state = State::Initialized; @@ -67,7 +67,7 @@ void IUser::Initialize(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IUser::Finalize(Kernel::HLERequestContext& ctx) { +void IUser::Finalize(HLERequestContext& ctx) { LOG_INFO(Service_NFC, "called"); state = State::NonInitialized; @@ -80,7 +80,7 @@ void IUser::Finalize(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IUser::GetState(Kernel::HLERequestContext& ctx) { +void IUser::GetState(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -88,7 +88,7 @@ void IUser::GetState(Kernel::HLERequestContext& ctx) { rb.PushEnum(state); } -void IUser::IsNfcEnabled(Kernel::HLERequestContext& ctx) { +void IUser::IsNfcEnabled(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -96,7 +96,7 @@ void IUser::IsNfcEnabled(Kernel::HLERequestContext& ctx) { rb.Push(state != State::NonInitialized); } -void IUser::ListDevices(Kernel::HLERequestContext& ctx) { +void IUser::ListDevices(HLERequestContext& ctx) { LOG_DEBUG(Service_NFC, "called"); if (state == State::NonInitialized) { @@ -142,7 +142,7 @@ void IUser::ListDevices(Kernel::HLERequestContext& ctx) { rb.Push(static_cast<s32>(nfp_devices.size())); } -void IUser::GetDeviceState(Kernel::HLERequestContext& ctx) { +void IUser::GetDeviceState(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -160,7 +160,7 @@ void IUser::GetDeviceState(Kernel::HLERequestContext& ctx) { rb.PushEnum(device.value()->GetCurrentState()); } -void IUser::GetNpadId(Kernel::HLERequestContext& ctx) { +void IUser::GetNpadId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -184,7 +184,7 @@ void IUser::GetNpadId(Kernel::HLERequestContext& ctx) { rb.PushEnum(device.value()->GetNpadId()); } -void IUser::AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx) { +void IUser::AttachAvailabilityChangeEvent(HLERequestContext& ctx) { LOG_INFO(Service_NFC, "called"); if (state == State::NonInitialized) { @@ -198,7 +198,7 @@ void IUser::AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(availability_change_event->GetReadableEvent()); } -void IUser::StartDetection(Kernel::HLERequestContext& ctx) { +void IUser::StartDetection(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; const auto nfp_protocol{rp.PopEnum<NFP::TagProtocol>()}; @@ -223,7 +223,7 @@ void IUser::StartDetection(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::StopDetection(Kernel::HLERequestContext& ctx) { +void IUser::StopDetection(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); @@ -247,7 +247,7 @@ void IUser::StopDetection(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::GetTagInfo(Kernel::HLERequestContext& ctx) { +void IUser::GetTagInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); @@ -273,7 +273,7 @@ void IUser::GetTagInfo(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::AttachActivateEvent(Kernel::HLERequestContext& ctx) { +void IUser::AttachActivateEvent(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -297,7 +297,7 @@ void IUser::AttachActivateEvent(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(device.value()->GetActivateEvent()); } -void IUser::AttachDeactivateEvent(Kernel::HLERequestContext& ctx) { +void IUser::AttachDeactivateEvent(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); @@ -321,7 +321,7 @@ void IUser::AttachDeactivateEvent(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(device.value()->GetDeactivateEvent()); } -void IUser::SendCommandByPassThrough(Kernel::HLERequestContext& ctx) { +void IUser::SendCommandByPassThrough(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; const auto timeout{rp.PopRaw<Time::Clock::TimeSpanType>()}; diff --git a/src/core/hle/service/nfc/nfc_user.h b/src/core/hle/service/nfc/nfc_user.h index a5a4f12f9..aee046ae8 100644 --- a/src/core/hle/service/nfc/nfc_user.h +++ b/src/core/hle/service/nfc/nfc_user.h @@ -24,20 +24,20 @@ private: Initialized, }; - void Initialize(Kernel::HLERequestContext& ctx); - void Finalize(Kernel::HLERequestContext& ctx); - void GetState(Kernel::HLERequestContext& ctx); - void IsNfcEnabled(Kernel::HLERequestContext& ctx); - void ListDevices(Kernel::HLERequestContext& ctx); - void GetDeviceState(Kernel::HLERequestContext& ctx); - void GetNpadId(Kernel::HLERequestContext& ctx); - void AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx); - void StartDetection(Kernel::HLERequestContext& ctx); - void StopDetection(Kernel::HLERequestContext& ctx); - void GetTagInfo(Kernel::HLERequestContext& ctx); - void AttachActivateEvent(Kernel::HLERequestContext& ctx); - void AttachDeactivateEvent(Kernel::HLERequestContext& ctx); - void SendCommandByPassThrough(Kernel::HLERequestContext& ctx); + void Initialize(HLERequestContext& ctx); + void Finalize(HLERequestContext& ctx); + void GetState(HLERequestContext& ctx); + void IsNfcEnabled(HLERequestContext& ctx); + void ListDevices(HLERequestContext& ctx); + void GetDeviceState(HLERequestContext& ctx); + void GetNpadId(HLERequestContext& ctx); + void AttachAvailabilityChangeEvent(HLERequestContext& ctx); + void StartDetection(HLERequestContext& ctx); + void StopDetection(HLERequestContext& ctx); + void GetTagInfo(HLERequestContext& ctx); + void AttachActivateEvent(HLERequestContext& ctx); + void AttachDeactivateEvent(HLERequestContext& ctx); + void SendCommandByPassThrough(HLERequestContext& ctx); std::optional<std::shared_ptr<NfcDevice>> GetNfcDevice(u64 handle); diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 0cb55ca49..e262dc2f2 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp @@ -2,9 +2,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nfp/nfp.h" #include "core/hle/service/nfp/nfp_user.h" +#include "core/hle/service/server_manager.h" namespace Service::NFP { @@ -21,7 +22,7 @@ public: } private: - void CreateUserInterface(Kernel::HLERequestContext& ctx) { + void CreateUserInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NFP, "called"); if (user_interface == nullptr) { @@ -36,8 +37,11 @@ private: std::shared_ptr<IUser> user_interface; }; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<IUserManager>(system)->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("nfp:user", std::make_shared<IUserManager>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::NFP diff --git a/src/core/hle/service/nfp/nfp.h b/src/core/hle/service/nfp/nfp.h index a25c362b8..a5aac710b 100644 --- a/src/core/hle/service/nfp/nfp.h +++ b/src/core/hle/service/nfp/nfp.h @@ -7,6 +7,6 @@ namespace Service::NFP { -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::NFP diff --git a/src/core/hle/service/nfp/nfp_device.cpp b/src/core/hle/service/nfp/nfp_device.cpp index 7a6bbbba7..1bdc42741 100644 --- a/src/core/hle/service/nfp/nfp_device.cpp +++ b/src/core/hle/service/nfp/nfp_device.cpp @@ -11,8 +11,8 @@ #include "core/hid/emulated_controller.h" #include "core/hid/hid_core.h" #include "core/hid/hid_types.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/mii/mii_manager.h" #include "core/hle/service/mii/types.h" #include "core/hle/service/nfp/amiibo_crypto.h" diff --git a/src/core/hle/service/nfp/nfp_user.cpp b/src/core/hle/service/nfp/nfp_user.cpp index a4d3d1bc7..4e8534113 100644 --- a/src/core/hle/service/nfp/nfp_user.cpp +++ b/src/core/hle/service/nfp/nfp_user.cpp @@ -4,8 +4,8 @@ #include "common/logging/log.h" #include "core/core.h" #include "core/hid/hid_types.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nfp/nfp_device.h" #include "core/hle/service/nfp/nfp_result.h" #include "core/hle/service/nfp/nfp_user.h" @@ -56,7 +56,7 @@ IUser ::~IUser() { availability_change_event->Close(); } -void IUser::Initialize(Kernel::HLERequestContext& ctx) { +void IUser::Initialize(HLERequestContext& ctx) { LOG_INFO(Service_NFP, "called"); state = State::Initialized; @@ -69,7 +69,7 @@ void IUser::Initialize(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IUser::Finalize(Kernel::HLERequestContext& ctx) { +void IUser::Finalize(HLERequestContext& ctx) { LOG_INFO(Service_NFP, "called"); state = State::NonInitialized; @@ -82,7 +82,7 @@ void IUser::Finalize(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IUser::ListDevices(Kernel::HLERequestContext& ctx) { +void IUser::ListDevices(HLERequestContext& ctx) { LOG_DEBUG(Service_NFP, "called"); if (state == State::NonInitialized) { @@ -128,7 +128,7 @@ void IUser::ListDevices(Kernel::HLERequestContext& ctx) { rb.Push(static_cast<s32>(nfp_devices.size())); } -void IUser::StartDetection(Kernel::HLERequestContext& ctx) { +void IUser::StartDetection(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; const auto nfp_protocol{rp.PopEnum<TagProtocol>()}; @@ -153,7 +153,7 @@ void IUser::StartDetection(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::StopDetection(Kernel::HLERequestContext& ctx) { +void IUser::StopDetection(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_INFO(Service_NFP, "called, device_handle={}", device_handle); @@ -177,7 +177,7 @@ void IUser::StopDetection(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::Mount(Kernel::HLERequestContext& ctx) { +void IUser::Mount(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; const auto model_type{rp.PopEnum<ModelType>()}; @@ -204,7 +204,7 @@ void IUser::Mount(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::Unmount(Kernel::HLERequestContext& ctx) { +void IUser::Unmount(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_INFO(Service_NFP, "called, device_handle={}", device_handle); @@ -228,7 +228,7 @@ void IUser::Unmount(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::OpenApplicationArea(Kernel::HLERequestContext& ctx) { +void IUser::OpenApplicationArea(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; const auto access_id{rp.Pop<u32>()}; @@ -253,7 +253,7 @@ void IUser::OpenApplicationArea(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::GetApplicationArea(Kernel::HLERequestContext& ctx) { +void IUser::GetApplicationArea(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; const auto data_size = ctx.GetWriteBufferSize(); @@ -287,7 +287,7 @@ void IUser::GetApplicationArea(Kernel::HLERequestContext& ctx) { rb.Push(static_cast<u32>(data_size)); } -void IUser::SetApplicationArea(Kernel::HLERequestContext& ctx) { +void IUser::SetApplicationArea(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; const auto data{ctx.ReadBuffer()}; @@ -318,7 +318,7 @@ void IUser::SetApplicationArea(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::Flush(Kernel::HLERequestContext& ctx) { +void IUser::Flush(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_INFO(Service_NFP, "called, device_handle={}", device_handle); @@ -342,7 +342,7 @@ void IUser::Flush(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::Restore(Kernel::HLERequestContext& ctx) { +void IUser::Restore(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_WARNING(Service_NFP, "(STUBBED) called, device_handle={}", device_handle); @@ -366,7 +366,7 @@ void IUser::Restore(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::CreateApplicationArea(Kernel::HLERequestContext& ctx) { +void IUser::CreateApplicationArea(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; const auto access_id{rp.Pop<u32>()}; @@ -399,7 +399,7 @@ void IUser::CreateApplicationArea(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::GetTagInfo(Kernel::HLERequestContext& ctx) { +void IUser::GetTagInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_INFO(Service_NFP, "called, device_handle={}", device_handle); @@ -425,7 +425,7 @@ void IUser::GetTagInfo(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::GetRegisterInfo(Kernel::HLERequestContext& ctx) { +void IUser::GetRegisterInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_INFO(Service_NFP, "called, device_handle={}", device_handle); @@ -451,7 +451,7 @@ void IUser::GetRegisterInfo(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::GetCommonInfo(Kernel::HLERequestContext& ctx) { +void IUser::GetCommonInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_INFO(Service_NFP, "called, device_handle={}", device_handle); @@ -477,7 +477,7 @@ void IUser::GetCommonInfo(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::GetModelInfo(Kernel::HLERequestContext& ctx) { +void IUser::GetModelInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_INFO(Service_NFP, "called, device_handle={}", device_handle); @@ -503,7 +503,7 @@ void IUser::GetModelInfo(Kernel::HLERequestContext& ctx) { rb.Push(result); } -void IUser::AttachActivateEvent(Kernel::HLERequestContext& ctx) { +void IUser::AttachActivateEvent(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle); @@ -527,7 +527,7 @@ void IUser::AttachActivateEvent(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(device.value()->GetActivateEvent()); } -void IUser::AttachDeactivateEvent(Kernel::HLERequestContext& ctx) { +void IUser::AttachDeactivateEvent(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle); @@ -551,7 +551,7 @@ void IUser::AttachDeactivateEvent(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(device.value()->GetDeactivateEvent()); } -void IUser::GetState(Kernel::HLERequestContext& ctx) { +void IUser::GetState(HLERequestContext& ctx) { LOG_DEBUG(Service_NFP, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -559,7 +559,7 @@ void IUser::GetState(Kernel::HLERequestContext& ctx) { rb.PushEnum(state); } -void IUser::GetDeviceState(Kernel::HLERequestContext& ctx) { +void IUser::GetDeviceState(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle); @@ -577,7 +577,7 @@ void IUser::GetDeviceState(Kernel::HLERequestContext& ctx) { rb.PushEnum(device.value()->GetCurrentState()); } -void IUser::GetNpadId(Kernel::HLERequestContext& ctx) { +void IUser::GetNpadId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle); @@ -601,7 +601,7 @@ void IUser::GetNpadId(Kernel::HLERequestContext& ctx) { rb.PushEnum(device.value()->GetNpadId()); } -void IUser::GetApplicationAreaSize(Kernel::HLERequestContext& ctx) { +void IUser::GetApplicationAreaSize(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle); @@ -619,7 +619,7 @@ void IUser::GetApplicationAreaSize(Kernel::HLERequestContext& ctx) { rb.Push(device.value()->GetApplicationAreaSize()); } -void IUser::AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx) { +void IUser::AttachAvailabilityChangeEvent(HLERequestContext& ctx) { LOG_INFO(Service_NFP, "called"); if (state == State::NonInitialized) { @@ -633,7 +633,7 @@ void IUser::AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx) { rb.PushCopyObjects(availability_change_event->GetReadableEvent()); } -void IUser::RecreateApplicationArea(Kernel::HLERequestContext& ctx) { +void IUser::RecreateApplicationArea(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop<u64>()}; const auto access_id{rp.Pop<u32>()}; diff --git a/src/core/hle/service/nfp/nfp_user.h b/src/core/hle/service/nfp/nfp_user.h index 7e9a90af8..1f3ff2ea8 100644 --- a/src/core/hle/service/nfp/nfp_user.h +++ b/src/core/hle/service/nfp/nfp_user.h @@ -24,31 +24,31 @@ private: Initialized, }; - void Initialize(Kernel::HLERequestContext& ctx); - void Finalize(Kernel::HLERequestContext& ctx); - void ListDevices(Kernel::HLERequestContext& ctx); - void StartDetection(Kernel::HLERequestContext& ctx); - void StopDetection(Kernel::HLERequestContext& ctx); - void Mount(Kernel::HLERequestContext& ctx); - void Unmount(Kernel::HLERequestContext& ctx); - void OpenApplicationArea(Kernel::HLERequestContext& ctx); - void GetApplicationArea(Kernel::HLERequestContext& ctx); - void SetApplicationArea(Kernel::HLERequestContext& ctx); - void Flush(Kernel::HLERequestContext& ctx); - void Restore(Kernel::HLERequestContext& ctx); - void CreateApplicationArea(Kernel::HLERequestContext& ctx); - void GetTagInfo(Kernel::HLERequestContext& ctx); - void GetRegisterInfo(Kernel::HLERequestContext& ctx); - void GetCommonInfo(Kernel::HLERequestContext& ctx); - void GetModelInfo(Kernel::HLERequestContext& ctx); - void AttachActivateEvent(Kernel::HLERequestContext& ctx); - void AttachDeactivateEvent(Kernel::HLERequestContext& ctx); - void GetState(Kernel::HLERequestContext& ctx); - void GetDeviceState(Kernel::HLERequestContext& ctx); - void GetNpadId(Kernel::HLERequestContext& ctx); - void GetApplicationAreaSize(Kernel::HLERequestContext& ctx); - void AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx); - void RecreateApplicationArea(Kernel::HLERequestContext& ctx); + void Initialize(HLERequestContext& ctx); + void Finalize(HLERequestContext& ctx); + void ListDevices(HLERequestContext& ctx); + void StartDetection(HLERequestContext& ctx); + void StopDetection(HLERequestContext& ctx); + void Mount(HLERequestContext& ctx); + void Unmount(HLERequestContext& ctx); + void OpenApplicationArea(HLERequestContext& ctx); + void GetApplicationArea(HLERequestContext& ctx); + void SetApplicationArea(HLERequestContext& ctx); + void Flush(HLERequestContext& ctx); + void Restore(HLERequestContext& ctx); + void CreateApplicationArea(HLERequestContext& ctx); + void GetTagInfo(HLERequestContext& ctx); + void GetRegisterInfo(HLERequestContext& ctx); + void GetCommonInfo(HLERequestContext& ctx); + void GetModelInfo(HLERequestContext& ctx); + void AttachActivateEvent(HLERequestContext& ctx); + void AttachDeactivateEvent(HLERequestContext& ctx); + void GetState(HLERequestContext& ctx); + void GetDeviceState(HLERequestContext& ctx); + void GetNpadId(HLERequestContext& ctx); + void GetApplicationAreaSize(HLERequestContext& ctx); + void AttachAvailabilityChangeEvent(HLERequestContext& ctx); + void RecreateApplicationArea(HLERequestContext& ctx); std::optional<std::shared_ptr<NfpDevice>> GetNfpDevice(u64 handle); diff --git a/src/core/hle/service/ngct/ngct.cpp b/src/core/hle/service/ngct/ngct.cpp index 8af8a835d..493c80ed2 100644 --- a/src/core/hle/service/ngct/ngct.cpp +++ b/src/core/hle/service/ngct/ngct.cpp @@ -3,8 +3,9 @@ #include "common/string_util.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ngct/ngct.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" namespace Service::NGCT { @@ -23,7 +24,7 @@ public: } private: - void Match(Kernel::HLERequestContext& ctx) { + void Match(HLERequestContext& ctx) { const auto buffer = ctx.ReadBuffer(); const auto text = Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast<const char*>(buffer.data()), buffer.size()); @@ -36,7 +37,7 @@ private: rb.Push(false); } - void Filter(Kernel::HLERequestContext& ctx) { + void Filter(HLERequestContext& ctx) { const auto buffer = ctx.ReadBuffer(); const auto text = Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast<const char*>(buffer.data()), buffer.size()); @@ -51,8 +52,11 @@ private: } }; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<IService>(system)->InstallAsService(system.ServiceManager()); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("ngct:u", std::make_shared<IService>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::NGCT diff --git a/src/core/hle/service/ngct/ngct.h b/src/core/hle/service/ngct/ngct.h index 370bd4a25..27c34dad4 100644 --- a/src/core/hle/service/ngct/ngct.h +++ b/src/core/hle/service/ngct/ngct.h @@ -7,13 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::NGCT { -/// Registers all NGCT services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::NGCT diff --git a/src/core/hle/service/nifm/nifm.cpp b/src/core/hle/service/nifm/nifm.cpp index 5d32adf64..0c042f412 100644 --- a/src/core/hle/service/nifm/nifm.cpp +++ b/src/core/hle/service/nifm/nifm.cpp @@ -2,10 +2,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/kernel_helpers.h" #include "core/hle/service/nifm/nifm.h" +#include "core/hle/service/server_manager.h" namespace { @@ -216,7 +217,7 @@ public: } private: - void Submit(Kernel::HLERequestContext& ctx) { + void Submit(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); if (state == RequestState::NotSubmitted) { @@ -227,7 +228,7 @@ private: rb.Push(ResultSuccess); } - void GetRequestState(Kernel::HLERequestContext& ctx) { + void GetRequestState(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -235,7 +236,7 @@ private: rb.PushEnum(state); } - void GetResult(Kernel::HLERequestContext& ctx) { + void GetResult(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); const auto result = [this] { @@ -260,7 +261,7 @@ private: rb.Push(result); } - void GetSystemEventReadableHandles(Kernel::HLERequestContext& ctx) { + void GetSystemEventReadableHandles(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 2}; @@ -268,21 +269,21 @@ private: rb.PushCopyObjects(event1->GetReadableEvent(), event2->GetReadableEvent()); } - void Cancel(Kernel::HLERequestContext& ctx) { + void Cancel(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void SetConnectionConfirmationOption(Kernel::HLERequestContext& ctx) { + void SetConnectionConfirmationOption(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void GetAppletInfo(Kernel::HLERequestContext& ctx) { + void GetAppletInfo(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); std::vector<u8> out_buffer(ctx.GetWriteBufferSize()); @@ -321,7 +322,7 @@ public: } }; -void IGeneralService::GetClientId(Kernel::HLERequestContext& ctx) { +void IGeneralService::GetClientId(HLERequestContext& ctx) { static constexpr u32 client_id = 1; LOG_WARNING(Service_NIFM, "(STUBBED) called"); @@ -330,7 +331,7 @@ void IGeneralService::GetClientId(Kernel::HLERequestContext& ctx) { rb.Push<u64>(client_id); // Client ID needs to be non zero otherwise it's considered invalid } -void IGeneralService::CreateScanRequest(Kernel::HLERequestContext& ctx) { +void IGeneralService::CreateScanRequest(HLERequestContext& ctx) { LOG_DEBUG(Service_NIFM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -339,7 +340,7 @@ void IGeneralService::CreateScanRequest(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IScanRequest>(system); } -void IGeneralService::CreateRequest(Kernel::HLERequestContext& ctx) { +void IGeneralService::CreateRequest(HLERequestContext& ctx) { LOG_DEBUG(Service_NIFM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -348,7 +349,7 @@ void IGeneralService::CreateRequest(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IRequest>(system); } -void IGeneralService::GetCurrentNetworkProfile(Kernel::HLERequestContext& ctx) { +void IGeneralService::GetCurrentNetworkProfile(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); const auto net_iface = Network::GetSelectedNetworkInterface(); @@ -407,14 +408,14 @@ void IGeneralService::GetCurrentNetworkProfile(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IGeneralService::RemoveNetworkProfile(Kernel::HLERequestContext& ctx) { +void IGeneralService::RemoveNetworkProfile(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void IGeneralService::GetCurrentIpAddress(Kernel::HLERequestContext& ctx) { +void IGeneralService::GetCurrentIpAddress(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); auto ipv4 = Network::GetHostIPv4Address(); @@ -435,7 +436,7 @@ void IGeneralService::GetCurrentIpAddress(Kernel::HLERequestContext& ctx) { rb.PushRaw(*ipv4); } -void IGeneralService::CreateTemporaryNetworkProfile(Kernel::HLERequestContext& ctx) { +void IGeneralService::CreateTemporaryNetworkProfile(HLERequestContext& ctx) { LOG_DEBUG(Service_NIFM, "called"); ASSERT_MSG(ctx.GetReadBufferSize() == 0x17c, "SfNetworkProfileData is not the correct size"); @@ -450,7 +451,7 @@ void IGeneralService::CreateTemporaryNetworkProfile(Kernel::HLERequestContext& c rb.PushRaw<u128>(uuid); } -void IGeneralService::GetCurrentIpConfigInfo(Kernel::HLERequestContext& ctx) { +void IGeneralService::GetCurrentIpConfigInfo(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); struct IpConfigInfo { @@ -494,7 +495,7 @@ void IGeneralService::GetCurrentIpConfigInfo(Kernel::HLERequestContext& ctx) { rb.PushRaw<IpConfigInfo>(ip_config_info); } -void IGeneralService::IsWirelessCommunicationEnabled(Kernel::HLERequestContext& ctx) { +void IGeneralService::IsWirelessCommunicationEnabled(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -502,7 +503,7 @@ void IGeneralService::IsWirelessCommunicationEnabled(Kernel::HLERequestContext& rb.Push<u8>(1); } -void IGeneralService::GetInternetConnectionStatus(Kernel::HLERequestContext& ctx) { +void IGeneralService::GetInternetConnectionStatus(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); struct Output { @@ -519,7 +520,7 @@ void IGeneralService::GetInternetConnectionStatus(Kernel::HLERequestContext& ctx rb.PushRaw(out); } -void IGeneralService::IsEthernetCommunicationEnabled(Kernel::HLERequestContext& ctx) { +void IGeneralService::IsEthernetCommunicationEnabled(HLERequestContext& ctx) { LOG_WARNING(Service_NIFM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -531,7 +532,7 @@ void IGeneralService::IsEthernetCommunicationEnabled(Kernel::HLERequestContext& } } -void IGeneralService::IsAnyInternetRequestAccepted(Kernel::HLERequestContext& ctx) { +void IGeneralService::IsAnyInternetRequestAccepted(HLERequestContext& ctx) { LOG_ERROR(Service_NIFM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -609,7 +610,7 @@ public: } private: - void CreateGeneralServiceOld(Kernel::HLERequestContext& ctx) { + void CreateGeneralServiceOld(HLERequestContext& ctx) { LOG_DEBUG(Service_NIFM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -617,7 +618,7 @@ private: rb.PushIpcInterface<IGeneralService>(system); } - void CreateGeneralService(Kernel::HLERequestContext& ctx) { + void CreateGeneralService(HLERequestContext& ctx) { LOG_DEBUG(Service_NIFM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -626,10 +627,16 @@ private: } }; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<NetworkInterface>("nifm:a", system)->InstallAsService(service_manager); - std::make_shared<NetworkInterface>("nifm:s", system)->InstallAsService(service_manager); - std::make_shared<NetworkInterface>("nifm:u", system)->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("nifm:a", + std::make_shared<NetworkInterface>("nifm:a", system)); + server_manager->RegisterNamedService("nifm:s", + std::make_shared<NetworkInterface>("nifm:s", system)); + server_manager->RegisterNamedService("nifm:u", + std::make_shared<NetworkInterface>("nifm:u", system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::NIFM diff --git a/src/core/hle/service/nifm/nifm.h b/src/core/hle/service/nifm/nifm.h index 48161be28..9b20e6823 100644 --- a/src/core/hle/service/nifm/nifm.h +++ b/src/core/hle/service/nifm/nifm.h @@ -12,14 +12,9 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::NIFM { -/// Registers all NIFM services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); class IGeneralService final : public ServiceFramework<IGeneralService> { public: @@ -27,18 +22,18 @@ public: ~IGeneralService() override; private: - void GetClientId(Kernel::HLERequestContext& ctx); - void CreateScanRequest(Kernel::HLERequestContext& ctx); - void CreateRequest(Kernel::HLERequestContext& ctx); - void GetCurrentNetworkProfile(Kernel::HLERequestContext& ctx); - void RemoveNetworkProfile(Kernel::HLERequestContext& ctx); - void GetCurrentIpAddress(Kernel::HLERequestContext& ctx); - void CreateTemporaryNetworkProfile(Kernel::HLERequestContext& ctx); - void GetCurrentIpConfigInfo(Kernel::HLERequestContext& ctx); - void IsWirelessCommunicationEnabled(Kernel::HLERequestContext& ctx); - void GetInternetConnectionStatus(Kernel::HLERequestContext& ctx); - void IsEthernetCommunicationEnabled(Kernel::HLERequestContext& ctx); - void IsAnyInternetRequestAccepted(Kernel::HLERequestContext& ctx); + void GetClientId(HLERequestContext& ctx); + void CreateScanRequest(HLERequestContext& ctx); + void CreateRequest(HLERequestContext& ctx); + void GetCurrentNetworkProfile(HLERequestContext& ctx); + void RemoveNetworkProfile(HLERequestContext& ctx); + void GetCurrentIpAddress(HLERequestContext& ctx); + void CreateTemporaryNetworkProfile(HLERequestContext& ctx); + void GetCurrentIpConfigInfo(HLERequestContext& ctx); + void IsWirelessCommunicationEnabled(HLERequestContext& ctx); + void GetInternetConnectionStatus(HLERequestContext& ctx); + void IsEthernetCommunicationEnabled(HLERequestContext& ctx); + void IsAnyInternetRequestAccepted(HLERequestContext& ctx); Network::RoomNetwork& network; }; diff --git a/src/core/hle/service/nim/nim.cpp b/src/core/hle/service/nim/nim.cpp index 5a8a91e0b..42de87f9a 100644 --- a/src/core/hle/service/nim/nim.cpp +++ b/src/core/hle/service/nim/nim.cpp @@ -4,12 +4,12 @@ #include <chrono> #include <ctime> #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/kernel_helpers.h" #include "core/hle/service/nim/nim.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" namespace Service::NIM { @@ -46,7 +46,7 @@ public: } private: - void CreateAsyncInterface(Kernel::HLERequestContext& ctx) { + void CreateAsyncInterface(HLERequestContext& ctx) { LOG_WARNING(Service_NIM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -68,7 +68,7 @@ public: } private: - void CreateAccessorInterface(Kernel::HLERequestContext& ctx) { + void CreateAccessorInterface(HLERequestContext& ctx) { LOG_WARNING(Service_NIM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -239,14 +239,14 @@ public: } private: - void CreateServerInterface(Kernel::HLERequestContext& ctx) { + void CreateServerInterface(HLERequestContext& ctx) { LOG_WARNING(Service_NIM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface<IShopServiceAccessServer>(system); } - void IsLargeResourceAvailable(Kernel::HLERequestContext& ctx) { + void IsLargeResourceAvailable(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto unknown{rp.Pop<u64>()}; @@ -325,7 +325,7 @@ public: } private: - void StartTask(Kernel::HLERequestContext& ctx) { + void StartTask(HLERequestContext& ctx) { // No need to connect to the internet, just finish the task straight away. LOG_DEBUG(Service_NIM, "called"); finished_event->Signal(); @@ -333,7 +333,7 @@ private: rb.Push(ResultSuccess); } - void GetFinishNotificationEvent(Kernel::HLERequestContext& ctx) { + void GetFinishNotificationEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_NIM, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -341,21 +341,21 @@ private: rb.PushCopyObjects(finished_event->GetReadableEvent()); } - void GetResult(Kernel::HLERequestContext& ctx) { + void GetResult(HLERequestContext& ctx) { LOG_DEBUG(Service_NIM, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void Cancel(Kernel::HLERequestContext& ctx) { + void Cancel(HLERequestContext& ctx) { LOG_DEBUG(Service_NIM, "called"); finished_event->Clear(); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void IsProcessing(Kernel::HLERequestContext& ctx) { + void IsProcessing(HLERequestContext& ctx) { LOG_DEBUG(Service_NIM, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -363,7 +363,7 @@ private: rb.PushRaw<u32>(0); // We instantly process the request } - void GetServerTime(Kernel::HLERequestContext& ctx) { + void GetServerTime(HLERequestContext& ctx) { LOG_DEBUG(Service_NIM, "called"); const s64 server_time{std::chrono::duration_cast<std::chrono::seconds>( @@ -394,7 +394,7 @@ public: } private: - void OpenEnsureNetworkClockAvailabilityService(Kernel::HLERequestContext& ctx) { + void OpenEnsureNetworkClockAvailabilityService(HLERequestContext& ctx) { LOG_DEBUG(Service_NIM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -403,14 +403,14 @@ private: } // TODO(ogniK): Do we need these? - void SuspendAutonomicTimeCorrection(Kernel::HLERequestContext& ctx) { + void SuspendAutonomicTimeCorrection(HLERequestContext& ctx) { LOG_WARNING(Service_NIM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void ResumeAutonomicTimeCorrection(Kernel::HLERequestContext& ctx) { + void ResumeAutonomicTimeCorrection(HLERequestContext& ctx) { LOG_WARNING(Service_NIM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -418,11 +418,14 @@ private: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<NIM>(system)->InstallAsService(sm); - std::make_shared<NIM_ECA>(system)->InstallAsService(sm); - std::make_shared<NIM_SHP>(system)->InstallAsService(sm); - std::make_shared<NTC>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("nim", std::make_shared<NIM>(system)); + server_manager->RegisterNamedService("nim:eca", std::make_shared<NIM_ECA>(system)); + server_manager->RegisterNamedService("nim:shp", std::make_shared<NIM_SHP>(system)); + server_manager->RegisterNamedService("ntc", std::make_shared<NTC>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::NIM diff --git a/src/core/hle/service/nim/nim.h b/src/core/hle/service/nim/nim.h index 8f6ff28e8..e7d599908 100644 --- a/src/core/hle/service/nim/nim.h +++ b/src/core/hle/service/nim/nim.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::NIM { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::NIM diff --git a/src/core/hle/service/npns/npns.cpp b/src/core/hle/service/npns/npns.cpp index 8133711c2..a162e5c54 100644 --- a/src/core/hle/service/npns/npns.cpp +++ b/src/core/hle/service/npns/npns.cpp @@ -4,8 +4,8 @@ #include <memory> #include "core/hle/service/npns/npns.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" namespace Service::NPNS { @@ -94,9 +94,12 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<NPNS_S>(system)->InstallAsService(sm); - std::make_shared<NPNS_U>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("npns:s", std::make_shared<NPNS_S>(system)); + server_manager->RegisterNamedService("npns:u", std::make_shared<NPNS_U>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::NPNS diff --git a/src/core/hle/service/npns/npns.h b/src/core/hle/service/npns/npns.h index 84e6ec437..0019fca76 100644 --- a/src/core/hle/service/npns/npns.h +++ b/src/core/hle/service/npns/npns.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::NPNS { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::NPNS diff --git a/src/core/hle/service/ns/errors.h b/src/core/hle/service/ns/errors.h index 8a7621798..16d2ea6f7 100644 --- a/src/core/hle/service/ns/errors.h +++ b/src/core/hle/service/ns/errors.h @@ -7,5 +7,6 @@ namespace Service::NS { -constexpr Result ERR_APPLICATION_LANGUAGE_NOT_FOUND{ErrorModule::NS, 300}; -}
\ No newline at end of file +constexpr Result ResultApplicationLanguageNotFound{ErrorModule::NS, 300}; + +} diff --git a/src/core/hle/service/ns/iplatform_service_manager.cpp b/src/core/hle/service/ns/iplatform_service_manager.cpp index 1fab2f0dd..cd2705881 100644 --- a/src/core/hle/service/ns/iplatform_service_manager.cpp +++ b/src/core/hle/service/ns/iplatform_service_manager.cpp @@ -15,11 +15,11 @@ #include "core/file_sys/registered_cache.h" #include "core/file_sys/romfs.h" #include "core/file_sys/system_archive/system_archive.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_shared_memory.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/physical_memory.h" #include "core/hle/service/filesystem/filesystem.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ns/iplatform_service_manager.h" namespace Service::NS { @@ -208,7 +208,7 @@ IPlatformServiceManager::IPlatformServiceManager(Core::System& system_, const ch IPlatformServiceManager::~IPlatformServiceManager() = default; -void IPlatformServiceManager::RequestLoad(Kernel::HLERequestContext& ctx) { +void IPlatformServiceManager::RequestLoad(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u32 shared_font_type{rp.Pop<u32>()}; // Games don't call this so all fonts should be loaded @@ -218,7 +218,7 @@ void IPlatformServiceManager::RequestLoad(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IPlatformServiceManager::GetLoadState(Kernel::HLERequestContext& ctx) { +void IPlatformServiceManager::GetLoadState(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u32 font_id{rp.Pop<u32>()}; LOG_DEBUG(Service_NS, "called, font_id={}", font_id); @@ -228,7 +228,7 @@ void IPlatformServiceManager::GetLoadState(Kernel::HLERequestContext& ctx) { rb.Push<u32>(static_cast<u32>(LoadState::Done)); } -void IPlatformServiceManager::GetSize(Kernel::HLERequestContext& ctx) { +void IPlatformServiceManager::GetSize(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u32 font_id{rp.Pop<u32>()}; LOG_DEBUG(Service_NS, "called, font_id={}", font_id); @@ -238,7 +238,7 @@ void IPlatformServiceManager::GetSize(Kernel::HLERequestContext& ctx) { rb.Push<u32>(impl->GetSharedFontRegion(font_id).size); } -void IPlatformServiceManager::GetSharedMemoryAddressOffset(Kernel::HLERequestContext& ctx) { +void IPlatformServiceManager::GetSharedMemoryAddressOffset(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u32 font_id{rp.Pop<u32>()}; LOG_DEBUG(Service_NS, "called, font_id={}", font_id); @@ -248,7 +248,7 @@ void IPlatformServiceManager::GetSharedMemoryAddressOffset(Kernel::HLERequestCon rb.Push<u32>(impl->GetSharedFontRegion(font_id).offset); } -void IPlatformServiceManager::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) { +void IPlatformServiceManager::GetSharedMemoryNativeHandle(HLERequestContext& ctx) { // Map backing memory for the font data LOG_DEBUG(Service_NS, "called"); @@ -261,7 +261,7 @@ void IPlatformServiceManager::GetSharedMemoryNativeHandle(Kernel::HLERequestCont rb.PushCopyObjects(&kernel.GetFontSharedMem()); } -void IPlatformServiceManager::GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx) { +void IPlatformServiceManager::GetSharedFontInOrderOfPriority(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 language_code{rp.Pop<u64>()}; // TODO(ogniK): Find out what this is used for LOG_DEBUG(Service_NS, "called, language_code={:X}", language_code); diff --git a/src/core/hle/service/ns/iplatform_service_manager.h b/src/core/hle/service/ns/iplatform_service_manager.h index ed6eda89f..03071e02b 100644 --- a/src/core/hle/service/ns/iplatform_service_manager.h +++ b/src/core/hle/service/ns/iplatform_service_manager.h @@ -42,12 +42,12 @@ public: ~IPlatformServiceManager() override; private: - void RequestLoad(Kernel::HLERequestContext& ctx); - void GetLoadState(Kernel::HLERequestContext& ctx); - void GetSize(Kernel::HLERequestContext& ctx); - void GetSharedMemoryAddressOffset(Kernel::HLERequestContext& ctx); - void GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx); - void GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx); + void RequestLoad(HLERequestContext& ctx); + void GetLoadState(HLERequestContext& ctx); + void GetSize(HLERequestContext& ctx); + void GetSharedMemoryAddressOffset(HLERequestContext& ctx); + void GetSharedMemoryNativeHandle(HLERequestContext& ctx); + void GetSharedFontInOrderOfPriority(HLERequestContext& ctx); struct Impl; std::unique_ptr<Impl> impl; diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index e53bdde52..376067a95 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp @@ -7,13 +7,14 @@ #include "core/file_sys/control_metadata.h" #include "core/file_sys/patch_manager.h" #include "core/file_sys/vfs.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/glue/glue_manager.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ns/errors.h" #include "core/hle/service/ns/iplatform_service_manager.h" #include "core/hle/service/ns/language.h" #include "core/hle/service/ns/ns.h" #include "core/hle/service/ns/pdm_qry.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/set/set.h" namespace Service::NS { @@ -328,7 +329,7 @@ IApplicationManagerInterface::IApplicationManagerInterface(Core::System& system_ IApplicationManagerInterface::~IApplicationManagerInterface() = default; -void IApplicationManagerInterface::GetApplicationControlData(Kernel::HLERequestContext& ctx) { +void IApplicationManagerInterface::GetApplicationControlData(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto flag = rp.PopRaw<u64>(); LOG_DEBUG(Service_NS, "called with flag={:016X}", flag); @@ -387,7 +388,7 @@ void IApplicationManagerInterface::GetApplicationControlData(Kernel::HLERequestC rb.Push<u32>(static_cast<u32>(out.size())); } -void IApplicationManagerInterface::GetApplicationDesiredLanguage(Kernel::HLERequestContext& ctx) { +void IApplicationManagerInterface::GetApplicationDesiredLanguage(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto supported_languages = rp.Pop<u32>(); @@ -415,14 +416,14 @@ ResultVal<u8> IApplicationManagerInterface::GetApplicationDesiredLanguage( if (application_language == std::nullopt) { LOG_ERROR(Service_NS, "Could not convert application language! language_code={}", language_code); - return ERR_APPLICATION_LANGUAGE_NOT_FOUND; + return Service::NS::ResultApplicationLanguageNotFound; } const auto priority_list = GetApplicationLanguagePriorityList(*application_language); if (!priority_list) { LOG_ERROR(Service_NS, "Could not find application language priorities! application_language={}", *application_language); - return ERR_APPLICATION_LANGUAGE_NOT_FOUND; + return Service::NS::ResultApplicationLanguageNotFound; } // Try to find a valid language. @@ -435,11 +436,11 @@ ResultVal<u8> IApplicationManagerInterface::GetApplicationDesiredLanguage( LOG_ERROR(Service_NS, "Could not find a valid language! supported_languages={:08X}", supported_languages); - return ERR_APPLICATION_LANGUAGE_NOT_FOUND; + return Service::NS::ResultApplicationLanguageNotFound; } void IApplicationManagerInterface::ConvertApplicationLanguageToLanguageCode( - Kernel::HLERequestContext& ctx) { + HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto application_language = rp.Pop<u8>(); @@ -460,7 +461,7 @@ ResultVal<u64> IApplicationManagerInterface::ConvertApplicationLanguageToLanguag ConvertToLanguageCode(static_cast<ApplicationLanguage>(application_language)); if (language_code == std::nullopt) { LOG_ERROR(Service_NS, "Language not found! application_language={}", application_language); - return ERR_APPLICATION_LANGUAGE_NOT_FOUND; + return Service::NS::ResultApplicationLanguageNotFound; } return static_cast<u64>(*language_code); @@ -603,8 +604,7 @@ IReadOnlyApplicationControlDataInterface::IReadOnlyApplicationControlDataInterfa IReadOnlyApplicationControlDataInterface::~IReadOnlyApplicationControlDataInterface() = default; -void IReadOnlyApplicationControlDataInterface::GetApplicationControlData( - Kernel::HLERequestContext& ctx) { +void IReadOnlyApplicationControlDataInterface::GetApplicationControlData(HLERequestContext& ctx) { enum class ApplicationControlSource : u8 { CacheOnly, Storage, @@ -752,7 +752,7 @@ public: } private: - void OpenSystemUpdateControl(Kernel::HLERequestContext& ctx) { + void OpenSystemUpdateControl(HLERequestContext& ctx) { LOG_DEBUG(Service_NS, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -776,7 +776,7 @@ public: } private: - void NeedsUpdateVulnerability(Kernel::HLERequestContext& ctx) { + void NeedsUpdateVulnerability(HLERequestContext& ctx) { LOG_WARNING(Service_NS, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -785,23 +785,26 @@ private: } }; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - - std::make_shared<NS>("ns:am2", system)->InstallAsService(service_manager); - std::make_shared<NS>("ns:ec", system)->InstallAsService(service_manager); - std::make_shared<NS>("ns:rid", system)->InstallAsService(service_manager); - std::make_shared<NS>("ns:rt", system)->InstallAsService(service_manager); - std::make_shared<NS>("ns:web", system)->InstallAsService(service_manager); - std::make_shared<NS>("ns:ro", system)->InstallAsService(service_manager); - - std::make_shared<NS_DEV>(system)->InstallAsService(service_manager); - std::make_shared<NS_SU>(system)->InstallAsService(service_manager); - std::make_shared<NS_VM>(system)->InstallAsService(service_manager); - - std::make_shared<PDM_QRY>(system)->InstallAsService(service_manager); - - std::make_shared<IPlatformServiceManager>(system, "pl:s")->InstallAsService(service_manager); - std::make_shared<IPlatformServiceManager>(system, "pl:u")->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("ns:am2", std::make_shared<NS>("ns:am2", system)); + server_manager->RegisterNamedService("ns:ec", std::make_shared<NS>("ns:ec", system)); + server_manager->RegisterNamedService("ns:rid", std::make_shared<NS>("ns:rid", system)); + server_manager->RegisterNamedService("ns:rt", std::make_shared<NS>("ns:rt", system)); + server_manager->RegisterNamedService("ns:web", std::make_shared<NS>("ns:web", system)); + server_manager->RegisterNamedService("ns:ro", std::make_shared<NS>("ns:ro", system)); + + server_manager->RegisterNamedService("ns:dev", std::make_shared<NS_DEV>(system)); + server_manager->RegisterNamedService("ns:su", std::make_shared<NS_SU>(system)); + server_manager->RegisterNamedService("ns:vm", std::make_shared<NS_VM>(system)); + server_manager->RegisterNamedService("pdm:qry", std::make_shared<PDM_QRY>(system)); + + server_manager->RegisterNamedService("pl:s", + std::make_shared<IPlatformServiceManager>(system, "pl:s")); + server_manager->RegisterNamedService("pl:u", + std::make_shared<IPlatformServiceManager>(system, "pl:u")); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::NS diff --git a/src/core/hle/service/ns/ns.h b/src/core/hle/service/ns/ns.h index 9c18e935c..203388e1f 100644 --- a/src/core/hle/service/ns/ns.h +++ b/src/core/hle/service/ns/ns.h @@ -32,9 +32,9 @@ public: ResultVal<u64> ConvertApplicationLanguageToLanguageCode(u8 application_language); private: - void GetApplicationControlData(Kernel::HLERequestContext& ctx); - void GetApplicationDesiredLanguage(Kernel::HLERequestContext& ctx); - void ConvertApplicationLanguageToLanguageCode(Kernel::HLERequestContext& ctx); + void GetApplicationControlData(HLERequestContext& ctx); + void GetApplicationDesiredLanguage(HLERequestContext& ctx); + void ConvertApplicationLanguageToLanguageCode(HLERequestContext& ctx); }; class IApplicationVersionInterface final : public ServiceFramework<IApplicationVersionInterface> { @@ -80,7 +80,7 @@ public: ~IReadOnlyApplicationControlDataInterface() override; private: - void GetApplicationControlData(Kernel::HLERequestContext& ctx); + void GetApplicationControlData(HLERequestContext& ctx); }; class NS final : public ServiceFramework<NS> { @@ -92,7 +92,7 @@ public: private: template <typename T, typename... Args> - void PushInterface(Kernel::HLERequestContext& ctx) { + void PushInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NS, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -100,7 +100,7 @@ private: rb.PushIpcInterface<T>(system); } - void PushIApplicationManagerInterface(Kernel::HLERequestContext& ctx) { + void PushIApplicationManagerInterface(HLERequestContext& ctx) { LOG_DEBUG(Service_NS, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -110,15 +110,14 @@ private: template <typename T, typename... Args> std::shared_ptr<T> GetInterface(Args&&... args) const { - static_assert(std::is_base_of_v<Kernel::SessionRequestHandler, T>, + static_assert(std::is_base_of_v<SessionRequestHandler, T>, "Not a base of ServiceFrameworkBase"); return std::make_shared<T>(std::forward<Args>(args)...); } }; -/// Registers all NS services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace NS } // namespace Service diff --git a/src/core/hle/service/ns/pdm_qry.cpp b/src/core/hle/service/ns/pdm_qry.cpp index aac8f573f..ce0ee30e0 100644 --- a/src/core/hle/service/ns/pdm_qry.cpp +++ b/src/core/hle/service/ns/pdm_qry.cpp @@ -5,7 +5,7 @@ #include "common/logging/log.h" #include "common/uuid.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ns/pdm_qry.h" #include "core/hle/service/service.h" @@ -42,7 +42,7 @@ PDM_QRY::PDM_QRY(Core::System& system_) : ServiceFramework{system_, "pdm:qry"} { PDM_QRY::~PDM_QRY() = default; -void PDM_QRY::QueryPlayStatisticsByApplicationIdAndUserAccountId(Kernel::HLERequestContext& ctx) { +void PDM_QRY::QueryPlayStatisticsByApplicationIdAndUserAccountId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto unknown = rp.Pop<bool>(); rp.Pop<u8>(); // Padding diff --git a/src/core/hle/service/ns/pdm_qry.h b/src/core/hle/service/ns/pdm_qry.h index abcc3bef3..c98e01660 100644 --- a/src/core/hle/service/ns/pdm_qry.h +++ b/src/core/hle/service/ns/pdm_qry.h @@ -26,7 +26,7 @@ public: ~PDM_QRY() override; private: - void QueryPlayStatisticsByApplicationIdAndUserAccountId(Kernel::HLERequestContext& ctx); + void QueryPlayStatisticsByApplicationIdAndUserAccountId(HLERequestContext& ctx); }; } // namespace Service::NS diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h index 81bd7960a..bcd0e3ed5 100644 --- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h +++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h @@ -8,8 +8,8 @@ #include "common/common_types.h" #include "common/math_util.h" #include "core/hle/service/nvdrv/devices/nvdevice.h" -#include "core/hle/service/nvflinger/buffer_transform_flags.h" -#include "core/hle/service/nvflinger/pixel_format.h" +#include "core/hle/service/nvnflinger/buffer_transform_flags.h" +#include "core/hle/service/nvnflinger/pixel_format.h" namespace Service::Nvidia::NvCore { class Container; diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp index 52d27e755..3d774eec4 100644 --- a/src/core/hle/service/nvdrv/nvdrv.cpp +++ b/src/core/hle/service/nvdrv/nvdrv.cpp @@ -6,8 +6,8 @@ #include <fmt/format.h> #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nvdrv/core/container.h" #include "core/hle/service/nvdrv/devices/nvdevice.h" #include "core/hle/service/nvdrv/devices/nvdisp_disp0.h" @@ -23,7 +23,8 @@ #include "core/hle/service/nvdrv/nvdrv.h" #include "core/hle/service/nvdrv/nvdrv_interface.h" #include "core/hle/service/nvdrv/nvmemp.h" -#include "core/hle/service/nvflinger/nvflinger.h" +#include "core/hle/service/nvnflinger/nvnflinger.h" +#include "core/hle/service/server_manager.h" #include "video_core/gpu.h" namespace Service::Nvidia { @@ -41,15 +42,19 @@ void EventInterface::FreeEvent(Kernel::KEvent* event) { module.service_context.CloseEvent(event); } -void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger, - Core::System& system) { - auto module_ = std::make_shared<Module>(system); - std::make_shared<NVDRV>(system, module_, "nvdrv")->InstallAsService(service_manager); - std::make_shared<NVDRV>(system, module_, "nvdrv:a")->InstallAsService(service_manager); - std::make_shared<NVDRV>(system, module_, "nvdrv:s")->InstallAsService(service_manager); - std::make_shared<NVDRV>(system, module_, "nvdrv:t")->InstallAsService(service_manager); - std::make_shared<NVMEMP>(system)->InstallAsService(service_manager); - nvflinger.SetNVDrvInstance(module_); +void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + auto module = std::make_shared<Module>(system); + server_manager->RegisterNamedService("nvdrv", std::make_shared<NVDRV>(system, module, "nvdrv")); + server_manager->RegisterNamedService("nvdrv:a", + std::make_shared<NVDRV>(system, module, "nvdrv:a")); + server_manager->RegisterNamedService("nvdrv:s", + std::make_shared<NVDRV>(system, module, "nvdrv:s")); + server_manager->RegisterNamedService("nvdrv:t", + std::make_shared<NVDRV>(system, module, "nvdrv:t")); + server_manager->RegisterNamedService("nvmemp", std::make_shared<NVMEMP>(system)); + nvnflinger.SetNVDrvInstance(module); + ServerManager::RunServer(std::move(server_manager)); } Module::Module(Core::System& system) diff --git a/src/core/hle/service/nvdrv/nvdrv.h b/src/core/hle/service/nvdrv/nvdrv.h index b09b6e585..668be742b 100644 --- a/src/core/hle/service/nvdrv/nvdrv.h +++ b/src/core/hle/service/nvdrv/nvdrv.h @@ -16,7 +16,7 @@ #include "core/hle/service/kernel_helpers.h" #include "core/hle/service/nvdrv/core/container.h" #include "core/hle/service/nvdrv/nvdata.h" -#include "core/hle/service/nvflinger/ui/fence.h" +#include "core/hle/service/nvnflinger/ui/fence.h" #include "core/hle/service/service.h" namespace Core { @@ -27,8 +27,8 @@ namespace Kernel { class KEvent; } -namespace Service::NVFlinger { -class NVFlinger; +namespace Service::Nvnflinger { +class Nvnflinger; } namespace Service::Nvidia { @@ -95,7 +95,7 @@ public: private: friend class EventInterface; - friend class Service::NVFlinger::NVFlinger; + friend class Service::Nvnflinger::Nvnflinger; /// Manages syncpoints on the host NvCore::Container container; @@ -114,8 +114,6 @@ private: std::unordered_map<std::string, std::function<FilesContainerType::iterator(DeviceFD)>> builders; }; -/// Registers all NVDRV services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger, - Core::System& system); +void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system); } // namespace Service::Nvidia diff --git a/src/core/hle/service/nvdrv/nvdrv_interface.cpp b/src/core/hle/service/nvdrv/nvdrv_interface.cpp index edbdfee43..d010a1e03 100644 --- a/src/core/hle/service/nvdrv/nvdrv_interface.cpp +++ b/src/core/hle/service/nvdrv/nvdrv_interface.cpp @@ -5,16 +5,16 @@ #include <cinttypes> #include "common/logging/log.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" #include "core/hle/kernel/k_readable_event.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nvdrv/nvdata.h" #include "core/hle/service/nvdrv/nvdrv.h" #include "core/hle/service/nvdrv/nvdrv_interface.h" namespace Service::Nvidia { -void NVDRV::Open(Kernel::HLERequestContext& ctx) { +void NVDRV::Open(HLERequestContext& ctx) { LOG_DEBUG(Service_NVDRV, "called"); IPC::ResponseBuilder rb{ctx, 4}; rb.Push(ResultSuccess); @@ -44,13 +44,13 @@ void NVDRV::Open(Kernel::HLERequestContext& ctx) { rb.PushEnum(fd != INVALID_NVDRV_FD ? NvResult::Success : NvResult::FileOperationFailed); } -void NVDRV::ServiceError(Kernel::HLERequestContext& ctx, NvResult result) { +void NVDRV::ServiceError(HLERequestContext& ctx, NvResult result) { IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); rb.PushEnum(result); } -void NVDRV::Ioctl1(Kernel::HLERequestContext& ctx) { +void NVDRV::Ioctl1(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto fd = rp.Pop<DeviceFD>(); const auto command = rp.PopRaw<Ioctl>(); @@ -76,7 +76,7 @@ void NVDRV::Ioctl1(Kernel::HLERequestContext& ctx) { rb.PushEnum(nv_result); } -void NVDRV::Ioctl2(Kernel::HLERequestContext& ctx) { +void NVDRV::Ioctl2(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto fd = rp.Pop<DeviceFD>(); const auto command = rp.PopRaw<Ioctl>(); @@ -103,7 +103,7 @@ void NVDRV::Ioctl2(Kernel::HLERequestContext& ctx) { rb.PushEnum(nv_result); } -void NVDRV::Ioctl3(Kernel::HLERequestContext& ctx) { +void NVDRV::Ioctl3(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto fd = rp.Pop<DeviceFD>(); const auto command = rp.PopRaw<Ioctl>(); @@ -131,7 +131,7 @@ void NVDRV::Ioctl3(Kernel::HLERequestContext& ctx) { rb.PushEnum(nv_result); } -void NVDRV::Close(Kernel::HLERequestContext& ctx) { +void NVDRV::Close(HLERequestContext& ctx) { LOG_DEBUG(Service_NVDRV, "called"); if (!is_initialized) { @@ -149,7 +149,7 @@ void NVDRV::Close(Kernel::HLERequestContext& ctx) { rb.PushEnum(result); } -void NVDRV::Initialize(Kernel::HLERequestContext& ctx) { +void NVDRV::Initialize(HLERequestContext& ctx) { LOG_WARNING(Service_NVDRV, "(STUBBED) called"); is_initialized = true; @@ -159,7 +159,7 @@ void NVDRV::Initialize(Kernel::HLERequestContext& ctx) { rb.PushEnum(NvResult::Success); } -void NVDRV::QueryEvent(Kernel::HLERequestContext& ctx) { +void NVDRV::QueryEvent(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto fd = rp.Pop<DeviceFD>(); const auto event_id = rp.Pop<u32>(); @@ -187,7 +187,7 @@ void NVDRV::QueryEvent(Kernel::HLERequestContext& ctx) { } } -void NVDRV::SetAruid(Kernel::HLERequestContext& ctx) { +void NVDRV::SetAruid(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; pid = rp.Pop<u64>(); LOG_WARNING(Service_NVDRV, "(STUBBED) called, pid=0x{:X}", pid); @@ -197,14 +197,14 @@ void NVDRV::SetAruid(Kernel::HLERequestContext& ctx) { rb.PushEnum(NvResult::Success); } -void NVDRV::SetGraphicsFirmwareMemoryMarginEnabled(Kernel::HLERequestContext& ctx) { +void NVDRV::SetGraphicsFirmwareMemoryMarginEnabled(HLERequestContext& ctx) { LOG_WARNING(Service_NVDRV, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void NVDRV::GetStatus(Kernel::HLERequestContext& ctx) { +void NVDRV::GetStatus(HLERequestContext& ctx) { LOG_WARNING(Service_NVDRV, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -212,7 +212,7 @@ void NVDRV::GetStatus(Kernel::HLERequestContext& ctx) { rb.PushEnum(NvResult::Success); } -void NVDRV::DumpGraphicsMemoryInfo(Kernel::HLERequestContext& ctx) { +void NVDRV::DumpGraphicsMemoryInfo(HLERequestContext& ctx) { // According to SwitchBrew, this has no inputs and no outputs, so effectively does nothing on // retail hardware. LOG_DEBUG(Service_NVDRV, "called"); @@ -222,7 +222,7 @@ void NVDRV::DumpGraphicsMemoryInfo(Kernel::HLERequestContext& ctx) { } NVDRV::NVDRV(Core::System& system_, std::shared_ptr<Module> nvdrv_, const char* name) - : ServiceFramework{system_, name, ServiceThreadType::CreateNew}, nvdrv{std::move(nvdrv_)} { + : ServiceFramework{system_, name}, nvdrv{std::move(nvdrv_)} { static const FunctionInfo functions[] = { {0, &NVDRV::Open, "Open"}, {1, &NVDRV::Ioctl1, "Ioctl"}, diff --git a/src/core/hle/service/nvdrv/nvdrv_interface.h b/src/core/hle/service/nvdrv/nvdrv_interface.h index 5ac06ee30..881ea1a6b 100644 --- a/src/core/hle/service/nvdrv/nvdrv_interface.h +++ b/src/core/hle/service/nvdrv/nvdrv_interface.h @@ -15,19 +15,19 @@ public: ~NVDRV() override; private: - void Open(Kernel::HLERequestContext& ctx); - void Ioctl1(Kernel::HLERequestContext& ctx); - void Ioctl2(Kernel::HLERequestContext& ctx); - void Ioctl3(Kernel::HLERequestContext& ctx); - void Close(Kernel::HLERequestContext& ctx); - void Initialize(Kernel::HLERequestContext& ctx); - void QueryEvent(Kernel::HLERequestContext& ctx); - void SetAruid(Kernel::HLERequestContext& ctx); - void SetGraphicsFirmwareMemoryMarginEnabled(Kernel::HLERequestContext& ctx); - void GetStatus(Kernel::HLERequestContext& ctx); - void DumpGraphicsMemoryInfo(Kernel::HLERequestContext& ctx); - - void ServiceError(Kernel::HLERequestContext& ctx, NvResult result); + void Open(HLERequestContext& ctx); + void Ioctl1(HLERequestContext& ctx); + void Ioctl2(HLERequestContext& ctx); + void Ioctl3(HLERequestContext& ctx); + void Close(HLERequestContext& ctx); + void Initialize(HLERequestContext& ctx); + void QueryEvent(HLERequestContext& ctx); + void SetAruid(HLERequestContext& ctx); + void SetGraphicsFirmwareMemoryMarginEnabled(HLERequestContext& ctx); + void GetStatus(HLERequestContext& ctx); + void DumpGraphicsMemoryInfo(HLERequestContext& ctx); + + void ServiceError(HLERequestContext& ctx, NvResult result); std::shared_ptr<Module> nvdrv; diff --git a/src/core/hle/service/nvdrv/nvmemp.cpp b/src/core/hle/service/nvdrv/nvmemp.cpp index e433580b1..fc10f6406 100644 --- a/src/core/hle/service/nvdrv/nvmemp.cpp +++ b/src/core/hle/service/nvdrv/nvmemp.cpp @@ -17,11 +17,11 @@ NVMEMP::NVMEMP(Core::System& system_) : ServiceFramework{system_, "nvmemp"} { NVMEMP::~NVMEMP() = default; -void NVMEMP::Open(Kernel::HLERequestContext& ctx) { +void NVMEMP::Open(HLERequestContext& ctx) { UNIMPLEMENTED(); } -void NVMEMP::GetAruid(Kernel::HLERequestContext& ctx) { +void NVMEMP::GetAruid(HLERequestContext& ctx) { UNIMPLEMENTED(); } diff --git a/src/core/hle/service/nvdrv/nvmemp.h b/src/core/hle/service/nvdrv/nvmemp.h index 3d4276327..85e3053a8 100644 --- a/src/core/hle/service/nvdrv/nvmemp.h +++ b/src/core/hle/service/nvdrv/nvmemp.h @@ -17,8 +17,8 @@ public: ~NVMEMP() override; private: - void Open(Kernel::HLERequestContext& ctx); - void GetAruid(Kernel::HLERequestContext& ctx); + void Open(HLERequestContext& ctx); + void GetAruid(HLERequestContext& ctx); }; } // namespace Service::Nvidia diff --git a/src/core/hle/service/nvflinger/binder.h b/src/core/hle/service/nvnflinger/binder.h index 157333ff8..aef1477e3 100644 --- a/src/core/hle/service/nvflinger/binder.h +++ b/src/core/hle/service/nvnflinger/binder.h @@ -9,10 +9,13 @@ #include "common/common_types.h" namespace Kernel { -class HLERequestContext; class KReadableEvent; } // namespace Kernel +namespace Service { +class HLERequestContext; +} + namespace Service::android { enum class TransactionId { @@ -35,8 +38,7 @@ enum class TransactionId { class IBinder { public: virtual ~IBinder() = default; - virtual void Transact(Kernel::HLERequestContext& ctx, android::TransactionId code, - u32 flags) = 0; + virtual void Transact(HLERequestContext& ctx, android::TransactionId code, u32 flags) = 0; virtual Kernel::KReadableEvent& GetNativeHandle() = 0; }; diff --git a/src/core/hle/service/nvflinger/buffer_item.h b/src/core/hle/service/nvnflinger/buffer_item.h index f73dec4f1..7fd808f54 100644 --- a/src/core/hle/service/nvflinger/buffer_item.h +++ b/src/core/hle/service/nvnflinger/buffer_item.h @@ -10,8 +10,8 @@ #include "common/common_types.h" #include "common/math_util.h" -#include "core/hle/service/nvflinger/ui/fence.h" -#include "core/hle/service/nvflinger/window.h" +#include "core/hle/service/nvnflinger/ui/fence.h" +#include "core/hle/service/nvnflinger/window.h" namespace Service::android { diff --git a/src/core/hle/service/nvflinger/buffer_item_consumer.cpp b/src/core/hle/service/nvnflinger/buffer_item_consumer.cpp index 152bb5bdf..cf151ea3a 100644 --- a/src/core/hle/service/nvflinger/buffer_item_consumer.cpp +++ b/src/core/hle/service/nvnflinger/buffer_item_consumer.cpp @@ -6,9 +6,9 @@ #include "common/assert.h" #include "common/logging/log.h" -#include "core/hle/service/nvflinger/buffer_item.h" -#include "core/hle/service/nvflinger/buffer_item_consumer.h" -#include "core/hle/service/nvflinger/buffer_queue_consumer.h" +#include "core/hle/service/nvnflinger/buffer_item.h" +#include "core/hle/service/nvnflinger/buffer_item_consumer.h" +#include "core/hle/service/nvnflinger/buffer_queue_consumer.h" namespace Service::android { @@ -25,7 +25,7 @@ Status BufferItemConsumer::AcquireBuffer(BufferItem* item, std::chrono::nanoseco if (const auto status = AcquireBufferLocked(item, present_when); status != Status::NoError) { if (status != Status::NoBufferAvailable) { - LOG_ERROR(Service_NVFlinger, "Failed to acquire buffer: {}", status); + LOG_ERROR(Service_Nvnflinger, "Failed to acquire buffer: {}", status); } return status; } @@ -44,12 +44,12 @@ Status BufferItemConsumer::ReleaseBuffer(const BufferItem& item, const Fence& re if (const auto status = AddReleaseFenceLocked(item.buf, item.graphic_buffer, release_fence); status != Status::NoError) { - LOG_ERROR(Service_NVFlinger, "Failed to add fence: {}", status); + LOG_ERROR(Service_Nvnflinger, "Failed to add fence: {}", status); } if (const auto status = ReleaseBufferLocked(item.buf, item.graphic_buffer); status != Status::NoError) { - LOG_WARNING(Service_NVFlinger, "Failed to release buffer: {}", status); + LOG_WARNING(Service_Nvnflinger, "Failed to release buffer: {}", status); return status; } diff --git a/src/core/hle/service/nvflinger/buffer_item_consumer.h b/src/core/hle/service/nvnflinger/buffer_item_consumer.h index a5c655d9e..e0c6b3604 100644 --- a/src/core/hle/service/nvflinger/buffer_item_consumer.h +++ b/src/core/hle/service/nvnflinger/buffer_item_consumer.h @@ -10,8 +10,8 @@ #include <memory> #include "common/common_types.h" -#include "core/hle/service/nvflinger/consumer_base.h" -#include "core/hle/service/nvflinger/status.h" +#include "core/hle/service/nvnflinger/consumer_base.h" +#include "core/hle/service/nvnflinger/status.h" namespace Service::android { diff --git a/src/core/hle/service/nvflinger/buffer_queue_consumer.cpp b/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp index 0767e548d..51291539d 100644 --- a/src/core/hle/service/nvflinger/buffer_queue_consumer.cpp +++ b/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp @@ -6,11 +6,11 @@ #include "common/logging/log.h" #include "core/hle/service/nvdrv/core/nvmap.h" -#include "core/hle/service/nvflinger/buffer_item.h" -#include "core/hle/service/nvflinger/buffer_queue_consumer.h" -#include "core/hle/service/nvflinger/buffer_queue_core.h" -#include "core/hle/service/nvflinger/producer_listener.h" -#include "core/hle/service/nvflinger/ui/graphic_buffer.h" +#include "core/hle/service/nvnflinger/buffer_item.h" +#include "core/hle/service/nvnflinger/buffer_queue_consumer.h" +#include "core/hle/service/nvnflinger/buffer_queue_core.h" +#include "core/hle/service/nvnflinger/producer_listener.h" +#include "core/hle/service/nvnflinger/ui/graphic_buffer.h" namespace Service::android { @@ -31,7 +31,7 @@ Status BufferQueueConsumer::AcquireBuffer(BufferItem* out_buffer, }))}; if (num_acquired_buffers >= core->max_acquired_buffer_count + 1) { - LOG_ERROR(Service_NVFlinger, "max acquired buffer count reached: {} (max {})", + LOG_ERROR(Service_Nvnflinger, "max acquired buffer count reached: {} (max {})", num_acquired_buffers, core->max_acquired_buffer_count); return Status::InvalidOperation; } @@ -57,12 +57,12 @@ Status BufferQueueConsumer::AcquireBuffer(BufferItem* out_buffer, if (desired_present < expected_present.count() - MAX_REASONABLE_NSEC || desired_present > expected_present.count()) { // This buffer is set to display in the near future, or desired_present is garbage. - LOG_DEBUG(Service_NVFlinger, "nodrop desire={} expect={}", desired_present, + LOG_DEBUG(Service_Nvnflinger, "nodrop desire={} expect={}", desired_present, expected_present.count()); break; } - LOG_DEBUG(Service_NVFlinger, "drop desire={} expect={} size={}", desired_present, + LOG_DEBUG(Service_Nvnflinger, "drop desire={} expect={} size={}", desired_present, expected_present.count(), core->queue.size()); if (core->StillTracking(*front)) { @@ -78,19 +78,19 @@ Status BufferQueueConsumer::AcquireBuffer(BufferItem* out_buffer, const auto desired_present = front->timestamp; if (desired_present > expected_present.count() && desired_present < expected_present.count() + MAX_REASONABLE_NSEC) { - LOG_DEBUG(Service_NVFlinger, "defer desire={} expect={}", desired_present, + LOG_DEBUG(Service_Nvnflinger, "defer desire={} expect={}", desired_present, expected_present.count()); return Status::PresentLater; } - LOG_DEBUG(Service_NVFlinger, "accept desire={} expect={}", desired_present, + LOG_DEBUG(Service_Nvnflinger, "accept desire={} expect={}", desired_present, expected_present.count()); } const auto slot = front->slot; *out_buffer = *front; - LOG_DEBUG(Service_NVFlinger, "acquiring slot={}", slot); + LOG_DEBUG(Service_Nvnflinger, "acquiring slot={}", slot); // If the buffer has previously been acquired by the consumer, set graphic_buffer to nullptr to // avoid unnecessarily remapping this buffer on the consumer side. @@ -109,7 +109,7 @@ Status BufferQueueConsumer::AcquireBuffer(BufferItem* out_buffer, Status BufferQueueConsumer::ReleaseBuffer(s32 slot, u64 frame_number, const Fence& release_fence) { if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) { - LOG_ERROR(Service_NVFlinger, "slot {} out of range", slot); + LOG_ERROR(Service_Nvnflinger, "slot {} out of range", slot); return Status::BadValue; } @@ -127,7 +127,7 @@ Status BufferQueueConsumer::ReleaseBuffer(s32 slot, u64 frame_number, const Fenc auto current(core->queue.begin()); while (current != core->queue.end()) { if (current->slot == slot) { - LOG_ERROR(Service_NVFlinger, "buffer slot {} pending release is currently queued", + LOG_ERROR(Service_Nvnflinger, "buffer slot {} pending release is currently queued", slot); return Status::BadValue; } @@ -140,7 +140,7 @@ Status BufferQueueConsumer::ReleaseBuffer(s32 slot, u64 frame_number, const Fenc listener = core->connected_producer_listener; - LOG_DEBUG(Service_NVFlinger, "releasing slot {}", slot); + LOG_DEBUG(Service_Nvnflinger, "releasing slot {}", slot); core->SignalDequeueCondition(); } @@ -156,16 +156,16 @@ Status BufferQueueConsumer::ReleaseBuffer(s32 slot, u64 frame_number, const Fenc Status BufferQueueConsumer::Connect(std::shared_ptr<IConsumerListener> consumer_listener, bool controlled_by_app) { if (consumer_listener == nullptr) { - LOG_ERROR(Service_NVFlinger, "consumer_listener may not be nullptr"); + LOG_ERROR(Service_Nvnflinger, "consumer_listener may not be nullptr"); return Status::BadValue; } - LOG_DEBUG(Service_NVFlinger, "controlled_by_app={}", controlled_by_app); + LOG_DEBUG(Service_Nvnflinger, "controlled_by_app={}", controlled_by_app); std::scoped_lock lock{core->mutex}; if (core->is_abandoned) { - LOG_ERROR(Service_NVFlinger, "BufferQueue has been abandoned"); + LOG_ERROR(Service_Nvnflinger, "BufferQueue has been abandoned"); return Status::NoInit; } @@ -177,14 +177,14 @@ Status BufferQueueConsumer::Connect(std::shared_ptr<IConsumerListener> consumer_ Status BufferQueueConsumer::GetReleasedBuffers(u64* out_slot_mask) { if (out_slot_mask == nullptr) { - LOG_ERROR(Service_NVFlinger, "out_slot_mask may not be nullptr"); + LOG_ERROR(Service_Nvnflinger, "out_slot_mask may not be nullptr"); return Status::BadValue; } std::scoped_lock lock{core->mutex}; if (core->is_abandoned) { - LOG_ERROR(Service_NVFlinger, "BufferQueue has been abandoned"); + LOG_ERROR(Service_Nvnflinger, "BufferQueue has been abandoned"); return Status::NoInit; } @@ -205,7 +205,7 @@ Status BufferQueueConsumer::GetReleasedBuffers(u64* out_slot_mask) { ++current; } - LOG_DEBUG(Service_NVFlinger, "returning mask {}", mask); + LOG_DEBUG(Service_Nvnflinger, "returning mask {}", mask); *out_slot_mask = mask; return Status::NoError; } diff --git a/src/core/hle/service/nvflinger/buffer_queue_consumer.h b/src/core/hle/service/nvnflinger/buffer_queue_consumer.h index 4ec06ca13..50ed0bb5f 100644 --- a/src/core/hle/service/nvflinger/buffer_queue_consumer.h +++ b/src/core/hle/service/nvnflinger/buffer_queue_consumer.h @@ -10,8 +10,8 @@ #include <memory> #include "common/common_types.h" -#include "core/hle/service/nvflinger/buffer_queue_defs.h" -#include "core/hle/service/nvflinger/status.h" +#include "core/hle/service/nvnflinger/buffer_queue_defs.h" +#include "core/hle/service/nvnflinger/status.h" namespace Service::Nvidia::NvCore { class NvMap; diff --git a/src/core/hle/service/nvflinger/buffer_queue_core.cpp b/src/core/hle/service/nvnflinger/buffer_queue_core.cpp index 3d1338e66..2dbe29616 100644 --- a/src/core/hle/service/nvflinger/buffer_queue_core.cpp +++ b/src/core/hle/service/nvnflinger/buffer_queue_core.cpp @@ -6,7 +6,7 @@ #include "common/assert.h" -#include "core/hle/service/nvflinger/buffer_queue_core.h" +#include "core/hle/service/nvnflinger/buffer_queue_core.h" namespace Service::android { @@ -82,7 +82,7 @@ s32 BufferQueueCore::GetPreallocatedBufferCountLocked() const { } void BufferQueueCore::FreeBufferLocked(s32 slot) { - LOG_DEBUG(Service_NVFlinger, "slot {}", slot); + LOG_DEBUG(Service_Nvnflinger, "slot {}", slot); slots[slot].graphic_buffer.reset(); diff --git a/src/core/hle/service/nvflinger/buffer_queue_core.h b/src/core/hle/service/nvnflinger/buffer_queue_core.h index 85b3bc4c1..9164f08a0 100644 --- a/src/core/hle/service/nvflinger/buffer_queue_core.h +++ b/src/core/hle/service/nvnflinger/buffer_queue_core.h @@ -13,11 +13,11 @@ #include <set> #include <vector> -#include "core/hle/service/nvflinger/buffer_item.h" -#include "core/hle/service/nvflinger/buffer_queue_defs.h" -#include "core/hle/service/nvflinger/pixel_format.h" -#include "core/hle/service/nvflinger/status.h" -#include "core/hle/service/nvflinger/window.h" +#include "core/hle/service/nvnflinger/buffer_item.h" +#include "core/hle/service/nvnflinger/buffer_queue_defs.h" +#include "core/hle/service/nvnflinger/pixel_format.h" +#include "core/hle/service/nvnflinger/status.h" +#include "core/hle/service/nvnflinger/window.h" namespace Service::android { diff --git a/src/core/hle/service/nvflinger/buffer_queue_defs.h b/src/core/hle/service/nvnflinger/buffer_queue_defs.h index 334445213..6fd3156f4 100644 --- a/src/core/hle/service/nvflinger/buffer_queue_defs.h +++ b/src/core/hle/service/nvnflinger/buffer_queue_defs.h @@ -9,7 +9,7 @@ #include <array> #include "common/common_types.h" -#include "core/hle/service/nvflinger/buffer_slot.h" +#include "core/hle/service/nvnflinger/buffer_slot.h" namespace Service::android::BufferQueueDefs { diff --git a/src/core/hle/service/nvflinger/buffer_queue_producer.cpp b/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp index bcbe05b0d..cd0a13094 100644 --- a/src/core/hle/service/nvflinger/buffer_queue_producer.cpp +++ b/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp @@ -8,18 +8,18 @@ #include "common/logging/log.h" #include "common/settings.h" #include "core/core.h" -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_event.h" #include "core/hle/kernel/k_readable_event.h" #include "core/hle/kernel/kernel.h" +#include "core/hle/service/hle_ipc.h" #include "core/hle/service/kernel_helpers.h" #include "core/hle/service/nvdrv/core/nvmap.h" -#include "core/hle/service/nvflinger/buffer_queue_core.h" -#include "core/hle/service/nvflinger/buffer_queue_producer.h" -#include "core/hle/service/nvflinger/consumer_listener.h" -#include "core/hle/service/nvflinger/parcel.h" -#include "core/hle/service/nvflinger/ui/graphic_buffer.h" -#include "core/hle/service/nvflinger/window.h" +#include "core/hle/service/nvnflinger/buffer_queue_core.h" +#include "core/hle/service/nvnflinger/buffer_queue_producer.h" +#include "core/hle/service/nvnflinger/consumer_listener.h" +#include "core/hle/service/nvnflinger/parcel.h" +#include "core/hle/service/nvnflinger/ui/graphic_buffer.h" +#include "core/hle/service/nvnflinger/window.h" #include "core/hle/service/vi/vi.h" namespace Service::android { @@ -37,20 +37,20 @@ BufferQueueProducer::~BufferQueueProducer() { } Status BufferQueueProducer::RequestBuffer(s32 slot, std::shared_ptr<GraphicBuffer>* buf) { - LOG_DEBUG(Service_NVFlinger, "slot {}", slot); + LOG_DEBUG(Service_Nvnflinger, "slot {}", slot); std::scoped_lock lock{core->mutex}; if (core->is_abandoned) { - LOG_ERROR(Service_NVFlinger, "BufferQueue has been abandoned"); + LOG_ERROR(Service_Nvnflinger, "BufferQueue has been abandoned"); return Status::NoInit; } if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) { - LOG_ERROR(Service_NVFlinger, "slot index {} out of range [0, {})", slot, + LOG_ERROR(Service_Nvnflinger, "slot index {} out of range [0, {})", slot, BufferQueueDefs::NUM_BUFFER_SLOTS); return Status::BadValue; } else if (slots[slot].buffer_state != BufferState::Dequeued) { - LOG_ERROR(Service_NVFlinger, "slot {} is not owned by the producer (state = {})", slot, + LOG_ERROR(Service_Nvnflinger, "slot {} is not owned by the producer (state = {})", slot, slots[slot].buffer_state); return Status::BadValue; } @@ -62,7 +62,7 @@ Status BufferQueueProducer::RequestBuffer(s32 slot, std::shared_ptr<GraphicBuffe } Status BufferQueueProducer::SetBufferCount(s32 buffer_count) { - LOG_DEBUG(Service_NVFlinger, "count = {}", buffer_count); + LOG_DEBUG(Service_Nvnflinger, "count = {}", buffer_count); std::shared_ptr<IConsumerListener> listener; { @@ -70,12 +70,12 @@ Status BufferQueueProducer::SetBufferCount(s32 buffer_count) { core->WaitWhileAllocatingLocked(); if (core->is_abandoned) { - LOG_ERROR(Service_NVFlinger, "BufferQueue has been abandoned"); + LOG_ERROR(Service_Nvnflinger, "BufferQueue has been abandoned"); return Status::NoInit; } if (buffer_count > BufferQueueDefs::NUM_BUFFER_SLOTS) { - LOG_ERROR(Service_NVFlinger, "buffer_count {} too large (max {})", buffer_count, + LOG_ERROR(Service_Nvnflinger, "buffer_count {} too large (max {})", buffer_count, BufferQueueDefs::NUM_BUFFER_SLOTS); return Status::BadValue; } @@ -83,7 +83,7 @@ Status BufferQueueProducer::SetBufferCount(s32 buffer_count) { // There must be no dequeued buffers when changing the buffer count. for (s32 s{}; s < BufferQueueDefs::NUM_BUFFER_SLOTS; ++s) { if (slots[s].buffer_state == BufferState::Dequeued) { - LOG_ERROR(Service_NVFlinger, "buffer owned by producer"); + LOG_ERROR(Service_Nvnflinger, "buffer owned by producer"); return Status::BadValue; } } @@ -96,7 +96,7 @@ Status BufferQueueProducer::SetBufferCount(s32 buffer_count) { const s32 min_buffer_slots = core->GetMinMaxBufferCountLocked(false); if (buffer_count < min_buffer_slots) { - LOG_ERROR(Service_NVFlinger, "requested buffer count {} is less than minimum {}", + LOG_ERROR(Service_Nvnflinger, "requested buffer count {} is less than minimum {}", buffer_count, min_buffer_slots); return Status::BadValue; } @@ -127,14 +127,14 @@ Status BufferQueueProducer::WaitForFreeSlotThenRelock(bool async, s32* found, St while (try_again) { if (core->is_abandoned) { - LOG_ERROR(Service_NVFlinger, "BufferQueue has been abandoned"); + LOG_ERROR(Service_Nvnflinger, "BufferQueue has been abandoned"); return Status::NoInit; } const s32 max_buffer_count = core->GetMaxBufferCountLocked(async); if (async && core->override_max_buffer_count) { if (core->override_max_buffer_count < max_buffer_count) { - LOG_ERROR(Service_NVFlinger, "async mode is invalid with buffer count override"); + LOG_ERROR(Service_Nvnflinger, "async mode is invalid with buffer count override"); return Status::BadValue; } } @@ -176,7 +176,7 @@ Status BufferQueueProducer::WaitForFreeSlotThenRelock(bool async, s32* found, St // Producers are not allowed to dequeue more than one buffer if they did not set a buffer // count if (!core->override_max_buffer_count && dequeued_count) { - LOG_ERROR(Service_NVFlinger, + LOG_ERROR(Service_Nvnflinger, "can't dequeue multiple buffers without setting the buffer count"); return Status::InvalidOperation; } @@ -188,7 +188,7 @@ Status BufferQueueProducer::WaitForFreeSlotThenRelock(bool async, s32* found, St const s32 new_undequeued_count = max_buffer_count - (dequeued_count + 1); const s32 min_undequeued_count = core->GetMinUndequeuedBufferCountLocked(async); if (new_undequeued_count < min_undequeued_count) { - LOG_ERROR(Service_NVFlinger, + LOG_ERROR(Service_Nvnflinger, "min undequeued buffer count({}) exceeded (dequeued={} undequeued={})", min_undequeued_count, dequeued_count, new_undequeued_count); return Status::InvalidOperation; @@ -200,7 +200,7 @@ Status BufferQueueProducer::WaitForFreeSlotThenRelock(bool async, s32* found, St // outrun the consumer. Wait here if it looks like we have too many buffers queued up. const bool too_many_buffers = core->queue.size() > static_cast<size_t>(max_buffer_count); if (too_many_buffers) { - LOG_ERROR(Service_NVFlinger, "queue size is {}, waiting", core->queue.size()); + LOG_ERROR(Service_Nvnflinger, "queue size is {}, waiting", core->queue.size()); } // If no buffer is found, or if the queue has too many buffers outstanding, wait for a @@ -226,11 +226,11 @@ Status BufferQueueProducer::WaitForFreeSlotThenRelock(bool async, s32* found, St Status BufferQueueProducer::DequeueBuffer(s32* out_slot, Fence* out_fence, bool async, u32 width, u32 height, PixelFormat format, u32 usage) { - LOG_DEBUG(Service_NVFlinger, "async={} w={} h={} format={}, usage={}", async ? "true" : "false", - width, height, format, usage); + LOG_DEBUG(Service_Nvnflinger, "async={} w={} h={} format={}, usage={}", + async ? "true" : "false", width, height, format, usage); if ((width != 0 && height == 0) || (width == 0 && height != 0)) { - LOG_ERROR(Service_NVFlinger, "invalid size: w={} h={}", width, height); + LOG_ERROR(Service_Nvnflinger, "invalid size: w={} h={}", width, height); return Status::BadValue; } @@ -255,7 +255,7 @@ Status BufferQueueProducer::DequeueBuffer(s32* out_slot, Fence* out_fence, bool // This should not happen if (found == BufferQueueCore::INVALID_BUFFER_SLOT) { - LOG_ERROR(Service_NVFlinger, "no available buffer slots"); + LOG_ERROR(Service_Nvnflinger, "no available buffer slots"); return Status::Busy; } @@ -287,11 +287,11 @@ Status BufferQueueProducer::DequeueBuffer(s32* out_slot, Fence* out_fence, bool } if ((return_flags & Status::BufferNeedsReallocation) != Status::None) { - LOG_DEBUG(Service_NVFlinger, "allocating a new buffer for slot {}", *out_slot); + LOG_DEBUG(Service_Nvnflinger, "allocating a new buffer for slot {}", *out_slot); auto graphic_buffer = std::make_shared<GraphicBuffer>(width, height, format, usage); if (graphic_buffer == nullptr) { - LOG_ERROR(Service_NVFlinger, "creating GraphicBuffer failed"); + LOG_ERROR(Service_Nvnflinger, "creating GraphicBuffer failed"); return Status::NoMemory; } @@ -299,7 +299,7 @@ Status BufferQueueProducer::DequeueBuffer(s32* out_slot, Fence* out_fence, bool std::scoped_lock lock{core->mutex}; if (core->is_abandoned) { - LOG_ERROR(Service_NVFlinger, "BufferQueue has been abandoned"); + LOG_ERROR(Service_Nvnflinger, "BufferQueue has been abandoned"); return Status::NoInit; } @@ -312,32 +312,32 @@ Status BufferQueueProducer::DequeueBuffer(s32* out_slot, Fence* out_fence, bool return_flags |= Status::BufferNeedsReallocation; } - LOG_DEBUG(Service_NVFlinger, "returning slot={} frame={}, flags={}", *out_slot, + LOG_DEBUG(Service_Nvnflinger, "returning slot={} frame={}, flags={}", *out_slot, slots[*out_slot].frame_number, return_flags); return return_flags; } Status BufferQueueProducer::DetachBuffer(s32 slot) { - LOG_DEBUG(Service_NVFlinger, "slot {}", slot); + LOG_DEBUG(Service_Nvnflinger, "slot {}", slot); std::scoped_lock lock{core->mutex}; if (core->is_abandoned) { - LOG_ERROR(Service_NVFlinger, "BufferQueue has been abandoned"); + LOG_ERROR(Service_Nvnflinger, "BufferQueue has been abandoned"); return Status::NoInit; } if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) { - LOG_ERROR(Service_NVFlinger, "slot {} out of range [0, {})", slot, + LOG_ERROR(Service_Nvnflinger, "slot {} out of range [0, {})", slot, BufferQueueDefs::NUM_BUFFER_SLOTS); return Status::BadValue; } else if (slots[slot].buffer_state != BufferState::Dequeued) { - LOG_ERROR(Service_NVFlinger, "slot {} is not owned by the producer (state = {})", slot, + LOG_ERROR(Service_Nvnflinger, "slot {} is not owned by the producer (state = {})", slot, slots[slot].buffer_state); return Status::BadValue; } else if (!slots[slot].request_buffer_called) { - LOG_ERROR(Service_NVFlinger, "buffer in slot {} has not been requested", slot); + LOG_ERROR(Service_Nvnflinger, "buffer in slot {} has not been requested", slot); return Status::BadValue; } @@ -350,10 +350,10 @@ Status BufferQueueProducer::DetachBuffer(s32 slot) { Status BufferQueueProducer::DetachNextBuffer(std::shared_ptr<GraphicBuffer>* out_buffer, Fence* out_fence) { if (out_buffer == nullptr) { - LOG_ERROR(Service_NVFlinger, "out_buffer must not be nullptr"); + LOG_ERROR(Service_Nvnflinger, "out_buffer must not be nullptr"); return Status::BadValue; } else if (out_fence == nullptr) { - LOG_ERROR(Service_NVFlinger, "out_fence must not be nullptr"); + LOG_ERROR(Service_Nvnflinger, "out_fence must not be nullptr"); return Status::BadValue; } @@ -361,7 +361,7 @@ Status BufferQueueProducer::DetachNextBuffer(std::shared_ptr<GraphicBuffer>* out core->WaitWhileAllocatingLocked(); if (core->is_abandoned) { - LOG_ERROR(Service_NVFlinger, "BufferQueue has been abandoned"); + LOG_ERROR(Service_Nvnflinger, "BufferQueue has been abandoned"); return Status::NoInit; } @@ -380,7 +380,7 @@ Status BufferQueueProducer::DetachNextBuffer(std::shared_ptr<GraphicBuffer>* out return Status::NoMemory; } - LOG_DEBUG(Service_NVFlinger, "Detached slot {}", found); + LOG_DEBUG(Service_Nvnflinger, "Detached slot {}", found); *out_buffer = slots[found].graphic_buffer; *out_fence = slots[found].fence; @@ -393,10 +393,10 @@ Status BufferQueueProducer::DetachNextBuffer(std::shared_ptr<GraphicBuffer>* out Status BufferQueueProducer::AttachBuffer(s32* out_slot, const std::shared_ptr<GraphicBuffer>& buffer) { if (out_slot == nullptr) { - LOG_ERROR(Service_NVFlinger, "out_slot must not be nullptr"); + LOG_ERROR(Service_Nvnflinger, "out_slot must not be nullptr"); return Status::BadValue; } else if (buffer == nullptr) { - LOG_ERROR(Service_NVFlinger, "Cannot attach nullptr buffer"); + LOG_ERROR(Service_Nvnflinger, "Cannot attach nullptr buffer"); return Status::BadValue; } @@ -413,13 +413,13 @@ Status BufferQueueProducer::AttachBuffer(s32* out_slot, // This should not happen if (found == BufferQueueCore::INVALID_BUFFER_SLOT) { - LOG_ERROR(Service_NVFlinger, "No available buffer slots"); + LOG_ERROR(Service_Nvnflinger, "No available buffer slots"); return Status::Busy; } *out_slot = found; - LOG_DEBUG(Service_NVFlinger, "Returning slot {} flags={}", *out_slot, return_flags); + LOG_DEBUG(Service_Nvnflinger, "Returning slot {} flags={}", *out_slot, return_flags); slots[*out_slot].graphic_buffer = buffer; slots[*out_slot].buffer_state = BufferState::Dequeued; @@ -451,7 +451,7 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input, case NativeWindowScalingMode::NoScaleCrop: break; default: - LOG_ERROR(Service_NVFlinger, "unknown scaling mode {}", scaling_mode); + LOG_ERROR(Service_Nvnflinger, "unknown scaling mode {}", scaling_mode); return Status::BadValue; } @@ -464,38 +464,38 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input, std::scoped_lock lock{core->mutex}; if (core->is_abandoned) { - LOG_ERROR(Service_NVFlinger, "BufferQueue has been abandoned"); + LOG_ERROR(Service_Nvnflinger, "BufferQueue has been abandoned"); return Status::NoInit; } const s32 max_buffer_count = core->GetMaxBufferCountLocked(async); if (async && core->override_max_buffer_count) { if (core->override_max_buffer_count < max_buffer_count) { - LOG_ERROR(Service_NVFlinger, "async mode is invalid with " - "buffer count override"); + LOG_ERROR(Service_Nvnflinger, "async mode is invalid with " + "buffer count override"); return Status::BadValue; } } if (slot < 0 || slot >= max_buffer_count) { - LOG_ERROR(Service_NVFlinger, "slot index {} out of range [0, {})", slot, + LOG_ERROR(Service_Nvnflinger, "slot index {} out of range [0, {})", slot, max_buffer_count); return Status::BadValue; } else if (slots[slot].buffer_state != BufferState::Dequeued) { - LOG_ERROR(Service_NVFlinger, + LOG_ERROR(Service_Nvnflinger, "slot {} is not owned by the producer " "(state = {})", slot, slots[slot].buffer_state); return Status::BadValue; } else if (!slots[slot].request_buffer_called) { - LOG_ERROR(Service_NVFlinger, + LOG_ERROR(Service_Nvnflinger, "slot {} was queued without requesting " "a buffer", slot); return Status::BadValue; } - LOG_DEBUG(Service_NVFlinger, + LOG_DEBUG(Service_Nvnflinger, "slot={} frame={} time={} crop=[{},{},{},{}] transform={} scale={}", slot, core->frame_counter + 1, timestamp, crop.Left(), crop.Top(), crop.Right(), crop.Bottom(), transform, scaling_mode); @@ -506,7 +506,7 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input, [[maybe_unused]] const bool unused = crop.Intersect(buffer_rect, &cropped_rect); if (cropped_rect != crop) { - LOG_ERROR(Service_NVFlinger, "crop rect is not contained within the buffer in slot {}", + LOG_ERROR(Service_Nvnflinger, "crop rect is not contained within the buffer in slot {}", slot); return Status::BadValue; } @@ -598,21 +598,21 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input, } void BufferQueueProducer::CancelBuffer(s32 slot, const Fence& fence) { - LOG_DEBUG(Service_NVFlinger, "slot {}", slot); + LOG_DEBUG(Service_Nvnflinger, "slot {}", slot); std::scoped_lock lock{core->mutex}; if (core->is_abandoned) { - LOG_ERROR(Service_NVFlinger, "BufferQueue has been abandoned"); + LOG_ERROR(Service_Nvnflinger, "BufferQueue has been abandoned"); return; } if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) { - LOG_ERROR(Service_NVFlinger, "slot index {} out of range [0, {})", slot, + LOG_ERROR(Service_Nvnflinger, "slot index {} out of range [0, {})", slot, BufferQueueDefs::NUM_BUFFER_SLOTS); return; } else if (slots[slot].buffer_state != BufferState::Dequeued) { - LOG_ERROR(Service_NVFlinger, "slot {} is not owned by the producer (state = {})", slot, + LOG_ERROR(Service_Nvnflinger, "slot {} is not owned by the producer (state = {})", slot, slots[slot].buffer_state); return; } @@ -629,12 +629,12 @@ Status BufferQueueProducer::Query(NativeWindow what, s32* out_value) { std::scoped_lock lock{core->mutex}; if (out_value == nullptr) { - LOG_ERROR(Service_NVFlinger, "outValue was nullptr"); + LOG_ERROR(Service_Nvnflinger, "outValue was nullptr"); return Status::BadValue; } if (core->is_abandoned) { - LOG_ERROR(Service_NVFlinger, "BufferQueue has been abandoned"); + LOG_ERROR(Service_Nvnflinger, "BufferQueue has been abandoned"); return Status::NoInit; } @@ -666,7 +666,7 @@ Status BufferQueueProducer::Query(NativeWindow what, s32* out_value) { return Status::BadValue; } - LOG_DEBUG(Service_NVFlinger, "what = {}, value = {}", what, value); + LOG_DEBUG(Service_Nvnflinger, "what = {}, value = {}", what, value); *out_value = static_cast<s32>(value); @@ -678,26 +678,26 @@ Status BufferQueueProducer::Connect(const std::shared_ptr<IProducerListener>& li QueueBufferOutput* output) { std::scoped_lock lock{core->mutex}; - LOG_DEBUG(Service_NVFlinger, "api = {} producer_controlled_by_app = {}", api, + LOG_DEBUG(Service_Nvnflinger, "api = {} producer_controlled_by_app = {}", api, producer_controlled_by_app); if (core->is_abandoned) { - LOG_ERROR(Service_NVFlinger, "BufferQueue has been abandoned"); + LOG_ERROR(Service_Nvnflinger, "BufferQueue has been abandoned"); return Status::NoInit; } if (core->consumer_listener == nullptr) { - LOG_ERROR(Service_NVFlinger, "BufferQueue has no consumer"); + LOG_ERROR(Service_Nvnflinger, "BufferQueue has no consumer"); return Status::NoInit; } if (output == nullptr) { - LOG_ERROR(Service_NVFlinger, "output was nullptr"); + LOG_ERROR(Service_Nvnflinger, "output was nullptr"); return Status::BadValue; } if (core->connected_api != NativeWindowApi::NoConnectedApi) { - LOG_ERROR(Service_NVFlinger, "already connected (cur = {} req = {})", core->connected_api, + LOG_ERROR(Service_Nvnflinger, "already connected (cur = {} req = {})", core->connected_api, api); return Status::BadValue; } @@ -714,7 +714,7 @@ Status BufferQueueProducer::Connect(const std::shared_ptr<IProducerListener>& li core->connected_producer_listener = listener; break; default: - LOG_ERROR(Service_NVFlinger, "unknown api = {}", api); + LOG_ERROR(Service_Nvnflinger, "unknown api = {}", api); status = Status::BadValue; break; } @@ -727,7 +727,7 @@ Status BufferQueueProducer::Connect(const std::shared_ptr<IProducerListener>& li } Status BufferQueueProducer::Disconnect(NativeWindowApi api) { - LOG_DEBUG(Service_NVFlinger, "api = {}", api); + LOG_DEBUG(Service_Nvnflinger, "api = {}", api); Status status = Status::NoError; std::shared_ptr<IConsumerListener> listener; @@ -762,13 +762,13 @@ Status BufferQueueProducer::Disconnect(NativeWindowApi api) { buffer_wait_event->Signal(); listener = core->consumer_listener; } else { - LOG_ERROR(Service_NVFlinger, "still connected to another api (cur = {} req = {})", + LOG_ERROR(Service_Nvnflinger, "still connected to another api (cur = {} req = {})", core->connected_api, api); status = Status::BadValue; } break; default: - LOG_ERROR(Service_NVFlinger, "unknown api = {}", api); + LOG_ERROR(Service_Nvnflinger, "unknown api = {}", api); status = Status::BadValue; break; } @@ -784,7 +784,7 @@ Status BufferQueueProducer::Disconnect(NativeWindowApi api) { Status BufferQueueProducer::SetPreallocatedBuffer(s32 slot, const std::shared_ptr<GraphicBuffer>& buffer) { - LOG_DEBUG(Service_NVFlinger, "slot {}", slot); + LOG_DEBUG(Service_Nvnflinger, "slot {}", slot); if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) { return Status::BadValue; @@ -813,7 +813,7 @@ Status BufferQueueProducer::SetPreallocatedBuffer(s32 slot, return Status::NoError; } -void BufferQueueProducer::Transact(Kernel::HLERequestContext& ctx, TransactionId code, u32 flags) { +void BufferQueueProducer::Transact(HLERequestContext& ctx, TransactionId code, u32 flags) { Status status{Status::NoError}; InputParcel parcel_in{ctx.ReadBuffer()}; OutputParcel parcel_out{}; @@ -914,7 +914,7 @@ void BufferQueueProducer::Transact(Kernel::HLERequestContext& ctx, TransactionId break; } case TransactionId::GetBufferHistory: - LOG_WARNING(Service_NVFlinger, "(STUBBED) called, transaction=GetBufferHistory"); + LOG_WARNING(Service_Nvnflinger, "(STUBBED) called, transaction=GetBufferHistory"); break; default: ASSERT_MSG(false, "Unimplemented TransactionId {}", code); diff --git a/src/core/hle/service/nvflinger/buffer_queue_producer.h b/src/core/hle/service/nvnflinger/buffer_queue_producer.h index 1d380480f..d4201c104 100644 --- a/src/core/hle/service/nvflinger/buffer_queue_producer.h +++ b/src/core/hle/service/nvnflinger/buffer_queue_producer.h @@ -12,13 +12,13 @@ #include "common/common_funcs.h" #include "core/hle/service/nvdrv/nvdata.h" -#include "core/hle/service/nvflinger/binder.h" -#include "core/hle/service/nvflinger/buffer_queue_defs.h" -#include "core/hle/service/nvflinger/buffer_slot.h" -#include "core/hle/service/nvflinger/graphic_buffer_producer.h" -#include "core/hle/service/nvflinger/pixel_format.h" -#include "core/hle/service/nvflinger/status.h" -#include "core/hle/service/nvflinger/window.h" +#include "core/hle/service/nvnflinger/binder.h" +#include "core/hle/service/nvnflinger/buffer_queue_defs.h" +#include "core/hle/service/nvnflinger/buffer_slot.h" +#include "core/hle/service/nvnflinger/graphic_buffer_producer.h" +#include "core/hle/service/nvnflinger/pixel_format.h" +#include "core/hle/service/nvnflinger/status.h" +#include "core/hle/service/nvnflinger/window.h" namespace Kernel { class KernelCore; @@ -46,7 +46,7 @@ public: Service::Nvidia::NvCore::NvMap& nvmap_); ~BufferQueueProducer(); - void Transact(Kernel::HLERequestContext& ctx, android::TransactionId code, u32 flags) override; + void Transact(HLERequestContext& ctx, android::TransactionId code, u32 flags) override; Kernel::KReadableEvent& GetNativeHandle() override; diff --git a/src/core/hle/service/nvflinger/buffer_slot.h b/src/core/hle/service/nvnflinger/buffer_slot.h index 0cd0e9964..d25bca049 100644 --- a/src/core/hle/service/nvflinger/buffer_slot.h +++ b/src/core/hle/service/nvnflinger/buffer_slot.h @@ -9,7 +9,7 @@ #include <memory> #include "common/common_types.h" -#include "core/hle/service/nvflinger/ui/fence.h" +#include "core/hle/service/nvnflinger/ui/fence.h" namespace Service::android { diff --git a/src/core/hle/service/nvflinger/buffer_transform_flags.h b/src/core/hle/service/nvnflinger/buffer_transform_flags.h index 67aa5dad6..67aa5dad6 100644 --- a/src/core/hle/service/nvflinger/buffer_transform_flags.h +++ b/src/core/hle/service/nvnflinger/buffer_transform_flags.h diff --git a/src/core/hle/service/nvflinger/consumer_base.cpp b/src/core/hle/service/nvnflinger/consumer_base.cpp index 982531e2d..4dcda8dac 100644 --- a/src/core/hle/service/nvflinger/consumer_base.cpp +++ b/src/core/hle/service/nvnflinger/consumer_base.cpp @@ -6,11 +6,11 @@ #include "common/assert.h" #include "common/logging/log.h" -#include "core/hle/service/nvflinger/buffer_item.h" -#include "core/hle/service/nvflinger/buffer_queue_consumer.h" -#include "core/hle/service/nvflinger/buffer_queue_core.h" -#include "core/hle/service/nvflinger/consumer_base.h" -#include "core/hle/service/nvflinger/ui/graphic_buffer.h" +#include "core/hle/service/nvnflinger/buffer_item.h" +#include "core/hle/service/nvnflinger/buffer_queue_consumer.h" +#include "core/hle/service/nvnflinger/buffer_queue_core.h" +#include "core/hle/service/nvnflinger/consumer_base.h" +#include "core/hle/service/nvnflinger/ui/graphic_buffer.h" namespace Service::android { @@ -28,7 +28,7 @@ void ConsumerBase::Connect(bool controlled_by_app) { } void ConsumerBase::FreeBufferLocked(s32 slot_index) { - LOG_DEBUG(Service_NVFlinger, "slot_index={}", slot_index); + LOG_DEBUG(Service_Nvnflinger, "slot_index={}", slot_index); slots[slot_index].graphic_buffer = nullptr; slots[slot_index].fence = Fence::NoFence(); @@ -36,17 +36,17 @@ void ConsumerBase::FreeBufferLocked(s32 slot_index) { } void ConsumerBase::OnFrameAvailable(const BufferItem& item) { - LOG_DEBUG(Service_NVFlinger, "called"); + LOG_DEBUG(Service_Nvnflinger, "called"); } void ConsumerBase::OnFrameReplaced(const BufferItem& item) { - LOG_DEBUG(Service_NVFlinger, "called"); + LOG_DEBUG(Service_Nvnflinger, "called"); } void ConsumerBase::OnBuffersReleased() { std::scoped_lock lock{mutex}; - LOG_DEBUG(Service_NVFlinger, "called"); + LOG_DEBUG(Service_Nvnflinger, "called"); if (is_abandoned) { // Nothing to do if we're already abandoned. @@ -77,7 +77,7 @@ Status ConsumerBase::AcquireBufferLocked(BufferItem* item, std::chrono::nanoseco slots[item->slot].frame_number = item->frame_number; slots[item->slot].fence = item->fence; - LOG_DEBUG(Service_NVFlinger, "slot={}", item->slot); + LOG_DEBUG(Service_Nvnflinger, "slot={}", item->slot); return Status::NoError; } @@ -85,7 +85,7 @@ Status ConsumerBase::AcquireBufferLocked(BufferItem* item, std::chrono::nanoseco Status ConsumerBase::AddReleaseFenceLocked(s32 slot, const std::shared_ptr<GraphicBuffer>& graphic_buffer, const Fence& fence) { - LOG_DEBUG(Service_NVFlinger, "slot={}", slot); + LOG_DEBUG(Service_Nvnflinger, "slot={}", slot); // If consumer no longer tracks this graphic_buffer, we can safely // drop this fence, as it will never be received by the producer. @@ -109,7 +109,7 @@ Status ConsumerBase::ReleaseBufferLocked(s32 slot, return Status::NoError; } - LOG_DEBUG(Service_NVFlinger, "slot={}", slot); + LOG_DEBUG(Service_Nvnflinger, "slot={}", slot); Status err = consumer->ReleaseBuffer(slot, slots[slot].frame_number, slots[slot].fence); if (err == Status::StaleBufferSlot) { FreeBufferLocked(slot); diff --git a/src/core/hle/service/nvflinger/consumer_base.h b/src/core/hle/service/nvnflinger/consumer_base.h index 9a8a5f6bb..264829414 100644 --- a/src/core/hle/service/nvflinger/consumer_base.h +++ b/src/core/hle/service/nvnflinger/consumer_base.h @@ -12,9 +12,9 @@ #include <mutex> #include "common/common_types.h" -#include "core/hle/service/nvflinger/buffer_queue_defs.h" -#include "core/hle/service/nvflinger/consumer_listener.h" -#include "core/hle/service/nvflinger/status.h" +#include "core/hle/service/nvnflinger/buffer_queue_defs.h" +#include "core/hle/service/nvnflinger/consumer_listener.h" +#include "core/hle/service/nvnflinger/status.h" namespace Service::android { diff --git a/src/core/hle/service/nvflinger/consumer_listener.h b/src/core/hle/service/nvnflinger/consumer_listener.h index 74a193988..74a193988 100644 --- a/src/core/hle/service/nvflinger/consumer_listener.h +++ b/src/core/hle/service/nvnflinger/consumer_listener.h diff --git a/src/core/hle/service/nvflinger/graphic_buffer_producer.cpp b/src/core/hle/service/nvnflinger/graphic_buffer_producer.cpp index 769e8c0a3..d72b49a8e 100644 --- a/src/core/hle/service/nvflinger/graphic_buffer_producer.cpp +++ b/src/core/hle/service/nvnflinger/graphic_buffer_producer.cpp @@ -4,8 +4,8 @@ // Parts of this implementation were based on: // https://cs.android.com/android/platform/superproject/+/android-5.1.1_r38:frameworks/native/libs/gui/IGraphicBufferProducer.cpp -#include "core/hle/service/nvflinger/graphic_buffer_producer.h" -#include "core/hle/service/nvflinger/parcel.h" +#include "core/hle/service/nvnflinger/graphic_buffer_producer.h" +#include "core/hle/service/nvnflinger/parcel.h" namespace Service::android { diff --git a/src/core/hle/service/nvflinger/graphic_buffer_producer.h b/src/core/hle/service/nvnflinger/graphic_buffer_producer.h index 2969f0fd5..21d7b31f3 100644 --- a/src/core/hle/service/nvflinger/graphic_buffer_producer.h +++ b/src/core/hle/service/nvnflinger/graphic_buffer_producer.h @@ -9,8 +9,8 @@ #include "common/common_funcs.h" #include "common/common_types.h" #include "common/math_util.h" -#include "core/hle/service/nvflinger/ui/fence.h" -#include "core/hle/service/nvflinger/window.h" +#include "core/hle/service/nvnflinger/ui/fence.h" +#include "core/hle/service/nvnflinger/window.h" namespace Service::android { diff --git a/src/core/hle/service/nvflinger/hos_binder_driver_server.cpp b/src/core/hle/service/nvnflinger/hos_binder_driver_server.cpp index dc9b2a9ec..b86a79ec9 100644 --- a/src/core/hle/service/nvflinger/hos_binder_driver_server.cpp +++ b/src/core/hle/service/nvnflinger/hos_binder_driver_server.cpp @@ -4,9 +4,9 @@ #include <mutex> #include "common/common_types.h" -#include "core/hle/service/nvflinger/hos_binder_driver_server.h" +#include "core/hle/service/nvnflinger/hos_binder_driver_server.h" -namespace Service::NVFlinger { +namespace Service::Nvnflinger { HosBinderDriverServer::HosBinderDriverServer(Core::System& system_) : service_context(system_, "HosBinderDriverServer") {} @@ -33,4 +33,4 @@ android::IBinder* HosBinderDriverServer::TryGetProducer(u64 id) { return {}; } -} // namespace Service::NVFlinger +} // namespace Service::Nvnflinger diff --git a/src/core/hle/service/nvflinger/hos_binder_driver_server.h b/src/core/hle/service/nvnflinger/hos_binder_driver_server.h index 8fddc1206..58bb9469a 100644 --- a/src/core/hle/service/nvflinger/hos_binder_driver_server.h +++ b/src/core/hle/service/nvnflinger/hos_binder_driver_server.h @@ -9,13 +9,13 @@ #include "common/common_types.h" #include "core/hle/service/kernel_helpers.h" -#include "core/hle/service/nvflinger/binder.h" +#include "core/hle/service/nvnflinger/binder.h" namespace Core { class System; } -namespace Service::NVFlinger { +namespace Service::Nvnflinger { class HosBinderDriverServer final { public: @@ -34,4 +34,4 @@ private: u64 last_id{}; }; -} // namespace Service::NVFlinger +} // namespace Service::Nvnflinger diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvnflinger/nvnflinger.cpp index f4416f5b2..4988e6e17 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvnflinger/nvnflinger.cpp @@ -15,11 +15,11 @@ #include "core/hle/kernel/k_readable_event.h" #include "core/hle/service/nvdrv/devices/nvdisp_disp0.h" #include "core/hle/service/nvdrv/nvdrv.h" -#include "core/hle/service/nvflinger/buffer_item_consumer.h" -#include "core/hle/service/nvflinger/buffer_queue_core.h" -#include "core/hle/service/nvflinger/hos_binder_driver_server.h" -#include "core/hle/service/nvflinger/nvflinger.h" -#include "core/hle/service/nvflinger/ui/graphic_buffer.h" +#include "core/hle/service/nvnflinger/buffer_item_consumer.h" +#include "core/hle/service/nvnflinger/buffer_queue_core.h" +#include "core/hle/service/nvnflinger/hos_binder_driver_server.h" +#include "core/hle/service/nvnflinger/nvnflinger.h" +#include "core/hle/service/nvnflinger/ui/graphic_buffer.h" #include "core/hle/service/vi/display/vi_display.h" #include "core/hle/service/vi/layer/vi_layer.h" #include "core/hle/service/vi/vi_results.h" @@ -27,11 +27,11 @@ #include "video_core/host1x/host1x.h" #include "video_core/host1x/syncpoint_manager.h" -namespace Service::NVFlinger { +namespace Service::Nvnflinger { constexpr auto frame_ns = std::chrono::nanoseconds{1000000000 / 60}; -void NVFlinger::SplitVSync(std::stop_token stop_token) { +void Nvnflinger::SplitVSync(std::stop_token stop_token) { system.RegisterHostThread(); std::string name = "VSyncThread"; MicroProfileOnThreadCreate(name.c_str()); @@ -54,8 +54,8 @@ void NVFlinger::SplitVSync(std::stop_token stop_token) { } } -NVFlinger::NVFlinger(Core::System& system_, HosBinderDriverServer& hos_binder_driver_server_) - : system(system_), service_context(system_, "nvflinger"), +Nvnflinger::Nvnflinger(Core::System& system_, HosBinderDriverServer& hos_binder_driver_server_) + : system(system_), service_context(system_, "nvnflinger"), hos_binder_driver_server(hos_binder_driver_server_) { displays.emplace_back(0, "Default", hos_binder_driver_server, service_context, system); displays.emplace_back(1, "External", hos_binder_driver_server, service_context, system); @@ -92,7 +92,7 @@ NVFlinger::NVFlinger(Core::System& system_, HosBinderDriverServer& hos_binder_dr } } -NVFlinger::~NVFlinger() { +Nvnflinger::~Nvnflinger() { if (system.IsMulticore()) { system.CoreTiming().UnscheduleEvent(multi_composition_event, {}); vsync_thread.request_stop(); @@ -109,7 +109,7 @@ NVFlinger::~NVFlinger() { } } -void NVFlinger::ShutdownLayers() { +void Nvnflinger::ShutdownLayers() { for (auto& display : displays) { for (size_t layer = 0; layer < display.GetNumLayers(); ++layer) { display.GetLayer(layer).Core().NotifyShutdown(); @@ -117,15 +117,15 @@ void NVFlinger::ShutdownLayers() { } } -void NVFlinger::SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance) { +void Nvnflinger::SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance) { nvdrv = std::move(instance); disp_fd = nvdrv->Open("/dev/nvdisp_disp0"); } -std::optional<u64> NVFlinger::OpenDisplay(std::string_view name) { +std::optional<u64> Nvnflinger::OpenDisplay(std::string_view name) { const auto lock_guard = Lock(); - LOG_DEBUG(Service_NVFlinger, "Opening \"{}\" display", name); + LOG_DEBUG(Service_Nvnflinger, "Opening \"{}\" display", name); const auto itr = std::find_if(displays.begin(), displays.end(), @@ -138,7 +138,7 @@ std::optional<u64> NVFlinger::OpenDisplay(std::string_view name) { return itr->GetID(); } -bool NVFlinger::CloseDisplay(u64 display_id) { +bool Nvnflinger::CloseDisplay(u64 display_id) { const auto lock_guard = Lock(); auto* const display = FindDisplay(display_id); @@ -151,7 +151,7 @@ bool NVFlinger::CloseDisplay(u64 display_id) { return true; } -std::optional<u64> NVFlinger::CreateLayer(u64 display_id) { +std::optional<u64> Nvnflinger::CreateLayer(u64 display_id) { const auto lock_guard = Lock(); auto* const display = FindDisplay(display_id); @@ -164,12 +164,12 @@ std::optional<u64> NVFlinger::CreateLayer(u64 display_id) { return layer_id; } -void NVFlinger::CreateLayerAtId(VI::Display& display, u64 layer_id) { +void Nvnflinger::CreateLayerAtId(VI::Display& display, u64 layer_id) { const auto buffer_id = next_buffer_queue_id++; display.CreateLayer(layer_id, buffer_id, nvdrv->container); } -void NVFlinger::CloseLayer(u64 layer_id) { +void Nvnflinger::CloseLayer(u64 layer_id) { const auto lock_guard = Lock(); for (auto& display : displays) { @@ -177,7 +177,7 @@ void NVFlinger::CloseLayer(u64 layer_id) { } } -std::optional<u32> NVFlinger::FindBufferQueueId(u64 display_id, u64 layer_id) { +std::optional<u32> Nvnflinger::FindBufferQueueId(u64 display_id, u64 layer_id) { const auto lock_guard = Lock(); const auto* const layer = FindOrCreateLayer(display_id, layer_id); @@ -188,7 +188,7 @@ std::optional<u32> NVFlinger::FindBufferQueueId(u64 display_id, u64 layer_id) { return layer->GetBinderId(); } -ResultVal<Kernel::KReadableEvent*> NVFlinger::FindVsyncEvent(u64 display_id) { +ResultVal<Kernel::KReadableEvent*> Nvnflinger::FindVsyncEvent(u64 display_id) { const auto lock_guard = Lock(); auto* const display = FindDisplay(display_id); @@ -199,7 +199,7 @@ ResultVal<Kernel::KReadableEvent*> NVFlinger::FindVsyncEvent(u64 display_id) { return display->GetVSyncEvent(); } -VI::Display* NVFlinger::FindDisplay(u64 display_id) { +VI::Display* Nvnflinger::FindDisplay(u64 display_id) { const auto itr = std::find_if(displays.begin(), displays.end(), [&](const VI::Display& display) { return display.GetID() == display_id; }); @@ -211,7 +211,7 @@ VI::Display* NVFlinger::FindDisplay(u64 display_id) { return &*itr; } -const VI::Display* NVFlinger::FindDisplay(u64 display_id) const { +const VI::Display* Nvnflinger::FindDisplay(u64 display_id) const { const auto itr = std::find_if(displays.begin(), displays.end(), [&](const VI::Display& display) { return display.GetID() == display_id; }); @@ -223,7 +223,7 @@ const VI::Display* NVFlinger::FindDisplay(u64 display_id) const { return &*itr; } -VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) { +VI::Layer* Nvnflinger::FindLayer(u64 display_id, u64 layer_id) { auto* const display = FindDisplay(display_id); if (display == nullptr) { @@ -233,7 +233,7 @@ VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) { return display->FindLayer(layer_id); } -const VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) const { +const VI::Layer* Nvnflinger::FindLayer(u64 display_id, u64 layer_id) const { const auto* const display = FindDisplay(display_id); if (display == nullptr) { @@ -243,7 +243,7 @@ const VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) const { return display->FindLayer(layer_id); } -VI::Layer* NVFlinger::FindOrCreateLayer(u64 display_id, u64 layer_id) { +VI::Layer* Nvnflinger::FindOrCreateLayer(u64 display_id, u64 layer_id) { auto* const display = FindDisplay(display_id); if (display == nullptr) { @@ -253,7 +253,7 @@ VI::Layer* NVFlinger::FindOrCreateLayer(u64 display_id, u64 layer_id) { auto* layer = display->FindLayer(layer_id); if (layer == nullptr) { - LOG_DEBUG(Service_NVFlinger, "Layer at id {} not found. Trying to create it.", layer_id); + LOG_DEBUG(Service_Nvnflinger, "Layer at id {} not found. Trying to create it.", layer_id); CreateLayerAtId(*display, layer_id); return display->FindLayer(layer_id); } @@ -261,7 +261,7 @@ VI::Layer* NVFlinger::FindOrCreateLayer(u64 display_id, u64 layer_id) { return layer; } -void NVFlinger::Compose() { +void Nvnflinger::Compose() { for (auto& display : displays) { // Trigger vsync for this display at the end of drawing SCOPE_EXIT({ display.SignalVSyncEvent(); }); @@ -311,7 +311,7 @@ void NVFlinger::Compose() { } } -s64 NVFlinger::GetNextTicks() const { +s64 Nvnflinger::GetNextTicks() const { const auto& settings = Settings::values; auto speed_scale = 1.f; if (settings.use_multi_core.GetValue()) { @@ -332,4 +332,4 @@ s64 NVFlinger::GetNextTicks() const { return static_cast<s64>(speed_scale * (1000000000.f / effective_fps)); } -} // namespace Service::NVFlinger +} // namespace Service::Nvnflinger diff --git a/src/core/hle/service/nvflinger/nvflinger.h b/src/core/hle/service/nvnflinger/nvnflinger.h index 3828cf272..a043cceb2 100644 --- a/src/core/hle/service/nvflinger/nvflinger.h +++ b/src/core/hle/service/nvnflinger/nvnflinger.h @@ -42,12 +42,12 @@ class BufferQueueCore; class BufferQueueProducer; } // namespace Service::android -namespace Service::NVFlinger { +namespace Service::Nvnflinger { -class NVFlinger final { +class Nvnflinger final { public: - explicit NVFlinger(Core::System& system_, HosBinderDriverServer& hos_binder_driver_server_); - ~NVFlinger(); + explicit Nvnflinger(Core::System& system_, HosBinderDriverServer& hos_binder_driver_server_); + ~Nvnflinger(); void ShutdownLayers(); @@ -152,4 +152,4 @@ private: HosBinderDriverServer& hos_binder_driver_server; }; -} // namespace Service::NVFlinger +} // namespace Service::Nvnflinger diff --git a/src/core/hle/service/nvflinger/parcel.h b/src/core/hle/service/nvnflinger/parcel.h index d1b6201e0..d1b6201e0 100644 --- a/src/core/hle/service/nvflinger/parcel.h +++ b/src/core/hle/service/nvnflinger/parcel.h diff --git a/src/core/hle/service/nvflinger/pixel_format.h b/src/core/hle/service/nvnflinger/pixel_format.h index f77d0acfb..f77d0acfb 100644 --- a/src/core/hle/service/nvflinger/pixel_format.h +++ b/src/core/hle/service/nvnflinger/pixel_format.h diff --git a/src/core/hle/service/nvflinger/producer_listener.h b/src/core/hle/service/nvnflinger/producer_listener.h index 6bf8aaf1e..6bf8aaf1e 100644 --- a/src/core/hle/service/nvflinger/producer_listener.h +++ b/src/core/hle/service/nvnflinger/producer_listener.h diff --git a/src/core/hle/service/nvflinger/status.h b/src/core/hle/service/nvnflinger/status.h index 7af166c40..7af166c40 100644 --- a/src/core/hle/service/nvflinger/status.h +++ b/src/core/hle/service/nvnflinger/status.h diff --git a/src/core/hle/service/nvflinger/ui/fence.h b/src/core/hle/service/nvnflinger/ui/fence.h index 536e8156d..536e8156d 100644 --- a/src/core/hle/service/nvflinger/ui/fence.h +++ b/src/core/hle/service/nvnflinger/ui/fence.h diff --git a/src/core/hle/service/nvflinger/ui/graphic_buffer.h b/src/core/hle/service/nvnflinger/ui/graphic_buffer.h index 9a27f8f02..75d1705a8 100644 --- a/src/core/hle/service/nvflinger/ui/graphic_buffer.h +++ b/src/core/hle/service/nvnflinger/ui/graphic_buffer.h @@ -8,7 +8,7 @@ #include "common/common_funcs.h" #include "common/common_types.h" -#include "core/hle/service/nvflinger/pixel_format.h" +#include "core/hle/service/nvnflinger/pixel_format.h" namespace Service::android { diff --git a/src/core/hle/service/nvflinger/window.h b/src/core/hle/service/nvnflinger/window.h index 61cca5b01..61cca5b01 100644 --- a/src/core/hle/service/nvflinger/window.h +++ b/src/core/hle/service/nvnflinger/window.h diff --git a/src/core/hle/service/olsc/olsc.cpp b/src/core/hle/service/olsc/olsc.cpp index 530e1be3b..14ba67b4c 100644 --- a/src/core/hle/service/olsc/olsc.cpp +++ b/src/core/hle/service/olsc/olsc.cpp @@ -1,10 +1,10 @@ // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/olsc/olsc.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" namespace Service::OLSC { @@ -42,7 +42,7 @@ public: } private: - void Initialize(Kernel::HLERequestContext& ctx) { + void Initialize(HLERequestContext& ctx) { LOG_WARNING(Service_OLSC, "(STUBBED) called"); initialized = true; @@ -51,7 +51,7 @@ private: rb.Push(ResultSuccess); } - void GetSaveDataBackupSetting(Kernel::HLERequestContext& ctx) { + void GetSaveDataBackupSetting(HLERequestContext& ctx) { LOG_WARNING(Service_OLSC, "(STUBBED) called"); // backup_setting is set to 0 since real value is unknown @@ -62,7 +62,7 @@ private: rb.Push(backup_setting); } - void SetSaveDataBackupSettingEnabled(Kernel::HLERequestContext& ctx) { + void SetSaveDataBackupSettingEnabled(HLERequestContext& ctx) { LOG_WARNING(Service_OLSC, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -72,8 +72,11 @@ private: bool initialized{}; }; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<OLSC>(system)->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("olsc:u", std::make_shared<OLSC>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::OLSC diff --git a/src/core/hle/service/olsc/olsc.h b/src/core/hle/service/olsc/olsc.h index 1522d8d32..620b634fa 100644 --- a/src/core/hle/service/olsc/olsc.h +++ b/src/core/hle/service/olsc/olsc.h @@ -7,13 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::OLSC { -/// Registers all SSL services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::OLSC diff --git a/src/core/hle/service/pcie/pcie.cpp b/src/core/hle/service/pcie/pcie.cpp index 79501b9f9..c6da6eb51 100644 --- a/src/core/hle/service/pcie/pcie.cpp +++ b/src/core/hle/service/pcie/pcie.cpp @@ -4,8 +4,8 @@ #include <memory> #include "core/hle/service/pcie/pcie.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" namespace Service::PCIe { @@ -59,8 +59,11 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<PCIe>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("pcie", std::make_shared<PCIe>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::PCIe diff --git a/src/core/hle/service/pcie/pcie.h b/src/core/hle/service/pcie/pcie.h index cebfd9042..5c2d4b805 100644 --- a/src/core/hle/service/pcie/pcie.h +++ b/src/core/hle/service/pcie/pcie.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::PCIe { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::PCIe diff --git a/src/core/hle/service/pctl/pctl_module.cpp b/src/core/hle/service/pctl/pctl_module.cpp index 083609b34..f966c5c8b 100644 --- a/src/core/hle/service/pctl/pctl_module.cpp +++ b/src/core/hle/service/pctl/pctl_module.cpp @@ -5,9 +5,10 @@ #include "core/core.h" #include "core/file_sys/control_metadata.h" #include "core/file_sys/patch_manager.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/pctl/pctl.h" #include "core/hle/service/pctl/pctl_module.h" +#include "core/hle/service/server_manager.h" namespace Service::PCTL { @@ -176,7 +177,7 @@ private: settings.is_stero_vision_restricted = is_restricted; } - void Initialize(Kernel::HLERequestContext& ctx) { + void Initialize(HLERequestContext& ctx) { LOG_DEBUG(Service_PCTL, "called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -214,7 +215,7 @@ private: rb.Push(ResultSuccess); } - void CheckFreeCommunicationPermission(Kernel::HLERequestContext& ctx) { + void CheckFreeCommunicationPermission(HLERequestContext& ctx) { LOG_DEBUG(Service_PCTL, "called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -227,7 +228,7 @@ private: states.free_communication = true; } - void ConfirmStereoVisionPermission(Kernel::HLERequestContext& ctx) { + void ConfirmStereoVisionPermission(HLERequestContext& ctx) { LOG_DEBUG(Service_PCTL, "called"); states.stereo_vision = true; @@ -235,14 +236,14 @@ private: rb.Push(ResultSuccess); } - void EndFreeCommunication(Kernel::HLERequestContext& ctx) { + void EndFreeCommunication(HLERequestContext& ctx) { LOG_WARNING(Service_PCTL, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void IsFreeCommunicationAvailable(Kernel::HLERequestContext& ctx) { + void IsFreeCommunicationAvailable(HLERequestContext& ctx) { LOG_WARNING(Service_PCTL, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -253,7 +254,7 @@ private: } } - void IsRestrictionEnabled(Kernel::HLERequestContext& ctx) { + void IsRestrictionEnabled(HLERequestContext& ctx) { LOG_DEBUG(Service_PCTL, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -267,7 +268,7 @@ private: rb.Push(pin_code[0] != '\0'); } - void ConfirmStereoVisionRestrictionConfigurable(Kernel::HLERequestContext& ctx) { + void ConfirmStereoVisionRestrictionConfigurable(HLERequestContext& ctx) { LOG_DEBUG(Service_PCTL, "called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -286,7 +287,7 @@ private: rb.Push(ResultSuccess); } - void IsStereoVisionPermitted(Kernel::HLERequestContext& ctx) { + void IsStereoVisionPermitted(HLERequestContext& ctx) { LOG_DEBUG(Service_PCTL, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -299,7 +300,7 @@ private: } } - void SetStereoVisionRestriction(Kernel::HLERequestContext& ctx) { + void SetStereoVisionRestriction(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto can_use = rp.Pop<bool>(); LOG_DEBUG(Service_PCTL, "called, can_use={}", can_use); @@ -315,7 +316,7 @@ private: rb.Push(ResultSuccess); } - void GetStereoVisionRestriction(Kernel::HLERequestContext& ctx) { + void GetStereoVisionRestriction(HLERequestContext& ctx) { LOG_DEBUG(Service_PCTL, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -330,7 +331,7 @@ private: rb.Push(settings.is_stero_vision_restricted); } - void ResetConfirmedStereoVisionPermission(Kernel::HLERequestContext& ctx) { + void ResetConfirmedStereoVisionPermission(HLERequestContext& ctx) { LOG_DEBUG(Service_PCTL, "called"); states.stereo_vision = false; @@ -369,7 +370,7 @@ private: Capability capability{}; }; -void Module::Interface::CreateService(Kernel::HLERequestContext& ctx) { +void Module::Interface::CreateService(HLERequestContext& ctx) { LOG_DEBUG(Service_PCTL, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -379,7 +380,7 @@ void Module::Interface::CreateService(Kernel::HLERequestContext& ctx) { rb.PushIpcInterface<IParentalControlService>(system, capability); } -void Module::Interface::CreateServiceWithoutInitialize(Kernel::HLERequestContext& ctx) { +void Module::Interface::CreateServiceWithoutInitialize(HLERequestContext& ctx) { LOG_DEBUG(Service_PCTL, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -393,19 +394,22 @@ Module::Interface::Interface(Core::System& system_, std::shared_ptr<Module> modu Module::Interface::~Interface() = default; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + auto module = std::make_shared<Module>(); - std::make_shared<PCTL>(system, module, "pctl", - Capability::Application | Capability::SnsPost | Capability::Status | - Capability::StereoVision) - ->InstallAsService(service_manager); + server_manager->RegisterNamedService( + "pctl", std::make_shared<PCTL>(system, module, "pctl", + Capability::Application | Capability::SnsPost | + Capability::Status | Capability::StereoVision)); // TODO(ogniK): Implement remaining capabilities - std::make_shared<PCTL>(system, module, "pctl:a", Capability::None) - ->InstallAsService(service_manager); - std::make_shared<PCTL>(system, module, "pctl:r", Capability::None) - ->InstallAsService(service_manager); - std::make_shared<PCTL>(system, module, "pctl:s", Capability::None) - ->InstallAsService(service_manager); + server_manager->RegisterNamedService( + "pctl:a", std::make_shared<PCTL>(system, module, "pctl:a", Capability::None)); + server_manager->RegisterNamedService( + "pctl:r", std::make_shared<PCTL>(system, module, "pctl:r", Capability::None)); + server_manager->RegisterNamedService( + "pctl:s", std::make_shared<PCTL>(system, module, "pctl:s", Capability::None)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::PCTL diff --git a/src/core/hle/service/pctl/pctl_module.h b/src/core/hle/service/pctl/pctl_module.h index 6f584530d..dff0d3f08 100644 --- a/src/core/hle/service/pctl/pctl_module.h +++ b/src/core/hle/service/pctl/pctl_module.h @@ -31,8 +31,8 @@ public: const char* name_, Capability capability_); ~Interface() override; - void CreateService(Kernel::HLERequestContext& ctx); - void CreateServiceWithoutInitialize(Kernel::HLERequestContext& ctx); + void CreateService(HLERequestContext& ctx); + void CreateServiceWithoutInitialize(HLERequestContext& ctx); protected: std::shared_ptr<Module> module; @@ -42,7 +42,6 @@ public: }; }; -/// Registers all PCTL services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::PCTL diff --git a/src/core/hle/service/pcv/pcv.cpp b/src/core/hle/service/pcv/pcv.cpp index 98037a8d4..c13ffa6f6 100644 --- a/src/core/hle/service/pcv/pcv.cpp +++ b/src/core/hle/service/pcv/pcv.cpp @@ -3,10 +3,10 @@ #include <memory> -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/pcv/pcv.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" namespace Service::PCV { @@ -76,7 +76,7 @@ public: } private: - void SetClockRate(Kernel::HLERequestContext& ctx) { + void SetClockRate(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; clock_rate = rp.Pop<u32>(); LOG_DEBUG(Service_PCV, "(STUBBED) called, clock_rate={}", clock_rate); @@ -85,7 +85,7 @@ private: rb.Push(ResultSuccess); } - void GetClockRate(Kernel::HLERequestContext& ctx) { + void GetClockRate(HLERequestContext& ctx) { LOG_DEBUG(Service_PCV, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -115,7 +115,7 @@ public: } private: - void OpenSession(Kernel::HLERequestContext& ctx) { + void OpenSession(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_code = static_cast<DeviceCode>(rp.Pop<u32>()); const auto unkonwn_input = rp.Pop<u32>(); @@ -141,11 +141,14 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<PCV>(system)->InstallAsService(sm); - std::make_shared<CLKRST>(system, "clkrst")->InstallAsService(sm); - std::make_shared<CLKRST>(system, "clkrst:i")->InstallAsService(sm); - std::make_shared<CLKRST_A>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("pcv", std::make_shared<PCV>(system)); + server_manager->RegisterNamedService("clkrst", std::make_shared<CLKRST>(system, "clkrst")); + server_manager->RegisterNamedService("clkrst:i", std::make_shared<CLKRST>(system, "clkrst:i")); + server_manager->RegisterNamedService("clkrst:a", std::make_shared<CLKRST_A>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::PCV diff --git a/src/core/hle/service/pcv/pcv.h b/src/core/hle/service/pcv/pcv.h index 6b26b6fa7..bf541e6fe 100644 --- a/src/core/hle/service/pcv/pcv.h +++ b/src/core/hle/service/pcv/pcv.h @@ -7,10 +7,6 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::PCV { enum class DeviceCode : u32 { @@ -104,6 +100,6 @@ enum class DeviceCode : u32 { OscClk = 0x40000080 }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::PCV diff --git a/src/core/hle/service/pm/pm.cpp b/src/core/hle/service/pm/pm.cpp index b10e86c8f..ea249c26f 100644 --- a/src/core/hle/service/pm/pm.cpp +++ b/src/core/hle/service/pm/pm.cpp @@ -2,10 +2,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_process.h" #include "core/hle/kernel/kernel.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/pm/pm.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" namespace Service::PM { @@ -33,7 +34,7 @@ std::optional<Kernel::KProcess*> SearchProcessList( return *iter; } -void GetApplicationPidGeneric(Kernel::HLERequestContext& ctx, +void GetApplicationPidGeneric(HLERequestContext& ctx, const std::vector<Kernel::KProcess*>& process_list) { const auto process = SearchProcessList(process_list, [](const auto& proc) { return proc->GetProcessID() == Kernel::KProcess::ProcessIDMin; @@ -57,7 +58,7 @@ public: } private: - void GetBootMode(Kernel::HLERequestContext& ctx) { + void GetBootMode(HLERequestContext& ctx) { LOG_DEBUG(Service_PM, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -65,7 +66,7 @@ private: rb.PushEnum(boot_mode); } - void SetMaintenanceBoot(Kernel::HLERequestContext& ctx) { + void SetMaintenanceBoot(HLERequestContext& ctx) { LOG_DEBUG(Service_PM, "called"); boot_mode = SystemBootMode::Maintenance; @@ -99,7 +100,7 @@ public: } private: - void GetProcessId(Kernel::HLERequestContext& ctx) { + void GetProcessId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto program_id = rp.PopRaw<u64>(); @@ -121,12 +122,12 @@ private: rb.Push((*process)->GetProcessID()); } - void GetApplicationProcessId(Kernel::HLERequestContext& ctx) { + void GetApplicationProcessId(HLERequestContext& ctx) { LOG_DEBUG(Service_PM, "called"); GetApplicationPidGeneric(ctx, kernel.GetProcessList()); } - void AtmosphereGetProcessInfo(Kernel::HLERequestContext& ctx) { + void AtmosphereGetProcessInfo(HLERequestContext& ctx) { // https://github.com/Atmosphere-NX/Atmosphere/blob/master/stratosphere/pm/source/impl/pm_process_manager.cpp#L614 // This implementation is incomplete; only a handle to the process is returned. IPC::RequestParser rp{ctx}; @@ -186,7 +187,7 @@ public: } private: - void GetProgramId(Kernel::HLERequestContext& ctx) { + void GetProgramId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto process_id = rp.PopRaw<u64>(); @@ -207,7 +208,7 @@ private: rb.Push((*process)->GetProgramID()); } - void AtmosphereGetProcessId(Kernel::HLERequestContext& ctx) { + void AtmosphereGetProcessId(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto program_id = rp.PopRaw<u64>(); @@ -254,7 +255,7 @@ public: } private: - void GetApplicationProcessIdForShell(Kernel::HLERequestContext& ctx) { + void GetApplicationProcessIdForShell(HLERequestContext& ctx) { LOG_DEBUG(Service_PM, "called"); GetApplicationPidGeneric(ctx, kernel.GetProcessList()); } @@ -262,12 +263,15 @@ private: const Kernel::KernelCore& kernel; }; -void InstallInterfaces(Core::System& system) { - std::make_shared<BootMode>(system)->InstallAsService(system.ServiceManager()); - std::make_shared<DebugMonitor>(system)->InstallAsService(system.ServiceManager()); - std::make_shared<Info>(system, system.Kernel().GetProcessList()) - ->InstallAsService(system.ServiceManager()); - std::make_shared<Shell>(system)->InstallAsService(system.ServiceManager()); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("pm:bm", std::make_shared<BootMode>(system)); + server_manager->RegisterNamedService("pm:dmnt", std::make_shared<DebugMonitor>(system)); + server_manager->RegisterNamedService( + "pm:info", std::make_shared<Info>(system, system.Kernel().GetProcessList())); + server_manager->RegisterNamedService("pm:shell", std::make_shared<Shell>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::PM diff --git a/src/core/hle/service/pm/pm.h b/src/core/hle/service/pm/pm.h index 060103928..5d4a1a171 100644 --- a/src/core/hle/service/pm/pm.h +++ b/src/core/hle/service/pm/pm.h @@ -14,7 +14,6 @@ enum class SystemBootMode { Maintenance, }; -/// Registers all PM services with the specified service manager. -void InstallInterfaces(Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::PM diff --git a/src/core/hle/service/prepo/prepo.cpp b/src/core/hle/service/prepo/prepo.cpp index 90c5f8756..ec4a84989 100644 --- a/src/core/hle/service/prepo/prepo.cpp +++ b/src/core/hle/service/prepo/prepo.cpp @@ -4,9 +4,10 @@ #include "common/hex_util.h" #include "common/logging/log.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/acc/profile_manager.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/prepo/prepo.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" #include "core/reporter.h" @@ -53,7 +54,7 @@ public: private: template <Core::Reporter::PlayReportType Type> - void SaveReport(Kernel::HLERequestContext& ctx) { + void SaveReport(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto process_id = rp.PopRaw<u64>(); @@ -79,7 +80,7 @@ private: } template <Core::Reporter::PlayReportType Type> - void SaveReportWithUser(Kernel::HLERequestContext& ctx) { + void SaveReportWithUser(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto user_id = rp.PopRaw<u128>(); const auto process_id = rp.PopRaw<u64>(); @@ -106,14 +107,14 @@ private: rb.Push(ResultSuccess); } - void RequestImmediateTransmission(Kernel::HLERequestContext& ctx) { + void RequestImmediateTransmission(HLERequestContext& ctx) { LOG_WARNING(Service_PREPO, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void GetTransmissionStatus(Kernel::HLERequestContext& ctx) { + void GetTransmissionStatus(HLERequestContext& ctx) { LOG_WARNING(Service_PREPO, "(STUBBED) called"); constexpr s32 status = 0; @@ -123,7 +124,7 @@ private: rb.Push(status); } - void GetSystemSessionId(Kernel::HLERequestContext& ctx) { + void GetSystemSessionId(HLERequestContext& ctx) { LOG_WARNING(Service_PREPO, "(STUBBED) called"); constexpr u64 system_session_id = 0; @@ -132,7 +133,7 @@ private: rb.Push(system_session_id); } - void SaveSystemReport(Kernel::HLERequestContext& ctx) { + void SaveSystemReport(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto title_id = rp.PopRaw<u64>(); @@ -155,7 +156,7 @@ private: rb.Push(ResultSuccess); } - void SaveSystemReportWithUser(Kernel::HLERequestContext& ctx) { + void SaveSystemReportWithUser(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto user_id = rp.PopRaw<u128>(); const auto title_id = rp.PopRaw<u64>(); @@ -183,12 +184,20 @@ private: } }; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<PlayReport>("prepo:a", system)->InstallAsService(service_manager); - std::make_shared<PlayReport>("prepo:a2", system)->InstallAsService(service_manager); - std::make_shared<PlayReport>("prepo:m", system)->InstallAsService(service_manager); - std::make_shared<PlayReport>("prepo:s", system)->InstallAsService(service_manager); - std::make_shared<PlayReport>("prepo:u", system)->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("prepo:a", + std::make_shared<PlayReport>("prepo:a", system)); + server_manager->RegisterNamedService("prepo:a2", + std::make_shared<PlayReport>("prepo:a2", system)); + server_manager->RegisterNamedService("prepo:m", + std::make_shared<PlayReport>("prepo:m", system)); + server_manager->RegisterNamedService("prepo:s", + std::make_shared<PlayReport>("prepo:s", system)); + server_manager->RegisterNamedService("prepo:u", + std::make_shared<PlayReport>("prepo:u", system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::PlayReport diff --git a/src/core/hle/service/prepo/prepo.h b/src/core/hle/service/prepo/prepo.h index 37ea5afad..2c2462f93 100644 --- a/src/core/hle/service/prepo/prepo.h +++ b/src/core/hle/service/prepo/prepo.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::PlayReport { -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::PlayReport diff --git a/src/core/hle/service/psc/psc.cpp b/src/core/hle/service/psc/psc.cpp index 3a9412cf5..cd0cc9287 100644 --- a/src/core/hle/service/psc/psc.cpp +++ b/src/core/hle/service/psc/psc.cpp @@ -4,16 +4,16 @@ #include <memory> #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/psc/psc.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" namespace Service::PSC { -class PSC_C final : public ServiceFramework<PSC_C> { +class IPmControl final : public ServiceFramework<IPmControl> { public: - explicit PSC_C(Core::System& system_) : ServiceFramework{system_, "psc:c"} { + explicit IPmControl(Core::System& system_) : ServiceFramework{system_, "psc:c"} { // clang-format off static const FunctionInfo functions[] = { {0, nullptr, "Initialize"}, @@ -23,8 +23,8 @@ public: {4, nullptr, "Cancel"}, {5, nullptr, "PrintModuleInformation"}, {6, nullptr, "GetModuleInformation"}, - {10, nullptr, "Unknown10"}, - {11, nullptr, "Unknown11"}, + {10, nullptr, "AcquireStateLock"}, + {11, nullptr, "HasStateLock"}, }; // clang-format on @@ -49,12 +49,12 @@ public: } }; -class PSC_M final : public ServiceFramework<PSC_M> { +class IPmService final : public ServiceFramework<IPmService> { public: - explicit PSC_M(Core::System& system_) : ServiceFramework{system_, "psc:m"} { + explicit IPmService(Core::System& system_) : ServiceFramework{system_, "psc:m"} { // clang-format off static const FunctionInfo functions[] = { - {0, &PSC_M::GetPmModule, "GetPmModule"}, + {0, &IPmService::GetPmModule, "GetPmModule"}, }; // clang-format on @@ -62,7 +62,7 @@ public: } private: - void GetPmModule(Kernel::HLERequestContext& ctx) { + void GetPmModule(HLERequestContext& ctx) { LOG_DEBUG(Service_PSC, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -71,9 +71,12 @@ private: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<PSC_C>(system)->InstallAsService(sm); - std::make_shared<PSC_M>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("psc:c", std::make_shared<IPmControl>(system)); + server_manager->RegisterNamedService("psc:m", std::make_shared<IPmService>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::PSC diff --git a/src/core/hle/service/psc/psc.h b/src/core/hle/service/psc/psc.h index d248372c2..459137f42 100644 --- a/src/core/hle/service/psc/psc.h +++ b/src/core/hle/service/psc/psc.h @@ -13,6 +13,6 @@ class ServiceManager; namespace Service::PSC { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::PSC diff --git a/src/core/hle/service/ptm/psm.cpp b/src/core/hle/service/ptm/psm.cpp index 1ac97fe31..136313d7b 100644 --- a/src/core/hle/service/ptm/psm.cpp +++ b/src/core/hle/service/ptm/psm.cpp @@ -5,8 +5,8 @@ #include "common/logging/log.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_event.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/kernel_helpers.h" #include "core/hle/service/ptm/psm.h" @@ -54,7 +54,7 @@ public: } private: - void BindStateChangeEvent(Kernel::HLERequestContext& ctx) { + void BindStateChangeEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_PTM, "called"); should_signal = true; @@ -64,7 +64,7 @@ private: rb.PushCopyObjects(state_change_event->GetReadableEvent()); } - void UnbindStateChangeEvent(Kernel::HLERequestContext& ctx) { + void UnbindStateChangeEvent(HLERequestContext& ctx) { LOG_DEBUG(Service_PTM, "called"); should_signal = false; @@ -73,7 +73,7 @@ private: rb.Push(ResultSuccess); } - void SetChargerTypeChangeEventEnabled(Kernel::HLERequestContext& ctx) { + void SetChargerTypeChangeEventEnabled(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto state = rp.Pop<bool>(); LOG_DEBUG(Service_PTM, "called, state={}", state); @@ -84,7 +84,7 @@ private: rb.Push(ResultSuccess); } - void SetPowerSupplyChangeEventEnabled(Kernel::HLERequestContext& ctx) { + void SetPowerSupplyChangeEventEnabled(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto state = rp.Pop<bool>(); LOG_DEBUG(Service_PTM, "called, state={}", state); @@ -95,7 +95,7 @@ private: rb.Push(ResultSuccess); } - void SetBatteryVoltageStateChangeEventEnabled(Kernel::HLERequestContext& ctx) { + void SetBatteryVoltageStateChangeEventEnabled(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto state = rp.Pop<bool>(); LOG_DEBUG(Service_PTM, "called, state={}", state); @@ -145,7 +145,7 @@ PSM::PSM(Core::System& system_) : ServiceFramework{system_, "psm"} { PSM::~PSM() = default; -void PSM::GetBatteryChargePercentage(Kernel::HLERequestContext& ctx) { +void PSM::GetBatteryChargePercentage(HLERequestContext& ctx) { LOG_DEBUG(Service_PTM, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -153,7 +153,7 @@ void PSM::GetBatteryChargePercentage(Kernel::HLERequestContext& ctx) { rb.Push<u32>(battery_charge_percentage); } -void PSM::GetChargerType(Kernel::HLERequestContext& ctx) { +void PSM::GetChargerType(HLERequestContext& ctx) { LOG_DEBUG(Service_PTM, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -161,7 +161,7 @@ void PSM::GetChargerType(Kernel::HLERequestContext& ctx) { rb.PushEnum(charger_type); } -void PSM::OpenSession(Kernel::HLERequestContext& ctx) { +void PSM::OpenSession(HLERequestContext& ctx) { LOG_DEBUG(Service_PTM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; diff --git a/src/core/hle/service/ptm/psm.h b/src/core/hle/service/ptm/psm.h index f674ba8bc..fa47919e5 100644 --- a/src/core/hle/service/ptm/psm.h +++ b/src/core/hle/service/ptm/psm.h @@ -20,9 +20,9 @@ private: Unknown = 3, }; - void GetBatteryChargePercentage(Kernel::HLERequestContext& ctx); - void GetChargerType(Kernel::HLERequestContext& ctx); - void OpenSession(Kernel::HLERequestContext& ctx); + void GetBatteryChargePercentage(HLERequestContext& ctx); + void GetChargerType(HLERequestContext& ctx); + void OpenSession(HLERequestContext& ctx); u32 battery_charge_percentage{100}; ChargerType charger_type{ChargerType::RegularCharger}; diff --git a/src/core/hle/service/ptm/ptm.cpp b/src/core/hle/service/ptm/ptm.cpp index 4bea995c6..6f0cfe04b 100644 --- a/src/core/hle/service/ptm/ptm.cpp +++ b/src/core/hle/service/ptm/ptm.cpp @@ -7,12 +7,16 @@ #include "core/hle/service/ptm/psm.h" #include "core/hle/service/ptm/ptm.h" #include "core/hle/service/ptm/ts.h" +#include "core/hle/service/server_manager.h" namespace Service::PTM { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<PSM>(system)->InstallAsService(sm); - std::make_shared<TS>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("psm", std::make_shared<PSM>(system)); + server_manager->RegisterNamedService("ts", std::make_shared<TS>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::PTM diff --git a/src/core/hle/service/ptm/ptm.h b/src/core/hle/service/ptm/ptm.h index 06224a24e..a0ae03d28 100644 --- a/src/core/hle/service/ptm/ptm.h +++ b/src/core/hle/service/ptm/ptm.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::PTM { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::PTM diff --git a/src/core/hle/service/ptm/ts.cpp b/src/core/hle/service/ptm/ts.cpp index b1a0a5544..ca064dd90 100644 --- a/src/core/hle/service/ptm/ts.cpp +++ b/src/core/hle/service/ptm/ts.cpp @@ -4,7 +4,7 @@ #include <memory> #include "core/core.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ptm/ts.h" namespace Service::PTM { @@ -25,7 +25,7 @@ TS::TS(Core::System& system_) : ServiceFramework{system_, "ts"} { TS::~TS() = default; -void TS::GetTemperature(Kernel::HLERequestContext& ctx) { +void TS::GetTemperature(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto location{rp.PopEnum<Location>()}; @@ -36,7 +36,7 @@ void TS::GetTemperature(Kernel::HLERequestContext& ctx) { rb.Push(temperature); } -void TS::GetTemperatureMilliC(Kernel::HLERequestContext& ctx) { +void TS::GetTemperatureMilliC(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto location{rp.PopEnum<Location>()}; diff --git a/src/core/hle/service/ptm/ts.h b/src/core/hle/service/ptm/ts.h index 39d51847e..c3f43d5a3 100644 --- a/src/core/hle/service/ptm/ts.h +++ b/src/core/hle/service/ptm/ts.h @@ -19,8 +19,8 @@ private: External, }; - void GetTemperature(Kernel::HLERequestContext& ctx); - void GetTemperatureMilliC(Kernel::HLERequestContext& ctx); + void GetTemperature(HLERequestContext& ctx); + void GetTemperatureMilliC(HLERequestContext& ctx); }; } // namespace Service::PTM diff --git a/src/core/hle/service/server_manager.cpp b/src/core/hle/service/server_manager.cpp new file mode 100644 index 000000000..bd04cd023 --- /dev/null +++ b/src/core/hle/service/server_manager.cpp @@ -0,0 +1,448 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "common/scope_exit.h" + +#include "core/core.h" +#include "core/hle/kernel/k_client_port.h" +#include "core/hle/kernel/k_client_session.h" +#include "core/hle/kernel/k_event.h" +#include "core/hle/kernel/k_object_name.h" +#include "core/hle/kernel/k_port.h" +#include "core/hle/kernel/k_server_port.h" +#include "core/hle/kernel/k_server_session.h" +#include "core/hle/kernel/k_synchronization_object.h" +#include "core/hle/kernel/svc_results.h" +#include "core/hle/service/hle_ipc.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" +#include "core/hle/service/sm/sm.h" + +namespace Service { + +constexpr size_t MaximumWaitObjects = 0x40; + +enum HandleType { + Port, + Session, + DeferEvent, + Event, +}; + +ServerManager::ServerManager(Core::System& system) : m_system{system}, m_serve_mutex{system} { + // Initialize event. + m_event = Kernel::KEvent::Create(system.Kernel()); + m_event->Initialize(nullptr); +} + +ServerManager::~ServerManager() { + // Signal stop. + m_stop_source.request_stop(); + m_event->Signal(); + + // Wait for processing to stop. + m_stopped.wait(false); + m_threads.clear(); + + // Clean up ports. + for (const auto& [port, handler] : m_ports) { + port->Close(); + } + + // Clean up sessions. + for (const auto& [session, manager] : m_sessions) { + session->Close(); + } + + for (const auto& request : m_deferrals) { + request.session->Close(); + } + + // Close event. + m_event->GetReadableEvent().Close(); + m_event->Close(); + + if (m_deferral_event) { + m_deferral_event->GetReadableEvent().Close(); + // Write event is owned by ServiceManager + } +} + +void ServerManager::RunServer(std::unique_ptr<ServerManager>&& server_manager) { + server_manager->m_system.RunServer(std::move(server_manager)); +} + +Result ServerManager::RegisterSession(Kernel::KServerSession* session, + std::shared_ptr<SessionRequestManager> manager) { + ASSERT(m_sessions.size() + m_ports.size() < MaximumWaitObjects); + + // We are taking ownership of the server session, so don't open it. + // Begin tracking the server session. + { + std::scoped_lock ll{m_list_mutex}; + m_sessions.emplace(session, std::move(manager)); + } + + // Signal the wakeup event. + m_event->Signal(); + + R_SUCCEED(); +} + +Result ServerManager::RegisterNamedService(const std::string& service_name, + std::shared_ptr<SessionRequestHandler>&& handler, + u32 max_sessions) { + ASSERT(m_sessions.size() + m_ports.size() < MaximumWaitObjects); + + // Add the new server to sm:. + ASSERT(R_SUCCEEDED( + m_system.ServiceManager().RegisterService(service_name, max_sessions, handler))); + + // Get the registered port. + auto port = m_system.ServiceManager().GetServicePort(service_name); + ASSERT(port.Succeeded()); + + // Open a new reference to the server port. + (*port)->GetServerPort().Open(); + + // Begin tracking the server port. + { + std::scoped_lock ll{m_list_mutex}; + m_ports.emplace(std::addressof((*port)->GetServerPort()), std::move(handler)); + } + + // Signal the wakeup event. + m_event->Signal(); + + R_SUCCEED(); +} + +Result ServerManager::ManageNamedPort(const std::string& service_name, + std::shared_ptr<SessionRequestHandler>&& handler, + u32 max_sessions) { + ASSERT(m_sessions.size() + m_ports.size() < MaximumWaitObjects); + + // Create a new port. + auto* port = Kernel::KPort::Create(m_system.Kernel()); + port->Initialize(max_sessions, false, service_name); + + // Register the port. + Kernel::KPort::Register(m_system.Kernel(), port); + + // Ensure that our reference to the port is closed if we fail to register it. + SCOPE_EXIT({ + port->GetClientPort().Close(); + port->GetServerPort().Close(); + }); + + // Register the object name with the kernel. + R_TRY(Kernel::KObjectName::NewFromName(m_system.Kernel(), std::addressof(port->GetClientPort()), + service_name.c_str())); + + // Open a new reference to the server port. + port->GetServerPort().Open(); + + // Begin tracking the server port. + { + std::scoped_lock ll{m_list_mutex}; + m_ports.emplace(std::addressof(port->GetServerPort()), std::move(handler)); + } + + // We succeeded. + R_SUCCEED(); +} + +Result ServerManager::ManageDeferral(Kernel::KEvent** out_event) { + // Create a new event. + m_deferral_event = Kernel::KEvent::Create(m_system.Kernel()); + ASSERT(m_deferral_event != nullptr); + + // Initialize the event. + m_deferral_event->Initialize(nullptr); + + // Set the output. + *out_event = m_deferral_event; + + // We succeeded. + R_SUCCEED(); +} + +void ServerManager::StartAdditionalHostThreads(const char* name, size_t num_threads) { + for (size_t i = 0; i < num_threads; i++) { + auto thread_name = fmt::format("{}:{}", name, i + 1); + m_threads.emplace_back(m_system.Kernel().RunOnHostCoreThread( + std::move(thread_name), [&] { this->LoopProcessImpl(); })); + } +} + +Result ServerManager::LoopProcess() { + SCOPE_EXIT({ + m_stopped.store(true); + m_stopped.notify_all(); + }); + + R_RETURN(this->LoopProcessImpl()); +} + +Result ServerManager::LoopProcessImpl() { + while (!m_stop_source.stop_requested()) { + R_TRY(this->WaitAndProcessImpl()); + } + + R_SUCCEED(); +} + +Result ServerManager::WaitAndProcessImpl() { + Kernel::KScopedAutoObject<Kernel::KSynchronizationObject> wait_obj; + HandleType wait_type{}; + + // Ensure we are the only thread waiting for this server. + std::unique_lock sl{m_serve_mutex}; + + // If we're done, return before we start waiting. + R_SUCCEED_IF(m_stop_source.stop_requested()); + + // Wait for a tracked object to become signaled. + { + s32 num_objs{}; + std::array<HandleType, MaximumWaitObjects> wait_types{}; + std::array<Kernel::KSynchronizationObject*, MaximumWaitObjects> wait_objs{}; + + const auto AddWaiter{ + [&](Kernel::KSynchronizationObject* synchronization_object, HandleType type) { + // Open a new reference to the object. + synchronization_object->Open(); + + // Insert into the list. + wait_types[num_objs] = type; + wait_objs[num_objs++] = synchronization_object; + }}; + + { + std::scoped_lock ll{m_list_mutex}; + + // Add all of our ports. + for (const auto& [port, handler] : m_ports) { + AddWaiter(port, HandleType::Port); + } + + // Add all of our sessions. + for (const auto& [session, manager] : m_sessions) { + AddWaiter(session, HandleType::Session); + } + } + + // Add the deferral wakeup event. + if (m_deferral_event != nullptr) { + AddWaiter(std::addressof(m_deferral_event->GetReadableEvent()), HandleType::DeferEvent); + } + + // Add the wakeup event. + AddWaiter(std::addressof(m_event->GetReadableEvent()), HandleType::Event); + + // Clean up extra references on exit. + SCOPE_EXIT({ + for (s32 i = 0; i < num_objs; i++) { + wait_objs[i]->Close(); + } + }); + + // Wait for a signal. + s32 out_index{-1}; + R_TRY(Kernel::KSynchronizationObject::Wait(m_system.Kernel(), &out_index, wait_objs.data(), + num_objs, -1)); + ASSERT(out_index >= 0 && out_index < num_objs); + + // Set the output index. + wait_obj = wait_objs[out_index]; + wait_type = wait_types[out_index]; + } + + // Process what we just received, temporarily removing the object so it is + // not processed concurrently by another thread. + { + switch (wait_type) { + case HandleType::Port: { + // Port signaled. + auto* port = wait_obj->DynamicCast<Kernel::KServerPort*>(); + std::shared_ptr<SessionRequestHandler> handler; + + // Remove from tracking. + { + std::scoped_lock ll{m_list_mutex}; + ASSERT(m_ports.contains(port)); + m_ports.at(port).swap(handler); + m_ports.erase(port); + } + + // Allow other threads to serve. + sl.unlock(); + + // Finish. + R_RETURN(this->OnPortEvent(port, std::move(handler))); + } + case HandleType::Session: { + // Session signaled. + auto* session = wait_obj->DynamicCast<Kernel::KServerSession*>(); + std::shared_ptr<SessionRequestManager> manager; + + // Remove from tracking. + { + std::scoped_lock ll{m_list_mutex}; + ASSERT(m_sessions.contains(session)); + m_sessions.at(session).swap(manager); + m_sessions.erase(session); + } + + // Allow other threads to serve. + sl.unlock(); + + // Finish. + R_RETURN(this->OnSessionEvent(session, std::move(manager))); + } + case HandleType::DeferEvent: { + // Clear event. + ASSERT(R_SUCCEEDED(m_deferral_event->Clear())); + + // Drain the list of deferrals while we process. + std::list<RequestState> deferrals; + { + std::scoped_lock ll{m_list_mutex}; + m_deferrals.swap(deferrals); + } + + // Allow other threads to serve. + sl.unlock(); + + // Finish. + R_RETURN(this->OnDeferralEvent(std::move(deferrals))); + } + case HandleType::Event: { + // Clear event and finish. + R_RETURN(m_event->Clear()); + } + default: { + UNREACHABLE(); + } + } + } +} + +Result ServerManager::OnPortEvent(Kernel::KServerPort* port, + std::shared_ptr<SessionRequestHandler>&& handler) { + // Accept a new server session. + Kernel::KServerSession* session = port->AcceptSession(); + ASSERT(session != nullptr); + + // Create the session manager and install the handler. + auto manager = std::make_shared<SessionRequestManager>(m_system.Kernel(), *this); + manager->SetSessionHandler(std::shared_ptr(handler)); + + // Track the server session. + { + std::scoped_lock ll{m_list_mutex}; + m_ports.emplace(port, std::move(handler)); + m_sessions.emplace(session, std::move(manager)); + } + + // Signal the wakeup event. + m_event->Signal(); + + // We succeeded. + R_SUCCEED(); +} + +Result ServerManager::OnSessionEvent(Kernel::KServerSession* session, + std::shared_ptr<SessionRequestManager>&& manager) { + Result rc{ResultSuccess}; + + // Try to receive a message. + std::shared_ptr<HLERequestContext> context; + rc = session->ReceiveRequest(&context, manager); + + // If the session has been closed, we're done. + if (rc == Kernel::ResultSessionClosed) { + // Close the session. + session->Close(); + + // Finish. + R_SUCCEED(); + } + ASSERT(R_SUCCEEDED(rc)); + + RequestState request{ + .session = session, + .context = std::move(context), + .manager = std::move(manager), + }; + + // Complete the sync request with deferral handling. + R_RETURN(this->CompleteSyncRequest(std::move(request))); +} + +Result ServerManager::CompleteSyncRequest(RequestState&& request) { + Result rc{ResultSuccess}; + Result service_rc{ResultSuccess}; + + // Mark the request as not deferred. + request.context->SetIsDeferred(false); + + // Complete the request. We have exclusive access to this session. + service_rc = request.manager->CompleteSyncRequest(request.session, *request.context); + + // If we've been deferred, we're done. + if (request.context->GetIsDeferred()) { + // Insert into deferral list. + std::scoped_lock ll{m_list_mutex}; + m_deferrals.emplace_back(std::move(request)); + + // Finish. + R_SUCCEED(); + } + + // Send the reply. + rc = request.session->SendReplyHLE(); + + // If the session has been closed, we're done. + if (rc == Kernel::ResultSessionClosed || service_rc == IPC::ResultSessionClosed) { + // Close the session. + request.session->Close(); + + // Finish. + R_SUCCEED(); + } + + ASSERT(R_SUCCEEDED(rc)); + ASSERT(R_SUCCEEDED(service_rc)); + + // Reinsert the session. + { + std::scoped_lock ll{m_list_mutex}; + m_sessions.emplace(request.session, std::move(request.manager)); + } + + // Signal the wakeup event. + m_event->Signal(); + + // We succeeded. + R_SUCCEED(); +} + +Result ServerManager::OnDeferralEvent(std::list<RequestState>&& deferrals) { + ON_RESULT_FAILURE { + std::scoped_lock ll{m_list_mutex}; + m_deferrals.splice(m_deferrals.end(), deferrals); + }; + + while (!deferrals.empty()) { + RequestState request = deferrals.front(); + deferrals.pop_front(); + + // Try again to complete the request. + R_TRY(this->CompleteSyncRequest(std::move(request))); + } + + R_SUCCEED(); +} + +} // namespace Service diff --git a/src/core/hle/service/server_manager.h b/src/core/hle/service/server_manager.h new file mode 100644 index 000000000..fdb8af2ff --- /dev/null +++ b/src/core/hle/service/server_manager.h @@ -0,0 +1,90 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <atomic> +#include <functional> +#include <list> +#include <map> +#include <mutex> +#include <string_view> +#include <vector> + +#include "common/polyfill_thread.h" +#include "core/hle/result.h" +#include "core/hle/service/mutex.h" + +namespace Core { +class System; +} + +namespace Kernel { +class KEvent; +class KServerPort; +class KServerSession; +class KSynchronizationObject; +} // namespace Kernel + +namespace Service { + +class HLERequestContext; +class SessionRequestHandler; +class SessionRequestManager; + +class ServerManager { +public: + explicit ServerManager(Core::System& system); + ~ServerManager(); + + Result RegisterSession(Kernel::KServerSession* session, + std::shared_ptr<SessionRequestManager> manager); + Result RegisterNamedService(const std::string& service_name, + std::shared_ptr<SessionRequestHandler>&& handler, + u32 max_sessions = 64); + Result ManageNamedPort(const std::string& service_name, + std::shared_ptr<SessionRequestHandler>&& handler, u32 max_sessions = 64); + Result ManageDeferral(Kernel::KEvent** out_event); + + Result LoopProcess(); + void StartAdditionalHostThreads(const char* name, size_t num_threads); + + static void RunServer(std::unique_ptr<ServerManager>&& server); + +private: + struct RequestState; + + Result LoopProcessImpl(); + Result WaitAndProcessImpl(); + Result OnPortEvent(Kernel::KServerPort* port, std::shared_ptr<SessionRequestHandler>&& handler); + Result OnSessionEvent(Kernel::KServerSession* session, + std::shared_ptr<SessionRequestManager>&& manager); + Result OnDeferralEvent(std::list<RequestState>&& deferrals); + Result CompleteSyncRequest(RequestState&& state); + +private: + Core::System& m_system; + Mutex m_serve_mutex; + std::mutex m_list_mutex; + + // Guest state tracking + std::map<Kernel::KServerPort*, std::shared_ptr<SessionRequestHandler>> m_ports{}; + std::map<Kernel::KServerSession*, std::shared_ptr<SessionRequestManager>> m_sessions{}; + Kernel::KEvent* m_event{}; + Kernel::KEvent* m_deferral_event{}; + + // Deferral tracking + struct RequestState { + Kernel::KServerSession* session; + std::shared_ptr<HLERequestContext> context; + std::shared_ptr<SessionRequestManager> manager; + }; + std::list<RequestState> m_deferrals{}; + + // Host state tracking + std::atomic<bool> m_stopped{}; + std::vector<std::jthread> m_threads{}; + std::stop_source m_stop_source{}; +}; + +} // namespace Service diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 1ffc1c694..69cdb5918 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -7,7 +7,6 @@ #include "common/settings.h" #include "core/core.h" #include "core/hle/ipc.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_process.h" #include "core/hle/kernel/k_server_port.h" #include "core/hle/kernel/kernel.h" @@ -31,6 +30,7 @@ #include "core/hle/service/glue/glue.h" #include "core/hle/service/grc/grc.h" #include "core/hle/service/hid/hid.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/jit/jit.h" #include "core/hle/service/lbl/lbl.h" #include "core/hle/service/ldn/ldn.h" @@ -49,8 +49,8 @@ #include "core/hle/service/npns/npns.h" #include "core/hle/service/ns/ns.h" #include "core/hle/service/nvdrv/nvdrv.h" -#include "core/hle/service/nvflinger/hos_binder_driver_server.h" -#include "core/hle/service/nvflinger/nvflinger.h" +#include "core/hle/service/nvnflinger/hos_binder_driver_server.h" +#include "core/hle/service/nvnflinger/nvnflinger.h" #include "core/hle/service/olsc/olsc.h" #include "core/hle/service/pcie/pcie.h" #include "core/hle/service/pctl/pctl_module.h" @@ -90,44 +90,13 @@ namespace Service { } ServiceFrameworkBase::ServiceFrameworkBase(Core::System& system_, const char* service_name_, - ServiceThreadType thread_type, u32 max_sessions_, - InvokerFn* handler_invoker_) - : SessionRequestHandler(system_.Kernel(), service_name_, thread_type), system{system_}, + u32 max_sessions_, InvokerFn* handler_invoker_) + : SessionRequestHandler(system_.Kernel(), service_name_), system{system_}, service_name{service_name_}, max_sessions{max_sessions_}, handler_invoker{handler_invoker_} {} ServiceFrameworkBase::~ServiceFrameworkBase() { // Wait for other threads to release access before destroying const auto guard = LockService(); - - if (named_port != nullptr) { - named_port->GetClientPort().Close(); - named_port->GetServerPort().Close(); - named_port = nullptr; - } -} - -void ServiceFrameworkBase::InstallAsService(SM::ServiceManager& service_manager) { - const auto guard = LockService(); - - ASSERT(!service_registered); - - service_manager.RegisterService(service_name, max_sessions, shared_from_this()); - service_registered = true; -} - -Kernel::KClientPort& ServiceFrameworkBase::CreatePort() { - const auto guard = LockService(); - - if (named_port == nullptr) { - ASSERT(!service_registered); - - named_port = Kernel::KPort::Create(kernel); - named_port->Initialize(max_sessions, false, service_name); - - service_registered = true; - } - - return named_port->GetClientPort(); } void ServiceFrameworkBase::RegisterHandlersBase(const FunctionInfoBase* functions, std::size_t n) { @@ -148,7 +117,7 @@ void ServiceFrameworkBase::RegisterHandlersBaseTipc(const FunctionInfoBase* func } } -void ServiceFrameworkBase::ReportUnimplementedFunction(Kernel::HLERequestContext& ctx, +void ServiceFrameworkBase::ReportUnimplementedFunction(HLERequestContext& ctx, const FunctionInfoBase* info) { auto cmd_buf = ctx.CommandBuffer(); std::string function_name = info == nullptr ? fmt::format("{}", ctx.GetCommand()) : info->name; @@ -171,7 +140,7 @@ void ServiceFrameworkBase::ReportUnimplementedFunction(Kernel::HLERequestContext } } -void ServiceFrameworkBase::InvokeRequest(Kernel::HLERequestContext& ctx) { +void ServiceFrameworkBase::InvokeRequest(HLERequestContext& ctx) { auto itr = handlers.find(ctx.GetCommand()); const FunctionInfoBase* info = itr == handlers.end() ? nullptr : &itr->second; if (info == nullptr || info->handler_callback == nullptr) { @@ -182,7 +151,7 @@ void ServiceFrameworkBase::InvokeRequest(Kernel::HLERequestContext& ctx) { handler_invoker(this, info->handler_callback, ctx); } -void ServiceFrameworkBase::InvokeRequestTipc(Kernel::HLERequestContext& ctx) { +void ServiceFrameworkBase::InvokeRequestTipc(HLERequestContext& ctx) { boost::container::flat_map<u32, FunctionInfoBase>::iterator itr; itr = handlers_tipc.find(ctx.GetCommand()); @@ -197,7 +166,7 @@ void ServiceFrameworkBase::InvokeRequestTipc(Kernel::HLERequestContext& ctx) { } Result ServiceFrameworkBase::HandleSyncRequest(Kernel::KServerSession& session, - Kernel::HLERequestContext& ctx) { + HLERequestContext& ctx) { const auto guard = LockService(); Result result = ResultSuccess; @@ -207,7 +176,7 @@ Result ServiceFrameworkBase::HandleSyncRequest(Kernel::KServerSession& session, case IPC::CommandType::TIPC_Close: { IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); - result = IPC::ERR_REMOTE_PROCESS_DEAD; + result = IPC::ResultSessionClosed; break; } case IPC::CommandType::ControlWithContext: @@ -241,70 +210,72 @@ Result ServiceFrameworkBase::HandleSyncRequest(Kernel::KServerSession& session, /// Initialize Services Services::Services(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system) - : hos_binder_driver_server{std::make_unique<NVFlinger::HosBinderDriverServer>(system)}, - nv_flinger{std::make_unique<NVFlinger::NVFlinger>(system, *hos_binder_driver_server)} { + : hos_binder_driver_server{std::make_unique<Nvnflinger::HosBinderDriverServer>(system)}, + nv_flinger{std::make_unique<Nvnflinger::Nvnflinger>(system, *hos_binder_driver_server)} { - // NVFlinger needs to be accessed by several services like Vi and AppletOE so we instantiate it - // here and pass it into the respective InstallInterfaces functions. + auto& kernel = system.Kernel(); + // Nvnflinger needs to be accessed by several services like Vi and AppletOE so we instantiate it + // here and pass it into the respective InstallInterfaces functions. system.GetFileSystemController().CreateFactories(*system.GetFilesystem(), false); - system.Kernel().RegisterNamedService("sm:", SM::ServiceManager::InterfaceFactory); - system.Kernel().RegisterInterfaceForNamedService("sm:", SM::ServiceManager::SessionHandler); - - Account::InstallInterfaces(system); - AM::InstallInterfaces(*sm, *nv_flinger, system); - AOC::InstallInterfaces(*sm, system); - APM::InstallInterfaces(system); - Audio::InstallInterfaces(*sm, system); - BCAT::InstallInterfaces(system); - BPC::InstallInterfaces(*sm, system); - BtDrv::InstallInterfaces(*sm, system); - BTM::InstallInterfaces(*sm, system); - Capture::InstallInterfaces(*sm, system); - ERPT::InstallInterfaces(*sm, system); - ES::InstallInterfaces(*sm, system); - EUPLD::InstallInterfaces(*sm, system); - Fatal::InstallInterfaces(*sm, system); - FGM::InstallInterfaces(*sm, system); - FileSystem::InstallInterfaces(system); - Friend::InstallInterfaces(*sm, system); - Glue::InstallInterfaces(system); - GRC::InstallInterfaces(*sm, system); - HID::InstallInterfaces(*sm, system); - JIT::InstallInterfaces(*sm, system); - LBL::InstallInterfaces(*sm, system); - LDN::InstallInterfaces(*sm, system); - LDR::InstallInterfaces(*sm, system); - LM::InstallInterfaces(system); - Migration::InstallInterfaces(*sm, system); - Mii::InstallInterfaces(*sm, system); - MM::InstallInterfaces(*sm, system); - MNPP::InstallInterfaces(*sm, system); - NCM::InstallInterfaces(*sm, system); - NFC::InstallInterfaces(*sm, system); - NFP::InstallInterfaces(*sm, system); - NGCT::InstallInterfaces(*sm, system); - NIFM::InstallInterfaces(*sm, system); - NIM::InstallInterfaces(*sm, system); - NPNS::InstallInterfaces(*sm, system); - NS::InstallInterfaces(*sm, system); - Nvidia::InstallInterfaces(*sm, *nv_flinger, system); - OLSC::InstallInterfaces(*sm, system); - PCIe::InstallInterfaces(*sm, system); - PCTL::InstallInterfaces(*sm, system); - PCV::InstallInterfaces(*sm, system); - PlayReport::InstallInterfaces(*sm, system); - PM::InstallInterfaces(system); - PSC::InstallInterfaces(*sm, system); - PTM::InstallInterfaces(*sm, system); - Set::InstallInterfaces(*sm, system); - Sockets::InstallInterfaces(*sm, system); - SPL::InstallInterfaces(*sm, system); - SSL::InstallInterfaces(*sm, system); - Time::InstallInterfaces(system); - USB::InstallInterfaces(*sm, system); - VI::InstallInterfaces(*sm, system, *nv_flinger, *hos_binder_driver_server); + // clang-format off + kernel.RunOnHostCoreProcess("audio", [&] { Audio::LoopProcess(system); }).detach(); + kernel.RunOnHostCoreProcess("FS", [&] { FileSystem::LoopProcess(system); }).detach(); + kernel.RunOnHostCoreProcess("jit", [&] { JIT::LoopProcess(system); }).detach(); + kernel.RunOnHostCoreProcess("ldn", [&] { LDN::LoopProcess(system); }).detach(); + kernel.RunOnHostCoreProcess("Loader", [&] { LDR::LoopProcess(system); }).detach(); + kernel.RunOnHostCoreProcess("nvservices", [&] { Nvidia::LoopProcess(*nv_flinger, system); }).detach(); + kernel.RunOnHostCoreProcess("bsdsocket", [&] { Sockets::LoopProcess(system); }).detach(); + kernel.RunOnHostCoreProcess("vi", [&] { VI::LoopProcess(system, *nv_flinger, *hos_binder_driver_server); }).detach(); + + kernel.RunOnGuestCoreProcess("sm", [&] { SM::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("account", [&] { Account::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("am", [&] { AM::LoopProcess(*nv_flinger, system); }); + kernel.RunOnGuestCoreProcess("aoc", [&] { AOC::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("apm", [&] { APM::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("bcat", [&] { BCAT::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("bpc", [&] { BPC::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("btdrv", [&] { BtDrv::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("btm", [&] { BTM::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("capsrv", [&] { Capture::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("erpt", [&] { ERPT::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("es", [&] { ES::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("eupld", [&] { EUPLD::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("fatal", [&] { Fatal::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("fgm", [&] { FGM::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("friends", [&] { Friend::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("glue", [&] { Glue::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("grc", [&] { GRC::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("hid", [&] { HID::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("lbl", [&] { LBL::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("LogManager.Prod", [&] { LM::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("mig", [&] { Migration::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("mii", [&] { Mii::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("mm", [&] { MM::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("mnpp", [&] { MNPP::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("NCM", [&] { NCM::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("nfc", [&] { NFC::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("nfp", [&] { NFP::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("ngct", [&] { NGCT::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("nifm", [&] { NIFM::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("nim", [&] { NIM::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("npns", [&] { NPNS::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("ns", [&] { NS::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("olsc", [&] { OLSC::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("pcie", [&] { PCIe::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("pctl", [&] { PCTL::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("pcv", [&] { PCV::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("prepo", [&] { PlayReport::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("ProcessManager", [&] { PM::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("psc", [&] { PSC::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("ptm", [&] { PTM::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("settings", [&] { Set::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("spl", [&] { SPL::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("ssl", [&] { SSL::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("time", [&] { Time::LoopProcess(system); }); + kernel.RunOnGuestCoreProcess("usb", [&] { USB::LoopProcess(system); }); + // clang-format on } Services::~Services() = default; diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 22e2119d7..0f79a1b7e 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -8,7 +8,7 @@ #include <string> #include <boost/container/flat_map.hpp> #include "common/common_types.h" -#include "core/hle/kernel/hle_ipc.h" +#include "core/hle/service/hle_ipc.h" //////////////////////////////////////////////////////////////////////////////////////////////////// // Namespace Service @@ -18,9 +18,6 @@ class System; } namespace Kernel { -class HLERequestContext; -class KClientPort; -class KPort; class KServerSession; class ServiceThread; } // namespace Kernel @@ -31,10 +28,10 @@ namespace FileSystem { class FileSystemController; } -namespace NVFlinger { +namespace Nvnflinger { class HosBinderDriverServer; -class NVFlinger; -} // namespace NVFlinger +class Nvnflinger; +} // namespace Nvnflinger namespace SM { class ServiceManager; @@ -52,7 +49,7 @@ static_assert(ServerSessionCountMax == 0x40, * * @see ServiceFramework */ -class ServiceFrameworkBase : public Kernel::SessionRequestHandler { +class ServiceFrameworkBase : public SessionRequestHandler { public: /// Returns the string identifier used to connect to the service. std::string GetServiceName() const { @@ -67,26 +64,19 @@ public: return max_sessions; } - /// Creates a port pair and registers this service with the given ServiceManager. - void InstallAsService(SM::ServiceManager& service_manager); - /// Invokes a service request routine using the HIPC protocol. - void InvokeRequest(Kernel::HLERequestContext& ctx); + void InvokeRequest(HLERequestContext& ctx); /// Invokes a service request routine using the HIPC protocol. - void InvokeRequestTipc(Kernel::HLERequestContext& ctx); - - /// Creates a port pair and registers it on the kernel's global port registry. - Kernel::KClientPort& CreatePort(); + void InvokeRequestTipc(HLERequestContext& ctx); /// Handles a synchronization request for the service. - Result HandleSyncRequest(Kernel::KServerSession& session, - Kernel::HLERequestContext& context) override; + Result HandleSyncRequest(Kernel::KServerSession& session, HLERequestContext& context) override; protected: /// Member-function pointer type of SyncRequest handlers. template <typename Self> - using HandlerFnP = void (Self::*)(Kernel::HLERequestContext&); + using HandlerFnP = void (Self::*)(HLERequestContext&); /// Used to gain exclusive access to the service members, e.g. from CoreTiming thread. [[nodiscard]] std::scoped_lock<std::mutex> LockService() { @@ -99,9 +89,6 @@ protected: /// Identifier string used to connect to the service. std::string service_name; - /// Port used by ManageNamedPort. - Kernel::KPort* named_port{}; - private: template <typename T> friend class ServiceFramework; @@ -113,16 +100,15 @@ private: }; using InvokerFn = void(ServiceFrameworkBase* object, HandlerFnP<ServiceFrameworkBase> member, - Kernel::HLERequestContext& ctx); + HLERequestContext& ctx); explicit ServiceFrameworkBase(Core::System& system_, const char* service_name_, - ServiceThreadType thread_type, u32 max_sessions_, - InvokerFn* handler_invoker_); + u32 max_sessions_, InvokerFn* handler_invoker_); ~ServiceFrameworkBase() override; void RegisterHandlersBase(const FunctionInfoBase* functions, std::size_t n); void RegisterHandlersBaseTipc(const FunctionInfoBase* functions, std::size_t n); - void ReportUnimplementedFunction(Kernel::HLERequestContext& ctx, const FunctionInfoBase* info); + void ReportUnimplementedFunction(HLERequestContext& ctx, const FunctionInfoBase* info); /// Maximum number of concurrent sessions that this service can handle. u32 max_sessions; @@ -181,15 +167,12 @@ protected: * * @param system_ The system context to construct this service under. * @param service_name_ Name of the service. - * @param thread_type Specifies the thread type for this service. If this is set to CreateNew, - * it creates a new thread for it, otherwise this uses the default thread. * @param max_sessions_ Maximum number of sessions that can be connected to this service at the * same time. */ explicit ServiceFramework(Core::System& system_, const char* service_name_, - ServiceThreadType thread_type = ServiceThreadType::Default, u32 max_sessions_ = ServerSessionCountMax) - : ServiceFrameworkBase(system_, service_name_, thread_type, max_sessions_, Invoker) {} + : ServiceFrameworkBase(system_, service_name_, max_sessions_, Invoker) {} /// Registers handlers in the service. template <std::size_t N> @@ -227,7 +210,7 @@ private: * of the derived class in order to invoke one of it's functions through a pointer. */ static void Invoker(ServiceFrameworkBase* object, HandlerFnP<ServiceFrameworkBase> member, - Kernel::HLERequestContext& ctx) { + HLERequestContext& ctx) { // Cast back up to our original types and call the member function (static_cast<Self*>(object)->*static_cast<HandlerFnP<Self>>(member))(ctx); } @@ -245,8 +228,8 @@ public: void KillNVNFlinger(); private: - std::unique_ptr<NVFlinger::HosBinderDriverServer> hos_binder_driver_server; - std::unique_ptr<NVFlinger::NVFlinger> nv_flinger; + std::unique_ptr<Nvnflinger::HosBinderDriverServer> hos_binder_driver_server; + std::unique_ptr<Nvnflinger::Nvnflinger> nv_flinger; }; } // namespace Service diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp index 16c5eaf75..f5788b481 100644 --- a/src/core/hle/service/set/set.cpp +++ b/src/core/hle/service/set/set.cpp @@ -6,7 +6,7 @@ #include <chrono> #include "common/logging/log.h" #include "common/settings.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/set/set.h" namespace Service::Set { @@ -74,15 +74,15 @@ constexpr std::array<std::pair<LanguageCode, KeyboardLayout>, 18> language_to_la constexpr std::size_t PRE_4_0_0_MAX_ENTRIES = 0xF; constexpr std::size_t POST_4_0_0_MAX_ENTRIES = 0x40; -constexpr Result ERR_INVALID_LANGUAGE{ErrorModule::Settings, 625}; +constexpr Result ResultInvalidLanguage{ErrorModule::Settings, 625}; -void PushResponseLanguageCode(Kernel::HLERequestContext& ctx, std::size_t num_language_codes) { +void PushResponseLanguageCode(HLERequestContext& ctx, std::size_t num_language_codes) { IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); rb.Push(static_cast<u32>(num_language_codes)); } -void GetAvailableLanguageCodesImpl(Kernel::HLERequestContext& ctx, std::size_t max_entries) { +void GetAvailableLanguageCodesImpl(HLERequestContext& ctx, std::size_t max_entries) { const std::size_t requested_amount = ctx.GetWriteBufferNumElements<LanguageCode>(); const std::size_t max_amount = std::min(requested_amount, max_entries); const std::size_t copy_amount = std::min(available_language_codes.size(), max_amount); @@ -92,7 +92,7 @@ void GetAvailableLanguageCodesImpl(Kernel::HLERequestContext& ctx, std::size_t m PushResponseLanguageCode(ctx, copy_amount); } -void GetKeyCodeMapImpl(Kernel::HLERequestContext& ctx) { +void GetKeyCodeMapImpl(HLERequestContext& ctx) { const auto language_code = available_language_codes[Settings::values.language_index.GetValue()]; const auto key_code = std::find_if(language_to_layout.cbegin(), language_to_layout.cend(), @@ -117,20 +117,20 @@ LanguageCode GetLanguageCodeFromIndex(std::size_t index) { return available_language_codes.at(index); } -void SET::GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx) { +void SET::GetAvailableLanguageCodes(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); GetAvailableLanguageCodesImpl(ctx, PRE_4_0_0_MAX_ENTRIES); } -void SET::MakeLanguageCode(Kernel::HLERequestContext& ctx) { +void SET::MakeLanguageCode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto index = rp.Pop<u32>(); if (index >= available_language_codes.size()) { LOG_ERROR(Service_SET, "Invalid language code index! index={}", index); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ERR_INVALID_LANGUAGE); + rb.Push(Set::ResultInvalidLanguage); return; } @@ -139,25 +139,25 @@ void SET::MakeLanguageCode(Kernel::HLERequestContext& ctx) { rb.PushEnum(available_language_codes[index]); } -void SET::GetAvailableLanguageCodes2(Kernel::HLERequestContext& ctx) { +void SET::GetAvailableLanguageCodes2(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); GetAvailableLanguageCodesImpl(ctx, POST_4_0_0_MAX_ENTRIES); } -void SET::GetAvailableLanguageCodeCount(Kernel::HLERequestContext& ctx) { +void SET::GetAvailableLanguageCodeCount(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); PushResponseLanguageCode(ctx, PRE_4_0_0_MAX_ENTRIES); } -void SET::GetAvailableLanguageCodeCount2(Kernel::HLERequestContext& ctx) { +void SET::GetAvailableLanguageCodeCount2(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); PushResponseLanguageCode(ctx, POST_4_0_0_MAX_ENTRIES); } -void SET::GetQuestFlag(Kernel::HLERequestContext& ctx) { +void SET::GetQuestFlag(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -165,7 +165,7 @@ void SET::GetQuestFlag(Kernel::HLERequestContext& ctx) { rb.Push(static_cast<u32>(Settings::values.quest_flag.GetValue())); } -void SET::GetLanguageCode(Kernel::HLERequestContext& ctx) { +void SET::GetLanguageCode(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called {}", Settings::values.language_index.GetValue()); IPC::ResponseBuilder rb{ctx, 4}; @@ -173,7 +173,7 @@ void SET::GetLanguageCode(Kernel::HLERequestContext& ctx) { rb.PushEnum(available_language_codes[Settings::values.language_index.GetValue()]); } -void SET::GetRegionCode(Kernel::HLERequestContext& ctx) { +void SET::GetRegionCode(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -181,17 +181,17 @@ void SET::GetRegionCode(Kernel::HLERequestContext& ctx) { rb.Push(Settings::values.region_index.GetValue()); } -void SET::GetKeyCodeMap(Kernel::HLERequestContext& ctx) { +void SET::GetKeyCodeMap(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "Called {}", ctx.Description()); GetKeyCodeMapImpl(ctx); } -void SET::GetKeyCodeMap2(Kernel::HLERequestContext& ctx) { +void SET::GetKeyCodeMap2(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "Called {}", ctx.Description()); GetKeyCodeMapImpl(ctx); } -void SET::GetDeviceNickName(Kernel::HLERequestContext& ctx) { +void SET::GetDeviceNickName(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); diff --git a/src/core/hle/service/set/set.h b/src/core/hle/service/set/set.h index 375975711..7fd3a7654 100644 --- a/src/core/hle/service/set/set.h +++ b/src/core/hle/service/set/set.h @@ -40,17 +40,17 @@ public: ~SET() override; private: - void GetLanguageCode(Kernel::HLERequestContext& ctx); - void GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx); - void MakeLanguageCode(Kernel::HLERequestContext& ctx); - void GetAvailableLanguageCodes2(Kernel::HLERequestContext& ctx); - void GetAvailableLanguageCodeCount(Kernel::HLERequestContext& ctx); - void GetAvailableLanguageCodeCount2(Kernel::HLERequestContext& ctx); - void GetQuestFlag(Kernel::HLERequestContext& ctx); - void GetRegionCode(Kernel::HLERequestContext& ctx); - void GetKeyCodeMap(Kernel::HLERequestContext& ctx); - void GetKeyCodeMap2(Kernel::HLERequestContext& ctx); - void GetDeviceNickName(Kernel::HLERequestContext& ctx); + void GetLanguageCode(HLERequestContext& ctx); + void GetAvailableLanguageCodes(HLERequestContext& ctx); + void MakeLanguageCode(HLERequestContext& ctx); + void GetAvailableLanguageCodes2(HLERequestContext& ctx); + void GetAvailableLanguageCodeCount(HLERequestContext& ctx); + void GetAvailableLanguageCodeCount2(HLERequestContext& ctx); + void GetQuestFlag(HLERequestContext& ctx); + void GetRegionCode(HLERequestContext& ctx); + void GetKeyCodeMap(HLERequestContext& ctx); + void GetKeyCodeMap2(HLERequestContext& ctx); + void GetDeviceNickName(HLERequestContext& ctx); }; } // namespace Service::Set diff --git a/src/core/hle/service/set/set_sys.cpp b/src/core/hle/service/set/set_sys.cpp index 94c20edda..2e38d1cfc 100644 --- a/src/core/hle/service/set/set_sys.cpp +++ b/src/core/hle/service/set/set_sys.cpp @@ -6,8 +6,8 @@ #include "common/settings.h" #include "core/file_sys/errors.h" #include "core/file_sys/system_archive/system_version.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/service/filesystem/filesystem.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/set/set_sys.h" namespace Service::Set { @@ -20,7 +20,7 @@ enum class GetFirmwareVersionType { Version2, }; -void GetFirmwareVersionImpl(Kernel::HLERequestContext& ctx, GetFirmwareVersionType type) { +void GetFirmwareVersionImpl(HLERequestContext& ctx, GetFirmwareVersionType type) { LOG_WARNING(Service_SET, "called - Using hardcoded firmware version '{}'", FileSys::SystemArchive::GetLongDisplayVersion()); @@ -73,17 +73,17 @@ void GetFirmwareVersionImpl(Kernel::HLERequestContext& ctx, GetFirmwareVersionTy } } // Anonymous namespace -void SET_SYS::GetFirmwareVersion(Kernel::HLERequestContext& ctx) { +void SET_SYS::GetFirmwareVersion(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); GetFirmwareVersionImpl(ctx, GetFirmwareVersionType::Version1); } -void SET_SYS::GetFirmwareVersion2(Kernel::HLERequestContext& ctx) { +void SET_SYS::GetFirmwareVersion2(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); GetFirmwareVersionImpl(ctx, GetFirmwareVersionType::Version2); } -void SET_SYS::GetColorSetId(Kernel::HLERequestContext& ctx) { +void SET_SYS::GetColorSetId(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -92,7 +92,7 @@ void SET_SYS::GetColorSetId(Kernel::HLERequestContext& ctx) { rb.PushEnum(color_set); } -void SET_SYS::SetColorSetId(Kernel::HLERequestContext& ctx) { +void SET_SYS::SetColorSetId(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); IPC::RequestParser rp{ctx}; @@ -126,7 +126,7 @@ static Settings GetSettings() { return ret; } -void SET_SYS::GetSettingsItemValueSize(Kernel::HLERequestContext& ctx) { +void SET_SYS::GetSettingsItemValueSize(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); // The category of the setting. This corresponds to the top-level keys of @@ -151,7 +151,7 @@ void SET_SYS::GetSettingsItemValueSize(Kernel::HLERequestContext& ctx) { rb.Push(response_size); } -void SET_SYS::GetSettingsItemValue(Kernel::HLERequestContext& ctx) { +void SET_SYS::GetSettingsItemValue(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); // The category of the setting. This corresponds to the top-level keys of @@ -177,7 +177,7 @@ void SET_SYS::GetSettingsItemValue(Kernel::HLERequestContext& ctx) { rb.Push(response); } -void SET_SYS::GetDeviceNickName(Kernel::HLERequestContext& ctx) { +void SET_SYS::GetDeviceNickName(HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); diff --git a/src/core/hle/service/set/set_sys.h b/src/core/hle/service/set/set_sys.h index 464ac3da1..1efbcc97a 100644 --- a/src/core/hle/service/set/set_sys.h +++ b/src/core/hle/service/set/set_sys.h @@ -23,13 +23,13 @@ private: BasicBlack = 1, }; - void GetSettingsItemValueSize(Kernel::HLERequestContext& ctx); - void GetSettingsItemValue(Kernel::HLERequestContext& ctx); - void GetFirmwareVersion(Kernel::HLERequestContext& ctx); - void GetFirmwareVersion2(Kernel::HLERequestContext& ctx); - void GetColorSetId(Kernel::HLERequestContext& ctx); - void SetColorSetId(Kernel::HLERequestContext& ctx); - void GetDeviceNickName(Kernel::HLERequestContext& ctx); + void GetSettingsItemValueSize(HLERequestContext& ctx); + void GetSettingsItemValue(HLERequestContext& ctx); + void GetFirmwareVersion(HLERequestContext& ctx); + void GetFirmwareVersion2(HLERequestContext& ctx); + void GetColorSetId(HLERequestContext& ctx); + void SetColorSetId(HLERequestContext& ctx); + void GetDeviceNickName(HLERequestContext& ctx); ColorSet color_set = ColorSet::BasicWhite; }; diff --git a/src/core/hle/service/set/settings.cpp b/src/core/hle/service/set/settings.cpp index 4ebc2a0ec..c48844f77 100644 --- a/src/core/hle/service/set/settings.cpp +++ b/src/core/hle/service/set/settings.cpp @@ -1,20 +1,23 @@ // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "core/hle/service/server_manager.h" #include "core/hle/service/set/set.h" #include "core/hle/service/set/set_cal.h" #include "core/hle/service/set/set_fd.h" #include "core/hle/service/set/set_sys.h" #include "core/hle/service/set/settings.h" -#include "core/hle/service/sm/sm.h" namespace Service::Set { -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<SET>(system)->InstallAsService(service_manager); - std::make_shared<SET_CAL>(system)->InstallAsService(service_manager); - std::make_shared<SET_FD>(system)->InstallAsService(service_manager); - std::make_shared<SET_SYS>(system)->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("set", std::make_shared<SET>(system)); + server_manager->RegisterNamedService("set:cal", std::make_shared<SET_CAL>(system)); + server_manager->RegisterNamedService("set:fd", std::make_shared<SET_FD>(system)); + server_manager->RegisterNamedService("set:sys", std::make_shared<SET_SYS>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::Set diff --git a/src/core/hle/service/set/settings.h b/src/core/hle/service/set/settings.h index 6cd7d634c..03cd4bb66 100644 --- a/src/core/hle/service/set/settings.h +++ b/src/core/hle/service/set/settings.h @@ -7,13 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::Set { -/// Registers all Settings services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::Set diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp index 84720094f..b4046d3ce 100644 --- a/src/core/hle/service/sm/sm.cpp +++ b/src/core/hle/service/sm/sm.cpp @@ -5,62 +5,60 @@ #include "common/assert.h" #include "common/scope_exit.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_client_port.h" #include "core/hle/kernel/k_client_session.h" #include "core/hle/kernel/k_port.h" #include "core/hle/kernel/k_scoped_resource_reservation.h" #include "core/hle/kernel/k_server_port.h" #include "core/hle/result.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/sm/sm.h" #include "core/hle/service/sm/sm_controller.h" namespace Service::SM { -constexpr Result ERR_NOT_INITIALIZED(ErrorModule::SM, 2); -constexpr Result ERR_ALREADY_REGISTERED(ErrorModule::SM, 4); -constexpr Result ERR_INVALID_NAME(ErrorModule::SM, 6); -constexpr Result ERR_SERVICE_NOT_REGISTERED(ErrorModule::SM, 7); +constexpr Result ResultInvalidClient(ErrorModule::SM, 2); +constexpr Result ResultAlreadyRegistered(ErrorModule::SM, 4); +constexpr Result ResultInvalidServiceName(ErrorModule::SM, 6); +constexpr Result ResultNotRegistered(ErrorModule::SM, 7); -ServiceManager::ServiceManager(Kernel::KernelCore& kernel_) : kernel{kernel_} {} +ServiceManager::ServiceManager(Kernel::KernelCore& kernel_) : kernel{kernel_} { + controller_interface = std::make_unique<Controller>(kernel.System()); +} ServiceManager::~ServiceManager() { for (auto& [name, port] : service_ports) { port->GetClientPort().Close(); port->GetServerPort().Close(); } + + if (deferral_event) { + deferral_event->Close(); + } } -void ServiceManager::InvokeControlRequest(Kernel::HLERequestContext& context) { +void ServiceManager::InvokeControlRequest(HLERequestContext& context) { controller_interface->InvokeRequest(context); } static Result ValidateServiceName(const std::string& name) { if (name.empty() || name.size() > 8) { LOG_ERROR(Service_SM, "Invalid service name! service={}", name); - return ERR_INVALID_NAME; + return Service::SM::ResultInvalidServiceName; } return ResultSuccess; } -Kernel::KClientPort& ServiceManager::InterfaceFactory(ServiceManager& self, Core::System& system) { - self.sm_interface = std::make_shared<SM>(self, system); - self.controller_interface = std::make_unique<Controller>(system); - return self.sm_interface->CreatePort(); -} - -void ServiceManager::SessionHandler(ServiceManager& self, Kernel::KServerPort* server_port) { - self.sm_interface->AcceptSession(server_port); -} - Result ServiceManager::RegisterService(std::string name, u32 max_sessions, - Kernel::SessionRequestHandlerPtr handler) { + SessionRequestHandlerPtr handler) { CASCADE_CODE(ValidateServiceName(name)); + std::scoped_lock lk{lock}; if (registered_services.find(name) != registered_services.end()) { LOG_ERROR(Service_SM, "Service is already registered! service={}", name); - return ERR_ALREADY_REGISTERED; + return Service::SM::ResultAlreadyRegistered; } auto* port = Kernel::KPort::Create(kernel); @@ -68,6 +66,9 @@ Result ServiceManager::RegisterService(std::string name, u32 max_sessions, service_ports.emplace(name, port); registered_services.emplace(name, handler); + if (deferral_event) { + deferral_event->Signal(); + } return ResultSuccess; } @@ -75,10 +76,11 @@ Result ServiceManager::RegisterService(std::string name, u32 max_sessions, Result ServiceManager::UnregisterService(const std::string& name) { CASCADE_CODE(ValidateServiceName(name)); + std::scoped_lock lk{lock}; const auto iter = registered_services.find(name); if (iter == registered_services.end()) { LOG_ERROR(Service_SM, "Server is not registered! service={}", name); - return ERR_SERVICE_NOT_REGISTERED; + return Service::SM::ResultNotRegistered; } registered_services.erase(iter); @@ -89,10 +91,12 @@ Result ServiceManager::UnregisterService(const std::string& name) { ResultVal<Kernel::KPort*> ServiceManager::GetServicePort(const std::string& name) { CASCADE_CODE(ValidateServiceName(name)); + + std::scoped_lock lk{lock}; auto it = service_ports.find(name); if (it == service_ports.end()) { - LOG_ERROR(Service_SM, "Server is not registered! service={}", name); - return ERR_SERVICE_NOT_REGISTERED; + LOG_WARNING(Service_SM, "Server is not registered! service={}", name); + return Service::SM::ResultNotRegistered; } return it->second; @@ -105,17 +109,22 @@ ResultVal<Kernel::KPort*> ServiceManager::GetServicePort(const std::string& name * Outputs: * 0: Result */ -void SM::Initialize(Kernel::HLERequestContext& ctx) { +void SM::Initialize(HLERequestContext& ctx) { LOG_DEBUG(Service_SM, "called"); - is_initialized = true; + ctx.GetManager()->SetIsInitializedForSm(); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } -void SM::GetService(Kernel::HLERequestContext& ctx) { +void SM::GetService(HLERequestContext& ctx) { auto result = GetServiceImpl(ctx); + if (ctx.GetIsDeferred()) { + // Don't overwrite the command buffer. + return; + } + if (result.Succeeded()) { IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles}; rb.Push(result.Code()); @@ -126,8 +135,13 @@ void SM::GetService(Kernel::HLERequestContext& ctx) { } } -void SM::GetServiceTipc(Kernel::HLERequestContext& ctx) { +void SM::GetServiceTipc(HLERequestContext& ctx) { auto result = GetServiceImpl(ctx); + if (ctx.GetIsDeferred()) { + // Don't overwrite the command buffer. + return; + } + IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles}; rb.Push(result.Code()); rb.PushMoveObjects(result.Succeeded() ? result.Unwrap() : nullptr); @@ -144,9 +158,9 @@ static std::string PopServiceName(IPC::RequestParser& rp) { return result; } -ResultVal<Kernel::KClientSession*> SM::GetServiceImpl(Kernel::HLERequestContext& ctx) { - if (!is_initialized) { - return ERR_NOT_INITIALIZED; +ResultVal<Kernel::KClientSession*> SM::GetServiceImpl(HLERequestContext& ctx) { + if (!ctx.GetManager()->GetIsInitializedForSm()) { + return Service::SM::ResultInvalidClient; } IPC::RequestParser rp{ctx}; @@ -154,10 +168,15 @@ ResultVal<Kernel::KClientSession*> SM::GetServiceImpl(Kernel::HLERequestContext& // Find the named port. auto port_result = service_manager.GetServicePort(name); - auto service = service_manager.GetService<Kernel::SessionRequestHandler>(name); - if (port_result.Failed() || !service) { - LOG_ERROR(Service_SM, "called service={} -> error 0x{:08X}", name, port_result.Code().raw); - return port_result.Code(); + if (port_result.Code() == Service::SM::ResultInvalidServiceName) { + LOG_ERROR(Service_SM, "Invalid service name '{}'", name); + return Service::SM::ResultInvalidServiceName; + } + + if (port_result.Failed()) { + LOG_INFO(Service_SM, "Waiting for service {} to become available", name); + ctx.SetIsDeferred(); + return Service::SM::ResultNotRegistered; } auto& port = port_result.Unwrap(); @@ -167,14 +186,13 @@ ResultVal<Kernel::KClientSession*> SM::GetServiceImpl(Kernel::HLERequestContext& LOG_ERROR(Service_SM, "called service={} -> error 0x{:08X}", name, result.raw); return result; } - service->AcceptSession(&port->GetServerPort()); LOG_DEBUG(Service_SM, "called service={} -> session={}", name, session->GetId()); return session; } -void SM::RegisterService(Kernel::HLERequestContext& ctx) { +void SM::RegisterService(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; std::string name(PopServiceName(rp)); @@ -201,7 +219,7 @@ void SM::RegisterService(Kernel::HLERequestContext& ctx) { rb.PushMoveObjects(port->GetServerPort()); } -void SM::UnregisterService(Kernel::HLERequestContext& ctx) { +void SM::UnregisterService(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; std::string name(PopServiceName(rp)); @@ -212,7 +230,7 @@ void SM::UnregisterService(Kernel::HLERequestContext& ctx) { } SM::SM(ServiceManager& service_manager_, Core::System& system_) - : ServiceFramework{system_, "sm:", ServiceThreadType::Default, 4}, + : ServiceFramework{system_, "sm:", 4}, service_manager{service_manager_}, kernel{system_.Kernel()} { RegisterHandlers({ {0, &SM::Initialize, "Initialize"}, @@ -232,4 +250,16 @@ SM::SM(ServiceManager& service_manager_, Core::System& system_) SM::~SM() = default; +void LoopProcess(Core::System& system) { + auto& service_manager = system.ServiceManager(); + auto server_manager = std::make_unique<ServerManager>(system); + + Kernel::KEvent* deferral_event{}; + server_manager->ManageDeferral(&deferral_event); + service_manager.SetDeferralEvent(deferral_event); + + server_manager->ManageNamedPort("sm:", std::make_shared<SM>(system.ServiceManager(), system)); + ServerManager::RunServer(std::move(server_manager)); +} + } // namespace Service::SM diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h index 02a5dde9e..6697f4007 100644 --- a/src/core/hle/service/sm/sm.h +++ b/src/core/hle/service/sm/sm.h @@ -4,6 +4,7 @@ #pragma once #include <memory> +#include <mutex> #include <string> #include <unordered_map> @@ -35,33 +36,28 @@ public: ~SM() override; private: - void Initialize(Kernel::HLERequestContext& ctx); - void GetService(Kernel::HLERequestContext& ctx); - void GetServiceTipc(Kernel::HLERequestContext& ctx); - void RegisterService(Kernel::HLERequestContext& ctx); - void UnregisterService(Kernel::HLERequestContext& ctx); + void Initialize(HLERequestContext& ctx); + void GetService(HLERequestContext& ctx); + void GetServiceTipc(HLERequestContext& ctx); + void RegisterService(HLERequestContext& ctx); + void UnregisterService(HLERequestContext& ctx); - ResultVal<Kernel::KClientSession*> GetServiceImpl(Kernel::HLERequestContext& ctx); + ResultVal<Kernel::KClientSession*> GetServiceImpl(HLERequestContext& ctx); ServiceManager& service_manager; - bool is_initialized{}; Kernel::KernelCore& kernel; }; class ServiceManager { public: - static Kernel::KClientPort& InterfaceFactory(ServiceManager& self, Core::System& system); - static void SessionHandler(ServiceManager& self, Kernel::KServerPort* server_port); - explicit ServiceManager(Kernel::KernelCore& kernel_); ~ServiceManager(); - Result RegisterService(std::string name, u32 max_sessions, - Kernel::SessionRequestHandlerPtr handler); + Result RegisterService(std::string name, u32 max_sessions, SessionRequestHandlerPtr handler); Result UnregisterService(const std::string& name); ResultVal<Kernel::KPort*> GetServicePort(const std::string& name); - template <Common::DerivedFrom<Kernel::SessionRequestHandler> T> + template <Common::DerivedFrom<SessionRequestHandler> T> std::shared_ptr<T> GetService(const std::string& service_name) const { auto service = registered_services.find(service_name); if (service == registered_services.end()) { @@ -71,18 +67,27 @@ public: return std::static_pointer_cast<T>(service->second); } - void InvokeControlRequest(Kernel::HLERequestContext& context); + void InvokeControlRequest(HLERequestContext& context); + + void SetDeferralEvent(Kernel::KEvent* deferral_event_) { + deferral_event = deferral_event_; + } private: std::shared_ptr<SM> sm_interface; std::unique_ptr<Controller> controller_interface; /// Map of registered services, retrieved using GetServicePort. - std::unordered_map<std::string, Kernel::SessionRequestHandlerPtr> registered_services; + std::mutex lock; + std::unordered_map<std::string, SessionRequestHandlerPtr> registered_services; std::unordered_map<std::string, Kernel::KPort*> service_ports; /// Kernel context Kernel::KernelCore& kernel; + Kernel::KEvent* deferral_event{}; }; +/// Runs SM services. +void LoopProcess(Core::System& system); + } // namespace Service::SM diff --git a/src/core/hle/service/sm/sm_controller.cpp b/src/core/hle/service/sm/sm_controller.cpp index 1cf9dd1c4..0111c8d7f 100644 --- a/src/core/hle/service/sm/sm_controller.cpp +++ b/src/core/hle/service/sm/sm_controller.cpp @@ -4,17 +4,18 @@ #include "common/assert.h" #include "common/logging/log.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_client_port.h" #include "core/hle/kernel/k_port.h" #include "core/hle/kernel/k_scoped_resource_reservation.h" #include "core/hle/kernel/k_server_session.h" #include "core/hle/kernel/k_session.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/sm/sm_controller.h" namespace Service::SM { -void Controller::ConvertCurrentObjectToDomain(Kernel::HLERequestContext& ctx) { +void Controller::ConvertCurrentObjectToDomain(HLERequestContext& ctx) { ASSERT_MSG(!ctx.GetManager()->IsDomain(), "Session is already a domain"); LOG_DEBUG(Service, "called, server_session={}", ctx.Session()->GetId()); ctx.GetManager()->ConvertToDomainOnRequestEnd(); @@ -24,7 +25,7 @@ void Controller::ConvertCurrentObjectToDomain(Kernel::HLERequestContext& ctx) { rb.Push<u32>(1); // Converted sessions start with 1 request handler } -void Controller::CloneCurrentObject(Kernel::HLERequestContext& ctx) { +void Controller::CloneCurrentObject(HLERequestContext& ctx) { LOG_DEBUG(Service, "called"); auto& process = *ctx.GetThread().GetOwnerProcess(); @@ -48,9 +49,9 @@ void Controller::CloneCurrentObject(Kernel::HLERequestContext& ctx) { // Commit the session reservation. session_reservation.Commit(); - // Register with manager. - session_manager->SessionHandler().RegisterSession(&session->GetServerSession(), - session_manager); + // Register with server manager. + session_manager->GetServerManager().RegisterSession(&session->GetServerSession(), + session_manager); // We succeeded. IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles}; @@ -58,13 +59,13 @@ void Controller::CloneCurrentObject(Kernel::HLERequestContext& ctx) { rb.PushMoveObjects(session->GetClientSession()); } -void Controller::CloneCurrentObjectEx(Kernel::HLERequestContext& ctx) { +void Controller::CloneCurrentObjectEx(HLERequestContext& ctx) { LOG_DEBUG(Service, "called"); CloneCurrentObject(ctx); } -void Controller::QueryPointerBufferSize(Kernel::HLERequestContext& ctx) { +void Controller::QueryPointerBufferSize(HLERequestContext& ctx) { LOG_WARNING(Service, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; diff --git a/src/core/hle/service/sm/sm_controller.h b/src/core/hle/service/sm/sm_controller.h index ed386f660..4e748b36d 100644 --- a/src/core/hle/service/sm/sm_controller.h +++ b/src/core/hle/service/sm/sm_controller.h @@ -17,10 +17,10 @@ public: ~Controller() override; private: - void ConvertCurrentObjectToDomain(Kernel::HLERequestContext& ctx); - void CloneCurrentObject(Kernel::HLERequestContext& ctx); - void CloneCurrentObjectEx(Kernel::HLERequestContext& ctx); - void QueryPointerBufferSize(Kernel::HLERequestContext& ctx); + void ConvertCurrentObjectToDomain(HLERequestContext& ctx); + void CloneCurrentObject(HLERequestContext& ctx); + void CloneCurrentObjectEx(HLERequestContext& ctx); + void QueryPointerBufferSize(HLERequestContext& ctx); }; } // namespace Service::SM diff --git a/src/core/hle/service/sockets/bsd.cpp b/src/core/hle/service/sockets/bsd.cpp index 330a66409..bce45d321 100644 --- a/src/core/hle/service/sockets/bsd.cpp +++ b/src/core/hle/service/sockets/bsd.cpp @@ -11,8 +11,8 @@ #include "common/microprofile.h" #include "common/socket_types.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_thread.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/sockets/bsd.h" #include "core/hle/service/sockets/sockets_translate.h" #include "core/internal_network/network.h" @@ -42,7 +42,7 @@ void BSD::PollWork::Execute(BSD* bsd) { std::tie(ret, bsd_errno) = bsd->PollImpl(write_buffer, read_buffer, nfds, timeout); } -void BSD::PollWork::Response(Kernel::HLERequestContext& ctx) { +void BSD::PollWork::Response(HLERequestContext& ctx) { if (write_buffer.size() > 0) { ctx.WriteBuffer(write_buffer); } @@ -57,7 +57,7 @@ void BSD::AcceptWork::Execute(BSD* bsd) { std::tie(ret, bsd_errno) = bsd->AcceptImpl(fd, write_buffer); } -void BSD::AcceptWork::Response(Kernel::HLERequestContext& ctx) { +void BSD::AcceptWork::Response(HLERequestContext& ctx) { if (write_buffer.size() > 0) { ctx.WriteBuffer(write_buffer); } @@ -73,7 +73,7 @@ void BSD::ConnectWork::Execute(BSD* bsd) { bsd_errno = bsd->ConnectImpl(fd, addr); } -void BSD::ConnectWork::Response(Kernel::HLERequestContext& ctx) { +void BSD::ConnectWork::Response(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 4}; rb.Push(ResultSuccess); rb.Push<s32>(bsd_errno == Errno::SUCCESS ? 0 : -1); @@ -84,7 +84,7 @@ void BSD::RecvWork::Execute(BSD* bsd) { std::tie(ret, bsd_errno) = bsd->RecvImpl(fd, flags, message); } -void BSD::RecvWork::Response(Kernel::HLERequestContext& ctx) { +void BSD::RecvWork::Response(HLERequestContext& ctx) { ctx.WriteBuffer(message); IPC::ResponseBuilder rb{ctx, 4}; @@ -97,7 +97,7 @@ void BSD::RecvFromWork::Execute(BSD* bsd) { std::tie(ret, bsd_errno) = bsd->RecvFromImpl(fd, flags, message, addr); } -void BSD::RecvFromWork::Response(Kernel::HLERequestContext& ctx) { +void BSD::RecvFromWork::Response(HLERequestContext& ctx) { ctx.WriteBuffer(message, 0); if (!addr.empty()) { ctx.WriteBuffer(addr, 1); @@ -114,7 +114,7 @@ void BSD::SendWork::Execute(BSD* bsd) { std::tie(ret, bsd_errno) = bsd->SendImpl(fd, flags, message); } -void BSD::SendWork::Response(Kernel::HLERequestContext& ctx) { +void BSD::SendWork::Response(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 4}; rb.Push(ResultSuccess); rb.Push<s32>(ret); @@ -125,14 +125,14 @@ void BSD::SendToWork::Execute(BSD* bsd) { std::tie(ret, bsd_errno) = bsd->SendToImpl(fd, flags, message, addr); } -void BSD::SendToWork::Response(Kernel::HLERequestContext& ctx) { +void BSD::SendToWork::Response(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 4}; rb.Push(ResultSuccess); rb.Push<s32>(ret); rb.PushEnum(bsd_errno); } -void BSD::RegisterClient(Kernel::HLERequestContext& ctx) { +void BSD::RegisterClient(HLERequestContext& ctx) { LOG_WARNING(Service, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 3}; @@ -141,7 +141,7 @@ void BSD::RegisterClient(Kernel::HLERequestContext& ctx) { rb.Push<s32>(0); // bsd errno } -void BSD::StartMonitoring(Kernel::HLERequestContext& ctx) { +void BSD::StartMonitoring(HLERequestContext& ctx) { LOG_WARNING(Service, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -149,7 +149,7 @@ void BSD::StartMonitoring(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void BSD::Socket(Kernel::HLERequestContext& ctx) { +void BSD::Socket(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u32 domain = rp.Pop<u32>(); const u32 type = rp.Pop<u32>(); @@ -166,7 +166,7 @@ void BSD::Socket(Kernel::HLERequestContext& ctx) { rb.PushEnum(bsd_errno); } -void BSD::Select(Kernel::HLERequestContext& ctx) { +void BSD::Select(HLERequestContext& ctx) { LOG_WARNING(Service, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 4}; @@ -176,7 +176,7 @@ void BSD::Select(Kernel::HLERequestContext& ctx) { rb.Push<u32>(0); // bsd errno } -void BSD::Poll(Kernel::HLERequestContext& ctx) { +void BSD::Poll(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 nfds = rp.Pop<s32>(); const s32 timeout = rp.Pop<s32>(); @@ -191,7 +191,7 @@ void BSD::Poll(Kernel::HLERequestContext& ctx) { }); } -void BSD::Accept(Kernel::HLERequestContext& ctx) { +void BSD::Accept(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); @@ -203,7 +203,7 @@ void BSD::Accept(Kernel::HLERequestContext& ctx) { }); } -void BSD::Bind(Kernel::HLERequestContext& ctx) { +void BSD::Bind(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); @@ -211,7 +211,7 @@ void BSD::Bind(Kernel::HLERequestContext& ctx) { BuildErrnoResponse(ctx, BindImpl(fd, ctx.ReadBuffer())); } -void BSD::Connect(Kernel::HLERequestContext& ctx) { +void BSD::Connect(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); @@ -223,7 +223,7 @@ void BSD::Connect(Kernel::HLERequestContext& ctx) { }); } -void BSD::GetPeerName(Kernel::HLERequestContext& ctx) { +void BSD::GetPeerName(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); @@ -241,7 +241,7 @@ void BSD::GetPeerName(Kernel::HLERequestContext& ctx) { rb.Push<u32>(static_cast<u32>(write_buffer.size())); } -void BSD::GetSockName(Kernel::HLERequestContext& ctx) { +void BSD::GetSockName(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); @@ -259,7 +259,7 @@ void BSD::GetSockName(Kernel::HLERequestContext& ctx) { rb.Push<u32>(static_cast<u32>(write_buffer.size())); } -void BSD::GetSockOpt(Kernel::HLERequestContext& ctx) { +void BSD::GetSockOpt(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); const u32 level = rp.Pop<u32>(); @@ -278,7 +278,7 @@ void BSD::GetSockOpt(Kernel::HLERequestContext& ctx) { rb.Push<u32>(static_cast<u32>(optval.size())); } -void BSD::Listen(Kernel::HLERequestContext& ctx) { +void BSD::Listen(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); const s32 backlog = rp.Pop<s32>(); @@ -288,7 +288,7 @@ void BSD::Listen(Kernel::HLERequestContext& ctx) { BuildErrnoResponse(ctx, ListenImpl(fd, backlog)); } -void BSD::Fcntl(Kernel::HLERequestContext& ctx) { +void BSD::Fcntl(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); const s32 cmd = rp.Pop<s32>(); @@ -304,7 +304,7 @@ void BSD::Fcntl(Kernel::HLERequestContext& ctx) { rb.PushEnum(bsd_errno); } -void BSD::SetSockOpt(Kernel::HLERequestContext& ctx) { +void BSD::SetSockOpt(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); @@ -328,7 +328,7 @@ void BSD::SetSockOpt(Kernel::HLERequestContext& ctx) { BuildErrnoResponse(ctx, SetSockOptImpl(fd, level, optname, optlen, optval)); } -void BSD::Shutdown(Kernel::HLERequestContext& ctx) { +void BSD::Shutdown(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); @@ -339,7 +339,7 @@ void BSD::Shutdown(Kernel::HLERequestContext& ctx) { BuildErrnoResponse(ctx, ShutdownImpl(fd, how)); } -void BSD::Recv(Kernel::HLERequestContext& ctx) { +void BSD::Recv(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); @@ -354,7 +354,7 @@ void BSD::Recv(Kernel::HLERequestContext& ctx) { }); } -void BSD::RecvFrom(Kernel::HLERequestContext& ctx) { +void BSD::RecvFrom(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); @@ -371,7 +371,7 @@ void BSD::RecvFrom(Kernel::HLERequestContext& ctx) { }); } -void BSD::Send(Kernel::HLERequestContext& ctx) { +void BSD::Send(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); @@ -386,7 +386,7 @@ void BSD::Send(Kernel::HLERequestContext& ctx) { }); } -void BSD::SendTo(Kernel::HLERequestContext& ctx) { +void BSD::SendTo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); const u32 flags = rp.Pop<u32>(); @@ -402,7 +402,7 @@ void BSD::SendTo(Kernel::HLERequestContext& ctx) { }); } -void BSD::Write(Kernel::HLERequestContext& ctx) { +void BSD::Write(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); @@ -415,7 +415,7 @@ void BSD::Write(Kernel::HLERequestContext& ctx) { }); } -void BSD::Read(Kernel::HLERequestContext& ctx) { +void BSD::Read(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); @@ -427,7 +427,7 @@ void BSD::Read(Kernel::HLERequestContext& ctx) { rb.Push<u32>(0); // bsd errno } -void BSD::Close(Kernel::HLERequestContext& ctx) { +void BSD::Close(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const s32 fd = rp.Pop<s32>(); @@ -436,7 +436,7 @@ void BSD::Close(Kernel::HLERequestContext& ctx) { BuildErrnoResponse(ctx, CloseImpl(fd)); } -void BSD::EventFd(Kernel::HLERequestContext& ctx) { +void BSD::EventFd(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 initval = rp.Pop<u64>(); const u32 flags = rp.Pop<u32>(); @@ -447,7 +447,7 @@ void BSD::EventFd(Kernel::HLERequestContext& ctx) { } template <typename Work> -void BSD::ExecuteWork(Kernel::HLERequestContext& ctx, Work work) { +void BSD::ExecuteWork(HLERequestContext& ctx, Work work) { work.Execute(this); work.Response(ctx); } @@ -862,7 +862,7 @@ bool BSD::IsFileDescriptorValid(s32 fd) const noexcept { return true; } -void BSD::BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept { +void BSD::BuildErrnoResponse(HLERequestContext& ctx, Errno bsd_errno) const noexcept { IPC::ResponseBuilder rb{ctx, 4}; rb.Push(ResultSuccess); @@ -881,8 +881,7 @@ void BSD::OnProxyPacketReceived(const Network::ProxyPacket& packet) { } BSD::BSD(Core::System& system_, const char* name) - : ServiceFramework{system_, name, ServiceThreadType::CreateNew}, room_network{ - system_.GetRoomNetwork()} { + : ServiceFramework{system_, name}, room_network{system_.GetRoomNetwork()} { // clang-format off static const FunctionInfo functions[] = { {0, &BSD::RegisterClient, "RegisterClient"}, diff --git a/src/core/hle/service/sockets/bsd.h b/src/core/hle/service/sockets/bsd.h index 56bb3f8b1..30ae9c140 100644 --- a/src/core/hle/service/sockets/bsd.h +++ b/src/core/hle/service/sockets/bsd.h @@ -41,7 +41,7 @@ private: struct PollWork { void Execute(BSD* bsd); - void Response(Kernel::HLERequestContext& ctx); + void Response(HLERequestContext& ctx); s32 nfds; s32 timeout; @@ -53,7 +53,7 @@ private: struct AcceptWork { void Execute(BSD* bsd); - void Response(Kernel::HLERequestContext& ctx); + void Response(HLERequestContext& ctx); s32 fd; std::vector<u8> write_buffer; @@ -63,7 +63,7 @@ private: struct ConnectWork { void Execute(BSD* bsd); - void Response(Kernel::HLERequestContext& ctx); + void Response(HLERequestContext& ctx); s32 fd; std::span<const u8> addr; @@ -72,7 +72,7 @@ private: struct RecvWork { void Execute(BSD* bsd); - void Response(Kernel::HLERequestContext& ctx); + void Response(HLERequestContext& ctx); s32 fd; u32 flags; @@ -83,7 +83,7 @@ private: struct RecvFromWork { void Execute(BSD* bsd); - void Response(Kernel::HLERequestContext& ctx); + void Response(HLERequestContext& ctx); s32 fd; u32 flags; @@ -95,7 +95,7 @@ private: struct SendWork { void Execute(BSD* bsd); - void Response(Kernel::HLERequestContext& ctx); + void Response(HLERequestContext& ctx); s32 fd; u32 flags; @@ -106,7 +106,7 @@ private: struct SendToWork { void Execute(BSD* bsd); - void Response(Kernel::HLERequestContext& ctx); + void Response(HLERequestContext& ctx); s32 fd; u32 flags; @@ -116,32 +116,32 @@ private: Errno bsd_errno{}; }; - void RegisterClient(Kernel::HLERequestContext& ctx); - void StartMonitoring(Kernel::HLERequestContext& ctx); - void Socket(Kernel::HLERequestContext& ctx); - void Select(Kernel::HLERequestContext& ctx); - void Poll(Kernel::HLERequestContext& ctx); - void Accept(Kernel::HLERequestContext& ctx); - void Bind(Kernel::HLERequestContext& ctx); - void Connect(Kernel::HLERequestContext& ctx); - void GetPeerName(Kernel::HLERequestContext& ctx); - void GetSockName(Kernel::HLERequestContext& ctx); - void GetSockOpt(Kernel::HLERequestContext& ctx); - void Listen(Kernel::HLERequestContext& ctx); - void Fcntl(Kernel::HLERequestContext& ctx); - void SetSockOpt(Kernel::HLERequestContext& ctx); - void Shutdown(Kernel::HLERequestContext& ctx); - void Recv(Kernel::HLERequestContext& ctx); - void RecvFrom(Kernel::HLERequestContext& ctx); - void Send(Kernel::HLERequestContext& ctx); - void SendTo(Kernel::HLERequestContext& ctx); - void Write(Kernel::HLERequestContext& ctx); - void Read(Kernel::HLERequestContext& ctx); - void Close(Kernel::HLERequestContext& ctx); - void EventFd(Kernel::HLERequestContext& ctx); + void RegisterClient(HLERequestContext& ctx); + void StartMonitoring(HLERequestContext& ctx); + void Socket(HLERequestContext& ctx); + void Select(HLERequestContext& ctx); + void Poll(HLERequestContext& ctx); + void Accept(HLERequestContext& ctx); + void Bind(HLERequestContext& ctx); + void Connect(HLERequestContext& ctx); + void GetPeerName(HLERequestContext& ctx); + void GetSockName(HLERequestContext& ctx); + void GetSockOpt(HLERequestContext& ctx); + void Listen(HLERequestContext& ctx); + void Fcntl(HLERequestContext& ctx); + void SetSockOpt(HLERequestContext& ctx); + void Shutdown(HLERequestContext& ctx); + void Recv(HLERequestContext& ctx); + void RecvFrom(HLERequestContext& ctx); + void Send(HLERequestContext& ctx); + void SendTo(HLERequestContext& ctx); + void Write(HLERequestContext& ctx); + void Read(HLERequestContext& ctx); + void Close(HLERequestContext& ctx); + void EventFd(HLERequestContext& ctx); template <typename Work> - void ExecuteWork(Kernel::HLERequestContext& ctx, Work work); + void ExecuteWork(HLERequestContext& ctx, Work work); std::pair<s32, Errno> SocketImpl(Domain domain, Type type, Protocol protocol); std::pair<s32, Errno> PollImpl(std::vector<u8>& write_buffer, std::span<const u8> read_buffer, @@ -166,7 +166,7 @@ private: s32 FindFreeFileDescriptorHandle() noexcept; bool IsFileDescriptorValid(s32 fd) const noexcept; - void BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept; + void BuildErrnoResponse(HLERequestContext& ctx, Errno bsd_errno) const noexcept; std::array<std::optional<FileDescriptor>, MAX_FD> file_descriptors; diff --git a/src/core/hle/service/sockets/sfdnsres.cpp b/src/core/hle/service/sockets/sfdnsres.cpp index e96eda7f3..132dd5797 100644 --- a/src/core/hle/service/sockets/sfdnsres.cpp +++ b/src/core/hle/service/sockets/sfdnsres.cpp @@ -8,7 +8,7 @@ #include "common/string_util.h" #include "common/swap.h" #include "core/core.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/sockets/sfdnsres.h" #include "core/memory.h" @@ -185,7 +185,7 @@ static std::vector<u8> SerializeAddrInfo(const addrinfo* addrinfo, s32 result_co return data; } -static std::pair<u32, s32> GetAddrInfoRequestImpl(Kernel::HLERequestContext& ctx) { +static std::pair<u32, s32> GetAddrInfoRequestImpl(HLERequestContext& ctx) { struct Parameters { u8 use_nsd_resolve; u32 unknown; @@ -221,7 +221,7 @@ static std::pair<u32, s32> GetAddrInfoRequestImpl(Kernel::HLERequestContext& ctx return std::make_pair(data_size, result_code); } -void SFDNSRES::GetAddrInfoRequest(Kernel::HLERequestContext& ctx) { +void SFDNSRES::GetAddrInfoRequest(HLERequestContext& ctx) { auto [data_size, result_code] = GetAddrInfoRequestImpl(ctx); IPC::ResponseBuilder rb{ctx, 4}; @@ -231,7 +231,7 @@ void SFDNSRES::GetAddrInfoRequest(Kernel::HLERequestContext& ctx) { rb.Push(data_size); // serialized size } -void SFDNSRES::GetAddrInfoRequestWithOptions(Kernel::HLERequestContext& ctx) { +void SFDNSRES::GetAddrInfoRequestWithOptions(HLERequestContext& ctx) { // Additional options are ignored auto [data_size, result_code] = GetAddrInfoRequestImpl(ctx); diff --git a/src/core/hle/service/sockets/sfdnsres.h b/src/core/hle/service/sockets/sfdnsres.h index 96018ea77..18e3cd60c 100644 --- a/src/core/hle/service/sockets/sfdnsres.h +++ b/src/core/hle/service/sockets/sfdnsres.h @@ -17,8 +17,8 @@ public: ~SFDNSRES() override; private: - void GetAddrInfoRequest(Kernel::HLERequestContext& ctx); - void GetAddrInfoRequestWithOptions(Kernel::HLERequestContext& ctx); + void GetAddrInfoRequest(HLERequestContext& ctx); + void GetAddrInfoRequestWithOptions(HLERequestContext& ctx); }; } // namespace Service::Sockets diff --git a/src/core/hle/service/sockets/sockets.cpp b/src/core/hle/service/sockets/sockets.cpp index b191b5cf5..676d24e03 100644 --- a/src/core/hle/service/sockets/sockets.cpp +++ b/src/core/hle/service/sockets/sockets.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "core/hle/service/server_manager.h" #include "core/hle/service/sockets/bsd.h" #include "core/hle/service/sockets/nsd.h" #include "core/hle/service/sockets/sfdnsres.h" @@ -8,15 +9,17 @@ namespace Service::Sockets { -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<BSD>(system, "bsd:s")->InstallAsService(service_manager); - std::make_shared<BSD>(system, "bsd:u")->InstallAsService(service_manager); - std::make_shared<BSDCFG>(system)->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); - std::make_shared<NSD>(system, "nsd:a")->InstallAsService(service_manager); - std::make_shared<NSD>(system, "nsd:u")->InstallAsService(service_manager); - - std::make_shared<SFDNSRES>(system)->InstallAsService(service_manager); + server_manager->RegisterNamedService("bsd:s", std::make_shared<BSD>(system, "bsd:s")); + server_manager->RegisterNamedService("bsd:u", std::make_shared<BSD>(system, "bsd:u")); + server_manager->RegisterNamedService("bsdcfg", std::make_shared<BSDCFG>(system)); + server_manager->RegisterNamedService("nsd:a", std::make_shared<NSD>(system, "nsd:a")); + server_manager->RegisterNamedService("nsd:u", std::make_shared<NSD>(system, "nsd:u")); + server_manager->RegisterNamedService("sfdnsres", std::make_shared<SFDNSRES>(system)); + server_manager->StartAdditionalHostThreads("bsdsocket", 2); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::Sockets diff --git a/src/core/hle/service/sockets/sockets.h b/src/core/hle/service/sockets/sockets.h index 9840c11f9..acd2dae7b 100644 --- a/src/core/hle/service/sockets/sockets.h +++ b/src/core/hle/service/sockets/sockets.h @@ -10,10 +10,6 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::Sockets { enum class Errno : u32 { @@ -99,7 +95,6 @@ struct Linger { u32 linger; }; -/// Registers all Sockets services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::Sockets diff --git a/src/core/hle/service/spl/spl_module.cpp b/src/core/hle/service/spl/spl_module.cpp index 64eae1ebf..0227d4393 100644 --- a/src/core/hle/service/spl/spl_module.cpp +++ b/src/core/hle/service/spl/spl_module.cpp @@ -8,7 +8,8 @@ #include "common/logging/log.h" #include "common/settings.h" #include "core/hle/api_version.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/spl/csrng.h" #include "core/hle/service/spl/spl.h" #include "core/hle/service/spl/spl_module.h" @@ -22,7 +23,7 @@ Module::Interface::Interface(Core::System& system_, std::shared_ptr<Module> modu Module::Interface::~Interface() = default; -void Module::Interface::GetConfig(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetConfig(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto config_item = rp.PopEnum<ConfigItem>(); @@ -47,21 +48,21 @@ void Module::Interface::GetConfig(Kernel::HLERequestContext& ctx) { rb.Push(*smc_result); } -void Module::Interface::ModularExponentiate(Kernel::HLERequestContext& ctx) { +void Module::Interface::ModularExponentiate(HLERequestContext& ctx) { UNIMPLEMENTED_MSG("ModularExponentiate is not implemented!"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSecureMonitorNotImplemented); } -void Module::Interface::SetConfig(Kernel::HLERequestContext& ctx) { +void Module::Interface::SetConfig(HLERequestContext& ctx) { UNIMPLEMENTED_MSG("SetConfig is not implemented!"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSecureMonitorNotImplemented); } -void Module::Interface::GenerateRandomBytes(Kernel::HLERequestContext& ctx) { +void Module::Interface::GenerateRandomBytes(HLERequestContext& ctx) { LOG_DEBUG(Service_SPL, "called"); const std::size_t size = ctx.GetWriteBufferSize(); @@ -76,21 +77,21 @@ void Module::Interface::GenerateRandomBytes(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Module::Interface::IsDevelopment(Kernel::HLERequestContext& ctx) { +void Module::Interface::IsDevelopment(HLERequestContext& ctx) { UNIMPLEMENTED_MSG("IsDevelopment is not implemented!"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSecureMonitorNotImplemented); } -void Module::Interface::SetBootReason(Kernel::HLERequestContext& ctx) { +void Module::Interface::SetBootReason(HLERequestContext& ctx) { UNIMPLEMENTED_MSG("SetBootReason is not implemented!"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSecureMonitorNotImplemented); } -void Module::Interface::GetBootReason(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetBootReason(HLERequestContext& ctx) { UNIMPLEMENTED_MSG("GetBootReason is not implemented!"); IPC::ResponseBuilder rb{ctx, 2}; @@ -158,15 +159,18 @@ ResultVal<u64> Module::Interface::GetConfigImpl(ConfigItem config_item) const { } } -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); auto module = std::make_shared<Module>(); - std::make_shared<CSRNG>(system, module)->InstallAsService(service_manager); - std::make_shared<SPL>(system, module)->InstallAsService(service_manager); - std::make_shared<SPL_MIG>(system, module)->InstallAsService(service_manager); - std::make_shared<SPL_FS>(system, module)->InstallAsService(service_manager); - std::make_shared<SPL_SSL>(system, module)->InstallAsService(service_manager); - std::make_shared<SPL_ES>(system, module)->InstallAsService(service_manager); - std::make_shared<SPL_MANU>(system, module)->InstallAsService(service_manager); + + server_manager->RegisterNamedService("csrng", std::make_shared<CSRNG>(system, module)); + server_manager->RegisterNamedService("spl", std::make_shared<SPL>(system, module)); + server_manager->RegisterNamedService("spl:mig", std::make_shared<SPL_MIG>(system, module)); + server_manager->RegisterNamedService("spl:fs", std::make_shared<SPL_FS>(system, module)); + server_manager->RegisterNamedService("spl:ssl", std::make_shared<SPL_SSL>(system, module)); + server_manager->RegisterNamedService("spl:es", std::make_shared<SPL_ES>(system, module)); + server_manager->RegisterNamedService("spl:manu", std::make_shared<SPL_MANU>(system, module)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::SPL diff --git a/src/core/hle/service/spl/spl_module.h b/src/core/hle/service/spl/spl_module.h index 4c9a3c618..e074e115d 100644 --- a/src/core/hle/service/spl/spl_module.h +++ b/src/core/hle/service/spl/spl_module.h @@ -23,13 +23,13 @@ public: ~Interface() override; // General - void GetConfig(Kernel::HLERequestContext& ctx); - void ModularExponentiate(Kernel::HLERequestContext& ctx); - void SetConfig(Kernel::HLERequestContext& ctx); - void GenerateRandomBytes(Kernel::HLERequestContext& ctx); - void IsDevelopment(Kernel::HLERequestContext& ctx); - void SetBootReason(Kernel::HLERequestContext& ctx); - void GetBootReason(Kernel::HLERequestContext& ctx); + void GetConfig(HLERequestContext& ctx); + void ModularExponentiate(HLERequestContext& ctx); + void SetConfig(HLERequestContext& ctx); + void GenerateRandomBytes(HLERequestContext& ctx); + void IsDevelopment(HLERequestContext& ctx); + void SetBootReason(HLERequestContext& ctx); + void GetBootReason(HLERequestContext& ctx); protected: std::shared_ptr<Module> module; @@ -41,7 +41,6 @@ public: }; }; -/// Registers all SPL services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::SPL diff --git a/src/core/hle/service/ssl/ssl.cpp b/src/core/hle/service/ssl/ssl.cpp index 015208593..2b99dd7ac 100644 --- a/src/core/hle/service/ssl/ssl.cpp +++ b/src/core/hle/service/ssl/ssl.cpp @@ -1,21 +1,43 @@ // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" #include "core/hle/service/ssl/ssl.h" namespace Service::SSL { +// This is nn::ssl::sf::CertificateFormat enum class CertificateFormat : u32 { Pem = 1, Der = 2, }; +// This is nn::ssl::sf::ContextOption +enum class ContextOption : u32 { + None = 0, + CrlImportDateCheckEnable = 1, +}; + +// This is nn::ssl::sf::SslVersion +struct SslVersion { + union { + u32 raw{}; + + BitField<0, 1, u32> tls_auto; + BitField<3, 1, u32> tls_v10; + BitField<4, 1, u32> tls_v11; + BitField<5, 1, u32> tls_v12; + BitField<6, 1, u32> tls_v13; + BitField<24, 7, u32> api_version; + }; +}; + class ISslConnection final : public ServiceFramework<ISslConnection> { public: - explicit ISslConnection(Core::System& system_) : ServiceFramework{system_, "ISslConnection"} { + explicit ISslConnection(Core::System& system_, SslVersion version) + : ServiceFramework{system_, "ISslConnection"}, ssl_version{version} { // clang-format off static const FunctionInfo functions[] = { {0, nullptr, "SetSocketDescriptor"}, @@ -59,11 +81,15 @@ public: RegisterHandlers(functions); } + +private: + SslVersion ssl_version; }; class ISslContext final : public ServiceFramework<ISslContext> { public: - explicit ISslContext(Core::System& system_) : ServiceFramework{system_, "ISslContext"} { + explicit ISslContext(Core::System& system_, SslVersion version) + : ServiceFramework{system_, "ISslContext"}, ssl_version{version} { static const FunctionInfo functions[] = { {0, &ISslContext::SetOption, "SetOption"}, {1, nullptr, "GetOption"}, @@ -84,31 +110,34 @@ public: } private: - void SetOption(Kernel::HLERequestContext& ctx) { + SslVersion ssl_version; + + void SetOption(HLERequestContext& ctx) { struct Parameters { - u8 enable; - u32 option; + ContextOption option; + s32 value; }; + static_assert(sizeof(Parameters) == 0x8, "Parameters is an invalid size"); IPC::RequestParser rp{ctx}; const auto parameters = rp.PopRaw<Parameters>(); - LOG_WARNING(Service_SSL, "(STUBBED) called. enable={}, option={}", parameters.enable, - parameters.option); + LOG_WARNING(Service_SSL, "(STUBBED) called. option={}, value={}", parameters.option, + parameters.value); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void CreateConnection(Kernel::HLERequestContext& ctx) { + void CreateConnection(HLERequestContext& ctx) { LOG_WARNING(Service_SSL, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface<ISslConnection>(system); + rb.PushIpcInterface<ISslConnection>(system, ssl_version); } - void ImportServerPki(Kernel::HLERequestContext& ctx) { + void ImportServerPki(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto certificate_format = rp.PopEnum<CertificateFormat>(); [[maybe_unused]] const auto pkcs_12_certificates = ctx.ReadBuffer(0); @@ -122,7 +151,7 @@ private: rb.Push(server_id); } - void ImportClientPki(Kernel::HLERequestContext& ctx) { + void ImportClientPki(HLERequestContext& ctx) { [[maybe_unused]] const auto pkcs_12_certificate = ctx.ReadBuffer(0); [[maybe_unused]] const auto ascii_password = [&ctx] { if (ctx.CanReadBuffer(1)) { @@ -142,20 +171,21 @@ private: } }; -class SSL final : public ServiceFramework<SSL> { +class ISslService final : public ServiceFramework<ISslService> { public: - explicit SSL(Core::System& system_) : ServiceFramework{system_, "ssl"} { + explicit ISslService(Core::System& system_) : ServiceFramework{system_, "ssl"} { // clang-format off static const FunctionInfo functions[] = { - {0, &SSL::CreateContext, "CreateContext"}, + {0, &ISslService::CreateContext, "CreateContext"}, {1, nullptr, "GetContextCount"}, {2, nullptr, "GetCertificates"}, {3, nullptr, "GetCertificateBufSize"}, {4, nullptr, "DebugIoctl"}, - {5, &SSL::SetInterfaceVersion, "SetInterfaceVersion"}, + {5, &ISslService::SetInterfaceVersion, "SetInterfaceVersion"}, {6, nullptr, "FlushSessionCache"}, {7, nullptr, "SetDebugOption"}, {8, nullptr, "GetDebugOption"}, + {8, nullptr, "ClearTls12FallbackFlag"}, }; // clang-format on @@ -163,28 +193,41 @@ public: } private: - u32 ssl_version{}; - void CreateContext(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_SSL, "(STUBBED) called"); + void CreateContext(HLERequestContext& ctx) { + struct Parameters { + SslVersion ssl_version; + INSERT_PADDING_BYTES(0x4); + u64 pid_placeholder; + }; + static_assert(sizeof(Parameters) == 0x10, "Parameters is an invalid size"); + + IPC::RequestParser rp{ctx}; + const auto parameters = rp.PopRaw<Parameters>(); + + LOG_WARNING(Service_SSL, "(STUBBED) called, api_version={}, pid_placeholder={}", + parameters.ssl_version.api_version, parameters.pid_placeholder); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface<ISslContext>(system); + rb.PushIpcInterface<ISslContext>(system, parameters.ssl_version); } - void SetInterfaceVersion(Kernel::HLERequestContext& ctx) { - LOG_DEBUG(Service_SSL, "called"); - + void SetInterfaceVersion(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - ssl_version = rp.Pop<u32>(); + u32 ssl_version = rp.Pop<u32>(); + + LOG_DEBUG(Service_SSL, "called, ssl_version={}", ssl_version); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } }; -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { - std::make_shared<SSL>(system)->InstallAsService(service_manager); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("ssl", std::make_shared<ISslService>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::SSL diff --git a/src/core/hle/service/ssl/ssl.h b/src/core/hle/service/ssl/ssl.h index 27b38a003..f6e21bbb3 100644 --- a/src/core/hle/service/ssl/ssl.h +++ b/src/core/hle/service/ssl/ssl.h @@ -7,13 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::SSL { -/// Registers all SSL services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::SSL diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp index f77cdbb43..868be60c5 100644 --- a/src/core/hle/service/time/time.cpp +++ b/src/core/hle/service/time/time.cpp @@ -5,8 +5,9 @@ #include "core/core.h" #include "core/core_timing.h" #include "core/hardware_properties.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/kernel.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/time/time.h" #include "core/hle/service/time/time_interface.h" #include "core/hle/service/time/time_manager.h" @@ -33,7 +34,7 @@ public: } private: - void GetCurrentTime(Kernel::HLERequestContext& ctx) { + void GetCurrentTime(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); if (!clock_core.IsInitialized()) { @@ -54,7 +55,7 @@ private: rb.Push<s64>(posix_time); } - void GetSystemClockContext(Kernel::HLERequestContext& ctx) { + void GetSystemClockContext(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); if (!clock_core.IsInitialized()) { @@ -97,7 +98,7 @@ public: } private: - void GetCurrentTimePoint(Kernel::HLERequestContext& ctx) { + void GetCurrentTimePoint(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); if (!clock_core.IsInitialized()) { @@ -177,7 +178,7 @@ Result Module::Interface::GetClockSnapshotFromSystemClockContextInternal( return ResultSuccess; } -void Module::Interface::GetStandardUserSystemClock(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetStandardUserSystemClock(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -185,7 +186,7 @@ void Module::Interface::GetStandardUserSystemClock(Kernel::HLERequestContext& ct system); } -void Module::Interface::GetStandardNetworkSystemClock(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetStandardNetworkSystemClock(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -193,14 +194,14 @@ void Module::Interface::GetStandardNetworkSystemClock(Kernel::HLERequestContext& system); } -void Module::Interface::GetStandardSteadyClock(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetStandardSteadyClock(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface<ISteadyClock>(system.GetTimeManager().GetStandardSteadyClockCore(), system); } -void Module::Interface::GetTimeZoneService(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetTimeZoneService(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -208,7 +209,7 @@ void Module::Interface::GetTimeZoneService(Kernel::HLERequestContext& ctx) { system.GetTimeManager().GetTimeZoneContentManager()); } -void Module::Interface::GetStandardLocalSystemClock(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetStandardLocalSystemClock(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -216,8 +217,7 @@ void Module::Interface::GetStandardLocalSystemClock(Kernel::HLERequestContext& c system); } -void Module::Interface::IsStandardNetworkSystemClockAccuracySufficient( - Kernel::HLERequestContext& ctx) { +void Module::Interface::IsStandardNetworkSystemClockAccuracySufficient(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); auto& clock_core{system.GetTimeManager().GetStandardNetworkSystemClockCore()}; IPC::ResponseBuilder rb{ctx, 3}; @@ -225,7 +225,7 @@ void Module::Interface::IsStandardNetworkSystemClockAccuracySufficient( rb.Push<u32>(clock_core.IsStandardNetworkSystemClockAccuracySufficient(system)); } -void Module::Interface::CalculateMonotonicSystemClockBaseTimePoint(Kernel::HLERequestContext& ctx) { +void Module::Interface::CalculateMonotonicSystemClockBaseTimePoint(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); auto& steady_clock_core{system.GetTimeManager().GetStandardSteadyClockCore()}; @@ -254,7 +254,7 @@ void Module::Interface::CalculateMonotonicSystemClockBaseTimePoint(Kernel::HLERe rb.Push(ERROR_TIME_MISMATCH); } -void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetClockSnapshot(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto type{rp.PopEnum<Clock::TimeType>()}; @@ -295,7 +295,7 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void Module::Interface::GetClockSnapshotFromSystemClockContext(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetClockSnapshotFromSystemClockContext(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto type{rp.PopEnum<Clock::TimeType>()}; @@ -321,8 +321,7 @@ void Module::Interface::GetClockSnapshotFromSystemClockContext(Kernel::HLEReques rb.Push(ResultSuccess); } -void Module::Interface::CalculateStandardUserSystemClockDifferenceByUser( - Kernel::HLERequestContext& ctx) { +void Module::Interface::CalculateStandardUserSystemClockDifferenceByUser(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); Clock::ClockSnapshot snapshot_a; @@ -349,7 +348,7 @@ void Module::Interface::CalculateStandardUserSystemClockDifferenceByUser( rb.PushRaw(time_span_type.nanoseconds); } -void Module::Interface::CalculateSpanBetween(Kernel::HLERequestContext& ctx) { +void Module::Interface::CalculateSpanBetween(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); Clock::ClockSnapshot snapshot_a; @@ -384,7 +383,7 @@ void Module::Interface::CalculateSpanBetween(Kernel::HLERequestContext& ctx) { rb.PushRaw(time_span_type.nanoseconds); } -void Module::Interface::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) { +void Module::Interface::GetSharedMemoryNativeHandle(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(ResultSuccess); @@ -397,11 +396,17 @@ Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& syst Module::Interface::~Interface() = default; -void InstallInterfaces(Core::System& system) { +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); auto module{std::make_shared<Module>()}; - std::make_shared<Time>(module, system, "time:a")->InstallAsService(system.ServiceManager()); - std::make_shared<Time>(module, system, "time:s")->InstallAsService(system.ServiceManager()); - std::make_shared<Time>(module, system, "time:u")->InstallAsService(system.ServiceManager()); + + server_manager->RegisterNamedService("time:a", + std::make_shared<Time>(module, system, "time:a")); + server_manager->RegisterNamedService("time:s", + std::make_shared<Time>(module, system, "time:s")); + server_manager->RegisterNamedService("time:u", + std::make_shared<Time>(module, system, "time:u")); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::Time diff --git a/src/core/hle/service/time/time.h b/src/core/hle/service/time/time.h index 76a46cfc7..b2d754ef3 100644 --- a/src/core/hle/service/time/time.h +++ b/src/core/hle/service/time/time.h @@ -22,18 +22,18 @@ public: const char* name); ~Interface() override; - void GetStandardUserSystemClock(Kernel::HLERequestContext& ctx); - void GetStandardNetworkSystemClock(Kernel::HLERequestContext& ctx); - void GetStandardSteadyClock(Kernel::HLERequestContext& ctx); - void GetTimeZoneService(Kernel::HLERequestContext& ctx); - void GetStandardLocalSystemClock(Kernel::HLERequestContext& ctx); - void IsStandardNetworkSystemClockAccuracySufficient(Kernel::HLERequestContext& ctx); - void CalculateMonotonicSystemClockBaseTimePoint(Kernel::HLERequestContext& ctx); - void GetClockSnapshot(Kernel::HLERequestContext& ctx); - void GetClockSnapshotFromSystemClockContext(Kernel::HLERequestContext& ctx); - void CalculateStandardUserSystemClockDifferenceByUser(Kernel::HLERequestContext& ctx); - void CalculateSpanBetween(Kernel::HLERequestContext& ctx); - void GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx); + void GetStandardUserSystemClock(HLERequestContext& ctx); + void GetStandardNetworkSystemClock(HLERequestContext& ctx); + void GetStandardSteadyClock(HLERequestContext& ctx); + void GetTimeZoneService(HLERequestContext& ctx); + void GetStandardLocalSystemClock(HLERequestContext& ctx); + void IsStandardNetworkSystemClockAccuracySufficient(HLERequestContext& ctx); + void CalculateMonotonicSystemClockBaseTimePoint(HLERequestContext& ctx); + void GetClockSnapshot(HLERequestContext& ctx); + void GetClockSnapshotFromSystemClockContext(HLERequestContext& ctx); + void CalculateStandardUserSystemClockDifferenceByUser(HLERequestContext& ctx); + void CalculateSpanBetween(HLERequestContext& ctx); + void GetSharedMemoryNativeHandle(HLERequestContext& ctx); private: Result GetClockSnapshotFromSystemClockContextInternal( @@ -46,7 +46,6 @@ public: }; }; -/// Registers all Time services with the specified service manager. -void InstallInterfaces(Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::Time diff --git a/src/core/hle/service/time/time_zone_service.cpp b/src/core/hle/service/time/time_zone_service.cpp index 961040bfc..cda8d8343 100644 --- a/src/core/hle/service/time/time_zone_service.cpp +++ b/src/core/hle/service/time/time_zone_service.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/time/time_zone_content_manager.h" #include "core/hle/service/time/time_zone_service.h" #include "core/hle/service/time/time_zone_types.h" @@ -28,7 +28,7 @@ ITimeZoneService::ITimeZoneService(Core::System& system_, RegisterHandlers(functions); } -void ITimeZoneService::GetDeviceLocationName(Kernel::HLERequestContext& ctx) { +void ITimeZoneService::GetDeviceLocationName(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); TimeZone::LocationName location_name{}; @@ -45,7 +45,7 @@ void ITimeZoneService::GetDeviceLocationName(Kernel::HLERequestContext& ctx) { rb.PushRaw(location_name); } -void ITimeZoneService::LoadTimeZoneRule(Kernel::HLERequestContext& ctx) { +void ITimeZoneService::LoadTimeZoneRule(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto raw_location_name{rp.PopRaw<std::array<u8, 0x24>>()}; @@ -77,7 +77,7 @@ void ITimeZoneService::LoadTimeZoneRule(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void ITimeZoneService::ToCalendarTime(Kernel::HLERequestContext& ctx) { +void ITimeZoneService::ToCalendarTime(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto posix_time{rp.Pop<s64>()}; @@ -101,7 +101,7 @@ void ITimeZoneService::ToCalendarTime(Kernel::HLERequestContext& ctx) { rb.PushRaw(calendar_info); } -void ITimeZoneService::ToCalendarTimeWithMyRule(Kernel::HLERequestContext& ctx) { +void ITimeZoneService::ToCalendarTimeWithMyRule(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto posix_time{rp.Pop<s64>()}; @@ -122,7 +122,7 @@ void ITimeZoneService::ToCalendarTimeWithMyRule(Kernel::HLERequestContext& ctx) rb.PushRaw(calendar_info); } -void ITimeZoneService::ToPosixTime(Kernel::HLERequestContext& ctx) { +void ITimeZoneService::ToPosixTime(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); IPC::RequestParser rp{ctx}; @@ -147,7 +147,7 @@ void ITimeZoneService::ToPosixTime(Kernel::HLERequestContext& ctx) { rb.PushRaw<u32>(1); // Number of times we're returning } -void ITimeZoneService::ToPosixTimeWithMyRule(Kernel::HLERequestContext& ctx) { +void ITimeZoneService::ToPosixTimeWithMyRule(HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); IPC::RequestParser rp{ctx}; diff --git a/src/core/hle/service/time/time_zone_service.h b/src/core/hle/service/time/time_zone_service.h index f151f4b56..ea83b5714 100644 --- a/src/core/hle/service/time/time_zone_service.h +++ b/src/core/hle/service/time/time_zone_service.h @@ -21,12 +21,12 @@ public: TimeZone::TimeZoneContentManager& time_zone_manager_); private: - void GetDeviceLocationName(Kernel::HLERequestContext& ctx); - void LoadTimeZoneRule(Kernel::HLERequestContext& ctx); - void ToCalendarTime(Kernel::HLERequestContext& ctx); - void ToCalendarTimeWithMyRule(Kernel::HLERequestContext& ctx); - void ToPosixTime(Kernel::HLERequestContext& ctx); - void ToPosixTimeWithMyRule(Kernel::HLERequestContext& ctx); + void GetDeviceLocationName(HLERequestContext& ctx); + void LoadTimeZoneRule(HLERequestContext& ctx); + void ToCalendarTime(HLERequestContext& ctx); + void ToCalendarTimeWithMyRule(HLERequestContext& ctx); + void ToPosixTime(HLERequestContext& ctx); + void ToPosixTimeWithMyRule(HLERequestContext& ctx); private: TimeZone::TimeZoneContentManager& time_zone_content_manager; diff --git a/src/core/hle/service/usb/usb.cpp b/src/core/hle/service/usb/usb.cpp index ac46a406c..f29fff1dd 100644 --- a/src/core/hle/service/usb/usb.cpp +++ b/src/core/hle/service/usb/usb.cpp @@ -4,9 +4,9 @@ #include <memory> #include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" +#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" -#include "core/hle/service/sm/sm.h" #include "core/hle/service/usb/usb.h" namespace Service::USB { @@ -16,19 +16,19 @@ public: explicit IDsInterface(Core::System& system_) : ServiceFramework{system_, "IDsInterface"} { // clang-format off static const FunctionInfo functions[] = { - {0, nullptr, "BindDevice"}, - {1, nullptr, "BindClientProcess"}, - {2, nullptr, "AddInterface"}, - {3, nullptr, "GetStateChangeEvent"}, - {4, nullptr, "GetState"}, - {5, nullptr, "ClearDeviceData"}, - {6, nullptr, "AddUsbStringDescriptor"}, - {7, nullptr, "DeleteUsbStringDescriptor"}, - {8, nullptr, "SetUsbDeviceDescriptor"}, - {9, nullptr, "SetBinaryObjectStore"}, - {10, nullptr, "Enable"}, - {11, nullptr, "Disable"}, - {12, nullptr, "Unknown12"}, + {0, nullptr, "AddEndpoint"}, + {1, nullptr, "GetSetupEvent"}, + {2, nullptr, "GetSetupPacket"}, + {3, nullptr, "Enable"}, + {4, nullptr, "Disable"}, + {5, nullptr, "CtrlIn"}, + {6, nullptr, "CtrlOut"}, + {7, nullptr, "GetCtrlInCompletionEvent"}, + {8, nullptr, "GetCtrlInUrbReport"}, + {9, nullptr, "GetCtrlOutCompletionEvent"}, + {10, nullptr, "GetCtrlOutUrbReport"}, + {11, nullptr, "CtrlStall"}, + {12, nullptr, "AppendConfigurationData"}, }; // clang-format on @@ -36,9 +36,9 @@ public: } }; -class USB_DS final : public ServiceFramework<USB_DS> { +class IDsRootSession final : public ServiceFramework<IDsRootSession> { public: - explicit USB_DS(Core::System& system_) : ServiceFramework{system_, "usb:ds"} { + explicit IDsRootSession(Core::System& system_) : ServiceFramework{system_, "usb:ds"} { // clang-format off static const FunctionInfo functions[] = { {0, nullptr, "OpenDsService"}, @@ -94,9 +94,9 @@ public: } }; -class USB_HS final : public ServiceFramework<USB_HS> { +class IClientRootSession final : public ServiceFramework<IClientRootSession> { public: - explicit USB_HS(Core::System& system_) : ServiceFramework{system_, "usb:hs"} { + explicit IClientRootSession(Core::System& system_) : ServiceFramework{system_, "usb:hs"} { // clang-format off static const FunctionInfo functions[] = { {0, nullptr, "BindClientProcess"}, @@ -107,7 +107,7 @@ public: {5, nullptr, "DestroyInterfaceAvailableEvent"}, {6, nullptr, "GetInterfaceStateChangeEvent"}, {7, nullptr, "AcquireUsbIf"}, - {8, nullptr, "ResetDevice"}, + {8, nullptr, "SetTestMode"}, }; // clang-format on @@ -134,12 +134,12 @@ public: } }; -class USB_PD final : public ServiceFramework<USB_PD> { +class IPdManager final : public ServiceFramework<IPdManager> { public: - explicit USB_PD(Core::System& system_) : ServiceFramework{system_, "usb:pd"} { + explicit IPdManager(Core::System& system_) : ServiceFramework{system_, "usb:pd"} { // clang-format off static const FunctionInfo functions[] = { - {0, &USB_PD::GetPdSession, "GetPdSession"}, + {0, &IPdManager::OpenSession, "OpenSession"}, }; // clang-format on @@ -147,7 +147,7 @@ public: } private: - void GetPdSession(Kernel::HLERequestContext& ctx) { + void OpenSession(HLERequestContext& ctx) { LOG_DEBUG(Service_USB, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -178,12 +178,12 @@ public: } }; -class USB_PD_C final : public ServiceFramework<USB_PD_C> { +class IPdCradleManager final : public ServiceFramework<IPdCradleManager> { public: - explicit USB_PD_C(Core::System& system_) : ServiceFramework{system_, "usb:pd:c"} { + explicit IPdCradleManager(Core::System& system_) : ServiceFramework{system_, "usb:pd:c"} { // clang-format off static const FunctionInfo functions[] = { - {0, &USB_PD_C::GetPdCradleSession, "GetPdCradleSession"}, + {0, &IPdCradleManager::OpenCradleSession, "OpenCradleSession"}, }; // clang-format on @@ -191,18 +191,18 @@ public: } private: - void GetPdCradleSession(Kernel::HLERequestContext& ctx) { + void OpenCradleSession(HLERequestContext& ctx) { + LOG_DEBUG(Service_USB, "called"); + IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); rb.PushIpcInterface<IPdCradleSession>(system); - - LOG_DEBUG(Service_USB, "called"); } }; -class USB_PM final : public ServiceFramework<USB_PM> { +class IPmMainService final : public ServiceFramework<IPmMainService> { public: - explicit USB_PM(Core::System& system_) : ServiceFramework{system_, "usb:pm"} { + explicit IPmMainService(Core::System& system_) : ServiceFramework{system_, "usb:pm"} { // clang-format off static const FunctionInfo functions[] = { {0, nullptr, "GetPowerEvent"}, @@ -218,12 +218,15 @@ public: } }; -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) { - std::make_shared<USB_DS>(system)->InstallAsService(sm); - std::make_shared<USB_HS>(system)->InstallAsService(sm); - std::make_shared<USB_PD>(system)->InstallAsService(sm); - std::make_shared<USB_PD_C>(system)->InstallAsService(sm); - std::make_shared<USB_PM>(system)->InstallAsService(sm); +void LoopProcess(Core::System& system) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService("usb:ds", std::make_shared<IDsRootSession>(system)); + server_manager->RegisterNamedService("usb:hs", std::make_shared<IClientRootSession>(system)); + server_manager->RegisterNamedService("usb:pd", std::make_shared<IPdManager>(system)); + server_manager->RegisterNamedService("usb:pd:c", std::make_shared<IPdCradleManager>(system)); + server_manager->RegisterNamedService("usb:pm", std::make_shared<IPmMainService>(system)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::USB diff --git a/src/core/hle/service/usb/usb.h b/src/core/hle/service/usb/usb.h index b41b9684c..98376ebc0 100644 --- a/src/core/hle/service/usb/usb.h +++ b/src/core/hle/service/usb/usb.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::USB { -void InstallInterfaces(SM::ServiceManager& sm, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::USB diff --git a/src/core/hle/service/vi/display/vi_display.cpp b/src/core/hle/service/vi/display/vi_display.cpp index 8ef74f1f0..69af2868a 100644 --- a/src/core/hle/service/vi/display/vi_display.cpp +++ b/src/core/hle/service/vi/display/vi_display.cpp @@ -12,11 +12,11 @@ #include "core/hle/kernel/k_readable_event.h" #include "core/hle/service/kernel_helpers.h" #include "core/hle/service/nvdrv/core/container.h" -#include "core/hle/service/nvflinger/buffer_item_consumer.h" -#include "core/hle/service/nvflinger/buffer_queue_consumer.h" -#include "core/hle/service/nvflinger/buffer_queue_core.h" -#include "core/hle/service/nvflinger/buffer_queue_producer.h" -#include "core/hle/service/nvflinger/hos_binder_driver_server.h" +#include "core/hle/service/nvnflinger/buffer_item_consumer.h" +#include "core/hle/service/nvnflinger/buffer_queue_consumer.h" +#include "core/hle/service/nvnflinger/buffer_queue_core.h" +#include "core/hle/service/nvnflinger/buffer_queue_producer.h" +#include "core/hle/service/nvnflinger/hos_binder_driver_server.h" #include "core/hle/service/vi/display/vi_display.h" #include "core/hle/service/vi/layer/vi_layer.h" #include "core/hle/service/vi/vi_results.h" @@ -39,7 +39,7 @@ static BufferQueue CreateBufferQueue(KernelHelpers::ServiceContext& service_cont } Display::Display(u64 id, std::string name_, - NVFlinger::HosBinderDriverServer& hos_binder_driver_server_, + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_, KernelHelpers::ServiceContext& service_context_, Core::System& system_) : display_id{id}, name{std::move(name_)}, hos_binder_driver_server{hos_binder_driver_server_}, service_context{service_context_} { diff --git a/src/core/hle/service/vi/display/vi_display.h b/src/core/hle/service/vi/display/vi_display.h index 0b65a65da..3f31d1f32 100644 --- a/src/core/hle/service/vi/display/vi_display.h +++ b/src/core/hle/service/vi/display/vi_display.h @@ -23,7 +23,7 @@ namespace Service::KernelHelpers { class ServiceContext; } -namespace Service::NVFlinger { +namespace Service::Nvnflinger { class HosBinderDriverServer; } @@ -45,12 +45,12 @@ public: /// Constructs a display with a given unique ID and name. /// /// @param id The unique ID for this display. - /// @param hos_binder_driver_server_ NVFlinger HOSBinderDriver server instance. + /// @param hos_binder_driver_server_ Nvnflinger HOSBinderDriver server instance. /// @param service_context_ The ServiceContext for the owning service. /// @param name_ The name for this display. /// @param system_ The global system instance. /// - Display(u64 id, std::string name_, NVFlinger::HosBinderDriverServer& hos_binder_driver_server_, + Display(u64 id, std::string name_, Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_, KernelHelpers::ServiceContext& service_context_, Core::System& system_); ~Display(); @@ -133,7 +133,7 @@ public: private: u64 display_id; std::string name; - NVFlinger::HosBinderDriverServer& hos_binder_driver_server; + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server; KernelHelpers::ServiceContext& service_context; std::vector<std::unique_ptr<Layer>> layers; diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 0915785d2..68eab5133 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -17,15 +17,16 @@ #include "common/settings.h" #include "common/swap.h" #include "core/core_timing.h" -#include "core/hle/ipc_helpers.h" #include "core/hle/kernel/k_readable_event.h" #include "core/hle/kernel/k_thread.h" +#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nvdrv/nvdata.h" -#include "core/hle/service/nvflinger/binder.h" -#include "core/hle/service/nvflinger/buffer_queue_producer.h" -#include "core/hle/service/nvflinger/hos_binder_driver_server.h" -#include "core/hle/service/nvflinger/nvflinger.h" -#include "core/hle/service/nvflinger/parcel.h" +#include "core/hle/service/nvnflinger/binder.h" +#include "core/hle/service/nvnflinger/buffer_queue_producer.h" +#include "core/hle/service/nvnflinger/hos_binder_driver_server.h" +#include "core/hle/service/nvnflinger/nvnflinger.h" +#include "core/hle/service/nvnflinger/parcel.h" +#include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" #include "core/hle/service/vi/vi.h" #include "core/hle/service/vi/vi_m.h" @@ -72,9 +73,8 @@ static_assert(sizeof(NativeWindow) == 0x28, "NativeWindow has wrong size"); class IHOSBinderDriver final : public ServiceFramework<IHOSBinderDriver> { public: - explicit IHOSBinderDriver(Core::System& system_, NVFlinger::HosBinderDriverServer& server_) - : ServiceFramework{system_, "IHOSBinderDriver", ServiceThreadType::CreateNew}, - server(server_) { + explicit IHOSBinderDriver(Core::System& system_, Nvnflinger::HosBinderDriverServer& server_) + : ServiceFramework{system_, "IHOSBinderDriver"}, server(server_) { static const FunctionInfo functions[] = { {0, &IHOSBinderDriver::TransactParcel, "TransactParcel"}, {1, &IHOSBinderDriver::AdjustRefcount, "AdjustRefcount"}, @@ -85,7 +85,7 @@ public: } private: - void TransactParcel(Kernel::HLERequestContext& ctx) { + void TransactParcel(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u32 id = rp.Pop<u32>(); const auto transaction = static_cast<android::TransactionId>(rp.Pop<u32>()); @@ -100,7 +100,7 @@ private: rb.Push(ResultSuccess); } - void AdjustRefcount(Kernel::HLERequestContext& ctx) { + void AdjustRefcount(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u32 id = rp.Pop<u32>(); const s32 addval = rp.PopRaw<s32>(); @@ -113,7 +113,7 @@ private: rb.Push(ResultSuccess); } - void GetNativeHandle(Kernel::HLERequestContext& ctx) { + void GetNativeHandle(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u32 id = rp.Pop<u32>(); const u32 unknown = rp.Pop<u32>(); @@ -126,7 +126,7 @@ private: } private: - NVFlinger::HosBinderDriverServer& server; + Nvnflinger::HosBinderDriverServer& server; }; class ISystemDisplayService final : public ServiceFramework<ISystemDisplayService> { @@ -186,7 +186,7 @@ public: } private: - void SetLayerZ(Kernel::HLERequestContext& ctx) { + void SetLayerZ(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 layer_id = rp.Pop<u64>(); const u64 z_value = rp.Pop<u64>(); @@ -200,7 +200,7 @@ private: // This function currently does nothing but return a success error code in // the vi library itself, so do the same thing, but log out the passed in values. - void SetLayerVisibility(Kernel::HLERequestContext& ctx) { + void SetLayerVisibility(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 layer_id = rp.Pop<u64>(); const bool visibility = rp.Pop<bool>(); @@ -211,7 +211,7 @@ private: rb.Push(ResultSuccess); } - void GetDisplayMode(Kernel::HLERequestContext& ctx) { + void GetDisplayMode(HLERequestContext& ctx) { LOG_WARNING(Service_VI, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 6}; @@ -232,7 +232,7 @@ private: class IManagerDisplayService final : public ServiceFramework<IManagerDisplayService> { public: - explicit IManagerDisplayService(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_) + explicit IManagerDisplayService(Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_) : ServiceFramework{system_, "IManagerDisplayService"}, nv_flinger{nv_flinger_} { // clang-format off static const FunctionInfo functions[] = { @@ -325,7 +325,7 @@ public: } private: - void CloseDisplay(Kernel::HLERequestContext& ctx) { + void CloseDisplay(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 display = rp.Pop<u64>(); @@ -335,7 +335,7 @@ private: rb.Push(rc); } - void CreateManagedLayer(Kernel::HLERequestContext& ctx) { + void CreateManagedLayer(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u32 unknown = rp.Pop<u32>(); rp.Skip(1, false); @@ -359,7 +359,7 @@ private: rb.Push(*layer_id); } - void AddToLayerStack(Kernel::HLERequestContext& ctx) { + void AddToLayerStack(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u32 stack = rp.Pop<u32>(); const u64 layer_id = rp.Pop<u64>(); @@ -371,7 +371,7 @@ private: rb.Push(ResultSuccess); } - void SetLayerVisibility(Kernel::HLERequestContext& ctx) { + void SetLayerVisibility(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 layer_id = rp.Pop<u64>(); const bool visibility = rp.Pop<bool>(); @@ -383,13 +383,13 @@ private: rb.Push(ResultSuccess); } - NVFlinger::NVFlinger& nv_flinger; + Nvnflinger::Nvnflinger& nv_flinger; }; class IApplicationDisplayService final : public ServiceFramework<IApplicationDisplayService> { public: - IApplicationDisplayService(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_, - NVFlinger::HosBinderDriverServer& hos_binder_driver_server_) + IApplicationDisplayService(Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_, + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_) : ServiceFramework{system_, "IApplicationDisplayService"}, nv_flinger{nv_flinger_}, hos_binder_driver_server{hos_binder_driver_server_} { @@ -440,7 +440,7 @@ private: PreserveAspectRatio = 4, }; - void GetRelayService(Kernel::HLERequestContext& ctx) { + void GetRelayService(HLERequestContext& ctx) { LOG_WARNING(Service_VI, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -448,7 +448,7 @@ private: rb.PushIpcInterface<IHOSBinderDriver>(system, hos_binder_driver_server); } - void GetSystemDisplayService(Kernel::HLERequestContext& ctx) { + void GetSystemDisplayService(HLERequestContext& ctx) { LOG_WARNING(Service_VI, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -456,7 +456,7 @@ private: rb.PushIpcInterface<ISystemDisplayService>(system); } - void GetManagerDisplayService(Kernel::HLERequestContext& ctx) { + void GetManagerDisplayService(HLERequestContext& ctx) { LOG_WARNING(Service_VI, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -464,7 +464,7 @@ private: rb.PushIpcInterface<IManagerDisplayService>(system, nv_flinger); } - void GetIndirectDisplayTransactionService(Kernel::HLERequestContext& ctx) { + void GetIndirectDisplayTransactionService(HLERequestContext& ctx) { LOG_WARNING(Service_VI, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -472,7 +472,7 @@ private: rb.PushIpcInterface<IHOSBinderDriver>(system, hos_binder_driver_server); } - void OpenDisplay(Kernel::HLERequestContext& ctx) { + void OpenDisplay(HLERequestContext& ctx) { LOG_WARNING(Service_VI, "(STUBBED) called"); IPC::RequestParser rp{ctx}; @@ -481,13 +481,13 @@ private: OpenDisplayImpl(ctx, std::string_view{name_buf.data(), name_buf.size()}); } - void OpenDefaultDisplay(Kernel::HLERequestContext& ctx) { + void OpenDefaultDisplay(HLERequestContext& ctx) { LOG_DEBUG(Service_VI, "called"); OpenDisplayImpl(ctx, "Default"); } - void OpenDisplayImpl(Kernel::HLERequestContext& ctx, std::string_view name) { + void OpenDisplayImpl(HLERequestContext& ctx, std::string_view name) { const auto trim_pos = name.find('\0'); if (trim_pos != std::string_view::npos) { @@ -509,7 +509,7 @@ private: rb.Push<u64>(*display_id); } - void CloseDisplay(Kernel::HLERequestContext& ctx) { + void CloseDisplay(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 display_id = rp.Pop<u64>(); @@ -521,14 +521,14 @@ private: // This literally does nothing internally in the actual service itself, // and just returns a successful result code regardless of the input. - void SetDisplayEnabled(Kernel::HLERequestContext& ctx) { + void SetDisplayEnabled(HLERequestContext& ctx) { LOG_DEBUG(Service_VI, "called."); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } - void GetDisplayResolution(Kernel::HLERequestContext& ctx) { + void GetDisplayResolution(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 display_id = rp.Pop<u64>(); @@ -544,7 +544,7 @@ private: rb.Push(static_cast<u64>(DisplayResolution::UndockedHeight)); } - void SetLayerScalingMode(Kernel::HLERequestContext& ctx) { + void SetLayerScalingMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto scaling_mode = rp.PopEnum<NintendoScaleMode>(); const u64 unknown = rp.Pop<u64>(); @@ -570,7 +570,7 @@ private: rb.Push(ResultSuccess); } - void ListDisplays(Kernel::HLERequestContext& ctx) { + void ListDisplays(HLERequestContext& ctx) { LOG_WARNING(Service_VI, "(STUBBED) called"); const DisplayInfo display_info; @@ -580,7 +580,7 @@ private: rb.Push<u64>(1); } - void OpenLayer(Kernel::HLERequestContext& ctx) { + void OpenLayer(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto name_buf = rp.PopRaw<std::array<u8, 0x40>>(); const auto end = std::find(name_buf.begin(), name_buf.end(), '\0'); @@ -616,7 +616,7 @@ private: rb.Push<u64>(buffer_size); } - void CloseLayer(Kernel::HLERequestContext& ctx) { + void CloseLayer(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto layer_id{rp.Pop<u64>()}; @@ -628,7 +628,7 @@ private: rb.Push(ResultSuccess); } - void CreateStrayLayer(Kernel::HLERequestContext& ctx) { + void CreateStrayLayer(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u32 flags = rp.Pop<u32>(); rp.Pop<u32>(); // padding @@ -663,7 +663,7 @@ private: rb.Push<u64>(buffer_size); } - void DestroyStrayLayer(Kernel::HLERequestContext& ctx) { + void DestroyStrayLayer(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 layer_id = rp.Pop<u64>(); @@ -673,7 +673,7 @@ private: rb.Push(ResultSuccess); } - void GetDisplayVsyncEvent(Kernel::HLERequestContext& ctx) { + void GetDisplayVsyncEvent(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 display_id = rp.Pop<u64>(); @@ -696,7 +696,7 @@ private: rb.PushCopyObjects(*vsync_event); } - void ConvertScalingMode(Kernel::HLERequestContext& ctx) { + void ConvertScalingMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto mode = rp.PopEnum<NintendoScaleMode>(); LOG_DEBUG(Service_VI, "called mode={}", mode); @@ -713,7 +713,7 @@ private: } } - void GetIndirectLayerImageMap(Kernel::HLERequestContext& ctx) { + void GetIndirectLayerImageMap(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto width = rp.Pop<s64>(); const auto height = rp.Pop<s64>(); @@ -739,7 +739,7 @@ private: rb.Push(ResultSuccess); } - void GetIndirectLayerImageRequiredMemoryInfo(Kernel::HLERequestContext& ctx) { + void GetIndirectLayerImageRequiredMemoryInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto width = rp.Pop<u64>(); const auto height = rp.Pop<u64>(); @@ -774,8 +774,8 @@ private: } } - NVFlinger::NVFlinger& nv_flinger; - NVFlinger::HosBinderDriverServer& hos_binder_driver_server; + Nvnflinger::Nvnflinger& nv_flinger; + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server; }; static bool IsValidServiceAccess(Permission permission, Policy policy) { @@ -790,9 +790,9 @@ static bool IsValidServiceAccess(Permission permission, Policy policy) { return false; } -void detail::GetDisplayServiceImpl(Kernel::HLERequestContext& ctx, Core::System& system, - NVFlinger::NVFlinger& nv_flinger, - NVFlinger::HosBinderDriverServer& hos_binder_driver_server, +void detail::GetDisplayServiceImpl(HLERequestContext& ctx, Core::System& system, + Nvnflinger::Nvnflinger& nv_flinger, + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server, Permission permission) { IPC::RequestParser rp{ctx}; const auto policy = rp.PopEnum<Policy>(); @@ -809,15 +809,17 @@ void detail::GetDisplayServiceImpl(Kernel::HLERequestContext& ctx, Core::System& rb.PushIpcInterface<IApplicationDisplayService>(system, nv_flinger, hos_binder_driver_server); } -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system, - NVFlinger::NVFlinger& nv_flinger, - NVFlinger::HosBinderDriverServer& hos_binder_driver_server) { - std::make_shared<VI_M>(system, nv_flinger, hos_binder_driver_server) - ->InstallAsService(service_manager); - std::make_shared<VI_S>(system, nv_flinger, hos_binder_driver_server) - ->InstallAsService(service_manager); - std::make_shared<VI_U>(system, nv_flinger, hos_binder_driver_server) - ->InstallAsService(service_manager); +void LoopProcess(Core::System& system, Nvnflinger::Nvnflinger& nv_flinger, + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server) { + auto server_manager = std::make_unique<ServerManager>(system); + + server_manager->RegisterNamedService( + "vi:m", std::make_shared<VI_M>(system, nv_flinger, hos_binder_driver_server)); + server_manager->RegisterNamedService( + "vi:s", std::make_shared<VI_S>(system, nv_flinger, hos_binder_driver_server)); + server_manager->RegisterNamedService( + "vi:u", std::make_shared<VI_U>(system, nv_flinger, hos_binder_driver_server)); + ServerManager::RunServer(std::move(server_manager)); } } // namespace Service::VI diff --git a/src/core/hle/service/vi/vi.h b/src/core/hle/service/vi/vi.h index fc2d717e7..a35b62f97 100644 --- a/src/core/hle/service/vi/vi.h +++ b/src/core/hle/service/vi/vi.h @@ -9,18 +9,14 @@ namespace Core { class System; } -namespace Kernel { +namespace Service { class HLERequestContext; } -namespace Service::NVFlinger { +namespace Service::Nvnflinger { class HosBinderDriverServer; -class NVFlinger; -} // namespace Service::NVFlinger - -namespace Service::SM { -class ServiceManager; -} +class Nvnflinger; +} // namespace Service::Nvnflinger namespace Service::VI { @@ -46,15 +42,13 @@ enum class Policy { }; namespace detail { -void GetDisplayServiceImpl(Kernel::HLERequestContext& ctx, Core::System& system, - NVFlinger::NVFlinger& nv_flinger, - NVFlinger::HosBinderDriverServer& hos_binder_driver_server, +void GetDisplayServiceImpl(HLERequestContext& ctx, Core::System& system, + Nvnflinger::Nvnflinger& nv_flinger, + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server, Permission permission); } // namespace detail -/// Registers all VI services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system, - NVFlinger::NVFlinger& nv_flinger, - NVFlinger::HosBinderDriverServer& hos_binder_driver_server); +void LoopProcess(Core::System& system, Nvnflinger::Nvnflinger& nv_flinger, + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server); } // namespace Service::VI diff --git a/src/core/hle/service/vi/vi_m.cpp b/src/core/hle/service/vi/vi_m.cpp index 7ca44354b..0f06dc2f3 100644 --- a/src/core/hle/service/vi/vi_m.cpp +++ b/src/core/hle/service/vi/vi_m.cpp @@ -7,8 +7,8 @@ namespace Service::VI { -VI_M::VI_M(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_, - NVFlinger::HosBinderDriverServer& hos_binder_driver_server_) +VI_M::VI_M(Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_, + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_) : ServiceFramework{system_, "vi:m"}, nv_flinger{nv_flinger_}, hos_binder_driver_server{ hos_binder_driver_server_} { static const FunctionInfo functions[] = { @@ -24,7 +24,7 @@ VI_M::VI_M(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_, VI_M::~VI_M() = default; -void VI_M::GetDisplayService(Kernel::HLERequestContext& ctx) { +void VI_M::GetDisplayService(HLERequestContext& ctx) { LOG_DEBUG(Service_VI, "called"); detail::GetDisplayServiceImpl(ctx, system, nv_flinger, hos_binder_driver_server, diff --git a/src/core/hle/service/vi/vi_m.h b/src/core/hle/service/vi/vi_m.h index 3bf76d439..9ca6f3905 100644 --- a/src/core/hle/service/vi/vi_m.h +++ b/src/core/hle/service/vi/vi_m.h @@ -9,28 +9,24 @@ namespace Core { class System; } -namespace Kernel { -class HLERequestContext; -} - -namespace Service::NVFlinger { +namespace Service::Nvnflinger { class HosBinderDriverServer; -class NVFlinger; -} // namespace Service::NVFlinger +class Nvnflinger; +} // namespace Service::Nvnflinger namespace Service::VI { class VI_M final : public ServiceFramework<VI_M> { public: - explicit VI_M(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_, - NVFlinger::HosBinderDriverServer& hos_binder_driver_server_); + explicit VI_M(Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_, + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_); ~VI_M() override; private: - void GetDisplayService(Kernel::HLERequestContext& ctx); + void GetDisplayService(HLERequestContext& ctx); - NVFlinger::NVFlinger& nv_flinger; - NVFlinger::HosBinderDriverServer& hos_binder_driver_server; + Nvnflinger::Nvnflinger& nv_flinger; + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server; }; } // namespace Service::VI diff --git a/src/core/hle/service/vi/vi_s.cpp b/src/core/hle/service/vi/vi_s.cpp index fd799dac1..77f7a88ff 100644 --- a/src/core/hle/service/vi/vi_s.cpp +++ b/src/core/hle/service/vi/vi_s.cpp @@ -7,8 +7,8 @@ namespace Service::VI { -VI_S::VI_S(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_, - NVFlinger::HosBinderDriverServer& hos_binder_driver_server_) +VI_S::VI_S(Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_, + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_) : ServiceFramework{system_, "vi:s"}, nv_flinger{nv_flinger_}, hos_binder_driver_server{ hos_binder_driver_server_} { static const FunctionInfo functions[] = { @@ -20,7 +20,7 @@ VI_S::VI_S(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_, VI_S::~VI_S() = default; -void VI_S::GetDisplayService(Kernel::HLERequestContext& ctx) { +void VI_S::GetDisplayService(HLERequestContext& ctx) { LOG_DEBUG(Service_VI, "called"); detail::GetDisplayServiceImpl(ctx, system, nv_flinger, hos_binder_driver_server, diff --git a/src/core/hle/service/vi/vi_s.h b/src/core/hle/service/vi/vi_s.h index 97503ac7f..157839c91 100644 --- a/src/core/hle/service/vi/vi_s.h +++ b/src/core/hle/service/vi/vi_s.h @@ -9,28 +9,24 @@ namespace Core { class System; } -namespace Kernel { -class HLERequestContext; -} - -namespace Service::NVFlinger { +namespace Service::Nvnflinger { class HosBinderDriverServer; -class NVFlinger; -} // namespace Service::NVFlinger +class Nvnflinger; +} // namespace Service::Nvnflinger namespace Service::VI { class VI_S final : public ServiceFramework<VI_S> { public: - explicit VI_S(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_, - NVFlinger::HosBinderDriverServer& hos_binder_driver_server_); + explicit VI_S(Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_, + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_); ~VI_S() override; private: - void GetDisplayService(Kernel::HLERequestContext& ctx); + void GetDisplayService(HLERequestContext& ctx); - NVFlinger::NVFlinger& nv_flinger; - NVFlinger::HosBinderDriverServer& hos_binder_driver_server; + Nvnflinger::Nvnflinger& nv_flinger; + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server; }; } // namespace Service::VI diff --git a/src/core/hle/service/vi/vi_u.cpp b/src/core/hle/service/vi/vi_u.cpp index 6cc54bd13..59e13c86b 100644 --- a/src/core/hle/service/vi/vi_u.cpp +++ b/src/core/hle/service/vi/vi_u.cpp @@ -7,8 +7,8 @@ namespace Service::VI { -VI_U::VI_U(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_, - NVFlinger::HosBinderDriverServer& hos_binder_driver_server_) +VI_U::VI_U(Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_, + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_) : ServiceFramework{system_, "vi:u"}, nv_flinger{nv_flinger_}, hos_binder_driver_server{ hos_binder_driver_server_} { static const FunctionInfo functions[] = { @@ -20,7 +20,7 @@ VI_U::VI_U(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_, VI_U::~VI_U() = default; -void VI_U::GetDisplayService(Kernel::HLERequestContext& ctx) { +void VI_U::GetDisplayService(HLERequestContext& ctx) { LOG_DEBUG(Service_VI, "called"); detail::GetDisplayServiceImpl(ctx, system, nv_flinger, hos_binder_driver_server, diff --git a/src/core/hle/service/vi/vi_u.h b/src/core/hle/service/vi/vi_u.h index 797941bd7..5d9ca54c6 100644 --- a/src/core/hle/service/vi/vi_u.h +++ b/src/core/hle/service/vi/vi_u.h @@ -9,28 +9,24 @@ namespace Core { class System; } -namespace Kernel { -class HLERequestContext; -} - -namespace Service::NVFlinger { +namespace Service::Nvnflinger { class HosBinderDriverServer; -class NVFlinger; -} // namespace Service::NVFlinger +class Nvnflinger; +} // namespace Service::Nvnflinger namespace Service::VI { class VI_U final : public ServiceFramework<VI_U> { public: - explicit VI_U(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_, - NVFlinger::HosBinderDriverServer& hos_binder_driver_server_); + explicit VI_U(Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_, + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_); ~VI_U() override; private: - void GetDisplayService(Kernel::HLERequestContext& ctx); + void GetDisplayService(HLERequestContext& ctx); - NVFlinger::NVFlinger& nv_flinger; - NVFlinger::HosBinderDriverServer& hos_binder_driver_server; + Nvnflinger::Nvnflinger& nv_flinger; + Nvnflinger::HosBinderDriverServer& hos_binder_driver_server; }; } // namespace Service::VI |