1
0
Fork 0
forked from suyu/suyu

vi: rewrite IApplicationRootService, IManagerRootService, ISystemRootService

This commit is contained in:
Liam 2024-02-13 23:53:56 -05:00
parent 2e8c0e9247
commit c448001d47
12 changed files with 145 additions and 90 deletions

View file

@ -969,6 +969,8 @@ add_library(core STATIC
hle/service/vi/manager_display_service.h hle/service/vi/manager_display_service.h
hle/service/vi/manager_root_service.cpp hle/service/vi/manager_root_service.cpp
hle/service/vi/manager_root_service.h hle/service/vi/manager_root_service.h
hle/service/vi/service_creator.cpp
hle/service/vi/service_creator.h
hle/service/vi/system_display_service.cpp hle/service/vi/system_display_service.cpp
hle/service/vi/system_display_service.h hle/service/vi/system_display_service.h
hle/service/vi/system_root_service.cpp hle/service/vi/system_root_service.cpp

View file

@ -1,19 +1,22 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "core/hle/service/cmif_serialization.h"
#include "core/hle/service/vi/application_display_service.h"
#include "core/hle/service/vi/application_root_service.h" #include "core/hle/service/vi/application_root_service.h"
#include "core/hle/service/vi/service_creator.h"
#include "core/hle/service/vi/vi.h" #include "core/hle/service/vi/vi.h"
#include "core/hle/service/vi/vi_types.h" #include "core/hle/service/vi/vi_types.h"
namespace Service::VI { namespace Service::VI {
IApplicationRootService::IApplicationRootService( IApplicationRootService::IApplicationRootService(
Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_, Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger,
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_) Nvnflinger::HosBinderDriverServer& hos_binder_driver_server)
: ServiceFramework{system_, "vi:u"}, nv_flinger{nv_flinger_}, : ServiceFramework{system_, "vi:u"}, m_nvnflinger{nvnflinger}, m_hos_binder_driver_server{
hos_binder_driver_server{hos_binder_driver_server_} { hos_binder_driver_server} {
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{0, &IApplicationRootService::GetDisplayService, "GetDisplayService"}, {0, C<&IApplicationRootService::GetDisplayService>, "GetDisplayService"},
{1, nullptr, "GetDisplayServiceWithProxyNameExchange"}, {1, nullptr, "GetDisplayServiceWithProxyNameExchange"},
}; };
RegisterHandlers(functions); RegisterHandlers(functions);
@ -21,11 +24,11 @@ IApplicationRootService::IApplicationRootService(
IApplicationRootService::~IApplicationRootService() = default; IApplicationRootService::~IApplicationRootService() = default;
void IApplicationRootService::GetDisplayService(HLERequestContext& ctx) { Result IApplicationRootService::GetDisplayService(
Out<SharedPointer<IApplicationDisplayService>> out_application_display_service, Policy policy) {
LOG_DEBUG(Service_VI, "called"); LOG_DEBUG(Service_VI, "called");
R_RETURN(GetApplicationDisplayService(out_application_display_service, system, m_nvnflinger,
detail::GetDisplayServiceImpl(ctx, system, nv_flinger, hos_binder_driver_server, m_hos_binder_driver_server, Permission::User, policy));
Permission::User);
} }
} // namespace Service::VI } // namespace Service::VI

View file

@ -3,6 +3,7 @@
#pragma once #pragma once
#include "core/hle/service/cmif_types.h"
#include "core/hle/service/service.h" #include "core/hle/service/service.h"
namespace Core { namespace Core {
@ -16,17 +17,23 @@ class Nvnflinger;
namespace Service::VI { namespace Service::VI {
class IApplicationDisplayService;
enum class Policy : u32;
class IApplicationRootService final : public ServiceFramework<IApplicationRootService> { class IApplicationRootService final : public ServiceFramework<IApplicationRootService> {
public: public:
explicit IApplicationRootService(Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_, explicit IApplicationRootService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger,
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_); Nvnflinger::HosBinderDriverServer& hos_binder_driver_server);
~IApplicationRootService() override; ~IApplicationRootService() override;
private: private:
void GetDisplayService(HLERequestContext& ctx); Result GetDisplayService(
Out<SharedPointer<IApplicationDisplayService>> out_application_display_service,
Policy policy);
Nvnflinger::Nvnflinger& nv_flinger; private:
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server; Nvnflinger::Nvnflinger& m_nvnflinger;
Nvnflinger::HosBinderDriverServer& m_hos_binder_driver_server;
}; };
} // namespace Service::VI } // namespace Service::VI

View file

@ -1,19 +1,22 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "core/hle/service/cmif_serialization.h"
#include "core/hle/service/vi/application_display_service.h"
#include "core/hle/service/vi/manager_root_service.h" #include "core/hle/service/vi/manager_root_service.h"
#include "core/hle/service/vi/service_creator.h"
#include "core/hle/service/vi/vi.h" #include "core/hle/service/vi/vi.h"
#include "core/hle/service/vi/vi_types.h" #include "core/hle/service/vi/vi_types.h"
namespace Service::VI { namespace Service::VI {
IManagerRootService::IManagerRootService( IManagerRootService::IManagerRootService(
Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_, Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger,
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_) Nvnflinger::HosBinderDriverServer& hos_binder_driver_server)
: ServiceFramework{system_, "vi:m"}, nv_flinger{nv_flinger_}, : ServiceFramework{system_, "vi:m"}, m_nvnflinger{nvnflinger}, m_hos_binder_driver_server{
hos_binder_driver_server{hos_binder_driver_server_} { hos_binder_driver_server} {
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{2, &IManagerRootService::GetDisplayService, "GetDisplayService"}, {2, C<&IManagerRootService::GetDisplayService>, "GetDisplayService"},
{3, nullptr, "GetDisplayServiceWithProxyNameExchange"}, {3, nullptr, "GetDisplayServiceWithProxyNameExchange"},
{100, nullptr, "PrepareFatal"}, {100, nullptr, "PrepareFatal"},
{101, nullptr, "ShowFatal"}, {101, nullptr, "ShowFatal"},
@ -25,11 +28,11 @@ IManagerRootService::IManagerRootService(
IManagerRootService::~IManagerRootService() = default; IManagerRootService::~IManagerRootService() = default;
void IManagerRootService::GetDisplayService(HLERequestContext& ctx) { Result IManagerRootService::GetDisplayService(
Out<SharedPointer<IApplicationDisplayService>> out_application_display_service, Policy policy) {
LOG_DEBUG(Service_VI, "called"); LOG_DEBUG(Service_VI, "called");
R_RETURN(GetApplicationDisplayService(out_application_display_service, system, m_nvnflinger,
detail::GetDisplayServiceImpl(ctx, system, nv_flinger, hos_binder_driver_server, m_hos_binder_driver_server, Permission::Manager, policy));
Permission::Manager);
} }
} // namespace Service::VI } // namespace Service::VI

View file

@ -3,6 +3,7 @@
#pragma once #pragma once
#include "core/hle/service/cmif_types.h"
#include "core/hle/service/service.h" #include "core/hle/service/service.h"
namespace Core { namespace Core {
@ -16,17 +17,22 @@ class Nvnflinger;
namespace Service::VI { namespace Service::VI {
class IApplicationDisplayService;
enum class Policy : u32;
class IManagerRootService final : public ServiceFramework<IManagerRootService> { class IManagerRootService final : public ServiceFramework<IManagerRootService> {
public: public:
explicit IManagerRootService(Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_, explicit IManagerRootService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger,
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_); Nvnflinger::HosBinderDriverServer& hos_binder_driver_server);
~IManagerRootService() override; ~IManagerRootService() override;
private: private:
void GetDisplayService(HLERequestContext& ctx); Result GetDisplayService(
Out<SharedPointer<IApplicationDisplayService>> out_application_display_service,
Policy policy);
Nvnflinger::Nvnflinger& nv_flinger; Nvnflinger::Nvnflinger& m_nvnflinger;
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server; Nvnflinger::HosBinderDriverServer& m_hos_binder_driver_server;
}; };
} // namespace Service::VI } // namespace Service::VI

View file

@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/hle/service/vi/application_display_service.h"
#include "core/hle/service/vi/service_creator.h"
#include "core/hle/service/vi/vi_results.h"
#include "core/hle/service/vi/vi_types.h"
namespace Service::VI {
static bool IsValidServiceAccess(Permission permission, Policy policy) {
if (permission == Permission::User) {
return policy == Policy::User;
}
if (permission == Permission::System || permission == Permission::Manager) {
return policy == Policy::User || policy == Policy::Compositor;
}
return false;
}
Result GetApplicationDisplayService(
std::shared_ptr<IApplicationDisplayService>* out_application_display_service,
Core::System& system, Nvnflinger::Nvnflinger& nvnflinger,
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server, Permission permission,
Policy policy) {
if (!IsValidServiceAccess(permission, policy)) {
LOG_ERROR(Service_VI, "Permission denied for policy {}", policy);
R_THROW(ResultPermissionDenied);
}
*out_application_display_service =
std::make_shared<IApplicationDisplayService>(system, nvnflinger, hos_binder_driver_server);
R_SUCCEED();
}
} // namespace Service::VI

View file

@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include "common/common_types.h"
namespace Core {
class System;
}
namespace Service::Nvnflinger {
class HosBinderDriverServer;
class Nvnflinger;
} // namespace Service::Nvnflinger
union Result;
namespace Service::VI {
class IApplicationDisplayService;
enum class Permission;
enum class Policy : u32;
Result GetApplicationDisplayService(
std::shared_ptr<IApplicationDisplayService>* out_application_display_service,
Core::System& system, Nvnflinger::Nvnflinger& nvnflinger,
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server, Permission permission,
Policy policy);
} // namespace Service::VI

View file

@ -1,18 +1,21 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "core/hle/service/cmif_serialization.h"
#include "core/hle/service/vi/application_display_service.h"
#include "core/hle/service/vi/service_creator.h"
#include "core/hle/service/vi/system_root_service.h" #include "core/hle/service/vi/system_root_service.h"
#include "core/hle/service/vi/vi.h" #include "core/hle/service/vi/vi.h"
#include "core/hle/service/vi/vi_types.h" #include "core/hle/service/vi/vi_types.h"
namespace Service::VI { namespace Service::VI {
ISystemRootService::ISystemRootService(Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_, ISystemRootService::ISystemRootService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger,
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_) Nvnflinger::HosBinderDriverServer& hos_binder_driver_server)
: ServiceFramework{system_, "vi:s"}, nv_flinger{nv_flinger_}, : ServiceFramework{system_, "vi:s"}, m_nvnflinger{nvnflinger}, m_hos_binder_driver_server{
hos_binder_driver_server{hos_binder_driver_server_} { hos_binder_driver_server} {
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{1, &ISystemRootService::GetDisplayService, "GetDisplayService"}, {1, C<&ISystemRootService::GetDisplayService>, "GetDisplayService"},
{3, nullptr, "GetDisplayServiceWithProxyNameExchange"}, {3, nullptr, "GetDisplayServiceWithProxyNameExchange"},
}; };
RegisterHandlers(functions); RegisterHandlers(functions);
@ -20,11 +23,11 @@ ISystemRootService::ISystemRootService(Core::System& system_, Nvnflinger::Nvnfli
ISystemRootService::~ISystemRootService() = default; ISystemRootService::~ISystemRootService() = default;
void ISystemRootService::GetDisplayService(HLERequestContext& ctx) { Result ISystemRootService::GetDisplayService(
Out<SharedPointer<IApplicationDisplayService>> out_application_display_service, Policy policy) {
LOG_DEBUG(Service_VI, "called"); LOG_DEBUG(Service_VI, "called");
R_RETURN(GetApplicationDisplayService(out_application_display_service, system, m_nvnflinger,
detail::GetDisplayServiceImpl(ctx, system, nv_flinger, hos_binder_driver_server, m_hos_binder_driver_server, Permission::System, policy));
Permission::System);
} }
} // namespace Service::VI } // namespace Service::VI

View file

@ -3,6 +3,7 @@
#pragma once #pragma once
#include "core/hle/service/cmif_types.h"
#include "core/hle/service/service.h" #include "core/hle/service/service.h"
namespace Core { namespace Core {
@ -16,17 +17,22 @@ class Nvnflinger;
namespace Service::VI { namespace Service::VI {
class IApplicationDisplayService;
enum class Policy : u32;
class ISystemRootService final : public ServiceFramework<ISystemRootService> { class ISystemRootService final : public ServiceFramework<ISystemRootService> {
public: public:
explicit ISystemRootService(Core::System& system_, Nvnflinger::Nvnflinger& nv_flinger_, explicit ISystemRootService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger,
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server_); Nvnflinger::HosBinderDriverServer& hos_binder_driver_server);
~ISystemRootService() override; ~ISystemRootService() override;
private: private:
void GetDisplayService(HLERequestContext& ctx); Result GetDisplayService(
Out<SharedPointer<IApplicationDisplayService>> out_application_display_service,
Policy policy);
Nvnflinger::Nvnflinger& nv_flinger; Nvnflinger::Nvnflinger& m_nvnflinger;
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server; Nvnflinger::HosBinderDriverServer& m_hos_binder_driver_server;
}; };
} // namespace Service::VI } // namespace Service::VI

View file

@ -1,49 +1,15 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "core/hle/service/ipc_helpers.h"
#include "core/hle/service/server_manager.h" #include "core/hle/service/server_manager.h"
#include "core/hle/service/vi/application_display_service.h" #include "core/hle/service/vi/application_display_service.h"
#include "core/hle/service/vi/application_root_service.h" #include "core/hle/service/vi/application_root_service.h"
#include "core/hle/service/vi/manager_root_service.h" #include "core/hle/service/vi/manager_root_service.h"
#include "core/hle/service/vi/system_root_service.h" #include "core/hle/service/vi/system_root_service.h"
#include "core/hle/service/vi/vi.h" #include "core/hle/service/vi/vi.h"
#include "core/hle/service/vi/vi_results.h"
#include "core/hle/service/vi/vi_types.h"
namespace Service::VI { namespace Service::VI {
static bool IsValidServiceAccess(Permission permission, Policy policy) {
if (permission == Permission::User) {
return policy == Policy::User;
}
if (permission == Permission::System || permission == Permission::Manager) {
return policy == Policy::User || policy == Policy::Compositor;
}
return false;
}
void detail::GetDisplayServiceImpl(HLERequestContext& ctx, Core::System& system,
Nvnflinger::Nvnflinger& nvnflinger,
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server,
Permission permission) {
IPC::RequestParser rp{ctx};
const auto policy = rp.PopEnum<Policy>();
if (!IsValidServiceAccess(permission, policy)) {
LOG_ERROR(Service_VI, "Permission denied for policy {}", policy);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultPermissionDenied);
return;
}
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IApplicationDisplayService>(system, nvnflinger, hos_binder_driver_server);
}
void LoopProcess(Core::System& system, Nvnflinger::Nvnflinger& nvnflinger, void LoopProcess(Core::System& system, Nvnflinger::Nvnflinger& nvnflinger,
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server) { Nvnflinger::HosBinderDriverServer& hos_binder_driver_server) {
auto server_manager = std::make_unique<ServerManager>(system); auto server_manager = std::make_unique<ServerManager>(system);

View file

@ -7,10 +7,6 @@ namespace Core {
class System; class System;
} }
namespace Service {
class HLERequestContext;
}
namespace Service::Nvnflinger { namespace Service::Nvnflinger {
class HosBinderDriverServer; class HosBinderDriverServer;
class Nvnflinger; class Nvnflinger;
@ -18,15 +14,6 @@ class Nvnflinger;
namespace Service::VI { namespace Service::VI {
enum class Permission;
namespace detail {
void GetDisplayServiceImpl(HLERequestContext& ctx, Core::System& system,
Nvnflinger::Nvnflinger& nv_flinger,
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server,
Permission permission);
} // namespace detail
void LoopProcess(Core::System& system, Nvnflinger::Nvnflinger& nvnflinger, void LoopProcess(Core::System& system, Nvnflinger::Nvnflinger& nvnflinger,
Nvnflinger::HosBinderDriverServer& hos_binder_driver_server); Nvnflinger::HosBinderDriverServer& hos_binder_driver_server);

View file

@ -23,7 +23,7 @@ enum class Permission {
/// A policy type that may be requested via GetDisplayService and /// A policy type that may be requested via GetDisplayService and
/// GetDisplayServiceWithProxyNameExchange /// GetDisplayServiceWithProxyNameExchange
enum class Policy { enum class Policy : u32 {
User, User,
Compositor, Compositor,
}; };