From a05aad41720c88d5b4e0a08211a6b664874d6e32 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Mon, 17 May 2021 20:18:48 +0200 Subject: [PATCH] early-access version 1693 --- README.md | 2 +- src/CMakeLists.txt | 1 + src/common/tree.h | 6 -- src/core/hle/ipc_helpers.h | 27 ++++---- src/core/hle/kernel/hle_ipc.cpp | 20 ++++-- src/core/hle/kernel/hle_ipc.h | 82 +++-------------------- src/core/hle/kernel/k_client_port.cpp | 8 +-- src/core/hle/kernel/k_client_port.h | 3 - src/core/hle/kernel/k_port.cpp | 7 +- src/core/hle/kernel/k_server_port.h | 16 +++-- src/core/hle/kernel/k_server_session.cpp | 35 +++++----- src/core/hle/kernel/k_server_session.h | 36 ++++------ src/core/hle/kernel/k_session.cpp | 2 +- src/core/hle/kernel/k_session.h | 4 -- src/core/hle/kernel/slab_helpers.h | 4 +- src/core/hle/service/audio/audren_u.cpp | 39 ++++------- src/core/hle/service/audio/audren_u.h | 2 + src/core/hle/service/service.cpp | 4 +- src/core/hle/service/sm/controller.cpp | 39 ++--------- src/core/hle/service/sm/sm.cpp | 20 +++--- src/core/hle/service/sm/sm.h | 2 +- src/yuzu/configuration/configure_debug.ui | 10 +-- 22 files changed, 135 insertions(+), 234 deletions(-) diff --git a/README.md b/README.md index feed90ecc..eb342810e 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 1692. +This is the source code for early-access 1693. ## Legal Notice diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8bd7e5f72..f30dd49a3 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,6 +54,7 @@ if (MSVC) /we4547 # 'operator' : operator before comma has no effect; expected operator with side-effect /we4549 # 'operator1': operator before comma has no effect; did you intend 'operator2'? /we4555 # Expression has no effect; expected expression with side-effect + /we4715 # 'function': not all control paths return a value /we4834 # Discarding return value of function with 'nodiscard' attribute /we5038 # data member 'member1' will be initialized after data member 'member2' ) diff --git a/src/common/tree.h b/src/common/tree.h index df88e20f4..9d2d0df4e 100755 --- a/src/common/tree.h +++ b/src/common/tree.h @@ -43,8 +43,6 @@ * The maximum height of a red-black tree is 2lg (n+1). */ -#include "common/assert.h" - namespace Common { template class RBHead { @@ -327,10 +325,6 @@ void RB_REMOVE_COLOR(RBHead* head, Node* parent, Node* elm) { while ((elm == nullptr || RB_IS_BLACK(elm)) && elm != head->Root() && parent != nullptr) { if (RB_LEFT(parent) == elm) { tmp = RB_RIGHT(parent); - if (!tmp) { - ASSERT_MSG(false, "tmp is invalid!"); - break; - } if (RB_IS_RED(tmp)) { RB_SET_BLACKRED(tmp, parent); RB_ROTATE_LEFT(head, parent, tmp); diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index 963f3db30..497f35d23 100755 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -86,8 +86,10 @@ public: // The entire size of the raw data section in u32 units, including the 16 bytes of mandatory // padding. - u32 raw_data_size = ctx.write_size = - ctx.IsTipc() ? normal_params_size - 1 : normal_params_size; + u32 raw_data_size = ctx.IsTipc() + ? normal_params_size - 1 + : sizeof(IPC::DataPayloadHeader) / 4 + 4 + normal_params_size; + u32 num_handles_to_move{}; u32 num_domain_objects{}; const bool always_move_handles{ @@ -99,20 +101,16 @@ public: } if (ctx.Session()->IsDomain()) { - raw_data_size += - static_cast(sizeof(DomainMessageHeader) / sizeof(u32) + num_domain_objects); - ctx.write_size += num_domain_objects; + raw_data_size += static_cast(sizeof(DomainMessageHeader) / 4 + num_domain_objects); } if (ctx.IsTipc()) { header.type.Assign(ctx.GetCommandType()); - } else { - raw_data_size += static_cast(sizeof(IPC::DataPayloadHeader) / sizeof(u32) + 4 + - normal_params_size); } - header.data_size.Assign(raw_data_size); - if (num_handles_to_copy || num_handles_to_move) { + ctx.data_size = static_cast(raw_data_size); + header.data_size.Assign(static_cast(raw_data_size)); + if (num_handles_to_copy != 0 || num_handles_to_move != 0) { header.enable_handle_descriptor.Assign(1); } PushRaw(header); @@ -145,8 +143,7 @@ public: data_payload_index = index; ctx.data_payload_offset = index; - ctx.write_size += index; - ctx.domain_offset = static_cast(index + raw_data_size / sizeof(u32)); + ctx.domain_offset = index + raw_data_size / 4; } template @@ -154,8 +151,8 @@ public: if (context->Session()->IsDomain()) { context->AddDomainObject(std::move(iface)); } else { - kernel.CurrentProcess()->GetResourceLimit()->Reserve( - Kernel::LimitableResource::Sessions, 1); + // kernel.CurrentProcess()->GetResourceLimit()->Reserve( + // Kernel::LimitableResource::Sessions, 1); auto* session = Kernel::KSession::Create(kernel); session->Initialize(nullptr, iface->GetServiceName()); @@ -407,7 +404,7 @@ public: std::shared_ptr PopIpcInterface() { ASSERT(context->Session()->IsDomain()); ASSERT(context->GetDomainMessageHeader().input_object_count > 0); - return context->GetDomainHandler(Pop() - 1); + return context->GetDomainRequestHandler(Pop() - 1); } }; diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 1b1a7a694..ce3466df8 100755 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -35,11 +35,11 @@ SessionRequestHandler::SessionRequestHandler() = default; SessionRequestHandler::~SessionRequestHandler() = default; void SessionRequestHandler::ClientConnected(KServerSession* session) { - session->SetSessionHandler(shared_from_this()); + session->SetHleHandler(shared_from_this()); } void SessionRequestHandler::ClientDisconnected(KServerSession* session) { - session->SetSessionHandler(nullptr); + session->SetHleHandler(nullptr); } HLERequestContext::HLERequestContext(KernelCore& kernel_, Core::Memory::Memory& memory_, @@ -186,6 +186,18 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_t auto& owner_process = *requesting_thread.GetOwnerProcess(); auto& handle_table = owner_process.GetHandleTable(); + // The data_size already includes the payload header, the padding and the domain header. + std::size_t size{}; + + if (IsTipc()) { + size = cmd_buf.size(); + } else { + size = data_payload_offset + data_size - sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4; + if (Session()->IsDomain()) { + size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32); + } + } + for (auto& object : copy_objects) { Handle handle{}; if (object) { @@ -210,7 +222,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_t if (Session()->IsDomain()) { current_offset = domain_offset - static_cast(domain_objects.size()); for (const auto& object : domain_objects) { - server_session->AppendDomainHandler(object); + server_session->AppendDomainRequestHandler(object); cmd_buf[current_offset++] = static_cast(server_session->NumDomainRequestHandlers()); } @@ -218,7 +230,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_t // Copy the translated command buffer back into the thread's command buffer area. memory.WriteBlock(owner_process, requesting_thread.GetTLSAddress(), cmd_buf.data(), - write_size * sizeof(u32)); + size * sizeof(u32)); return RESULT_SUCCESS; } diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index e9608e44f..4fba300dc 100755 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -12,8 +12,6 @@ #include #include #include - -#include "common/assert.h" #include "common/common_types.h" #include "common/concepts.h" #include "common/swap.h" @@ -86,69 +84,6 @@ public: void ClientDisconnected(KServerSession* session); }; -using SessionRequestHandlerPtr = std::shared_ptr; - -/** - * Manages the underlying HLE requests for a session, and whether (or not) the session should be - * treated as a domain. This is managed separately from server sessions, as this state is shared - * when objects are cloned. - */ -class SessionRequestManager final { -public: - SessionRequestManager() = default; - - bool IsDomain() const { - return is_domain; - } - - void ConvertToDomain() { - domain_handlers = {session_handler}; - is_domain = true; - } - - std::size_t DomainHandlerCount() const { - return domain_handlers.size(); - } - - bool HasSessionHandler() const { - return session_handler != nullptr; - } - - SessionRequestHandler& SessionHandler() { - return *session_handler; - } - - const SessionRequestHandler& SessionHandler() const { - return *session_handler; - } - - void CloseDomainHandler(std::size_t index) { - if (index < DomainHandlerCount()) { - domain_handlers[index] = nullptr; - } else { - UNREACHABLE_MSG("Unexpected handler index {}", index); - } - } - - SessionRequestHandlerPtr DomainHandler(std::size_t index) const { - ASSERT_MSG(index < DomainHandlerCount(), "Unexpected handler index {}", index); - return domain_handlers.at(index); - } - - void AppendDomainHandler(SessionRequestHandlerPtr&& handler) { - domain_handlers.emplace_back(std::move(handler)); - } - - void SetSessionHandler(SessionRequestHandlerPtr&& handler) { - session_handler = std::move(handler); - } - -private: - bool is_domain{}; - SessionRequestHandlerPtr session_handler; - std::vector domain_handlers; -}; - /** * 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 @@ -300,17 +235,18 @@ public: copy_objects.emplace_back(object); } - void AddDomainObject(SessionRequestHandlerPtr object) { + void AddDomainObject(std::shared_ptr object) { domain_objects.emplace_back(std::move(object)); } template - std::shared_ptr GetDomainHandler(std::size_t index) const { - return std::static_pointer_cast(manager->DomainHandler(index)); + std::shared_ptr GetDomainRequestHandler(std::size_t index) const { + return std::static_pointer_cast(domain_request_handlers.at(index)); } - void SetSessionRequestManager(std::shared_ptr manager_) { - manager = std::move(manager_); + void SetDomainRequestHandlers( + const std::vector>& handlers) { + domain_request_handlers = handlers; } /// Clears the list of objects so that no lingering objects are written accidentally to the @@ -357,7 +293,7 @@ private: boost::container::small_vector copy_handles; boost::container::small_vector move_objects; boost::container::small_vector copy_objects; - boost::container::small_vector domain_objects; + boost::container::small_vector, 8> domain_objects; std::optional command_header; std::optional handle_descriptor_header; @@ -369,13 +305,13 @@ private: std::vector buffer_w_desciptors; std::vector buffer_c_desciptors; - u32 write_size{}; u32 data_payload_offset{}; u32 handles_offset{}; u32 domain_offset{}; + u32 data_size{}; u32_le command{}; - std::shared_ptr manager; + std::vector> domain_request_handlers; bool is_thread_waiting{}; KernelCore& kernel; diff --git a/src/core/hle/kernel/k_client_port.cpp b/src/core/hle/kernel/k_client_port.cpp index 4a12dee10..ad01cf67e 100755 --- a/src/core/hle/kernel/k_client_port.cpp +++ b/src/core/hle/kernel/k_client_port.cpp @@ -58,9 +58,9 @@ bool KClientPort::IsSignaled() const { ResultCode KClientPort::CreateSession(KClientSession** out) { // Reserve a new session from the resource limit. - KScopedResourceReservation session_reservation(kernel.CurrentProcess()->GetResourceLimit(), - LimitableResource::Sessions); - R_UNLESS(session_reservation.Succeeded(), ResultLimitReached); + // KScopedResourceReservation session_reservation(kernel.CurrentProcess()->GetResourceLimit(), + // LimitableResource::Sessions); + // R_UNLESS(session_reservation.Succeeded(), ResultLimitReached); // Update the session counts. { @@ -104,7 +104,7 @@ ResultCode KClientPort::CreateSession(KClientSession** out) { session->Initialize(this, parent->GetName()); // Commit the session reservation. - session_reservation.Commit(); + // session_reservation.Commit(); // Register the session. KSession::Register(kernel, session); diff --git a/src/core/hle/kernel/k_client_port.h b/src/core/hle/kernel/k_client_port.h index 8501156e8..d00ce3ddd 100755 --- a/src/core/hle/kernel/k_client_port.h +++ b/src/core/hle/kernel/k_client_port.h @@ -31,9 +31,6 @@ public: const KPort* GetParent() const { return parent; } - KPort* GetParent() { - return parent; - } s32 GetNumSessions() const { return num_sessions; diff --git a/src/core/hle/kernel/k_port.cpp b/src/core/hle/kernel/k_port.cpp index 723a1b571..feb2bb11f 100755 --- a/src/core/hle/kernel/k_port.cpp +++ b/src/core/hle/kernel/k_port.cpp @@ -56,8 +56,11 @@ ResultCode KPort::EnqueueSession(KServerSession* session) { R_UNLESS(state == State::Normal, ResultPortClosed); - server.GetSessionRequestHandler()->ClientConnected(session); - server.EnqueueSession(session); + if (server.HasHLEHandler()) { + server.GetHLEHandler()->ClientConnected(session); + } else { + server.EnqueueSession(session); + } return RESULT_SUCCESS; } diff --git a/src/core/hle/kernel/k_server_port.h b/src/core/hle/kernel/k_server_port.h index d1a757ec3..e76792253 100755 --- a/src/core/hle/kernel/k_server_port.h +++ b/src/core/hle/kernel/k_server_port.h @@ -32,24 +32,26 @@ public: explicit KServerPort(KernelCore& kernel_); virtual ~KServerPort() override; + using HLEHandler = std::shared_ptr; + void Initialize(KPort* parent_, std::string&& name_); /// Whether or not this server port has an HLE handler available. - bool HasSessionRequestHandler() const { - return session_handler != nullptr; + bool HasHLEHandler() const { + return hle_handler != nullptr; } /// Gets the HLE handler for this port. - SessionRequestHandlerPtr GetSessionRequestHandler() const { - return session_handler; + HLEHandler GetHLEHandler() const { + return hle_handler; } /** * Sets the HLE handler template for the port. ServerSessions crated by connecting to this port * will inherit a reference to this handler. */ - void SetSessionHandler(SessionRequestHandlerPtr&& handler) { - session_handler = std::move(handler); + void SetHleHandler(HLEHandler hle_handler_) { + hle_handler = std::move(hle_handler_); } void EnqueueSession(KServerSession* pending_session); @@ -71,7 +73,7 @@ private: private: SessionList session_list; - SessionRequestHandlerPtr session_handler; + HLEHandler hle_handler; KPort* parent{}; }; diff --git a/src/core/hle/kernel/k_server_session.cpp b/src/core/hle/kernel/k_server_session.cpp index 457fdfd60..8850d9af5 100755 --- a/src/core/hle/kernel/k_server_session.cpp +++ b/src/core/hle/kernel/k_server_session.cpp @@ -23,8 +23,7 @@ namespace Kernel { -KServerSession::KServerSession(KernelCore& kernel_) - : KSynchronizationObject{kernel_}, manager{std::make_shared()} {} +KServerSession::KServerSession(KernelCore& kernel_) : KSynchronizationObject{kernel_} {} KServerSession::~KServerSession() { kernel.ReleaseServiceThread(service_thread); @@ -44,8 +43,14 @@ void KServerSession::Destroy() { } void KServerSession::OnClientClosed() { - if (manager->HasSessionHandler()) { - manager->SessionHandler().ClientDisconnected(this); + // We keep a shared pointer to the hle handler to keep it alive throughout + // the call to ClientDisconnected, as ClientDisconnected invalidates the + // hle_handler member itself during the course of the function executing. + std::shared_ptr handler = hle_handler; + if (handler) { + // Note that after this returns, this server session's hle_handler is + // invalidated (set to null). + handler->ClientDisconnected(this); } } @@ -61,12 +66,12 @@ bool KServerSession::IsSignaled() const { return false; } -void KServerSession::AppendDomainHandler(SessionRequestHandlerPtr handler) { - manager->AppendDomainHandler(std::move(handler)); +void KServerSession::AppendDomainRequestHandler(std::shared_ptr handler) { + domain_request_handlers.push_back(std::move(handler)); } std::size_t KServerSession::NumDomainRequestHandlers() const { - return manager->DomainHandlerCount(); + return domain_request_handlers.size(); } ResultCode KServerSession::HandleDomainSyncRequest(Kernel::HLERequestContext& context) { @@ -75,14 +80,14 @@ ResultCode KServerSession::HandleDomainSyncRequest(Kernel::HLERequestContext& co } // Set domain handlers in HLE context, used for domain objects (IPC interfaces) as inputs - context.SetSessionRequestManager(manager); + context.SetDomainRequestHandlers(domain_request_handlers); // If there is a DomainMessageHeader, then this is CommandType "Request" const auto& domain_message_header = context.GetDomainMessageHeader(); const u32 object_id{domain_message_header.object_id}; switch (domain_message_header.command) { case IPC::DomainMessageHeader::CommandType::SendMessage: - if (object_id > manager->DomainHandlerCount()) { + if (object_id > domain_request_handlers.size()) { LOG_CRITICAL(IPC, "object_id {} is too big! This probably means a recent service call " "to {} needed to return a new interface!", @@ -90,12 +95,12 @@ ResultCode KServerSession::HandleDomainSyncRequest(Kernel::HLERequestContext& co UNREACHABLE(); return RESULT_SUCCESS; // Ignore error if asserts are off } - return manager->DomainHandler(object_id - 1)->HandleSyncRequest(*this, context); + return domain_request_handlers[object_id - 1]->HandleSyncRequest(*this, context); case IPC::DomainMessageHeader::CommandType::CloseVirtualHandle: { LOG_DEBUG(IPC, "CloseVirtualHandle, object_id=0x{:08X}", object_id); - manager->CloseDomainHandler(object_id - 1); + domain_request_handlers[object_id - 1] = nullptr; IPC::ResponseBuilder rb{context, 2}; rb.Push(RESULT_SUCCESS); @@ -128,14 +133,14 @@ ResultCode KServerSession::CompleteSyncRequest(HLERequestContext& context) { if (IsDomain() && context.HasDomainMessageHeader()) { result = HandleDomainSyncRequest(context); // If there is no domain header, the regular session handler is used - } else if (manager->HasSessionHandler()) { + } else if (hle_handler != nullptr) { // If this ServerSession has an associated HLE handler, forward the request to it. - result = manager->SessionHandler().HandleSyncRequest(*this, context); + result = hle_handler->HandleSyncRequest(*this, context); } if (convert_to_domain) { - ASSERT_MSG(!IsDomain(), "ServerSession is already a domain instance."); - manager->ConvertToDomain(); + ASSERT_MSG(IsSession(), "ServerSession is already a domain instance."); + domain_request_handlers = {hle_handler}; convert_to_domain = false; } diff --git a/src/core/hle/kernel/k_server_session.h b/src/core/hle/kernel/k_server_session.h index dd4de2904..597d76d38 100755 --- a/src/core/hle/kernel/k_server_session.h +++ b/src/core/hle/kernel/k_server_session.h @@ -12,7 +12,6 @@ #include #include "common/threadsafe_queue.h" -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_synchronization_object.h" #include "core/hle/kernel/service_thread.h" #include "core/hle/result.h" @@ -65,8 +64,8 @@ public: * instead of the regular IPC machinery. (The regular IPC machinery is currently not * implemented.) */ - void SetSessionHandler(SessionRequestHandlerPtr handler) { - manager->SetSessionHandler(std::move(handler)); + void SetHleHandler(std::shared_ptr hle_handler_) { + hle_handler = std::move(hle_handler_); } /** @@ -83,7 +82,7 @@ public: /// Adds a new domain request handler to the collection of request handlers within /// this ServerSession instance. - void AppendDomainHandler(SessionRequestHandlerPtr handler); + void AppendDomainRequestHandler(std::shared_ptr handler); /// Retrieves the total number of domain request handlers that have been /// appended to this ServerSession instance. @@ -91,7 +90,12 @@ public: /// Returns true if the session has been converted to a domain, otherwise False bool IsDomain() const { - return manager->IsDomain(); + return !IsSession(); + } + + /// Returns true if this session has not been converted to a domain, otherwise false. + bool IsSession() const { + return domain_request_handlers.empty(); } /// Converts the session to a domain at the end of the current command @@ -99,21 +103,6 @@ public: convert_to_domain = true; } - /// Gets the session request manager, which forwards requests to the underlying service - std::shared_ptr& GetSessionRequestManager() { - return manager; - } - - /// Gets the session request manager, which forwards requests to the underlying service - const std::shared_ptr& GetSessionRequestManager() const { - return manager; - } - - /// Sets the session request manager, which forwards requests to the underlying service - void SetSessionRequestManager(std::shared_ptr manager_) { - manager = std::move(manager_); - } - private: /// Queues a sync request from the emulated application. ResultCode QueueSyncRequest(KThread* thread, Core::Memory::Memory& memory); @@ -125,8 +114,11 @@ private: /// object handle. ResultCode HandleDomainSyncRequest(Kernel::HLERequestContext& context); - /// This session's HLE request handlers - std::shared_ptr manager; + /// This session's HLE request handler (applicable when not a domain) + std::shared_ptr hle_handler; + + /// This is the list of domain request handlers (after conversion to a domain) + std::vector> domain_request_handlers; /// When set to True, converts the session to a domain at the end of the command bool convert_to_domain{}; diff --git a/src/core/hle/kernel/k_session.cpp b/src/core/hle/kernel/k_session.cpp index 025b8b555..b7ce27a0b 100755 --- a/src/core/hle/kernel/k_session.cpp +++ b/src/core/hle/kernel/k_session.cpp @@ -78,7 +78,7 @@ void KSession::OnClientClosed() { void KSession::PostDestroy(uintptr_t arg) { // Release the session count resource the owner process holds. KProcess* owner = reinterpret_cast(arg); - owner->GetResourceLimit()->Release(LimitableResource::Sessions, 1); + // owner->GetResourceLimit()->Release(LimitableResource::Sessions, 1); owner->Close(); } diff --git a/src/core/hle/kernel/k_session.h b/src/core/hle/kernel/k_session.h index a981fd1f6..16901e19c 100755 --- a/src/core/hle/kernel/k_session.h +++ b/src/core/hle/kernel/k_session.h @@ -66,10 +66,6 @@ public: return port; } - KClientPort* GetParent() { - return port; - } - private: enum class State : u8 { Invalid = 0, diff --git a/src/core/hle/kernel/slab_helpers.h b/src/core/hle/kernel/slab_helpers.h index 0c5995db0..d0f7f084b 100755 --- a/src/core/hle/kernel/slab_helpers.h +++ b/src/core/hle/kernel/slab_helpers.h @@ -67,11 +67,11 @@ class KAutoObjectWithSlabHeapAndContainer : public Base { private: static Derived* Allocate(KernelCore& kernel) { - return kernel.SlabHeap().AllocateWithKernel(kernel); + return new Derived(kernel); } static void Free(KernelCore& kernel, Derived* obj) { - kernel.SlabHeap().Free(obj); + delete obj; } public: diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index fbb6f3528..ae4284adf 100755 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp @@ -169,10 +169,9 @@ private: class IAudioDevice final : public ServiceFramework { public: - explicit IAudioDevice(Core::System& system_, u32_le revision_num) - : ServiceFramework{system_, "IAudioDevice"}, revision{revision_num}, - buffer_event{system.Kernel()}, audio_input_device_switch_event{system.Kernel()}, - audio_output_device_switch_event{system.Kernel()} { + explicit IAudioDevice(Core::System& system_, Kernel::KEvent& buffer_event_, u32_le revision_) + : ServiceFramework{system_, "IAudioDevice"}, buffer_event{buffer_event_}, revision{ + revision_} { static const FunctionInfo functions[] = { {0, &IAudioDevice::ListAudioDeviceName, "ListAudioDeviceName"}, {1, &IAudioDevice::SetAudioDeviceOutputVolume, "SetAudioDeviceOutputVolume"}, @@ -189,18 +188,6 @@ public: {13, nullptr, "GetAudioSystemMasterVolumeSetting"}, }; RegisterHandlers(functions); - - Kernel::KAutoObject::Create(std::addressof(buffer_event)); - buffer_event.Initialize("IAudioOutBufferReleasedEvent"); - - // Should be similar to audio_output_device_switch_event - Kernel::KAutoObject::Create(std::addressof(audio_input_device_switch_event)); - audio_input_device_switch_event.Initialize("IAudioDevice:AudioInputDeviceSwitchedEvent"); - - // Should only be signalled when an audio output device has been changed, example: speaker - // to headset - Kernel::KAutoObject::Create(std::addressof(audio_output_device_switch_event)); - audio_output_device_switch_event.Initialize("IAudioDevice:AudioOutputDeviceSwitchedEvent"); } private: @@ -310,7 +297,7 @@ private: IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(RESULT_SUCCESS); - rb.PushCopyObjects(audio_input_device_switch_event.GetReadableEvent()); + rb.PushCopyObjects(buffer_event.GetReadableEvent()); } void QueryAudioDeviceOutputEvent(Kernel::HLERequestContext& ctx) { @@ -318,17 +305,16 @@ private: IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(RESULT_SUCCESS); - rb.PushCopyObjects(audio_output_device_switch_event.GetReadableEvent()); + rb.PushCopyObjects(buffer_event.GetReadableEvent()); } + Kernel::KEvent& buffer_event; u32_le revision = 0; - Kernel::KEvent buffer_event; - Kernel::KEvent audio_input_device_switch_event; - Kernel::KEvent audio_output_device_switch_event; +}; -}; // namespace Audio +AudRenU::AudRenU(Core::System& system_) + : ServiceFramework{system_, "audren:u"}, buffer_event{system.Kernel()} { -AudRenU::AudRenU(Core::System& system_) : ServiceFramework{system_, "audren:u"} { // clang-format off static const FunctionInfo functions[] = { {0, &AudRenU::OpenAudioRenderer, "OpenAudioRenderer"}, @@ -340,6 +326,9 @@ AudRenU::AudRenU(Core::System& system_) : ServiceFramework{system_, "audren:u"} // clang-format on RegisterHandlers(functions); + + Kernel::KAutoObject::Create(std::addressof(buffer_event)); + buffer_event.Initialize("IAudioOutBufferReleasedEvent"); } AudRenU::~AudRenU() = default; @@ -663,7 +652,7 @@ void AudRenU::GetAudioDeviceService(Kernel::HLERequestContext& ctx) { // always assumes the initial release revision (REV1). IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); - rb.PushIpcInterface(system, Common::MakeMagic('R', 'E', 'V', '1')); + rb.PushIpcInterface(system, buffer_event, Common::MakeMagic('R', 'E', 'V', '1')); } void AudRenU::OpenAudioRendererForManualExecution(Kernel::HLERequestContext& ctx) { @@ -685,7 +674,7 @@ void AudRenU::GetAudioDeviceServiceWithRevisionInfo(Kernel::HLERequestContext& c IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); - rb.PushIpcInterface(system, revision); + rb.PushIpcInterface(system, buffer_event, revision); } void AudRenU::OpenAudioRendererImpl(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/audio/audren_u.h b/src/core/hle/service/audio/audren_u.h index 37e8b4716..0ee6f9542 100755 --- a/src/core/hle/service/audio/audren_u.h +++ b/src/core/hle/service/audio/audren_u.h @@ -4,6 +4,7 @@ #pragma once +#include "core/hle/kernel/k_event.h" #include "core/hle/service/service.h" namespace Core { @@ -31,6 +32,7 @@ private: void OpenAudioRendererImpl(Kernel::HLERequestContext& ctx); std::size_t audren_instance_count = 0; + Kernel::KEvent buffer_event; }; // Describes a particular audio feature that may be supported in a particular revision. diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index fa61a5c7b..2c9b2ce6d 100755 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -107,7 +107,7 @@ void ServiceFrameworkBase::InstallAsService(SM::ServiceManager& service_manager) ASSERT(!port_installed); auto port = service_manager.RegisterService(service_name, max_sessions).Unwrap(); - port->SetSessionHandler(shared_from_this()); + port->SetHleHandler(shared_from_this()); port_installed = true; } @@ -118,7 +118,7 @@ Kernel::KClientPort& ServiceFrameworkBase::CreatePort(Kernel::KernelCore& kernel auto* port = Kernel::KPort::Create(kernel); port->Initialize(max_sessions, false, service_name); - port->GetServerPort().SetSessionHandler(shared_from_this()); + port->GetServerPort().SetHleHandler(shared_from_this()); port_installed = true; diff --git a/src/core/hle/service/sm/controller.cpp b/src/core/hle/service/sm/controller.cpp index 147f12147..de530cbfb 100755 --- a/src/core/hle/service/sm/controller.cpp +++ b/src/core/hle/service/sm/controller.cpp @@ -4,13 +4,8 @@ #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_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/kernel/k_server_session.h" #include "core/hle/kernel/k_session.h" #include "core/hle/service/sm/controller.h" @@ -18,7 +13,7 @@ namespace Service::SM { void Controller::ConvertCurrentObjectToDomain(Kernel::HLERequestContext& ctx) { - ASSERT_MSG(!ctx.Session()->IsDomain(), "Session is already a domain"); + ASSERT_MSG(ctx.Session()->IsSession(), "Session is already a domain"); LOG_DEBUG(Service, "called, server_session={}", ctx.Session()->GetId()); ctx.Session()->ConvertToDomain(); @@ -34,36 +29,16 @@ void Controller::CloneCurrentObject(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service, "called"); - auto& kernel = system.Kernel(); - auto* session = ctx.Session()->GetParent(); - auto* port = session->GetParent()->GetParent(); + auto session = ctx.Session()->GetParent(); - // Reserve a new session from the process resource limit. - Kernel::KScopedResourceReservation session_reservation( - kernel.CurrentProcess()->GetResourceLimit(), Kernel::LimitableResource::Sessions); - if (!session_reservation.Succeeded()) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(Kernel::ResultLimitReached); - } + // Open a reference to the session to simulate a new one being created. + session->Open(); + session->GetClientSession().Open(); + session->GetServerSession().Open(); - // Create a new session. - auto* clone = Kernel::KSession::Create(kernel); - clone->Initialize(&port->GetClientPort(), session->GetName()); - - // Commit the session reservation. - session_reservation.Commit(); - - // Enqueue the session with the named port. - port->EnqueueSession(&clone->GetServerSession()); - - // Set the session request manager. - clone->GetServerSession().SetSessionRequestManager( - session->GetServerSession().GetSessionRequestManager()); - - // We succeeded. IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles}; rb.Push(RESULT_SUCCESS); - rb.PushMoveObjects(clone->GetClientSession()); + rb.PushMoveObjects(session->GetClientSession()); } void Controller::CloneCurrentObjectEx(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp index a9bc7da74..8cc9aee8a 100755 --- a/src/core/hle/service/sm/sm.cpp +++ b/src/core/hle/service/sm/sm.cpp @@ -150,31 +150,31 @@ ResultVal SM::GetServiceImpl(Kernel::HLERequestContext& IPC::RequestParser rp{ctx}; std::string name(PopServiceName(rp)); - // Find the named port. auto result = service_manager.GetServicePort(name); if (result.Failed()) { LOG_ERROR(Service_SM, "called service={} -> error 0x{:08X}", name, result.Code().raw); return result.Code(); } + auto* port = result.Unwrap(); - // Reserve a new session from the process resource limit. - Kernel::KScopedResourceReservation session_reservation( - kernel.CurrentProcess()->GetResourceLimit(), Kernel::LimitableResource::Sessions); - R_UNLESS(session_reservation.Succeeded(), Kernel::ResultLimitReached); + // Kernel::KScopedResourceReservation session_reservation( + // kernel.CurrentProcess()->GetResourceLimit(), Kernel::LimitableResource::Sessions); + // R_UNLESS(session_reservation.Succeeded(), Kernel::ResultLimitReached); - // Create a new session. auto* session = Kernel::KSession::Create(kernel); session->Initialize(&port->GetClientPort(), std::move(name)); // Commit the session reservation. - session_reservation.Commit(); + // session_reservation.Commit(); - // Enqueue the session with the named port. - port->EnqueueSession(&session->GetServerSession()); + if (port->GetServerPort().GetHLEHandler()) { + port->GetServerPort().GetHLEHandler()->ClientConnected(&session->GetServerSession()); + } else { + port->EnqueueSession(&session->GetServerSession()); + } LOG_DEBUG(Service_SM, "called service={} -> session={}", name, session->GetId()); - return MakeResult(&session->GetClientSession()); } diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h index ea37f11d4..60f0b3f8a 100755 --- a/src/core/hle/service/sm/sm.h +++ b/src/core/hle/service/sm/sm.h @@ -73,7 +73,7 @@ public: if (port == nullptr) { return nullptr; } - return std::static_pointer_cast(port->GetServerPort().GetSessionRequestHandler()); + return std::static_pointer_cast(port->GetServerPort().GetHLEHandler()); } void InvokeControlRequest(Kernel::HLERequestContext& context); diff --git a/src/yuzu/configuration/configure_debug.ui b/src/yuzu/configuration/configure_debug.ui index d812858b6..c9e60ee08 100755 --- a/src/yuzu/configuration/configure_debug.ui +++ b/src/yuzu/configuration/configure_debug.ui @@ -23,7 +23,7 @@ - + Global Log Filter @@ -66,7 +66,7 @@ - + true @@ -92,7 +92,7 @@ - + Arguments String @@ -155,7 +155,7 @@ - + true @@ -200,7 +200,7 @@ - + true