From 9fde97cfdd34412bc887acaf438e31a1fec15be5 Mon Sep 17 00:00:00 2001 From: SciresM Date: Tue, 7 Jul 2020 17:07:23 -0700 Subject: [PATCH] sf: Change interface definition methodology (#1074) * sf: Begin experimenting with new interface declaration format * sf: convert fs interfaces to new format * sf: finish conversion of libstrat to new definitions * sf: convert loader to new format * sf: convert spl to new format * sf: update ncm for new format * sf: convert pm to new format * sf: convert ro/sm to new format * sf: update fatal for new format * sf: support building dmnt under new scheme * sf: update ams.mitm for new format * sf: correct invocation def for pointer holder * fs: correct 10.x+ user bindings for Get*SpaceSize --- .../libstratosphere/include/stratosphere.hpp | 1 + .../erpt/sf/erpt_sf_i_attachment.hpp | 37 +-- .../erpt/sf/erpt_sf_i_context.hpp | 58 +--- .../erpt/sf/erpt_sf_i_manager.hpp | 38 +-- .../stratosphere/erpt/sf/erpt_sf_i_report.hpp | 38 +-- .../erpt/sf/erpt_sf_i_session.hpp | 25 +- .../include/stratosphere/fatal.hpp | 5 +- .../fatal/impl/fatal_i_private_service.hpp | 29 ++ .../fatal/impl/fatal_i_service.hpp | 31 ++ .../include/stratosphere/fs/fs_path_tool.hpp | 4 +- .../include/stratosphere/fs/fs_path_utils.hpp | 4 +- .../stratosphere/fs/fs_query_range.hpp | 4 +- .../include/stratosphere/fs/fsa/fs_ifile.hpp | 8 +- .../include/stratosphere/fssrv.hpp | 3 +- .../fssrv_filesystem_interface_adapter.hpp | 108 +------ .../fssrv_storage_interface_adapter.hpp | 33 +- .../fssrv/sf/fssrv_sf_idirectory.hpp | 29 ++ .../stratosphere/fssrv/sf/fssrv_sf_ifile.hpp | 34 ++ .../fssrv/sf/fssrv_sf_ifilesystem.hpp | 47 +++ .../fssrv/sf/fssrv_sf_istorage.hpp | 34 ++ .../fssrv/{ => sf}/fssrv_sf_path.hpp | 0 .../include/stratosphere/hos/hos_types.hpp | 2 - .../include/stratosphere/ldr.hpp | 3 + .../ldr/impl/ldr_debug_monitor_interface.hpp | 32 ++ .../impl/ldr_process_manager_interface.hpp | 36 +++ .../ldr/impl/ldr_shell_interface.hpp | 32 ++ .../lr_i_add_on_content_location_resolver.hpp | 36 +-- .../lr/lr_i_location_resolver.hpp | 122 ++----- .../lr/lr_i_location_resolver_manager.hpp | 22 +- .../lr/lr_i_registered_location_resolver.hpp | 69 +--- .../lr/lr_location_resolver_manager_impl.hpp | 18 +- .../ncm/ncm_content_manager_impl.hpp | 33 +- .../ncm/ncm_i_content_manager.hpp | 72 ++--- .../ncm/ncm_i_content_meta_database.hpp | 105 ++---- .../ncm/ncm_i_content_storage.hpp | 137 ++------ .../include/stratosphere/ns.hpp | 19 ++ .../stratosphere/ns/impl/ns_i_async.hpp | 31 ++ .../pgl/sf/pgl_sf_i_event_observer.hpp | 21 +- .../pgl/sf/pgl_sf_i_shell_interface.hpp | 62 +--- .../pgl/srv/pgl_srv_shell_interface.hpp | 27 +- .../include/stratosphere/pm.hpp | 14 +- .../pm/impl/pm_boot_mode_interface.hpp | 30 ++ .../pm/impl/pm_debug_monitor_interface.hpp | 50 +++ .../pm/impl/pm_information_interface.hpp | 32 ++ .../pm/impl/pm_shell_interface.hpp | 52 +++ .../psc/sf/psc_sf_i_pm_module.hpp | 33 +- .../psc/sf/psc_sf_i_pm_service.hpp | 17 +- .../include/stratosphere/ro.hpp | 4 +- .../ro/impl/ro_debug_monitor_interface.hpp | 29 ++ .../stratosphere/ro/impl/ro_ro_interface.hpp | 34 ++ .../include/stratosphere/sf.hpp | 1 + .../sf/cmif/sf_cmif_service_dispatch.hpp | 12 +- .../sf/hipc/sf_hipc_server_manager.hpp | 38 +-- .../sf/impl/sf_impl_command_serialization.hpp | 41 +-- .../sf/impl/sf_impl_service_object_macros.hpp | 293 +++++++++++++++++ .../stratosphere/sf/sf_service_object.hpp | 48 +-- .../include/stratosphere/sm.hpp | 14 +- .../sm/impl/sm_debug_monitor_interface.hpp | 31 ++ .../sm/impl/sm_manager_interface.hpp | 33 ++ .../sm/impl/sm_user_interface.hpp | 40 +++ .../include/stratosphere/spl.hpp | 15 +- .../spl/impl/spl_crypto_interface.hpp | 39 +++ .../impl/spl_deprecated_general_interface.hpp | 54 ++++ .../impl/spl_device_unique_data_interface.hpp | 32 ++ .../spl/impl/spl_es_interface.hpp | 38 +++ .../spl/impl/spl_fs_interface.hpp | 36 +++ .../spl/impl/spl_general_interface.hpp | 35 ++ .../spl/impl/spl_manu_interface.hpp | 31 ++ .../spl/impl/spl_random_interface.hpp | 29 ++ .../spl/impl/spl_ssl_interface.hpp | 32 ++ .../include/stratosphere/spl/smc/spl_smc.hpp | 43 ++- .../include/stratosphere/spl/spl_types.hpp | 115 ++++--- .../source/ams/ams_exosphere_api.cpp | 10 +- ...odersrv_decoder_control_server_manager.cpp | 2 +- ...odersrv_decoder_control_server_manager.hpp | 1 + .../decodersrv_decoder_control_service.hpp | 20 +- .../erpt/srv/erpt_srv_attachment_impl.hpp | 15 +- .../source/erpt/srv/erpt_srv_context_impl.hpp | 25 +- .../source/erpt/srv/erpt_srv_manager_impl.hpp | 15 +- .../source/erpt/srv/erpt_srv_report_impl.hpp | 15 +- .../source/erpt/srv/erpt_srv_service.cpp | 10 +- .../source/erpt/srv/erpt_srv_session_impl.cpp | 42 +-- .../source/erpt/srv/erpt_srv_session_impl.hpp | 9 +- .../source/fs/fsa/fs_user_filesystem.cpp | 4 +- .../fssrv_filesystem_interface_adapter.cpp | 8 +- ..._add_on_content_location_resolver_impl.hpp | 15 +- .../libstratosphere/source/lr/lr_api.cpp | 4 +- .../lr/lr_content_location_resolver_impl.hpp | 53 +-- .../lr/lr_location_resolver_impl_base.hpp | 2 +- .../lr/lr_location_resolver_manager_impl.cpp | 10 +- ...r_redirect_only_location_resolver_impl.hpp | 53 +-- .../lr_registered_location_resolver_impl.hpp | 31 +- .../lr/lr_remote_location_resolver_impl.hpp | 83 ++--- ...mote_registered_location_resolver_impl.hpp | 33 +- .../libstratosphere/source/ncm/ncm_api.cpp | 2 +- .../source/ncm/ncm_content_manager_impl.cpp | 16 +- .../ncm_content_meta_database_impl_base.hpp | 28 +- .../ncm/ncm_content_storage_impl_base.hpp | 35 +- .../ncm/ncm_remote_content_manager_impl.hpp | 37 +-- .../ncm_remote_content_meta_database_impl.hpp | 50 +-- .../ncm/ncm_remote_content_storage_impl.hpp | 63 ++-- .../source/pgl/pgl_remote_event_observer.hpp | 9 +- .../source/pgl/pgl_shell_api.cpp | 2 +- .../pgl/srv/pgl_srv_shell_event_observer.cpp | 10 +- .../pgl/srv/pgl_srv_shell_event_observer.hpp | 19 +- .../pgl/srv/pgl_srv_shell_interface.cpp | 12 +- .../source/psc/psc_pm_module.os.horizon.cpp | 2 +- .../source/psc/psc_remote_pm_module.hpp | 15 +- .../source/sf/hipc/sf_hipc_mitm_query_api.cpp | 19 +- .../sf_hipc_server_domain_session_manager.cpp | 31 +- .../source/spl/smc/spl_smc.cpp | 73 ++--- .../libstratosphere/source/spl/spl_api.cpp | 2 +- .../include/vapours/results/spl_results.hpp | 5 +- .../source/bpc_mitm/bpc_ams_module.cpp | 2 +- .../source/bpc_mitm/bpc_ams_service.hpp | 25 +- .../source/bpc_mitm/bpc_mitm_service.hpp | 27 +- .../source/bpc_mitm/bpcmitm_module.cpp | 2 +- .../source/fs_mitm/fs_mitm_service.cpp | 68 ++-- .../source/fs_mitm/fs_mitm_service.hpp | 60 ++-- .../ams_mitm/source/fs_mitm/fsmitm_module.cpp | 2 +- .../source/hid_mitm/hid_mitm_service.hpp | 24 +- .../source/hid_mitm/hidmitm_module.cpp | 2 +- .../source/ns_mitm/ns_am_mitm_service.hpp | 30 +- .../source/ns_mitm/ns_web_mitm_service.cpp | 4 +- .../source/ns_mitm/ns_web_mitm_service.hpp | 50 ++- .../ams_mitm/source/ns_mitm/nsmitm_module.cpp | 4 +- .../source/set_mitm/set_mitm_service.hpp | 33 +- .../source/set_mitm/setmitm_module.cpp | 4 +- .../source/set_mitm/setsys_mitm_service.hpp | 32 +- .../sysupdater/sysupdater_async_impl.hpp | 25 +- .../sysupdater/sysupdater_i_async_result.hpp | 44 --- .../source/sysupdater/sysupdater_module.cpp | 2 +- .../source/sysupdater/sysupdater_service.cpp | 8 +- .../source/sysupdater/sysupdater_service.hpp | 48 ++- .../dmnt/source/cheat/dmnt_cheat_service.hpp | 100 ++---- stratosphere/dmnt/source/dmnt_main.cpp | 2 +- stratosphere/dmnt/source/dmnt_service.hpp | 58 +--- stratosphere/fatal/source/fatal_main.cpp | 5 +- stratosphere/fatal/source/fatal_service.cpp | 6 +- stratosphere/fatal/source/fatal_service.hpp | 32 +- .../loader/source/ldr_loader_service.hpp | 110 ++----- stratosphere/loader/source/ldr_main.cpp | 6 +- stratosphere/ncm/source/ncm_main.cpp | 40 +-- stratosphere/pgl/source/pgl_main.cpp | 6 +- .../pm/source/pm_boot_mode_service.cpp | 16 +- .../pm/source/pm_boot_mode_service.hpp | 18 +- .../pm/source/pm_debug_monitor_service.cpp | 22 +- .../pm/source/pm_debug_monitor_service.hpp | 94 +----- stratosphere/pm/source/pm_info_service.cpp | 10 +- stratosphere/pm/source/pm_info_service.hpp | 23 +- stratosphere/pm/source/pm_main.cpp | 12 +- stratosphere/pm/source/pm_shell_service.cpp | 34 +- stratosphere/pm/source/pm_shell_service.hpp | 99 +----- .../ro/source/impl/ro_service_impl.cpp | 8 +- .../ro/source/impl/ro_service_impl.hpp | 8 +- ...nitor.cpp => ro_debug_monitor_service.cpp} | 2 +- ...nitor.hpp => ro_debug_monitor_service.hpp} | 14 +- stratosphere/ro/source/ro_main.cpp | 14 +- stratosphere/ro/source/ro_ro_service.cpp | 67 ++++ stratosphere/ro/source/ro_ro_service.hpp | 56 ++++ stratosphere/ro/source/ro_service.cpp | 67 ---- stratosphere/ro/source/ro_service.hpp | 62 ---- ...rvice.cpp => sm_debug_monitor_service.cpp} | 8 +- .../sm/source/sm_debug_monitor_service.hpp | 31 ++ stratosphere/sm/source/sm_dmnt_service.hpp | 44 --- stratosphere/sm/source/sm_main.cpp | 8 +- stratosphere/sm/source/sm_manager_service.hpp | 33 +- stratosphere/sm/source/sm_user_service.cpp | 8 +- stratosphere/sm/source/sm_user_service.hpp | 63 +--- stratosphere/spl/source/spl_api_impl.cpp | 305 +++++++++--------- stratosphere/spl/source/spl_api_impl.hpp | 44 +-- .../spl/source/spl_crypto_service.cpp | 19 +- .../spl/source/spl_crypto_service.hpp | 41 +-- .../spl/source/spl_deprecated_service.cpp | 72 +++-- .../spl/source/spl_deprecated_service.hpp | 135 ++------ .../source/spl_device_unique_data_service.cpp | 30 ++ ...hpp => spl_device_unique_data_service.hpp} | 10 +- stratosphere/spl/source/spl_es_service.cpp | 32 +- stratosphere/spl/source/spl_es_service.hpp | 53 +-- stratosphere/spl/source/spl_fs_service.cpp | 16 +- stratosphere/spl/source/spl_fs_service.hpp | 41 +-- .../spl/source/spl_general_service.cpp | 8 +- .../spl/source/spl_general_service.hpp | 77 +---- stratosphere/spl/source/spl_main.cpp | 16 +- stratosphere/spl/source/spl_manu_service.cpp | 4 +- stratosphere/spl/source/spl_manu_service.hpp | 33 +- .../spl/source/spl_random_service.hpp | 16 +- stratosphere/spl/source/spl_rsa_service.cpp | 30 -- stratosphere/spl/source/spl_ssl_service.cpp | 8 +- stratosphere/spl/source/spl_ssl_service.hpp | 36 +-- 190 files changed, 3220 insertions(+), 3172 deletions(-) create mode 100644 libraries/libstratosphere/include/stratosphere/fatal/impl/fatal_i_private_service.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/fatal/impl/fatal_i_service.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_idirectory.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_ifile.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_ifilesystem.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_istorage.hpp rename libraries/libstratosphere/include/stratosphere/fssrv/{ => sf}/fssrv_sf_path.hpp (100%) create mode 100644 libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_shell_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/ns.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/ns/impl/ns_i_async.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/pm/impl/pm_boot_mode_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/pm/impl/pm_debug_monitor_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/pm/impl/pm_shell_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/ro/impl/ro_debug_monitor_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/ro/impl/ro_ro_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_service_object_macros.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/sm/impl/sm_debug_monitor_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/sm/impl/sm_manager_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/sm/impl/sm_user_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/spl/impl/spl_crypto_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/spl/impl/spl_deprecated_general_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/spl/impl/spl_device_unique_data_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/spl/impl/spl_es_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/spl/impl/spl_fs_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/spl/impl/spl_general_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/spl/impl/spl_manu_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/spl/impl/spl_random_interface.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/spl/impl/spl_ssl_interface.hpp delete mode 100644 stratosphere/ams_mitm/source/sysupdater/sysupdater_i_async_result.hpp rename stratosphere/ro/source/{ro_debug_monitor.cpp => ro_debug_monitor_service.cpp} (96%) rename stratosphere/ro/source/{ro_debug_monitor.hpp => ro_debug_monitor_service.hpp} (71%) create mode 100644 stratosphere/ro/source/ro_ro_service.cpp create mode 100644 stratosphere/ro/source/ro_ro_service.hpp delete mode 100644 stratosphere/ro/source/ro_service.cpp delete mode 100644 stratosphere/ro/source/ro_service.hpp rename stratosphere/sm/source/{sm_dmnt_service.cpp => sm_debug_monitor_service.cpp} (73%) create mode 100644 stratosphere/sm/source/sm_debug_monitor_service.hpp delete mode 100644 stratosphere/sm/source/sm_dmnt_service.hpp create mode 100644 stratosphere/spl/source/spl_device_unique_data_service.cpp rename stratosphere/spl/source/{spl_rsa_service.hpp => spl_device_unique_data_service.hpp} (60%) delete mode 100644 stratosphere/spl/source/spl_rsa_service.cpp diff --git a/libraries/libstratosphere/include/stratosphere.hpp b/libraries/libstratosphere/include/stratosphere.hpp index 7a51e59eb..9fffefa9f 100644 --- a/libraries/libstratosphere/include/stratosphere.hpp +++ b/libraries/libstratosphere/include/stratosphere.hpp @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include diff --git a/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_attachment.hpp b/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_attachment.hpp index cf403c4b6..0d44e8929 100644 --- a/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_attachment.hpp +++ b/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_attachment.hpp @@ -19,33 +19,14 @@ namespace ams::erpt::sf { - class IAttachment : public ams::sf::IServiceObject { - protected: - enum class CommandId { - Open = 0, - Read = 1, - SetFlags = 2, - GetFlags = 3, - Close = 4, - GetSize = 5, - }; - public: - /* Actual commands. */ - virtual Result Open(const AttachmentId &attachment_id) = 0; - virtual Result Read(ams::sf::Out out_count, const ams::sf::OutBuffer &out_buffer) = 0; - virtual Result SetFlags(AttachmentFlagSet flags) = 0; - virtual Result GetFlags(ams::sf::Out out) = 0; - virtual Result Close() = 0; - virtual Result GetSize(ams::sf::Out out) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(Open), - MAKE_SERVICE_COMMAND_META(Read), - MAKE_SERVICE_COMMAND_META(SetFlags), - MAKE_SERVICE_COMMAND_META(GetFlags), - MAKE_SERVICE_COMMAND_META(Close), - MAKE_SERVICE_COMMAND_META(GetSize), - }; - }; + #define AMS_ERPT_I_ATTACHMENT_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Open, (const AttachmentId &attachment_id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, Read, (ams::sf::Out out_count, const ams::sf::OutBuffer &out_buffer)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, SetFlags, (AttachmentFlagSet flags)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetFlags, (ams::sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, Close, ()) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetSize, (ams::sf::Out out)) + + AMS_SF_DEFINE_INTERFACE(IAttachment, AMS_ERPT_I_ATTACHMENT_INTERFACE_INFO) } \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_context.hpp b/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_context.hpp index 85d18ef44..47cc54018 100644 --- a/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_context.hpp +++ b/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_context.hpp @@ -22,48 +22,20 @@ namespace ams::erpt::sf { - class IContext : public ams::sf::IServiceObject { - protected: - enum class CommandId { - SubmitContext = 0, - CreateReport = 1, - SetInitialLaunchSettingsCompletionTime = 2, - ClearInitialLaunchSettingsCompletionTime = 3, - UpdatePowerOnTime = 4, - UpdateAwakeTime = 5, - SubmitMultipleCategoryContext = 6, - UpdateApplicationLaunchTime = 7, - ClearApplicationLaunchTime = 8, - SubmitAttachment = 9, - CreateReportWithAttachments = 10, - }; - public: - /* Actual commands. */ - virtual Result SubmitContext(const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer) = 0; - virtual Result CreateReport(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer, const ams::sf::InBuffer &meta_buffer) = 0; - virtual Result SetInitialLaunchSettingsCompletionTime(const time::SteadyClockTimePoint &time_point) = 0; - virtual Result ClearInitialLaunchSettingsCompletionTime() = 0; - virtual Result UpdatePowerOnTime() = 0; - virtual Result UpdateAwakeTime() = 0; - virtual Result SubmitMultipleCategoryContext(const MultipleCategoryContextEntry &ctx_entry, const ams::sf::InBuffer &str_buffer) = 0; - virtual Result UpdateApplicationLaunchTime() = 0; - virtual Result ClearApplicationLaunchTime() = 0; - virtual Result SubmitAttachment(ams::sf::Out out, const ams::sf::InBuffer &attachment_name, const ams::sf::InBuffer &attachment_data) = 0; - virtual Result CreateReportWithAttachments(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer, const ams::sf::InBuffer &attachment_ids_buffer) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(SubmitContext), - MAKE_SERVICE_COMMAND_META(CreateReport), - MAKE_SERVICE_COMMAND_META(SetInitialLaunchSettingsCompletionTime, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(ClearInitialLaunchSettingsCompletionTime, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(UpdatePowerOnTime, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(UpdateAwakeTime, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(SubmitMultipleCategoryContext, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(UpdateApplicationLaunchTime, hos::Version_6_0_0), - MAKE_SERVICE_COMMAND_META(ClearApplicationLaunchTime, hos::Version_6_0_0), - MAKE_SERVICE_COMMAND_META(SubmitAttachment, hos::Version_8_0_0), - MAKE_SERVICE_COMMAND_META(CreateReportWithAttachments, hos::Version_8_0_0), - }; - }; + #define AMS_ERPT_I_CONTEXT_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, SubmitContext, (const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, CreateReport, (ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer, const ams::sf::InBuffer &meta_buffer)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, SetInitialLaunchSettingsCompletionTime, (const time::SteadyClockTimePoint &time_point), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, ClearInitialLaunchSettingsCompletionTime, (), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, UpdatePowerOnTime, (), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, UpdateAwakeTime, (), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, SubmitMultipleCategoryContext, (const MultipleCategoryContextEntry &ctx_entry, const ams::sf::InBuffer &str_buffer), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, UpdateApplicationLaunchTime, (), hos::Version_6_0_0) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, ClearApplicationLaunchTime, (), hos::Version_6_0_0) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, SubmitAttachment, (ams::sf::Out out, const ams::sf::InBuffer &attachment_name, const ams::sf::InBuffer &attachment_data), hos::Version_8_0_0) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, CreateReportWithAttachments, (ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer, const ams::sf::InBuffer &attachment_ids_buffer), hos::Version_8_0_0) + + + AMS_SF_DEFINE_INTERFACE(IContext, AMS_ERPT_I_CONTEXT_INTERFACE_INFO) } \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_manager.hpp b/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_manager.hpp index 43329a6f5..01fe43534 100644 --- a/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_manager.hpp @@ -19,33 +19,15 @@ namespace ams::erpt::sf { - class IManager : public ams::sf::IServiceObject { - protected: - enum class CommandId { - GetReportList = 0, - GetEvent = 1, - CleanupReports = 2, - DeleteReport = 3, - GetStorageUsageStatistics = 4, - GetAttachmentList = 5, - }; - public: - /* Actual commands. */ - virtual Result GetReportList(const ams::sf::OutBuffer &out_list, ReportType type_filter) = 0; - virtual Result GetEvent(ams::sf::OutCopyHandle out) = 0; - virtual Result CleanupReports() = 0; - virtual Result DeleteReport(const ReportId &report_id) = 0; - virtual Result GetStorageUsageStatistics(ams::sf::Out out) = 0; - virtual Result GetAttachmentList(const ams::sf::OutBuffer &out_buf, const ReportId &report_id) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetReportList), - MAKE_SERVICE_COMMAND_META(GetEvent), - MAKE_SERVICE_COMMAND_META(CleanupReports, hos::Version_4_0_0), - MAKE_SERVICE_COMMAND_META(DeleteReport, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(GetStorageUsageStatistics, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(GetAttachmentList, hos::Version_8_0_0), - }; - }; + #define AMS_ERPT_I_MANAGER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetReportList, (const ams::sf::OutBuffer &out_list, ReportType type_filter)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetEvent, (ams::sf::OutCopyHandle out)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, CleanupReports, (), hos::Version_4_0_0) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, DeleteReport, (const ReportId &report_id), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetStorageUsageStatistics, (ams::sf::Out out), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetAttachmentList, (const ams::sf::OutBuffer &out_buf, const ReportId &report_id), hos::Version_8_0_0) + + + AMS_SF_DEFINE_INTERFACE(IManager, AMS_ERPT_I_MANAGER_INTERFACE_INFO) } \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_report.hpp b/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_report.hpp index cc053ad84..2d8171c97 100644 --- a/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_report.hpp +++ b/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_report.hpp @@ -19,33 +19,15 @@ namespace ams::erpt::sf { - class IReport : public ams::sf::IServiceObject { - protected: - enum class CommandId { - Open = 0, - Read = 1, - SetFlags = 2, - GetFlags = 3, - Close = 4, - GetSize = 5, - }; - public: - /* Actual commands. */ - virtual Result Open(const ReportId &report_id) = 0; - virtual Result Read(ams::sf::Out out_count, const ams::sf::OutBuffer &out_buffer) = 0; - virtual Result SetFlags(ReportFlagSet flags) = 0; - virtual Result GetFlags(ams::sf::Out out) = 0; - virtual Result Close() = 0; - virtual Result GetSize(ams::sf::Out out) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(Open), - MAKE_SERVICE_COMMAND_META(Read), - MAKE_SERVICE_COMMAND_META(SetFlags), - MAKE_SERVICE_COMMAND_META(GetFlags), - MAKE_SERVICE_COMMAND_META(Close), - MAKE_SERVICE_COMMAND_META(GetSize), - }; - }; + #define AMS_ERPT_I_REPORT_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Open, (const ReportId &report_id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, Read, (ams::sf::Out out_count, const ams::sf::OutBuffer &out_buffer)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, SetFlags, (ReportFlagSet flags)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetFlags, (ams::sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, Close, ()) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetSize, (ams::sf::Out out)) + + + AMS_SF_DEFINE_INTERFACE(IReport, AMS_ERPT_I_REPORT_INTERFACE_INFO) } \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_session.hpp b/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_session.hpp index 739d0bde2..c61e22229 100644 --- a/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_session.hpp +++ b/libraries/libstratosphere/include/stratosphere/erpt/sf/erpt_sf_i_session.hpp @@ -22,24 +22,11 @@ namespace ams::erpt::sf { - class ISession : public ams::sf::IServiceObject { - protected: - enum class CommandId { - OpenReport = 0, - OpenManager = 1, - OpenAttachment = 2, - }; - public: - /* Actual commands. */ - virtual Result OpenReport(ams::sf::Out> out) = 0; - virtual Result OpenManager(ams::sf::Out> out) = 0; - virtual Result OpenAttachment(ams::sf::Out> out) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(OpenReport), - MAKE_SERVICE_COMMAND_META(OpenManager), - MAKE_SERVICE_COMMAND_META(OpenAttachment, hos::Version_8_0_0), - }; - }; + #define AMS_ERPT_I_SESSION_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, OpenReport, (ams::sf::Out> out)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, OpenManager, (ams::sf::Out> out)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, OpenAttachment, (ams::sf::Out> out), hos::Version_8_0_0) + + AMS_SF_DEFINE_INTERFACE(ISession, AMS_ERPT_I_SESSION_INTERFACE_INFO) } \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/fatal.hpp b/libraries/libstratosphere/include/stratosphere/fatal.hpp index 52ad0b054..00025c562 100644 --- a/libraries/libstratosphere/include/stratosphere/fatal.hpp +++ b/libraries/libstratosphere/include/stratosphere/fatal.hpp @@ -16,4 +16,7 @@ #pragma once -#include "fatal/fatal_types.hpp" +#include + +#include +#include diff --git a/libraries/libstratosphere/include/stratosphere/fatal/impl/fatal_i_private_service.hpp b/libraries/libstratosphere/include/stratosphere/fatal/impl/fatal_i_private_service.hpp new file mode 100644 index 000000000..59e2b70bc --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/fatal/impl/fatal_i_private_service.hpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::fatal::impl { + + #define AMS_FATAL_I_PRIVATE_SERVICE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetFatalEvent, (sf::OutCopyHandle out_h)) + + AMS_SF_DEFINE_INTERFACE(IPrivateService, AMS_FATAL_I_PRIVATE_SERVICE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/fatal/impl/fatal_i_service.hpp b/libraries/libstratosphere/include/stratosphere/fatal/impl/fatal_i_service.hpp new file mode 100644 index 000000000..36922e786 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/fatal/impl/fatal_i_service.hpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::fatal::impl { + + #define AMS_FATAL_I_SERVICE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, ThrowFatal, (Result error, const sf::ClientProcessId &client_pid)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, ThrowFatalWithPolicy, (Result error, const sf::ClientProcessId &client_pid, FatalPolicy policy)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, ThrowFatalWithCpuContext, (Result error, const sf::ClientProcessId &client_pid, FatalPolicy policy, const CpuContext &cpu_ctx)) + + AMS_SF_DEFINE_INTERFACE(IService, AMS_FATAL_I_SERVICE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_path_tool.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_path_tool.hpp index 37f2c5b5d..9d9e145b8 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_path_tool.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_path_tool.hpp @@ -14,8 +14,8 @@ * along with this program. If not, see . */ #pragma once -#include "fs_common.hpp" -#include "../fssrv/fssrv_sf_path.hpp" +#include +#include namespace ams::fs { diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_path_utils.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_path_utils.hpp index 63cb917d3..59174ce20 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_path_utils.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_path_utils.hpp @@ -14,8 +14,8 @@ * along with this program. If not, see . */ #pragma once -#include "fs_common.hpp" -#include "../fssrv/fssrv_sf_path.hpp" +#include +#include namespace ams::fs { diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_query_range.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_query_range.hpp index 2456f48db..35e684c9c 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_query_range.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_query_range.hpp @@ -14,8 +14,8 @@ * along with this program. If not, see . */ #pragma once -#include "fs_common.hpp" -#include "fs_file.hpp" +#include +#include namespace ams::fs { diff --git a/libraries/libstratosphere/include/stratosphere/fs/fsa/fs_ifile.hpp b/libraries/libstratosphere/include/stratosphere/fs/fsa/fs_ifile.hpp index 422240110..2d262639b 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fsa/fs_ifile.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fsa/fs_ifile.hpp @@ -14,10 +14,10 @@ * along with this program. If not, see . */ #pragma once -#include "../fs_common.hpp" -#include "../fs_file.hpp" -#include "../fs_filesystem.hpp" -#include "../fs_operate_range.hpp" +#include +#include +#include +#include namespace ams::fs::fsa { diff --git a/libraries/libstratosphere/include/stratosphere/fssrv.hpp b/libraries/libstratosphere/include/stratosphere/fssrv.hpp index 91d839512..a2fb95b3d 100644 --- a/libraries/libstratosphere/include/stratosphere/fssrv.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssrv.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include +#include +#include #include #include #include diff --git a/libraries/libstratosphere/include/stratosphere/fssrv/interface_adapters/fssrv_filesystem_interface_adapter.hpp b/libraries/libstratosphere/include/stratosphere/fssrv/interface_adapters/fssrv_filesystem_interface_adapter.hpp index 4355176d1..a62bda661 100644 --- a/libraries/libstratosphere/include/stratosphere/fssrv/interface_adapters/fssrv_filesystem_interface_adapter.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssrv/interface_adapters/fssrv_filesystem_interface_adapter.hpp @@ -14,13 +14,16 @@ * along with this program. If not, see . */ #pragma once -#include "../../fs/fs_common.hpp" -#include "../../fs/fs_file.hpp" -#include "../../fs/fs_directory.hpp" -#include "../../fs/fs_filesystem.hpp" -#include "../../fs/fs_query_range.hpp" -#include "../../fssrv/fssrv_sf_path.hpp" -#include "../../fssystem/fssystem_utility.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace ams::fs::fsa { @@ -34,17 +37,8 @@ namespace ams::fssrv::impl { class FileSystemInterfaceAdapter; - class FileInterfaceAdapter final : public ams::sf::IServiceObject { + class FileInterfaceAdapter final { NON_COPYABLE(FileInterfaceAdapter); - public: - enum class CommandId { - Read = 0, - Write = 1, - Flush = 2, - SetSize = 3, - GetSize = 4, - OperateRange = 5, - }; private: std::shared_ptr parent_filesystem; std::unique_ptr base_file; @@ -62,27 +56,11 @@ namespace ams::fssrv::impl { Result SetSize(s64 size); Result GetSize(ams::sf::Out out); Result OperateRange(ams::sf::Out out, s32 op_id, s64 offset, s64 size); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - /* 1.0.0- */ - MAKE_SERVICE_COMMAND_META(Read), - MAKE_SERVICE_COMMAND_META(Write), - MAKE_SERVICE_COMMAND_META(Flush), - MAKE_SERVICE_COMMAND_META(SetSize), - MAKE_SERVICE_COMMAND_META(GetSize), - - /* 4.0.0- */ - MAKE_SERVICE_COMMAND_META(OperateRange, hos::Version_4_0_0), - }; }; + static_assert(fssrv::sf::IsIFile); - class DirectoryInterfaceAdapter final : public ams::sf::IServiceObject { + class DirectoryInterfaceAdapter final { NON_COPYABLE(DirectoryInterfaceAdapter); - public: - enum class CommandId { - Read = 0, - GetEntryCount = 1, - }; private: std::shared_ptr parent_filesystem; std::unique_ptr base_dir; @@ -94,39 +72,11 @@ namespace ams::fssrv::impl { /* Command API */ Result Read(ams::sf::Out out, const ams::sf::OutBuffer &out_entries); Result GetEntryCount(ams::sf::Out out); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(Read), - MAKE_SERVICE_COMMAND_META(GetEntryCount), - }; }; + static_assert(fssrv::sf::IsIDirectory); - class FileSystemInterfaceAdapter final : public std::enable_shared_from_this, public ams::sf::IServiceObject { + class FileSystemInterfaceAdapter final : public std::enable_shared_from_this { NON_COPYABLE(FileSystemInterfaceAdapter); - public: - enum class CommandId { - /* 1.0.0+ */ - CreateFile = 0, - DeleteFile = 1, - CreateDirectory = 2, - DeleteDirectory = 3, - DeleteDirectoryRecursively = 4, - RenameFile = 5, - RenameDirectory = 6, - GetEntryType = 7, - OpenFile = 8, - OpenDirectory = 9, - Commit = 10, - GetFreeSpaceSize = 11, - GetTotalSpaceSize = 12, - - /* 3.0.0+ */ - CleanDirectoryRecursively = 13, - GetFileTimeStampRaw = 14, - - /* 4.0.0+ */ - QueryEntry = 15, - }; private: std::shared_ptr base_fs; std::unique_lock mount_count_semaphore; @@ -153,8 +103,8 @@ namespace ams::fssrv::impl { Result RenameFile(const fssrv::sf::Path &old_path, const fssrv::sf::Path &new_path); Result RenameDirectory(const fssrv::sf::Path &old_path, const fssrv::sf::Path &new_path); Result GetEntryType(ams::sf::Out out, const fssrv::sf::Path &path); - Result OpenFile(ams::sf::Out> out, const fssrv::sf::Path &path, u32 mode); - Result OpenDirectory(ams::sf::Out> out, const fssrv::sf::Path &path, u32 mode); + Result OpenFile(ams::sf::Out> out, const fssrv::sf::Path &path, u32 mode); + Result OpenDirectory(ams::sf::Out> out, const fssrv::sf::Path &path, u32 mode); Result Commit(); Result GetFreeSpaceSize(ams::sf::Out out, const fssrv::sf::Path &path); Result GetTotalSpaceSize(ams::sf::Out out, const fssrv::sf::Path &path); @@ -163,30 +113,6 @@ namespace ams::fssrv::impl { Result GetFileTimeStampRaw(ams::sf::Out out, const fssrv::sf::Path &path); Result QueryEntry(const ams::sf::OutBuffer &out_buf, const ams::sf::InBuffer &in_buf, s32 query_id, const fssrv::sf::Path &path); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - /* 1.0.0- */ - MAKE_SERVICE_COMMAND_META(CreateFile), - MAKE_SERVICE_COMMAND_META(DeleteFile), - MAKE_SERVICE_COMMAND_META(CreateDirectory), - MAKE_SERVICE_COMMAND_META(DeleteDirectory), - MAKE_SERVICE_COMMAND_META(DeleteDirectoryRecursively), - MAKE_SERVICE_COMMAND_META(RenameFile), - MAKE_SERVICE_COMMAND_META(RenameDirectory), - MAKE_SERVICE_COMMAND_META(GetEntryType), - MAKE_SERVICE_COMMAND_META(OpenFile), - MAKE_SERVICE_COMMAND_META(OpenDirectory), - MAKE_SERVICE_COMMAND_META(Commit), - MAKE_SERVICE_COMMAND_META(GetFreeSpaceSize), - MAKE_SERVICE_COMMAND_META(GetTotalSpaceSize), - - /* 3.0.0- */ - MAKE_SERVICE_COMMAND_META(CleanDirectoryRecursively, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GetFileTimeStampRaw, hos::Version_3_0_0), - - /* 4.0.0- */ - MAKE_SERVICE_COMMAND_META(QueryEntry, hos::Version_4_0_0), - }; }; } diff --git a/libraries/libstratosphere/include/stratosphere/fssrv/interface_adapters/fssrv_storage_interface_adapter.hpp b/libraries/libstratosphere/include/stratosphere/fssrv/interface_adapters/fssrv_storage_interface_adapter.hpp index 6170e3f08..c1a74b42f 100644 --- a/libraries/libstratosphere/include/stratosphere/fssrv/interface_adapters/fssrv_storage_interface_adapter.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssrv/interface_adapters/fssrv_storage_interface_adapter.hpp @@ -14,9 +14,10 @@ * along with this program. If not, see . */ #pragma once -#include "../../fs/fs_common.hpp" -#include "../../fs/fs_query_range.hpp" -#include "../../fssystem/fssystem_utility.hpp" +#include +#include +#include +#include namespace ams::fs { @@ -26,17 +27,8 @@ namespace ams::fs { namespace ams::fssrv::impl { - class StorageInterfaceAdapter final : public ams::sf::IServiceObject { + class StorageInterfaceAdapter final { NON_COPYABLE(StorageInterfaceAdapter); - public: - enum class CommandId { - Read = 0, - Write = 1, - Flush = 2, - SetSize = 3, - GetSize = 4, - OperateRange = 5, - }; private: /* TODO: Nintendo uses fssystem::AsynchronousAccessStorage here. */ std::shared_ptr base_storage; @@ -53,7 +45,7 @@ namespace ams::fssrv::impl { ~StorageInterfaceAdapter(); private: std::optional> AcquireCacheInvalidationReadLock(); - private: + public: /* Command API. */ Result Read(s64 offset, const ams::sf::OutNonSecureBuffer &buffer, s64 size); Result Write(s64 offset, const ams::sf::InNonSecureBuffer &buffer, s64 size); @@ -61,18 +53,7 @@ namespace ams::fssrv::impl { Result SetSize(s64 size); Result GetSize(ams::sf::Out out); Result OperateRange(ams::sf::Out out, s32 op_id, s64 offset, s64 size); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - /* 1.0.0- */ - MAKE_SERVICE_COMMAND_META(Read), - MAKE_SERVICE_COMMAND_META(Write), - MAKE_SERVICE_COMMAND_META(Flush), - MAKE_SERVICE_COMMAND_META(SetSize), - MAKE_SERVICE_COMMAND_META(GetSize), - - /* 4.0.0- */ - MAKE_SERVICE_COMMAND_META(OperateRange, hos::Version_4_0_0), - }; }; + static_assert(fssrv::sf::IsIStorage); } diff --git a/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_idirectory.hpp b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_idirectory.hpp new file mode 100644 index 000000000..422a06dde --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_idirectory.hpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include +#include +#include + +namespace ams::fssrv::sf { + + #define AMS_FSSRV_I_DIRECTORY_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Read, (ams::sf::Out out, const ams::sf::OutBuffer &out_entries)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetEntryCount, (ams::sf::Out out)) + + AMS_SF_DEFINE_INTERFACE(IDirectory, AMS_FSSRV_I_DIRECTORY_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_ifile.hpp b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_ifile.hpp new file mode 100644 index 000000000..03d30b29a --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_ifile.hpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include +#include +#include +#include + +namespace ams::fssrv::sf { + + #define AMS_FSSRV_I_FILE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Read, (ams::sf::Out out, s64 offset, const ams::sf::OutNonSecureBuffer &buffer, s64 size, ams::fs::ReadOption option)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, Write, (s64 offset, const ams::sf::InNonSecureBuffer &buffer, s64 size, ams::fs::WriteOption option)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, Flush, ()) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, SetSize, (s64 size)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetSize, (ams::sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, OperateRange, (ams::sf::Out out, s32 op_id, s64 offset, s64 size), hos::Version_4_0_0) \ + + AMS_SF_DEFINE_INTERFACE(IFile, AMS_FSSRV_I_FILE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_ifilesystem.hpp b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_ifilesystem.hpp new file mode 100644 index 000000000..90fa215ee --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_ifilesystem.hpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include +#include +#include +#include +#include +#include +#include + +namespace ams::fssrv::sf { + + #define AMS_FSSRV_I_FILESYSTEM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, CreateFile, (const ams::fssrv::sf::Path &path, s64 size, s32 option)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, DeleteFile, (const ams::fssrv::sf::Path &path)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, CreateDirectory, (const ams::fssrv::sf::Path &path)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, DeleteDirectory, (const ams::fssrv::sf::Path &path)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, DeleteDirectoryRecursively, (const ams::fssrv::sf::Path &path)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, RenameFile, (const ams::fssrv::sf::Path &old_path, const ams::fssrv::sf::Path &new_path)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, RenameDirectory, (const ams::fssrv::sf::Path &old_path, const ams::fssrv::sf::Path &new_path)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, GetEntryType, (ams::sf::Out out, const ams::fssrv::sf::Path &path)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, OpenFile, (ams::sf::Out> out, const ams::fssrv::sf::Path &path, u32 mode)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, OpenDirectory, (ams::sf::Out> out, const ams::fssrv::sf::Path &path, u32 mode)) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, Commit, ()) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, GetFreeSpaceSize, (ams::sf::Out out, const ams::fssrv::sf::Path &path)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, GetTotalSpaceSize, (ams::sf::Out out, const ams::fssrv::sf::Path &path)) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, CleanDirectoryRecursively, (const ams::fssrv::sf::Path &path), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 14, Result, GetFileTimeStampRaw, (ams::sf::Out out, const ams::fssrv::sf::Path &path), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, QueryEntry, (const ams::sf::OutBuffer &out_buf, const ams::sf::InBuffer &in_buf, s32 query_id, const ams::fssrv::sf::Path &path), hos::Version_4_0_0) + + AMS_SF_DEFINE_INTERFACE(IFileSystem, AMS_FSSRV_I_FILESYSTEM_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_istorage.hpp b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_istorage.hpp new file mode 100644 index 000000000..5f8cb761f --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_istorage.hpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include +#include +#include +#include + +namespace ams::fssrv::sf { + + #define AMS_FSSRV_I_STORAGE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Read, (s64 offset, const ams::sf::OutNonSecureBuffer &buffer, s64 size)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, Write, (s64 offset, const ams::sf::InNonSecureBuffer &buffer, s64 size)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, Flush, ()) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, SetSize, (s64 size)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetSize, (ams::sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, OperateRange, (ams::sf::Out out, s32 op_id, s64 offset, s64 size), hos::Version_4_0_0) + + AMS_SF_DEFINE_INTERFACE(IStorage, AMS_FSSRV_I_STORAGE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/fssrv/fssrv_sf_path.hpp b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_path.hpp similarity index 100% rename from libraries/libstratosphere/include/stratosphere/fssrv/fssrv_sf_path.hpp rename to libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_path.hpp diff --git a/libraries/libstratosphere/include/stratosphere/hos/hos_types.hpp b/libraries/libstratosphere/include/stratosphere/hos/hos_types.hpp index b93c6e738..8a31591ae 100644 --- a/libraries/libstratosphere/include/stratosphere/hos/hos_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/hos/hos_types.hpp @@ -60,6 +60,4 @@ namespace ams::hos { Version_Max = ::ams::TargetFirmware_Max, }; - - } diff --git a/libraries/libstratosphere/include/stratosphere/ldr.hpp b/libraries/libstratosphere/include/stratosphere/ldr.hpp index c278de699..20f40cbdd 100644 --- a/libraries/libstratosphere/include/stratosphere/ldr.hpp +++ b/libraries/libstratosphere/include/stratosphere/ldr.hpp @@ -19,3 +19,6 @@ #include #include #include +#include +#include +#include \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp new file mode 100644 index 000000000..328ae400c --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::ldr::impl { + + #define AMS_LDR_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArguments, (ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, FlushArguments, ()) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GetProcessModuleInfo, (sf::Out count, const sf::OutPointerArray &out, os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedProgram, (sf::Out out, ncm::ProgramId program_id)) + + AMS_SF_DEFINE_INTERFACE(IDebugMonitorInterface, AMS_LDR_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp new file mode 100644 index 000000000..946ef636c --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::ldr::impl { + + #define AMS_LDR_I_PROCESS_MANAGER_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, CreateProcess, (sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle reslimit_h)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetProgramInfo, (sf::Out out_program_info, const ncm::ProgramLocation &loc)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, PinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, UnpinProgram, (PinId id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, SetEnabledProgramVerification, (bool enabled), hos::Version_10_0_0) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedProgram, (sf::Out out, ncm::ProgramId program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereGetProgramInfo, (sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc)) \ + AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmospherePinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status)) + + AMS_SF_DEFINE_INTERFACE(IProcessManagerInterface, AMS_LDR_I_PROCESS_MANAGER_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_shell_interface.hpp b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_shell_interface.hpp new file mode 100644 index 000000000..5e3e31188 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_shell_interface.hpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::ldr::impl { + + #define AMS_LDR_I_SHELL_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArguments, (ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, FlushArguments, ()) \ + AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereRegisterExternalCode, (sf::OutMoveHandle out, ncm::ProgramId program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65001, void, AtmosphereUnregisterExternalCode, (ncm::ProgramId program_id)) + + AMS_SF_DEFINE_INTERFACE(IShellInterface, AMS_LDR_I_SHELL_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/lr/lr_i_add_on_content_location_resolver.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_i_add_on_content_location_resolver.hpp index 70a8a58b8..64495307a 100644 --- a/libraries/libstratosphere/include/stratosphere/lr/lr_i_add_on_content_location_resolver.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_i_add_on_content_location_resolver.hpp @@ -19,34 +19,14 @@ namespace ams::lr { - class IAddOnContentLocationResolver : public sf::IServiceObject { - protected: - enum class CommandId { - ResolveAddOnContentPath = 0, - RegisterAddOnContentStorageDeprecated = 1, - RegisterAddOnContentStorage = 1, - UnregisterAllAddOnContentPath = 2, - RefreshApplicationAddOnContent = 3, - UnregisterApplicationAddOnContent = 4, - }; - public: - /* Actual commands. */ - virtual Result ResolveAddOnContentPath(sf::Out out, ncm::DataId id) = 0; - virtual Result RegisterAddOnContentStorageDeprecated(ncm::DataId id, ncm::StorageId storage_id) = 0; - virtual Result RegisterAddOnContentStorage(ncm::DataId id, ncm::ApplicationId application_id, ncm::StorageId storage_id) = 0; - virtual Result UnregisterAllAddOnContentPath() = 0; - virtual Result RefreshApplicationAddOnContent(const sf::InArray &ids) = 0; - virtual Result UnregisterApplicationAddOnContent(ncm::ApplicationId id) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(ResolveAddOnContentPath, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(RegisterAddOnContentStorageDeprecated, hos::Version_2_0_0, hos::Version_8_1_0), - MAKE_SERVICE_COMMAND_META(RegisterAddOnContentStorage, hos::Version_9_0_0), - MAKE_SERVICE_COMMAND_META(UnregisterAllAddOnContentPath, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(RefreshApplicationAddOnContent, hos::Version_9_0_0), - MAKE_SERVICE_COMMAND_META(UnregisterApplicationAddOnContent, hos::Version_9_0_0), - }; - }; + #define AMS_LR_I_ADD_ON_CONTENT_LOCATION_RESOLVER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, ResolveAddOnContentPath, (sf::Out out, ncm::DataId id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, RegisterAddOnContentStorageDeprecated, (ncm::DataId id, ncm::StorageId storage_id), hos::Version_2_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, RegisterAddOnContentStorage, (ncm::DataId id, ncm::ApplicationId application_id, ncm::StorageId storage_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, UnregisterAllAddOnContentPath, (), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, RefreshApplicationAddOnContent, (const sf::InArray &ids), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, UnregisterApplicationAddOnContent, (ncm::ApplicationId id), hos::Version_9_0_0) + AMS_SF_DEFINE_INTERFACE(IAddOnContentLocationResolver, AMS_LR_I_ADD_ON_CONTENT_LOCATION_RESOLVER_INTERFACE_INFO) } diff --git a/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver.hpp index d9d8d9daf..29dec9f59 100644 --- a/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver.hpp @@ -19,97 +19,35 @@ namespace ams::lr { - class ILocationResolver : public sf::IServiceObject { - NON_COPYABLE(ILocationResolver); - NON_MOVEABLE(ILocationResolver); - protected: - enum class CommandId { - ResolveProgramPath = 0, - RedirectProgramPath = 1, - ResolveApplicationControlPath = 2, - ResolveApplicationHtmlDocumentPath = 3, - ResolveDataPath = 4, - RedirectApplicationControlPathDeprecated = 5, - RedirectApplicationControlPath = 5, - RedirectApplicationHtmlDocumentPathDeprecated = 6, - RedirectApplicationHtmlDocumentPath = 6, - ResolveApplicationLegalInformationPath = 7, - RedirectApplicationLegalInformationPathDeprecated = 8, - RedirectApplicationLegalInformationPath = 8, - Refresh = 9, - RedirectApplicationProgramPathDeprecated = 10, - RedirectApplicationProgramPath = 10, - ClearApplicationRedirectionDeprecated = 11, - ClearApplicationRedirection = 11, - EraseProgramRedirection = 12, - EraseApplicationControlRedirection = 13, - EraseApplicationHtmlDocumentRedirection = 14, - EraseApplicationLegalInformationRedirection = 15, - ResolveProgramPathForDebug = 16, - RedirectProgramPathForDebug = 17, - RedirectApplicationProgramPathForDebugDeprecated = 18, - RedirectApplicationProgramPathForDebug = 18, - EraseProgramRedirectionForDebug = 19, - }; - public: - ILocationResolver() { /* ... */ } - public: - /* Actual commands. */ - virtual Result ResolveProgramPath(sf::Out out, ncm::ProgramId id) = 0; - virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id) = 0; - virtual Result ResolveApplicationControlPath(sf::Out out, ncm::ProgramId id) = 0; - virtual Result ResolveApplicationHtmlDocumentPath(sf::Out out, ncm::ProgramId id) = 0; - virtual Result ResolveDataPath(sf::Out out, ncm::DataId id) = 0; - virtual Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) = 0; - virtual Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0; - virtual Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) = 0; - virtual Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0; - virtual Result ResolveApplicationLegalInformationPath(sf::Out out, ncm::ProgramId id) = 0; - virtual Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) = 0; - virtual Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0; - virtual Result Refresh() = 0; - virtual Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) = 0; - virtual Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0; - virtual Result ClearApplicationRedirectionDeprecated() = 0; - virtual Result ClearApplicationRedirection(const sf::InArray &excluding_ids) = 0; - virtual Result EraseProgramRedirection(ncm::ProgramId id) = 0; - virtual Result EraseApplicationControlRedirection(ncm::ProgramId id) = 0; - virtual Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) = 0; - virtual Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id) = 0; - virtual Result ResolveProgramPathForDebug(sf::Out out, ncm::ProgramId id) = 0; - virtual Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) = 0; - virtual Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) = 0; - virtual Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0; - virtual Result EraseProgramRedirectionForDebug(ncm::ProgramId id) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(ResolveProgramPath), - MAKE_SERVICE_COMMAND_META(RedirectProgramPath), - MAKE_SERVICE_COMMAND_META(ResolveApplicationControlPath), - MAKE_SERVICE_COMMAND_META(ResolveApplicationHtmlDocumentPath), - MAKE_SERVICE_COMMAND_META(ResolveDataPath), - MAKE_SERVICE_COMMAND_META(RedirectApplicationControlPathDeprecated, hos::Version_1_0_0, hos::Version_8_1_0), - MAKE_SERVICE_COMMAND_META(RedirectApplicationControlPath, hos::Version_9_0_0), - MAKE_SERVICE_COMMAND_META(RedirectApplicationHtmlDocumentPathDeprecated, hos::Version_1_0_0, hos::Version_8_1_0), - MAKE_SERVICE_COMMAND_META(RedirectApplicationHtmlDocumentPath, hos::Version_9_0_0), - MAKE_SERVICE_COMMAND_META(ResolveApplicationLegalInformationPath), - MAKE_SERVICE_COMMAND_META(RedirectApplicationLegalInformationPathDeprecated, hos::Version_1_0_0, hos::Version_8_1_0), - MAKE_SERVICE_COMMAND_META(RedirectApplicationLegalInformationPath, hos::Version_9_0_0), - MAKE_SERVICE_COMMAND_META(Refresh), - MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathDeprecated, hos::Version_5_0_0, hos::Version_8_1_0), - MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPath, hos::Version_9_0_0), - MAKE_SERVICE_COMMAND_META(ClearApplicationRedirectionDeprecated, hos::Version_5_0_0, hos::Version_8_1_0), - MAKE_SERVICE_COMMAND_META(ClearApplicationRedirection, hos::Version_9_0_0), - MAKE_SERVICE_COMMAND_META(EraseProgramRedirection, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(EraseApplicationControlRedirection, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(EraseApplicationHtmlDocumentRedirection, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(EraseApplicationLegalInformationRedirection, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(ResolveProgramPathForDebug, hos::Version_7_0_0), - MAKE_SERVICE_COMMAND_META(RedirectProgramPathForDebug, hos::Version_7_0_0), - MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathForDebugDeprecated, hos::Version_7_0_0, hos::Version_8_1_0), - MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathForDebug, hos::Version_9_0_0), - MAKE_SERVICE_COMMAND_META(EraseProgramRedirectionForDebug, hos::Version_7_0_0), - }; - }; + #define AMS_LR_I_LOCATION_RESOLVER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, ResolveProgramPath, (sf::Out out, ncm::ProgramId id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, RedirectProgramPath, (const Path &path, ncm::ProgramId id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, ResolveApplicationControlPath, (sf::Out out, ncm::ProgramId id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, ResolveApplicationHtmlDocumentPath, (sf::Out out, ncm::ProgramId id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, ResolveDataPath, (sf::Out out, ncm::DataId id)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, RedirectApplicationControlPathDeprecated, (const Path &path, ncm::ProgramId id), hos::Version_1_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, RedirectApplicationControlPath, (const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, RedirectApplicationHtmlDocumentPathDeprecated, (const Path &path, ncm::ProgramId id), hos::Version_1_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, RedirectApplicationHtmlDocumentPath, (const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, ResolveApplicationLegalInformationPath, (sf::Out out, ncm::ProgramId id)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, RedirectApplicationLegalInformationPathDeprecated, (const Path &path, ncm::ProgramId id), hos::Version_1_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, RedirectApplicationLegalInformationPath, (const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, Refresh, ()) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, RedirectApplicationProgramPathDeprecated, (const Path &path, ncm::ProgramId id), hos::Version_5_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, RedirectApplicationProgramPath, (const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, ClearApplicationRedirectionDeprecated, (), hos::Version_5_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, ClearApplicationRedirection, (const sf::InArray &excluding_ids), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, EraseProgramRedirection, (ncm::ProgramId id), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, EraseApplicationControlRedirection, (ncm::ProgramId id), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 14, Result, EraseApplicationHtmlDocumentRedirection, (ncm::ProgramId id), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, EraseApplicationLegalInformationRedirection, (ncm::ProgramId id), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 16, Result, ResolveProgramPathForDebug, (sf::Out out, ncm::ProgramId id), hos::Version_7_0_0) \ + AMS_SF_METHOD_INFO(C, H, 17, Result, RedirectProgramPathForDebug, (const Path &path, ncm::ProgramId id), hos::Version_7_0_0) \ + AMS_SF_METHOD_INFO(C, H, 18, Result, RedirectApplicationProgramPathForDebugDeprecated, (const Path &path, ncm::ProgramId id), hos::Version_7_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 18, Result, RedirectApplicationProgramPathForDebug, (const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 19, Result, EraseProgramRedirectionForDebug, (ncm::ProgramId id), hos::Version_7_0_0) + + + AMS_SF_DEFINE_INTERFACE(ILocationResolver, AMS_LR_I_LOCATION_RESOLVER_INTERFACE_INFO) } diff --git a/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver_manager.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver_manager.hpp index 5d9c55184..79cac08eb 100644 --- a/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver_manager.hpp @@ -22,20 +22,12 @@ namespace ams::lr { - class ILocationResolverManager : public sf::IServiceObject { - protected: - enum class CommandId { - OpenLocationResolver = 0, - OpenRegisteredLocationResolver = 1, - RefreshLocationResolver = 2, - OpenAddOnContentLocationResolver = 3, - }; - public: - /* Actual commands. */ - virtual Result OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id) = 0; - virtual Result OpenRegisteredLocationResolver(sf::Out> out) = 0; - virtual Result RefreshLocationResolver(ncm::StorageId storage_id) = 0; - virtual Result OpenAddOnContentLocationResolver(sf::Out> out) = 0; - }; + #define AMS_LR_I_LOCATION_RESOLVER_MANAGER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, OpenLocationResolver, (sf::Out> out, ncm::StorageId storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, OpenRegisteredLocationResolver, (sf::Out> out)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, RefreshLocationResolver, (ncm::StorageId storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, OpenAddOnContentLocationResolver, (sf::Out> out), hos::Version_2_0_0) + + AMS_SF_DEFINE_INTERFACE(ILocationResolverManager, AMS_LR_I_LOCATION_RESOLVER_MANAGER_INTERFACE_INFO) } diff --git a/libraries/libstratosphere/include/stratosphere/lr/lr_i_registered_location_resolver.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_i_registered_location_resolver.hpp index 837dfbc8b..d628c5a51 100644 --- a/libraries/libstratosphere/include/stratosphere/lr/lr_i_registered_location_resolver.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_i_registered_location_resolver.hpp @@ -19,57 +19,22 @@ namespace ams::lr { - class IRegisteredLocationResolver : public sf::IServiceObject { - protected: - enum class CommandId { - ResolveProgramPath = 0, - RegisterProgramPathDeprecated = 1, - RegisterProgramPath = 1, - UnregisterProgramPath = 2, - RedirectProgramPathDeprecated = 3, - RedirectProgramPath = 3, - ResolveHtmlDocumentPath = 4, - RegisterHtmlDocumentPathDeprecated = 5, - RegisterHtmlDocumentPath = 5, - UnregisterHtmlDocumentPath = 6, - RedirectHtmlDocumentPathDeprecated = 7, - RedirectHtmlDocumentPath = 7, - Refresh = 8, - RefreshExcluding = 9, - }; - public: - /* Actual commands. */ - virtual Result ResolveProgramPath(sf::Out out, ncm::ProgramId id) = 0; - virtual Result RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) = 0; - virtual Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0; - virtual Result UnregisterProgramPath(ncm::ProgramId id) = 0; - virtual Result RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id) = 0; - virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0; - virtual Result ResolveHtmlDocumentPath(sf::Out out, ncm::ProgramId id) = 0; - virtual Result RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) = 0; - virtual Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0; - virtual Result UnregisterHtmlDocumentPath(ncm::ProgramId id) = 0; - virtual Result RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) = 0; - virtual Result RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) = 0; - virtual Result Refresh() = 0; - virtual Result RefreshExcluding(const sf::InArray &ids) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(ResolveProgramPath), - MAKE_SERVICE_COMMAND_META(RegisterProgramPathDeprecated, hos::Version_1_0_0, hos::Version_8_1_0), - MAKE_SERVICE_COMMAND_META(RegisterProgramPath, hos::Version_9_0_0), - MAKE_SERVICE_COMMAND_META(UnregisterProgramPath), - MAKE_SERVICE_COMMAND_META(RedirectProgramPathDeprecated, hos::Version_1_0_0, hos::Version_8_1_0), - MAKE_SERVICE_COMMAND_META(RedirectProgramPath, hos::Version_9_0_0), - MAKE_SERVICE_COMMAND_META(ResolveHtmlDocumentPath, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(RegisterHtmlDocumentPathDeprecated, hos::Version_2_0_0, hos::Version_8_1_0), - MAKE_SERVICE_COMMAND_META(RegisterHtmlDocumentPath, hos::Version_9_0_0), - MAKE_SERVICE_COMMAND_META(UnregisterHtmlDocumentPath, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(RedirectHtmlDocumentPathDeprecated, hos::Version_2_0_0, hos::Version_8_1_0), - MAKE_SERVICE_COMMAND_META(RedirectHtmlDocumentPath, hos::Version_9_0_0), - MAKE_SERVICE_COMMAND_META(Refresh, hos::Version_7_0_0), - MAKE_SERVICE_COMMAND_META(RefreshExcluding, hos::Version_9_0_0), - }; - }; + #define AMS_LR_I_REGISTERED_LOCATION_RESOLVER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, ResolveProgramPath, (sf::Out out, ncm::ProgramId id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, RegisterProgramPathDeprecated, (const Path &path, ncm::ProgramId id), hos::Version_1_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, RegisterProgramPath, (const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, UnregisterProgramPath, (ncm::ProgramId id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, RedirectProgramPathDeprecated, (const Path &path, ncm::ProgramId id), hos::Version_1_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, RedirectProgramPath, (const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, ResolveHtmlDocumentPath, (sf::Out out, ncm::ProgramId id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, RegisterHtmlDocumentPathDeprecated, (const Path &path, ncm::ProgramId id), hos::Version_2_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, RegisterHtmlDocumentPath, (const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, UnregisterHtmlDocumentPath, (ncm::ProgramId id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, RedirectHtmlDocumentPathDeprecated, (const Path &path, ncm::ProgramId id), hos::Version_2_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, RedirectHtmlDocumentPath, (const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, Refresh, (), hos::Version_7_0_0) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, RefreshExcluding, (const sf::InArray &ids), hos::Version_9_0_0) + + AMS_SF_DEFINE_INTERFACE(IRegisteredLocationResolver, AMS_LR_I_REGISTERED_LOCATION_RESOLVER_INTERFACE_INFO) } diff --git a/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver_manager_impl.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver_manager_impl.hpp index 6711cab75..25e571883 100644 --- a/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver_manager_impl.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver_manager_impl.hpp @@ -21,7 +21,7 @@ namespace ams::lr { - class LocationResolverManagerImpl final : public ILocationResolverManager { + class LocationResolverManagerImpl final { private: /* Resolver storage. */ ncm::BoundedMap, 5> location_resolvers; @@ -31,17 +31,11 @@ namespace ams::lr { os::Mutex mutex{false}; public: /* Actual commands. */ - virtual Result OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id) override; - virtual Result OpenRegisteredLocationResolver(sf::Out> out) override; - virtual Result RefreshLocationResolver(ncm::StorageId storage_id) override; - virtual Result OpenAddOnContentLocationResolver(sf::Out> out) override; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(OpenLocationResolver), - MAKE_SERVICE_COMMAND_META(OpenRegisteredLocationResolver), - MAKE_SERVICE_COMMAND_META(RefreshLocationResolver), - MAKE_SERVICE_COMMAND_META(OpenAddOnContentLocationResolver, hos::Version_2_0_0), - }; + Result OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id); + Result OpenRegisteredLocationResolver(sf::Out> out); + Result RefreshLocationResolver(ncm::StorageId storage_id); + Result OpenAddOnContentLocationResolver(sf::Out> out); }; + static_assert(IsILocationResolverManager); } diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_manager_impl.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_manager_impl.hpp index 244aa3ffb..ecff33061 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_manager_impl.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_manager_impl.hpp @@ -67,7 +67,7 @@ namespace ams::ncm { }; static_assert(util::is_pod::value); - class ContentManagerImpl final : public IContentManager { + class ContentManagerImpl final { private: constexpr static size_t MaxContentStorageRoots = 8; constexpr static size_t MaxContentMetaDatabaseRoots = 8; @@ -131,21 +131,22 @@ namespace ams::ncm { Result EnsureAndMountSystemSaveData(const char *mount, const SystemSaveDataInfo &info) const; public: /* Actual commands. */ - virtual Result CreateContentStorage(StorageId storage_id) override; - virtual Result CreateContentMetaDatabase(StorageId storage_id) override; - virtual Result VerifyContentStorage(StorageId storage_id) override; - virtual Result VerifyContentMetaDatabase(StorageId storage_id) override; - virtual Result OpenContentStorage(sf::Out> out, StorageId storage_id) override; - virtual Result OpenContentMetaDatabase(sf::Out> out, StorageId storage_id) override; - virtual Result CloseContentStorageForcibly(StorageId storage_id) override; - virtual Result CloseContentMetaDatabaseForcibly(StorageId storage_id) override; - virtual Result CleanupContentMetaDatabase(StorageId storage_id) override; - virtual Result ActivateContentStorage(StorageId storage_id) override; - virtual Result InactivateContentStorage(StorageId storage_id) override; - virtual Result ActivateContentMetaDatabase(StorageId storage_id) override; - virtual Result InactivateContentMetaDatabase(StorageId storage_id) override; - virtual Result InvalidateRightsIdCache() override; - virtual Result GetMemoryReport(sf::Out out) override; + Result CreateContentStorage(StorageId storage_id); + Result CreateContentMetaDatabase(StorageId storage_id); + Result VerifyContentStorage(StorageId storage_id); + Result VerifyContentMetaDatabase(StorageId storage_id); + Result OpenContentStorage(sf::Out> out, StorageId storage_id); + Result OpenContentMetaDatabase(sf::Out> out, StorageId storage_id); + Result CloseContentStorageForcibly(StorageId storage_id); + Result CloseContentMetaDatabaseForcibly(StorageId storage_id); + Result CleanupContentMetaDatabase(StorageId storage_id); + Result ActivateContentStorage(StorageId storage_id); + Result InactivateContentStorage(StorageId storage_id); + Result ActivateContentMetaDatabase(StorageId storage_id); + Result InactivateContentMetaDatabase(StorageId storage_id); + Result InvalidateRightsIdCache(); + Result GetMemoryReport(sf::Out out); }; + static_assert(IsIContentManager); } diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_manager.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_manager.hpp index 1ddfd6aa3..c65867ab4 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_manager.hpp @@ -20,59 +20,23 @@ namespace ams::ncm { - class IContentManager : public sf::IServiceObject { - protected: - enum class CommandId { - CreateContentStorage = 0, - CreateContentMetaDatabase = 1, - VerifyContentStorage = 2, - VerifyContentMetaDatabase = 3, - OpenContentStorage = 4, - OpenContentMetaDatabase = 5, - CloseContentStorageForcibly = 6, - CloseContentMetaDatabaseForcibly = 7, - CleanupContentMetaDatabase = 8, - ActivateContentStorage = 9, - InactivateContentStorage = 10, - ActivateContentMetaDatabase = 11, - InactivateContentMetaDatabase = 12, - InvalidateRightsIdCache = 13, - GetMemoryReport = 14, - }; - public: - virtual Result CreateContentStorage(StorageId storage_id) = 0; - virtual Result CreateContentMetaDatabase(StorageId storage_id) = 0; - virtual Result VerifyContentStorage(StorageId storage_id) = 0; - virtual Result VerifyContentMetaDatabase(StorageId storage_id) = 0; - virtual Result OpenContentStorage(sf::Out> out, StorageId storage_id) = 0; - virtual Result OpenContentMetaDatabase(sf::Out> out, StorageId storage_id) = 0; - virtual Result CloseContentStorageForcibly(StorageId storage_id) = 0; - virtual Result CloseContentMetaDatabaseForcibly(StorageId storage_id) = 0; - virtual Result CleanupContentMetaDatabase(StorageId storage_id) = 0; - virtual Result ActivateContentStorage(StorageId storage_id) = 0; - virtual Result InactivateContentStorage(StorageId storage_id) = 0; - virtual Result ActivateContentMetaDatabase(StorageId storage_id) = 0; - virtual Result InactivateContentMetaDatabase(StorageId storage_id) = 0; - virtual Result InvalidateRightsIdCache() = 0; - virtual Result GetMemoryReport(sf::Out out) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(CreateContentStorage), - MAKE_SERVICE_COMMAND_META(CreateContentMetaDatabase), - MAKE_SERVICE_COMMAND_META(VerifyContentStorage), - MAKE_SERVICE_COMMAND_META(VerifyContentMetaDatabase), - MAKE_SERVICE_COMMAND_META(OpenContentStorage), - MAKE_SERVICE_COMMAND_META(OpenContentMetaDatabase), - MAKE_SERVICE_COMMAND_META(CloseContentStorageForcibly, hos::Version_1_0_0, hos::Version_1_0_0), - MAKE_SERVICE_COMMAND_META(CloseContentMetaDatabaseForcibly, hos::Version_1_0_0, hos::Version_1_0_0), - MAKE_SERVICE_COMMAND_META(CleanupContentMetaDatabase), - MAKE_SERVICE_COMMAND_META(ActivateContentStorage, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(InactivateContentStorage, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(ActivateContentMetaDatabase, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(InactivateContentMetaDatabase, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(InvalidateRightsIdCache, hos::Version_9_0_0), - MAKE_SERVICE_COMMAND_META(GetMemoryReport, hos::Version_10_0_0), - }; - }; + #define AMS_NCM_I_CONTENT_MANAGER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, CreateContentStorage, (StorageId storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, CreateContentMetaDatabase, (StorageId storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, VerifyContentStorage, (StorageId storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, VerifyContentMetaDatabase, (StorageId storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, OpenContentStorage, (sf::Out> out, StorageId storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, OpenContentMetaDatabase, (sf::Out> out, StorageId storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, CloseContentStorageForcibly, (StorageId storage_id), hos::Version_1_0_0, hos::Version_1_0_0) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, CloseContentMetaDatabaseForcibly, (StorageId storage_id), hos::Version_1_0_0, hos::Version_1_0_0) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, CleanupContentMetaDatabase, (StorageId storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, ActivateContentStorage, (StorageId storage_id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, InactivateContentStorage, (StorageId storage_id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, ActivateContentMetaDatabase, (StorageId storage_id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, InactivateContentMetaDatabase, (StorageId storage_id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, InvalidateRightsIdCache, (), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 14, Result, GetMemoryReport, (sf::Out out), hos::Version_10_0_0) + + AMS_SF_DEFINE_INTERFACE(IContentManager, AMS_NCM_I_CONTENT_MANAGER_INTERFACE_INFO); } diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_meta_database.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_meta_database.hpp index 98b001c21..b7d81067b 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_meta_database.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_meta_database.hpp @@ -19,84 +19,31 @@ namespace ams::ncm { - class IContentMetaDatabase : public sf::IServiceObject { - protected: - enum class CommandId { - Set = 0, - Get = 1, - Remove = 2, - GetContentIdByType = 3, - ListContentInfo = 4, - List = 5, - GetLatestContentMetaKey = 6, - ListApplication = 7, - Has = 8, - HasAll = 9, - GetSize = 10, - GetRequiredSystemVersion = 11, - GetPatchId = 12, - DisableForcibly = 13, - LookupOrphanContent = 14, - Commit = 15, - HasContent = 16, - ListContentMetaInfo = 17, - GetAttributes = 18, - GetRequiredApplicationVersion = 19, - GetContentIdByTypeAndIdOffset = 20, - GetCount = 21, - GetOwnerApplicationId = 22, - }; - public: - /* Actual commands. */ - virtual Result Set(const ContentMetaKey &key, sf::InBuffer value) = 0; - virtual Result Get(sf::Out out_size, const ContentMetaKey &key, sf::OutBuffer out_value) = 0; - virtual Result Remove(const ContentMetaKey &key) = 0; - virtual Result GetContentIdByType(sf::Out out_content_id, const ContentMetaKey &key, ContentType type) = 0; - virtual Result ListContentInfo(sf::Out out_entries_written, const sf::OutArray &out_info, const ContentMetaKey &key, s32 offset) = 0; - virtual Result List(sf::Out out_entries_total, sf::Out out_entries_written, const sf::OutArray &out_info, ContentMetaType meta_type, ApplicationId application_id, u64 min, u64 max, ContentInstallType install_type) = 0; - virtual Result GetLatestContentMetaKey(sf::Out out_key, u64 id) = 0; - virtual Result ListApplication(sf::Out out_entries_total, sf::Out out_entries_written, const sf::OutArray &out_keys, ContentMetaType meta_type) = 0; - virtual Result Has(sf::Out out, const ContentMetaKey &key) = 0; - virtual Result HasAll(sf::Out out, const sf::InArray &keys) = 0; - virtual Result GetSize(sf::Out out_size, const ContentMetaKey &key) = 0; - virtual Result GetRequiredSystemVersion(sf::Out out_version, const ContentMetaKey &key) = 0; - virtual Result GetPatchId(sf::Out out_patch_id, const ContentMetaKey &key) = 0; - virtual Result DisableForcibly() = 0; - virtual Result LookupOrphanContent(const sf::OutArray &out_orphaned, const sf::InArray &content_ids) = 0; - virtual Result Commit() = 0; - virtual Result HasContent(sf::Out out, const ContentMetaKey &key, const ContentId &content_id) = 0; - virtual Result ListContentMetaInfo(sf::Out out_entries_written, const sf::OutArray &out_meta_info, const ContentMetaKey &key, s32 offset) = 0; - virtual Result GetAttributes(sf::Out out_attributes, const ContentMetaKey &key) = 0; - virtual Result GetRequiredApplicationVersion(sf::Out out_version, const ContentMetaKey &key) = 0; - virtual Result GetContentIdByTypeAndIdOffset(sf::Out out_content_id, const ContentMetaKey &key, ContentType type, u8 id_offset) = 0; - virtual Result GetCount(sf::Out out_count) = 0; - virtual Result GetOwnerApplicationId(sf::Out out_id, const ContentMetaKey &key) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(Set), - MAKE_SERVICE_COMMAND_META(Get), - MAKE_SERVICE_COMMAND_META(Remove), - MAKE_SERVICE_COMMAND_META(GetContentIdByType), - MAKE_SERVICE_COMMAND_META(ListContentInfo), - MAKE_SERVICE_COMMAND_META(List), - MAKE_SERVICE_COMMAND_META(GetLatestContentMetaKey), - MAKE_SERVICE_COMMAND_META(ListApplication), - MAKE_SERVICE_COMMAND_META(Has), - MAKE_SERVICE_COMMAND_META(HasAll), - MAKE_SERVICE_COMMAND_META(GetSize), - MAKE_SERVICE_COMMAND_META(GetRequiredSystemVersion), - MAKE_SERVICE_COMMAND_META(GetPatchId), - MAKE_SERVICE_COMMAND_META(DisableForcibly), - MAKE_SERVICE_COMMAND_META(LookupOrphanContent), - MAKE_SERVICE_COMMAND_META(Commit), - MAKE_SERVICE_COMMAND_META(HasContent), - MAKE_SERVICE_COMMAND_META(ListContentMetaInfo), - MAKE_SERVICE_COMMAND_META(GetAttributes), - MAKE_SERVICE_COMMAND_META(GetRequiredApplicationVersion, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(GetContentIdByTypeAndIdOffset, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(GetCount, hos::Version_10_0_0), - MAKE_SERVICE_COMMAND_META(GetOwnerApplicationId, hos::Version_10_0_0), - }; - }; + #define AMS_NCM_I_CONTENT_META_DATABASE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Set, (const ContentMetaKey &key, sf::InBuffer value)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, Get, (sf::Out out_size, const ContentMetaKey &key, sf::OutBuffer out_value)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, Remove, (const ContentMetaKey &key)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetContentIdByType, (sf::Out out_content_id, const ContentMetaKey &key, ContentType type)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, ListContentInfo, (sf::Out out_entries_written, const sf::OutArray &out_info, const ContentMetaKey &key, s32 offset)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, List, (sf::Out out_entries_total, sf::Out out_entries_written, const sf::OutArray &out_info, ContentMetaType meta_type, ApplicationId application_id, u64 min, u64 max, ContentInstallType install_type)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, GetLatestContentMetaKey, (sf::Out out_key, u64 id)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, ListApplication, (sf::Out out_entries_total, sf::Out out_entries_written, const sf::OutArray &out_keys, ContentMetaType meta_type)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, Has, (sf::Out out, const ContentMetaKey &key)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, HasAll, (sf::Out out, const sf::InArray &keys)) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, GetSize, (sf::Out out_size, const ContentMetaKey &key)) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, GetRequiredSystemVersion, (sf::Out out_version, const ContentMetaKey &key)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, GetPatchId, (sf::Out out_patch_id, const ContentMetaKey &key)) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, DisableForcibly, ()) \ + AMS_SF_METHOD_INFO(C, H, 14, Result, LookupOrphanContent, (const sf::OutArray &out_orphaned, const sf::InArray &content_ids)) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, Commit, ()) \ + AMS_SF_METHOD_INFO(C, H, 16, Result, HasContent, (sf::Out out, const ContentMetaKey &key, const ContentId &content_id)) \ + AMS_SF_METHOD_INFO(C, H, 17, Result, ListContentMetaInfo, (sf::Out out_entries_written, const sf::OutArray &out_meta_info, const ContentMetaKey &key, s32 offset)) \ + AMS_SF_METHOD_INFO(C, H, 18, Result, GetAttributes, (sf::Out out_attributes, const ContentMetaKey &key)) \ + AMS_SF_METHOD_INFO(C, H, 19, Result, GetRequiredApplicationVersion, (sf::Out out_version, const ContentMetaKey &key), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 20, Result, GetContentIdByTypeAndIdOffset, (sf::Out out_content_id, const ContentMetaKey &key, ContentType type, u8 id_offset), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 21, Result, GetCount, (sf::Out out_count), hos::Version_10_0_0) \ + AMS_SF_METHOD_INFO(C, H, 22, Result, GetOwnerApplicationId, (sf::Out out_id, const ContentMetaKey &key), hos::Version_10_0_0) + + AMS_SF_DEFINE_INTERFACE(IContentMetaDatabase, AMS_NCM_I_CONTENT_META_DATABASE_INTERFACE_INFO) } diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_storage.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_storage.hpp index abe070674..6ab43bb9e 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_storage.hpp @@ -22,109 +22,38 @@ namespace ams::ncm { - class IContentStorage : public sf::IServiceObject { - NON_COPYABLE(IContentStorage); - NON_MOVEABLE(IContentStorage); - protected: - enum class CommandId { - GeneratePlaceHolderId = 0, - CreatePlaceHolder = 1, - DeletePlaceHolder = 2, - HasPlaceHolder = 3, - WritePlaceHolder = 4, - Register = 5, - Delete = 6, - Has = 7, - GetPath = 8, - GetPlaceHolderPath = 9, - CleanupAllPlaceHolder = 10, - ListPlaceHolder = 11, - GetContentCount = 12, - ListContentId = 13, - GetSizeFromContentId = 14, - DisableForcibly = 15, - RevertToPlaceHolder = 16, - SetPlaceHolderSize = 17, - ReadContentIdFile = 18, - GetRightsIdFromPlaceHolderIdDeprecated = 19, - GetRightsIdFromPlaceHolderId = 19, - GetRightsIdFromContentIdDeprecated = 20, - GetRightsIdFromContentId = 20, - WriteContentForDebug = 21, - GetFreeSpaceSize = 22, - GetTotalSpaceSize = 23, - FlushPlaceHolder = 24, - GetSizeFromPlaceHolderId = 25, - RepairInvalidFileAttribute = 26, - GetRightsIdFromPlaceHolderIdWithCache = 27, - }; - public: - IContentStorage() { /* ... */ } - public: - virtual Result GeneratePlaceHolderId(sf::Out out) = 0; - virtual Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, s64 size) = 0; - virtual Result DeletePlaceHolder(PlaceHolderId placeholder_id) = 0; - virtual Result HasPlaceHolder(sf::Out out, PlaceHolderId placeholder_id) = 0; - virtual Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, sf::InBuffer data) = 0; - virtual Result Register(PlaceHolderId placeholder_id, ContentId content_id) = 0; - virtual Result Delete(ContentId content_id) = 0; - virtual Result Has(sf::Out out, ContentId content_id) = 0; - virtual Result GetPath(sf::Out out, ContentId content_id) = 0; - virtual Result GetPlaceHolderPath(sf::Out out, PlaceHolderId placeholder_id) = 0; - virtual Result CleanupAllPlaceHolder() = 0; - virtual Result ListPlaceHolder(sf::Out out_count, const sf::OutArray &out_buf) = 0; - virtual Result GetContentCount(sf::Out out_count) = 0; - virtual Result ListContentId(sf::Out out_count, const sf::OutArray &out_buf, s32 start_offset) = 0; - virtual Result GetSizeFromContentId(sf::Out out_size, ContentId content_id) = 0; - virtual Result DisableForcibly() = 0; - virtual Result RevertToPlaceHolder(PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id) = 0; - virtual Result SetPlaceHolderSize(PlaceHolderId placeholder_id, s64 size) = 0; - virtual Result ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, s64 offset) = 0; - virtual Result GetRightsIdFromPlaceHolderIdDeprecated(sf::Out out_rights_id, PlaceHolderId placeholder_id) = 0; - virtual Result GetRightsIdFromPlaceHolderId(sf::Out out_rights_id, PlaceHolderId placeholder_id) = 0; - virtual Result GetRightsIdFromContentIdDeprecated(sf::Out out_rights_id, ContentId content_id) = 0; - virtual Result GetRightsIdFromContentId(sf::Out out_rights_id, ContentId content_id) = 0; - virtual Result WriteContentForDebug(ContentId content_id, s64 offset, sf::InBuffer data) = 0; - virtual Result GetFreeSpaceSize(sf::Out out_size) = 0; - virtual Result GetTotalSpaceSize(sf::Out out_size) = 0; - virtual Result FlushPlaceHolder() = 0; - virtual Result GetSizeFromPlaceHolderId(sf::Out out, PlaceHolderId placeholder_id) = 0; - virtual Result RepairInvalidFileAttribute() = 0; - virtual Result GetRightsIdFromPlaceHolderIdWithCache(sf::Out out_rights_id, PlaceHolderId placeholder_id, ContentId cache_content_id) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GeneratePlaceHolderId), - MAKE_SERVICE_COMMAND_META(CreatePlaceHolder), - MAKE_SERVICE_COMMAND_META(DeletePlaceHolder), - MAKE_SERVICE_COMMAND_META(HasPlaceHolder), - MAKE_SERVICE_COMMAND_META(WritePlaceHolder), - MAKE_SERVICE_COMMAND_META(Register), - MAKE_SERVICE_COMMAND_META(Delete), - MAKE_SERVICE_COMMAND_META(Has), - MAKE_SERVICE_COMMAND_META(GetPath), - MAKE_SERVICE_COMMAND_META(GetPlaceHolderPath), - MAKE_SERVICE_COMMAND_META(CleanupAllPlaceHolder), - MAKE_SERVICE_COMMAND_META(ListPlaceHolder), - MAKE_SERVICE_COMMAND_META(GeneratePlaceHolderId), - MAKE_SERVICE_COMMAND_META(GetContentCount), - MAKE_SERVICE_COMMAND_META(ListContentId), - MAKE_SERVICE_COMMAND_META(GetSizeFromContentId), - MAKE_SERVICE_COMMAND_META(DisableForcibly), - MAKE_SERVICE_COMMAND_META(RevertToPlaceHolder, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(SetPlaceHolderSize, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(ReadContentIdFile, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(GetRightsIdFromPlaceHolderIdDeprecated, hos::Version_2_0_0, hos::Version_2_3_0), - MAKE_SERVICE_COMMAND_META(GetRightsIdFromPlaceHolderId, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GetRightsIdFromContentIdDeprecated, hos::Version_2_0_0, hos::Version_2_3_0), - MAKE_SERVICE_COMMAND_META(GetRightsIdFromContentId, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(WriteContentForDebug, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(GetFreeSpaceSize, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(GetTotalSpaceSize, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(FlushPlaceHolder, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GetSizeFromPlaceHolderId, hos::Version_4_0_0), - MAKE_SERVICE_COMMAND_META(RepairInvalidFileAttribute, hos::Version_4_0_0), - MAKE_SERVICE_COMMAND_META(GetRightsIdFromPlaceHolderIdWithCache, hos::Version_8_0_0), - }; - }; + #define AMS_NCM_I_CONTENT_STORAGE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GeneratePlaceHolderId, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, CreatePlaceHolder, (PlaceHolderId placeholder_id, ContentId content_id, s64 size)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, DeletePlaceHolder, (PlaceHolderId placeholder_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, HasPlaceHolder, (sf::Out out, PlaceHolderId placeholder_id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, WritePlaceHolder, (PlaceHolderId placeholder_id, s64 offset, sf::InBuffer data)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, Register, (PlaceHolderId placeholder_id, ContentId content_id)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, Delete, (ContentId content_id)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, Has, (sf::Out out, ContentId content_id)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, GetPath, (sf::Out out, ContentId content_id)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, GetPlaceHolderPath, (sf::Out out, PlaceHolderId placeholder_id)) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, CleanupAllPlaceHolder, ()) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, ListPlaceHolder, (sf::Out out_count, const sf::OutArray &out_buf)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, GetContentCount, (sf::Out out_count)) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, ListContentId, (sf::Out out_count, const sf::OutArray &out_buf, s32 start_offset)) \ + AMS_SF_METHOD_INFO(C, H, 14, Result, GetSizeFromContentId, (sf::Out out_size, ContentId content_id)) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, DisableForcibly, ()) \ + AMS_SF_METHOD_INFO(C, H, 16, Result, RevertToPlaceHolder, (PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 17, Result, SetPlaceHolderSize, (PlaceHolderId placeholder_id, s64 size), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 18, Result, ReadContentIdFile, (sf::OutBuffer buf, ContentId content_id, s64 offset), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 19, Result, GetRightsIdFromPlaceHolderIdDeprecated, (sf::Out out_rights_id, PlaceHolderId placeholder_id), hos::Version_2_0_0, hos::Version_2_3_0) \ + AMS_SF_METHOD_INFO(C, H, 19, Result, GetRightsIdFromPlaceHolderId, (sf::Out out_rights_id, PlaceHolderId placeholder_id), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 20, Result, GetRightsIdFromContentIdDeprecated, (sf::Out out_rights_id, ContentId content_id), hos::Version_2_0_0, hos::Version_2_3_0) \ + AMS_SF_METHOD_INFO(C, H, 20, Result, GetRightsIdFromContentId, (sf::Out out_rights_id, ContentId content_id), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 21, Result, WriteContentForDebug, (ContentId content_id, s64 offset, sf::InBuffer data), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 22, Result, GetFreeSpaceSize, (sf::Out out_size), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 23, Result, GetTotalSpaceSize, (sf::Out out_size), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 24, Result, FlushPlaceHolder, (), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 25, Result, GetSizeFromPlaceHolderId, (sf::Out out, PlaceHolderId placeholder_id), hos::Version_4_0_0) \ + AMS_SF_METHOD_INFO(C, H, 26, Result, RepairInvalidFileAttribute, (), hos::Version_4_0_0) \ + AMS_SF_METHOD_INFO(C, H, 27, Result, GetRightsIdFromPlaceHolderIdWithCache, (sf::Out out_rights_id, PlaceHolderId placeholder_id, ContentId cache_content_id), hos::Version_8_0_0) + + AMS_SF_DEFINE_INTERFACE(IContentStorage, AMS_NCM_I_CONTENT_STORAGE_INTERFACE_INFO) } diff --git a/libraries/libstratosphere/include/stratosphere/ns.hpp b/libraries/libstratosphere/include/stratosphere/ns.hpp new file mode 100644 index 000000000..8e7d2a607 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/ns.hpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include diff --git a/libraries/libstratosphere/include/stratosphere/ns/impl/ns_i_async.hpp b/libraries/libstratosphere/include/stratosphere/ns/impl/ns_i_async.hpp new file mode 100644 index 000000000..1d4885da6 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/ns/impl/ns_i_async.hpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::ns::impl { + + #define AMS_NS_I_ASYNC_RESULT_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Get, ()) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, Cancel, ()) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GetErrorContext, (::ams::sf::Out<::ams::err::ErrorContext> out)) + + AMS_SF_DEFINE_INTERFACE(IAsyncResult, AMS_NS_I_ASYNC_RESULT_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_event_observer.hpp b/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_event_observer.hpp index d3e147e9c..d212ab30f 100644 --- a/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_event_observer.hpp +++ b/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_event_observer.hpp @@ -22,21 +22,10 @@ namespace ams::pgl::sf { - class IEventObserver : public ams::sf::IServiceObject { - protected: - enum class CommandId { - GetProcessEventHandle = 0, - GetProcessEventInfo = 1, - }; - public: - /* Actual commands. */ - virtual Result GetProcessEventHandle(ams::sf::OutCopyHandle out) = 0; - virtual Result GetProcessEventInfo(ams::sf::Out out) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetProcessEventHandle), - MAKE_SERVICE_COMMAND_META(GetProcessEventInfo), - }; - }; + #define AMS_PGL_I_EVENT_OBSERVER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetProcessEventHandle, (ams::sf::OutCopyHandle out)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetProcessEventInfo, (ams::sf::Out out)) + + AMS_SF_DEFINE_INTERFACE(IEventObserver, AMS_PGL_I_EVENT_OBSERVER_INTERFACE_INFO); } \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_shell_interface.hpp b/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_shell_interface.hpp index c44d72924..9046b2ef2 100644 --- a/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_shell_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/pgl/sf/pgl_sf_i_shell_interface.hpp @@ -23,52 +23,22 @@ namespace ams::pgl::sf { - class IShellInterface : public ams::sf::IServiceObject { - protected: - enum class CommandId { - LaunchProgram = 0, - TerminateProcess = 1, - LaunchProgramFromHost = 2, - GetHostContentMetaInfo = 4, - GetApplicationProcessId = 5, - BoostSystemMemoryResourceLimit = 6, - IsProcessTracked = 7, - EnableApplicationCrashReport = 8, - IsApplicationCrashReportEnabled = 9, - EnableApplicationAllThreadDumpOnCrash = 10, - TriggerApplicationSnapShotDumper = 12, - GetShellEventObserver = 20, - }; - public: - /* Actual commands. */ - virtual Result LaunchProgram(ams::sf::Out out, const ncm::ProgramLocation &loc, u32 pm_flags, u8 pgl_flags) = 0; - virtual Result TerminateProcess(os::ProcessId process_id) = 0; - virtual Result LaunchProgramFromHost(ams::sf::Out out, const ams::sf::InBuffer &content_path, u32 pm_flags) = 0; - virtual Result GetHostContentMetaInfo(ams::sf::Out out, const ams::sf::InBuffer &content_path) = 0; - virtual Result GetApplicationProcessId(ams::sf::Out out) = 0; - virtual Result BoostSystemMemoryResourceLimit(u64 size) = 0; - virtual Result IsProcessTracked(ams::sf::Out out, os::ProcessId process_id) = 0; - virtual Result EnableApplicationCrashReport(bool enabled) = 0; - virtual Result IsApplicationCrashReportEnabled(ams::sf::Out out) = 0; - virtual Result EnableApplicationAllThreadDumpOnCrash(bool enabled) = 0; - virtual Result TriggerApplicationSnapShotDumper(SnapShotDumpType dump_type, const ams::sf::InBuffer &arg) = 0; + #define AMS_PGL_I_SHELL_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, LaunchProgram, (ams::sf::Out out, const ncm::ProgramLocation &loc, u32 pm_flags, u8 pgl_flags)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, TerminateProcess, (os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, LaunchProgramFromHost, (ams::sf::Out out, const ams::sf::InBuffer &content_path, u32 pm_flags)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetHostContentMetaInfo, (ams::sf::Out out, const ams::sf::InBuffer &content_path)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetApplicationProcessId, (ams::sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, BoostSystemMemoryResourceLimit, (u64 size)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, IsProcessTracked, (ams::sf::Out out, os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, EnableApplicationCrashReport, (bool enabled)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, IsApplicationCrashReportEnabled, (ams::sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, EnableApplicationAllThreadDumpOnCrash, (bool enabled)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, TriggerApplicationSnapShotDumper, (SnapShotDumpType dump_type, const ams::sf::InBuffer &arg)) \ + AMS_SF_METHOD_INFO(C, H, 20, Result, GetShellEventObserver, (ams::sf::Out> out)) + + AMS_SF_DEFINE_INTERFACE(IShellInterface, AMS_PGL_I_SHELL_INTERFACE_INTERFACE_INFO); + - virtual Result GetShellEventObserver(ams::sf::Out> out) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(LaunchProgram), - MAKE_SERVICE_COMMAND_META(TerminateProcess), - MAKE_SERVICE_COMMAND_META(LaunchProgramFromHost), - MAKE_SERVICE_COMMAND_META(GetHostContentMetaInfo), - MAKE_SERVICE_COMMAND_META(GetApplicationProcessId), - MAKE_SERVICE_COMMAND_META(BoostSystemMemoryResourceLimit), - MAKE_SERVICE_COMMAND_META(IsProcessTracked), - MAKE_SERVICE_COMMAND_META(EnableApplicationCrashReport), - MAKE_SERVICE_COMMAND_META(IsApplicationCrashReportEnabled), - MAKE_SERVICE_COMMAND_META(EnableApplicationAllThreadDumpOnCrash), - MAKE_SERVICE_COMMAND_META(TriggerApplicationSnapShotDumper), - MAKE_SERVICE_COMMAND_META(GetShellEventObserver), - }; - }; } \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/pgl/srv/pgl_srv_shell_interface.hpp b/libraries/libstratosphere/include/stratosphere/pgl/srv/pgl_srv_shell_interface.hpp index 40f74f3ba..3487c550b 100644 --- a/libraries/libstratosphere/include/stratosphere/pgl/srv/pgl_srv_shell_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/pgl/srv/pgl_srv_shell_interface.hpp @@ -20,7 +20,7 @@ namespace ams::pgl::srv { - class ShellInterface final : public pgl::sf::IShellInterface { + class ShellInterface final { NON_COPYABLE(ShellInterface); NON_MOVEABLE(ShellInterface); private: @@ -34,19 +34,20 @@ namespace ams::pgl::srv { } public: /* Interface commands. */ - virtual Result LaunchProgram(ams::sf::Out out, const ncm::ProgramLocation &loc, u32 pm_flags, u8 pgl_flags) override final; - virtual Result TerminateProcess(os::ProcessId process_id) override final; - virtual Result LaunchProgramFromHost(ams::sf::Out out, const ams::sf::InBuffer &content_path, u32 pm_flags) override final; - virtual Result GetHostContentMetaInfo(ams::sf::Out out, const ams::sf::InBuffer &content_path) override final; - virtual Result GetApplicationProcessId(ams::sf::Out out) override final; - virtual Result BoostSystemMemoryResourceLimit(u64 size) override final; - virtual Result IsProcessTracked(ams::sf::Out out, os::ProcessId process_id) override final; - virtual Result EnableApplicationCrashReport(bool enabled) override final; - virtual Result IsApplicationCrashReportEnabled(ams::sf::Out out) override final; - virtual Result EnableApplicationAllThreadDumpOnCrash(bool enabled) override final; - virtual Result TriggerApplicationSnapShotDumper(SnapShotDumpType dump_type, const ams::sf::InBuffer &arg) override final; + Result LaunchProgram(ams::sf::Out out, const ncm::ProgramLocation &loc, u32 pm_flags, u8 pgl_flags); + Result TerminateProcess(os::ProcessId process_id); + Result LaunchProgramFromHost(ams::sf::Out out, const ams::sf::InBuffer &content_path, u32 pm_flags); + Result GetHostContentMetaInfo(ams::sf::Out out, const ams::sf::InBuffer &content_path); + Result GetApplicationProcessId(ams::sf::Out out); + Result BoostSystemMemoryResourceLimit(u64 size); + Result IsProcessTracked(ams::sf::Out out, os::ProcessId process_id); + Result EnableApplicationCrashReport(bool enabled); + Result IsApplicationCrashReportEnabled(ams::sf::Out out); + Result EnableApplicationAllThreadDumpOnCrash(bool enabled); + Result TriggerApplicationSnapShotDumper(SnapShotDumpType dump_type, const ams::sf::InBuffer &arg); - virtual Result GetShellEventObserver(ams::sf::Out> out) override final; + Result GetShellEventObserver(ams::sf::Out> out); }; + static_assert(pgl::sf::IsIShellInterface); } diff --git a/libraries/libstratosphere/include/stratosphere/pm.hpp b/libraries/libstratosphere/include/stratosphere/pm.hpp index 801993fc1..5b252aefb 100644 --- a/libraries/libstratosphere/include/stratosphere/pm.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm.hpp @@ -16,8 +16,12 @@ #pragma once -#include "pm/pm_types.hpp" -#include "pm/pm_boot_mode_api.hpp" -#include "pm/pm_info_api.hpp" -#include "pm/pm_shell_api.hpp" -#include "pm/pm_dmnt_api.hpp" \ No newline at end of file +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/libraries/libstratosphere/include/stratosphere/pm/impl/pm_boot_mode_interface.hpp b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_boot_mode_interface.hpp new file mode 100644 index 000000000..9f37bacc5 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_boot_mode_interface.hpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::pm::impl { + + #define AMS_PM_I_BOOT_MODE_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, void, GetBootMode, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 1, void, SetMaintenanceBoot, ()) + + AMS_SF_DEFINE_INTERFACE(IBootModeInterface, AMS_PM_I_BOOT_MODE_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/pm/impl/pm_debug_monitor_interface.hpp b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_debug_monitor_interface.hpp new file mode 100644 index 000000000..1e3bfa6d6 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_debug_monitor_interface.hpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::pm::impl { + + #define AMS_PM_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetExceptionProcessIdList, (sf::Out out_count, const sf::OutArray &out_process_ids)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, StartProcess, (os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GetProcessId, (sf::Out out, ncm::ProgramId program_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, HookToCreateProcess, (sf::OutCopyHandle out_hook, ncm::ProgramId program_id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetApplicationProcessId, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, HookToCreateApplicationProcess, (sf::OutCopyHandle out_hook)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, ClearHook, (u32 which), hos::Version_6_0_0) \ + AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereGetProcessInfo, (sf::OutCopyHandle out_process_handle, sf::Out out_loc, sf::Out out_status, os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereGetCurrentLimitInfo, (sf::Out out_cur_val, sf::Out out_lim_val, u32 group, u32 resource)) + + AMS_SF_DEFINE_INTERFACE(IDebugMonitorInterface, AMS_PM_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO) + + #define AMS_PM_I_DEPRECATED_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetModuleIdList, (sf::Out out_count, const sf::OutBuffer &out_buf, u64 unused)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetExceptionProcessIdList, (sf::Out out_count, const sf::OutArray &out_process_ids)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, StartProcess, (os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetProcessId, (sf::Out out, ncm::ProgramId program_id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, HookToCreateProcess, (sf::OutCopyHandle out_hook, ncm::ProgramId program_id)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetApplicationProcessId, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, HookToCreateApplicationProcess, (sf::OutCopyHandle out_hook)) \ + AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereGetProcessInfo, (sf::OutCopyHandle out_process_handle, sf::Out out_loc, sf::Out out_status, os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereGetCurrentLimitInfo, (sf::Out out_cur_val, sf::Out out_lim_val, u32 group, u32 resource)) + + AMS_SF_DEFINE_INTERFACE(IDeprecatedDebugMonitorInterface, AMS_PM_I_DEPRECATED_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp new file mode 100644 index 000000000..c09b3b208 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::pm::impl { + + #define AMS_PM_I_INFORMATION_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetProgramId, (sf::Out out, os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereGetProcessId, (sf::Out out, ncm::ProgramId program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereHasLaunchedProgram, (sf::Out out, ncm::ProgramId program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmosphereGetProcessInfo, (sf::Out out_loc, sf::Out out_status, os::ProcessId process_id)) + + AMS_SF_DEFINE_INTERFACE(IInformationInterface, AMS_PM_I_INFORMATION_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/pm/impl/pm_shell_interface.hpp b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_shell_interface.hpp new file mode 100644 index 000000000..1343b7919 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_shell_interface.hpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::pm::impl { + + #define AMS_PM_I_SHELL_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, LaunchProgram, (sf::Out out_process_id, const ncm::ProgramLocation &loc, u32 flags)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, TerminateProcess, (os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, TerminateProgram, (ncm::ProgramId program_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, void, GetProcessEventHandle, (sf::OutCopyHandle out)) \ + AMS_SF_METHOD_INFO(C, H, 4, void, GetProcessEventInfo, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 5, void, NotifyBootFinished, ()) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, GetApplicationProcessIdForShell, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, BoostSystemMemoryResourceLimit, (u64 boost_size)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, BoostApplicationThreadResourceLimit, (), hos::Version_7_0_0) \ + AMS_SF_METHOD_INFO(C, H, 9, void, GetBootFinishedEventHandle, (sf::OutCopyHandle out), hos::Version_8_0_0) + + AMS_SF_DEFINE_INTERFACE(IShellInterface, AMS_PM_I_SHELL_INTERFACE_INTERFACE_INFO) + + #define AMS_PM_I_DEPRECATED_SHELL_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, LaunchProgram, (sf::Out out_process_id, const ncm::ProgramLocation &loc, u32 flags)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, TerminateProcess, (os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, TerminateProgram, (ncm::ProgramId program_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, void, GetProcessEventHandle, (sf::OutCopyHandle out)) \ + AMS_SF_METHOD_INFO(C, H, 4, void, GetProcessEventInfo, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, CleanupProcess, (os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, ClearExceptionOccurred, (os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 7, void, NotifyBootFinished, ()) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, GetApplicationProcessIdForShell, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, BoostSystemMemoryResourceLimit, (u64 boost_size), hos::Version_4_0_0) + + AMS_SF_DEFINE_INTERFACE(IDeprecatedShellInterface, AMS_PM_I_DEPRECATED_SHELL_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/psc/sf/psc_sf_i_pm_module.hpp b/libraries/libstratosphere/include/stratosphere/psc/sf/psc_sf_i_pm_module.hpp index 5673bd4ab..42fd75d3d 100644 --- a/libraries/libstratosphere/include/stratosphere/psc/sf/psc_sf_i_pm_module.hpp +++ b/libraries/libstratosphere/include/stratosphere/psc/sf/psc_sf_i_pm_module.hpp @@ -21,30 +21,13 @@ namespace ams::psc::sf { - class IPmModule : public ams::sf::IServiceObject { - protected: - enum class CommandId { - Initialize = 0, - GetRequest = 1, - Acknowledge = 2, - Finalize = 3, - AcknowledgeEx = 4, - }; - public: - /* Actual commands. */ - virtual Result Initialize(ams::sf::OutCopyHandle out, psc::PmModuleId module_id, const ams::sf::InBuffer &child_list) = 0; - virtual Result GetRequest(ams::sf::Out out_state, ams::sf::Out out_flags) = 0; - virtual Result Acknowledge() = 0; - virtual Result Finalize() = 0; - virtual Result AcknowledgeEx(PmState state) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(Initialize), - MAKE_SERVICE_COMMAND_META(GetRequest), - MAKE_SERVICE_COMMAND_META(Acknowledge), - MAKE_SERVICE_COMMAND_META(Finalize), - MAKE_SERVICE_COMMAND_META(AcknowledgeEx, hos::Version_5_1_0), - }; - }; + #define AMS_PSC_I_PM_MODULE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Initialize, (ams::sf::OutCopyHandle out, psc::PmModuleId module_id, const ams::sf::InBuffer &child_list)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetRequest, (ams::sf::Out out_state, ams::sf::Out out_flags)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, Acknowledge, ()) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, Finalize, ()) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, AcknowledgeEx, (PmState state), hos::Version_5_1_0) + + AMS_SF_DEFINE_INTERFACE(IPmModule, AMS_PSC_I_PM_MODULE_INTERFACE_INFO) } \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/psc/sf/psc_sf_i_pm_service.hpp b/libraries/libstratosphere/include/stratosphere/psc/sf/psc_sf_i_pm_service.hpp index f4bf8cc8b..f4dffbeb0 100644 --- a/libraries/libstratosphere/include/stratosphere/psc/sf/psc_sf_i_pm_service.hpp +++ b/libraries/libstratosphere/include/stratosphere/psc/sf/psc_sf_i_pm_service.hpp @@ -20,18 +20,9 @@ namespace ams::psc::sf { - class IPmService : public ams::sf::IServiceObject { - protected: - enum class CommandId { - Initialize = 0, - }; - public: - /* Actual commands. */ - virtual Result Initialize(ams::sf::Out> out) = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(Initialize), - }; - }; + #define AMS_PSC_I_PM_SERVICE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Initialize, (ams::sf::Out> out)) + + AMS_SF_DEFINE_INTERFACE(IPmService, AMS_PSC_I_PM_SERVICE_INTERFACE_INFO) } \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/ro.hpp b/libraries/libstratosphere/include/stratosphere/ro.hpp index a5972ab3a..d3a695220 100644 --- a/libraries/libstratosphere/include/stratosphere/ro.hpp +++ b/libraries/libstratosphere/include/stratosphere/ro.hpp @@ -16,4 +16,6 @@ #pragma once -#include "ro/ro_types.hpp" +#include +#include +#include diff --git a/libraries/libstratosphere/include/stratosphere/ro/impl/ro_debug_monitor_interface.hpp b/libraries/libstratosphere/include/stratosphere/ro/impl/ro_debug_monitor_interface.hpp new file mode 100644 index 000000000..40e703a8a --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/ro/impl/ro_debug_monitor_interface.hpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::ro::impl { + + #define AMS_RO_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetProcessModuleInfo, (sf::Out out_count, const sf::OutArray &out_infos, os::ProcessId process_id)) + + AMS_SF_DEFINE_INTERFACE(IDebugMonitorInterface, AMS_RO_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/ro/impl/ro_ro_interface.hpp b/libraries/libstratosphere/include/stratosphere/ro/impl/ro_ro_interface.hpp new file mode 100644 index 000000000..624d1e5d8 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/ro/impl/ro_ro_interface.hpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::ro::impl { + + #define AMS_RO_I_RO_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, MapManualLoadModuleMemory, (sf::Out out_load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, UnmapManualLoadModuleMemory, (const sf::ClientProcessId &client_pid, u64 nro_address)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, RegisterModuleInfo, (const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, UnregisterModuleInfo, (const sf::ClientProcessId &client_pid, u64 nrr_address)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, RegisterProcessHandle, (const sf::ClientProcessId &client_pid, sf::CopyHandle process_h)) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, RegisterModuleInfoEx, (const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h), hos::Version_7_0_0) + + AMS_SF_DEFINE_INTERFACE(IRoInterface, AMS_RO_I_RO_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/sf.hpp b/libraries/libstratosphere/include/stratosphere/sf.hpp index 333391f71..77568edf1 100644 --- a/libraries/libstratosphere/include/stratosphere/sf.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include diff --git a/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp b/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp index cca03664c..4ee1c3f65 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp @@ -114,7 +114,7 @@ namespace ams::sf::cmif { explicit constexpr ServiceDispatchTable(Entries... entries) : impl::ServiceDispatchTableImpl(entries...) { /* ... */ } }; - #define DEFINE_SERVICE_DISPATCH_TABLE \ + #define AMS_SF_CMIF_IMPL_DEFINE_SERVICE_DISPATCH_TABLE \ template \ static constexpr inline ::ams::sf::cmif::ServiceDispatchTable s_CmifServiceDispatchTable @@ -127,23 +127,21 @@ namespace ams::sf::cmif { } }; - template + template requires sf::IsServiceObject struct ServiceDispatchTraits { - static_assert(std::is_base_of::value, "ServiceObjects must derive from sf::IServiceObject"); - using ProcessHandlerType = decltype(ServiceDispatchMeta::ProcessHandler); static constexpr inline auto DispatchTable = T::template s_CmifServiceDispatchTable; using DispatchTableType = decltype(DispatchTable); - static constexpr ProcessHandlerType ProcessHandlerImpl = ServiceObjectTraits::IsMitmServiceObject ? (&impl::ServiceDispatchTableBase::ProcessMessageForMitm) - : (&impl::ServiceDispatchTableBase::ProcessMessage); + static constexpr ProcessHandlerType ProcessHandlerImpl = sf::IsMitmServiceObject ? (&impl::ServiceDispatchTableBase::ProcessMessageForMitm) + : (&impl::ServiceDispatchTableBase::ProcessMessage); static constexpr inline ServiceDispatchMeta Meta{&DispatchTable, ProcessHandlerImpl}; }; template - NX_CONSTEXPR const ServiceDispatchMeta *GetServiceDispatchMeta() { + constexpr ALWAYS_INLINE const ServiceDispatchMeta *GetServiceDispatchMeta() { return &ServiceDispatchTraits::Meta; } diff --git a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp index fabff0f93..bb0020129 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp @@ -69,12 +69,12 @@ namespace ams::sf::hipc { virtual void CreateSessionObjectHolder(cmif::ServiceObjectHolder *out_obj, std::shared_ptr<::Service> *out_fsrv) const = 0; }; - template> + template class Server : public ServerBase { NON_COPYABLE(Server); NON_MOVEABLE(Server); private: - static constexpr bool IsMitmServer = ServiceObjectTraits::IsMitmServiceObject; + static constexpr bool IsMitmServer = sf::IsMitmServiceObject; public: Server(Handle ph, sm::ServiceName sn, bool m, cmif::ServiceObjectHolder &&sh) : ServerBase(ph, sn, m, std::forward(sh)) { /* ... */ @@ -145,14 +145,14 @@ namespace ams::sf::hipc { void ProcessDeferredSessions(); - template> + template void RegisterServerImpl(Handle port_handle, sm::ServiceName service_name, bool managed, cmif::ServiceObjectHolder &&static_holder) { /* Allocate server memory. */ auto *server = this->AllocateServer(); AMS_ABORT_UNLESS(server != nullptr); - new (server) Server(port_handle, service_name, managed, std::forward(static_holder)); + new (server) Server(port_handle, service_name, managed, std::forward(static_holder)); - if constexpr (!ServiceObjectTraits::IsMitmServiceObject) { + if constexpr (!sf::IsMitmServiceObject) { /* Non-mitm server. */ os::SetWaitableHolderUserData(server, static_cast(UserDataTag::Server)); } else { @@ -163,9 +163,9 @@ namespace ams::sf::hipc { os::LinkWaitableHolder(std::addressof(this->waitable_manager), server); } - template - static constexpr inline std::shared_ptr MakeSharedMitm(std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &client_info) { - return std::make_shared(std::forward>(s), client_info); + template + static constexpr inline std::shared_ptr MakeSharedMitm(std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &client_info) { + return sf::MakeShared(std::forward>(s), client_info); } Result InstallMitmServerImpl(Handle *out_port_handle, sm::ServiceName service_name, MitmQueryFunction query_func); @@ -187,21 +187,18 @@ namespace ams::sf::hipc { os::InitializeWaitableManager(std::addressof(this->waitlist)); } - template> - void RegisterServer(Handle port_handle, std::shared_ptr static_object = nullptr) { - static_assert(!ServiceObjectTraits::IsMitmServiceObject, "RegisterServer requires non-mitm object. Use RegisterMitmServer instead."); + template> requires (sf::IsServiceObject && !sf::IsMitmServiceObject) + void RegisterServer(Handle port_handle, std::shared_ptr static_object = nullptr) { /* Register server. */ cmif::ServiceObjectHolder static_holder; if (static_object != nullptr) { static_holder = cmif::ServiceObjectHolder(std::move(static_object)); } - this->RegisterServerImpl(port_handle, sm::InvalidServiceName, false, std::move(static_holder)); + this->RegisterServerImpl(port_handle, sm::InvalidServiceName, false, std::move(static_holder)); } - template> - Result RegisterServer(sm::ServiceName service_name, size_t max_sessions, std::shared_ptr static_object = nullptr) { - static_assert(!ServiceObjectTraits::IsMitmServiceObject, "RegisterServer requires non-mitm object. Use RegisterMitmServer instead."); - + template> requires (sf::IsServiceObject && !sf::IsMitmServiceObject) + Result RegisterServer(sm::ServiceName service_name, size_t max_sessions, std::shared_ptr static_object = nullptr) { /* Register service. */ Handle port_handle; R_TRY(sm::RegisterService(&port_handle, service_name, max_sessions, false)); @@ -211,19 +208,18 @@ namespace ams::sf::hipc { if (static_object != nullptr) { static_holder = cmif::ServiceObjectHolder(std::move(static_object)); } - this->RegisterServerImpl(port_handle, service_name, true, std::move(static_holder)); + this->RegisterServerImpl(port_handle, service_name, true, std::move(static_holder)); return ResultSuccess(); } - template> + template> + requires (sf::IsMitmServiceObject && sf::IsMitmServiceImpl) Result RegisterMitmServer(sm::ServiceName service_name) { - static_assert(ServiceObjectTraits::IsMitmServiceObject, "RegisterMitmServer requires mitm object. Use RegisterServer instead."); - /* Install mitm service. */ Handle port_handle; R_TRY(this->InstallMitmServerImpl(&port_handle, service_name, &ServiceImpl::ShouldMitm)); - this->RegisterServerImpl(port_handle, service_name, true, cmif::ServiceObjectHolder()); + this->RegisterServerImpl(port_handle, service_name, true, cmif::ServiceObjectHolder()); return ResultSuccess(); } diff --git a/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp index 2247d6de5..aae4a5d2c 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp @@ -368,22 +368,13 @@ namespace ams::sf::impl { size_t out_object_index; }; - template + template struct CommandMetaInfo { - private: - template - static R GetReturnTypeImpl(R(C::*)(A...)); - - template - static C *GetClassTypePointerImpl(R(C::*)(A...)); - - template - static std::tuple::type...> GetArgsImpl(R(C::*)(A...)); public: - using ReturnType = decltype(GetReturnTypeImpl(MemberFunction)); - using ClassTypePointer = decltype(GetClassTypePointerImpl(MemberFunction)); - using ArgsType = decltype(GetArgsImpl(MemberFunction)); - using ClassType = typename std::remove_pointer::type; + using ReturnType = Return; + using ClassType = Class; + using ClassTypePointer = ClassType *; + using ArgsType = std::tuple::type...>; static constexpr bool ReturnsResult = std::is_same::value; static constexpr bool ReturnsVoid = std::is_same::value; @@ -1045,9 +1036,9 @@ namespace ams::sf::impl { return ResultSuccess(); } - template + template constexpr Result InvokeServiceCommandImpl(CmifOutHeader **out_header_ptr, cmif::ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) { - using CommandMeta = CommandMetaInfo; + using CommandMeta = CommandMetaInfo; using ImplProcessorType = HipcCommandProcessor; using BufferArrayType = std::array; using OutHandleHolderType = OutHandleHolder; @@ -1113,7 +1104,7 @@ namespace ams::sf::impl { } if constexpr (CommandMeta::ReturnsResult) { - const auto command_result = std::apply([=](auto&&... args) { return (this_ptr->*ServiceCommandImpl)(args...); }, args_tuple); + const auto command_result = std::apply([=](auto&&... args) { return (this_ptr->*ServiceCommandImpl)(std::forward(args)...); }, args_tuple); if (R_FAILED(command_result)) { cmif::PointerAndSize out_raw_data; ctx.processor->PrepareForErrorReply(ctx, out_raw_data, runtime_metadata); @@ -1121,7 +1112,7 @@ namespace ams::sf::impl { return command_result; } } else { - std::apply([=](auto&&... args) { (this_ptr->*ServiceCommandImpl)(args...); }, args_tuple); + std::apply([=](auto&&... args) { (this_ptr->*ServiceCommandImpl)(std::forward(args)...); }, args_tuple); } } @@ -1148,18 +1139,16 @@ namespace ams::sf::impl { } -namespace ams::sf { +namespace ams::sf::impl { - template - inline static constexpr cmif::ServiceCommandMeta MakeServiceCommandMeta() { + template + consteval inline cmif::ServiceCommandMeta MakeServiceCommandMeta() { return { - .hosver_low = Low, + .hosver_low = Low, .hosver_high = High, - .cmd_id = static_cast(CommandId), - .handler = ::ams::sf::impl::InvokeServiceCommandImpl, + .cmd_id = static_cast(CommandId), + .handler = ::ams::sf::impl::InvokeServiceCommandImpl, }; } } - -#define MAKE_SERVICE_COMMAND_META(Name, ...) ::ams::sf::MakeServiceCommandMeta() diff --git a/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_service_object_macros.hpp b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_service_object_macros.hpp new file mode 100644 index 000000000..2d251f58a --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_service_object_macros.hpp @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include + +namespace ams::sf::impl { + + template + concept ServiceCommandResult = std::same_as<::ams::Result, T> || std::same_as; + + template + concept Invokable = requires (Arguments &&... args) { + { F(std::forward(args)...) }; + }; + + struct FunctionTraits { + public: + template + static std::tuple GetArgsImpl(R(A...)); + }; + + template + using FunctionArgsType = decltype(FunctionTraits::GetArgsImpl(F)); + + template + struct ClassFunctionPointerHelper; + + template + struct ClassFunctionPointerHelper> { + using Type = Return (*)(Class *, Arguments &&...); + }; + + template + using ClassFunctionPointer = typename ClassFunctionPointerHelper::Type; + + template + struct TypeTag{}; + + #define AMS_SF_IMPL_HELPER_FUNCTION_NAME_IMPL(CLASSNAME, FUNCNAME, SUFFIX) \ + __ams_sf_impl_helper_##CLASSNAME##_##FUNCNAME##_##SUFFIX + + #define AMS_SF_IMPL_HELPER_FUNCTION_NAME(CLASSNAME, FUNCNAME) \ + AMS_SF_IMPL_HELPER_FUNCTION_NAME_IMPL(CLASSNAME, FUNCNAME, intf) + + #define AMS_SF_IMPL_HELPER_FUNCTION_ARGS(CLASSNAME, FUNCNAME) \ + ::ams::sf::impl::FunctionArgsType + + #define AMS_SF_IMPL_CONCEPT_HELPER_FUNCTION_NAME(CLASSNAME, FUNCNAME) \ + AMS_SF_IMPL_HELPER_FUNCTION_NAME_IMPL(CLASSNAME, FUNCNAME, intf_for_concept) + + #define AMS_SF_IMPL_DECLARE_HELPER_FUNCTIONS(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + static void AMS_SF_IMPL_HELPER_FUNCTION_NAME(CLASSNAME, NAME) ARGS { __builtin_unreachable(); } \ + template \ + requires std::same_as, AMS_SF_IMPL_HELPER_FUNCTION_ARGS(CLASSNAME, NAME)> \ + static auto AMS_SF_IMPL_CONCEPT_HELPER_FUNCTION_NAME(CLASSNAME, NAME) (T &t, std::tuple a) { \ + return [&](std::index_sequence) { \ + return t.NAME(std::forward::type>(std::get(a))...); \ + }(std::make_index_sequence()); \ + } + + #define AMS_SF_IMPL_DECLARE_HELPERS(CLASSNAME, CMD_MACRO) \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DECLARE_HELPER_FUNCTIONS) + + #define AMS_SF_IMPL_DECLARE_CONCEPT_REQUIREMENT(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + { AMS_SF_IMPL_CONCEPT_HELPER_FUNCTION_NAME(CLASSNAME, NAME) (impl, std::declval()) } -> ::ams::sf::impl::ServiceCommandResult; + + #define AMS_SF_IMPL_DEFINE_CONCEPT(CLASSNAME, CMD_MACRO) \ + template \ + concept Is##CLASSNAME = requires (Impl &impl) { \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DECLARE_CONCEPT_REQUIREMENT) \ + }; + + #define AMS_SF_IMPL_FUNCTION_POINTER_TYPE(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + ::ams::sf::impl::ClassFunctionPointer + + #define AMS_SF_IMPL_DECLARE_FUNCTION_POINTER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + AMS_SF_IMPL_FUNCTION_POINTER_TYPE(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) NAME; + + #define AMS_SF_IMPL_DECLARE_INTERFACE_FUNCTION(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + template \ + requires std::same_as, AMS_SF_IMPL_HELPER_FUNCTION_ARGS(CLASSNAME, NAME)> \ + RETURN Invoke##NAME##ByCommandTable (Arguments &&... args) { \ + return this->cmd_table->NAME(this, std::forward(args)...); \ + } \ + template \ + requires (::ams::sf::impl::Invokable && \ + std::same_as, AMS_SF_IMPL_HELPER_FUNCTION_ARGS(CLASSNAME, NAME)>) \ + ALWAYS_INLINE RETURN NAME (Arguments &&... args) { \ + return this->Invoke##NAME##ByCommandTable(std::forward(args)...); \ + } \ + template \ + requires (::ams::sf::impl::Invokable && \ + !std::same_as, AMS_SF_IMPL_HELPER_FUNCTION_ARGS(CLASSNAME, NAME)>) \ + ALWAYS_INLINE RETURN NAME (Arguments &&... args) { \ + return [this] ALWAYS_INLINE_LAMBDA (::ams::sf::impl::TypeTag>, PassedArguments &&...args_) -> RETURN { \ + return this->template NAME(std::forward(args_)...); \ + }(::ams::sf::impl::TypeTag{}, std::forward(args)...); \ + } + + #define AMS_SF_IMPL_DECLARE_INTERFACE_FUNCTION_INVOKER_HOLDER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + template \ + requires std::same_as, AMS_SF_IMPL_HELPER_FUNCTION_ARGS(CLASSNAME, NAME)> \ + static RETURN NAME##Invoker (CLASSNAME *_this, Arguments &&... args) { \ + return static_cast(_this)->NAME(std::forward(args)...); \ + } + + #define AMS_SF_IMPL_DECLARE_INTERFACE_FUNCTION_INVOKER_POINTER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + template \ + requires std::same_as, AMS_SF_IMPL_HELPER_FUNCTION_ARGS(CLASSNAME, NAME)> \ + static RETURN NAME##Invoker (CLASSNAME *_this, Arguments &&... args) { \ + return static_cast(_this)->NAME(std::forward(args)...); \ + } + + #define AMS_SF_IMPL_DECLARE_INTERFACE_FUNCTION_IMPL(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + template \ + requires (std::same_as, AMS_SF_IMPL_HELPER_FUNCTION_ARGS(CLASSNAME, NAME)> && \ + std::same_as()...))>) \ + RETURN NAME (Arguments &&... args) { \ + return this->impl.NAME(std::forward(args)...); \ + } + + #define AMS_SF_IMPL_DECLARE_INTERFACE_FUNCTION_IMPL_PTR(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + template \ + requires (std::same_as, AMS_SF_IMPL_HELPER_FUNCTION_ARGS(CLASSNAME, NAME)> && \ + std::same_asNAME(std::declval()...))>) \ + RETURN NAME (Arguments &&... args) { \ + return this->impl->NAME(std::forward(args)...); \ + } + + #define AMS_SF_IMPL_DEFINE_INTERFACE_IMPL_FUNCTION_POINTER_HOLDER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + template struct NAME##FunctionPointerHolder; \ + \ + template \ + requires std::same_as, AMS_SF_IMPL_HELPER_FUNCTION_ARGS(CLASSNAME, NAME)> \ + struct NAME##FunctionPointerHolder> { \ + static constexpr auto Value = static_cast(&NAME##Invoker); \ + }; + + #define AMS_SF_IMPL_DEFINE_INTERFACE_SERVICE_COMMAND_META_HOLDER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + template struct NAME##ServiceCommandMetaHolder; \ + \ + template \ + requires std::same_as, AMS_SF_IMPL_HELPER_FUNCTION_ARGS(CLASSNAME, NAME)> \ + struct NAME##ServiceCommandMetaHolder> { \ + static constexpr auto Value = ::ams::sf::impl::MakeServiceCommandMeta, RETURN, CLASSNAME, Arguments...>(); \ + }; + + #define AMS_SF_IMPL_DEFINE_INTERFACE_COMMAND_POINTER_TABLE_MEMBER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + .NAME = NAME##FunctionPointerHolder::Value, + + #define AMS_SF_IMPL_DEFINE_CMIF_SERVICE_COMMAND_META_TABLE_ENTRY(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + NAME##ServiceCommandMetaHolder::Value, + + template + struct Print; + + #define AMS_SF_IMPL_DEFINE_CLASS(BASECLASS, CLASSNAME, CMD_MACRO) \ + class CLASSNAME : public BASECLASS { \ + NON_COPYABLE(CLASSNAME); \ + NON_MOVEABLE(CLASSNAME); \ + private: \ + struct CommandPointerTable { \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DECLARE_FUNCTION_POINTER) \ + }; \ + private: \ + const CommandPointerTable * const cmd_table; \ + private: \ + CLASSNAME() = delete; \ + protected: \ + constexpr CLASSNAME(const CommandPointerTable *ct) \ + : cmd_table(ct) { /* ... */ } \ + virtual ~CLASSNAME() { /* ... */ } \ + public: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DECLARE_INTERFACE_FUNCTION) \ + private: \ + template \ + requires ((std::same_as && !std::same_as&& Is##CLASSNAME) && \ + (::ams::sf::IsMitmServiceObject == ::ams::sf::IsMitmServiceImpl)) \ + struct ImplGenerator { \ + public: \ + class ImplHolder : public S { \ + private: \ + T impl; \ + public: \ + template requires std::constructible_from \ + constexpr ImplHolder(Args &&... args) \ + : S(std::addressof(CommandPointerTableImpl)), impl(std::forward(args)...) \ + { \ + /* ... */ \ + } \ + ALWAYS_INLINE T &GetImpl() { return this->impl; } \ + ALWAYS_INLINE const T &GetImpl() const { return this->impl; } \ + \ + template requires ::ams::sf::IsMitmServiceObject && std::same_as \ + static ALWAYS_INLINE bool ShouldMitm(os::ProcessId p, ncm::ProgramId r) { return T::ShouldMitm(p, r); } \ + private: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DECLARE_INTERFACE_FUNCTION_INVOKER_HOLDER) \ + public: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DECLARE_INTERFACE_FUNCTION_IMPL) \ + private: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DEFINE_INTERFACE_IMPL_FUNCTION_POINTER_HOLDER) \ + public: \ + static constexpr CommandPointerTable CommandPointerTableImpl = { \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DEFINE_INTERFACE_COMMAND_POINTER_TABLE_MEMBER) \ + }; \ + }; \ + static_assert(Is##CLASSNAME); \ + \ + class ImplPointer : public S { \ + private: \ + T *impl; \ + public: \ + constexpr ImplPointer(T *t) \ + : S(std::addressof(CommandPointerTableImpl)), impl(t) \ + { \ + /* ... */ \ + } \ + ALWAYS_INLINE T &GetImpl() { return *this->impl; } \ + ALWAYS_INLINE const T &GetImpl() const { return *this->impl; } \ + private: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DECLARE_INTERFACE_FUNCTION_INVOKER_POINTER) \ + public: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DECLARE_INTERFACE_FUNCTION_IMPL_PTR) \ + private: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DEFINE_INTERFACE_IMPL_FUNCTION_POINTER_HOLDER) \ + public: \ + static constexpr CommandPointerTable CommandPointerTableImpl = { \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DEFINE_INTERFACE_COMMAND_POINTER_TABLE_MEMBER) \ + }; \ + }; \ + static_assert(Is##CLASSNAME); \ + }; \ + private: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DEFINE_INTERFACE_SERVICE_COMMAND_META_HOLDER) \ + public: \ + template requires (!std::same_as&& Is##CLASSNAME) \ + using ImplHolder = typename ImplGenerator::ImplHolder; \ + \ + template requires (!std::same_as&& Is##CLASSNAME) \ + using ImplPointer = typename ImplGenerator::ImplPointer; \ + \ + AMS_SF_CMIF_IMPL_DEFINE_SERVICE_DISPATCH_TABLE { \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DEFINE_CMIF_SERVICE_COMMAND_META_TABLE_ENTRY) \ + }; \ + }; + + #define AMS_SF_METHOD_INFO_6(CLASSNAME, HANDLER, CMD_ID, RETURN, NAME, ARGS) \ + HANDLER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, hos::Version_Min, hos::Version_Max) + + #define AMS_SF_METHOD_INFO_7(CLASSNAME, HANDLER, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN) \ + HANDLER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, hos::Version_Max) + + #define AMS_SF_METHOD_INFO_8(CLASSNAME, HANDLER, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + HANDLER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) + + #define AMS_SF_METHOD_INFO_X(_, _0, _1, _2, _3, _4, _5, _6, _7, FUNC, ...) FUNC + + #define AMS_SF_METHOD_INFO(...) \ + AMS_SF_METHOD_INFO_X(, ## __VA_ARGS__, AMS_SF_METHOD_INFO_8(__VA_ARGS__), AMS_SF_METHOD_INFO_7(__VA_ARGS__), AMS_SF_METHOD_INFO_6(__VA_ARGS__)) + + #define AMS_SF_DEFINE_INTERFACE(CLASSNAME, CMD_MACRO) \ + AMS_SF_IMPL_DECLARE_HELPERS(CLASSNAME,CMD_MACRO) \ + AMS_SF_IMPL_DEFINE_CONCEPT(CLASSNAME, CMD_MACRO) \ + AMS_SF_IMPL_DEFINE_CLASS( ::ams::sf::IServiceObject, CLASSNAME, CMD_MACRO) \ + static_assert(Is##CLASSNAME); + + #define AMS_SF_DEFINE_MITM_INTERFACE(CLASSNAME, CMD_MACRO) \ + AMS_SF_IMPL_DECLARE_HELPERS(CLASSNAME,CMD_MACRO) \ + AMS_SF_IMPL_DEFINE_CONCEPT(CLASSNAME, CMD_MACRO) \ + AMS_SF_IMPL_DEFINE_CLASS(::ams::sf::IMitmServiceObject, CLASSNAME, CMD_MACRO) \ + static_assert(Is##CLASSNAME); + + #define AMS_SF_IMPL_DECLARE_INTERFACE_METHODS(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, VERSION_MIN, VERSION_MAX) \ + RETURN NAME ARGS; + + #define AMS_SF_DECLARE_INTERFACE_METHODS(CMD_MACRO) \ + CMD_MACRO(_, AMS_SF_IMPL_DECLARE_INTERFACE_METHODS) + +} \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_service_object.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_service_object.hpp index 70b93ec6f..7406be541 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/sf_service_object.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_service_object.hpp @@ -25,38 +25,44 @@ namespace ams::sf { virtual ~IServiceObject() { /* ... */ } }; + template + concept IsServiceObject = std::derived_from; + class IMitmServiceObject : public IServiceObject { + public: + virtual ~IMitmServiceObject() { /* ... */ } + }; + + class MitmServiceImplBase { protected: std::shared_ptr<::Service> forward_service; sm::MitmProcessInfo client_info; public: - IMitmServiceObject(std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &c) : forward_service(std::move(s)), client_info(c) { /* ... */ } - - virtual ~IMitmServiceObject() { /* ... */ } - - static bool ShouldMitm(os::ProcessId process_id, ncm::ProgramId program_id); + MitmServiceImplBase(std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &c) : forward_service(std::move(s)), client_info(c) { /* ... */ } }; - /* Utility. */ - #define SF_MITM_SERVICE_OBJECT_CTOR(cls) cls(std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &c) : ::ams::sf::IMitmServiceObject(std::forward>(s), c) - template - struct ServiceObjectTraits { - static_assert(std::is_base_of::value, "ServiceObjectTraits requires ServiceObject"); + concept IsMitmServiceObject = IsServiceObject && std::derived_from; - static constexpr bool IsMitmServiceObject = std::is_base_of::value; - - struct SharedPointerHelper { - - static constexpr void EmptyDelete(T *) { /* Empty deleter, for fake shared pointer. */ } - - static constexpr std::shared_ptr GetEmptyDeleteSharedPointer(T *srv_obj) { - return std::shared_ptr(srv_obj, EmptyDelete); - } - - }; + template + concept IsMitmServiceImpl = requires (std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &c) { + { T(std::forward>(s), c) }; + { T::ShouldMitm(c) } -> std::same_as; }; + template requires std::constructible_from + constexpr ALWAYS_INLINE std::shared_ptr> MakeShared(Arguments &&... args) { + return std::make_shared>(std::forward(args)...); + } + template + constexpr ALWAYS_INLINE std::shared_ptr> GetSharedPointerTo(Impl *impl) { + return std::make_shared>(impl); + } + + template + constexpr ALWAYS_INLINE std::shared_ptr> GetSharedPointerTo(Impl &impl) { + return GetSharedPointerTo(std::addressof(impl)); + } } \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/sm.hpp b/libraries/libstratosphere/include/stratosphere/sm.hpp index d5c4456d1..98e3f83ac 100644 --- a/libraries/libstratosphere/include/stratosphere/sm.hpp +++ b/libraries/libstratosphere/include/stratosphere/sm.hpp @@ -16,9 +16,13 @@ #pragma once -#include "sm/sm_types.hpp" -#include "sm/sm_api.hpp" -#include "sm/sm_mitm_api.hpp" -#include "sm/sm_scoped_holder.hpp" +#include +#include +#include +#include -#include "sm/sm_manager_api.hpp" +#include + +#include +#include +#include diff --git a/libraries/libstratosphere/include/stratosphere/sm/impl/sm_debug_monitor_interface.hpp b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_debug_monitor_interface.hpp new file mode 100644 index 000000000..af79293c8 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_debug_monitor_interface.hpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::sm::impl { + + #define AMS_SM_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereGetRecord, (sf::Out record, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65001, void, AtmosphereListRecords, (const sf::OutArray &records, sf::Out out_count, u64 offset)) \ + AMS_SF_METHOD_INFO(C, H, 65002, void, AtmosphereGetRecordSize, (sf::Out record_size)) + + AMS_SF_DEFINE_INTERFACE(IDebugMonitorInterface, AMS_SM_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/sm/impl/sm_manager_interface.hpp b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_manager_interface.hpp new file mode 100644 index 000000000..6037bafe0 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_manager_interface.hpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::sm::impl { + + #define AMS_SM_I_MANAGER_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, RegisterProcess, (os::ProcessId process_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, UnregisterProcess, (os::ProcessId process_id)) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereEndInitDefers, ()) \ + AMS_SF_METHOD_INFO(C, H, 65001, void, AtmosphereHasMitm, (sf::Out out, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmosphereRegisterProcess, (os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus override_status, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac)) + + AMS_SF_DEFINE_INTERFACE(IManagerInterface, AMS_SM_I_MANAGER_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/sm/impl/sm_user_interface.hpp b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_user_interface.hpp new file mode 100644 index 000000000..843162857 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_user_interface.hpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::sm::impl { + + #define AMS_SM_I_USER_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, RegisterClient, (const sf::ClientProcessId &client_process_id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetServiceHandle, (sf::OutMoveHandle out_h, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, RegisterService, (sf::OutMoveHandle out_h, ServiceName service, u32 max_sessions, bool is_light)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, UnregisterService, (ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereInstallMitm, (sf::OutMoveHandle srv_h, sf::OutMoveHandle qry_h, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereUninstallMitm, (ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65003, Result, AtmosphereAcknowledgeMitmSession, (sf::Out client_info, sf::OutMoveHandle fwd_h, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65004, Result, AtmosphereHasMitm, (sf::Out out, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65005, Result, AtmosphereWaitMitm, (ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65006, Result, AtmosphereDeclareFutureMitm, (ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65100, Result, AtmosphereHasService, (sf::Out out, ServiceName service)) \ + AMS_SF_METHOD_INFO(C, H, 65101, Result, AtmosphereWaitService, (ServiceName service)) + + AMS_SF_DEFINE_INTERFACE(IUserInterface, AMS_SM_I_USER_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/spl.hpp b/libraries/libstratosphere/include/stratosphere/spl.hpp index d8b7518f6..e9ec412fc 100644 --- a/libraries/libstratosphere/include/stratosphere/spl.hpp +++ b/libraries/libstratosphere/include/stratosphere/spl.hpp @@ -16,6 +16,15 @@ #pragma once -#include "spl/spl_types.hpp" -#include "spl/spl_api.hpp" -#include "spl/smc/spl_smc.hpp" \ No newline at end of file +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_crypto_interface.hpp b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_crypto_interface.hpp new file mode 100644 index 000000000..d3e68b95c --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_crypto_interface.hpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include +#include + +namespace ams::spl::impl { + + #define AMS_SPL_I_CRYPTO_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SPL_I_GENERAL_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GenerateAesKek, (sf::Out out_access_key, KeySource key_source, u32 generation, u32 option)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, LoadAesKey, (s32 keyslot, AccessKey access_key, KeySource key_source)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GenerateAesKey, (sf::Out out_key, AccessKey access_key, KeySource key_source)) \ + AMS_SF_METHOD_INFO(C, H, 14, Result, DecryptAesKey, (sf::Out out_key, KeySource key_source, u32 generation, u32 option)) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, ComputeCtr, (const sf::OutNonSecureBuffer &out_buf, s32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr)) \ + AMS_SF_METHOD_INFO(C, H, 16, Result, ComputeCmac, (sf::Out out_cmac, s32 keyslot, const sf::InPointerBuffer &in_buf)) \ + AMS_SF_METHOD_INFO(C, H, 21, Result, AllocateAesKeySlot, (sf::Out out_keyslot)) \ + AMS_SF_METHOD_INFO(C, H, 22, Result, DeallocateAesKeySlot, (s32 keyslot)) \ + AMS_SF_METHOD_INFO(C, H, 23, Result, GetAesKeySlotAvailableEvent, (sf::OutCopyHandle out_hnd)) + + AMS_SF_DEFINE_INTERFACE(ICryptoInterface, AMS_SPL_I_CRYPTO_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_deprecated_general_interface.hpp b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_deprecated_general_interface.hpp new file mode 100644 index 000000000..e6d85f06e --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_deprecated_general_interface.hpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::spl::impl { + + #define AMS_SPL_I_DEPRECATED_GENERAL_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetConfig, (sf::Out out, u32 which)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, ModularExponentiate, (const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GenerateAesKek, (sf::Out out_access_key, KeySource key_source, u32 generation, u32 option)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, LoadAesKey, (s32 keyslot, AccessKey access_key, KeySource key_source)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GenerateAesKey, (sf::Out out_key, AccessKey access_key, KeySource key_source)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, SetConfig, (u32 which, u64 value)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, GenerateRandomBytes, (const sf::OutPointerBuffer &out)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, DecryptAndStoreGcKey, (const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option)) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, DecryptGcMessage, (sf::Out out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest)) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, IsDevelopment, (sf::Out is_dev)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, GenerateSpecificAesKey, (sf::Out out_key, KeySource key_source, u32 generation, u32 which)) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, DecryptDeviceUniqueData, (const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option)) \ + AMS_SF_METHOD_INFO(C, H, 14, Result, DecryptAesKey, (sf::Out out_key, KeySource key_source, u32 generation, u32 option)) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, ComputeCtrDeprecated, (const sf::OutBuffer &out_buf, s32 keyslot, const sf::InBuffer &in_buf, IvCtr iv_ctr), hos::Version_1_0_0, hos::Version_1_0_0) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, ComputeCtr, (const sf::OutNonSecureBuffer &out_buf, s32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 16, Result, ComputeCmac, (sf::Out out_cmac, s32 keyslot, const sf::InPointerBuffer &in_buf)) \ + AMS_SF_METHOD_INFO(C, H, 17, Result, LoadEsDeviceKey, (const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option)) \ + AMS_SF_METHOD_INFO(C, H, 18, Result, PrepareEsTitleKeyDeprecated, (sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest), hos::Version_1_0_0, hos::Version_2_3_0) \ + AMS_SF_METHOD_INFO(C, H, 18, Result, PrepareEsTitleKey, (sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 19, Result, LoadPreparedAesKey, (s32 keyslot, AccessKey access_key)) \ + AMS_SF_METHOD_INFO(C, H, 20, Result, PrepareCommonEsTitleKeyDeprecated, (sf::Out out_access_key, KeySource key_source), hos::Version_2_0_0, hos::Version_2_3_0) \ + AMS_SF_METHOD_INFO(C, H, 20, Result, PrepareCommonEsTitleKey, (sf::Out out_access_key, KeySource key_source, u32 generation), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 22, Result, DeallocateAesKeySlot, (s32 keyslot)) \ + AMS_SF_METHOD_INFO(C, H, 23, Result, GetAesKeySlotAvailableEvent, (sf::OutCopyHandle out_hnd)) \ + AMS_SF_METHOD_INFO(C, H, 24, Result, SetBootReason, (spl::BootReasonValue boot_reason), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 25, Result, GetBootReason, (sf::Out out), hos::Version_3_0_0) + + AMS_SF_DEFINE_INTERFACE(IDeprecatedGeneralInterface, AMS_SPL_I_DEPRECATED_GENERAL_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_device_unique_data_interface.hpp b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_device_unique_data_interface.hpp new file mode 100644 index 000000000..307f238ce --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_device_unique_data_interface.hpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include +#include + +namespace ams::spl::impl { + + #define AMS_SPL_I_DEVICE_UNIQUE_DATA_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SPL_I_CRYPTO_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, DecryptDeviceUniqueDataDeprecated, (const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option), hos::Version_Min, hos::Version_4_1_0) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, DecryptDeviceUniqueData, (const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source), hos::Version_5_0_0) + + AMS_SF_DEFINE_INTERFACE(IDeviceUniqueDataInterface, AMS_SPL_I_DEVICE_UNIQUE_DATA_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_es_interface.hpp b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_es_interface.hpp new file mode 100644 index 000000000..e29ddc743 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_es_interface.hpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include +#include + +namespace ams::spl::impl { + + #define AMS_SPL_I_ES_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SPL_I_DEVICE_UNIQUE_DATA_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 17, Result, LoadEsDeviceKeyDeprecated, (const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option), hos::Version_Min, hos::Version_4_1_0) \ + AMS_SF_METHOD_INFO(C, H, 17, Result, LoadEsDeviceKey, (const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 18, Result, PrepareEsTitleKey, (sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation)) \ + AMS_SF_METHOD_INFO(C, H, 20, Result, PrepareCommonEsTitleKey, (sf::Out out_access_key, KeySource key_source, u32 generation), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 28, Result, DecryptAndStoreDrmDeviceCertKey, (const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 29, Result, ModularExponentiateWithDrmDeviceCertKey, (const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 31, Result, PrepareEsArchiveKey, (sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation), hos::Version_6_0_0) \ + AMS_SF_METHOD_INFO(C, H, 32, Result, LoadPreparedAesKey, (s32 keyslot, AccessKey access_key), hos::Version_6_0_0) + + AMS_SF_DEFINE_INTERFACE(IEsInterface, AMS_SPL_I_ES_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_fs_interface.hpp b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_fs_interface.hpp new file mode 100644 index 000000000..d487280ec --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_fs_interface.hpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include +#include + +namespace ams::spl::impl { + + #define AMS_SPL_I_FS_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SPL_I_CRYPTO_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, DecryptAndStoreGcKeyDeprecated, (const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option), hos::Version_Min, hos::Version_4_1_0) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, DecryptAndStoreGcKey, (const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, DecryptGcMessage, (sf::Out out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, GenerateSpecificAesKey, (sf::Out out_key, KeySource key_source, u32 generation, u32 which)) \ + AMS_SF_METHOD_INFO(C, H, 19, Result, LoadPreparedAesKey, (s32 keyslot, AccessKey access_key)) \ + AMS_SF_METHOD_INFO(C, H, 31, Result, GetPackage2Hash, (const sf::OutPointerBuffer &dst), hos::Version_5_0_0) + + AMS_SF_DEFINE_INTERFACE(IFsInterface, AMS_SPL_I_FS_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_general_interface.hpp b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_general_interface.hpp new file mode 100644 index 000000000..28f596b94 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_general_interface.hpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::spl::impl { + + #define AMS_SPL_I_GENERAL_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetConfig, (sf::Out out, u32 which)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, ModularExponentiate, (const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, SetConfig, (u32 which, u64 value)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, GenerateRandomBytes, (const sf::OutPointerBuffer &out)) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, IsDevelopment, (sf::Out is_dev)) \ + AMS_SF_METHOD_INFO(C, H, 24, Result, SetBootReason, (spl::BootReasonValue boot_reason), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 25, Result, GetBootReason, (sf::Out out), hos::Version_3_0_0) + + AMS_SF_DEFINE_INTERFACE(IGeneralInterface, AMS_SPL_I_GENERAL_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_manu_interface.hpp b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_manu_interface.hpp new file mode 100644 index 000000000..5e9695dde --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_manu_interface.hpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include +#include + +namespace ams::spl::impl { + + #define AMS_SPL_I_MANU_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SPL_I_DEVICE_UNIQUE_DATA_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 30, Result, ReencryptDeviceUniqueData, (const sf::OutPointerBuffer &out, const sf::InPointerBuffer &src, AccessKey access_key_dec, KeySource source_dec, AccessKey access_key_enc, KeySource source_enc, u32 option)) \ + + AMS_SF_DEFINE_INTERFACE(IManuInterface, AMS_SPL_I_MANU_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_random_interface.hpp b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_random_interface.hpp new file mode 100644 index 000000000..6181ccc30 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_random_interface.hpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include + +namespace ams::spl::impl { + + #define AMS_SPL_I_RANDOM_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GenerateRandomBytes, (const sf::OutBuffer &out)) + + AMS_SF_DEFINE_INTERFACE(IRandomInterface, AMS_SPL_I_RANDOM_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_ssl_interface.hpp b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_ssl_interface.hpp new file mode 100644 index 000000000..3df104ef3 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_ssl_interface.hpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include +#include + +namespace ams::spl::impl { + + #define AMS_SPL_I_SSL_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SPL_I_DEVICE_UNIQUE_DATA_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 26, Result, DecryptAndStoreSslClientCertKey, (const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 27, Result, ModularExponentiateWithSslClientCertKey, (const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod), hos::Version_5_0_0) + + AMS_SF_DEFINE_INTERFACE(ISslInterface, AMS_SPL_I_SSL_INTERFACE_INTERFACE_INFO) + +} diff --git a/libraries/libstratosphere/include/stratosphere/spl/smc/spl_smc.hpp b/libraries/libstratosphere/include/stratosphere/spl/smc/spl_smc.hpp index 3d83ac749..38a98d5df 100644 --- a/libraries/libstratosphere/include/stratosphere/spl/smc/spl_smc.hpp +++ b/libraries/libstratosphere/include/stratosphere/spl/smc/spl_smc.hpp @@ -20,54 +20,47 @@ namespace ams::spl::smc { /* Helpers for converting arguments. */ - inline u32 GetCryptAesMode(CipherMode mode, u32 keyslot) { + inline u32 GetComputeAesMode(CipherMode mode, u32 keyslot) { return static_cast((static_cast(mode) << 4) | (keyslot & 7)); } - inline u32 GetUnwrapEsKeyOption(EsKeyType type, u32 generation) { + inline u32 GetPrepareEsDeviceUniqueKeyOption(EsCommonKeyType type, u32 generation) { return static_cast((static_cast(type) << 6) | (generation & 0x3F)); } /* Functions. */ - Result SetConfig(SplConfigItem which, const u64 *value, size_t num_qwords); - Result GetConfig(u64 *out, size_t num_qwords, SplConfigItem which); - Result CheckStatus(Result *out, AsyncOperationKey op); - Result GetResult(Result *out, void *out_buf, size_t out_buf_size, AsyncOperationKey op); - Result ExpMod(AsyncOperationKey *out_op, const void *base, const void *exp, size_t exp_size, const void *mod); + Result SetConfig(spl::ConfigItem which, const u64 *value, size_t num_qwords); + Result GetConfig(u64 *out, size_t num_qwords, spl::ConfigItem which); + Result GetResult(Result *out, AsyncOperationKey op); + Result GetResultData(Result *out, void *out_buf, size_t out_buf_size, AsyncOperationKey op); + Result ModularExponentiate(AsyncOperationKey *out_op, const void *base, const void *exp, size_t exp_size, const void *mod); Result GenerateRandomBytes(void *out, size_t size); Result GenerateAesKek(AccessKey *out, const KeySource &source, u32 generation, u32 option); Result LoadAesKey(u32 keyslot, const AccessKey &access_key, const KeySource &source); - Result CryptAes(AsyncOperationKey *out_op, u32 mode, const IvCtr &iv_ctr, u32 dst_addr, u32 src_addr, size_t size); + Result ComputeAes(AsyncOperationKey *out_op, u32 mode, const IvCtr &iv_ctr, u32 dst_addr, u32 src_addr, size_t size); Result GenerateSpecificAesKey(AesKey *out_key, const KeySource &source, u32 generation, u32 which); Result ComputeCmac(Cmac *out_mac, u32 keyslot, const void *data, size_t size); - Result ReEncryptRsaPrivateKey(void *data, size_t size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option); - Result DecryptOrImportRsaPrivateKey(void *data, size_t size, const AccessKey &access_key, const KeySource &source, DecryptOrImportMode mode); - Result SecureExpMod(AsyncOperationKey *out_op, const void *base, const void *mod, SecureExpModMode mode); - Result UnwrapTitleKey(AsyncOperationKey *out_op, const void *base, const void *mod, const void *label_digest, size_t label_digest_size, u32 option); - Result LoadTitleKey(u32 keyslot, const AccessKey &access_key); - Result UnwrapCommonTitleKey(AccessKey *out, const KeySource &source, u32 generation); + Result ReencryptDeviceUniqueData(void *data, size_t size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option); + Result DecryptDeviceUniqueData(void *data, size_t size, const AccessKey &access_key, const KeySource &source, DeviceUniqueDataMode mode); + Result ModularExponentiateWithStorageKey(AsyncOperationKey *out_op, const void *base, const void *mod, ModularExponentiateWithStorageKeyMode mode); + Result PrepareEsDeviceUniqueKey(AsyncOperationKey *out_op, const void *base, const void *mod, const void *label_digest, size_t label_digest_size, u32 option); + Result LoadPreparedAesKey(u32 keyslot, const AccessKey &access_key); + Result PrepareCommonEsTitleKey(AccessKey *out, const KeySource &source, u32 generation); /* Deprecated functions. */ - Result ImportEsKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option); - Result DecryptRsaPrivateKey(size_t *out_size, void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option); - Result ImportSecureExpModKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option); + Result LoadEsDeviceKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option); + Result DecryptDeviceUniqueData(size_t *out_size, void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option); + Result DecryptAndStoreGcKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option); /* Atmosphere functions. */ Result AtmosphereCopyToIram(uintptr_t iram_dst, const void *dram_src, size_t size); Result AtmosphereCopyFromIram(void *dram_dst, uintptr_t iram_src, size_t size); Result AtmosphereReadWriteRegister(uint64_t address, uint32_t mask, uint32_t value, uint32_t *out_value); - Result AtmosphereWriteAddress(void *dst, const void *src, size_t size); Result AtmosphereGetEmummcConfig(void *out_config, void *out_paths, u32 storage_id); /* Helpers. */ - inline Result SetConfig(SplConfigItem which, const u64 value) { + inline Result SetConfig(spl::ConfigItem which, const u64 value) { return SetConfig(which, &value, 1); } - template - inline Result AtmosphereWriteAddress(void *dst, const T value) { - static_assert(std::is_integral::value && sizeof(T) <= 8 && (sizeof(T) & (sizeof(T) - 1)) == 0, "AtmosphereWriteAddress requires integral type."); - return AtmosphereWriteAddress(dst, &value, sizeof(T)); - } - } diff --git a/libraries/libstratosphere/include/stratosphere/spl/spl_types.hpp b/libraries/libstratosphere/include/stratosphere/spl/spl_types.hpp index b02bf1fd8..21a7ba25c 100644 --- a/libraries/libstratosphere/include/stratosphere/spl/spl_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/spl/spl_types.hpp @@ -22,35 +22,34 @@ namespace ams::spl { namespace smc { enum class FunctionId : u32 { - SetConfig = 0xC3000401, - GetConfig = 0xC3000002, - CheckStatus = 0xC3000003, - GetResult = 0xC3000404, - ExpMod = 0xC3000E05, - GenerateRandomBytes = 0xC3000006, - GenerateAesKek = 0xC3000007, - LoadAesKey = 0xC3000008, - CryptAes = 0xC3000009, - GenerateSpecificAesKey = 0xC300000A, - ComputeCmac = 0xC300040B, - ReEncryptRsaPrivateKey = 0xC300D60C, - DecryptOrImportRsaPrivateKey = 0xC300100D, + SetConfig = 0xC3000401, + GetConfig = 0xC3000002, + GetResult = 0xC3000003, + GetResultData = 0xC3000404, + ModularExponentiate = 0xC3000E05, + GenerateRandomBytes = 0xC3000006, + GenerateAesKek = 0xC3000007, + LoadAesKey = 0xC3000008, + ComputeAes = 0xC3000009, + GenerateSpecificAesKey = 0xC300000A, + ComputeCmac = 0xC300040B, + ReencryptDeviceUniqueData = 0xC300D60C, + DecryptDeviceUniqueData = 0xC300100D, - SecureExpMod = 0xC300060F, - UnwrapTitleKey = 0xC3000610, - LoadTitleKey = 0xC3000011, - UnwrapCommonTitleKey = 0xC3000012, + ModularExponentiateWithStorageKey = 0xC300060F, + PrepareEsDeviceUniqueKey = 0xC3000610, + LoadPreparedAesKey = 0xC3000011, + PrepareCommonEsTitleKey = 0xC3000012, /* Deprecated functions. */ - ImportEsKey = 0xC300100C, - DecryptRsaPrivateKey = 0xC300100D, - ImportSecureExpModKey = 0xC300100E, + LoadEsDeviceKey = 0xC300100C, + DecryptAndStoreGcKey = 0xC300100E, /* Atmosphere functions. */ - AtmosphereIramCopy = 0xF0000201, - AtmosphereReadWriteRegister = 0xF0000002, - AtmosphereWriteAddress = 0xF0000003, - AtmosphereGetEmummcConfig = 0xF0000404, + AtmosphereIramCopy = 0xF0000201, + AtmosphereReadWriteRegister = 0xF0000002, + + AtmosphereGetEmummcConfig = 0xF0000404, }; enum class Result { @@ -61,6 +60,7 @@ namespace ams::spl { NoAsyncOperation = 4, InvalidAsyncOperation = 5, NotPermitted = 6, + NotInitialized = 7, }; constexpr inline ::ams::Result ConvertResult(Result smc_result) { @@ -69,11 +69,10 @@ namespace ams::spl { /* Convert to the list of known SecureMonitorErrors. */ const auto converted = R_MAKE_NAMESPACE_RESULT(::ams::spl, static_cast(smc_result)); - if (spl::ResultSecureMonitorError::Includes(converted)) { - return converted; - } + R_UNLESS(spl::ResultSecureMonitorError::Includes(converted), spl::ResultUnknownSecureMonitorError()); - return spl::ResultUnknownSecureMonitorError(); + /* Return the error. */ + return converted; } enum class CipherMode { @@ -82,23 +81,23 @@ namespace ams::spl { Ctr = 2, }; - enum class DecryptOrImportMode { - DecryptRsaPrivateKey = 0, - ImportLotusKey = 1, - ImportEsKey = 2, - ImportSslKey = 3, - ImportDrmKey = 4, + enum class DeviceUniqueDataMode { + DecryptDeviceUniqueData = 0, + DecryptAndStoreGcKey = 1, + DecryptAndStoreEsDeviceKey = 2, + DecryptAndStoreSslKey = 3, + DecryptAndStoreDrmDeviceCertKey = 4, }; - enum class SecureExpModMode { - Lotus = 0, - Ssl = 1, - Drm = 2, + enum class ModularExponentiateWithStorageKeyMode { + Gc = 0, + Ssl = 1, + DrmDeviceCert = 2, }; - enum class EsKeyType { - TitleKey = 0, - ElicenseKey = 1, + enum class EsCommonKeyType { + TitleKey = 0, + ArchiveKey = 1, }; struct AsyncOperationKey { @@ -196,23 +195,23 @@ namespace ams::spl { enum class ConfigItem : u32 { /* Standard config items. */ - DisableProgramVerification = 1, - DramId = 2, - SecurityEngineIrqNumber = 3, - FuseVersion = 4, - HardwareType = 5, - HardwareState = 6, - IsRecoveryBoot = 7, - DeviceId = 8, - BootReason = 9, - MemoryMode = 10, - IsDevelopmentFunctionEnabled = 11, - KernelConfiguration = 12, - IsChargerHiZModeEnabled = 13, - IsQuest = 14, - RegulatorType = 15, - DeviceUniqueKeyGeneration = 16, - Package2Hash = 17, + DisableProgramVerification = 1, + DramId = 2, + SecurityEngineInterruptNumber = 3, + FuseVersion = 4, + HardwareType = 5, + HardwareState = 6, + IsRecoveryBoot = 7, + DeviceId = 8, + BootReason = 9, + MemoryMode = 10, + IsDevelopmentFunctionEnabled = 11, + KernelConfiguration = 12, + IsChargerHiZModeEnabled = 13, + QuestState = 14, + RegulatorType = 15, + DeviceUniqueKeyGeneration = 16, + Package2Hash = 17, /* Extension config items for exosphere. */ ExosphereApiVersion = 65000, diff --git a/libraries/libstratosphere/source/ams/ams_exosphere_api.cpp b/libraries/libstratosphere/source/ams/ams_exosphere_api.cpp index e964d3931..a8cf21b9a 100644 --- a/libraries/libstratosphere/source/ams/ams_exosphere_api.cpp +++ b/libraries/libstratosphere/source/ams/ams_exosphere_api.cpp @@ -21,7 +21,7 @@ namespace ams::exosphere { ApiInfo GetApiInfo() { u64 exosphere_cfg; - if (spl::smc::GetConfig(&exosphere_cfg, 1, SplConfigItem_ExosphereApiVersion) != spl::smc::Result::Success) { + if (spl::smc::GetConfig(&exosphere_cfg, 1, spl::ConfigItem::ExosphereApiVersion) != spl::smc::Result::Success) { R_ABORT_UNLESS(ResultNotPresent()); } @@ -29,15 +29,15 @@ namespace ams::exosphere { } void ForceRebootToRcm() { - R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::SetConfig(SplConfigItem_ExosphereNeedsReboot, 1))); + R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::SetConfig(spl::ConfigItem::ExosphereNeedsReboot, 1))); } void ForceRebootToIramPayload() { - R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::SetConfig(SplConfigItem_ExosphereNeedsReboot, 2))); + R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::SetConfig(spl::ConfigItem::ExosphereNeedsReboot, 2))); } void ForceShutdown() { - R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::SetConfig(SplConfigItem_ExosphereNeedsShutdown, 1))); + R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::SetConfig(spl::ConfigItem::ExosphereNeedsShutdown, 1))); } void CopyToIram(uintptr_t iram_dst, const void *dram_src, size_t size) { @@ -52,7 +52,7 @@ namespace ams::exosphere { inline u64 GetU64ConfigItem(spl::ConfigItem cfg) { u64 tmp; - R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::GetConfig(std::addressof(tmp), 1, static_cast<::SplConfigItem>(cfg)))); + R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::GetConfig(std::addressof(tmp), 1, cfg))); return tmp; } diff --git a/libraries/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_control_server_manager.cpp b/libraries/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_control_server_manager.cpp index 42553cfcb..b5e9a6232 100644 --- a/libraries/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_control_server_manager.cpp +++ b/libraries/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_control_server_manager.cpp @@ -24,7 +24,7 @@ namespace ams::capsrv::server { this->server_manager_holder.emplace(); /* Register the service. */ - R_ABORT_UNLESS(this->server_manager_holder->RegisterServer(ServiceName, MaxSessions, sf::ServiceObjectTraits::SharedPointerHelper::GetEmptyDeleteSharedPointer(std::addressof(*this->service_holder)))); + R_ABORT_UNLESS((this->server_manager_holder->RegisterServer(ServiceName, MaxSessions, sf::GetSharedPointerTo(*this->service_holder)))); /* Initialize the idle event, we're idle initially. */ os::InitializeEvent(std::addressof(this->idle_event), true, os::EventClearMode_ManualClear); diff --git a/libraries/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_control_server_manager.hpp b/libraries/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_control_server_manager.hpp index d8db8697f..3d7fdbf17 100644 --- a/libraries/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_control_server_manager.hpp +++ b/libraries/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_control_server_manager.hpp @@ -26,6 +26,7 @@ namespace ams::capsrv::server { static constexpr inline size_t MaxSessions = 2; static constexpr inline sm::ServiceName ServiceName = sm::ServiceName::Encode("caps:dc"); + using Interface = IDecoderControlService; using Service = DecoderControlService; using ServerOptions = sf::hipc::DefaultServerManagerOptions; using ServerManager = sf::hipc::ServerManager; diff --git a/libraries/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_control_service.hpp b/libraries/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_control_service.hpp index 0a095883b..961018cc1 100644 --- a/libraries/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_control_service.hpp +++ b/libraries/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_control_service.hpp @@ -18,17 +18,15 @@ namespace ams::capsrv::server { - class DecoderControlService final : public sf::IServiceObject { - protected: - enum class CommandId { - DecodeJpeg = 3001, - }; + #define AMS_CAPSRV_DECODER_CONTROL_SERVICE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 3001, Result, DecodeJpeg, (const sf::OutNonSecureBuffer &out, const sf::InBuffer &in, u32 width, u32 height, const ScreenShotDecodeOption &option)) + + AMS_SF_DEFINE_INTERFACE(IDecoderControlService, AMS_CAPSRV_DECODER_CONTROL_SERVICE_INTERFACE_INFO) + + class DecoderControlService final { public: - /* Actual commands. */ - virtual Result DecodeJpeg(const sf::OutNonSecureBuffer &out, const sf::InBuffer &in, u32 width, u32 height, const ScreenShotDecodeOption &option); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(DecodeJpeg) - }; + Result DecodeJpeg(const sf::OutNonSecureBuffer &out, const sf::InBuffer &in, u32 width, u32 height, const ScreenShotDecodeOption &option); }; + static_assert(IsIDecoderControlService); + } \ No newline at end of file diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment_impl.hpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment_impl.hpp index 8d0e65670..05aebe943 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment_impl.hpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment_impl.hpp @@ -20,19 +20,20 @@ namespace ams::erpt::srv { class Attachment; - class AttachmentImpl final : public erpt::sf::IAttachment { + class AttachmentImpl final { private: Attachment *attachment; public: AttachmentImpl(); ~AttachmentImpl(); public: - virtual Result Open(const AttachmentId &attachment_id) override final; - virtual Result Read(ams::sf::Out out_count, const ams::sf::OutBuffer &out_buffer) override final; - virtual Result SetFlags(AttachmentFlagSet flags) override final; - virtual Result GetFlags(ams::sf::Out out) override final; - virtual Result Close() override final; - virtual Result GetSize(ams::sf::Out out) override final; + Result Open(const AttachmentId &attachment_id); + Result Read(ams::sf::Out out_count, const ams::sf::OutBuffer &out_buffer); + Result SetFlags(AttachmentFlagSet flags); + Result GetFlags(ams::sf::Out out); + Result Close(); + Result GetSize(ams::sf::Out out); }; + static_assert(erpt::sf::IsIAttachment); } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_context_impl.hpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_context_impl.hpp index 662f02022..f2660638a 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_context_impl.hpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_context_impl.hpp @@ -18,19 +18,20 @@ namespace ams::erpt::srv { - class ContextImpl final : public erpt::sf::IContext { + class ContextImpl final { public: - virtual Result SubmitContext(const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer) override final; - virtual Result CreateReport(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer, const ams::sf::InBuffer &meta_buffer) override final; - virtual Result SetInitialLaunchSettingsCompletionTime(const time::SteadyClockTimePoint &time_point) override final; - virtual Result ClearInitialLaunchSettingsCompletionTime() override final; - virtual Result UpdatePowerOnTime() override final; - virtual Result UpdateAwakeTime() override final; - virtual Result SubmitMultipleCategoryContext(const MultipleCategoryContextEntry &ctx_entry, const ams::sf::InBuffer &str_buffer) override final; - virtual Result UpdateApplicationLaunchTime() override final; - virtual Result ClearApplicationLaunchTime() override final; - virtual Result SubmitAttachment(ams::sf::Out out, const ams::sf::InBuffer &attachment_name, const ams::sf::InBuffer &attachment_data) override final; - virtual Result CreateReportWithAttachments(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer, const ams::sf::InBuffer &attachment_ids_buffer) override final; + Result SubmitContext(const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer); + Result CreateReport(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer, const ams::sf::InBuffer &meta_buffer); + Result SetInitialLaunchSettingsCompletionTime(const time::SteadyClockTimePoint &time_point); + Result ClearInitialLaunchSettingsCompletionTime(); + Result UpdatePowerOnTime(); + Result UpdateAwakeTime(); + Result SubmitMultipleCategoryContext(const MultipleCategoryContextEntry &ctx_entry, const ams::sf::InBuffer &str_buffer); + Result UpdateApplicationLaunchTime(); + Result ClearApplicationLaunchTime(); + Result SubmitAttachment(ams::sf::Out out, const ams::sf::InBuffer &attachment_name, const ams::sf::InBuffer &attachment_data); + Result CreateReportWithAttachments(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer, const ams::sf::InBuffer &attachment_ids_buffer); }; + static_assert(erpt::sf::IsIContext); } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_manager_impl.hpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_manager_impl.hpp index b75d01955..e59dddb51 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_manager_impl.hpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_manager_impl.hpp @@ -18,7 +18,7 @@ namespace ams::erpt::srv { - class ManagerImpl final : public erpt::sf::IManager, public util::IntrusiveListBaseNode { + class ManagerImpl final : public util::IntrusiveListBaseNode { private: os::SystemEvent system_event; public: @@ -29,12 +29,13 @@ namespace ams::erpt::srv { public: static Result NotifyAll(); public: - virtual Result GetReportList(const ams::sf::OutBuffer &out_list, ReportType type_filter) override final; - virtual Result GetEvent(ams::sf::OutCopyHandle out) override final; - virtual Result CleanupReports() override final; - virtual Result DeleteReport(const ReportId &report_id) override final; - virtual Result GetStorageUsageStatistics(ams::sf::Out out) override final; - virtual Result GetAttachmentList(const ams::sf::OutBuffer &out_buf, const ReportId &report_id) override final; + Result GetReportList(const ams::sf::OutBuffer &out_list, ReportType type_filter); + Result GetEvent(ams::sf::OutCopyHandle out); + Result CleanupReports(); + Result DeleteReport(const ReportId &report_id); + Result GetStorageUsageStatistics(ams::sf::Out out); + Result GetAttachmentList(const ams::sf::OutBuffer &out_buf, const ReportId &report_id); }; + static_assert(erpt::sf::IsIManager); } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_report_impl.hpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_report_impl.hpp index 8b60e536a..c1adc2529 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_report_impl.hpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_report_impl.hpp @@ -20,19 +20,20 @@ namespace ams::erpt::srv { class Report; - class ReportImpl final : public erpt::sf::IReport { + class ReportImpl final { private: Report *report; public: ReportImpl(); ~ReportImpl(); public: - virtual Result Open(const ReportId &report_id) override final; - virtual Result Read(ams::sf::Out out_count, const ams::sf::OutBuffer &out_buffer) override final; - virtual Result SetFlags(ReportFlagSet flags) override final; - virtual Result GetFlags(ams::sf::Out out) override final; - virtual Result Close() override final; - virtual Result GetSize(ams::sf::Out out) override final; + Result Open(const ReportId &report_id); + Result Read(ams::sf::Out out_count, const ams::sf::OutBuffer &out_buffer); + Result SetFlags(ReportFlagSet flags); + Result GetFlags(ams::sf::Out out); + Result Close(); + Result GetSize(ams::sf::Out out); }; + static_assert(erpt::sf::IsIReport); } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_service.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_service.cpp index b6fd8725e..293a5358e 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_service.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_service.cpp @@ -42,7 +42,7 @@ namespace ams::erpt::srv { class ErrorReportServiceManager : public ams::sf::hipc::ServerManager { private: os::ThreadType thread; - std::shared_ptr context_session_object; + std::shared_ptr context_session_object; private: static void ThreadFunction(void *_this) { reinterpret_cast(_this)->SetupAndLoopProcess(); @@ -51,14 +51,14 @@ namespace ams::erpt::srv { void SetupAndLoopProcess(); public: ErrorReportServiceManager(erpt::srv::ContextImpl *c) - : context_session_object(ams::sf::ServiceObjectTraits::SharedPointerHelper::GetEmptyDeleteSharedPointer(c)) + : context_session_object(ams::sf::GetSharedPointerTo(c)) { /* ... */ } Result Initialize() { - R_ABORT_UNLESS(this->RegisterServer(ErrorReportContextServiceName, ErrorReportContextSessions, this->context_session_object)); - R_ABORT_UNLESS(this->RegisterServer(ErrorReportReportServiceName, ErrorReportReportSessions)); + R_ABORT_UNLESS((this->RegisterServer(ErrorReportContextServiceName, ErrorReportContextSessions, this->context_session_object))); + R_ABORT_UNLESS((this->RegisterServer(ErrorReportReportServiceName, ErrorReportReportSessions))); this->ResumeProcessing(); @@ -117,7 +117,7 @@ namespace ams::erpt::srv { } } - erpt::srv::ContextImpl g_context_object; + constinit erpt::srv::ContextImpl g_context_object; ErrorReportServiceManager g_erpt_server_manager(std::addressof(g_context_object)); } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_session_impl.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_session_impl.cpp index 3a0eda8b0..4aec973b6 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_session_impl.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_session_impl.cpp @@ -21,34 +21,34 @@ namespace ams::erpt::srv { - Result SessionImpl::OpenReport(ams::sf::Out> out) { - /* Create an interface. */ - auto intf = std::shared_ptr(new (std::nothrow) ReportImpl); - R_UNLESS(intf != nullptr, erpt::ResultOutOfMemory()); + namespace { - /* Return it. */ - out.SetValue(std::move(intf)); - return ResultSuccess(); + template + ALWAYS_INLINE Result OpenInterface(ams::sf::Out> &out) { + /* Define holder type. */ + using Holder = typename Interface::ImplHolder; + + /* Create an interface holder. */ + auto intf = std::shared_ptr(new (std::nothrow) Holder); + R_UNLESS(intf != nullptr, erpt::ResultOutOfMemory()); + + /* Return it. */ + out.SetValue(std::move(intf)); + return ResultSuccess(); + } + + } + + Result SessionImpl::OpenReport(ams::sf::Out> out) { + return OpenInterface(out); } Result SessionImpl::OpenManager(ams::sf::Out> out) { - /* Create an interface. */ - auto intf = std::shared_ptr(new (std::nothrow) ManagerImpl); - R_UNLESS(intf != nullptr, erpt::ResultOutOfMemory()); - - /* Return it. */ - out.SetValue(std::move(intf)); - return ResultSuccess(); + return OpenInterface(out); } Result SessionImpl::OpenAttachment(ams::sf::Out> out) { - /* Create an interface. */ - auto intf = std::shared_ptr(new (std::nothrow) AttachmentImpl); - R_UNLESS(intf != nullptr, erpt::ResultOutOfMemory()); - - /* Return it. */ - out.SetValue(std::move(intf)); - return ResultSuccess(); + return OpenInterface(out); } } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_session_impl.hpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_session_impl.hpp index 4dcc165b0..8d68c701d 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_session_impl.hpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_session_impl.hpp @@ -18,11 +18,12 @@ namespace ams::erpt::srv { - class SessionImpl final : public erpt::sf::ISession { + class SessionImpl final { public: - virtual Result OpenReport(ams::sf::Out> out) override final; - virtual Result OpenManager(ams::sf::Out> out) override final; - virtual Result OpenAttachment(ams::sf::Out> out) override final; + Result OpenReport(ams::sf::Out> out); + Result OpenManager(ams::sf::Out> out); + Result OpenAttachment(ams::sf::Out> out); }; + static_assert(erpt::sf::IsISession); } diff --git a/libraries/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp b/libraries/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp index c1d5bfdd1..6308ef9de 100644 --- a/libraries/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp +++ b/libraries/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp @@ -184,7 +184,7 @@ namespace ams::fs { /* Get the space size. */ auto get_size_impl = [&]() -> Result { R_UNLESS(sub_path == nullptr || std::strcmp(sub_path, "/") == 0, fs::ResultInvalidMountName()); - R_TRY(accessor->GetFreeSpaceSize(out, path)); + R_TRY(accessor->GetFreeSpaceSize(out, "/")); return ResultSuccess(); }; @@ -214,7 +214,7 @@ namespace ams::fs { /* Get the space size. */ auto get_size_impl = [&]() -> Result { R_UNLESS(sub_path == nullptr || std::strcmp(sub_path, "/") == 0, fs::ResultInvalidMountName()); - R_TRY(accessor->GetTotalSpaceSize(out, path)); + R_TRY(accessor->GetTotalSpaceSize(out, "/")); return ResultSuccess(); }; diff --git a/libraries/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp b/libraries/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp index 75b2dbd15..23040e25c 100644 --- a/libraries/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp +++ b/libraries/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp @@ -232,7 +232,7 @@ namespace ams::fssrv::impl { return this->base_fs->GetEntryType(reinterpret_cast(out.GetPointer()), normalizer.GetPath()); } - Result FileSystemInterfaceAdapter::OpenFile(ams::sf::Out> out, const fssrv::sf::Path &path, u32 mode) { + Result FileSystemInterfaceAdapter::OpenFile(ams::sf::Out> out, const fssrv::sf::Path &path, u32 mode) { auto read_lock = this->AcquireCacheInvalidationReadLock(); std::unique_lock open_count_semaphore; @@ -254,14 +254,14 @@ namespace ams::fssrv::impl { /* TODO: N creates an nn::fssystem::AsynchronousAccessFile here. */ std::shared_ptr shared_this = this->shared_from_this(); - std::shared_ptr file_intf = std::make_shared(std::move(file), std::move(shared_this), std::move(open_count_semaphore)); + auto file_intf = ams::sf::MakeShared(std::move(file), std::move(shared_this), std::move(open_count_semaphore)); R_UNLESS(file_intf != nullptr, fs::ResultAllocationFailureInFileSystemInterfaceAdapter()); out.SetValue(std::move(file_intf), target_object_id); return ResultSuccess(); } - Result FileSystemInterfaceAdapter::OpenDirectory(ams::sf::Out> out, const fssrv::sf::Path &path, u32 mode) { + Result FileSystemInterfaceAdapter::OpenDirectory(ams::sf::Out> out, const fssrv::sf::Path &path, u32 mode) { auto read_lock = this->AcquireCacheInvalidationReadLock(); std::unique_lock open_count_semaphore; @@ -281,7 +281,7 @@ namespace ams::fssrv::impl { const auto target_object_id = dir->GetDomainObjectId(); std::shared_ptr shared_this = this->shared_from_this(); - std::shared_ptr dir_intf = std::make_shared(std::move(dir), std::move(shared_this), std::move(open_count_semaphore)); + auto dir_intf = ams::sf::MakeShared(std::move(dir), std::move(shared_this), std::move(open_count_semaphore)); R_UNLESS(dir_intf != nullptr, fs::ResultAllocationFailureInFileSystemInterfaceAdapter()); out.SetValue(std::move(dir_intf), target_object_id); diff --git a/libraries/libstratosphere/source/lr/lr_add_on_content_location_resolver_impl.hpp b/libraries/libstratosphere/source/lr/lr_add_on_content_location_resolver_impl.hpp index 17c7a0c1c..60e57b767 100644 --- a/libraries/libstratosphere/source/lr/lr_add_on_content_location_resolver_impl.hpp +++ b/libraries/libstratosphere/source/lr/lr_add_on_content_location_resolver_impl.hpp @@ -21,7 +21,7 @@ namespace ams::lr { - class AddOnContentLocationResolverImpl : public IAddOnContentLocationResolver { + class AddOnContentLocationResolverImpl { private: /* Storage for RegisteredData entries by data id. */ RegisteredStorages registered_storages; @@ -29,12 +29,13 @@ namespace ams::lr { AddOnContentLocationResolverImpl() : registered_storages(hos::GetVersion() < hos::Version_9_0_0 ? 0x800 : 0x2) { /* ... */ } /* Actual commands. */ - virtual Result ResolveAddOnContentPath(sf::Out out, ncm::DataId id) override; - virtual Result RegisterAddOnContentStorageDeprecated(ncm::DataId id, ncm::StorageId storage_id) override; - virtual Result RegisterAddOnContentStorage(ncm::DataId id, ncm::ApplicationId application_id, ncm::StorageId storage_id) override; - virtual Result UnregisterAllAddOnContentPath() override; - virtual Result RefreshApplicationAddOnContent(const sf::InArray &ids) override; - virtual Result UnregisterApplicationAddOnContent(ncm::ApplicationId id) override; + Result ResolveAddOnContentPath(sf::Out out, ncm::DataId id); + Result RegisterAddOnContentStorageDeprecated(ncm::DataId id, ncm::StorageId storage_id); + Result RegisterAddOnContentStorage(ncm::DataId id, ncm::ApplicationId application_id, ncm::StorageId storage_id); + Result UnregisterAllAddOnContentPath(); + Result RefreshApplicationAddOnContent(const sf::InArray &ids); + Result UnregisterApplicationAddOnContent(ncm::ApplicationId id); }; + static_assert(lr::IsIAddOnContentLocationResolver); } diff --git a/libraries/libstratosphere/source/lr/lr_api.cpp b/libraries/libstratosphere/source/lr/lr_api.cpp index 36a7cb813..391285080 100644 --- a/libraries/libstratosphere/source/lr/lr_api.cpp +++ b/libraries/libstratosphere/source/lr/lr_api.cpp @@ -42,7 +42,7 @@ namespace ams::lr { LrLocationResolver lr; R_TRY(lrOpenLocationResolver(static_cast(storage_id), std::addressof(lr))); - *out = LocationResolver(std::make_shared(lr)); + *out = LocationResolver(sf::MakeShared(lr)); return ResultSuccess(); } @@ -50,7 +50,7 @@ namespace ams::lr { LrRegisteredLocationResolver lr; R_TRY(lrOpenRegisteredLocationResolver(std::addressof(lr))); - *out = RegisteredLocationResolver(std::make_shared(lr)); + *out = RegisteredLocationResolver(sf::MakeShared(lr)); return ResultSuccess(); } diff --git a/libraries/libstratosphere/source/lr/lr_content_location_resolver_impl.hpp b/libraries/libstratosphere/source/lr/lr_content_location_resolver_impl.hpp index 5553962da..5b344bdfc 100644 --- a/libraries/libstratosphere/source/lr/lr_content_location_resolver_impl.hpp +++ b/libraries/libstratosphere/source/lr/lr_content_location_resolver_impl.hpp @@ -35,32 +35,33 @@ namespace ams::lr { void GetContentStoragePath(Path *out, ncm::ContentId content_id); public: /* Actual commands. */ - virtual Result ResolveProgramPath(sf::Out out, ncm::ProgramId id) override; - virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id) override; - virtual Result ResolveApplicationControlPath(sf::Out out, ncm::ProgramId id) override; - virtual Result ResolveApplicationHtmlDocumentPath(sf::Out out, ncm::ProgramId id) override; - virtual Result ResolveDataPath(sf::Out out, ncm::DataId id) override; - virtual Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result ResolveApplicationLegalInformationPath(sf::Out out, ncm::ProgramId id) override; - virtual Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result Refresh() override; - virtual Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result ClearApplicationRedirectionDeprecated() override; - virtual Result ClearApplicationRedirection(const sf::InArray &excluding_ids) override; - virtual Result EraseProgramRedirection(ncm::ProgramId id) override; - virtual Result EraseApplicationControlRedirection(ncm::ProgramId id) override; - virtual Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) override; - virtual Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id) override; - virtual Result ResolveProgramPathForDebug(sf::Out out, ncm::ProgramId id) override; - virtual Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result EraseProgramRedirectionForDebug(ncm::ProgramId id) override; + Result ResolveProgramPath(sf::Out out, ncm::ProgramId id); + Result RedirectProgramPath(const Path &path, ncm::ProgramId id); + Result ResolveApplicationControlPath(sf::Out out, ncm::ProgramId id); + Result ResolveApplicationHtmlDocumentPath(sf::Out out, ncm::ProgramId id); + Result ResolveDataPath(sf::Out out, ncm::DataId id); + Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id); + Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id); + Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result ResolveApplicationLegalInformationPath(sf::Out out, ncm::ProgramId id); + Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id); + Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result Refresh(); + Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id); + Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result ClearApplicationRedirectionDeprecated(); + Result ClearApplicationRedirection(const sf::InArray &excluding_ids); + Result EraseProgramRedirection(ncm::ProgramId id); + Result EraseApplicationControlRedirection(ncm::ProgramId id); + Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id); + Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id); + Result ResolveProgramPathForDebug(sf::Out out, ncm::ProgramId id); + Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id); + Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id); + Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result EraseProgramRedirectionForDebug(ncm::ProgramId id); }; + static_assert(lr::IsILocationResolver); } diff --git a/libraries/libstratosphere/source/lr/lr_location_resolver_impl_base.hpp b/libraries/libstratosphere/source/lr/lr_location_resolver_impl_base.hpp index d8931d041..03f7c68ee 100644 --- a/libraries/libstratosphere/source/lr/lr_location_resolver_impl_base.hpp +++ b/libraries/libstratosphere/source/lr/lr_location_resolver_impl_base.hpp @@ -20,7 +20,7 @@ namespace ams::lr { - class LocationResolverImplBase : public ILocationResolver { + class LocationResolverImplBase { NON_COPYABLE(LocationResolverImplBase); NON_MOVEABLE(LocationResolverImplBase); protected: diff --git a/libraries/libstratosphere/source/lr/lr_location_resolver_manager_impl.cpp b/libraries/libstratosphere/source/lr/lr_location_resolver_manager_impl.cpp index f726cdf7e..fd5392c52 100644 --- a/libraries/libstratosphere/source/lr/lr_location_resolver_manager_impl.cpp +++ b/libraries/libstratosphere/source/lr/lr_location_resolver_manager_impl.cpp @@ -30,10 +30,10 @@ namespace ams::lr { /* No existing resolver is present, create one. */ if (!resolver) { if (storage_id == ncm::StorageId::Host) { - AMS_ABORT_UNLESS(this->location_resolvers.Insert(storage_id, std::make_shared())); + AMS_ABORT_UNLESS(this->location_resolvers.Insert(storage_id, sf::MakeShared())); } else { - auto content_resolver = std::make_shared(storage_id); - R_TRY(content_resolver->Refresh()); + auto content_resolver = sf::MakeShared(storage_id); + R_TRY(content_resolver->GetImpl().Refresh()); AMS_ABORT_UNLESS(this->location_resolvers.Insert(storage_id, std::move(content_resolver))); } @@ -51,7 +51,7 @@ namespace ams::lr { /* No existing resolver is present, create one. */ if (!this->registered_location_resolver) { - this->registered_location_resolver = std::make_shared(); + this->registered_location_resolver = sf::MakeShared(); } /* Copy the output interface. */ @@ -79,7 +79,7 @@ namespace ams::lr { /* No existing resolver is present, create one. */ if (!this->add_on_content_location_resolver) { - this->add_on_content_location_resolver = std::make_shared(); + this->add_on_content_location_resolver = sf::MakeShared(); } /* Copy the output interface. */ diff --git a/libraries/libstratosphere/source/lr/lr_redirect_only_location_resolver_impl.hpp b/libraries/libstratosphere/source/lr/lr_redirect_only_location_resolver_impl.hpp index a204169d1..a9aee02b4 100644 --- a/libraries/libstratosphere/source/lr/lr_redirect_only_location_resolver_impl.hpp +++ b/libraries/libstratosphere/source/lr/lr_redirect_only_location_resolver_impl.hpp @@ -24,32 +24,33 @@ namespace ams::lr { ~RedirectOnlyLocationResolverImpl(); public: /* Actual commands. */ - virtual Result ResolveProgramPath(sf::Out out, ncm::ProgramId id) override; - virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id) override; - virtual Result ResolveApplicationControlPath(sf::Out out, ncm::ProgramId id) override; - virtual Result ResolveApplicationHtmlDocumentPath(sf::Out out, ncm::ProgramId id) override; - virtual Result ResolveDataPath(sf::Out out, ncm::DataId id) override; - virtual Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result ResolveApplicationLegalInformationPath(sf::Out out, ncm::ProgramId id) override; - virtual Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result Refresh() override; - virtual Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result ClearApplicationRedirectionDeprecated() override; - virtual Result ClearApplicationRedirection(const sf::InArray &excluding_ids) override; - virtual Result EraseProgramRedirection(ncm::ProgramId id) override; - virtual Result EraseApplicationControlRedirection(ncm::ProgramId id) override; - virtual Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) override; - virtual Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id) override; - virtual Result ResolveProgramPathForDebug(sf::Out out, ncm::ProgramId id) override; - virtual Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result EraseProgramRedirectionForDebug(ncm::ProgramId id) override; + Result ResolveProgramPath(sf::Out out, ncm::ProgramId id); + Result RedirectProgramPath(const Path &path, ncm::ProgramId id); + Result ResolveApplicationControlPath(sf::Out out, ncm::ProgramId id); + Result ResolveApplicationHtmlDocumentPath(sf::Out out, ncm::ProgramId id); + Result ResolveDataPath(sf::Out out, ncm::DataId id); + Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id); + Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id); + Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result ResolveApplicationLegalInformationPath(sf::Out out, ncm::ProgramId id); + Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id); + Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result Refresh(); + Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id); + Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result ClearApplicationRedirectionDeprecated(); + Result ClearApplicationRedirection(const sf::InArray &excluding_ids); + Result EraseProgramRedirection(ncm::ProgramId id); + Result EraseApplicationControlRedirection(ncm::ProgramId id); + Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id); + Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id); + Result ResolveProgramPathForDebug(sf::Out out, ncm::ProgramId id); + Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id); + Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id); + Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result EraseProgramRedirectionForDebug(ncm::ProgramId id); }; + static_assert(lr::IsILocationResolver); } diff --git a/libraries/libstratosphere/source/lr/lr_registered_location_resolver_impl.hpp b/libraries/libstratosphere/source/lr/lr_registered_location_resolver_impl.hpp index 1a5ea6994..b1399336f 100644 --- a/libraries/libstratosphere/source/lr/lr_registered_location_resolver_impl.hpp +++ b/libraries/libstratosphere/source/lr/lr_registered_location_resolver_impl.hpp @@ -21,7 +21,7 @@ namespace ams::lr { - class RegisteredLocationResolverImpl : public IRegisteredLocationResolver { + class RegisteredLocationResolverImpl { private: static constexpr size_t MaxRegisteredLocationsDeprecated = 0x10; static constexpr size_t MaxRegisteredLocations = 0x20; @@ -49,20 +49,21 @@ namespace ams::lr { ~RegisteredLocationResolverImpl(); public: /* Actual commands. */ - virtual Result ResolveProgramPath(sf::Out out, ncm::ProgramId id) override; - virtual Result RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result UnregisterProgramPath(ncm::ProgramId id) override; - virtual Result RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result ResolveHtmlDocumentPath(sf::Out out, ncm::ProgramId id) override; - virtual Result RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result UnregisterHtmlDocumentPath(ncm::ProgramId id) override; - virtual Result RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override; - virtual Result RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; - virtual Result Refresh() override; - virtual Result RefreshExcluding(const sf::InArray &ids) override; + Result ResolveProgramPath(sf::Out out, ncm::ProgramId id); + Result RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id); + Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result UnregisterProgramPath(ncm::ProgramId id); + Result RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id); + Result RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result ResolveHtmlDocumentPath(sf::Out out, ncm::ProgramId id); + Result RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id); + Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result UnregisterHtmlDocumentPath(ncm::ProgramId id); + Result RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id); + Result RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); + Result Refresh(); + Result RefreshExcluding(const sf::InArray &ids); }; + static_assert(lr::IsIRegisteredLocationResolver); } diff --git a/libraries/libstratosphere/source/lr/lr_remote_location_resolver_impl.hpp b/libraries/libstratosphere/source/lr/lr_remote_location_resolver_impl.hpp index 59093e7d8..895325dcf 100644 --- a/libraries/libstratosphere/source/lr/lr_remote_location_resolver_impl.hpp +++ b/libraries/libstratosphere/source/lr/lr_remote_location_resolver_impl.hpp @@ -18,7 +18,7 @@ namespace ams::lr { - class RemoteLocationResolverImpl : public ILocationResolver { + class RemoteLocationResolverImpl { private: ::LrLocationResolver srv; public: @@ -27,121 +27,122 @@ namespace ams::lr { ~RemoteLocationResolverImpl() { ::serviceClose(&srv.s); } public: /* Actual commands. */ - virtual Result ResolveProgramPath(sf::Out out, ncm::ProgramId id) override { - return lrLrResolveProgramPath(std::addressof(this->srv), id.value, out->str); + Result ResolveProgramPath(sf::Out out, ncm::ProgramId id) { + return ::lrLrResolveProgramPath(std::addressof(this->srv), id.value, out->str); } - virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id) override { - return lrLrRedirectProgramPath(std::addressof(this->srv), id.value, path.str); + Result RedirectProgramPath(const Path &path, ncm::ProgramId id) { + return ::lrLrRedirectProgramPath(std::addressof(this->srv), id.value, path.str); } - virtual Result ResolveApplicationControlPath(sf::Out out, ncm::ProgramId id) override { - return lrLrResolveApplicationControlPath(std::addressof(this->srv), id.value, out->str); + Result ResolveApplicationControlPath(sf::Out out, ncm::ProgramId id) { + return ::lrLrResolveApplicationControlPath(std::addressof(this->srv), id.value, out->str); } - virtual Result ResolveApplicationHtmlDocumentPath(sf::Out out, ncm::ProgramId id) override { - return lrLrResolveApplicationHtmlDocumentPath(std::addressof(this->srv), id.value, out->str); + Result ResolveApplicationHtmlDocumentPath(sf::Out out, ncm::ProgramId id) { + return ::lrLrResolveApplicationHtmlDocumentPath(std::addressof(this->srv), id.value, out->str); } - virtual Result ResolveDataPath(sf::Out out, ncm::DataId id) override { - return lrLrResolveDataPath(std::addressof(this->srv), id.value, out->str); + Result ResolveDataPath(sf::Out out, ncm::DataId id) { + return ::lrLrResolveDataPath(std::addressof(this->srv), id.value, out->str); } - virtual Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) override { - return lrLrRedirectApplicationControlPath(std::addressof(this->srv), id.value, 0, path.str); + Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) { + return ::lrLrRedirectApplicationControlPath(std::addressof(this->srv), id.value, 0, path.str); } - virtual Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override { - return lrLrRedirectApplicationControlPath(std::addressof(this->srv), id.value, owner_id.value, path.str); + Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { + return ::lrLrRedirectApplicationControlPath(std::addressof(this->srv), id.value, owner_id.value, path.str); } - virtual Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override { - return lrLrRedirectApplicationHtmlDocumentPath(std::addressof(this->srv), id.value, 0, path.str); + Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) { + return ::lrLrRedirectApplicationHtmlDocumentPath(std::addressof(this->srv), id.value, 0, path.str); } - virtual Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override { - return lrLrRedirectApplicationHtmlDocumentPath(std::addressof(this->srv), id.value, owner_id.value, path.str); + Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { + return ::lrLrRedirectApplicationHtmlDocumentPath(std::addressof(this->srv), id.value, owner_id.value, path.str); } - virtual Result ResolveApplicationLegalInformationPath(sf::Out out, ncm::ProgramId id) override { - return lrLrResolveApplicationLegalInformationPath(std::addressof(this->srv), id.value, out->str); + Result ResolveApplicationLegalInformationPath(sf::Out out, ncm::ProgramId id) { + return ::lrLrResolveApplicationLegalInformationPath(std::addressof(this->srv), id.value, out->str); } - virtual Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) override { - return lrLrRedirectApplicationLegalInformationPath(std::addressof(this->srv), id.value, 0, path.str); + Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) { + return ::lrLrRedirectApplicationLegalInformationPath(std::addressof(this->srv), id.value, 0, path.str); } - virtual Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override { - return lrLrRedirectApplicationLegalInformationPath(std::addressof(this->srv), id.value, owner_id.value, path.str); + Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { + return ::lrLrRedirectApplicationLegalInformationPath(std::addressof(this->srv), id.value, owner_id.value, path.str); } - virtual Result Refresh() override { - return lrLrRefresh(std::addressof(this->srv)); + Result Refresh() { + return ::lrLrRefresh(std::addressof(this->srv)); } - virtual Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) override { + Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override { + Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result ClearApplicationRedirectionDeprecated() override { + Result ClearApplicationRedirectionDeprecated() { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result ClearApplicationRedirection(const sf::InArray &excluding_ids) override { + Result ClearApplicationRedirection(const sf::InArray &excluding_ids) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result EraseProgramRedirection(ncm::ProgramId id) override { - return lrLrEraseProgramRedirection(std::addressof(this->srv), id.value); + Result EraseProgramRedirection(ncm::ProgramId id) { + return ::lrLrEraseProgramRedirection(std::addressof(this->srv), id.value); } - virtual Result EraseApplicationControlRedirection(ncm::ProgramId id) override { + Result EraseApplicationControlRedirection(ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) override { + Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id) override { + Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result ResolveProgramPathForDebug(sf::Out out, ncm::ProgramId id) override { + Result ResolveProgramPathForDebug(sf::Out out, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) override { + Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) override { + Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override { + Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result EraseProgramRedirectionForDebug(ncm::ProgramId id) override { + Result EraseProgramRedirectionForDebug(ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } }; + static_assert(lr::IsILocationResolver); } diff --git a/libraries/libstratosphere/source/lr/lr_remote_registered_location_resolver_impl.hpp b/libraries/libstratosphere/source/lr/lr_remote_registered_location_resolver_impl.hpp index 3b8551756..2a3367d34 100644 --- a/libraries/libstratosphere/source/lr/lr_remote_registered_location_resolver_impl.hpp +++ b/libraries/libstratosphere/source/lr/lr_remote_registered_location_resolver_impl.hpp @@ -19,7 +19,7 @@ namespace ams::lr { - class RemoteRegisteredLocationResolverImpl : public IRegisteredLocationResolver { + class RemoteRegisteredLocationResolverImpl { private: ::LrRegisteredLocationResolver srv; public: @@ -28,74 +28,75 @@ namespace ams::lr { ~RemoteRegisteredLocationResolverImpl() { ::serviceClose(&srv.s); } public: /* Actual commands. */ - virtual Result ResolveProgramPath(sf::Out out, ncm::ProgramId id) override { - return lrRegLrResolveProgramPath(std::addressof(this->srv), static_cast(id), out->str); + Result ResolveProgramPath(sf::Out out, ncm::ProgramId id) { + return ::lrRegLrResolveProgramPath(std::addressof(this->srv), static_cast(id), out->str); } - virtual Result RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) override { + Result RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override { + Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result UnregisterProgramPath(ncm::ProgramId id) override { + Result UnregisterProgramPath(ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id) override { + Result RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override { + Result RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result ResolveHtmlDocumentPath(sf::Out out, ncm::ProgramId id) override { + Result ResolveHtmlDocumentPath(sf::Out out, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override { + Result RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override { + Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result UnregisterHtmlDocumentPath(ncm::ProgramId id) override { + Result UnregisterHtmlDocumentPath(ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) override { + Result RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override { + Result RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result Refresh() override { + Result Refresh() { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result RefreshExcluding(const sf::InArray &ids) override { + Result RefreshExcluding(const sf::InArray &ids) { /* TODO: libnx bindings */ AMS_ABORT(); } }; + static_assert(lr::IsIRegisteredLocationResolver); } diff --git a/libraries/libstratosphere/source/ncm/ncm_api.cpp b/libraries/libstratosphere/source/ncm/ncm_api.cpp index b2c3e2d9c..ca392ab6a 100644 --- a/libraries/libstratosphere/source/ncm/ncm_api.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_api.cpp @@ -27,7 +27,7 @@ namespace ams::ncm { void Initialize() { AMS_ASSERT(g_content_manager == nullptr); R_ABORT_UNLESS(ncmInitialize()); - g_content_manager = std::make_shared(); + g_content_manager = sf::MakeShared(); } void Finalize() { diff --git a/libraries/libstratosphere/source/ncm/ncm_content_manager_impl.cpp b/libraries/libstratosphere/source/ncm/ncm_content_manager_impl.cpp index 3f4dabcb0..7302acc19 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_manager_impl.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_manager_impl.cpp @@ -553,23 +553,23 @@ namespace ams::ncm { if (storage_id == StorageId::GameCard) { /* Game card content storage is read only. */ - auto content_storage = std::make_shared(); - R_TRY(content_storage->Initialize(root->path, MakeFlatContentFilePath)); + auto content_storage = sf::MakeShared(); + R_TRY(content_storage->GetImpl().Initialize(root->path, MakeFlatContentFilePath)); root->content_storage = std::move(content_storage); } else { /* Create a content storage. */ - auto content_storage = std::make_shared(); + auto content_storage = sf::MakeShared(); /* Initialize content storage with an appropriate path function. */ switch (storage_id) { case StorageId::BuiltInSystem: - R_TRY(content_storage->Initialize(root->path, MakeFlatContentFilePath, MakeFlatPlaceHolderFilePath, false, std::addressof(this->rights_id_cache))); + R_TRY(content_storage->GetImpl().Initialize(root->path, MakeFlatContentFilePath, MakeFlatPlaceHolderFilePath, false, std::addressof(this->rights_id_cache))); break; case StorageId::SdCard: - R_TRY(content_storage->Initialize(root->path, MakeSha256HierarchicalContentFilePath_ForFat16KCluster, MakeSha256HierarchicalPlaceHolderFilePath_ForFat16KCluster, true, std::addressof(this->rights_id_cache))); + R_TRY(content_storage->GetImpl().Initialize(root->path, MakeSha256HierarchicalContentFilePath_ForFat16KCluster, MakeSha256HierarchicalPlaceHolderFilePath_ForFat16KCluster, true, std::addressof(this->rights_id_cache))); break; default: - R_TRY(content_storage->Initialize(root->path, MakeSha256HierarchicalContentFilePath_ForFat16KCluster, MakeSha256HierarchicalPlaceHolderFilePath_ForFat16KCluster, false, std::addressof(this->rights_id_cache))); + R_TRY(content_storage->GetImpl().Initialize(root->path, MakeSha256HierarchicalContentFilePath_ForFat16KCluster, MakeSha256HierarchicalPlaceHolderFilePath_ForFat16KCluster, false, std::addressof(this->rights_id_cache))); break; } @@ -617,7 +617,7 @@ namespace ams::ncm { R_TRY(root->kvs->Initialize(root->max_content_metas, root->memory_resource)); /* Create an on memory content meta database for game cards. */ - root->content_meta_database = std::make_shared(std::addressof(*root->kvs)); + root->content_meta_database = sf::MakeShared(std::addressof(*root->kvs)); } else { /* Mount save data for this root. */ R_TRY(fs::MountSystemSaveData(root->mount_name, root->info.space_id, root->info.id)); @@ -630,7 +630,7 @@ namespace ams::ncm { R_TRY(root->kvs->Load()); /* Create the content meta database. */ - root->content_meta_database = std::make_shared(std::addressof(*root->kvs), root->mount_name); + root->content_meta_database = sf::MakeShared(std::addressof(*root->kvs), root->mount_name); mount_guard.Cancel(); } diff --git a/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl_base.hpp b/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl_base.hpp index 171180622..21945868c 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl_base.hpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl_base.hpp @@ -18,7 +18,7 @@ namespace ams::ncm { - class ContentMetaDatabaseImplBase : public IContentMetaDatabase { + class ContentMetaDatabaseImplBase { NON_COPYABLE(ContentMetaDatabaseImplBase); NON_MOVEABLE(ContentMetaDatabaseImplBase); protected: @@ -52,6 +52,32 @@ namespace ams::ncm { R_TRY(this->GetContentMetaSize(out_size, key)); return this->kvs->GetValuePointer(reinterpret_cast(out_value_ptr), key); } + public: + /* Actual commands. */ + virtual Result Set(const ContentMetaKey &key, sf::InBuffer value) = 0; + virtual Result Get(sf::Out out_size, const ContentMetaKey &key, sf::OutBuffer out_value) = 0; + virtual Result Remove(const ContentMetaKey &key) = 0; + virtual Result GetContentIdByType(sf::Out out_content_id, const ContentMetaKey &key, ContentType type) = 0; + virtual Result ListContentInfo(sf::Out out_entries_written, const sf::OutArray &out_info, const ContentMetaKey &key, s32 offset) = 0; + virtual Result List(sf::Out out_entries_total, sf::Out out_entries_written, const sf::OutArray &out_info, ContentMetaType meta_type, ApplicationId application_id, u64 min, u64 max, ContentInstallType install_type) = 0; + virtual Result GetLatestContentMetaKey(sf::Out out_key, u64 id) = 0; + virtual Result ListApplication(sf::Out out_entries_total, sf::Out out_entries_written, const sf::OutArray &out_keys, ContentMetaType meta_type) = 0; + virtual Result Has(sf::Out out, const ContentMetaKey &key) = 0; + virtual Result HasAll(sf::Out out, const sf::InArray &keys) = 0; + virtual Result GetSize(sf::Out out_size, const ContentMetaKey &key) = 0; + virtual Result GetRequiredSystemVersion(sf::Out out_version, const ContentMetaKey &key) = 0; + virtual Result GetPatchId(sf::Out out_patch_id, const ContentMetaKey &key) = 0; + virtual Result DisableForcibly() = 0; + virtual Result LookupOrphanContent(const sf::OutArray &out_orphaned, const sf::InArray &content_ids) = 0; + virtual Result Commit() = 0; + virtual Result HasContent(sf::Out out, const ContentMetaKey &key, const ContentId &content_id) = 0; + virtual Result ListContentMetaInfo(sf::Out out_entries_written, const sf::OutArray &out_meta_info, const ContentMetaKey &key, s32 offset) = 0; + virtual Result GetAttributes(sf::Out out_attributes, const ContentMetaKey &key) = 0; + virtual Result GetRequiredApplicationVersion(sf::Out out_version, const ContentMetaKey &key) = 0; + virtual Result GetContentIdByTypeAndIdOffset(sf::Out out_content_id, const ContentMetaKey &key, ContentType type, u8 id_offset) = 0; + virtual Result GetCount(sf::Out out_count) = 0; + virtual Result GetOwnerApplicationId(sf::Out out_id, const ContentMetaKey &key) = 0; }; + static_assert(ncm::IsIContentMetaDatabase); } diff --git a/libraries/libstratosphere/source/ncm/ncm_content_storage_impl_base.hpp b/libraries/libstratosphere/source/ncm/ncm_content_storage_impl_base.hpp index 7991eeb2b..3c094dba8 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_storage_impl_base.hpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_storage_impl_base.hpp @@ -18,7 +18,7 @@ namespace ams::ncm { - class ContentStorageImplBase : public IContentStorage { + class ContentStorageImplBase { NON_COPYABLE(ContentStorageImplBase); NON_MOVEABLE(ContentStorageImplBase); protected: @@ -43,6 +43,39 @@ namespace ams::ncm { } return ResultSuccess(); } + public: + /* Actual commands. */ + virtual Result GeneratePlaceHolderId(sf::Out out) = 0; + virtual Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, s64 size) = 0; + virtual Result DeletePlaceHolder(PlaceHolderId placeholder_id) = 0; + virtual Result HasPlaceHolder(sf::Out out, PlaceHolderId placeholder_id) = 0; + virtual Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, sf::InBuffer data) = 0; + virtual Result Register(PlaceHolderId placeholder_id, ContentId content_id) = 0; + virtual Result Delete(ContentId content_id) = 0; + virtual Result Has(sf::Out out, ContentId content_id) = 0; + virtual Result GetPath(sf::Out out, ContentId content_id) = 0; + virtual Result GetPlaceHolderPath(sf::Out out, PlaceHolderId placeholder_id) = 0; + virtual Result CleanupAllPlaceHolder() = 0; + virtual Result ListPlaceHolder(sf::Out out_count, const sf::OutArray &out_buf) = 0; + virtual Result GetContentCount(sf::Out out_count) = 0; + virtual Result ListContentId(sf::Out out_count, const sf::OutArray &out_buf, s32 start_offset) = 0; + virtual Result GetSizeFromContentId(sf::Out out_size, ContentId content_id) = 0; + virtual Result DisableForcibly() = 0; + virtual Result RevertToPlaceHolder(PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id) = 0; + virtual Result SetPlaceHolderSize(PlaceHolderId placeholder_id, s64 size) = 0; + virtual Result ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, s64 offset) = 0; + virtual Result GetRightsIdFromPlaceHolderIdDeprecated(sf::Out out_rights_id, PlaceHolderId placeholder_id) = 0; + virtual Result GetRightsIdFromPlaceHolderId(sf::Out out_rights_id, PlaceHolderId placeholder_id) = 0; + virtual Result GetRightsIdFromContentIdDeprecated(sf::Out out_rights_id, ContentId content_id) = 0; + virtual Result GetRightsIdFromContentId(sf::Out out_rights_id, ContentId content_id) = 0; + virtual Result WriteContentForDebug(ContentId content_id, s64 offset, sf::InBuffer data) = 0; + virtual Result GetFreeSpaceSize(sf::Out out_size) = 0; + virtual Result GetTotalSpaceSize(sf::Out out_size) = 0; + virtual Result FlushPlaceHolder() = 0; + virtual Result GetSizeFromPlaceHolderId(sf::Out out, PlaceHolderId placeholder_id) = 0; + virtual Result RepairInvalidFileAttribute() = 0; + virtual Result GetRightsIdFromPlaceHolderIdWithCache(sf::Out out_rights_id, PlaceHolderId placeholder_id, ContentId cache_content_id) = 0; }; + static_assert(ncm::IsIContentStorage); } diff --git a/libraries/libstratosphere/source/ncm/ncm_remote_content_manager_impl.hpp b/libraries/libstratosphere/source/ncm/ncm_remote_content_manager_impl.hpp index 5ff6ca8d5..59577f7ae 100644 --- a/libraries/libstratosphere/source/ncm/ncm_remote_content_manager_impl.hpp +++ b/libraries/libstratosphere/source/ncm/ncm_remote_content_manager_impl.hpp @@ -20,80 +20,81 @@ namespace ams::ncm { - class RemoteContentManagerImpl final : public IContentManager { + class RemoteContentManagerImpl final { public: RemoteContentManagerImpl() { /* ... */ } ~RemoteContentManagerImpl() { /* ... */ } public: - virtual Result CreateContentStorage(StorageId storage_id) override { + Result CreateContentStorage(StorageId storage_id) { return ::ncmCreateContentStorage(static_cast(storage_id)); } - virtual Result CreateContentMetaDatabase(StorageId storage_id) override { + Result CreateContentMetaDatabase(StorageId storage_id) { return ::ncmCreateContentMetaDatabase(static_cast(storage_id)); } - virtual Result VerifyContentStorage(StorageId storage_id) override { + Result VerifyContentStorage(StorageId storage_id) { return ::ncmVerifyContentStorage(static_cast(storage_id)); } - virtual Result VerifyContentMetaDatabase(StorageId storage_id) override { + Result VerifyContentMetaDatabase(StorageId storage_id) { return ::ncmVerifyContentMetaDatabase(static_cast(storage_id)); } - virtual Result OpenContentStorage(sf::Out> out, StorageId storage_id) override { + Result OpenContentStorage(sf::Out> out, StorageId storage_id) { NcmContentStorage cs; R_TRY(::ncmOpenContentStorage(std::addressof(cs), static_cast(storage_id))); - out.SetValue(std::make_shared(cs)); + out.SetValue(sf::MakeShared(cs)); return ResultSuccess(); } - virtual Result OpenContentMetaDatabase(sf::Out> out, StorageId storage_id) override { + Result OpenContentMetaDatabase(sf::Out> out, StorageId storage_id) { NcmContentMetaDatabase db; R_TRY(::ncmOpenContentMetaDatabase(std::addressof(db), static_cast(storage_id))); - out.SetValue(std::make_shared(db)); + out.SetValue(sf::MakeShared(db)); return ResultSuccess(); } - virtual Result CloseContentStorageForcibly(StorageId storage_id) override { + Result CloseContentStorageForcibly(StorageId storage_id) { return ::ncmCloseContentStorageForcibly(static_cast(storage_id)); } - virtual Result CloseContentMetaDatabaseForcibly(StorageId storage_id) override { + Result CloseContentMetaDatabaseForcibly(StorageId storage_id) { return ::ncmCloseContentMetaDatabaseForcibly(static_cast(storage_id)); } - virtual Result CleanupContentMetaDatabase(StorageId storage_id) override { + Result CleanupContentMetaDatabase(StorageId storage_id) { return ::ncmCleanupContentMetaDatabase(static_cast(storage_id)); } - virtual Result ActivateContentStorage(StorageId storage_id) override { + Result ActivateContentStorage(StorageId storage_id) { return ::ncmActivateContentStorage(static_cast(storage_id)); } - virtual Result InactivateContentStorage(StorageId storage_id) override { + Result InactivateContentStorage(StorageId storage_id) { return ::ncmInactivateContentStorage(static_cast(storage_id)); } - virtual Result ActivateContentMetaDatabase(StorageId storage_id) override { + Result ActivateContentMetaDatabase(StorageId storage_id) { return ::ncmActivateContentMetaDatabase(static_cast(storage_id)); } - virtual Result InactivateContentMetaDatabase(StorageId storage_id) override { + Result InactivateContentMetaDatabase(StorageId storage_id) { return ::ncmInactivateContentMetaDatabase(static_cast(storage_id)); } - virtual Result InvalidateRightsIdCache() override { + Result InvalidateRightsIdCache() { return ::ncmInvalidateRightsIdCache(); } - virtual Result GetMemoryReport(sf::Out out) override { + Result GetMemoryReport(sf::Out out) { /* TODO: libnx bindings */ AMS_ABORT(); } }; + static_assert(ncm::IsIContentManager); } diff --git a/libraries/libstratosphere/source/ncm/ncm_remote_content_meta_database_impl.hpp b/libraries/libstratosphere/source/ncm/ncm_remote_content_meta_database_impl.hpp index 98fc25068..14935f465 100644 --- a/libraries/libstratosphere/source/ncm/ncm_remote_content_meta_database_impl.hpp +++ b/libraries/libstratosphere/source/ncm/ncm_remote_content_meta_database_impl.hpp @@ -18,7 +18,7 @@ namespace ams::ncm { - class RemoteContentMetaDatabaseImpl final : public IContentMetaDatabase { + class RemoteContentMetaDatabaseImpl final { private: ::NcmContentMetaDatabase srv; public: @@ -71,101 +71,101 @@ namespace ams::ncm { return reinterpret_cast(std::addressof(c)); } public: - virtual Result Set(const ContentMetaKey &key, sf::InBuffer value) override { + Result Set(const ContentMetaKey &key, sf::InBuffer value) { return ncmContentMetaDatabaseSet(std::addressof(this->srv), Convert(key), value.GetPointer(), value.GetSize()); } - virtual Result Get(sf::Out out_size, const ContentMetaKey &key, sf::OutBuffer out_value) override { + Result Get(sf::Out out_size, const ContentMetaKey &key, sf::OutBuffer out_value) { return ncmContentMetaDatabaseGet(std::addressof(this->srv), Convert(key), out_size.GetPointer(), out_value.GetPointer(), out_value.GetSize()); } - virtual Result Remove(const ContentMetaKey &key) override { + Result Remove(const ContentMetaKey &key) { return ncmContentMetaDatabaseRemove(std::addressof(this->srv), Convert(key)); } - virtual Result GetContentIdByType(sf::Out out_content_id, const ContentMetaKey &key, ContentType type) override { + Result GetContentIdByType(sf::Out out_content_id, const ContentMetaKey &key, ContentType type) { return ncmContentMetaDatabaseGetContentIdByType(std::addressof(this->srv), Convert(out_content_id.GetPointer()), Convert(key), static_cast<::NcmContentType>(type)); } - virtual Result ListContentInfo(sf::Out out_entries_written, const sf::OutArray &out_info, const ContentMetaKey &key, s32 offset) override { + Result ListContentInfo(sf::Out out_entries_written, const sf::OutArray &out_info, const ContentMetaKey &key, s32 offset) { return ncmContentMetaDatabaseListContentInfo(std::addressof(this->srv), out_entries_written.GetPointer(), Convert(out_info.GetPointer()), out_info.GetSize(), Convert(key), offset); } - virtual Result List(sf::Out out_entries_total, sf::Out out_entries_written, const sf::OutArray &out_info, ContentMetaType meta_type, ApplicationId application_id, u64 min, u64 max, ContentInstallType install_type) override { + Result List(sf::Out out_entries_total, sf::Out out_entries_written, const sf::OutArray &out_info, ContentMetaType meta_type, ApplicationId application_id, u64 min, u64 max, ContentInstallType install_type) { return ncmContentMetaDatabaseList(std::addressof(this->srv), out_entries_total.GetPointer(), out_entries_written.GetPointer(), Convert(out_info.GetPointer()), out_info.GetSize(), static_cast<::NcmContentMetaType>(meta_type), application_id.value, min, max, static_cast<::NcmContentInstallType>(install_type)); } - virtual Result GetLatestContentMetaKey(sf::Out out_key, u64 id) override { + Result GetLatestContentMetaKey(sf::Out out_key, u64 id) { return ncmContentMetaDatabaseGetLatestContentMetaKey(std::addressof(this->srv), Convert(out_key.GetPointer()), static_cast(id)); } - virtual Result ListApplication(sf::Out out_entries_total, sf::Out out_entries_written, const sf::OutArray &out_keys, ContentMetaType meta_type) override { + Result ListApplication(sf::Out out_entries_total, sf::Out out_entries_written, const sf::OutArray &out_keys, ContentMetaType meta_type) { return ncmContentMetaDatabaseListApplication(std::addressof(this->srv), out_entries_total.GetPointer(), out_entries_written.GetPointer(), Convert(out_keys.GetPointer()), out_keys.GetSize(), static_cast<::NcmContentMetaType>(meta_type)); } - virtual Result Has(sf::Out out, const ContentMetaKey &key) override { + Result Has(sf::Out out, const ContentMetaKey &key) { return ncmContentMetaDatabaseHas(std::addressof(this->srv), out.GetPointer(), Convert(key)); } - virtual Result HasAll(sf::Out out, const sf::InArray &keys) override { + Result HasAll(sf::Out out, const sf::InArray &keys) { return ncmContentMetaDatabaseHasAll(std::addressof(this->srv), out.GetPointer(), Convert(keys.GetPointer()), keys.GetSize()); } - virtual Result GetSize(sf::Out out_size, const ContentMetaKey &key) override { + Result GetSize(sf::Out out_size, const ContentMetaKey &key) { return ncmContentMetaDatabaseGetSize(std::addressof(this->srv), out_size.GetPointer(), Convert(key)); } - virtual Result GetRequiredSystemVersion(sf::Out out_version, const ContentMetaKey &key) override { + Result GetRequiredSystemVersion(sf::Out out_version, const ContentMetaKey &key) { return ncmContentMetaDatabaseGetRequiredSystemVersion(std::addressof(this->srv), out_version.GetPointer(), Convert(key)); } - virtual Result GetPatchId(sf::Out out_patch_id, const ContentMetaKey &key) override { + Result GetPatchId(sf::Out out_patch_id, const ContentMetaKey &key) { return ncmContentMetaDatabaseGetPatchId(std::addressof(this->srv), reinterpret_cast(out_patch_id.GetPointer()), Convert(key)); } - virtual Result DisableForcibly() override { + Result DisableForcibly() { return ncmContentMetaDatabaseDisableForcibly(std::addressof(this->srv)); } - virtual Result LookupOrphanContent(const sf::OutArray &out_orphaned, const sf::InArray &content_ids) override { + Result LookupOrphanContent(const sf::OutArray &out_orphaned, const sf::InArray &content_ids) { return ncmContentMetaDatabaseLookupOrphanContent(std::addressof(this->srv), out_orphaned.GetPointer(), Convert(content_ids.GetPointer()), std::min(out_orphaned.GetSize(), content_ids.GetSize())); } - virtual Result Commit() override { + Result Commit() { return ncmContentMetaDatabaseCommit(std::addressof(this->srv)); } - virtual Result HasContent(sf::Out out, const ContentMetaKey &key, const ContentId &content_id) override { + Result HasContent(sf::Out out, const ContentMetaKey &key, const ContentId &content_id) { return ncmContentMetaDatabaseHasContent(std::addressof(this->srv), out.GetPointer(), Convert(key), Convert(content_id)); } - virtual Result ListContentMetaInfo(sf::Out out_entries_written, const sf::OutArray &out_meta_info, const ContentMetaKey &key, s32 offset) override { + Result ListContentMetaInfo(sf::Out out_entries_written, const sf::OutArray &out_meta_info, const ContentMetaKey &key, s32 offset) { return ncmContentMetaDatabaseListContentMetaInfo(std::addressof(this->srv), out_entries_written.GetPointer(), out_meta_info.GetPointer(), out_meta_info.GetSize(), Convert(key), offset); } - virtual Result GetAttributes(sf::Out out_attributes, const ContentMetaKey &key) override { + Result GetAttributes(sf::Out out_attributes, const ContentMetaKey &key) { static_assert(sizeof(ContentMetaAttribute) == sizeof(u8)); return ncmContentMetaDatabaseGetAttributes(std::addressof(this->srv), Convert(key), out_attributes.GetPointer()); } - virtual Result GetRequiredApplicationVersion(sf::Out out_version, const ContentMetaKey &key) override { + Result GetRequiredApplicationVersion(sf::Out out_version, const ContentMetaKey &key) { return ncmContentMetaDatabaseGetRequiredApplicationVersion(std::addressof(this->srv), out_version.GetPointer(), Convert(key)); } - virtual Result GetContentIdByTypeAndIdOffset(sf::Out out_content_id, const ContentMetaKey &key, ContentType type, u8 id_offset) override { + Result GetContentIdByTypeAndIdOffset(sf::Out out_content_id, const ContentMetaKey &key, ContentType type, u8 id_offset) { return ncmContentMetaDatabaseGetContentIdByTypeAndIdOffset(std::addressof(this->srv), Convert(out_content_id.GetPointer()), Convert(key), static_cast<::NcmContentType>(type), id_offset); } - virtual Result GetCount(sf::Out out_count) override { + Result GetCount(sf::Out out_count) { /* TODO: libnx bindings */ AMS_ABORT(); } - virtual Result GetOwnerApplicationId(sf::Out out_id, const ContentMetaKey &key) override { + Result GetOwnerApplicationId(sf::Out out_id, const ContentMetaKey &key) { /* TODO: libnx bindings */ AMS_ABORT(); } - }; + static_assert(ncm::IsIContentMetaDatabase); } diff --git a/libraries/libstratosphere/source/ncm/ncm_remote_content_storage_impl.hpp b/libraries/libstratosphere/source/ncm/ncm_remote_content_storage_impl.hpp index a7db1d4d9..32465f563 100644 --- a/libraries/libstratosphere/source/ncm/ncm_remote_content_storage_impl.hpp +++ b/libraries/libstratosphere/source/ncm/ncm_remote_content_storage_impl.hpp @@ -18,7 +18,7 @@ namespace ams::ncm { - class RemoteContentStorageImpl final : public IContentStorage { + class RemoteContentStorageImpl final { private: ::NcmContentStorage srv; public: @@ -46,85 +46,85 @@ namespace ams::ncm { return reinterpret_cast<::NcmContentId *>(std::addressof(c)); } public: - virtual Result GeneratePlaceHolderId(sf::Out out) override { + Result GeneratePlaceHolderId(sf::Out out) { return ncmContentStorageGeneratePlaceHolderId(std::addressof(this->srv), Convert(out.GetPointer())); } - virtual Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, s64 size) override { + Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, s64 size) { static_assert(alignof(ContentId) < alignof(PlaceHolderId)); return ncmContentStorageCreatePlaceHolder(std::addressof(this->srv), Convert(content_id), Convert(placeholder_id), size); } - virtual Result DeletePlaceHolder(PlaceHolderId placeholder_id) override { + Result DeletePlaceHolder(PlaceHolderId placeholder_id) { return ncmContentStorageDeletePlaceHolder(std::addressof(this->srv), Convert(placeholder_id)); } - virtual Result HasPlaceHolder(sf::Out out, PlaceHolderId placeholder_id) override { + Result HasPlaceHolder(sf::Out out, PlaceHolderId placeholder_id) { return ncmContentStorageHasPlaceHolder(std::addressof(this->srv), out.GetPointer(), Convert(placeholder_id)); } - virtual Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, sf::InBuffer data) override { + Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, sf::InBuffer data) { return ncmContentStorageWritePlaceHolder(std::addressof(this->srv), Convert(placeholder_id), offset, data.GetPointer(), data.GetSize()); } - virtual Result Register(PlaceHolderId placeholder_id, ContentId content_id) override { + Result Register(PlaceHolderId placeholder_id, ContentId content_id) { static_assert(alignof(ContentId) < alignof(PlaceHolderId)); return ncmContentStorageRegister(std::addressof(this->srv), Convert(content_id), Convert(placeholder_id)); } - virtual Result Delete(ContentId content_id) override { + Result Delete(ContentId content_id) { return ncmContentStorageDelete(std::addressof(this->srv), Convert(content_id)); } - virtual Result Has(sf::Out out, ContentId content_id) override { + Result Has(sf::Out out, ContentId content_id) { return ncmContentStorageHas(std::addressof(this->srv), out.GetPointer(), Convert(content_id)); } - virtual Result GetPath(sf::Out out, ContentId content_id) override { + Result GetPath(sf::Out out, ContentId content_id) { return ncmContentStorageGetPath(std::addressof(this->srv), out.GetPointer()->str, sizeof(out.GetPointer()->str), Convert(content_id)); } - virtual Result GetPlaceHolderPath(sf::Out out, PlaceHolderId placeholder_id) override { + Result GetPlaceHolderPath(sf::Out out, PlaceHolderId placeholder_id) { return ncmContentStorageGetPlaceHolderPath(std::addressof(this->srv), out.GetPointer()->str, sizeof(out.GetPointer()->str), Convert(placeholder_id)); } - virtual Result CleanupAllPlaceHolder() override { + Result CleanupAllPlaceHolder() { return ncmContentStorageCleanupAllPlaceHolder(std::addressof(this->srv)); } - virtual Result ListPlaceHolder(sf::Out out_count, const sf::OutArray &out_buf) override { + Result ListPlaceHolder(sf::Out out_count, const sf::OutArray &out_buf) { return ncmContentStorageListPlaceHolder(std::addressof(this->srv), Convert(out_buf.GetPointer()), out_buf.GetSize(), out_count.GetPointer()); } - virtual Result GetContentCount(sf::Out out_count) override { + Result GetContentCount(sf::Out out_count) { return ncmContentStorageGetContentCount(std::addressof(this->srv), out_count.GetPointer()); } - virtual Result ListContentId(sf::Out out_count, const sf::OutArray &out_buf, s32 offset) override { + Result ListContentId(sf::Out out_count, const sf::OutArray &out_buf, s32 offset) { return ncmContentStorageListContentId(std::addressof(this->srv), Convert(out_buf.GetPointer()), out_buf.GetSize(), out_count.GetPointer(), offset); } - virtual Result GetSizeFromContentId(sf::Out out_size, ContentId content_id) override { + Result GetSizeFromContentId(sf::Out out_size, ContentId content_id) { return ncmContentStorageGetSizeFromContentId(std::addressof(this->srv), out_size.GetPointer(), Convert(content_id)); } - virtual Result DisableForcibly() override { + Result DisableForcibly() { return ncmContentStorageDisableForcibly(std::addressof(this->srv)); } - virtual Result RevertToPlaceHolder(PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id) override { + Result RevertToPlaceHolder(PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id) { return ncmContentStorageRevertToPlaceHolder(std::addressof(this->srv), Convert(placeholder_id), Convert(old_content_id), Convert(new_content_id)); } - virtual Result SetPlaceHolderSize(PlaceHolderId placeholder_id, s64 size) override { + Result SetPlaceHolderSize(PlaceHolderId placeholder_id, s64 size) { return ncmContentStorageSetPlaceHolderSize(std::addressof(this->srv), Convert(placeholder_id), size); } - virtual Result ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, s64 offset) override { + Result ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, s64 offset) { return ncmContentStorageReadContentIdFile(std::addressof(this->srv), buf.GetPointer(), buf.GetSize(), Convert(content_id), offset); } - virtual Result GetRightsIdFromPlaceHolderIdDeprecated(sf::Out out_rights_id, PlaceHolderId placeholder_id) override { + Result GetRightsIdFromPlaceHolderIdDeprecated(sf::Out out_rights_id, PlaceHolderId placeholder_id) { ::NcmRightsId rights_id; R_TRY(ncmContentStorageGetRightsIdFromPlaceHolderId(std::addressof(this->srv), std::addressof(rights_id), Convert(placeholder_id))); @@ -133,7 +133,7 @@ namespace ams::ncm { return ResultSuccess(); } - virtual Result GetRightsIdFromPlaceHolderId(sf::Out out_rights_id, PlaceHolderId placeholder_id) override { + Result GetRightsIdFromPlaceHolderId(sf::Out out_rights_id, PlaceHolderId placeholder_id) { ::NcmRightsId rights_id; R_TRY(ncmContentStorageGetRightsIdFromPlaceHolderId(std::addressof(this->srv), std::addressof(rights_id), Convert(placeholder_id))); @@ -142,7 +142,7 @@ namespace ams::ncm { return ResultSuccess(); } - virtual Result GetRightsIdFromContentIdDeprecated(sf::Out out_rights_id, ContentId content_id) override { + Result GetRightsIdFromContentIdDeprecated(sf::Out out_rights_id, ContentId content_id) { ::NcmRightsId rights_id; R_TRY(ncmContentStorageGetRightsIdFromContentId(std::addressof(this->srv), std::addressof(rights_id), Convert(content_id))); @@ -151,7 +151,7 @@ namespace ams::ncm { return ResultSuccess(); } - virtual Result GetRightsIdFromContentId(sf::Out out_rights_id, ContentId content_id) override { + Result GetRightsIdFromContentId(sf::Out out_rights_id, ContentId content_id) { ::NcmRightsId rights_id; R_TRY(ncmContentStorageGetRightsIdFromContentId(std::addressof(this->srv), std::addressof(rights_id), Convert(content_id))); @@ -160,35 +160,36 @@ namespace ams::ncm { return ResultSuccess(); } - virtual Result WriteContentForDebug(ContentId content_id, s64 offset, sf::InBuffer data) override { + Result WriteContentForDebug(ContentId content_id, s64 offset, sf::InBuffer data) { return ncmContentStorageWriteContentForDebug(std::addressof(this->srv), Convert(content_id), offset, data.GetPointer(), data.GetSize()); } - virtual Result GetFreeSpaceSize(sf::Out out_size) override { + Result GetFreeSpaceSize(sf::Out out_size) { return ncmContentStorageGetFreeSpaceSize(std::addressof(this->srv), out_size.GetPointer()); } - virtual Result GetTotalSpaceSize(sf::Out out_size) override { + Result GetTotalSpaceSize(sf::Out out_size) { return ncmContentStorageGetTotalSpaceSize(std::addressof(this->srv), out_size.GetPointer()); } - virtual Result FlushPlaceHolder() override { + Result FlushPlaceHolder() { return ncmContentStorageFlushPlaceHolder(std::addressof(this->srv)); } - virtual Result GetSizeFromPlaceHolderId(sf::Out out_size, PlaceHolderId placeholder_id) override { + Result GetSizeFromPlaceHolderId(sf::Out out_size, PlaceHolderId placeholder_id) { return ncmContentStorageGetSizeFromPlaceHolderId(std::addressof(this->srv), out_size.GetPointer(), Convert(placeholder_id)); } - virtual Result RepairInvalidFileAttribute() override { + Result RepairInvalidFileAttribute() { return ncmContentStorageRepairInvalidFileAttribute(std::addressof(this->srv)); } - virtual Result GetRightsIdFromPlaceHolderIdWithCache(sf::Out out_rights_id, PlaceHolderId placeholder_id, ContentId cache_content_id) override { + Result GetRightsIdFromPlaceHolderIdWithCache(sf::Out out_rights_id, PlaceHolderId placeholder_id, ContentId cache_content_id) { static_assert(sizeof(::NcmRightsId) == sizeof(ncm::RightsId)); ::NcmRightsId *out = reinterpret_cast<::NcmRightsId *>(out_rights_id.GetPointer()); return ncmContentStorageGetRightsIdFromPlaceHolderIdWithCache(std::addressof(this->srv), out, Convert(placeholder_id), Convert(cache_content_id)); } }; + static_assert(ncm::IsIContentStorage); } diff --git a/libraries/libstratosphere/source/pgl/pgl_remote_event_observer.hpp b/libraries/libstratosphere/source/pgl/pgl_remote_event_observer.hpp index c7cf0d844..418ec6e99 100644 --- a/libraries/libstratosphere/source/pgl/pgl_remote_event_observer.hpp +++ b/libraries/libstratosphere/source/pgl/pgl_remote_event_observer.hpp @@ -18,28 +18,29 @@ namespace ams::pgl { - class RemoteEventObserver final : public pgl::sf::IEventObserver { + class RemoteEventObserver final { NON_COPYABLE(RemoteEventObserver); NON_MOVEABLE(RemoteEventObserver); private: ::PglEventObserver observer; public: constexpr RemoteEventObserver(const ::PglEventObserver &o) : observer(o) { /* ... */ } - virtual ~RemoteEventObserver() override { + ~RemoteEventObserver() { ::pglEventObserverClose(std::addressof(this->observer)); } - virtual Result GetProcessEventHandle(ams::sf::OutCopyHandle out) override { + Result GetProcessEventHandle(ams::sf::OutCopyHandle out) { ::Event ev; R_TRY(::pglEventObserverGetProcessEvent(std::addressof(this->observer), std::addressof(ev))); out.SetValue(ev.revent); return ResultSuccess(); } - virtual Result GetProcessEventInfo(ams::sf::Out out) override { + Result GetProcessEventInfo(ams::sf::Out out) { static_assert(sizeof(*out.GetPointer()) == sizeof(::PmProcessEventInfo)); return ::pglEventObserverGetProcessEventInfo(std::addressof(this->observer), reinterpret_cast<::PmProcessEventInfo *>(out.GetPointer())); } }; + static_assert(pgl::sf::IsIEventObserver); } \ No newline at end of file diff --git a/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp b/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp index 66c2bc2d0..742292091 100644 --- a/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp +++ b/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp @@ -79,7 +79,7 @@ namespace ams::pgl { ::PglEventObserver obs; R_TRY(::pglGetEventObserver(std::addressof(obs))); - auto remote_observer = std::make_shared(obs); + auto remote_observer = ams::sf::MakeShared(obs); AMS_ABORT_UNLESS(remote_observer != nullptr); *out = pgl::EventObserver(remote_observer); diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_event_observer.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_event_observer.cpp index daaa1e0f5..5b7bacec9 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_event_observer.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_event_observer.cpp @@ -66,13 +66,13 @@ namespace ams::pgl::srv { this->event.Signal(); } - Result EventObserverInterface::GetProcessEventHandle(ams::sf::OutCopyHandle out) { - out.SetValue(GetReference(this->observer).GetEvent().GetReadableHandle()); + Result ShellEventObserver::GetProcessEventHandle(ams::sf::OutCopyHandle out) { + out.SetValue(this->GetEvent().GetReadableHandle()); return ResultSuccess(); } - Result EventObserverInterface::GetProcessEventInfo(ams::sf::Out out) { - return GetReference(this->observer).PopEventInfo(out.GetPointer()); + Result ShellEventObserver::GetProcessEventInfo(ams::sf::Out out) { + return this->PopEventInfo(out.GetPointer()); } -} \ No newline at end of file +} diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_event_observer.hpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_event_observer.hpp index 29918a8c3..30387526b 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_event_observer.hpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_event_observer.hpp @@ -56,23 +56,10 @@ namespace ams::pgl::srv { Result PopEventInfo(pm::ProcessEventInfo *out); virtual void Notify(const pm::ProcessEventInfo &info) override final; - }; - class EventObserverInterface final : public pgl::sf::IEventObserver { - private: - TYPED_STORAGE(ShellEventObserver) observer; - public: - EventObserverInterface() { - std::memset(std::addressof(this->observer), 0, sizeof(this->observer)); - new (GetPointer(this->observer)) ShellEventObserver; - } - - ~EventObserverInterface() { - GetReference(this->observer).~ShellEventObserver(); - } - public: - virtual Result GetProcessEventHandle(ams::sf::OutCopyHandle out) override final; - virtual Result GetProcessEventInfo(ams::sf::Out out) override final; + Result GetProcessEventHandle(ams::sf::OutCopyHandle out); + Result GetProcessEventInfo(ams::sf::Out out); }; + static_assert(pgl::sf::IsIEventObserver); } diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp index 614488e25..81b2641d5 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp @@ -69,20 +69,22 @@ namespace ams::pgl::srv { } Result ShellInterface::GetShellEventObserver(ams::sf::Out> out) { + using Interface = typename pgl::sf::IEventObserver::ImplHolder; + /* Allocate a new interface. */ - auto *observer_memory = this->memory_resource->Allocate(sizeof(EventObserverInterface), alignof(EventObserverInterface)); + auto *observer_memory = this->memory_resource->Allocate(sizeof(Interface), alignof(Interface)); AMS_ABORT_UNLESS(observer_memory != nullptr); /* Create the interface object. */ - new (observer_memory) EventObserverInterface; + new (observer_memory) Interface; /* Set the output. */ - out.SetValue(std::shared_ptr(reinterpret_cast(observer_memory), [&](EventObserverInterface *obj) { + out.SetValue(std::shared_ptr(reinterpret_cast(observer_memory), [&](Interface *obj) { /* Destroy the object. */ - obj->~EventObserverInterface(); + obj->~Interface(); /* Custom deleter: use the memory resource to free. */ - this->memory_resource->Deallocate(obj, sizeof(EventObserverInterface), alignof(EventObserverInterface)); + this->memory_resource->Deallocate(obj, sizeof(Interface), alignof(Interface)); })); return ResultSuccess(); } diff --git a/libraries/libstratosphere/source/psc/psc_pm_module.os.horizon.cpp b/libraries/libstratosphere/source/psc/psc_pm_module.os.horizon.cpp index 146e5e47a..f9c10cc06 100644 --- a/libraries/libstratosphere/source/psc/psc_pm_module.os.horizon.cpp +++ b/libraries/libstratosphere/source/psc/psc_pm_module.os.horizon.cpp @@ -34,7 +34,7 @@ namespace ams::psc { ::PscPmModule module; R_TRY(::pscmGetPmModule(std::addressof(module), static_cast<::PscPmModuleId>(mid), reinterpret_cast(dependencies), dependency_count, clear_mode == os::EventClearMode_AutoClear)); - this->intf = std::make_shared(module); + this->intf = ams::sf::MakeShared(module); this->system_event.AttachReadableHandle(module.event.revent, false, clear_mode); this->initialized = true; return ResultSuccess(); diff --git a/libraries/libstratosphere/source/psc/psc_remote_pm_module.hpp b/libraries/libstratosphere/source/psc/psc_remote_pm_module.hpp index ff6451a62..6afc613fc 100644 --- a/libraries/libstratosphere/source/psc/psc_remote_pm_module.hpp +++ b/libraries/libstratosphere/source/psc/psc_remote_pm_module.hpp @@ -18,41 +18,42 @@ namespace ams::psc { - class RemotePmModule final : public psc::sf::IPmModule { + class RemotePmModule final { NON_COPYABLE(RemotePmModule); NON_MOVEABLE(RemotePmModule); private: ::PscPmModule module; public: constexpr RemotePmModule(const ::PscPmModule &m) : module(m) { /* ... */ } - virtual ~RemotePmModule() override { + ~RemotePmModule() { ::pscPmModuleClose(std::addressof(this->module)); } - virtual Result Initialize(ams::sf::OutCopyHandle out, psc::PmModuleId module_id, const ams::sf::InBuffer &child_list) override final { + Result Initialize(ams::sf::OutCopyHandle out, psc::PmModuleId module_id, const ams::sf::InBuffer &child_list) { /* NOTE: This functionality is already implemented by the libnx command we use to instantiate the PscPmModule. */ AMS_ABORT(); } - virtual Result GetRequest(ams::sf::Out out_state, ams::sf::Out out_flags) override final { + Result GetRequest(ams::sf::Out out_state, ams::sf::Out out_flags) { static_assert(sizeof(PmState) == sizeof(::PscPmState)); static_assert(sizeof(PmFlagSet) == sizeof(u32)); return ::pscPmModuleGetRequest(std::addressof(this->module), reinterpret_cast<::PscPmState *>(out_state.GetPointer()), reinterpret_cast(out_flags.GetPointer())); } - virtual Result Acknowledge() override final { + Result Acknowledge() { /* NOTE: libnx does not separate acknowledge/acknowledgeEx. */ return ::pscPmModuleAcknowledge(std::addressof(this->module), static_cast<::PscPmState>(0)); } - virtual Result Finalize() override final { + Result Finalize() { return ::pscPmModuleFinalize(std::addressof(this->module)); } - virtual Result AcknowledgeEx(PmState state) override final { + Result AcknowledgeEx(PmState state) { static_assert(sizeof(state) == sizeof(::PscPmState)); return ::pscPmModuleAcknowledge(std::addressof(this->module), static_cast<::PscPmState>(state)); } }; + static_assert(psc::sf::IsIPmModule); } \ No newline at end of file diff --git a/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp index 29b3e5c56..ee6f9c18a 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp +++ b/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp @@ -20,11 +20,13 @@ namespace ams::sf::hipc::impl { namespace { - class MitmQueryService : public IServiceObject { - private: - enum class CommandId { - ShouldMitm = 65000, - }; + #define AMS_SF_HIPC_IMPL_I_MITM_QUERY_SERVICE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, ShouldMitm, (sf::Out out, const sm::MitmProcessInfo &client_info)) + + AMS_SF_DEFINE_INTERFACE(IMitmQueryService, AMS_SF_HIPC_IMPL_I_MITM_QUERY_SERVICE_INTERFACE_INFO) + + + class MitmQueryService { private: ServerManagerBase::MitmQueryFunction query_function; public: @@ -33,11 +35,8 @@ namespace ams::sf::hipc::impl { void ShouldMitm(sf::Out out, const sm::MitmProcessInfo &client_info) { out.SetValue(this->query_function(client_info)); } - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(ShouldMitm), - }; }; + static_assert(IsIMitmQueryService); /* Globals. */ os::Mutex g_query_server_lock(false); @@ -66,7 +65,7 @@ namespace ams::sf::hipc::impl { g_constructed_server = true; } - R_ABORT_UNLESS(GetPointer(g_query_server_storage)->RegisterSession(query_handle, cmif::ServiceObjectHolder(std::make_shared(query_func)))); + R_ABORT_UNLESS(GetPointer(g_query_server_storage)->RegisterSession(query_handle, cmif::ServiceObjectHolder(sf::MakeShared(query_func)))); if (AMS_UNLIKELY(!g_registered_any)) { R_ABORT_UNLESS(os::CreateThread(std::addressof(g_query_server_process_thread), &QueryServerProcessThreadMain, GetPointer(g_query_server_storage), g_server_process_thread_stack, sizeof(g_server_process_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(mitm_sf, QueryServerProcessThread))); diff --git a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp index 2177bd237..20578d12d 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp +++ b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp @@ -19,15 +19,16 @@ namespace ams::sf::hipc { namespace impl { - class HipcManager : public IServiceObject { - private: - enum class CommandId { - ConvertCurrentObjectToDomain = 0, - CopyFromCurrentDomain = 1, - CloneCurrentObject = 2, - QueryPointerBufferSize = 3, - CloneCurrentObjectEx = 4, - }; + #define AMS_SF_HIPC_IMPL_I_HIPC_MANAGER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, ConvertCurrentObjectToDomain, (ams::sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, CopyFromCurrentDomain, (ams::sf::OutMoveHandle out, ams::sf::cmif::DomainObjectId object_id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, CloneCurrentObject, (ams::sf::OutMoveHandle out)) \ + AMS_SF_METHOD_INFO(C, H, 3, void, QueryPointerBufferSize, (ams::sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, CloneCurrentObjectEx, (ams::sf::OutMoveHandle out, u32 tag)) + + AMS_SF_DEFINE_INTERFACE(IHipcManager, AMS_SF_HIPC_IMPL_I_HIPC_MANAGER_INTERFACE_INFO) + + class HipcManager final { private: ServerDomainSessionManager *manager; ServerSession *session; @@ -150,16 +151,8 @@ namespace ams::sf::hipc { Result CloneCurrentObjectEx(sf::OutMoveHandle out, u32 tag) { return this->CloneCurrentObjectImpl(out.GetHandlePointer(), this->manager->GetSessionManagerByTag(tag)); } - - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(ConvertCurrentObjectToDomain), - MAKE_SERVICE_COMMAND_META(CopyFromCurrentDomain), - MAKE_SERVICE_COMMAND_META(CloneCurrentObject), - MAKE_SERVICE_COMMAND_META(QueryPointerBufferSize), - MAKE_SERVICE_COMMAND_META(CloneCurrentObjectEx), - }; }; + static_assert(IsIHipcManager); } @@ -168,7 +161,7 @@ namespace ams::sf::hipc { /* Note: This is safe, as no additional references to the hipc manager can ever be stored. */ /* The shared pointer to stack object is definitely gross, though. */ impl::HipcManager hipc_manager(this, session); - return this->DispatchRequest(cmif::ServiceObjectHolder(std::move(ServiceObjectTraits::SharedPointerHelper::GetEmptyDeleteSharedPointer(&hipc_manager))), session, in_message, out_message); + return this->DispatchRequest(cmif::ServiceObjectHolder(sf::GetSharedPointerTo(hipc_manager)), session, in_message, out_message); } } diff --git a/libraries/libstratosphere/source/spl/smc/spl_smc.cpp b/libraries/libstratosphere/source/spl/smc/spl_smc.cpp index 232be11e8..02934c7a9 100644 --- a/libraries/libstratosphere/source/spl/smc/spl_smc.cpp +++ b/libraries/libstratosphere/source/spl/smc/spl_smc.cpp @@ -17,11 +17,11 @@ namespace ams::spl::smc { - Result SetConfig(SplConfigItem which, const u64 *value, size_t num_qwords) { + Result SetConfig(spl::ConfigItem which, const u64 *value, size_t num_qwords) { SecmonArgs args; args.X[0] = static_cast(FunctionId::SetConfig); - args.X[1] = which; + args.X[1] = static_cast(which); args.X[2] = 0; for (size_t i = 0; i < std::min(size_t(4), num_qwords); i++) { args.X[3 + i] = value[i]; @@ -31,11 +31,11 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result GetConfig(u64 *out, size_t num_qwords, SplConfigItem which) { + Result GetConfig(u64 *out, size_t num_qwords, spl::ConfigItem which) { SecmonArgs args; args.X[0] = static_cast(FunctionId::GetConfig); - args.X[1] = which; + args.X[1] = static_cast(which); svcCallSecureMonitor(&args); for (size_t i = 0; i < std::min(size_t(4), num_qwords); i++) { @@ -44,10 +44,10 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result CheckStatus(Result *out, AsyncOperationKey op) { + Result GetResult(Result *out, AsyncOperationKey op) { SecmonArgs args; - args.X[0] = static_cast(FunctionId::CheckStatus); + args.X[0] = static_cast(FunctionId::GetResult); args.X[1] = op.value; svcCallSecureMonitor(&args); @@ -55,10 +55,10 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result GetResult(Result *out, void *out_buf, size_t out_buf_size, AsyncOperationKey op) { + Result GetResultData(Result *out, void *out_buf, size_t out_buf_size, AsyncOperationKey op) { SecmonArgs args; - args.X[0] = static_cast(FunctionId::GetResult); + args.X[0] = static_cast(FunctionId::GetResultData); args.X[1] = op.value; args.X[2] = reinterpret_cast(out_buf); args.X[3] = out_buf_size; @@ -68,10 +68,10 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result ExpMod(AsyncOperationKey *out_op, const void *base, const void *exp, size_t exp_size, const void *mod) { + Result ModularExponentiate(AsyncOperationKey *out_op, const void *base, const void *exp, size_t exp_size, const void *mod) { SecmonArgs args; - args.X[0] = static_cast(FunctionId::ExpMod); + args.X[0] = static_cast(FunctionId::ModularExponentiate); args.X[1] = reinterpret_cast(base); args.X[2] = reinterpret_cast(exp); args.X[3] = reinterpret_cast(mod); @@ -124,10 +124,10 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result CryptAes(AsyncOperationKey *out_op, u32 mode, const IvCtr &iv_ctr, u32 dst_addr, u32 src_addr, size_t size) { + Result ComputeAes(AsyncOperationKey *out_op, u32 mode, const IvCtr &iv_ctr, u32 dst_addr, u32 src_addr, size_t size) { SecmonArgs args; - args.X[0] = static_cast(FunctionId::CryptAes); + args.X[0] = static_cast(FunctionId::ComputeAes); args.X[1] = mode; args.X[2] = iv_ctr.data64[0]; args.X[3] = iv_ctr.data64[1]; @@ -169,10 +169,10 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result ReEncryptRsaPrivateKey(void *data, size_t size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option) { + Result ReencryptDeviceUniqueData(void *data, size_t size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option) { SecmonArgs args; - args.X[0] = static_cast(FunctionId::ReEncryptRsaPrivateKey); + args.X[0] = static_cast(FunctionId::ReencryptDeviceUniqueData); args.X[1] = reinterpret_cast(&access_key_dec); args.X[2] = reinterpret_cast(&access_key_enc); args.X[3] = option; @@ -185,10 +185,10 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result DecryptOrImportRsaPrivateKey(void *data, size_t size, const AccessKey &access_key, const KeySource &source, DecryptOrImportMode mode) { + Result DecryptDeviceUniqueData(void *data, size_t size, const AccessKey &access_key, const KeySource &source, DeviceUniqueDataMode mode) { SecmonArgs args; - args.X[0] = static_cast(FunctionId::DecryptOrImportRsaPrivateKey); + args.X[0] = static_cast(FunctionId::DecryptDeviceUniqueData); args.X[1] = access_key.data64[0]; args.X[2] = access_key.data64[1]; args.X[3] = static_cast(mode); @@ -201,10 +201,10 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result SecureExpMod(AsyncOperationKey *out_op, const void *base, const void *mod, SecureExpModMode mode) { + Result ModularExponentiateWithStorageKey(AsyncOperationKey *out_op, const void *base, const void *mod, ModularExponentiateWithStorageKeyMode mode) { SecmonArgs args; - args.X[0] = static_cast(FunctionId::SecureExpMod); + args.X[0] = static_cast(FunctionId::ModularExponentiateWithStorageKey); args.X[1] = reinterpret_cast(base); args.X[2] = reinterpret_cast(mod); args.X[3] = static_cast(mode); @@ -214,10 +214,10 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result UnwrapTitleKey(AsyncOperationKey *out_op, const void *base, const void *mod, const void *label_digest, size_t label_digest_size, u32 option) { + Result PrepareEsDeviceUniqueKey(AsyncOperationKey *out_op, const void *base, const void *mod, const void *label_digest, size_t label_digest_size, u32 option) { SecmonArgs args; - args.X[0] = static_cast(FunctionId::UnwrapTitleKey); + args.X[0] = static_cast(FunctionId::PrepareEsDeviceUniqueKey); args.X[1] = reinterpret_cast(base); args.X[2] = reinterpret_cast(mod); std::memset(&args.X[3], 0, 4 * sizeof(args.X[3])); @@ -229,10 +229,10 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result LoadTitleKey(u32 keyslot, const AccessKey &access_key) { + Result LoadPreparedAesKey(u32 keyslot, const AccessKey &access_key) { SecmonArgs args; - args.X[0] = static_cast(FunctionId::LoadTitleKey); + args.X[0] = static_cast(FunctionId::LoadPreparedAesKey); args.X[1] = keyslot; args.X[2] = access_key.data64[0]; args.X[3] = access_key.data64[1]; @@ -241,10 +241,10 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result UnwrapCommonTitleKey(AccessKey *out, const KeySource &source, u32 generation) { + Result PrepareCommonEsTitleKey(AccessKey *out, const KeySource &source, u32 generation) { SecmonArgs args; - args.X[0] = static_cast(FunctionId::UnwrapCommonTitleKey); + args.X[0] = static_cast(FunctionId::PrepareCommonEsTitleKey); args.X[1] = source.data64[0]; args.X[2] = source.data64[1]; args.X[3] = generation; @@ -257,10 +257,10 @@ namespace ams::spl::smc { /* Deprecated functions. */ - Result ImportEsKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) { + Result LoadEsDeviceKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) { SecmonArgs args; - args.X[0] = static_cast(FunctionId::ImportEsKey); + args.X[0] = static_cast(FunctionId::LoadEsDeviceKey); args.X[1] = access_key.data64[0]; args.X[2] = access_key.data64[1]; args.X[3] = option; @@ -273,10 +273,10 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result DecryptRsaPrivateKey(size_t *out_size, void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) { + Result DecryptDeviceUniqueData(size_t *out_size, void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) { SecmonArgs args; - args.X[0] = static_cast(FunctionId::DecryptRsaPrivateKey); + args.X[0] = static_cast(FunctionId::DecryptDeviceUniqueData); args.X[1] = access_key.data64[0]; args.X[2] = access_key.data64[1]; args.X[3] = option; @@ -290,10 +290,10 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result ImportSecureExpModKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) { + Result DecryptAndStoreGcKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) { SecmonArgs args; - args.X[0] = static_cast(FunctionId::ImportSecureExpModKey); + args.X[0] = static_cast(FunctionId::DecryptAndStoreGcKey); args.X[1] = access_key.data64[0]; args.X[2] = access_key.data64[1]; args.X[3] = option; @@ -348,19 +348,6 @@ namespace ams::spl::smc { return static_cast(args.X[0]); } - Result AtmosphereWriteAddress(void *dst, const void *src, size_t size) { - AMS_ABORT_UNLESS(size <= sizeof(u64)); - - SecmonArgs args; - args.X[0] = static_cast(FunctionId::AtmosphereWriteAddress); - args.X[1] = reinterpret_cast(dst); - __builtin_memcpy(&args.X[1], src, size); - args.X[3] = size; - svcCallSecureMonitor(&args); - - return static_cast(args.X[0]); - } - Result AtmosphereGetEmummcConfig(void *out_config, void *out_paths, u32 storage_id) { const u64 paths = reinterpret_cast(out_paths); AMS_ABORT_UNLESS(util::IsAligned(paths, os::MemoryPageSize)); diff --git a/libraries/libstratosphere/source/spl/spl_api.cpp b/libraries/libstratosphere/source/spl/spl_api.cpp index 6e8240244..f53b75379 100644 --- a/libraries/libstratosphere/source/spl/spl_api.cpp +++ b/libraries/libstratosphere/source/spl/spl_api.cpp @@ -63,7 +63,7 @@ namespace ams::spl { auto is_event_initialized = false; while (true) { R_TRY_CATCH(static_cast<::ams::Result>(f())) { - R_CATCH(spl::ResultOutOfKeyslots) { + R_CATCH(spl::ResultOutOfKeySlots) { if (!is_event_initialized) { GetAesKeySlotAvailableEvent(std::addressof(event)); is_event_initialized = true; diff --git a/libraries/libvapours/include/vapours/results/spl_results.hpp b/libraries/libvapours/include/vapours/results/spl_results.hpp index 8ea794825..f8d857e19 100644 --- a/libraries/libvapours/include/vapours/results/spl_results.hpp +++ b/libraries/libvapours/include/vapours/results/spl_results.hpp @@ -28,13 +28,14 @@ namespace ams::spl { R_DEFINE_ERROR_RESULT(SecureMonitorNoAsyncOperation, 4); R_DEFINE_ERROR_RESULT(SecureMonitorInvalidAsyncOperation, 5); R_DEFINE_ERROR_RESULT(SecureMonitorNotPermitted, 6); + R_DEFINE_ERROR_RESULT(SecureMonitorNotInitialized, 7); R_DEFINE_ERROR_RESULT(InvalidSize, 100); R_DEFINE_ERROR_RESULT(UnknownSecureMonitorError, 101); R_DEFINE_ERROR_RESULT(DecryptionFailed, 102); - R_DEFINE_ERROR_RESULT(OutOfKeyslots, 104); - R_DEFINE_ERROR_RESULT(InvalidKeyslot, 105); + R_DEFINE_ERROR_RESULT(OutOfKeySlots, 104); + R_DEFINE_ERROR_RESULT(InvalidKeySlot, 105); R_DEFINE_ERROR_RESULT(BootReasonAlreadySet, 106); R_DEFINE_ERROR_RESULT(BootReasonNotSet, 107); R_DEFINE_ERROR_RESULT(InvalidArgument, 108); diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_module.cpp b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_module.cpp index e2733d18f..06a45b876 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_module.cpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_module.cpp @@ -37,7 +37,7 @@ namespace ams::mitm::bpc_ams { { Handle bpcams_h; R_ABORT_UNLESS(svcManageNamedPort(&bpcams_h, AtmosphereServiceName.name, AtmosphereMaxSessions)); - g_server_manager.RegisterServer(bpcams_h); + g_server_manager.RegisterServer(bpcams_h); } /* Loop forever, servicing our services. */ diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.hpp b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.hpp index 7a00d6de5..234b92c91 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.hpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.hpp @@ -18,20 +18,21 @@ namespace ams::mitm::bpc { - class AtmosphereService final : public sf::IServiceObject { - private: - enum class CommandId { - RebootToFatalError = 65000, - SetRebootPayload = 65001, - }; - private: + namespace impl { + + #define AMS_BPC_MITM_ATMOSPHERE_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, RebootToFatalError, (const ams::FatalErrorContext &ctx)) \ + AMS_SF_METHOD_INFO(C, H, 65001, void, SetRebootPayload, (const ams::sf::InBuffer &payload)) + + AMS_SF_DEFINE_INTERFACE(IAtmosphereInterface, AMS_BPC_MITM_ATMOSPHERE_INTERFACE_INTERFACE_INFO) + + } + + class AtmosphereService final { + public: void RebootToFatalError(const ams::FatalErrorContext &ctx); void SetRebootPayload(const ams::sf::InBuffer &payload); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(RebootToFatalError), - MAKE_SERVICE_COMMAND_META(SetRebootPayload), - }; }; + static_assert(impl::IsIAtmosphereInterface); } diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpc_mitm_service.hpp b/stratosphere/ams_mitm/source/bpc_mitm/bpc_mitm_service.hpp index b4bd1d4bd..de88296f5 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpc_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpc_mitm_service.hpp @@ -18,12 +18,19 @@ namespace ams::mitm::bpc { - class BpcMitmService : public sf::IMitmServiceObject { - private: - enum class CommandId { - ShutdownSystem = 0, - RebootSystem = 1, - }; + namespace impl { + + #define AMS_BPC_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, ShutdownSystem, ()) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, RebootSystem, ()) + + AMS_SF_DEFINE_MITM_INTERFACE(IBpcMitmInterface, AMS_BPC_MITM_INTERFACE_INFO) + + } + + class BpcMitmService : public sf::MitmServiceImplBase { + public: + using MitmServiceImplBase::MitmServiceImplBase; public: static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { /* We will mitm: @@ -36,16 +43,10 @@ namespace ams::mitm::bpc { client_info.override_status.IsHbl(); } public: - SF_MITM_SERVICE_OBJECT_CTOR(BpcMitmService) { /* ... */ } - protected: /* Overridden commands. */ Result ShutdownSystem(); Result RebootSystem(); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(ShutdownSystem), - MAKE_SERVICE_COMMAND_META(RebootSystem), - }; }; + static_assert(impl::IsIBpcMitmInterface); } diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_module.cpp b/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_module.cpp index 36f3934a0..1ea2b7eb9 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_module.cpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_module.cpp @@ -39,7 +39,7 @@ namespace ams::mitm::bpc { /* Create bpc mitm. */ const sm::ServiceName service_name = (hos::GetVersion() >= hos::Version_2_0_0) ? MitmServiceName : DeprecatedMitmServiceName; - R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(service_name)); + R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(service_name))); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp index 60aec454e..5a3525fcc 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp @@ -35,9 +35,9 @@ namespace ams::mitm::fs { os::Mutex g_data_storage_lock(false); os::Mutex g_storage_cache_lock(false); - std::unordered_map> g_storage_cache; + std::unordered_map> g_storage_cache; - std::shared_ptr GetStorageCacheEntry(ncm::ProgramId program_id) { + std::shared_ptr GetStorageCacheEntry(ncm::ProgramId program_id) { std::scoped_lock lk(g_storage_cache_lock); auto it = g_storage_cache.find(static_cast(program_id)); @@ -48,7 +48,7 @@ namespace ams::mitm::fs { return it->second.lock(); } - void SetStorageCacheEntry(ncm::ProgramId program_id, std::shared_ptr *new_intf) { + void SetStorageCacheEntry(ncm::ProgramId program_id, std::shared_ptr *new_intf) { std::scoped_lock lk(g_storage_cache_lock); auto it = g_storage_cache.find(static_cast(program_id)); @@ -69,7 +69,17 @@ namespace ams::mitm::fs { return (tmp != 0); } - Result OpenHblWebContentFileSystem(sf::Out> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type) { + template + constexpr ALWAYS_INLINE auto MakeSharedFileSystem(Arguments &&... args) { + return sf::MakeShared(std::forward(args)...); + } + + template + constexpr ALWAYS_INLINE auto MakeSharedStorage(Arguments &&... args) { + return sf::MakeShared(std::forward(args)...); + } + + Result OpenHblWebContentFileSystem(sf::Out> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type) { /* Verify eligibility. */ bool is_hbl; R_UNLESS(R_SUCCEEDED(pm::info::IsHblProgramId(&is_hbl, program_id)), sm::mitm::ResultShouldForwardToSession()); @@ -88,11 +98,11 @@ namespace ams::mitm::fs { const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(&sd_fs.s)}; std::unique_ptr sd_ifs = std::make_unique(sd_fs); - out.SetValue(std::make_shared(std::make_shared(std::make_unique(std::move(sd_ifs), AtmosphereHblWebContentDir)), false), target_object_id); + out.SetValue(MakeSharedFileSystem(std::make_shared(std::make_unique(std::move(sd_ifs), AtmosphereHblWebContentDir)), false), target_object_id); return ResultSuccess(); } - Result OpenProgramSpecificWebContentFileSystem(sf::Out> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type, Service *fwd, const fssrv::sf::Path *path, bool with_id) { + Result OpenProgramSpecificWebContentFileSystem(sf::Out> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type, Service *fwd, const fssrv::sf::Path *path, bool with_id) { /* Directory must exist. */ { FsDir d; @@ -132,13 +142,13 @@ namespace ams::mitm::fs { new_fs = std::make_shared(std::move(subdir_fs)); } - out.SetValue(std::make_shared(std::move(new_fs), false), target_object_id); + out.SetValue(MakeSharedFileSystem(std::move(new_fs), false), target_object_id); } return ResultSuccess(); } - Result OpenWebContentFileSystem(sf::Out> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type, Service *fwd, const fssrv::sf::Path *path, bool with_id, bool try_program_specific) { + Result OpenWebContentFileSystem(sf::Out> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type, Service *fwd, const fssrv::sf::Path *path, bool with_id, bool try_program_specific) { /* Check first that we're a web applet opening web content. */ R_UNLESS(ncm::IsWebAppletId(client_program_id), sm::mitm::ResultShouldForwardToSession()); R_UNLESS(filesystem_type == FsFileSystemType_ContentManual, sm::mitm::ResultShouldForwardToSession()); @@ -155,15 +165,15 @@ namespace ams::mitm::fs { } - Result FsMitmService::OpenFileSystemWithPatch(sf::Out> out, ncm::ProgramId program_id, u32 _filesystem_type) { + Result FsMitmService::OpenFileSystemWithPatch(sf::Out> out, ncm::ProgramId program_id, u32 _filesystem_type) { return OpenWebContentFileSystem(out, this->client_info.program_id, program_id, static_cast(_filesystem_type), this->forward_service.get(), nullptr, false, this->client_info.override_status.IsProgramSpecific()); } - Result FsMitmService::OpenFileSystemWithId(sf::Out> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type) { + Result FsMitmService::OpenFileSystemWithId(sf::Out> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type) { return OpenWebContentFileSystem(out, this->client_info.program_id, program_id, static_cast(_filesystem_type), this->forward_service.get(), std::addressof(path), true, this->client_info.override_status.IsProgramSpecific()); } - Result FsMitmService::OpenSdCardFileSystem(sf::Out> out) { + Result FsMitmService::OpenSdCardFileSystem(sf::Out> out) { /* We only care about redirecting this for NS/emummc. */ R_UNLESS(this->client_info.program_id == ncm::SystemProgramId::Ns, sm::mitm::ResultShouldForwardToSession()); R_UNLESS(emummc::IsActive(), sm::mitm::ResultShouldForwardToSession()); @@ -175,11 +185,11 @@ namespace ams::mitm::fs { /* Return output filesystem. */ std::shared_ptr redir_fs = std::make_shared(std::make_shared(sd_fs), "/Nintendo", emummc::GetNintendoDirPath()); - out.SetValue(std::make_shared(std::move(redir_fs), false), target_object_id); + out.SetValue(MakeSharedFileSystem(std::move(redir_fs), false), target_object_id); return ResultSuccess(); } - Result FsMitmService::OpenSaveDataFileSystem(sf::Out> out, u8 _space_id, const fs::SaveDataAttribute &attribute) { + Result FsMitmService::OpenSaveDataFileSystem(sf::Out> out, u8 _space_id, const fs::SaveDataAttribute &attribute) { /* We only want to intercept saves for games, right now. */ const bool is_game_or_hbl = this->client_info.override_status.IsHbl() || ncm::IsApplicationId(this->client_info.program_id); R_UNLESS(is_game_or_hbl, sm::mitm::ResultShouldForwardToSession()); @@ -240,11 +250,11 @@ namespace ams::mitm::fs { } /* Set output. */ - out.SetValue(std::make_shared(std::move(dirsave_ifs), false), target_object_id); + out.SetValue(MakeSharedFileSystem(std::move(dirsave_ifs), false), target_object_id); return ResultSuccess(); } - Result FsMitmService::OpenBisStorage(sf::Out> out, u32 _bis_partition_id) { + Result FsMitmService::OpenBisStorage(sf::Out> out, u32 _bis_partition_id) { const ::FsBisPartitionId bis_partition_id = static_cast<::FsBisPartitionId>(_bis_partition_id); /* Try to open a storage for the partition. */ @@ -265,23 +275,23 @@ namespace ams::mitm::fs { /* Set output storage. */ if (bis_partition_id == FsBisPartitionId_BootPartition1Root) { - out.SetValue(std::make_shared(new Boot0Storage(bis_storage, this->client_info)), target_object_id); + out.SetValue(MakeSharedStorage(new Boot0Storage(bis_storage, this->client_info)), target_object_id); } else if (bis_partition_id == FsBisPartitionId_CalibrationBinary) { - out.SetValue(std::make_shared(new CalibrationBinaryStorage(bis_storage, this->client_info)), target_object_id); + out.SetValue(MakeSharedStorage(new CalibrationBinaryStorage(bis_storage, this->client_info)), target_object_id); } else { if (can_write_bis || can_write_bis_for_choi_support) { /* We can write, so create a writable storage. */ - out.SetValue(std::make_shared(new RemoteStorage(bis_storage)), target_object_id); + out.SetValue(MakeSharedStorage(new RemoteStorage(bis_storage)), target_object_id); } else { /* We can only read, so create a readable storage. */ - out.SetValue(std::make_shared(new ReadOnlyStorageAdapter(new RemoteStorage(bis_storage))), target_object_id); + out.SetValue(MakeSharedStorage(new ReadOnlyStorageAdapter(new RemoteStorage(bis_storage))), target_object_id); } } return ResultSuccess(); } - Result FsMitmService::OpenDataStorageByCurrentProcess(sf::Out> out) { + Result FsMitmService::OpenDataStorageByCurrentProcess(sf::Out> out) { /* Only mitm if we should override contents for the current process. */ R_UNLESS(this->client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession()); @@ -298,7 +308,7 @@ namespace ams::mitm::fs { /* Try to get a storage from the cache. */ { - std::shared_ptr cached_storage = GetStorageCacheEntry(this->client_info.program_id); + std::shared_ptr cached_storage = GetStorageCacheEntry(this->client_info.program_id); if (cached_storage != nullptr) { out.SetValue(std::move(cached_storage), target_object_id); return ResultSuccess(); @@ -307,18 +317,18 @@ namespace ams::mitm::fs { /* Make a new layered romfs, and cache to storage. */ { - std::shared_ptr new_storage_intf = nullptr; + std::shared_ptr new_storage_intf = nullptr; /* Create the layered storage. */ FsFile data_file; if (R_SUCCEEDED(OpenAtmosphereSdFile(&data_file, this->client_info.program_id, "romfs.bin", OpenMode_Read))) { auto layered_storage = std::make_shared(std::make_unique(new RemoteStorage(data_storage)), std::make_unique(new FileStorage(new RemoteFile(data_file))), this->client_info.program_id); layered_storage->BeginInitialize(); - new_storage_intf = std::make_shared(layered_storage); + new_storage_intf = MakeSharedStorage(layered_storage); } else { auto layered_storage = std::make_shared(std::make_unique(new RemoteStorage(data_storage)), nullptr, this->client_info.program_id); layered_storage->BeginInitialize(); - new_storage_intf = std::make_shared(layered_storage); + new_storage_intf = MakeSharedStorage(layered_storage); } SetStorageCacheEntry(this->client_info.program_id, &new_storage_intf); @@ -328,7 +338,7 @@ namespace ams::mitm::fs { return ResultSuccess(); } - Result FsMitmService::OpenDataStorageByDataId(sf::Out> out, ncm::DataId _data_id, u8 storage_id) { + Result FsMitmService::OpenDataStorageByDataId(sf::Out> out, ncm::DataId _data_id, u8 storage_id) { /* Only mitm if we should override contents for the current process. */ R_UNLESS(this->client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession()); @@ -348,7 +358,7 @@ namespace ams::mitm::fs { /* Try to get a storage from the cache. */ { - std::shared_ptr cached_storage = GetStorageCacheEntry(data_id); + std::shared_ptr cached_storage = GetStorageCacheEntry(data_id); if (cached_storage != nullptr) { out.SetValue(std::move(cached_storage), target_object_id); return ResultSuccess(); @@ -357,18 +367,18 @@ namespace ams::mitm::fs { /* Make a new layered romfs, and cache to storage. */ { - std::shared_ptr new_storage_intf = nullptr; + std::shared_ptr new_storage_intf = nullptr; /* Create the layered storage. */ FsFile data_file; if (R_SUCCEEDED(OpenAtmosphereSdFile(&data_file, data_id, "romfs.bin", OpenMode_Read))) { auto layered_storage = std::make_shared(std::make_unique(new RemoteStorage(data_storage)), std::make_unique(new FileStorage(new RemoteFile(data_file))), data_id); layered_storage->BeginInitialize(); - new_storage_intf = std::make_shared(layered_storage); + new_storage_intf = MakeSharedStorage(layered_storage); } else { auto layered_storage = std::make_shared(std::make_unique(new RemoteStorage(data_storage)), nullptr, data_id); layered_storage->BeginInitialize(); - new_storage_intf = std::make_shared(layered_storage); + new_storage_intf = MakeSharedStorage(layered_storage); } SetStorageCacheEntry(data_id, &new_storage_intf); diff --git a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp index 6ac10a225..d674b197a 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp @@ -20,30 +20,26 @@ namespace ams::mitm::fs { - using IStorageInterface = ams::fssrv::impl::StorageInterfaceAdapter; - using IFileSystemInterface = ams::fssrv::impl::FileSystemInterfaceAdapter; + namespace { - /* TODO: Consider re-enabling the mitm flag logic. */ + #define AMS_FS_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, OpenFileSystemWithPatch, (sf::Out> out, ncm::ProgramId program_id, u32 _filesystem_type), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, OpenFileSystemWithId, (sf::Out> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 18, Result, OpenSdCardFileSystem, (sf::Out> out)) \ + AMS_SF_METHOD_INFO(C, H, 51, Result, OpenSaveDataFileSystem, (sf::Out> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, OpenBisStorage, (sf::Out> out, u32 bis_partition_id)) \ + AMS_SF_METHOD_INFO(C, H, 200, Result, OpenDataStorageByCurrentProcess, (sf::Out> out)) \ + AMS_SF_METHOD_INFO(C, H, 202, Result, OpenDataStorageByDataId, (sf::Out> out, ncm::DataId data_id, u8 storage_id)) - class FsMitmService : public sf::IMitmServiceObject { - private: - enum class CommandId { - OpenFileSystemDeprecated = 0, + AMS_SF_DEFINE_MITM_INTERFACE(IFsMitmInterface, AMS_FS_MITM_INTERFACE_INFO) - SetCurrentProcess = 1, - OpenFileSystemWithPatch = 7, - OpenFileSystemWithId = 8, + } - OpenSdCardFileSystem = 18, - - OpenSaveDataFileSystem = 51, - - OpenBisStorage = 12, - OpenDataStorageByCurrentProcess = 200, - OpenDataStorageByDataId = 202, - }; + class FsMitmService : public sf::MitmServiceImplBase { public: - NX_CONSTEXPR bool ShouldMitmProgramId(const ncm::ProgramId program_id) { + using MitmServiceImplBase::MitmServiceImplBase; + public: + static constexpr ALWAYS_INLINE bool ShouldMitmProgramId(const ncm::ProgramId program_id) { /* We want to mitm everything that isn't a system-module. */ if (!ncm::IsSystemProgramId(program_id)) { return true; @@ -81,26 +77,14 @@ namespace ams::mitm::fs { return has_launched_qlaunch || ShouldMitmProgramId(client_info.program_id); } public: - SF_MITM_SERVICE_OBJECT_CTOR(FsMitmService) { /* ... */ } - protected: /* Overridden commands. */ - Result OpenFileSystemWithPatch(sf::Out> out, ncm::ProgramId program_id, u32 _filesystem_type); - Result OpenFileSystemWithId(sf::Out> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type); - Result OpenSdCardFileSystem(sf::Out> out); - Result OpenSaveDataFileSystem(sf::Out> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute); - Result OpenBisStorage(sf::Out> out, u32 bis_partition_id); - Result OpenDataStorageByCurrentProcess(sf::Out> out); - Result OpenDataStorageByDataId(sf::Out> out, ncm::DataId data_id, u8 storage_id); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(OpenFileSystemWithPatch, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(OpenFileSystemWithId, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(OpenSdCardFileSystem), - MAKE_SERVICE_COMMAND_META(OpenSaveDataFileSystem), - MAKE_SERVICE_COMMAND_META(OpenBisStorage), - MAKE_SERVICE_COMMAND_META(OpenDataStorageByCurrentProcess), - MAKE_SERVICE_COMMAND_META(OpenDataStorageByDataId), - }; + Result OpenFileSystemWithPatch(sf::Out> out, ncm::ProgramId program_id, u32 _filesystem_type); + Result OpenFileSystemWithId(sf::Out> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type); + Result OpenSdCardFileSystem(sf::Out> out); + Result OpenSaveDataFileSystem(sf::Out> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute); + Result OpenBisStorage(sf::Out> out, u32 bis_partition_id); + Result OpenDataStorageByCurrentProcess(sf::Out> out); + Result OpenDataStorageByDataId(sf::Out> out, ncm::DataId data_id, u8 storage_id); }; } diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_module.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_module.cpp index a8a709287..ad0894d5c 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_module.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_module.cpp @@ -78,7 +78,7 @@ namespace ams::mitm::fs { void MitmModule::ThreadFunction(void *arg) { /* Create fs mitm. */ - R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(MitmServiceName)); + R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(MitmServiceName))); /* Process for the server. */ ProcessForServerOnAllThreads(); diff --git a/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.hpp b/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.hpp index 71002d532..53beaf305 100644 --- a/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/hid_mitm/hid_mitm_service.hpp @@ -19,11 +19,18 @@ namespace ams::mitm::hid { - class HidMitmService : public sf::IMitmServiceObject { - private: - enum class CommandId { - SetSupportedNpadStyleSet = 100, - }; + namespace { + + #define AMS_HID_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 100, Result, SetSupportedNpadStyleSet, (const sf::ClientAppletResourceUserId &client_aruid, u32 style_set)) + + AMS_SF_DEFINE_MITM_INTERFACE(IHidMitmInterface, AMS_HID_MITM_INTERFACE_INFO) + + } + + class HidMitmService : public sf::MitmServiceImplBase { + public: + using MitmServiceImplBase::MitmServiceImplBase; public: static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { /* TODO: Remove in Atmosphere 0.10.2. */ @@ -33,14 +40,9 @@ namespace ams::mitm::hid { return client_info.override_status.IsHbl(); } public: - SF_MITM_SERVICE_OBJECT_CTOR(HidMitmService) { /* ... */ } - protected: /* Overridden commands. */ Result SetSupportedNpadStyleSet(const sf::ClientAppletResourceUserId &client_aruid, u32 style_set); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(SetSupportedNpadStyleSet), - }; }; + static_assert(IsIHidMitmInterface); } diff --git a/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.cpp b/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.cpp index c40d39b56..583095376 100644 --- a/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.cpp +++ b/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.cpp @@ -59,7 +59,7 @@ namespace ams::mitm::hid { } /* Create hid mitm. */ - R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(MitmServiceName)); + R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(MitmServiceName))); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/ams_mitm/source/ns_mitm/ns_am_mitm_service.hpp b/stratosphere/ams_mitm/source/ns_mitm/ns_am_mitm_service.hpp index 085e6097b..f84f3f6c0 100644 --- a/stratosphere/ams_mitm/source/ns_mitm/ns_am_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/ns_mitm/ns_am_mitm_service.hpp @@ -18,13 +18,20 @@ namespace ams::mitm::ns { - class NsAmMitmService : public sf::IMitmServiceObject { - private: - enum class CommandId { - GetApplicationContentPath = 21, - ResolveApplicationContentPath = 23, - GetRunningApplicationProgramId = 92, - }; + namespace impl { + + #define AMS_NS_AM_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 21, Result, GetApplicationContentPath, (const sf::OutBuffer &out_path, ncm::ProgramId application_id, u8 content_type)) \ + AMS_SF_METHOD_INFO(C, H, 23, Result, ResolveApplicationContentPath, (ncm::ProgramId application_id, u8 content_type)) \ + AMS_SF_METHOD_INFO(C, H, 92, Result, GetRunningApplicationProgramId, (sf::Out out, ncm::ProgramId application_id), hos::Version_6_0_0) + + AMS_SF_DEFINE_MITM_INTERFACE(IAmMitmInterface, AMS_NS_AM_MITM_INTERFACE_INFO) + + } + + class NsAmMitmService : public sf::MitmServiceImplBase { + public: + using MitmServiceImplBase::MitmServiceImplBase; public: static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { /* We will mitm: @@ -33,18 +40,11 @@ namespace ams::mitm::ns { return ncm::IsWebAppletId(client_info.program_id); } public: - SF_MITM_SERVICE_OBJECT_CTOR(NsAmMitmService) { /* ... */ } - protected: /* Actual command API. */ Result GetApplicationContentPath(const sf::OutBuffer &out_path, ncm::ProgramId application_id, u8 content_type); Result ResolveApplicationContentPath(ncm::ProgramId application_id, u8 content_type); Result GetRunningApplicationProgramId(sf::Out out, ncm::ProgramId application_id); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetApplicationContentPath), - MAKE_SERVICE_COMMAND_META(ResolveApplicationContentPath), - MAKE_SERVICE_COMMAND_META(GetRunningApplicationProgramId, hos::Version_6_0_0), - }; }; + static_assert(impl::IsIAmMitmInterface); } diff --git a/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.cpp b/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.cpp index 04a46e401..f364b5401 100644 --- a/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.cpp @@ -37,13 +37,13 @@ namespace ams::mitm::ns { return nswebGetRunningApplicationProgramId(this->srv.get(), reinterpret_cast(out.GetPointer()), static_cast(application_id)); } - Result NsWebMitmService::GetDocumentInterface(sf::Out> out) { + Result NsWebMitmService::GetDocumentInterface(sf::Out> out) { /* Open a document interface. */ NsDocumentInterface doc; R_TRY(nsGetDocumentInterfaceFwd(this->forward_service.get(), &doc)); const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(&doc.s)}; - out.SetValue(std::make_shared(this->client_info, std::make_unique(doc)), target_object_id); + out.SetValue(sf::MakeShared(this->client_info, std::make_unique(doc)), target_object_id); return ResultSuccess(); } diff --git a/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.hpp b/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.hpp index d525927a6..8f7574ee8 100644 --- a/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/ns_mitm/ns_web_mitm_service.hpp @@ -20,13 +20,23 @@ namespace ams::mitm::ns { - class NsDocumentService : public sf::IServiceObject { - private: - enum class CommandId { - GetApplicationContentPath = 21, - ResolveApplicationContentPath = 23, - GetRunningApplicationProgramId = 92, - }; + namespace impl { + + #define AMS_NS_DOCUMENT_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 21, Result, GetApplicationContentPath, (const sf::OutBuffer &out_path, ncm::ProgramId application_id, u8 content_type)) \ + AMS_SF_METHOD_INFO(C, H, 23, Result, ResolveApplicationContentPath, (ncm::ProgramId application_id, u8 content_type)) \ + AMS_SF_METHOD_INFO(C, H, 92, Result, GetRunningApplicationProgramId, (sf::Out out, ncm::ProgramId application_id), hos::Version_6_0_0) + + AMS_SF_DEFINE_INTERFACE(IDocumentInterface, AMS_NS_DOCUMENT_MITM_INTERFACE_INFO) + + #define AMS_NS_WEB_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 7999, Result, GetDocumentInterface, (sf::Out> out)) + + AMS_SF_DEFINE_MITM_INTERFACE(IWebMitmInterface, AMS_NS_WEB_MITM_INTERFACE_INFO) + + } + + class NsDocumentService { private: sm::MitmProcessInfo client_info; std::unique_ptr<::NsDocumentInterface> srv; @@ -36,24 +46,17 @@ namespace ams::mitm::ns { virtual ~NsDocumentService() { nsDocumentInterfaceClose(this->srv.get()); } - protected: + public: /* Actual command API. */ Result GetApplicationContentPath(const sf::OutBuffer &out_path, ncm::ProgramId application_id, u8 content_type); Result ResolveApplicationContentPath(ncm::ProgramId application_id, u8 content_type); Result GetRunningApplicationProgramId(sf::Out out, ncm::ProgramId application_id); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetApplicationContentPath), - MAKE_SERVICE_COMMAND_META(ResolveApplicationContentPath), - MAKE_SERVICE_COMMAND_META(GetRunningApplicationProgramId, hos::Version_6_0_0), - }; }; + static_assert(impl::IsIDocumentInterface); - class NsWebMitmService : public sf::IMitmServiceObject { - private: - enum class CommandId { - GetDocumentInterface = 7999, - }; + class NsWebMitmService : public sf::MitmServiceImplBase { + public: + using MitmServiceImplBase::MitmServiceImplBase; public: static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { /* We will mitm: @@ -62,13 +65,8 @@ namespace ams::mitm::ns { return ncm::IsWebAppletId(client_info.program_id); } public: - SF_MITM_SERVICE_OBJECT_CTOR(NsWebMitmService) { /* ... */ } - protected: - Result GetDocumentInterface(sf::Out> out); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetDocumentInterface), - }; + Result GetDocumentInterface(sf::Out> out); }; + static_assert(impl::IsIWebMitmInterface); } diff --git a/stratosphere/ams_mitm/source/ns_mitm/nsmitm_module.cpp b/stratosphere/ams_mitm/source/ns_mitm/nsmitm_module.cpp index 33db54be5..4a7a708ac 100644 --- a/stratosphere/ams_mitm/source/ns_mitm/nsmitm_module.cpp +++ b/stratosphere/ams_mitm/source/ns_mitm/nsmitm_module.cpp @@ -39,9 +39,9 @@ namespace ams::mitm::ns { /* Create mitm servers. */ if (hos::GetVersion() < hos::Version_3_0_0) { - R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(NsAmMitmServiceName)); + R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(NsAmMitmServiceName))); } else { - R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(NsWebMitmServiceName)); + R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(NsWebMitmServiceName))); } /* Loop forever, servicing our services. */ diff --git a/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp b/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp index 7c5f3f1d4..fe57f425f 100644 --- a/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp @@ -18,16 +18,23 @@ namespace ams::mitm::settings { - class SetMitmService : public sf::IMitmServiceObject { - private: - enum class CommandId { - GetLanguageCode = 0, - GetRegionCode = 4, - }; + namespace { + + #define AMS_SETTINGS_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetLanguageCode, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetRegionCode, (sf::Out out)) + + AMS_SF_DEFINE_MITM_INTERFACE(ISetMitmInterface, AMS_SETTINGS_MITM_INTERFACE_INFO) + + } + + class SetMitmService : public sf::MitmServiceImplBase { private: os::Mutex lock{false}; cfg::OverrideLocale locale; - bool got_locale; + bool got_locale = false; + public: + using MitmServiceImplBase::MitmServiceImplBase; public: static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { /* We will mitm: @@ -36,20 +43,12 @@ namespace ams::mitm::settings { const bool is_game = (ncm::IsApplicationId(client_info.program_id) && !client_info.override_status.IsHbl()); return client_info.program_id == ncm::SystemProgramId::Ns || is_game; } - public: - SF_MITM_SERVICE_OBJECT_CTOR(SetMitmService) { - this->got_locale = false; - } private: Result EnsureLocale(); - protected: + public: Result GetLanguageCode(sf::Out out); Result GetRegionCode(sf::Out out); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetLanguageCode), - MAKE_SERVICE_COMMAND_META(GetRegionCode), - }; }; + static_assert(IsISetMitmInterface); } diff --git a/stratosphere/ams_mitm/source/set_mitm/setmitm_module.cpp b/stratosphere/ams_mitm/source/set_mitm/setmitm_module.cpp index 26637a092..787e285e8 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setmitm_module.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setmitm_module.cpp @@ -43,8 +43,8 @@ namespace ams::mitm::settings { mitm::WaitInitialized(); /* Create mitm servers. */ - R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(SetMitmServiceName)); - R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(SetSysMitmServiceName)); + R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(SetMitmServiceName))); + R_ABORT_UNLESS((g_server_manager.RegisterMitmServer(SetSysMitmServiceName))); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp index 4dade3eb1..54bb22ecd 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp @@ -18,15 +18,21 @@ namespace ams::mitm::settings { - class SetSysMitmService : public sf::IMitmServiceObject { - private: - enum class CommandId { - GetFirmwareVersion = 3, - GetFirmwareVersion2 = 4, + namespace { - GetSettingsItemValueSize = 37, - GetSettingsItemValue = 38, - }; + #define AMS_SETTINGS_SYSTEM_MITM_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetFirmwareVersion, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetFirmwareVersion2, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 37, Result, GetSettingsItemValueSize, (sf::Out out_size, const ams::settings::fwdbg::SettingsName &name, const ams::settings::fwdbg::SettingsItemKey &key)) \ + AMS_SF_METHOD_INFO(C, H, 38, Result, GetSettingsItemValue, (sf::Out out_size, const sf::OutBuffer &out, const ams::settings::fwdbg::SettingsName &name, const ams::settings::fwdbg::SettingsItemKey &key)) + + AMS_SF_DEFINE_MITM_INTERFACE(ISetSysMitmInterface, AMS_SETTINGS_SYSTEM_MITM_INTERFACE_INFO) + + } + + class SetSysMitmService : public sf::MitmServiceImplBase { + public: + using MitmServiceImplBase::MitmServiceImplBase; public: static bool ShouldMitm(const sm::MitmProcessInfo &client_info) { /* We will mitm: @@ -35,19 +41,11 @@ namespace ams::mitm::settings { return true; } public: - SF_MITM_SERVICE_OBJECT_CTOR(SetSysMitmService) { /* ... */ } - protected: Result GetFirmwareVersion(sf::Out out); Result GetFirmwareVersion2(sf::Out out); Result GetSettingsItemValueSize(sf::Out out_size, const ams::settings::fwdbg::SettingsName &name, const ams::settings::fwdbg::SettingsItemKey &key); Result GetSettingsItemValue(sf::Out out_size, const sf::OutBuffer &out, const ams::settings::fwdbg::SettingsName &name, const ams::settings::fwdbg::SettingsItemKey &key); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetFirmwareVersion), - MAKE_SERVICE_COMMAND_META(GetFirmwareVersion2), - MAKE_SERVICE_COMMAND_META(GetSettingsItemValueSize), - MAKE_SERVICE_COMMAND_META(GetSettingsItemValue), - }; }; + static_assert(IsISetSysMitmInterface); } diff --git a/stratosphere/ams_mitm/source/sysupdater/sysupdater_async_impl.hpp b/stratosphere/ams_mitm/source/sysupdater/sysupdater_async_impl.hpp index e65f9b50a..ff062c3ed 100644 --- a/stratosphere/ams_mitm/source/sysupdater/sysupdater_async_impl.hpp +++ b/stratosphere/ams_mitm/source/sysupdater/sysupdater_async_impl.hpp @@ -15,7 +15,6 @@ */ #pragma once #include -#include "sysupdater_i_async_result.hpp" #include "sysupdater_thread_allocator.hpp" namespace ams::mitm::sysupdater { @@ -59,18 +58,18 @@ namespace ams::mitm::sysupdater { } }; - class AsyncBase : public IAsyncBase { + class AsyncBase { public: virtual ~AsyncBase() { /* ... */ } static Result ToAsyncResult(Result result); - virtual Result Cancel() override final { + Result Cancel() { this->CancelImpl(); return ResultSuccess(); } - virtual Result GetErrorContext(sf::Out out) override { + virtual Result GetErrorContext(sf::Out out) { *out = {}; return ResultSuccess(); } @@ -78,29 +77,17 @@ namespace ams::mitm::sysupdater { virtual void CancelImpl() = 0; }; - class AsyncResultBase : public IAsyncResult { + class AsyncResultBase : public AsyncBase { public: virtual ~AsyncResultBase() { /* ... */ } - static Result ToAsyncResult(Result result) { return AsyncBase::ToAsyncResult(result); } - - virtual Result Cancel() override final { - this->CancelImpl(); - return ResultSuccess(); - } - - virtual Result Get() override final { + Result Get() { return ToAsyncResult(this->GetImpl()); } - - virtual Result GetErrorContext(sf::Out out) override { - *out = {}; - return ResultSuccess(); - } private: - virtual void CancelImpl() = 0; virtual Result GetImpl() = 0; }; + static_assert(ns::impl::IsIAsyncResult); /* NOTE: Based off of ns AsyncPrepareCardUpdateImpl. */ /* We don't implement the RequestServer::ManagedStop details, as we don't implement stoppable request list. */ diff --git a/stratosphere/ams_mitm/source/sysupdater/sysupdater_i_async_result.hpp b/stratosphere/ams_mitm/source/sysupdater/sysupdater_i_async_result.hpp deleted file mode 100644 index 77d37447d..000000000 --- a/stratosphere/ams_mitm/source/sysupdater/sysupdater_i_async_result.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2018-2020 Atmosphère-NX - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#pragma once -#include - -namespace ams::mitm::sysupdater { - - class IAsyncBase : public sf::IServiceObject { - public: - virtual Result Cancel() = 0; - virtual Result GetErrorContext(sf::Out out) = 0; - }; - - class IAsyncResult : public IAsyncBase { - private: - enum class CommandId { - Get = 0, - Cancel = 1, - GetErrorContext = 2, - }; - public: - virtual Result Get() = 0; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(Get), - MAKE_SERVICE_COMMAND_META(Cancel), - MAKE_SERVICE_COMMAND_META(GetErrorContext), - }; - }; - -} diff --git a/stratosphere/ams_mitm/source/sysupdater/sysupdater_module.cpp b/stratosphere/ams_mitm/source/sysupdater/sysupdater_module.cpp index bd4c35474..5ab7ff6e5 100644 --- a/stratosphere/ams_mitm/source/sysupdater/sysupdater_module.cpp +++ b/stratosphere/ams_mitm/source/sysupdater/sysupdater_module.cpp @@ -50,7 +50,7 @@ namespace ams::mitm::sysupdater { ON_SCOPE_EXIT { nim::FinalizeForNetworkInstallManager(); }; /* Register ams:su. */ - R_ABORT_UNLESS((g_server_manager.RegisterServer(SystemUpdateServiceName, SystemUpdateMaxSessions, sf::ServiceObjectTraits::SharedPointerHelper::GetEmptyDeleteSharedPointer(std::addressof(g_system_update_service_object))))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(SystemUpdateServiceName, SystemUpdateMaxSessions, sf::GetSharedPointerTo(g_system_update_service_object)))); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp index 9a04d4560..5e03944b0 100644 --- a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp +++ b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp @@ -411,21 +411,21 @@ namespace ams::mitm::sysupdater { return this->SetupUpdateImpl(transfer_memory.GetValue(), transfer_memory_size, path, exfat, firmware_variation_id); } - Result SystemUpdateService::RequestPrepareUpdate(sf::OutCopyHandle out_event_handle, sf::Out> out_async) { + Result SystemUpdateService::RequestPrepareUpdate(sf::OutCopyHandle out_event_handle, sf::Out> out_async) { /* Ensure the update is setup but not prepared. */ R_UNLESS(this->setup_update, ns::ResultCardUpdateNotSetup()); R_UNLESS(!this->requested_update, ns::ResultPrepareCardUpdateAlreadyRequested()); /* Create the async result. */ - auto async_result = std::make_shared(std::addressof(*this->update_task)); + auto async_result = sf::MakeShared(std::addressof(*this->update_task)); R_UNLESS(async_result != nullptr, ns::ResultOutOfMaxRunningTask()); /* Run the task. */ - R_TRY(async_result->Run()); + R_TRY(async_result->GetImpl().Run()); /* We prepared the task! */ this->requested_update = true; - out_event_handle.SetValue(async_result->GetEvent().GetReadableHandle()); + out_event_handle.SetValue(async_result->GetImpl().GetEvent().GetReadableHandle()); out_async.SetValue(std::move(async_result)); return ResultSuccess(); diff --git a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.hpp b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.hpp index 82ac8332f..afb819532 100644 --- a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.hpp +++ b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.hpp @@ -15,7 +15,6 @@ */ #pragma once #include -#include "sysupdater_i_async_result.hpp" #include "sysupdater_apply_manager.hpp" namespace ams::mitm::sysupdater { @@ -39,18 +38,25 @@ namespace ams::mitm::sysupdater { s64 total_size; }; - class SystemUpdateService final : public sf::IServiceObject { - private: - enum class CommandId { - GetUpdateInformation = 0, - ValidateUpdate = 1, - SetupUpdate = 2, - SetupUpdateWithVariation = 3, - RequestPrepareUpdate = 4, - GetPrepareUpdateProgress = 5, - HasPreparedUpdate = 6, - ApplyPreparedUpdate = 7, - }; + namespace impl { + + #define AMS_SYSUPDATER_SYSTEM_UPDATE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetUpdateInformation, (sf::Out out, const ncm::Path &path)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, ValidateUpdate, (sf::Out out_validate_result, sf::Out out_validate_info, const ncm::Path &path)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, SetupUpdate, (sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, SetupUpdateWithVariation, (sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, RequestPrepareUpdate, (sf::OutCopyHandle out_event_handle, sf::Out> out_async)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetPrepareUpdateProgress, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, HasPreparedUpdate, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, ApplyPreparedUpdate, ()) + + AMS_SF_DEFINE_INTERFACE(ISystemUpdateInterface, AMS_SYSUPDATER_SYSTEM_UPDATE_INTERFACE_INFO) + + + + } + + class SystemUpdateService final { private: SystemUpdateApplyManager apply_manager; std::optional update_task; @@ -62,26 +68,16 @@ namespace ams::mitm::sysupdater { private: Result SetupUpdateImpl(os::ManagedHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id); Result InitializeUpdateTask(os::ManagedHandle &transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id); - private: + public: Result GetUpdateInformation(sf::Out out, const ncm::Path &path); Result ValidateUpdate(sf::Out out_validate_result, sf::Out out_validate_info, const ncm::Path &path); Result SetupUpdate(sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat); Result SetupUpdateWithVariation(sf::CopyHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id); - Result RequestPrepareUpdate(sf::OutCopyHandle out_event_handle, sf::Out> out_async); + Result RequestPrepareUpdate(sf::OutCopyHandle out_event_handle, sf::Out> out_async); Result GetPrepareUpdateProgress(sf::Out out); Result HasPreparedUpdate(sf::Out out); Result ApplyPreparedUpdate(); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetUpdateInformation), - MAKE_SERVICE_COMMAND_META(ValidateUpdate), - MAKE_SERVICE_COMMAND_META(SetupUpdate), - MAKE_SERVICE_COMMAND_META(SetupUpdateWithVariation), - MAKE_SERVICE_COMMAND_META(RequestPrepareUpdate), - MAKE_SERVICE_COMMAND_META(GetPrepareUpdateProgress), - MAKE_SERVICE_COMMAND_META(HasPreparedUpdate), - MAKE_SERVICE_COMMAND_META(ApplyPreparedUpdate), - }; }; + static_assert(impl::IsISystemUpdateInterface); } diff --git a/stratosphere/dmnt/source/cheat/dmnt_cheat_service.hpp b/stratosphere/dmnt/source/cheat/dmnt_cheat_service.hpp index 35c7d2c7c..9a507fb3a 100644 --- a/stratosphere/dmnt/source/cheat/dmnt_cheat_service.hpp +++ b/stratosphere/dmnt/source/cheat/dmnt_cheat_service.hpp @@ -18,43 +18,42 @@ namespace ams::dmnt::cheat { - class CheatService final : public sf::IServiceObject { - private: - enum class CommandId { - /* Meta */ - HasCheatProcess = 65000, - GetCheatProcessEvent = 65001, - GetCheatProcessMetadata = 65002, - ForceOpenCheatProcess = 65003, - PauseCheatProcess = 65004, - ResumeCheatProcess = 65005, + /* TODO: In libstratosphere, eventually? */ + namespace impl { - /* Interact with Memory */ - GetCheatProcessMappingCount = 65100, - GetCheatProcessMappings = 65101, - ReadCheatProcessMemory = 65102, - WriteCheatProcessMemory = 65103, - QueryCheatProcessMemory = 65104, + #define AMS_DMNT_I_CHEAT_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, HasCheatProcess, (sf::Out out)) \ + AMS_SF_METHOD_INFO(C, H, 65001, void, GetCheatProcessEvent, (sf::OutCopyHandle out_event)) \ + AMS_SF_METHOD_INFO(C, H, 65002, Result, GetCheatProcessMetadata, (sf::Out out_metadata)) \ + AMS_SF_METHOD_INFO(C, H, 65003, Result, ForceOpenCheatProcess, ()) \ + AMS_SF_METHOD_INFO(C, H, 65004, Result, PauseCheatProcess, ()) \ + AMS_SF_METHOD_INFO(C, H, 65005, Result, ResumeCheatProcess, ()) \ + AMS_SF_METHOD_INFO(C, H, 65100, Result, GetCheatProcessMappingCount, (sf::Out out_count)) \ + AMS_SF_METHOD_INFO(C, H, 65101, Result, GetCheatProcessMappings, (const sf::OutArray &mappings, sf::Out out_count, u64 offset)) \ + AMS_SF_METHOD_INFO(C, H, 65102, Result, ReadCheatProcessMemory, (const sf::OutBuffer &buffer, u64 address, u64 out_size)) \ + AMS_SF_METHOD_INFO(C, H, 65103, Result, WriteCheatProcessMemory, (const sf::InBuffer &buffer, u64 address, u64 in_size)) \ + AMS_SF_METHOD_INFO(C, H, 65104, Result, QueryCheatProcessMemory, (sf::Out mapping, u64 address)) \ + AMS_SF_METHOD_INFO(C, H, 65200, Result, GetCheatCount, (sf::Out out_count)) \ + AMS_SF_METHOD_INFO(C, H, 65201, Result, GetCheats, (const sf::OutArray &cheats, sf::Out out_count, u64 offset)) \ + AMS_SF_METHOD_INFO(C, H, 65202, Result, GetCheatById, (sf::Out cheat, u32 cheat_id)) \ + AMS_SF_METHOD_INFO(C, H, 65203, Result, ToggleCheat, (u32 cheat_id)) \ + AMS_SF_METHOD_INFO(C, H, 65204, Result, AddCheat, (const CheatDefinition &cheat, sf::Out out_cheat_id, bool enabled)) \ + AMS_SF_METHOD_INFO(C, H, 65205, Result, RemoveCheat, (u32 cheat_id)) \ + AMS_SF_METHOD_INFO(C, H, 65206, Result, ReadStaticRegister, (sf::Out out, u8 which)) \ + AMS_SF_METHOD_INFO(C, H, 65207, Result, WriteStaticRegister, (u8 which, u64 value)) \ + AMS_SF_METHOD_INFO(C, H, 65208, Result, ResetStaticRegisters, ()) \ + AMS_SF_METHOD_INFO(C, H, 65300, Result, GetFrozenAddressCount, (sf::Out out_count)) \ + AMS_SF_METHOD_INFO(C, H, 65301, Result, GetFrozenAddresses, (const sf::OutArray &addresses, sf::Out out_count, u64 offset)) \ + AMS_SF_METHOD_INFO(C, H, 65302, Result, GetFrozenAddress, (sf::Out entry, u64 address)) \ + AMS_SF_METHOD_INFO(C, H, 65303, Result, EnableFrozenAddress, (sf::Out out_value, u64 address, u64 width)) \ + AMS_SF_METHOD_INFO(C, H, 65304, Result, DisableFrozenAddress, (u64 address)) - /* Interact with Cheats */ - GetCheatCount = 65200, - GetCheats = 65201, - GetCheatById = 65202, - ToggleCheat = 65203, - AddCheat = 65204, - RemoveCheat = 65205, - ReadStaticRegister = 65206, - WriteStaticRegister = 65207, - ResetStaticRegisters = 65208, + AMS_SF_DEFINE_INTERFACE(ICheatInterface, AMS_DMNT_I_CHEAT_INTERFACE_INTERFACE_INFO) - /* Interact with Frozen Addresses */ - GetFrozenAddressCount = 65300, - GetFrozenAddresses = 65301, - GetFrozenAddress = 65302, - EnableFrozenAddress = 65303, - DisableFrozenAddress = 65304, - }; - private: + } + + class CheatService final { + public: void HasCheatProcess(sf::Out out); void GetCheatProcessEvent(sf::OutCopyHandle out_event); Result GetCheatProcessMetadata(sf::Out out_metadata); @@ -83,38 +82,7 @@ namespace ams::dmnt::cheat { Result GetFrozenAddress(sf::Out entry, u64 address); Result EnableFrozenAddress(sf::Out out_value, u64 address, u64 width); Result DisableFrozenAddress(u64 address); - - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(HasCheatProcess), - MAKE_SERVICE_COMMAND_META(GetCheatProcessEvent), - MAKE_SERVICE_COMMAND_META(GetCheatProcessMetadata), - MAKE_SERVICE_COMMAND_META(ForceOpenCheatProcess), - MAKE_SERVICE_COMMAND_META(PauseCheatProcess), - MAKE_SERVICE_COMMAND_META(ResumeCheatProcess), - - MAKE_SERVICE_COMMAND_META(GetCheatProcessMappingCount), - MAKE_SERVICE_COMMAND_META(GetCheatProcessMappings), - MAKE_SERVICE_COMMAND_META(ReadCheatProcessMemory), - MAKE_SERVICE_COMMAND_META(WriteCheatProcessMemory), - MAKE_SERVICE_COMMAND_META(QueryCheatProcessMemory), - - MAKE_SERVICE_COMMAND_META(GetCheatCount), - MAKE_SERVICE_COMMAND_META(GetCheats), - MAKE_SERVICE_COMMAND_META(GetCheatById), - MAKE_SERVICE_COMMAND_META(ToggleCheat), - MAKE_SERVICE_COMMAND_META(AddCheat), - MAKE_SERVICE_COMMAND_META(RemoveCheat), - MAKE_SERVICE_COMMAND_META(ReadStaticRegister), - MAKE_SERVICE_COMMAND_META(WriteStaticRegister), - MAKE_SERVICE_COMMAND_META(ResetStaticRegisters), - - MAKE_SERVICE_COMMAND_META(GetFrozenAddressCount), - MAKE_SERVICE_COMMAND_META(GetFrozenAddresses), - MAKE_SERVICE_COMMAND_META(GetFrozenAddress), - MAKE_SERVICE_COMMAND_META(EnableFrozenAddress), - MAKE_SERVICE_COMMAND_META(DisableFrozenAddress), - }; }; + static_assert(impl::IsICheatInterface); } diff --git a/stratosphere/dmnt/source/dmnt_main.cpp b/stratosphere/dmnt/source/dmnt_main.cpp index 3839d4b9a..ff99db916 100644 --- a/stratosphere/dmnt/source/dmnt_main.cpp +++ b/stratosphere/dmnt/source/dmnt_main.cpp @@ -140,7 +140,7 @@ int main(int argc, char **argv) /* Create services. */ /* TODO: Implement rest of dmnt:- in ams.tma development branch. */ /* R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); */ - R_ABORT_UNLESS((g_server_manager.RegisterServer(CheatServiceName, CheatMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(CheatServiceName, CheatMaxSessions))); /* Loop forever, servicing our services. */ /* Nintendo loops four threads processing on the manager -- we'll loop an extra fifth for our cheat service. */ diff --git a/stratosphere/dmnt/source/dmnt_service.hpp b/stratosphere/dmnt/source/dmnt_service.hpp index 80ba6de55..8372f6241 100644 --- a/stratosphere/dmnt/source/dmnt_service.hpp +++ b/stratosphere/dmnt/source/dmnt_service.hpp @@ -57,7 +57,8 @@ namespace ams::dmnt { static_assert(util::is_pod::value && sizeof(TargetIOFileHandle) == sizeof(u64), "TargetIOFileHandle"); - class DebugMonitorService final : public sf::IServiceObject { + /* TODO: Convert to new sf format in the future. */ + class DebugMonitorService final { private: enum class CommandId { BreakDebugProcess = 0, @@ -131,61 +132,6 @@ namespace ams::dmnt { Result TargetIO_FileSetSize(const sf::InBuffer &input, s64 size); Result TargetIO_FileDelete(const sf::InBuffer &path); Result TargetIO_FileMove(const sf::InBuffer &src_path, const sf::InBuffer &dst_path); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(BreakDebugProcess), - MAKE_SERVICE_COMMAND_META(TerminateDebugProcess), - MAKE_SERVICE_COMMAND_META(CloseHandle), - // MAKE_SERVICE_COMMAND_META(LoadImage), - MAKE_SERVICE_COMMAND_META(GetProcessId), - MAKE_SERVICE_COMMAND_META(GetProcessHandle), - MAKE_SERVICE_COMMAND_META(WaitSynchronization), - //MAKE_SERVICE_COMMAND_META(GetDebugEvent), - // MAKE_SERVICE_COMMAND_META(GetProcessModuleInfo), - // MAKE_SERVICE_COMMAND_META(GetProcessList), - // MAKE_SERVICE_COMMAND_META(GetThreadList), - // MAKE_SERVICE_COMMAND_META(GetDebugThreadContext), - // MAKE_SERVICE_COMMAND_META(ContinueDebugEvent), - // MAKE_SERVICE_COMMAND_META(ReadDebugProcessMemory), - // MAKE_SERVICE_COMMAND_META(WriteDebugProcessMemory), - // MAKE_SERVICE_COMMAND_META(SetDebugThreadContext), - // MAKE_SERVICE_COMMAND_META(GetDebugThreadParam), - // MAKE_SERVICE_COMMAND_META(InitializeThreadInfo), - // MAKE_SERVICE_COMMAND_META(SetHardwareBreakPoint), - // MAKE_SERVICE_COMMAND_META(QueryDebugProcessMemory), - // MAKE_SERVICE_COMMAND_META(GetProcessMemoryDetails), - // MAKE_SERVICE_COMMAND_META(AttachByProgramId), - // MAKE_SERVICE_COMMAND_META(AttachOnLaunch), - // MAKE_SERVICE_COMMAND_META(GetDebugMonitorProcessId), - // MAKE_SERVICE_COMMAND_META(GetJitDebugProcessList), - // MAKE_SERVICE_COMMAND_META(CreateCoreDump), - // MAKE_SERVICE_COMMAND_META(GetAllDebugThreadInfo), - MAKE_SERVICE_COMMAND_META(TargetIO_FileOpen), - MAKE_SERVICE_COMMAND_META(TargetIO_FileClose), - MAKE_SERVICE_COMMAND_META(TargetIO_FileRead), - MAKE_SERVICE_COMMAND_META(TargetIO_FileWrite), - MAKE_SERVICE_COMMAND_META(TargetIO_FileSetAttributes), - MAKE_SERVICE_COMMAND_META(TargetIO_FileGetInformation), - MAKE_SERVICE_COMMAND_META(TargetIO_FileSetTime), - MAKE_SERVICE_COMMAND_META(TargetIO_FileSetSize), - MAKE_SERVICE_COMMAND_META(TargetIO_FileDelete), - MAKE_SERVICE_COMMAND_META(TargetIO_FileMove), - // MAKE_SERVICE_COMMAND_META(TargetIO_DirectoryCreate), - // MAKE_SERVICE_COMMAND_META(TargetIO_DirectoryDelete), - // MAKE_SERVICE_COMMAND_META(TargetIO_DirectoryRename), - // MAKE_SERVICE_COMMAND_META(TargetIO_DirectoryGetCount), - // MAKE_SERVICE_COMMAND_META(TargetIO_DirectoryOpen), - // MAKE_SERVICE_COMMAND_META(TargetIO_DirectoryGetNext), - // MAKE_SERVICE_COMMAND_META(TargetIO_DirectoryClose), - // MAKE_SERVICE_COMMAND_META(TargetIO_GetFreeSpace), - // MAKE_SERVICE_COMMAND_META(TargetIO_GetVolumeInformation), - // MAKE_SERVICE_COMMAND_META(InitiateCoreDump), - // MAKE_SERVICE_COMMAND_META(ContinueCoreDump), - // MAKE_SERVICE_COMMAND_META(AddTTYToCoreDump), - // MAKE_SERVICE_COMMAND_META(AddImageToCoreDump), - // MAKE_SERVICE_COMMAND_META(CloseCoreDump), - // MAKE_SERVICE_COMMAND_META(CancelAttach), - }; }; } diff --git a/stratosphere/fatal/source/fatal_main.cpp b/stratosphere/fatal/source/fatal_main.cpp index 587c40f4a..3b576347b 100644 --- a/stratosphere/fatal/source/fatal_main.cpp +++ b/stratosphere/fatal/source/fatal_main.cpp @@ -156,11 +156,10 @@ int main(int argc, char **argv) fatal::srv::CheckRepairStatus(); /* Create services. */ - R_ABORT_UNLESS((g_server_manager.RegisterServer(PrivateServiceName, PrivateMaxSessions))); - R_ABORT_UNLESS((g_server_manager.RegisterServer(UserServiceName, UserMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(PrivateServiceName, PrivateMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(UserServiceName, UserMaxSessions))); /* Add dirty event holder. */ - /* TODO: s_server_manager.AddWaitable(ams::fatal::srv::GetFatalDirtyEvent()); */ auto *dirty_event_holder = ams::fatal::srv::GetFatalDirtyWaitableHolder(); g_server_manager.AddUserWaitableHolder(dirty_event_holder); diff --git a/stratosphere/fatal/source/fatal_service.cpp b/stratosphere/fatal/source/fatal_service.cpp index 0e86883b6..5c0744c35 100644 --- a/stratosphere/fatal/source/fatal_service.cpp +++ b/stratosphere/fatal/source/fatal_service.cpp @@ -133,15 +133,15 @@ namespace ams::fatal::srv { return g_context.ThrowFatalWithPolicy(result, os::GetCurrentProcessId(), FatalPolicy_ErrorScreen); } - Result UserService::ThrowFatal(Result result, const sf::ClientProcessId &client_pid) { + Result Service::ThrowFatal(Result result, const sf::ClientProcessId &client_pid) { return g_context.ThrowFatal(result, client_pid.GetValue()); } - Result UserService::ThrowFatalWithPolicy(Result result, const sf::ClientProcessId &client_pid, FatalPolicy policy) { + Result Service::ThrowFatalWithPolicy(Result result, const sf::ClientProcessId &client_pid, FatalPolicy policy) { return g_context.ThrowFatalWithPolicy(result, client_pid.GetValue(), policy); } - Result UserService::ThrowFatalWithCpuContext(Result result, const sf::ClientProcessId &client_pid, FatalPolicy policy, const CpuContext &cpu_ctx) { + Result Service::ThrowFatalWithCpuContext(Result result, const sf::ClientProcessId &client_pid, FatalPolicy policy, const CpuContext &cpu_ctx) { return g_context.ThrowFatalWithCpuContext(result, client_pid.GetValue(), policy, cpu_ctx); } diff --git a/stratosphere/fatal/source/fatal_service.hpp b/stratosphere/fatal/source/fatal_service.hpp index 04c707e0a..ca20c5e9f 100644 --- a/stratosphere/fatal/source/fatal_service.hpp +++ b/stratosphere/fatal/source/fatal_service.hpp @@ -18,39 +18,19 @@ namespace ams::fatal::srv { - class UserService final : public sf::IServiceObject { - private: - enum class CommandId { - ThrowFatal = 0, - ThrowFatalWithPolicy = 1, - ThrowFatalWithCpuContext = 2, - }; - private: - /* Actual commands. */ + class Service final { + public: Result ThrowFatal(Result error, const sf::ClientProcessId &client_pid); Result ThrowFatalWithPolicy(Result error, const sf::ClientProcessId &client_pid, FatalPolicy policy); Result ThrowFatalWithCpuContext(Result error, const sf::ClientProcessId &client_pid, FatalPolicy policy, const CpuContext &cpu_ctx); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(ThrowFatal), - MAKE_SERVICE_COMMAND_META(ThrowFatalWithPolicy), - MAKE_SERVICE_COMMAND_META(ThrowFatalWithCpuContext), - }; }; + static_assert(fatal::impl::IsIService); - class PrivateService final : public sf::IServiceObject { - private: - enum class CommandId { - GetFatalEvent = 0, - }; - private: - /* Actual commands. */ - Result GetFatalEvent(sf::OutCopyHandle out_h); + class PrivateService final { public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetFatalEvent), - }; + Result GetFatalEvent(sf::OutCopyHandle out_h); }; + static_assert(fatal::impl::IsIPrivateService); } diff --git a/stratosphere/loader/source/ldr_loader_service.hpp b/stratosphere/loader/source/ldr_loader_service.hpp index 2d5d5942a..289c384a7 100644 --- a/stratosphere/loader/source/ldr_loader_service.hpp +++ b/stratosphere/loader/source/ldr_loader_service.hpp @@ -18,101 +18,27 @@ namespace ams::ldr { - class LoaderService : public sf::IServiceObject { - protected: + class LoaderService final { + public: /* Official commands. */ - virtual Result CreateProcess(sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle reslimit_h); - virtual Result GetProgramInfo(sf::Out out_program_info, const ncm::ProgramLocation &loc); - virtual Result PinProgram(sf::Out out_id, const ncm::ProgramLocation &loc); - virtual Result UnpinProgram(PinId id); - virtual Result SetProgramArguments(ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size); - virtual Result FlushArguments(); - virtual Result GetProcessModuleInfo(sf::Out count, const sf::OutPointerArray &out, os::ProcessId process_id); - virtual Result SetEnabledProgramVerification(bool enabled); + Result CreateProcess(sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle reslimit_h); + Result GetProgramInfo(sf::Out out_program_info, const ncm::ProgramLocation &loc); + Result PinProgram(sf::Out out_id, const ncm::ProgramLocation &loc); + Result UnpinProgram(PinId id); + Result SetProgramArguments(ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size); + Result FlushArguments(); + Result GetProcessModuleInfo(sf::Out count, const sf::OutPointerArray &out, os::ProcessId process_id); + Result SetEnabledProgramVerification(bool enabled); /* Atmosphere commands. */ - virtual Result AtmosphereRegisterExternalCode(sf::OutMoveHandle out, ncm::ProgramId program_id); - virtual void AtmosphereUnregisterExternalCode(ncm::ProgramId program_id); - virtual void AtmosphereHasLaunchedProgram(sf::Out out, ncm::ProgramId program_id); - virtual Result AtmosphereGetProgramInfo(sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc); - virtual Result AtmospherePinProgram(sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status); + Result AtmosphereRegisterExternalCode(sf::OutMoveHandle out, ncm::ProgramId program_id); + void AtmosphereUnregisterExternalCode(ncm::ProgramId program_id); + void AtmosphereHasLaunchedProgram(sf::Out out, ncm::ProgramId program_id); + Result AtmosphereGetProgramInfo(sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc); + Result AtmospherePinProgram(sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status); }; - - namespace pm { - - class ProcessManagerInterface final : public LoaderService { - protected: - enum class CommandId { - CreateProcess = 0, - GetProgramInfo = 1, - PinProgram = 2, - UnpinProgram = 3, - SetEnabledProgramVerification = 4, - - AtmosphereHasLaunchedProgram = 65000, - AtmosphereGetProgramInfo = 65001, - AtmospherePinProgram = 65002, - }; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(CreateProcess), - MAKE_SERVICE_COMMAND_META(GetProgramInfo), - MAKE_SERVICE_COMMAND_META(PinProgram), - MAKE_SERVICE_COMMAND_META(UnpinProgram), - MAKE_SERVICE_COMMAND_META(SetEnabledProgramVerification, hos::Version_10_0_0), - - MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedProgram), - MAKE_SERVICE_COMMAND_META(AtmosphereGetProgramInfo), - MAKE_SERVICE_COMMAND_META(AtmospherePinProgram), - }; - }; - - } - - namespace dmnt { - - class DebugMonitorInterface final : public LoaderService { - protected: - enum class CommandId { - SetProgramArguments = 0, - FlushArguments = 1, - GetProcessModuleInfo = 2, - - AtmosphereHasLaunchedProgram = 65000, - }; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(SetProgramArguments), - MAKE_SERVICE_COMMAND_META(FlushArguments), - MAKE_SERVICE_COMMAND_META(GetProcessModuleInfo), - - MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedProgram), - }; - }; - - } - - namespace shell { - - class ShellInterface final : public LoaderService { - protected: - enum class CommandId { - SetProgramArguments = 0, - FlushArguments = 1, - - AtmosphereRegisterExternalCode = 65000, - AtmosphereUnregisterExternalCode = 65001, - }; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(SetProgramArguments), - MAKE_SERVICE_COMMAND_META(FlushArguments), - - MAKE_SERVICE_COMMAND_META(AtmosphereRegisterExternalCode), - MAKE_SERVICE_COMMAND_META(AtmosphereUnregisterExternalCode), - }; - }; - - } + static_assert(ams::ldr::impl::IsIProcessManagerInterface); + static_assert(ams::ldr::impl::IsIDebugMonitorInterface); + static_assert(ams::ldr::impl::IsIShellInterface); } diff --git a/stratosphere/loader/source/ldr_main.cpp b/stratosphere/loader/source/ldr_main.cpp index ace9cd4b2..73de30843 100644 --- a/stratosphere/loader/source/ldr_main.cpp +++ b/stratosphere/loader/source/ldr_main.cpp @@ -129,9 +129,9 @@ int main(int argc, char **argv) ldr::SetDevelopmentForAcidSignatureCheck(spl::IsDevelopment()); /* Add services to manager. */ - R_ABORT_UNLESS((g_server_manager.RegisterServer(ProcessManagerServiceName, ProcessManagerMaxSessions))); - R_ABORT_UNLESS((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); - R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ProcessManagerServiceName, ProcessManagerMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/ncm/source/ncm_main.cpp b/stratosphere/ncm/source/ncm_main.cpp index 84cb3099a..860d3adab 100644 --- a/stratosphere/ncm/source/ncm_main.cpp +++ b/stratosphere/ncm/source/ncm_main.cpp @@ -153,24 +153,21 @@ namespace { class ContentManagerServerManager : public sf::hipc::ServerManager { private: - using ServiceType = ncm::ContentManagerImpl; + using Interface = ncm::IContentManager; + using ServiceImpl = ncm::ContentManagerImpl; private: os::ThreadType thread; - std::shared_ptr ncm_manager; + std::shared_ptr ncm_manager; private: static void ThreadFunction(void *_this) { reinterpret_cast(_this)->LoopProcess(); } public: - ContentManagerServerManager(ServiceType *m) - : ncm_manager() - { - /* ... */ - } + ContentManagerServerManager() : ncm_manager() { /* ... */ } - ams::Result Initialize(std::shared_ptr manager_obj) { + ams::Result Initialize(std::shared_ptr manager_obj) { this->ncm_manager = manager_obj; - return this->RegisterServer(ContentManagerServiceName, ContentManagerManagerSessions, this->ncm_manager); + return this->RegisterServer(ContentManagerServiceName, ContentManagerManagerSessions, this->ncm_manager); } ams::Result StartThreads() { @@ -200,23 +197,20 @@ namespace { class LocationResolverServerManager : public sf::hipc::ServerManager { private: - using ServiceType = lr::LocationResolverManagerImpl; + using Interface = lr::ILocationResolverManager; + using ServiceImpl = lr::LocationResolverManagerImpl; private: os::ThreadType thread; - std::shared_ptr lr_manager; + std::shared_ptr lr_manager; private: static void ThreadFunction(void *_this) { reinterpret_cast(_this)->LoopProcess(); } public: - LocationResolverServerManager(ServiceType *m) - : lr_manager(sf::ServiceObjectTraits::SharedPointerHelper::GetEmptyDeleteSharedPointer(m)) - { - /* ... */ - } + LocationResolverServerManager(ServiceImpl &m) : lr_manager(sf::GetSharedPointerTo(m)) { /* ... */ } ams::Result Initialize() { - return this->RegisterServer(LocationResolverServiceName, LocationResolverManagerSessions, this->lr_manager); + return this->RegisterServer(LocationResolverServiceName, LocationResolverManagerSessions, this->lr_manager); } ams::Result StartThreads() { @@ -232,14 +226,10 @@ namespace { }; ncm::ContentManagerImpl g_ncm_manager_service_object; - ContentManagerServerManager g_ncm_server_manager(std::addressof(g_ncm_manager_service_object)); + ContentManagerServerManager g_ncm_server_manager; lr::LocationResolverManagerImpl g_lr_manager_service_object; - LocationResolverServerManager g_lr_server_manager(std::addressof(g_lr_manager_service_object)); - - ALWAYS_INLINE std::shared_ptr GetSharedPointerToContentManager() { - return sf::ServiceObjectTraits::SharedPointerHelper::GetEmptyDeleteSharedPointer(std::addressof(g_ncm_manager_service_object)); - } + LocationResolverServerManager g_lr_server_manager(g_lr_manager_service_object); /* Compile-time configuration. */ #ifdef NCM_BUILD_FOR_INTITIALIZE @@ -270,8 +260,8 @@ int main(int argc, char **argv) AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(ncm, MainWaitThreads)); /* Create and initialize the content manager. */ - auto content_manager = GetSharedPointerToContentManager(); - R_ABORT_UNLESS(content_manager->Initialize(ManagerConfig)); + auto content_manager = sf::GetSharedPointerTo(g_ncm_manager_service_object); + R_ABORT_UNLESS(content_manager->GetImpl().Initialize(ManagerConfig)); /* Initialize ncm's server and start threads. */ R_ABORT_UNLESS(g_ncm_server_manager.Initialize(content_manager)); diff --git a/stratosphere/pgl/source/pgl_main.cpp b/stratosphere/pgl/source/pgl_main.cpp index cc5d89650..8532d6cc0 100644 --- a/stratosphere/pgl/source/pgl_main.cpp +++ b/stratosphere/pgl/source/pgl_main.cpp @@ -66,12 +66,8 @@ namespace ams::pgl { constinit pgl::srv::ShellInterface g_shell_interface; - ALWAYS_INLINE std::shared_ptr GetSharedPointerToShellInterface() { - return ams::sf::ServiceObjectTraits::SharedPointerHelper::GetEmptyDeleteSharedPointer(std::addressof(g_shell_interface)); - } - void RegisterServiceSession() { - R_ABORT_UNLESS(g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions, GetSharedPointerToShellInterface())); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions, ams::sf::GetSharedPointerTo(g_shell_interface)))); } void LoopProcess() { diff --git a/stratosphere/pm/source/pm_boot_mode_service.cpp b/stratosphere/pm/source/pm_boot_mode_service.cpp index e185ddf0a..290f05f27 100644 --- a/stratosphere/pm/source/pm_boot_mode_service.cpp +++ b/stratosphere/pm/source/pm_boot_mode_service.cpp @@ -16,7 +16,7 @@ #include #include "pm_boot_mode_service.hpp" -namespace ams::pm::bm { +namespace ams::pm { namespace { @@ -26,12 +26,16 @@ namespace ams::pm::bm { } /* Override of weakly linked boot_mode_api functions. */ - BootMode GetBootMode() { - return g_boot_mode; - } + namespace bm { + + BootMode GetBootMode() { + return g_boot_mode; + } + + void SetMaintenanceBoot() { + g_boot_mode = BootMode::Maintenance; + } - void SetMaintenanceBoot() { - g_boot_mode = BootMode::Maintenance; } /* Service command implementations. */ diff --git a/stratosphere/pm/source/pm_boot_mode_service.hpp b/stratosphere/pm/source/pm_boot_mode_service.hpp index a15f66d15..c7b6fc0b7 100644 --- a/stratosphere/pm/source/pm_boot_mode_service.hpp +++ b/stratosphere/pm/source/pm_boot_mode_service.hpp @@ -16,23 +16,13 @@ #pragma once #include -namespace ams::pm::bm { +namespace ams::pm { - class BootModeService final : public sf::IServiceObject { - private: - enum class CommandId { - GetBootMode = 0, - SetMaintenanceBoot = 1, - }; - private: - /* Actual command implementations. */ + class BootModeService final { + public: void GetBootMode(sf::Out out); void SetMaintenanceBoot(); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetBootMode), - MAKE_SERVICE_COMMAND_META(SetMaintenanceBoot), - }; }; + static_assert(pm::impl::IsIBootModeInterface); } diff --git a/stratosphere/pm/source/pm_debug_monitor_service.cpp b/stratosphere/pm/source/pm_debug_monitor_service.cpp index a42156a55..2fd98f893 100644 --- a/stratosphere/pm/source/pm_debug_monitor_service.cpp +++ b/stratosphere/pm/source/pm_debug_monitor_service.cpp @@ -17,49 +17,49 @@ #include "pm_debug_monitor_service.hpp" #include "impl/pm_process_manager.hpp" -namespace ams::pm::dmnt { +namespace ams::pm { /* Actual command implementations. */ - Result DebugMonitorServiceBase::GetModuleIdList(sf::Out out_count, const sf::OutBuffer &out_buf, u64 unused) { + Result DebugMonitorService::GetModuleIdList(sf::Out out_count, const sf::OutBuffer &out_buf, u64 unused) { R_UNLESS(out_buf.GetSize() <= std::numeric_limits::max(), pm::ResultInvalidSize()); return impl::GetModuleIdList(out_count.GetPointer(), out_buf.GetPointer(), out_buf.GetSize(), unused); } - Result DebugMonitorServiceBase::GetExceptionProcessIdList(sf::Out out_count, const sf::OutArray &out_process_ids) { + Result DebugMonitorService::GetExceptionProcessIdList(sf::Out out_count, const sf::OutArray &out_process_ids) { R_UNLESS(out_process_ids.GetSize() <= std::numeric_limits::max(), pm::ResultInvalidSize()); return impl::GetExceptionProcessIdList(out_count.GetPointer(), out_process_ids.GetPointer(), out_process_ids.GetSize()); } - Result DebugMonitorServiceBase::StartProcess(os::ProcessId process_id) { + Result DebugMonitorService::StartProcess(os::ProcessId process_id) { return impl::StartProcess(process_id); } - Result DebugMonitorServiceBase::GetProcessId(sf::Out out, ncm::ProgramId program_id) { + Result DebugMonitorService::GetProcessId(sf::Out out, ncm::ProgramId program_id) { return impl::GetProcessId(out.GetPointer(), program_id); } - Result DebugMonitorServiceBase::HookToCreateProcess(sf::OutCopyHandle out_hook, ncm::ProgramId program_id) { + Result DebugMonitorService::HookToCreateProcess(sf::OutCopyHandle out_hook, ncm::ProgramId program_id) { return impl::HookToCreateProcess(out_hook.GetHandlePointer(), program_id); } - Result DebugMonitorServiceBase::GetApplicationProcessId(sf::Out out) { + Result DebugMonitorService::GetApplicationProcessId(sf::Out out) { return impl::GetApplicationProcessId(out.GetPointer()); } - Result DebugMonitorServiceBase::HookToCreateApplicationProcess(sf::OutCopyHandle out_hook) { + Result DebugMonitorService::HookToCreateApplicationProcess(sf::OutCopyHandle out_hook) { return impl::HookToCreateApplicationProcess(out_hook.GetHandlePointer()); } - Result DebugMonitorServiceBase::ClearHook(u32 which) { + Result DebugMonitorService::ClearHook(u32 which) { return impl::ClearHook(which); } /* Atmosphere extension commands. */ - Result DebugMonitorServiceBase::AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out out_loc, sf::Out out_status, os::ProcessId process_id) { + Result DebugMonitorService::AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out out_loc, sf::Out out_status, os::ProcessId process_id) { return impl::AtmosphereGetProcessInfo(out_process_handle.GetHandlePointer(), out_loc.GetPointer(), out_status.GetPointer(), process_id); } - Result DebugMonitorServiceBase::AtmosphereGetCurrentLimitInfo(sf::Out out_cur_val, sf::Out out_lim_val, u32 group, u32 resource) { + Result DebugMonitorService::AtmosphereGetCurrentLimitInfo(sf::Out out_cur_val, sf::Out out_lim_val, u32 group, u32 resource) { return impl::AtmosphereGetCurrentLimitInfo(out_cur_val.GetPointer(), out_lim_val.GetPointer(), group, resource); } diff --git a/stratosphere/pm/source/pm_debug_monitor_service.hpp b/stratosphere/pm/source/pm_debug_monitor_service.hpp index 396d86e20..634e61104 100644 --- a/stratosphere/pm/source/pm_debug_monitor_service.hpp +++ b/stratosphere/pm/source/pm_debug_monitor_service.hpp @@ -16,90 +16,24 @@ #pragma once #include -namespace ams::pm::dmnt { +namespace ams::pm { - class DebugMonitorServiceBase : public sf::IServiceObject { - protected: + class DebugMonitorService final { + public: /* Actual command implementations. */ - virtual Result GetModuleIdList(sf::Out out_count, const sf::OutBuffer &out_buf, u64 unused); - virtual Result GetExceptionProcessIdList(sf::Out out_count, const sf::OutArray &out_process_ids); - virtual Result StartProcess(os::ProcessId process_id); - virtual Result GetProcessId(sf::Out out, ncm::ProgramId program_id); - virtual Result HookToCreateProcess(sf::OutCopyHandle out_hook, ncm::ProgramId program_id); - virtual Result GetApplicationProcessId(sf::Out out); - virtual Result HookToCreateApplicationProcess(sf::OutCopyHandle out_hook); - virtual Result ClearHook(u32 which); + Result GetModuleIdList(sf::Out out_count, const sf::OutBuffer &out_buf, u64 unused); + Result GetExceptionProcessIdList(sf::Out out_count, const sf::OutArray &out_process_ids); + Result StartProcess(os::ProcessId process_id); + Result GetProcessId(sf::Out out, ncm::ProgramId program_id); + Result HookToCreateProcess(sf::OutCopyHandle out_hook, ncm::ProgramId program_id); + Result GetApplicationProcessId(sf::Out out); + Result HookToCreateApplicationProcess(sf::OutCopyHandle out_hook); + Result ClearHook(u32 which); /* Atmosphere extension commands. */ - virtual Result AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out out_loc, sf::Out out_status, os::ProcessId process_id); - virtual Result AtmosphereGetCurrentLimitInfo(sf::Out out_cur_val, sf::Out out_lim_val, u32 group, u32 resource); - }; - - /* This represents modern DebugMonitorService (5.0.0+). */ - class DebugMonitorService final : public DebugMonitorServiceBase { - private: - enum class CommandId { - GetExceptionProcessIdList = 0, - StartProcess = 1, - GetProcessId = 2, - HookToCreateProcess = 3, - GetApplicationProcessId = 4, - HookToCreateApplicationProcess = 5, - - ClearHook = 6, - - AtmosphereGetProcessInfo = 65000, - AtmosphereGetCurrentLimitInfo = 65001, - }; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - /* 5.0.0-* */ - MAKE_SERVICE_COMMAND_META(GetExceptionProcessIdList), - MAKE_SERVICE_COMMAND_META(StartProcess), - MAKE_SERVICE_COMMAND_META(GetProcessId), - MAKE_SERVICE_COMMAND_META(HookToCreateProcess), - MAKE_SERVICE_COMMAND_META(GetApplicationProcessId), - MAKE_SERVICE_COMMAND_META(HookToCreateApplicationProcess), - - /* 6.0.0-* */ - MAKE_SERVICE_COMMAND_META(ClearHook, hos::Version_6_0_0), - - /* Atmosphere extensions. */ - MAKE_SERVICE_COMMAND_META(AtmosphereGetProcessInfo), - MAKE_SERVICE_COMMAND_META(AtmosphereGetCurrentLimitInfo), - }; - }; - - /* This represents deprecated DebugMonitorService (1.0.0-4.1.0). */ - class DebugMonitorServiceDeprecated final : public DebugMonitorServiceBase { - private: - enum class CommandId { - GetModuleIdList = 0, - GetExceptionProcessIdList = 1, - StartProcess = 2, - GetProcessId = 3, - HookToCreateProcess = 4, - GetApplicationProcessId = 5, - HookToCreateApplicationProcess = 6, - - AtmosphereGetProcessInfo = 65000, - AtmosphereGetCurrentLimitInfo = 65001, - }; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - /* 1.0.0-4.1.0 */ - MAKE_SERVICE_COMMAND_META(GetModuleIdList), - MAKE_SERVICE_COMMAND_META(GetExceptionProcessIdList), - MAKE_SERVICE_COMMAND_META(StartProcess), - MAKE_SERVICE_COMMAND_META(GetProcessId), - MAKE_SERVICE_COMMAND_META(HookToCreateProcess), - MAKE_SERVICE_COMMAND_META(GetApplicationProcessId), - MAKE_SERVICE_COMMAND_META(HookToCreateApplicationProcess), - - /* Atmosphere extensions. */ - MAKE_SERVICE_COMMAND_META(AtmosphereGetProcessInfo), - MAKE_SERVICE_COMMAND_META(AtmosphereGetCurrentLimitInfo), - }; + Result AtmosphereGetProcessInfo(sf::OutCopyHandle out_process_handle, sf::Out out_loc, sf::Out out_status, os::ProcessId process_id); + Result AtmosphereGetCurrentLimitInfo(sf::Out out_cur_val, sf::Out out_lim_val, u32 group, u32 resource); }; + static_assert(pm::impl::IsIDebugMonitorInterface); } diff --git a/stratosphere/pm/source/pm_info_service.cpp b/stratosphere/pm/source/pm_info_service.cpp index d6e34e30b..5ec0f23a4 100644 --- a/stratosphere/pm/source/pm_info_service.cpp +++ b/stratosphere/pm/source/pm_info_service.cpp @@ -17,11 +17,15 @@ #include "pm_info_service.hpp" #include "impl/pm_process_manager.hpp" -namespace ams::pm::info { +namespace ams::pm { /* Overrides for libstratosphere pm::info commands. */ - Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id) { - return ldr::pm::HasLaunchedProgram(out, program_id); + namespace info { + + Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id) { + return ldr::pm::HasLaunchedProgram(out, program_id); + } + } /* Actual command implementations. */ diff --git a/stratosphere/pm/source/pm_info_service.hpp b/stratosphere/pm/source/pm_info_service.hpp index 70043aeb8..f46639b27 100644 --- a/stratosphere/pm/source/pm_info_service.hpp +++ b/stratosphere/pm/source/pm_info_service.hpp @@ -16,18 +16,10 @@ #pragma once #include -namespace ams::pm::info { +namespace ams::pm { - class InformationService final : public sf::IServiceObject { - private: - enum class CommandId { - GetProgramId = 0, - - AtmosphereGetProcessId = 65000, - AtmosphereHasLaunchedProgram = 65001, - AtmosphereGetProcessInfo = 65002, - }; - private: + class InformationService final { + public: /* Actual command implementations. */ Result GetProgramId(sf::Out out, os::ProcessId process_id); @@ -35,14 +27,7 @@ namespace ams::pm::info { Result AtmosphereGetProcessId(sf::Out out, ncm::ProgramId program_id); Result AtmosphereHasLaunchedProgram(sf::Out out, ncm::ProgramId program_id); Result AtmosphereGetProcessInfo(sf::Out out_loc, sf::Out out_status, os::ProcessId process_id); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetProgramId), - - MAKE_SERVICE_COMMAND_META(AtmosphereGetProcessId), - MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedProgram), - MAKE_SERVICE_COMMAND_META(AtmosphereGetProcessInfo), - }; }; + static_assert(pm::impl::IsIInformationInterface); } diff --git a/stratosphere/pm/source/pm_main.cpp b/stratosphere/pm/source/pm_main.cpp index ae7078c32..a14bed856 100644 --- a/stratosphere/pm/source/pm_main.cpp +++ b/stratosphere/pm/source/pm_main.cpp @@ -196,14 +196,14 @@ int main(int argc, char **argv) /* NOTE: Extra sessions have been added to pm:bm and pm:info to facilitate access by the rest of stratosphere. */ /* Also Note: PM was rewritten in 5.0.0, so the shell and dmnt services are different before/after. */ if (hos::GetVersion() >= hos::Version_5_0_0) { - R_ABORT_UNLESS((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); - R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); } else { - R_ABORT_UNLESS((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); - R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); } - R_ABORT_UNLESS((g_server_manager.RegisterServer(BootModeServiceName, BootModeMaxSessions))); - R_ABORT_UNLESS((g_server_manager.RegisterServer(InformationServiceName, InformationMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(BootModeServiceName, BootModeMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(InformationServiceName, InformationMaxSessions))); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/pm/source/pm_shell_service.cpp b/stratosphere/pm/source/pm_shell_service.cpp index 939066dea..491c3169f 100644 --- a/stratosphere/pm/source/pm_shell_service.cpp +++ b/stratosphere/pm/source/pm_shell_service.cpp @@ -17,59 +17,63 @@ #include "pm_shell_service.hpp" #include "impl/pm_process_manager.hpp" -namespace ams::pm::shell { +namespace ams::pm { /* Overrides for libstratosphere pm::shell commands. */ - Result LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 launch_flags) { - return impl::LaunchProgram(out_process_id, loc, launch_flags); + namespace shell { + + Result LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 launch_flags) { + return impl::LaunchProgram(out_process_id, loc, launch_flags); + } + } /* Service command implementations. */ - Result ShellServiceBase::LaunchProgram(sf::Out out_process_id, const ncm::ProgramLocation &loc, u32 flags) { + Result ShellService::LaunchProgram(sf::Out out_process_id, const ncm::ProgramLocation &loc, u32 flags) { return pm::shell::LaunchProgram(out_process_id.GetPointer(), loc, flags); } - Result ShellServiceBase::TerminateProcess(os::ProcessId process_id) { + Result ShellService::TerminateProcess(os::ProcessId process_id) { return impl::TerminateProcess(process_id); } - Result ShellServiceBase::TerminateProgram(ncm::ProgramId program_id) { + Result ShellService::TerminateProgram(ncm::ProgramId program_id) { return impl::TerminateProgram(program_id); } - void ShellServiceBase::GetProcessEventHandle(sf::OutCopyHandle out) { + void ShellService::GetProcessEventHandle(sf::OutCopyHandle out) { R_ABORT_UNLESS(impl::GetProcessEventHandle(out.GetHandlePointer())); } - void ShellServiceBase::GetProcessEventInfo(sf::Out out) { + void ShellService::GetProcessEventInfo(sf::Out out) { R_ABORT_UNLESS(impl::GetProcessEventInfo(out.GetPointer())); } - Result ShellServiceBase::CleanupProcess(os::ProcessId process_id) { + Result ShellService::CleanupProcess(os::ProcessId process_id) { return impl::CleanupProcess(process_id); } - Result ShellServiceBase::ClearExceptionOccurred(os::ProcessId process_id) { + Result ShellService::ClearExceptionOccurred(os::ProcessId process_id) { return impl::ClearExceptionOccurred(process_id); } - void ShellServiceBase::NotifyBootFinished() { + void ShellService::NotifyBootFinished() { R_ABORT_UNLESS(impl::NotifyBootFinished()); } - Result ShellServiceBase::GetApplicationProcessIdForShell(sf::Out out) { + Result ShellService::GetApplicationProcessIdForShell(sf::Out out) { return impl::GetApplicationProcessId(out.GetPointer()); } - Result ShellServiceBase::BoostSystemMemoryResourceLimit(u64 boost_size) { + Result ShellService::BoostSystemMemoryResourceLimit(u64 boost_size) { return impl::BoostSystemMemoryResourceLimit(boost_size); } - Result ShellServiceBase::BoostApplicationThreadResourceLimit() { + Result ShellService::BoostApplicationThreadResourceLimit() { return impl::BoostApplicationThreadResourceLimit(); } - void ShellServiceBase::GetBootFinishedEventHandle(sf::OutCopyHandle out) { + void ShellService::GetBootFinishedEventHandle(sf::OutCopyHandle out) { R_ABORT_UNLESS(impl::GetBootFinishedEventHandle(out.GetHandlePointer())); } diff --git a/stratosphere/pm/source/pm_shell_service.hpp b/stratosphere/pm/source/pm_shell_service.hpp index 7c0d60c07..8794eedd4 100644 --- a/stratosphere/pm/source/pm_shell_service.hpp +++ b/stratosphere/pm/source/pm_shell_service.hpp @@ -16,91 +16,24 @@ #pragma once #include -namespace ams::pm::shell { +namespace ams::pm { - class ShellServiceBase : public sf::IServiceObject { - protected: + class ShellService final { + public: /* Actual command implementations. */ - virtual Result LaunchProgram(sf::Out out_process_id, const ncm::ProgramLocation &loc, u32 flags); - virtual Result TerminateProcess(os::ProcessId process_id); - virtual Result TerminateProgram(ncm::ProgramId program_id); - virtual void GetProcessEventHandle(sf::OutCopyHandle out); - virtual void GetProcessEventInfo(sf::Out out); - virtual Result CleanupProcess(os::ProcessId process_id); - virtual Result ClearExceptionOccurred(os::ProcessId process_id); - virtual void NotifyBootFinished(); - virtual Result GetApplicationProcessIdForShell(sf::Out out); - virtual Result BoostSystemMemoryResourceLimit(u64 boost_size); - virtual Result BoostApplicationThreadResourceLimit(); - virtual void GetBootFinishedEventHandle(sf::OutCopyHandle out); - }; - - /* This represents modern ShellService (5.0.0+). */ - class ShellService final : public ShellServiceBase { - private: - enum class CommandId { - LaunchProgram = 0, - TerminateProcess = 1, - TerminateProgram = 2, - GetProcessEventHandle = 3, - GetProcessEventInfo = 4, - NotifyBootFinished = 5, - GetApplicationProcessIdForShell = 6, - BoostSystemMemoryResourceLimit = 7, - BoostApplicationThreadResourceLimit = 8, - GetBootFinishedEventHandle = 9, - }; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - /* 5.0.0-* */ - MAKE_SERVICE_COMMAND_META(LaunchProgram), - MAKE_SERVICE_COMMAND_META(TerminateProcess), - MAKE_SERVICE_COMMAND_META(TerminateProgram), - MAKE_SERVICE_COMMAND_META(GetProcessEventHandle), - MAKE_SERVICE_COMMAND_META(GetProcessEventInfo), - MAKE_SERVICE_COMMAND_META(NotifyBootFinished), - MAKE_SERVICE_COMMAND_META(GetApplicationProcessIdForShell), - MAKE_SERVICE_COMMAND_META(BoostSystemMemoryResourceLimit), - - /* 7.0.0-* */ - MAKE_SERVICE_COMMAND_META(BoostApplicationThreadResourceLimit, hos::Version_7_0_0), - - /* 8.0.0-* */ - MAKE_SERVICE_COMMAND_META(GetBootFinishedEventHandle, hos::Version_8_0_0), - }; - }; - - /* This represents deprecated ShellService (1.0.0-4.1.0). */ - class ShellServiceDeprecated final : public ShellServiceBase { - private: - enum class CommandId { - LaunchProgram = 0, - TerminateProcess = 1, - TerminateProgram = 2, - GetProcessEventHandle = 3, - GetProcessEventInfo = 4, - CleanupProcess = 5, - ClearExceptionOccurred = 6, - NotifyBootFinished = 7, - GetApplicationProcessIdForShell = 8, - BoostSystemMemoryResourceLimit = 9, - }; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - /* 1.0.0-4.1.0 */ - MAKE_SERVICE_COMMAND_META(LaunchProgram), - MAKE_SERVICE_COMMAND_META(TerminateProcess), - MAKE_SERVICE_COMMAND_META(TerminateProgram), - MAKE_SERVICE_COMMAND_META(GetProcessEventHandle), - MAKE_SERVICE_COMMAND_META(GetProcessEventInfo), - MAKE_SERVICE_COMMAND_META(CleanupProcess), - MAKE_SERVICE_COMMAND_META(ClearExceptionOccurred), - MAKE_SERVICE_COMMAND_META(NotifyBootFinished), - MAKE_SERVICE_COMMAND_META(GetApplicationProcessIdForShell), - - /* 4.0.0-4.1.0 */ - MAKE_SERVICE_COMMAND_META(BoostSystemMemoryResourceLimit, hos::Version_4_0_0), - }; + Result LaunchProgram(sf::Out out_process_id, const ncm::ProgramLocation &loc, u32 flags); + Result TerminateProcess(os::ProcessId process_id); + Result TerminateProgram(ncm::ProgramId program_id); + void GetProcessEventHandle(sf::OutCopyHandle out); + void GetProcessEventInfo(sf::Out out); + Result CleanupProcess(os::ProcessId process_id); + Result ClearExceptionOccurred(os::ProcessId process_id); + void NotifyBootFinished(); + Result GetApplicationProcessIdForShell(sf::Out out); + Result BoostSystemMemoryResourceLimit(u64 boost_size); + Result BoostApplicationThreadResourceLimit(); + void GetBootFinishedEventHandle(sf::OutCopyHandle out); }; + static_assert(pm::impl::IsIShellInterface); } diff --git a/stratosphere/ro/source/impl/ro_service_impl.cpp b/stratosphere/ro/source/impl/ro_service_impl.cpp index 3fde492fa..5568b0f43 100644 --- a/stratosphere/ro/source/impl/ro_service_impl.cpp +++ b/stratosphere/ro/source/impl/ro_service_impl.cpp @@ -413,7 +413,7 @@ namespace ams::ro::impl { } /* Service implementations. */ - Result LoadNrr(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type) { + Result RegisterModuleInfo(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type) { /* Get context. */ ProcessContext *context = GetContextById(context_id); AMS_ABORT_UNLESS(context != nullptr); @@ -454,7 +454,7 @@ namespace ams::ro::impl { return ResultSuccess(); } - Result UnloadNrr(size_t context_id, u64 nrr_address) { + Result UnregisterModuleInfo(size_t context_id, u64 nrr_address) { /* Get context. */ ProcessContext *context = GetContextById(context_id); AMS_ABORT_UNLESS(context != nullptr); @@ -476,7 +476,7 @@ namespace ams::ro::impl { return UnmapNrr(context->process_handle, nrr_backup.mapped_header, nrr_backup.nrr_heap_address, nrr_backup.nrr_heap_size, nrr_backup.mapped_code_address); } - Result LoadNro(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) { + Result MapManualLoadModuleMemory(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) { /* Get context. */ ProcessContext *context = GetContextById(context_id); AMS_ABORT_UNLESS(context != nullptr); @@ -522,7 +522,7 @@ namespace ams::ro::impl { return ResultSuccess(); } - Result UnloadNro(size_t context_id, u64 nro_address) { + Result UnmapManualLoadModuleMemory(size_t context_id, u64 nro_address) { /* Get context. */ ProcessContext *context = GetContextById(context_id); AMS_ABORT_UNLESS(context != nullptr); diff --git a/stratosphere/ro/source/impl/ro_service_impl.hpp b/stratosphere/ro/source/impl/ro_service_impl.hpp index 01ad09e67..a8f45456d 100644 --- a/stratosphere/ro/source/impl/ro_service_impl.hpp +++ b/stratosphere/ro/source/impl/ro_service_impl.hpp @@ -35,10 +35,10 @@ namespace ams::ro::impl { void UnregisterProcess(size_t context_id); /* Service implementations. */ - Result LoadNrr(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type); - Result UnloadNrr(size_t context_id, u64 nrr_address); - Result LoadNro(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size); - Result UnloadNro(size_t context_id, u64 nro_address); + Result RegisterModuleInfo(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type); + Result UnregisterModuleInfo(size_t context_id, u64 nrr_address); + Result MapManualLoadModuleMemory(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size); + Result UnmapManualLoadModuleMemory(size_t context_id, u64 nro_address); /* Debug service implementations. */ Result GetProcessModuleInfo(u32 *out_count, LoaderModuleInfo *out_infos, size_t max_out_count, os::ProcessId process_id); diff --git a/stratosphere/ro/source/ro_debug_monitor.cpp b/stratosphere/ro/source/ro_debug_monitor_service.cpp similarity index 96% rename from stratosphere/ro/source/ro_debug_monitor.cpp rename to stratosphere/ro/source/ro_debug_monitor_service.cpp index 2cb4aa8ee..21a105109 100644 --- a/stratosphere/ro/source/ro_debug_monitor.cpp +++ b/stratosphere/ro/source/ro_debug_monitor_service.cpp @@ -14,7 +14,7 @@ * along with this program. If not, see . */ #include -#include "ro_debug_monitor.hpp" +#include "ro_debug_monitor_service.hpp" #include "impl/ro_service_impl.hpp" namespace ams::ro { diff --git a/stratosphere/ro/source/ro_debug_monitor.hpp b/stratosphere/ro/source/ro_debug_monitor_service.hpp similarity index 71% rename from stratosphere/ro/source/ro_debug_monitor.hpp rename to stratosphere/ro/source/ro_debug_monitor_service.hpp index f86eb00d6..58b634e43 100644 --- a/stratosphere/ro/source/ro_debug_monitor.hpp +++ b/stratosphere/ro/source/ro_debug_monitor_service.hpp @@ -18,18 +18,10 @@ namespace ams::ro { - class DebugMonitorService final : public sf::IServiceObject { - protected: - enum class CommandId { - GetProcessModuleInfo = 0, - }; - private: - /* Actual commands. */ - Result GetProcessModuleInfo(sf::Out out_count, const sf::OutArray &out_infos, os::ProcessId process_id); + class DebugMonitorService final { public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetProcessModuleInfo), - }; + Result GetProcessModuleInfo(sf::Out out_count, const sf::OutArray &out_infos, os::ProcessId process_id); }; + static_assert(ro::impl::IsIDebugMonitorInterface); } diff --git a/stratosphere/ro/source/ro_main.cpp b/stratosphere/ro/source/ro_main.cpp index 2a0a8034c..f3de32bb9 100644 --- a/stratosphere/ro/source/ro_main.cpp +++ b/stratosphere/ro/source/ro_main.cpp @@ -14,8 +14,8 @@ * along with this program. If not, see . */ #include -#include "ro_debug_monitor.hpp" -#include "ro_service.hpp" +#include "ro_debug_monitor_service.hpp" +#include "ro_ro_service.hpp" extern "C" { extern u32 __start__; @@ -84,10 +84,6 @@ void __appExit(void) { setsysExit(); } -/* Helpers to create RO objects. */ -static constexpr auto MakeRoServiceForSelf = []() { return std::make_shared(ro::ModuleType::ForSelf); }; -static constexpr auto MakeRoServiceForOthers = []() { return std::make_shared(ro::ModuleType::ForOthers); }; - namespace { /* ldr:ro, ro:dmnt, ro:1. */ @@ -122,11 +118,11 @@ int main(int argc, char **argv) } /* Create services. */ - R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); - R_ABORT_UNLESS((g_server_manager.RegisterServer(ForSelfServiceName, ForSelfMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ForSelfServiceName, ForSelfMaxSessions))); if (hos::GetVersion() >= hos::Version_7_0_0) { - R_ABORT_UNLESS((g_server_manager.RegisterServer(ForOthersServiceName, ForOthersMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ForOthersServiceName, ForOthersMaxSessions))); } /* Loop forever, servicing our services. */ diff --git a/stratosphere/ro/source/ro_ro_service.cpp b/stratosphere/ro/source/ro_ro_service.cpp new file mode 100644 index 000000000..47eb27b02 --- /dev/null +++ b/stratosphere/ro/source/ro_ro_service.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include "ro_ro_service.hpp" +#include "impl/ro_service_impl.hpp" + +namespace ams::ro { + + void SetDevelopmentHardware(bool is_development_hardware) { + impl::SetDevelopmentHardware(is_development_hardware); + } + + void SetDevelopmentFunctionEnabled(bool is_development_function_enabled) { + impl::SetDevelopmentFunctionEnabled(is_development_function_enabled); + } + + RoService::RoService(ModuleType t) : context_id(impl::InvalidContextId), type(t) { + /* ... */ + } + + RoService::~RoService() { + impl::UnregisterProcess(this->context_id); + } + + Result RoService::MapManualLoadModuleMemory(sf::Out load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) { + R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); + return impl::MapManualLoadModuleMemory(load_address.GetPointer(), this->context_id, nro_address, nro_size, bss_address, bss_size); + } + + Result RoService::UnmapManualLoadModuleMemory(const sf::ClientProcessId &client_pid, u64 nro_address) { + R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); + return impl::UnmapManualLoadModuleMemory(this->context_id, nro_address); + } + + Result RoService::RegisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size) { + R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); + return impl::RegisterModuleInfo(this->context_id, svc::InvalidHandle, nrr_address, nrr_size, ModuleType::ForSelf, true); + } + + Result RoService::UnregisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address) { + R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); + return impl::UnregisterModuleInfo(this->context_id, nrr_address); + } + + Result RoService::RegisterProcessHandle(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h) { + return impl::RegisterProcess(std::addressof(this->context_id), process_h.GetValue(), client_pid.GetValue()); + } + + Result RoService::RegisterModuleInfoEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h) { + R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); + return impl::RegisterModuleInfo(this->context_id, process_h.GetValue(), nrr_address, nrr_size, this->type, this->type == ModuleType::ForOthers); + } + +} diff --git a/stratosphere/ro/source/ro_ro_service.hpp b/stratosphere/ro/source/ro_ro_service.hpp new file mode 100644 index 000000000..c3dd6d15b --- /dev/null +++ b/stratosphere/ro/source/ro_ro_service.hpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include + +namespace ams::ro { + + /* Access utilities. */ + void SetDevelopmentHardware(bool is_development_hardware); + void SetDevelopmentFunctionEnabled(bool is_development_function_enabled); + + class RoService { + private: + size_t context_id; + ModuleType type; + protected: + explicit RoService(ModuleType t); + public: + virtual ~RoService(); + public: + /* Actual commands. */ + Result MapManualLoadModuleMemory(sf::Out out_load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size); + Result UnmapManualLoadModuleMemory(const sf::ClientProcessId &client_pid, u64 nro_address); + Result RegisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size); + Result UnregisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address); + Result RegisterProcessHandle(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h); + Result RegisterModuleInfoEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h); + }; + static_assert(ro::impl::IsIRoInterface); + + class RoServiceForSelf final : public RoService { + public: + RoServiceForSelf() : RoService(ro::ModuleType::ForSelf) { /* ... */ } + }; + + /* TODO: This is really JitPlugin... */ + class RoServiceForOthers final : public RoService { + public: + RoServiceForOthers() : RoService(ro::ModuleType::ForOthers) { /* ... */ } + }; + +} diff --git a/stratosphere/ro/source/ro_service.cpp b/stratosphere/ro/source/ro_service.cpp deleted file mode 100644 index 96d38519f..000000000 --- a/stratosphere/ro/source/ro_service.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2018-2020 Atmosphère-NX - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include -#include "ro_service.hpp" -#include "impl/ro_service_impl.hpp" - -namespace ams::ro { - - void SetDevelopmentHardware(bool is_development_hardware) { - impl::SetDevelopmentHardware(is_development_hardware); - } - - void SetDevelopmentFunctionEnabled(bool is_development_function_enabled) { - impl::SetDevelopmentFunctionEnabled(is_development_function_enabled); - } - - Service::Service(ModuleType t) : context_id(impl::InvalidContextId), type(t) { - /* ... */ - } - - Service::~Service() { - impl::UnregisterProcess(this->context_id); - } - - Result Service::LoadNro(sf::Out load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) { - R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); - return impl::LoadNro(load_address.GetPointer(), this->context_id, nro_address, nro_size, bss_address, bss_size); - } - - Result Service::UnloadNro(const sf::ClientProcessId &client_pid, u64 nro_address) { - R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); - return impl::UnloadNro(this->context_id, nro_address); - } - - Result Service::LoadNrr(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size) { - R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); - return impl::LoadNrr(this->context_id, INVALID_HANDLE, nrr_address, nrr_size, ModuleType::ForSelf, true); - } - - Result Service::UnloadNrr(const sf::ClientProcessId &client_pid, u64 nrr_address) { - R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); - return impl::UnloadNrr(this->context_id, nrr_address); - } - - Result Service::Initialize(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h) { - return impl::RegisterProcess(&this->context_id, process_h.GetValue(), client_pid.GetValue()); - } - - Result Service::LoadNrrEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h) { - R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue())); - return impl::LoadNrr(this->context_id, process_h.GetValue(), nrr_address, nrr_size, this->type, this->type == ModuleType::ForOthers); - } - -} diff --git a/stratosphere/ro/source/ro_service.hpp b/stratosphere/ro/source/ro_service.hpp deleted file mode 100644 index 6cc943ef9..000000000 --- a/stratosphere/ro/source/ro_service.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2018-2020 Atmosphère-NX - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once -#include - -namespace ams::ro { - - /* Access utilities. */ - void SetDevelopmentHardware(bool is_development_hardware); - void SetDevelopmentFunctionEnabled(bool is_development_function_enabled); - - class Service final : public sf::IServiceObject { - protected: - enum class CommandId { - LoadNro = 0, - UnloadNro = 1, - LoadNrr = 2, - UnloadNrr = 3, - Initialize = 4, - LoadNrrEx = 10, - }; - private: - size_t context_id; - ModuleType type; - public: - explicit Service(ModuleType t); - virtual ~Service(); - private: - /* Actual commands. */ - Result LoadNro(sf::Out out_load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size); - Result UnloadNro(const sf::ClientProcessId &client_pid, u64 nro_address); - Result LoadNrr(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size); - Result UnloadNrr(const sf::ClientProcessId &client_pid, u64 nrr_address); - Result Initialize(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h); - Result LoadNrrEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(LoadNro), - MAKE_SERVICE_COMMAND_META(UnloadNro), - MAKE_SERVICE_COMMAND_META(LoadNrr), - MAKE_SERVICE_COMMAND_META(UnloadNrr), - MAKE_SERVICE_COMMAND_META(Initialize), - MAKE_SERVICE_COMMAND_META(LoadNrrEx, hos::Version_7_0_0), - }; - - }; - -} diff --git a/stratosphere/sm/source/sm_dmnt_service.cpp b/stratosphere/sm/source/sm_debug_monitor_service.cpp similarity index 73% rename from stratosphere/sm/source/sm_dmnt_service.cpp rename to stratosphere/sm/source/sm_debug_monitor_service.cpp index 7ee32f363..4622bbb4d 100644 --- a/stratosphere/sm/source/sm_dmnt_service.cpp +++ b/stratosphere/sm/source/sm_debug_monitor_service.cpp @@ -14,20 +14,20 @@ * along with this program. If not, see . */ #include -#include "sm_dmnt_service.hpp" +#include "sm_debug_monitor_service.hpp" #include "impl/sm_service_manager.hpp" namespace ams::sm { - Result DmntService::AtmosphereGetRecord(sf::Out record, ServiceName service) { + Result DebugMonitorService::AtmosphereGetRecord(sf::Out record, ServiceName service) { return impl::GetServiceRecord(record.GetPointer(), service); } - void DmntService::AtmosphereListRecords(const sf::OutArray &records, sf::Out out_count, u64 offset) { + void DebugMonitorService::AtmosphereListRecords(const sf::OutArray &records, sf::Out out_count, u64 offset) { R_ABORT_UNLESS(impl::ListServiceRecords(records.GetPointer(), out_count.GetPointer(), offset, records.GetSize())); } - void DmntService::AtmosphereGetRecordSize(sf::Out record_size) { + void DebugMonitorService::AtmosphereGetRecordSize(sf::Out record_size) { record_size.SetValue(sizeof(ServiceRecord)); } diff --git a/stratosphere/sm/source/sm_debug_monitor_service.hpp b/stratosphere/sm/source/sm_debug_monitor_service.hpp new file mode 100644 index 000000000..9b405e769 --- /dev/null +++ b/stratosphere/sm/source/sm_debug_monitor_service.hpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include + +namespace ams::sm { + + /* Service definition. */ + class DebugMonitorService final { + public: + Result AtmosphereGetRecord(sf::Out record, ServiceName service); + void AtmosphereListRecords(const sf::OutArray &records, sf::Out out_count, u64 offset); + void AtmosphereGetRecordSize(sf::Out record_size); + }; + static_assert(sm::impl::IsIDebugMonitorInterface); + +} diff --git a/stratosphere/sm/source/sm_dmnt_service.hpp b/stratosphere/sm/source/sm_dmnt_service.hpp deleted file mode 100644 index 08a1c2ac6..000000000 --- a/stratosphere/sm/source/sm_dmnt_service.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2018-2020 Atmosphère-NX - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once -#include - -namespace ams::sm { - - /* Service definition. */ - class DmntService final : public sf::IServiceObject { - protected: - /* Command IDs. */ - enum class CommandId { - AtmosphereGetRecord = 65000, - AtmosphereListRecords = 65001, - AtmosphereGetRecordSize = 65002, - }; - private: - /* Actual commands. */ - virtual Result AtmosphereGetRecord(sf::Out record, ServiceName service); - virtual void AtmosphereListRecords(const sf::OutArray &records, sf::Out out_count, u64 offset); - virtual void AtmosphereGetRecordSize(sf::Out record_size); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(AtmosphereGetRecord), - MAKE_SERVICE_COMMAND_META(AtmosphereListRecords), - MAKE_SERVICE_COMMAND_META(AtmosphereGetRecordSize), - }; - }; - -} diff --git a/stratosphere/sm/source/sm_main.cpp b/stratosphere/sm/source/sm_main.cpp index eb2c56dfc..2916c8e51 100644 --- a/stratosphere/sm/source/sm_main.cpp +++ b/stratosphere/sm/source/sm_main.cpp @@ -16,7 +16,7 @@ #include #include "sm_user_service.hpp" #include "sm_manager_service.hpp" -#include "sm_dmnt_service.hpp" +#include "sm_debug_monitor_service.hpp" #include "impl/sm_service_manager.hpp" extern "C" { @@ -101,14 +101,14 @@ int main(int argc, char **argv) { Handle sm_h; R_ABORT_UNLESS(svcManageNamedPort(&sm_h, "sm:", 0x40)); - g_server_manager.RegisterServer(sm_h); + g_server_manager.RegisterServer(sm_h); } /* Create sm:m manually. */ { Handle smm_h; R_ABORT_UNLESS(sm::impl::RegisterServiceForSelf(&smm_h, sm::ServiceName::Encode("sm:m"), 1)); - g_server_manager.RegisterServer(smm_h); + g_server_manager.RegisterServer(smm_h); } /*===== ATMOSPHERE EXTENSION =====*/ @@ -116,7 +116,7 @@ int main(int argc, char **argv) { Handle smdmnt_h; R_ABORT_UNLESS(sm::impl::RegisterServiceForSelf(&smdmnt_h, sm::ServiceName::Encode("sm:dmnt"), 1)); - g_server_manager.RegisterServer(smdmnt_h); + g_server_manager.RegisterServer(smdmnt_h); } /*================================*/ diff --git a/stratosphere/sm/source/sm_manager_service.hpp b/stratosphere/sm/source/sm_manager_service.hpp index 05340baa4..1906c1824 100644 --- a/stratosphere/sm/source/sm_manager_service.hpp +++ b/stratosphere/sm/source/sm_manager_service.hpp @@ -19,33 +19,14 @@ namespace ams::sm { /* Service definition. */ - class ManagerService final : public sf::IServiceObject { - protected: - /* Command IDs. */ - enum class CommandId { - RegisterProcess = 0, - UnregisterProcess = 1, - - AtmosphereEndInitDefers = 65000, - AtmosphereHasMitm = 65001, - AtmosphereRegisterProcess = 65002, - }; - private: - /* Actual commands. */ - virtual Result RegisterProcess(os::ProcessId process_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac); - virtual Result UnregisterProcess(os::ProcessId process_id); - virtual void AtmosphereEndInitDefers(); - virtual void AtmosphereHasMitm(sf::Out out, ServiceName service); - virtual Result AtmosphereRegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus override_status, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac); + class ManagerService final { public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(RegisterProcess), - MAKE_SERVICE_COMMAND_META(UnregisterProcess), - - MAKE_SERVICE_COMMAND_META(AtmosphereEndInitDefers), - MAKE_SERVICE_COMMAND_META(AtmosphereHasMitm), - MAKE_SERVICE_COMMAND_META(AtmosphereRegisterProcess), - }; + Result RegisterProcess(os::ProcessId process_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac); + Result UnregisterProcess(os::ProcessId process_id); + void AtmosphereEndInitDefers(); + void AtmosphereHasMitm(sf::Out out, ServiceName service); + Result AtmosphereRegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus override_status, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac); }; + static_assert(sm::impl::IsIManagerInterface); } diff --git a/stratosphere/sm/source/sm_user_service.cpp b/stratosphere/sm/source/sm_user_service.cpp index f36c661e7..67143af19 100644 --- a/stratosphere/sm/source/sm_user_service.cpp +++ b/stratosphere/sm/source/sm_user_service.cpp @@ -19,20 +19,18 @@ namespace ams::sm { - Result UserService::Initialize(const sf::ClientProcessId &client_process_id) { + Result UserService::RegisterClient(const sf::ClientProcessId &client_process_id) { this->process_id = client_process_id.GetValue(); this->has_initialized = true; return ResultSuccess(); } Result UserService::EnsureInitialized() { - if (!this->has_initialized) { - return sm::ResultInvalidClient(); - } + R_UNLESS(this->has_initialized, sm::ResultInvalidClient()); return ResultSuccess(); } - Result UserService::GetService(sf::OutMoveHandle out_h, ServiceName service) { + Result UserService::GetServiceHandle(sf::OutMoveHandle out_h, ServiceName service) { R_TRY(this->EnsureInitialized()); return impl::GetServiceHandle(out_h.GetHandlePointer(), this->process_id, service); } diff --git a/stratosphere/sm/source/sm_user_service.hpp b/stratosphere/sm/source/sm_user_service.hpp index 341760f8f..bc2c02f3f 100644 --- a/stratosphere/sm/source/sm_user_service.hpp +++ b/stratosphere/sm/source/sm_user_service.hpp @@ -20,26 +20,7 @@ namespace ams::sm { /* Service definition. */ - class UserService final : public sf::IServiceObject { - protected: - /* Command IDs. */ - enum class CommandId { - Initialize = 0, - GetService = 1, - RegisterService = 2, - UnregisterService = 3, - - AtmosphereInstallMitm = 65000, - AtmosphereUninstallMitm = 65001, - /* Deprecated: AtmosphereAssociatePidTidForMitm = 65002 */ - AtmosphereAcknowledgeMitmSession = 65003, - AtmosphereHasMitm = 65004, - AtmosphereWaitMitm = 65005, - AtmosphereDeclareFutureMitm = 65006, - - AtmosphereHasService = 65100, - AtmosphereWaitService = 65101, - }; + class UserService final { private: os::ProcessId process_id = os::InvalidProcessId; bool has_initialized = false; @@ -47,38 +28,22 @@ namespace ams::sm { Result EnsureInitialized(); public: /* Official commands. */ - virtual Result Initialize(const sf::ClientProcessId &client_process_id); - virtual Result GetService(sf::OutMoveHandle out_h, ServiceName service); - virtual Result RegisterService(sf::OutMoveHandle out_h, ServiceName service, u32 max_sessions, bool is_light); - virtual Result UnregisterService(ServiceName service); + Result RegisterClient(const sf::ClientProcessId &client_process_id); + Result GetServiceHandle(sf::OutMoveHandle out_h, ServiceName service); + Result RegisterService(sf::OutMoveHandle out_h, ServiceName service, u32 max_sessions, bool is_light); + Result UnregisterService(ServiceName service); /* Atmosphere commands. */ - virtual Result AtmosphereInstallMitm(sf::OutMoveHandle srv_h, sf::OutMoveHandle qry_h, ServiceName service); - virtual Result AtmosphereUninstallMitm(ServiceName service); - virtual Result AtmosphereAcknowledgeMitmSession(sf::Out client_info, sf::OutMoveHandle fwd_h, ServiceName service); - virtual Result AtmosphereHasMitm(sf::Out out, ServiceName service); - virtual Result AtmosphereWaitMitm(ServiceName service); - virtual Result AtmosphereDeclareFutureMitm(ServiceName service); + Result AtmosphereInstallMitm(sf::OutMoveHandle srv_h, sf::OutMoveHandle qry_h, ServiceName service); + Result AtmosphereUninstallMitm(ServiceName service); + Result AtmosphereAcknowledgeMitmSession(sf::Out client_info, sf::OutMoveHandle fwd_h, ServiceName service); + Result AtmosphereHasMitm(sf::Out out, ServiceName service); + Result AtmosphereWaitMitm(ServiceName service); + Result AtmosphereDeclareFutureMitm(ServiceName service); - virtual Result AtmosphereHasService(sf::Out out, ServiceName service); - virtual Result AtmosphereWaitService(ServiceName service); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(Initialize), - MAKE_SERVICE_COMMAND_META(GetService), - MAKE_SERVICE_COMMAND_META(RegisterService), - MAKE_SERVICE_COMMAND_META(UnregisterService), - - MAKE_SERVICE_COMMAND_META(AtmosphereInstallMitm), - MAKE_SERVICE_COMMAND_META(AtmosphereUninstallMitm), - MAKE_SERVICE_COMMAND_META(AtmosphereAcknowledgeMitmSession), - MAKE_SERVICE_COMMAND_META(AtmosphereHasMitm), - MAKE_SERVICE_COMMAND_META(AtmosphereWaitMitm), - MAKE_SERVICE_COMMAND_META(AtmosphereDeclareFutureMitm), - - MAKE_SERVICE_COMMAND_META(AtmosphereHasService), - MAKE_SERVICE_COMMAND_META(AtmosphereWaitService), - }; + Result AtmosphereHasService(sf::Out out, ServiceName service); + Result AtmosphereWaitService(ServiceName service); }; + static_assert(sm::impl::IsIUserInterface); } diff --git a/stratosphere/spl/source/spl_api_impl.cpp b/stratosphere/spl/source/spl_api_impl.cpp index f4c420070..2a5550d12 100644 --- a/stratosphere/spl/source/spl_api_impl.cpp +++ b/stratosphere/spl/source/spl_api_impl.cpp @@ -24,39 +24,39 @@ namespace ams::spl::impl { /* Convenient defines. */ constexpr size_t DeviceAddressSpaceAlign = 0x400000; - constexpr u32 WorkBufferMapBase = 0x80000000u; - constexpr u32 CryptAesInMapBase = 0x90000000u; - constexpr u32 CryptAesOutMapBase = 0xC0000000u; - constexpr size_t CryptAesSizeMax = static_cast(CryptAesOutMapBase - CryptAesInMapBase); + constexpr u32 WorkBufferMapBase = 0x80000000u; + constexpr u32 ComputeAesInMapBase = 0x90000000u; + constexpr u32 ComputeAesOutMapBase = 0xC0000000u; + constexpr size_t ComputeAesSizeMax = static_cast(ComputeAesOutMapBase - ComputeAesInMapBase); constexpr size_t RsaPrivateKeySize = 0x100; - constexpr size_t RsaPrivateKeyMetaSize = 0x30; + constexpr size_t DeviceUniqueDataMetaSize = 0x30; constexpr size_t LabelDigestSizeMax = 0x20; constexpr size_t WorkBufferSizeMax = 0x800; - constexpr s32 MaxPhysicalAesKeyslots = 6; - constexpr s32 MaxPhysicalAesKeyslotsDeprecated = 4; + constexpr s32 MaxPhysicalAesKeySlots = 6; + constexpr s32 MaxPhysicalAesKeySlotsDeprecated = 4; - constexpr s32 MaxVirtualAesKeyslots = 9; + constexpr s32 MaxVirtualAesKeySlots = 9; - /* Keyslot management. */ + /* KeySlot management. */ KeySlotCache g_keyslot_cache; - std::optional g_keyslot_cache_entry[MaxPhysicalAesKeyslots]; + std::optional g_keyslot_cache_entry[MaxPhysicalAesKeySlots]; - inline s32 GetMaxPhysicalKeyslots() { - return (hos::GetVersion() >= hos::Version_6_0_0) ? MaxPhysicalAesKeyslots : MaxPhysicalAesKeyslotsDeprecated; + inline s32 GetMaxPhysicalKeySlots() { + return (hos::GetVersion() >= hos::Version_6_0_0) ? MaxPhysicalAesKeySlots : MaxPhysicalAesKeySlotsDeprecated; } constexpr s32 VirtualKeySlotMin = 16; - constexpr s32 VirtualKeySlotMax = VirtualKeySlotMin + MaxVirtualAesKeyslots - 1; + constexpr s32 VirtualKeySlotMax = VirtualKeySlotMin + MaxVirtualAesKeySlots - 1; constexpr inline bool IsVirtualKeySlot(s32 keyslot) { return VirtualKeySlotMin <= keyslot && keyslot <= VirtualKeySlotMax; } inline bool IsPhysicalKeySlot(s32 keyslot) { - return keyslot < GetMaxPhysicalKeyslots(); + return keyslot < GetMaxPhysicalKeySlots(); } constexpr inline s32 GetVirtualKeySlotIndex(s32 keyslot) { @@ -71,16 +71,16 @@ namespace ams::spl::impl { } void InitializeKeySlotCache() { - for (s32 i = 0; i < MaxPhysicalAesKeyslots; i++) { + for (s32 i = 0; i < MaxPhysicalAesKeySlots; i++) { g_keyslot_cache_entry[i].emplace(i); g_keyslot_cache.AddEntry(std::addressof(g_keyslot_cache_entry[i].value())); } } enum class KeySlotContentType { - None = 0, - AesKey = 1, - TitleKey = 2, + None = 0, + AesKey = 1, + PreparedKey = 2, }; struct KeySlotContents { @@ -92,15 +92,15 @@ namespace ams::spl::impl { } aes_key; struct { AccessKey access_key; - } title_key; + } prepared_key; }; }; - const void *g_keyslot_owners[MaxVirtualAesKeyslots]; - KeySlotContents g_keyslot_contents[MaxVirtualAesKeyslots]; - KeySlotContents g_physical_keyslot_contents_for_backwards_compatibility[MaxPhysicalAesKeyslots]; + const void *g_keyslot_owners[MaxVirtualAesKeySlots]; + KeySlotContents g_keyslot_contents[MaxVirtualAesKeySlots]; + KeySlotContents g_physical_keyslot_contents_for_backwards_compatibility[MaxPhysicalAesKeySlots]; - void ClearPhysicalKeyslot(s32 keyslot) { + void ClearPhysicalKeySlot(s32 keyslot) { AMS_ASSERT(IsPhysicalKeySlot(keyslot)); AccessKey access_key = {}; @@ -139,13 +139,13 @@ namespace ams::spl::impl { if (load) { switch (contents->type) { case KeySlotContentType::None: - ClearPhysicalKeyslot(phys_slot); + ClearPhysicalKeySlot(phys_slot); break; case KeySlotContentType::AesKey: R_ABORT_UNLESS(smc::ConvertResult(smc::LoadAesKey(phys_slot, contents->aes_key.access_key, contents->aes_key.key_source))); break; - case KeySlotContentType::TitleKey: - R_ABORT_UNLESS(smc::ConvertResult(smc::LoadTitleKey(phys_slot, contents->title_key.access_key))); + case KeySlotContentType::PreparedKey: + R_ABORT_UNLESS(smc::ConvertResult(smc::LoadPreparedAesKey(phys_slot, contents->prepared_key.access_key))); break; AMS_UNREACHABLE_DEFAULT_CASE(); } @@ -169,32 +169,32 @@ namespace ams::spl::impl { return ResultSuccess(); } - Result LoadVirtualTitleKey(s32 keyslot, const AccessKey &access_key) { + Result LoadVirtualPreparedAesKey(s32 keyslot, const AccessKey &access_key) { /* Ensure we can load into the slot. */ const s32 phys_slot = GetPhysicalKeySlot(keyslot, false); - R_TRY(smc::ConvertResult(smc::LoadTitleKey(phys_slot, access_key))); + R_TRY(smc::ConvertResult(smc::LoadPreparedAesKey(phys_slot, access_key))); /* Update our contents. */ const s32 index = GetVirtualKeySlotIndex(keyslot); - g_keyslot_contents[index].type = KeySlotContentType::TitleKey; - g_keyslot_contents[index].title_key.access_key = access_key; + g_keyslot_contents[index].type = KeySlotContentType::PreparedKey; + g_keyslot_contents[index].prepared_key.access_key = access_key; return ResultSuccess(); } /* Type definitions. */ - class ScopedAesKeyslot { + class ScopedAesKeySlot { private: s32 slot; bool has_slot; public: - ScopedAesKeyslot() : slot(-1), has_slot(false) { + ScopedAesKeySlot() : slot(-1), has_slot(false) { /* ... */ } - ~ScopedAesKeyslot() { + ~ScopedAesKeySlot() { if (this->has_slot) { - FreeAesKeyslot(slot, this); + DeallocateAesKeySlot(slot, this); } } @@ -203,7 +203,7 @@ namespace ams::spl::impl { } Result Allocate() { - R_TRY(AllocateAesKeyslot(&this->slot, this)); + R_TRY(AllocateAesKeySlot(&this->slot, this)); this->has_slot = true; return ResultSuccess(); } @@ -269,7 +269,7 @@ namespace ams::spl::impl { void InitializeSeEvents() { u64 irq_num; - AMS_ABORT_UNLESS(smc::GetConfig(&irq_num, 1, SplConfigItem_SecurityEngineIrqNumber) == smc::Result::Success); + AMS_ABORT_UNLESS(smc::GetConfig(&irq_num, 1, ConfigItem::SecurityEngineInterruptNumber) == smc::Result::Success); os::InitializeInterruptEvent(std::addressof(g_se_event), irq_num, os::EventClearMode_AutoClear); R_ABORT_UNLESS(os::CreateSystemEvent(std::addressof(g_se_keyslot_available_event), os::EventClearMode_AutoClear, true)); @@ -320,7 +320,7 @@ namespace ams::spl::impl { WaitSeOperationComplete(); smc::Result op_res; - smc::Result res = smc::CheckStatus(&op_res, op_key); + smc::Result res = smc::GetResult(&op_res, op_key); if (res != smc::Result::Success) { return res; } @@ -332,7 +332,7 @@ namespace ams::spl::impl { WaitSeOperationComplete(); smc::Result op_res; - smc::Result res = smc::GetResult(&op_res, out_buf, out_buf_size, op_key); + smc::Result res = smc::GetResultData(&op_res, out_buf, out_buf_size, op_key); if (res != smc::Result::Success) { return res; } @@ -340,17 +340,17 @@ namespace ams::spl::impl { return op_res; } - /* Internal Keyslot utility. */ - Result ValidateAesKeyslot(s32 keyslot, const void *owner) { + /* Internal KeySlot utility. */ + Result ValidateAesKeySlot(s32 keyslot, const void *owner) { /* Allow the use of physical keyslots on 1.0.0. */ if (hos::GetVersion() == hos::Version_1_0_0) { R_SUCCEED_IF(IsPhysicalKeySlot(keyslot)); } - R_UNLESS(IsVirtualKeySlot(keyslot), spl::ResultInvalidKeyslot()); + R_UNLESS(IsVirtualKeySlot(keyslot), spl::ResultInvalidKeySlot()); const s32 index = GetVirtualKeySlotIndex(keyslot); - R_UNLESS(g_keyslot_owners[index] == owner, spl::ResultInvalidKeyslot()); + R_UNLESS(g_keyslot_owners[index] == owner, spl::ResultInvalidKeySlot()); return ResultSuccess(); } @@ -377,11 +377,11 @@ namespace ams::spl::impl { std::scoped_lock lk(g_async_op_lock); smc::AsyncOperationKey op_key; const IvCtr iv_ctr = {}; - const u32 mode = smc::GetCryptAesMode(smc::CipherMode::CbcDecrypt, GetPhysicalKeySlot(keyslot, true)); + const u32 mode = smc::GetComputeAesMode(smc::CipherMode::CbcDecrypt, GetPhysicalKeySlot(keyslot, true)); const u32 dst_ll_addr = g_se_mapped_work_buffer_addr + offsetof(DecryptAesBlockLayout, crypt_ctx.out); const u32 src_ll_addr = g_se_mapped_work_buffer_addr + offsetof(DecryptAesBlockLayout, crypt_ctx.in); - smc::Result res = smc::CryptAes(&op_key, mode, iv_ctr, dst_ll_addr, src_ll_addr, sizeof(layout->in_block)); + smc::Result res = smc::ComputeAes(&op_key, mode, iv_ctr, dst_ll_addr, src_ll_addr, sizeof(layout->in_block)); if (res != smc::Result::Success) { return res; } @@ -397,33 +397,33 @@ namespace ams::spl::impl { } /* Implementation wrappers for API commands. */ - Result ImportSecureExpModKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option) { - struct ImportSecureExpModKeyLayout { - u8 data[RsaPrivateKeyMetaSize + 2 * RsaPrivateKeySize + 0x10]; + Result DecryptAndStoreDeviceUniqueKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option) { + struct DecryptAndStoreDeviceUniqueKeyLayout { + u8 data[DeviceUniqueDataMetaSize + 2 * RsaPrivateKeySize + 0x10]; }; - ImportSecureExpModKeyLayout *layout = reinterpret_cast(g_work_buffer); + DecryptAndStoreDeviceUniqueKeyLayout *layout = reinterpret_cast(g_work_buffer); /* Validate size. */ - R_UNLESS(src_size <= sizeof(ImportSecureExpModKeyLayout), spl::ResultInvalidSize()); + R_UNLESS(src_size <= sizeof(DecryptAndStoreDeviceUniqueKeyLayout), spl::ResultInvalidSize()); std::memcpy(layout, src, src_size); armDCacheFlush(layout, sizeof(*layout)); smc::Result smc_res; if (hos::GetVersion() >= hos::Version_5_0_0) { - smc_res = smc::DecryptOrImportRsaPrivateKey(layout->data, src_size, access_key, key_source, static_cast(option)); + smc_res = smc::DecryptDeviceUniqueData(layout->data, src_size, access_key, key_source, static_cast(option)); } else { - smc_res = smc::ImportSecureExpModKey(layout->data, src_size, access_key, key_source, option); + smc_res = smc::DecryptAndStoreGcKey(layout->data, src_size, access_key, key_source, option); } return smc::ConvertResult(smc_res); } - Result SecureExpMod(void *out, size_t out_size, const void *base, size_t base_size, const void *mod, size_t mod_size, smc::SecureExpModMode mode) { - struct SecureExpModLayout { + Result ModularExponentiateWithStorageKey(void *out, size_t out_size, const void *base, size_t base_size, const void *mod, size_t mod_size, smc::ModularExponentiateWithStorageKeyMode mode) { + struct ModularExponentiateWithStorageKeyLayout { u8 base[0x100]; u8 mod[0x100]; }; - SecureExpModLayout *layout = reinterpret_cast(g_work_buffer); + ModularExponentiateWithStorageKeyLayout *layout = reinterpret_cast(g_work_buffer); /* Validate sizes. */ R_UNLESS(base_size <= sizeof(layout->base), spl::ResultInvalidSize()); @@ -443,7 +443,7 @@ namespace ams::spl::impl { std::scoped_lock lk(g_async_op_lock); smc::AsyncOperationKey op_key; - smc::Result res = smc::SecureExpMod(&op_key, layout->base, layout->mod, mode); + smc::Result res = smc::ModularExponentiateWithStorageKey(&op_key, layout->base, layout->mod, mode); if (res != smc::Result::Success) { return smc::ConvertResult(res); } @@ -458,12 +458,12 @@ namespace ams::spl::impl { return ResultSuccess(); } - Result UnwrapEsRsaOaepWrappedKey(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation, smc::EsKeyType type) { - struct UnwrapEsKeyLayout { + Result PrepareEsDeviceUniqueKey(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation, smc::EsCommonKeyType type) { + struct PrepareEsDeviceUniqueKeyLayout { u8 base[0x100]; u8 mod[0x100]; }; - UnwrapEsKeyLayout *layout = reinterpret_cast(g_work_buffer); + PrepareEsDeviceUniqueKeyLayout *layout = reinterpret_cast(g_work_buffer); /* Validate sizes. */ R_UNLESS(base_size <= sizeof(layout->base), spl::ResultInvalidSize()); @@ -483,7 +483,7 @@ namespace ams::spl::impl { std::scoped_lock lk(g_async_op_lock); smc::AsyncOperationKey op_key; - smc::Result res = smc::UnwrapTitleKey(&op_key, layout->base, layout->mod, label_digest, label_digest_size, smc::GetUnwrapEsKeyOption(type, generation)); + smc::Result res = smc::PrepareEsDeviceUniqueKey(&op_key, layout->base, layout->mod, label_digest, label_digest_size, smc::GetPrepareEsDeviceUniqueKeyOption(type, generation)); if (res != smc::Result::Success) { return smc::ConvertResult(res); } @@ -514,39 +514,45 @@ namespace ams::spl::impl { } /* General. */ - Result GetConfig(u64 *out, SplConfigItem which) { + Result GetConfig(u64 *out, ConfigItem which) { /* Nintendo explicitly blacklists package2 hash here, amusingly. */ /* This is not blacklisted in safemode, but we're never in safe mode... */ - R_UNLESS(which != SplConfigItem_Package2Hash, spl::ResultInvalidArgument()); + R_UNLESS(which != ConfigItem::Package2Hash, spl::ResultInvalidArgument()); smc::Result res = smc::GetConfig(out, 1, which); /* Nintendo has some special handling here for hardware type/is_retail. */ - if (which == SplConfigItem_HardwareType && res == smc::Result::InvalidArgument) { - *out = 0; - res = smc::Result::Success; - } - if (which == SplConfigItem_IsRetail && res == smc::Result::InvalidArgument) { - *out = 0; - res = smc::Result::Success; + if (res == smc::Result::InvalidArgument) { + switch (which) { + case ConfigItem::HardwareType: + *out = static_cast(HardwareType::Icosa); + res = smc::Result::Success; + break; + case ConfigItem::HardwareState: + *out = HardwareState_Development; + res = smc::Result::Success; + break; + default: + break; + } } return smc::ConvertResult(res); } - Result ExpMod(void *out, size_t out_size, const void *base, size_t base_size, const void *exp, size_t exp_size, const void *mod, size_t mod_size) { - struct ExpModLayout { + Result ModularExponentiate(void *out, size_t out_size, const void *base, size_t base_size, const void *exp, size_t exp_size, const void *mod, size_t mod_size) { + struct ModularExponentiateLayout { u8 base[0x100]; u8 exp[0x100]; u8 mod[0x100]; }; - ExpModLayout *layout = reinterpret_cast(g_work_buffer); + ModularExponentiateLayout *layout = reinterpret_cast(g_work_buffer); /* Validate sizes. */ R_UNLESS(base_size <= sizeof(layout->base), spl::ResultInvalidSize()); - R_UNLESS(exp_size <= sizeof(layout->exp), spl::ResultInvalidSize()); - R_UNLESS(mod_size <= sizeof(layout->mod), spl::ResultInvalidSize()); - R_UNLESS(out_size <= WorkBufferSizeMax, spl::ResultInvalidSize()); + R_UNLESS(exp_size <= sizeof(layout->exp), spl::ResultInvalidSize()); + R_UNLESS(mod_size <= sizeof(layout->mod), spl::ResultInvalidSize()); + R_UNLESS(out_size <= WorkBufferSizeMax, spl::ResultInvalidSize()); /* Copy data into work buffer. */ const size_t base_ofs = sizeof(layout->base) - base_size; @@ -562,7 +568,7 @@ namespace ams::spl::impl { std::scoped_lock lk(g_async_op_lock); smc::AsyncOperationKey op_key; - smc::Result res = smc::ExpMod(&op_key, layout->base, layout->exp, exp_size, layout->mod); + smc::Result res = smc::ModularExponentiate(&op_key, layout->base, layout->exp, exp_size, layout->mod); if (res != smc::Result::Success) { return smc::ConvertResult(res); } @@ -577,7 +583,7 @@ namespace ams::spl::impl { return ResultSuccess(); } - Result SetConfig(SplConfigItem which, u64 value) { + Result SetConfig(ConfigItem which, u64 value) { return smc::ConvertResult(smc::SetConfig(which, &value, 1)); } @@ -595,10 +601,10 @@ namespace ams::spl::impl { } Result IsDevelopment(bool *out) { - u64 is_retail; - R_TRY(GetConfig(&is_retail, SplConfigItem_IsRetail)); + u64 hardware_state; + R_TRY(impl::GetConfig(&hardware_state, ConfigItem::HardwareState)); - *out = (is_retail == 0); + *out = (hardware_state == HardwareState_Development); return ResultSuccess(); } @@ -623,7 +629,7 @@ namespace ams::spl::impl { } Result LoadAesKey(s32 keyslot, const void *owner, const AccessKey &access_key, const KeySource &key_source) { - R_TRY(ValidateAesKeyslot(keyslot, owner)); + R_TRY(ValidateAesKeySlot(keyslot, owner)); return LoadVirtualAesKey(keyslot, access_key, key_source); } @@ -632,7 +638,7 @@ namespace ams::spl::impl { .data = {0x89, 0x61, 0x5E, 0xE0, 0x5C, 0x31, 0xB6, 0x80, 0x5F, 0xE5, 0x8F, 0x3D, 0xA2, 0x4F, 0x7A, 0xA8} }; - ScopedAesKeyslot keyslot_holder; + ScopedAesKeySlot keyslot_holder; R_TRY(keyslot_holder.Allocate()); R_TRY(LoadVirtualAesKey(keyslot_holder.GetKeySlot(), access_key, s_generate_aes_key_source)); @@ -651,8 +657,8 @@ namespace ams::spl::impl { return GenerateAesKey(out_key, access_key, key_source); } - Result CryptAesCtr(void *dst, size_t dst_size, s32 keyslot, const void *owner, const void *src, size_t src_size, const IvCtr &iv_ctr) { - R_TRY(ValidateAesKeyslot(keyslot, owner)); + Result ComputeCtr(void *dst, size_t dst_size, s32 keyslot, const void *owner, const void *src, size_t src_size, const IvCtr &iv_ctr) { + R_TRY(ValidateAesKeySlot(keyslot, owner)); /* Succeed immediately if there's nothing to crypt. */ if (src_size == 0) { @@ -670,14 +676,14 @@ namespace ams::spl::impl { const uintptr_t dst_addr_page_aligned = util::AlignDown(dst_addr, os::MemoryPageSize); const size_t src_size_page_aligned = util::AlignUp(src_addr + src_size, os::MemoryPageSize) - src_addr_page_aligned; const size_t dst_size_page_aligned = util::AlignUp(dst_addr + dst_size, os::MemoryPageSize) - dst_addr_page_aligned; - const u32 src_se_map_addr = CryptAesInMapBase + (src_addr_page_aligned % DeviceAddressSpaceAlign); - const u32 dst_se_map_addr = CryptAesOutMapBase + (dst_addr_page_aligned % DeviceAddressSpaceAlign); - const u32 src_se_addr = CryptAesInMapBase + (src_addr % DeviceAddressSpaceAlign); - const u32 dst_se_addr = CryptAesOutMapBase + (dst_addr % DeviceAddressSpaceAlign); + const u32 src_se_map_addr = ComputeAesInMapBase + (src_addr_page_aligned % DeviceAddressSpaceAlign); + const u32 dst_se_map_addr = ComputeAesOutMapBase + (dst_addr_page_aligned % DeviceAddressSpaceAlign); + const u32 src_se_addr = ComputeAesInMapBase + (src_addr % DeviceAddressSpaceAlign); + const u32 dst_se_addr = ComputeAesOutMapBase + (dst_addr % DeviceAddressSpaceAlign); /* Validate aligned sizes. */ - R_UNLESS(src_size_page_aligned <= CryptAesSizeMax, spl::ResultInvalidSize()); - R_UNLESS(dst_size_page_aligned <= CryptAesSizeMax, spl::ResultInvalidSize()); + R_UNLESS(src_size_page_aligned <= ComputeAesSizeMax, spl::ResultInvalidSize()); + R_UNLESS(dst_size_page_aligned <= ComputeAesSizeMax, spl::ResultInvalidSize()); /* Helpers for mapping/unmapping. */ DeviceAddressSpaceMapHelper in_mapper(g_se_das_hnd, src_se_map_addr, src_addr_page_aligned, src_size_page_aligned, 1); @@ -698,11 +704,11 @@ namespace ams::spl::impl { { std::scoped_lock lk(g_async_op_lock); smc::AsyncOperationKey op_key; - const u32 mode = smc::GetCryptAesMode(smc::CipherMode::Ctr, GetPhysicalKeySlot(keyslot, true)); + const u32 mode = smc::GetComputeAesMode(smc::CipherMode::Ctr, GetPhysicalKeySlot(keyslot, true)); const u32 dst_ll_addr = g_se_mapped_work_buffer_addr + offsetof(SeCryptContext, out); const u32 src_ll_addr = g_se_mapped_work_buffer_addr + offsetof(SeCryptContext, in); - smc::Result res = smc::CryptAes(&op_key, mode, iv_ctr, dst_ll_addr, src_ll_addr, src_size); + smc::Result res = smc::ComputeAes(&op_key, mode, iv_ctr, dst_ll_addr, src_ll_addr, src_size); if (res != smc::Result::Success) { return smc::ConvertResult(res); } @@ -717,7 +723,7 @@ namespace ams::spl::impl { } Result ComputeCmac(Cmac *out_cmac, s32 keyslot, const void *owner, const void *data, size_t size) { - R_TRY(ValidateAesKeyslot(keyslot, owner)); + R_TRY(ValidateAesKeySlot(keyslot, owner)); R_UNLESS(size <= WorkBufferSizeMax, spl::ResultInvalidSize()); @@ -725,9 +731,9 @@ namespace ams::spl::impl { return smc::ConvertResult(smc::ComputeCmac(out_cmac, GetPhysicalKeySlot(keyslot, true), g_work_buffer, size)); } - Result AllocateAesKeyslot(s32 *out_keyslot, const void *owner) { + Result AllocateAesKeySlot(s32 *out_keyslot, const void *owner) { /* Find a virtual keyslot. */ - for (s32 i = 0; i < MaxVirtualAesKeyslots; i++) { + for (s32 i = 0; i < MaxVirtualAesKeySlots; i++) { if (g_keyslot_owners[i] == nullptr) { g_keyslot_owners[i] = owner; g_keyslot_contents[i] = { .type = KeySlotContentType::None }; @@ -737,20 +743,20 @@ namespace ams::spl::impl { } os::ClearSystemEvent(std::addressof(g_se_keyslot_available_event)); - return spl::ResultOutOfKeyslots(); + return spl::ResultOutOfKeySlots(); } - Result FreeAesKeyslot(s32 keyslot, const void *owner) { + Result DeallocateAesKeySlot(s32 keyslot, const void *owner) { /* Only virtual keyslots can be freed. */ - R_UNLESS(IsVirtualKeySlot(keyslot), spl::ResultInvalidKeyslot()); + R_UNLESS(IsVirtualKeySlot(keyslot), spl::ResultInvalidKeySlot()); /* Ensure the keyslot is owned. */ - R_TRY(ValidateAesKeyslot(keyslot, owner)); + R_TRY(ValidateAesKeySlot(keyslot, owner)); /* Clear the physical keyslot, if we're cached. */ s32 phys_slot; if (g_keyslot_cache.Release(std::addressof(phys_slot), keyslot)) { - ClearPhysicalKeyslot(phys_slot); + ClearPhysicalKeySlot(phys_slot); } /* Clear the virtual keyslot. */ @@ -763,15 +769,15 @@ namespace ams::spl::impl { } /* RSA. */ - Result DecryptRsaPrivateKey(void *dst, size_t dst_size, const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option) { - struct DecryptRsaPrivateKeyLayout { - u8 data[RsaPrivateKeySize + RsaPrivateKeyMetaSize]; + Result DecryptDeviceUniqueData(void *dst, size_t dst_size, const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option) { + struct DecryptDeviceUniqueDataLayout { + u8 data[RsaPrivateKeySize + DeviceUniqueDataMetaSize]; }; - DecryptRsaPrivateKeyLayout *layout = reinterpret_cast(g_work_buffer); + DecryptDeviceUniqueDataLayout *layout = reinterpret_cast(g_work_buffer); /* Validate size. */ - R_UNLESS(src_size >= RsaPrivateKeyMetaSize, spl::ResultInvalidSize()); - R_UNLESS(src_size <= sizeof(DecryptRsaPrivateKeyLayout), spl::ResultInvalidSize()); + R_UNLESS(src_size >= DeviceUniqueDataMetaSize, spl::ResultInvalidSize()); + R_UNLESS(src_size <= sizeof(DecryptDeviceUniqueDataLayout), spl::ResultInvalidSize()); std::memcpy(layout->data, src, src_size); armDCacheFlush(layout, sizeof(*layout)); @@ -779,10 +785,10 @@ namespace ams::spl::impl { smc::Result smc_res; size_t copy_size = 0; if (hos::GetVersion() >= hos::Version_5_0_0) { - copy_size = std::min(dst_size, src_size - RsaPrivateKeyMetaSize); - smc_res = smc::DecryptOrImportRsaPrivateKey(layout->data, src_size, access_key, key_source, static_cast(option)); + copy_size = std::min(dst_size, src_size - DeviceUniqueDataMetaSize); + smc_res = smc::DecryptDeviceUniqueData(layout->data, src_size, access_key, key_source, static_cast(option)); } else { - smc_res = smc::DecryptRsaPrivateKey(©_size, layout->data, src_size, access_key, key_source, option); + smc_res = smc::DecryptDeviceUniqueData(©_size, layout->data, src_size, access_key, key_source, option); copy_size = std::min(dst_size, copy_size); } @@ -795,71 +801,66 @@ namespace ams::spl::impl { } /* SSL */ - Result ImportSslKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source) { - return ImportSecureExpModKey(src, src_size, access_key, key_source, static_cast(smc::DecryptOrImportMode::ImportSslKey)); + Result DecryptAndStoreSslClientCertKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source) { + return DecryptAndStoreDeviceUniqueKey(src, src_size, access_key, key_source, static_cast(smc::DeviceUniqueDataMode::DecryptAndStoreSslKey)); } - Result SslExpMod(void *out, size_t out_size, const void *base, size_t base_size, const void *mod, size_t mod_size) { - return SecureExpMod(out, out_size, base, base_size, mod, mod_size, smc::SecureExpModMode::Ssl); + Result ModularExponentiateWithSslClientCertKey(void *out, size_t out_size, const void *base, size_t base_size, const void *mod, size_t mod_size) { + return ModularExponentiateWithStorageKey(out, out_size, base, base_size, mod, mod_size, smc::ModularExponentiateWithStorageKeyMode::Ssl); } /* ES */ - Result ImportEsKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option) { + Result LoadEsDeviceKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option) { if (hos::GetVersion() >= hos::Version_5_0_0) { - return ImportSecureExpModKey(src, src_size, access_key, key_source, option); + return DecryptAndStoreDeviceUniqueKey(src, src_size, access_key, key_source, option); } else { - struct ImportEsKeyLayout { - u8 data[RsaPrivateKeyMetaSize + 2 * RsaPrivateKeySize + 0x10]; + struct LoadEsDeviceKeyLayout { + u8 data[DeviceUniqueDataMetaSize + 2 * RsaPrivateKeySize + 0x10]; }; - ImportEsKeyLayout *layout = reinterpret_cast(g_work_buffer); + LoadEsDeviceKeyLayout *layout = reinterpret_cast(g_work_buffer); /* Validate size. */ - R_UNLESS(src_size <= sizeof(ImportEsKeyLayout), spl::ResultInvalidSize()); + R_UNLESS(src_size <= sizeof(LoadEsDeviceKeyLayout), spl::ResultInvalidSize()); std::memcpy(layout, src, src_size); armDCacheFlush(layout, sizeof(*layout)); - return smc::ConvertResult(smc::ImportEsKey(layout->data, src_size, access_key, key_source, option)); + return smc::ConvertResult(smc::LoadEsDeviceKey(layout->data, src_size, access_key, key_source, option)); } } - Result UnwrapTitleKey(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation) { - return UnwrapEsRsaOaepWrappedKey(out_access_key, base, base_size, mod, mod_size, label_digest, label_digest_size, generation, smc::EsKeyType::TitleKey); + Result PrepareEsTitleKey(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation) { + return PrepareEsDeviceUniqueKey(out_access_key, base, base_size, mod, mod_size, label_digest, label_digest_size, generation, smc::EsCommonKeyType::TitleKey); } - Result UnwrapCommonTitleKey(AccessKey *out_access_key, const KeySource &key_source, u32 generation) { - return smc::ConvertResult(smc::UnwrapCommonTitleKey(out_access_key, key_source, generation)); + Result PrepareCommonEsTitleKey(AccessKey *out_access_key, const KeySource &key_source, u32 generation) { + return smc::ConvertResult(smc::PrepareCommonEsTitleKey(out_access_key, key_source, generation)); } - Result ImportDrmKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source) { - return ImportSecureExpModKey(src, src_size, access_key, key_source, static_cast(smc::DecryptOrImportMode::ImportDrmKey)); + Result DecryptAndStoreDrmDeviceCertKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source) { + return DecryptAndStoreDeviceUniqueKey(src, src_size, access_key, key_source, static_cast(smc::DeviceUniqueDataMode::DecryptAndStoreDrmDeviceCertKey)); } - Result DrmExpMod(void *out, size_t out_size, const void *base, size_t base_size, const void *mod, size_t mod_size) { - return SecureExpMod(out, out_size, base, base_size, mod, mod_size, smc::SecureExpModMode::Drm); + Result ModularExponentiateWithDrmDeviceCertKey(void *out, size_t out_size, const void *base, size_t base_size, const void *mod, size_t mod_size) { + return ModularExponentiateWithStorageKey(out, out_size, base, base_size, mod, mod_size, smc::ModularExponentiateWithStorageKeyMode::DrmDeviceCert); } - Result UnwrapElicenseKey(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation) { - return UnwrapEsRsaOaepWrappedKey(out_access_key, base, base_size, mod, mod_size, label_digest, label_digest_size, generation, smc::EsKeyType::ElicenseKey); - } - - Result LoadElicenseKey(s32 keyslot, const void *owner, const AccessKey &access_key) { - /* Right now, this is just literally the same function as LoadTitleKey in N's impl. */ - return LoadTitleKey(keyslot, owner, access_key); + Result PrepareEsArchiveKey(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation) { + return PrepareEsDeviceUniqueKey(out_access_key, base, base_size, mod, mod_size, label_digest, label_digest_size, generation, smc::EsCommonKeyType::ArchiveKey); } /* FS */ - Result ImportLotusKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option) { - return ImportSecureExpModKey(src, src_size, access_key, key_source, option); + Result DecryptAndStoreGcKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option) { + return DecryptAndStoreDeviceUniqueKey(src, src_size, access_key, key_source, option); } - Result DecryptLotusMessage(u32 *out_size, void *dst, size_t dst_size, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size) { + Result DecryptGcMessage(u32 *out_size, void *dst, size_t dst_size, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size) { /* Validate sizes. */ R_UNLESS(dst_size <= WorkBufferSizeMax, spl::ResultInvalidSize()); R_UNLESS(label_digest_size == LabelDigestSizeMax, spl::ResultInvalidSize()); /* Nintendo doesn't check this result code, but we will. */ - R_TRY(SecureExpMod(g_work_buffer, 0x100, base, base_size, mod, mod_size, smc::SecureExpModMode::Lotus)); + R_TRY(ModularExponentiateWithStorageKey(g_work_buffer, 0x100, base, base_size, mod, mod_size, smc::ModularExponentiateWithStorageKeyMode::Gc)); size_t data_size = crypto::DecodeRsa2048OaepSha256(dst, dst_size, label_digest, label_digest_size, g_work_buffer, 0x100); R_UNLESS(data_size > 0, spl::ResultDecryptionFailed()); @@ -872,9 +873,9 @@ namespace ams::spl::impl { return smc::ConvertResult(smc::GenerateSpecificAesKey(out_key, key_source, generation, which)); } - Result LoadTitleKey(s32 keyslot, const void *owner, const AccessKey &access_key) { - R_TRY(ValidateAesKeyslot(keyslot, owner)); - return LoadVirtualTitleKey(keyslot, access_key); + Result LoadPreparedAesKey(s32 keyslot, const void *owner, const AccessKey &access_key) { + R_TRY(ValidateAesKeySlot(keyslot, owner)); + return LoadVirtualPreparedAesKey(keyslot, access_key); } Result GetPackage2Hash(void *dst, const size_t size) { @@ -882,7 +883,7 @@ namespace ams::spl::impl { R_UNLESS(size >= sizeof(hash), spl::ResultInvalidSize()); smc::Result smc_res; - if ((smc_res = smc::GetConfig(hash, 4, SplConfigItem_Package2Hash)) != smc::Result::Success) { + if ((smc_res = smc::GetConfig(hash, 4, ConfigItem::Package2Hash)) != smc::Result::Success) { return smc::ConvertResult(smc_res); } @@ -891,19 +892,19 @@ namespace ams::spl::impl { } /* Manu. */ - Result ReEncryptRsaPrivateKey(void *dst, size_t dst_size, const void *src, size_t src_size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option) { - struct ReEncryptRsaPrivateKeyLayout { - u8 data[RsaPrivateKeyMetaSize + 2 * RsaPrivateKeySize + 0x10]; + Result ReencryptDeviceUniqueData(void *dst, size_t dst_size, const void *src, size_t src_size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option) { + struct ReencryptDeviceUniqueDataLayout { + u8 data[DeviceUniqueDataMetaSize + 2 * RsaPrivateKeySize + 0x10]; AccessKey access_key_dec; KeySource source_dec; AccessKey access_key_enc; KeySource source_enc; }; - ReEncryptRsaPrivateKeyLayout *layout = reinterpret_cast(g_work_buffer); + ReencryptDeviceUniqueDataLayout *layout = reinterpret_cast(g_work_buffer); /* Validate size. */ - R_UNLESS(src_size >= RsaPrivateKeyMetaSize, spl::ResultInvalidSize()); - R_UNLESS(src_size <= sizeof(ReEncryptRsaPrivateKeyLayout), spl::ResultInvalidSize()); + R_UNLESS(src_size >= DeviceUniqueDataMetaSize, spl::ResultInvalidSize()); + R_UNLESS(src_size <= sizeof(ReencryptDeviceUniqueDataLayout), spl::ResultInvalidSize()); std::memcpy(layout, src, src_size); layout->access_key_dec = access_key_dec; @@ -913,7 +914,7 @@ namespace ams::spl::impl { armDCacheFlush(layout, sizeof(*layout)); - smc::Result smc_res = smc::ReEncryptRsaPrivateKey(layout->data, src_size, layout->access_key_dec, layout->source_dec, layout->access_key_enc, layout->source_enc, option); + smc::Result smc_res = smc::ReencryptDeviceUniqueData(layout->data, src_size, layout->access_key_dec, layout->source_dec, layout->access_key_enc, layout->source_enc, option); if (smc_res == smc::Result::Success) { size_t copy_size = std::min(dst_size, src_size); armDCacheFlush(layout, copy_size); @@ -924,16 +925,16 @@ namespace ams::spl::impl { } /* Helper. */ - Result FreeAesKeyslots(const void *owner) { + Result DeallocateAllAesKeySlots(const void *owner) { for (s32 slot = VirtualKeySlotMin; slot <= VirtualKeySlotMax; ++slot) { if (g_keyslot_owners[GetVirtualKeySlotIndex(slot)] == owner) { - FreeAesKeyslot(slot, owner); + DeallocateAesKeySlot(slot, owner); } } return ResultSuccess(); } - Handle GetAesKeyslotAvailableEventHandle() { + Handle GetAesKeySlotAvailableEventHandle() { return os::GetReadableHandleOfSystemEvent(std::addressof(g_se_keyslot_available_event)); } diff --git a/stratosphere/spl/source/spl_api_impl.hpp b/stratosphere/spl/source/spl_api_impl.hpp index 483f29e53..f41129035 100644 --- a/stratosphere/spl/source/spl_api_impl.hpp +++ b/stratosphere/spl/source/spl_api_impl.hpp @@ -22,9 +22,9 @@ namespace ams::spl::impl { void Initialize(); /* General. */ - Result GetConfig(u64 *out, SplConfigItem which); - Result ExpMod(void *out, size_t out_size, const void *base, size_t base_size, const void *exp, size_t exp_size, const void *mod, size_t mod_size); - Result SetConfig(SplConfigItem which, u64 value); + Result GetConfig(u64 *out, spl::ConfigItem which); + Result ModularExponentiate(void *out, size_t out_size, const void *base, size_t base_size, const void *exp, size_t exp_size, const void *mod, size_t mod_size); + Result SetConfig(spl::ConfigItem which, u64 value); Result GenerateRandomBytes(void *out, size_t size); Result IsDevelopment(bool *out); Result SetBootReason(BootReasonValue boot_reason); @@ -35,39 +35,39 @@ namespace ams::spl::impl { Result LoadAesKey(s32 keyslot, const void *owner, const AccessKey &access_key, const KeySource &key_source); Result GenerateAesKey(AesKey *out_key, const AccessKey &access_key, const KeySource &key_source); Result DecryptAesKey(AesKey *out_key, const KeySource &key_source, u32 generation, u32 option); - Result CryptAesCtr(void *dst, size_t dst_size, s32 keyslot, const void *owner, const void *src, size_t src_size, const IvCtr &iv_ctr); + Result ComputeCtr(void *dst, size_t dst_size, s32 keyslot, const void *owner, const void *src, size_t src_size, const IvCtr &iv_ctr); Result ComputeCmac(Cmac *out_cmac, s32 keyslot, const void *owner, const void *data, size_t size); - Result AllocateAesKeyslot(s32 *out_keyslot, const void *owner); - Result FreeAesKeyslot(s32 keyslot, const void *owner); + Result AllocateAesKeySlot(s32 *out_keyslot, const void *owner); + Result DeallocateAesKeySlot(s32 keyslot, const void *owner); /* RSA. */ - Result DecryptRsaPrivateKey(void *dst, size_t dst_size, const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option); + Result DecryptDeviceUniqueData(void *dst, size_t dst_size, const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option); /* SSL */ - Result ImportSslKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source); - Result SslExpMod(void *out, size_t out_size, const void *base, size_t base_size, const void *mod, size_t mod_size); + Result DecryptAndStoreSslClientCertKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source); + Result ModularExponentiateWithSslClientCertKey(void *out, size_t out_size, const void *base, size_t base_size, const void *mod, size_t mod_size); /* ES */ - Result ImportEsKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option); - Result UnwrapTitleKey(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation); - Result UnwrapCommonTitleKey(AccessKey *out_access_key, const KeySource &key_source, u32 generation); - Result ImportDrmKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source); - Result DrmExpMod(void *out, size_t out_size, const void *base, size_t base_size, const void *mod, size_t mod_size); - Result UnwrapElicenseKey(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation); - Result LoadElicenseKey(s32 keyslot, const void *owner, const AccessKey &access_key); + Result LoadEsDeviceKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option); + Result PrepareEsTitleKey(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation); + Result PrepareCommonEsTitleKey(AccessKey *out_access_key, const KeySource &key_source, u32 generation); + Result DecryptAndStoreDrmDeviceCertKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source); + Result ModularExponentiateWithDrmDeviceCertKey(void *out, size_t out_size, const void *base, size_t base_size, const void *mod, size_t mod_size); + Result PrepareEsArchiveKey(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation); + Result LoadPreparedAesKey(s32 keyslot, const void *owner, const AccessKey &access_key); /* FS */ - Result ImportLotusKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option); - Result DecryptLotusMessage(u32 *out_size, void *dst, size_t dst_size, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size); + Result DecryptAndStoreGcKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option); + Result DecryptGcMessage(u32 *out_size, void *dst, size_t dst_size, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size); Result GenerateSpecificAesKey(AesKey *out_key, const KeySource &key_source, u32 generation, u32 which); - Result LoadTitleKey(s32 keyslot, const void *owner, const AccessKey &access_key); + Result LoadPreparedAesKey(s32 keyslot, const void *owner, const AccessKey &access_key); Result GetPackage2Hash(void *dst, const size_t size); /* Manu. */ - Result ReEncryptRsaPrivateKey(void *dst, size_t dst_size, const void *src, size_t src_size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option); + Result ReencryptDeviceUniqueData(void *dst, size_t dst_size, const void *src, size_t src_size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option); /* Helper. */ - Result FreeAesKeyslots(const void *owner); - Handle GetAesKeyslotAvailableEventHandle(); + Result DeallocateAllAesKeySlots(const void *owner); + Handle GetAesKeySlotAvailableEventHandle(); } diff --git a/stratosphere/spl/source/spl_crypto_service.cpp b/stratosphere/spl/source/spl_crypto_service.cpp index 63b150a43..b559e6e87 100644 --- a/stratosphere/spl/source/spl_crypto_service.cpp +++ b/stratosphere/spl/source/spl_crypto_service.cpp @@ -21,7 +21,7 @@ namespace ams::spl { CryptoService::~CryptoService() { /* Free any keyslots this service is using. */ - impl::FreeAesKeyslots(this); + impl::DeallocateAllAesKeySlots(this); } Result CryptoService::GenerateAesKek(sf::Out out_access_key, KeySource key_source, u32 generation, u32 option) { @@ -40,24 +40,25 @@ namespace ams::spl { return impl::DecryptAesKey(out_key.GetPointer(), key_source, generation, option); } - Result CryptoService::CryptAesCtr(const sf::OutNonSecureBuffer &out_buf, s32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr) { - return impl::CryptAesCtr(out_buf.GetPointer(), out_buf.GetSize(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize(), iv_ctr); + Result CryptoService::ComputeCtr(const sf::OutNonSecureBuffer &out_buf, s32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr) { + return impl::ComputeCtr(out_buf.GetPointer(), out_buf.GetSize(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize(), iv_ctr); } Result CryptoService::ComputeCmac(sf::Out out_cmac, s32 keyslot, const sf::InPointerBuffer &in_buf) { return impl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize()); } - Result CryptoService::AllocateAesKeyslot(sf::Out out_keyslot) { - return impl::AllocateAesKeyslot(out_keyslot.GetPointer(), this); + Result CryptoService::AllocateAesKeySlot(sf::Out out_keyslot) { + return impl::AllocateAesKeySlot(out_keyslot.GetPointer(), this); } - Result CryptoService::FreeAesKeyslot(s32 keyslot) { - return impl::FreeAesKeyslot(keyslot, this); + Result CryptoService::DeallocateAesKeySlot(s32 keyslot) { + return impl::DeallocateAesKeySlot(keyslot, this); } - void CryptoService::GetAesKeyslotAvailableEvent(sf::OutCopyHandle out_hnd) { - out_hnd.SetValue(impl::GetAesKeyslotAvailableEventHandle()); + Result CryptoService::GetAesKeySlotAvailableEvent(sf::OutCopyHandle out_hnd) { + out_hnd.SetValue(impl::GetAesKeySlotAvailableEventHandle()); + return ResultSuccess(); } } diff --git a/stratosphere/spl/source/spl_crypto_service.hpp b/stratosphere/spl/source/spl_crypto_service.hpp index 8eec93dd8..a6facc9cc 100644 --- a/stratosphere/spl/source/spl_crypto_service.hpp +++ b/stratosphere/spl/source/spl_crypto_service.hpp @@ -20,38 +20,19 @@ namespace ams::spl { class CryptoService : public GeneralService { public: - CryptoService() : GeneralService() { /* ... */ } virtual ~CryptoService(); - protected: - /* Actual commands. */ - virtual Result GenerateAesKek(sf::Out out_access_key, KeySource key_source, u32 generation, u32 option); - virtual Result LoadAesKey(s32 keyslot, AccessKey access_key, KeySource key_source); - virtual Result GenerateAesKey(sf::Out out_key, AccessKey access_key, KeySource key_source); - virtual Result DecryptAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 option); - virtual Result CryptAesCtr(const sf::OutNonSecureBuffer &out_buf, s32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr); - virtual Result ComputeCmac(sf::Out out_cmac, s32 keyslot, const sf::InPointerBuffer &in_buf); - virtual Result AllocateAesKeyslot(sf::Out out_keyslot); - virtual Result FreeAesKeyslot(s32 keyslot); - virtual void GetAesKeyslotAvailableEvent(sf::OutCopyHandle out_hnd); public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetConfig), - MAKE_SERVICE_COMMAND_META(ExpMod), - MAKE_SERVICE_COMMAND_META(SetConfig), - MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(IsDevelopment), - MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GenerateAesKek), - MAKE_SERVICE_COMMAND_META(LoadAesKey), - MAKE_SERVICE_COMMAND_META(GenerateAesKey), - MAKE_SERVICE_COMMAND_META(DecryptAesKey), - MAKE_SERVICE_COMMAND_META(CryptAesCtr), - MAKE_SERVICE_COMMAND_META(ComputeCmac), - MAKE_SERVICE_COMMAND_META(AllocateAesKeyslot /* Atmosphere extension: This was added in hos::Version_2_0_0, but is allowed on older firmware by atmosphere. */), - MAKE_SERVICE_COMMAND_META(FreeAesKeyslot /* Atmosphere extension: This was added in hos::Version_2_0_0, but is allowed on older firmware by atmosphere. */), - MAKE_SERVICE_COMMAND_META(GetAesKeyslotAvailableEvent /* Atmosphere extension: This was added in hos::Version_2_0_0, but is allowed on older firmware by atmosphere. */), - }; + /* Actual commands. */ + Result GenerateAesKek(sf::Out out_access_key, KeySource key_source, u32 generation, u32 option); + Result LoadAesKey(s32 keyslot, AccessKey access_key, KeySource key_source); + Result GenerateAesKey(sf::Out out_key, AccessKey access_key, KeySource key_source); + Result DecryptAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 option); + Result ComputeCtr(const sf::OutNonSecureBuffer &out_buf, s32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr); + Result ComputeCmac(sf::Out out_cmac, s32 keyslot, const sf::InPointerBuffer &in_buf); + Result AllocateAesKeySlot(sf::Out out_keyslot); + Result DeallocateAesKeySlot(s32 keyslot); + Result GetAesKeySlotAvailableEvent(sf::OutCopyHandle out_hnd); }; + static_assert(spl::impl::IsICryptoInterface); } diff --git a/stratosphere/spl/source/spl_deprecated_service.cpp b/stratosphere/spl/source/spl_deprecated_service.cpp index f6c4ec8c8..358a557a8 100644 --- a/stratosphere/spl/source/spl_deprecated_service.cpp +++ b/stratosphere/spl/source/spl_deprecated_service.cpp @@ -19,12 +19,17 @@ namespace ams::spl { - Result DeprecatedService::GetConfig(sf::Out out, u32 which) { - return impl::GetConfig(out.GetPointer(), static_cast(which)); + DeprecatedService::~DeprecatedService() { + /* Free any keyslots this service is using. */ + impl::DeallocateAllAesKeySlots(this); } - Result DeprecatedService::ExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod) { - return impl::ExpMod(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), exp.GetPointer(), exp.GetSize(), mod.GetPointer(), mod.GetSize()); + Result DeprecatedService::GetConfig(sf::Out out, u32 which) { + return impl::GetConfig(out.GetPointer(), static_cast(which)); + } + + Result DeprecatedService::ModularExponentiate(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod) { + return impl::ModularExponentiate(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), exp.GetPointer(), exp.GetSize(), mod.GetPointer(), mod.GetSize()); } Result DeprecatedService::GenerateAesKek(sf::Out out_access_key, KeySource key_source, u32 generation, u32 option) { @@ -40,19 +45,19 @@ namespace ams::spl { } Result DeprecatedService::SetConfig(u32 which, u64 value) { - return impl::SetConfig(static_cast(which), value); + return impl::SetConfig(static_cast(which), value); } Result DeprecatedService::GenerateRandomBytes(const sf::OutPointerBuffer &out) { return impl::GenerateRandomBytes(out.GetPointer(), out.GetSize()); } - Result DeprecatedService::ImportLotusKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { - return impl::ImportLotusKey(src.GetPointer(), src.GetSize(), access_key, key_source, option); + Result DeprecatedService::DecryptAndStoreGcKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { + return impl::DecryptAndStoreGcKey(src.GetPointer(), src.GetSize(), access_key, key_source, option); } - Result DeprecatedService::DecryptLotusMessage(sf::Out out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest) { - return impl::DecryptLotusMessage(out_size.GetPointer(), out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize()); + Result DeprecatedService::DecryptGcMessage(sf::Out out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest) { + return impl::DecryptGcMessage(out_size.GetPointer(), out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize()); } Result DeprecatedService::IsDevelopment(sf::Out is_dev) { @@ -63,60 +68,61 @@ namespace ams::spl { return impl::GenerateSpecificAesKey(out_key.GetPointer(), key_source, generation, which); } - Result DeprecatedService::DecryptRsaPrivateKey(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { - return impl::DecryptRsaPrivateKey(dst.GetPointer(), dst.GetSize(), src.GetPointer(), src.GetSize(), access_key, key_source, option); + Result DeprecatedService::DecryptDeviceUniqueData(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { + return impl::DecryptDeviceUniqueData(dst.GetPointer(), dst.GetSize(), src.GetPointer(), src.GetSize(), access_key, key_source, option); } Result DeprecatedService::DecryptAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 option) { return impl::DecryptAesKey(out_key.GetPointer(), key_source, generation, option); } - Result DeprecatedService::CryptAesCtrDeprecated(const sf::OutBuffer &out_buf, s32 keyslot, const sf::InBuffer &in_buf, IvCtr iv_ctr) { - return impl::CryptAesCtr(out_buf.GetPointer(), out_buf.GetSize(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize(), iv_ctr); + Result DeprecatedService::ComputeCtrDeprecated(const sf::OutBuffer &out_buf, s32 keyslot, const sf::InBuffer &in_buf, IvCtr iv_ctr) { + return impl::ComputeCtr(out_buf.GetPointer(), out_buf.GetSize(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize(), iv_ctr); } - Result DeprecatedService::CryptAesCtr(const sf::OutNonSecureBuffer &out_buf, s32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr) { - return impl::CryptAesCtr(out_buf.GetPointer(), out_buf.GetSize(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize(), iv_ctr); + Result DeprecatedService::ComputeCtr(const sf::OutNonSecureBuffer &out_buf, s32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr) { + return impl::ComputeCtr(out_buf.GetPointer(), out_buf.GetSize(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize(), iv_ctr); } Result DeprecatedService::ComputeCmac(sf::Out out_cmac, s32 keyslot, const sf::InPointerBuffer &in_buf) { return impl::ComputeCmac(out_cmac.GetPointer(), keyslot, this, in_buf.GetPointer(), in_buf.GetSize()); } - Result DeprecatedService::ImportEsKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { - return impl::ImportEsKey(src.GetPointer(), src.GetSize(), access_key, key_source, option); + Result DeprecatedService::LoadEsDeviceKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { + return impl::LoadEsDeviceKey(src.GetPointer(), src.GetSize(), access_key, key_source, option); } - Result DeprecatedService::UnwrapTitleKeyDeprecated(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest) { - return impl::UnwrapTitleKey(out_access_key.GetPointer(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize(), 0); + Result DeprecatedService::PrepareEsTitleKeyDeprecated(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest) { + return impl::PrepareEsTitleKey(out_access_key.GetPointer(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize(), 0); } - Result DeprecatedService::UnwrapTitleKey(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation) { - return impl::UnwrapTitleKey(out_access_key.GetPointer(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize(), generation); + Result DeprecatedService::PrepareEsTitleKey(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation) { + return impl::PrepareEsTitleKey(out_access_key.GetPointer(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize(), generation); } - Result DeprecatedService::LoadTitleKey(s32 keyslot, AccessKey access_key) { - return impl::LoadTitleKey(keyslot, this, access_key); + Result DeprecatedService::LoadPreparedAesKey(s32 keyslot, AccessKey access_key) { + return impl::LoadPreparedAesKey(keyslot, this, access_key); } - Result DeprecatedService::UnwrapCommonTitleKeyDeprecated(sf::Out out_access_key, KeySource key_source) { - return impl::UnwrapCommonTitleKey(out_access_key.GetPointer(), key_source, 0); + Result DeprecatedService::PrepareCommonEsTitleKeyDeprecated(sf::Out out_access_key, KeySource key_source) { + return impl::PrepareCommonEsTitleKey(out_access_key.GetPointer(), key_source, 0); } - Result DeprecatedService::UnwrapCommonTitleKey(sf::Out out_access_key, KeySource key_source, u32 generation) { - return impl::UnwrapCommonTitleKey(out_access_key.GetPointer(), key_source, generation); + Result DeprecatedService::PrepareCommonEsTitleKey(sf::Out out_access_key, KeySource key_source, u32 generation) { + return impl::PrepareCommonEsTitleKey(out_access_key.GetPointer(), key_source, generation); } - Result DeprecatedService::AllocateAesKeyslot(sf::Out out_keyslot) { - return impl::AllocateAesKeyslot(out_keyslot.GetPointer(), this); + Result DeprecatedService::AllocateAesKeySlot(sf::Out out_keyslot) { + return impl::AllocateAesKeySlot(out_keyslot.GetPointer(), this); } - Result DeprecatedService::FreeAesKeyslot(s32 keyslot) { - return impl::FreeAesKeyslot(keyslot, this); + Result DeprecatedService::DeallocateAesKeySlot(s32 keyslot) { + return impl::DeallocateAesKeySlot(keyslot, this); } - void DeprecatedService::GetAesKeyslotAvailableEvent(sf::OutCopyHandle out_hnd) { - out_hnd.SetValue(impl::GetAesKeyslotAvailableEventHandle()); + Result DeprecatedService::GetAesKeySlotAvailableEvent(sf::OutCopyHandle out_hnd) { + out_hnd.SetValue(impl::GetAesKeySlotAvailableEventHandle()); + return ResultSuccess(); } Result DeprecatedService::SetBootReason(BootReasonValue boot_reason) { diff --git a/stratosphere/spl/source/spl_deprecated_service.hpp b/stratosphere/spl/source/spl_deprecated_service.hpp index 11d49a7d9..b7c03291b 100644 --- a/stratosphere/spl/source/spl_deprecated_service.hpp +++ b/stratosphere/spl/source/spl_deprecated_service.hpp @@ -18,112 +18,39 @@ namespace ams::spl { - class DeprecatedService : public sf::IServiceObject { - protected: - enum class CommandId { - /* 1.0.0+ */ - GetConfig = 0, - ExpMod = 1, - GenerateAesKek = 2, - LoadAesKey = 3, - GenerateAesKey = 4, - SetConfig = 5, - GenerateRandomBytes = 7, - ImportLotusKey = 9, - DecryptLotusMessage = 10, - IsDevelopment = 11, - GenerateSpecificAesKey = 12, - DecryptRsaPrivateKeyDeprecated = 13, - DecryptRsaPrivateKey = 13, - DecryptAesKey = 14, - CryptAesCtrDeprecated = 15, - CryptAesCtr = 15, - ComputeCmac = 16, - ImportEsKey = 17, - UnwrapTitleKeyDeprecated = 18, - UnwrapTitleKey = 18, - LoadTitleKey = 19, - - /* 2.0.0+ */ - UnwrapCommonTitleKeyDeprecated = 20, - UnwrapCommonTitleKey = 20, - AllocateAesKeyslot = 21, - FreeAesKeyslot = 22, - GetAesKeyslotAvailableEvent = 23, - - /* 3.0.0+ */ - SetBootReason = 24, - GetBootReason = 25, - }; + class DeprecatedService final { + public: + virtual ~DeprecatedService(); public: - DeprecatedService() { /* ... */ } - virtual ~DeprecatedService() { /* ... */ } - protected: /* Actual commands. */ - virtual Result GetConfig(sf::Out out, u32 which); - virtual Result ExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod); - virtual Result GenerateAesKek(sf::Out out_access_key, KeySource key_source, u32 generation, u32 option); - virtual Result LoadAesKey(s32 keyslot, AccessKey access_key, KeySource key_source); - virtual Result GenerateAesKey(sf::Out out_key, AccessKey access_key, KeySource key_source); - virtual Result SetConfig(u32 which, u64 value); - virtual Result GenerateRandomBytes(const sf::OutPointerBuffer &out); - virtual Result ImportLotusKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); - virtual Result DecryptLotusMessage(sf::Out out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest); - virtual Result IsDevelopment(sf::Out is_dev); - virtual Result GenerateSpecificAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 which); - virtual Result DecryptRsaPrivateKey(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); - virtual Result DecryptAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 option); - virtual Result CryptAesCtrDeprecated(const sf::OutBuffer &out_buf, s32 keyslot, const sf::InBuffer &in_buf, IvCtr iv_ctr); - virtual Result CryptAesCtr(const sf::OutNonSecureBuffer &out_buf, s32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr); - virtual Result ComputeCmac(sf::Out out_cmac, s32 keyslot, const sf::InPointerBuffer &in_buf); - virtual Result ImportEsKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); - virtual Result UnwrapTitleKeyDeprecated(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest); - virtual Result UnwrapTitleKey(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation); - virtual Result LoadTitleKey(s32 keyslot, AccessKey access_key); - virtual Result UnwrapCommonTitleKeyDeprecated(sf::Out out_access_key, KeySource key_source); - virtual Result UnwrapCommonTitleKey(sf::Out out_access_key, KeySource key_source, u32 generation); - virtual Result AllocateAesKeyslot(sf::Out out_keyslot); - virtual Result FreeAesKeyslot(s32 keyslot); - virtual void GetAesKeyslotAvailableEvent(sf::OutCopyHandle out_hnd); - virtual Result SetBootReason(BootReasonValue boot_reason); - virtual Result GetBootReason(sf::Out out); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetConfig), - MAKE_SERVICE_COMMAND_META(ExpMod), - MAKE_SERVICE_COMMAND_META(GenerateAesKek), - MAKE_SERVICE_COMMAND_META(LoadAesKey), - MAKE_SERVICE_COMMAND_META(GenerateAesKey), - MAKE_SERVICE_COMMAND_META(SetConfig), - MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(ImportLotusKey), - MAKE_SERVICE_COMMAND_META(DecryptLotusMessage), - MAKE_SERVICE_COMMAND_META(IsDevelopment), - MAKE_SERVICE_COMMAND_META(GenerateSpecificAesKey), - MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKey), - MAKE_SERVICE_COMMAND_META(DecryptAesKey), - - MAKE_SERVICE_COMMAND_META(CryptAesCtrDeprecated, hos::Version_1_0_0, hos::Version_1_0_0), - MAKE_SERVICE_COMMAND_META(CryptAesCtr, hos::Version_2_0_0), - - MAKE_SERVICE_COMMAND_META(ComputeCmac), - MAKE_SERVICE_COMMAND_META(ImportEsKey), - - MAKE_SERVICE_COMMAND_META(UnwrapTitleKeyDeprecated, hos::Version_1_0_0, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(UnwrapTitleKey, hos::Version_3_0_0), - - MAKE_SERVICE_COMMAND_META(LoadTitleKey), - - MAKE_SERVICE_COMMAND_META(UnwrapCommonTitleKeyDeprecated, hos::Version_2_0_0, hos::Version_2_3_0), - MAKE_SERVICE_COMMAND_META(UnwrapCommonTitleKey, hos::Version_3_0_0), - - MAKE_SERVICE_COMMAND_META(AllocateAesKeyslot /* Atmosphere extension: This was added in hos::Version_2_0_0, but is allowed on older firmware by atmosphere. */), - MAKE_SERVICE_COMMAND_META(FreeAesKeyslot /* Atmosphere extension: This was added in hos::Version_2_0_0, but is allowed on older firmware by atmosphere. */), - MAKE_SERVICE_COMMAND_META(GetAesKeyslotAvailableEvent /* Atmosphere extension: This was added in hos::Version_2_0_0, but is allowed on older firmware by atmosphere. */), - - MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_3_0_0), - }; + Result GetConfig(sf::Out out, u32 which); + Result ModularExponentiate(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod); + Result GenerateAesKek(sf::Out out_access_key, KeySource key_source, u32 generation, u32 option); + Result LoadAesKey(s32 keyslot, AccessKey access_key, KeySource key_source); + Result GenerateAesKey(sf::Out out_key, AccessKey access_key, KeySource key_source); + Result SetConfig(u32 which, u64 value); + Result GenerateRandomBytes(const sf::OutPointerBuffer &out); + Result DecryptAndStoreGcKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); + Result DecryptGcMessage(sf::Out out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest); + Result IsDevelopment(sf::Out is_dev); + Result GenerateSpecificAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 which); + Result DecryptDeviceUniqueData(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); + Result DecryptAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 option); + Result ComputeCtrDeprecated(const sf::OutBuffer &out_buf, s32 keyslot, const sf::InBuffer &in_buf, IvCtr iv_ctr); + Result ComputeCtr(const sf::OutNonSecureBuffer &out_buf, s32 keyslot, const sf::InNonSecureBuffer &in_buf, IvCtr iv_ctr); + Result ComputeCmac(sf::Out out_cmac, s32 keyslot, const sf::InPointerBuffer &in_buf); + Result LoadEsDeviceKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); + Result PrepareEsTitleKeyDeprecated(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest); + Result PrepareEsTitleKey(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation); + Result LoadPreparedAesKey(s32 keyslot, AccessKey access_key); + Result PrepareCommonEsTitleKeyDeprecated(sf::Out out_access_key, KeySource key_source); + Result PrepareCommonEsTitleKey(sf::Out out_access_key, KeySource key_source, u32 generation); + Result AllocateAesKeySlot(sf::Out out_keyslot); + Result DeallocateAesKeySlot(s32 keyslot); + Result GetAesKeySlotAvailableEvent(sf::OutCopyHandle out_hnd); + Result SetBootReason(BootReasonValue boot_reason); + Result GetBootReason(sf::Out out); }; + static_assert(spl::impl::IsIDeprecatedGeneralInterface); } diff --git a/stratosphere/spl/source/spl_device_unique_data_service.cpp b/stratosphere/spl/source/spl_device_unique_data_service.cpp new file mode 100644 index 000000000..4dd281fd6 --- /dev/null +++ b/stratosphere/spl/source/spl_device_unique_data_service.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include "spl_api_impl.hpp" +#include "spl_device_unique_data_service.hpp" + +namespace ams::spl { + + Result DeviceUniqueDataService::DecryptDeviceUniqueDataDeprecated(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { + return impl::DecryptDeviceUniqueData(dst.GetPointer(), dst.GetSize(), src.GetPointer(), src.GetSize(), access_key, key_source, option); + } + + Result DeviceUniqueDataService::DecryptDeviceUniqueData(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { + return impl::DecryptDeviceUniqueData(dst.GetPointer(), dst.GetSize(), src.GetPointer(), src.GetSize(), access_key, key_source, static_cast(smc::DeviceUniqueDataMode::DecryptDeviceUniqueData)); + } + +} diff --git a/stratosphere/spl/source/spl_rsa_service.hpp b/stratosphere/spl/source/spl_device_unique_data_service.hpp similarity index 60% rename from stratosphere/spl/source/spl_rsa_service.hpp rename to stratosphere/spl/source/spl_device_unique_data_service.hpp index e7c38b6fd..397a271f0 100644 --- a/stratosphere/spl/source/spl_rsa_service.hpp +++ b/stratosphere/spl/source/spl_device_unique_data_service.hpp @@ -18,14 +18,12 @@ namespace ams::spl { - class RsaService : public CryptoService { + class DeviceUniqueDataService : public CryptoService { public: - RsaService() : CryptoService() { /* ... */ } - virtual ~RsaService() { /* ... */ } - protected: /* Actual commands. */ - virtual Result DecryptRsaPrivateKeyDeprecated(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); - virtual Result DecryptRsaPrivateKey(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); + Result DecryptDeviceUniqueDataDeprecated(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); + Result DecryptDeviceUniqueData(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); }; + static_assert(spl::impl::IsIDeviceUniqueDataInterface); } diff --git a/stratosphere/spl/source/spl_es_service.cpp b/stratosphere/spl/source/spl_es_service.cpp index 9f1a9cffc..969212835 100644 --- a/stratosphere/spl/source/spl_es_service.cpp +++ b/stratosphere/spl/source/spl_es_service.cpp @@ -19,36 +19,36 @@ namespace ams::spl { - Result EsService::ImportEsKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { - return impl::ImportEsKey(src.GetPointer(), src.GetSize(), access_key, key_source, option); + Result EsService::LoadEsDeviceKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { + return impl::LoadEsDeviceKey(src.GetPointer(), src.GetSize(), access_key, key_source, option); } - Result EsService::ImportEsKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { - return impl::ImportEsKey(src.GetPointer(), src.GetSize(), access_key, key_source, static_cast(smc::DecryptOrImportMode::ImportEsKey)); + Result EsService::LoadEsDeviceKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { + return impl::LoadEsDeviceKey(src.GetPointer(), src.GetSize(), access_key, key_source, static_cast(smc::DeviceUniqueDataMode::DecryptAndStoreEsDeviceKey)); } - Result EsService::UnwrapTitleKey(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation) { - return impl::UnwrapTitleKey(out_access_key.GetPointer(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize(), generation); + Result EsService::PrepareEsTitleKey(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation) { + return impl::PrepareEsTitleKey(out_access_key.GetPointer(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize(), generation); } - Result EsService::UnwrapCommonTitleKey(sf::Out out_access_key, KeySource key_source, u32 generation) { - return impl::UnwrapCommonTitleKey(out_access_key.GetPointer(), key_source, generation); + Result EsService::PrepareCommonEsTitleKey(sf::Out out_access_key, KeySource key_source, u32 generation) { + return impl::PrepareCommonEsTitleKey(out_access_key.GetPointer(), key_source, generation); } - Result EsService::ImportDrmKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { - return impl::ImportDrmKey(src.GetPointer(), src.GetSize(), access_key, key_source); + Result EsService::DecryptAndStoreDrmDeviceCertKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { + return impl::DecryptAndStoreDrmDeviceCertKey(src.GetPointer(), src.GetSize(), access_key, key_source); } - Result EsService::DrmExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod) { - return impl::DrmExpMod(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize()); + Result EsService::ModularExponentiateWithDrmDeviceCertKey(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod) { + return impl::ModularExponentiateWithDrmDeviceCertKey(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize()); } - Result EsService::UnwrapElicenseKey(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation) { - return impl::UnwrapElicenseKey(out_access_key.GetPointer(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize(), generation); + Result EsService::PrepareEsArchiveKey(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation) { + return impl::PrepareEsArchiveKey(out_access_key.GetPointer(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize(), generation); } - Result EsService::LoadElicenseKey(s32 keyslot, AccessKey access_key) { - return impl::LoadElicenseKey(keyslot, this, access_key); + Result EsService::LoadPreparedAesKey(s32 keyslot, AccessKey access_key) { + return impl::LoadPreparedAesKey(keyslot, this, access_key); } } diff --git a/stratosphere/spl/source/spl_es_service.hpp b/stratosphere/spl/source/spl_es_service.hpp index abbe0b59b..2c5a375bf 100644 --- a/stratosphere/spl/source/spl_es_service.hpp +++ b/stratosphere/spl/source/spl_es_service.hpp @@ -14,53 +14,22 @@ * along with this program. If not, see . */ #pragma once -#include "spl_rsa_service.hpp" +#include "spl_device_unique_data_service.hpp" namespace ams::spl { - class EsService : public RsaService { + class EsService : public DeviceUniqueDataService { public: - EsService() : RsaService() { /* ... */ } - virtual ~EsService() { /* ... */} - protected: /* Actual commands. */ - virtual Result ImportEsKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); - virtual Result ImportEsKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); - virtual Result UnwrapTitleKey(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation); - virtual Result UnwrapCommonTitleKey(sf::Out out_access_key, KeySource key_source, u32 generation); - virtual Result ImportDrmKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); - virtual Result DrmExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod); - virtual Result UnwrapElicenseKey(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation); - virtual Result LoadElicenseKey(s32 keyslot, AccessKey access_key); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetConfig), - MAKE_SERVICE_COMMAND_META(ExpMod), - MAKE_SERVICE_COMMAND_META(SetConfig), - MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(IsDevelopment), - MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GenerateAesKek), - MAKE_SERVICE_COMMAND_META(LoadAesKey), - MAKE_SERVICE_COMMAND_META(GenerateAesKey), - MAKE_SERVICE_COMMAND_META(DecryptAesKey), - MAKE_SERVICE_COMMAND_META(CryptAesCtr), - MAKE_SERVICE_COMMAND_META(ComputeCmac), - MAKE_SERVICE_COMMAND_META(AllocateAesKeyslot, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(FreeAesKeyslot, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(GetAesKeyslotAvailableEvent, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKeyDeprecated, hos::Version_4_0_0, hos::Version_4_1_0), - MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKey, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(ImportEsKeyDeprecated, hos::Version_4_0_0, hos::Version_4_1_0), - MAKE_SERVICE_COMMAND_META(ImportEsKey, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(UnwrapTitleKey), - MAKE_SERVICE_COMMAND_META(UnwrapCommonTitleKey, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(ImportDrmKey, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(DrmExpMod, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(UnwrapElicenseKey, hos::Version_6_0_0), - MAKE_SERVICE_COMMAND_META(LoadElicenseKey, hos::Version_6_0_0), - }; + Result LoadEsDeviceKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); + Result LoadEsDeviceKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); + Result PrepareEsTitleKey(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation); + Result PrepareCommonEsTitleKey(sf::Out out_access_key, KeySource key_source, u32 generation); + Result DecryptAndStoreDrmDeviceCertKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); + Result ModularExponentiateWithDrmDeviceCertKey(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod); + Result PrepareEsArchiveKey(sf::Out out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation); + Result LoadPreparedAesKey(s32 keyslot, AccessKey access_key); }; + static_assert(spl::impl::IsIEsInterface); } diff --git a/stratosphere/spl/source/spl_fs_service.cpp b/stratosphere/spl/source/spl_fs_service.cpp index 290e4b177..411909c30 100644 --- a/stratosphere/spl/source/spl_fs_service.cpp +++ b/stratosphere/spl/source/spl_fs_service.cpp @@ -19,24 +19,24 @@ namespace ams::spl { - Result FsService::ImportLotusKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { - return impl::ImportLotusKey(src.GetPointer(), src.GetSize(), access_key, key_source, option); + Result FsService::DecryptAndStoreGcKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { + return impl::DecryptAndStoreGcKey(src.GetPointer(), src.GetSize(), access_key, key_source, option); } - Result FsService::ImportLotusKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { - return impl::ImportLotusKey(src.GetPointer(), src.GetSize(), access_key, key_source, static_cast(smc::DecryptOrImportMode::ImportLotusKey)); + Result FsService::DecryptAndStoreGcKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { + return impl::DecryptAndStoreGcKey(src.GetPointer(), src.GetSize(), access_key, key_source, static_cast(smc::DeviceUniqueDataMode::DecryptAndStoreGcKey)); } - Result FsService::DecryptLotusMessage(sf::Out out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest) { - return impl::DecryptLotusMessage(out_size.GetPointer(), out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize()); + Result FsService::DecryptGcMessage(sf::Out out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest) { + return impl::DecryptGcMessage(out_size.GetPointer(), out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize(), label_digest.GetPointer(), label_digest.GetSize()); } Result FsService::GenerateSpecificAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 which) { return impl::GenerateSpecificAesKey(out_key.GetPointer(), key_source, generation, which); } - Result FsService::LoadTitleKey(s32 keyslot, AccessKey access_key) { - return impl::LoadTitleKey(keyslot, this, access_key); + Result FsService::LoadPreparedAesKey(s32 keyslot, AccessKey access_key) { + return impl::LoadPreparedAesKey(keyslot, this, access_key); } Result FsService::GetPackage2Hash(const sf::OutPointerBuffer &dst) { diff --git a/stratosphere/spl/source/spl_fs_service.hpp b/stratosphere/spl/source/spl_fs_service.hpp index eace4735f..a236047a8 100644 --- a/stratosphere/spl/source/spl_fs_service.hpp +++ b/stratosphere/spl/source/spl_fs_service.hpp @@ -20,41 +20,14 @@ namespace ams::spl { class FsService : public CryptoService { public: - FsService() : CryptoService() { /* ... */ } - virtual ~FsService() { /* ... */ } - protected: /* Actual commands. */ - virtual Result ImportLotusKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); - virtual Result ImportLotusKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); - virtual Result DecryptLotusMessage(sf::Out out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest); - virtual Result GenerateSpecificAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 which); - virtual Result LoadTitleKey(s32 keyslot, AccessKey access_key); - virtual Result GetPackage2Hash(const sf::OutPointerBuffer &dst); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetConfig), - MAKE_SERVICE_COMMAND_META(ExpMod), - MAKE_SERVICE_COMMAND_META(SetConfig), - MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(IsDevelopment), - MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GenerateAesKek), - MAKE_SERVICE_COMMAND_META(LoadAesKey), - MAKE_SERVICE_COMMAND_META(GenerateAesKey), - MAKE_SERVICE_COMMAND_META(DecryptAesKey), - MAKE_SERVICE_COMMAND_META(CryptAesCtr), - MAKE_SERVICE_COMMAND_META(ComputeCmac), - MAKE_SERVICE_COMMAND_META(AllocateAesKeyslot, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(FreeAesKeyslot, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(GetAesKeyslotAvailableEvent, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(ImportLotusKeyDeprecated, hos::Version_4_0_0, hos::Version_4_1_0), - MAKE_SERVICE_COMMAND_META(ImportLotusKey, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(DecryptLotusMessage), - MAKE_SERVICE_COMMAND_META(GenerateSpecificAesKey), - MAKE_SERVICE_COMMAND_META(LoadTitleKey), - MAKE_SERVICE_COMMAND_META(GetPackage2Hash, hos::Version_5_0_0), - }; + Result DecryptAndStoreGcKeyDeprecated(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option); + Result DecryptAndStoreGcKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); + Result DecryptGcMessage(sf::Out out_size, const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest); + Result GenerateSpecificAesKey(sf::Out out_key, KeySource key_source, u32 generation, u32 which); + Result LoadPreparedAesKey(s32 keyslot, AccessKey access_key); + Result GetPackage2Hash(const sf::OutPointerBuffer &dst); }; + static_assert(spl::impl::IsIFsInterface); } diff --git a/stratosphere/spl/source/spl_general_service.cpp b/stratosphere/spl/source/spl_general_service.cpp index cb87c37fb..83bbe9419 100644 --- a/stratosphere/spl/source/spl_general_service.cpp +++ b/stratosphere/spl/source/spl_general_service.cpp @@ -20,15 +20,15 @@ namespace ams::spl { Result GeneralService::GetConfig(sf::Out out, u32 which) { - return impl::GetConfig(out.GetPointer(), static_cast(which)); + return impl::GetConfig(out.GetPointer(), static_cast(which)); } - Result GeneralService::ExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod) { - return impl::ExpMod(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), exp.GetPointer(), exp.GetSize(), mod.GetPointer(), mod.GetSize()); + Result GeneralService::ModularExponentiate(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod) { + return impl::ModularExponentiate(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), exp.GetPointer(), exp.GetSize(), mod.GetPointer(), mod.GetSize()); } Result GeneralService::SetConfig(u32 which, u64 value) { - return impl::SetConfig(static_cast(which), value); + return impl::SetConfig(static_cast(which), value); } Result GeneralService::GenerateRandomBytes(const sf::OutPointerBuffer &out) { diff --git a/stratosphere/spl/source/spl_general_service.hpp b/stratosphere/spl/source/spl_general_service.hpp index b8c212a48..7e397f4f8 100644 --- a/stratosphere/spl/source/spl_general_service.hpp +++ b/stratosphere/spl/source/spl_general_service.hpp @@ -18,76 +18,17 @@ namespace ams::spl { - class GeneralService : public sf::IServiceObject { - protected: - enum class CommandId { - /* 1.0.0+ */ - GetConfig = 0, - ExpMod = 1, - GenerateAesKek = 2, - LoadAesKey = 3, - GenerateAesKey = 4, - SetConfig = 5, - GenerateRandomBytes = 7, - ImportLotusKeyDeprecated = 9, - ImportLotusKey = 9, - DecryptLotusMessage = 10, - IsDevelopment = 11, - GenerateSpecificAesKey = 12, - DecryptRsaPrivateKeyDeprecated = 13, - DecryptRsaPrivateKey = 13, - DecryptAesKey = 14, - CryptAesCtr = 15, - ComputeCmac = 16, - ImportEsKeyDeprecated = 17, - ImportEsKey = 17, - UnwrapTitleKey = 18, - LoadTitleKey = 19, - - /* 2.0.0+ */ - UnwrapCommonTitleKey = 20, - AllocateAesKeyslot = 21, - FreeAesKeyslot = 22, - GetAesKeyslotAvailableEvent = 23, - - /* 3.0.0+ */ - SetBootReason = 24, - GetBootReason = 25, - - /* 5.0.0+ */ - ImportSslKey = 26, - SslExpMod = 27, - ImportDrmKey = 28, - DrmExpMod = 29, - ReEncryptRsaPrivateKey = 30, - GetPackage2Hash = 31, - - /* 6.0.0+ */ - UnwrapElicenseKey = 31, /* re-used command id :( */ - LoadElicenseKey = 32, - }; + class GeneralService { public: - GeneralService() { /* ... */ } - virtual ~GeneralService() { /* ... */ } - protected: /* Actual commands. */ - virtual Result GetConfig(sf::Out out, u32 which); - virtual Result ExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod); - virtual Result SetConfig(u32 which, u64 value); - virtual Result GenerateRandomBytes(const sf::OutPointerBuffer &out); - virtual Result IsDevelopment(sf::Out is_dev); - virtual Result SetBootReason(BootReasonValue boot_reason); - virtual Result GetBootReason(sf::Out out); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetConfig), - MAKE_SERVICE_COMMAND_META(ExpMod), - MAKE_SERVICE_COMMAND_META(SetConfig), - MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(IsDevelopment), - MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_3_0_0), - }; + Result GetConfig(sf::Out out, u32 which); + Result ModularExponentiate(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &exp, const sf::InPointerBuffer &mod); + Result SetConfig(u32 which, u64 value); + Result GenerateRandomBytes(const sf::OutPointerBuffer &out); + Result IsDevelopment(sf::Out is_dev); + Result SetBootReason(BootReasonValue boot_reason); + Result GetBootReason(sf::Out out); }; + static_assert(spl::impl::IsIGeneralInterface); } diff --git a/stratosphere/spl/source/spl_main.cpp b/stratosphere/spl/source/spl_main.cpp index 6ffc5a290..5a615d303 100644 --- a/stratosphere/spl/source/spl_main.cpp +++ b/stratosphere/spl/source/spl_main.cpp @@ -138,18 +138,18 @@ int main(int argc, char **argv) spl::impl::Initialize(); /* Create services. */ - R_ABORT_UNLESS(g_server_manager.RegisterServer(RandomServiceName, RandomMaxSessions)); + R_ABORT_UNLESS((g_server_manager.RegisterServer(RandomServiceName, RandomMaxSessions))); if (hos::GetVersion() >= hos::Version_4_0_0) { - R_ABORT_UNLESS(g_server_manager.RegisterServer(GeneralServiceName, GeneralMaxSessions)); - R_ABORT_UNLESS(g_server_manager.RegisterServer(CryptoServiceName, CryptoMaxSessions)); - R_ABORT_UNLESS(g_server_manager.RegisterServer(SslServiceName, SslMaxSessions)); - R_ABORT_UNLESS(g_server_manager.RegisterServer(EsServiceName, EsMaxSessions)); - R_ABORT_UNLESS(g_server_manager.RegisterServer(FsServiceName, FsMaxSessions)); + R_ABORT_UNLESS((g_server_manager.RegisterServer(GeneralServiceName, GeneralMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(CryptoServiceName, CryptoMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(SslServiceName, SslMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(EsServiceName, EsMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(FsServiceName, FsMaxSessions))); if (hos::GetVersion() >= hos::Version_5_0_0) { - R_ABORT_UNLESS(g_server_manager.RegisterServer(ManuServiceName, ManuMaxSessions)); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ManuServiceName, ManuMaxSessions))); } } else { - R_ABORT_UNLESS(g_server_manager.RegisterServer(DeprecatedServiceName, DeprecatedMaxSessions)); + R_ABORT_UNLESS((g_server_manager.RegisterServer(DeprecatedServiceName, DeprecatedMaxSessions))); } /* Loop forever, servicing our services. */ diff --git a/stratosphere/spl/source/spl_manu_service.cpp b/stratosphere/spl/source/spl_manu_service.cpp index 17cc8bcce..4532a0d54 100644 --- a/stratosphere/spl/source/spl_manu_service.cpp +++ b/stratosphere/spl/source/spl_manu_service.cpp @@ -19,8 +19,8 @@ namespace ams::spl { - Result ManuService::ReEncryptRsaPrivateKey(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &src, AccessKey access_key_dec, KeySource source_dec, AccessKey access_key_enc, KeySource source_enc, u32 option) { - return impl::ReEncryptRsaPrivateKey(out.GetPointer(), out.GetSize(), src.GetPointer(), src.GetSize(), access_key_dec, source_dec, access_key_enc, source_enc, option); + Result ManuService::ReencryptDeviceUniqueData(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &src, AccessKey access_key_dec, KeySource source_dec, AccessKey access_key_enc, KeySource source_enc, u32 option) { + return impl::ReencryptDeviceUniqueData(out.GetPointer(), out.GetSize(), src.GetPointer(), src.GetSize(), access_key_dec, source_dec, access_key_enc, source_enc, option); } } diff --git a/stratosphere/spl/source/spl_manu_service.hpp b/stratosphere/spl/source/spl_manu_service.hpp index 9e6342369..30f4b63c3 100644 --- a/stratosphere/spl/source/spl_manu_service.hpp +++ b/stratosphere/spl/source/spl_manu_service.hpp @@ -14,40 +14,15 @@ * along with this program. If not, see . */ #pragma once -#include "spl_rsa_service.hpp" +#include "spl_device_unique_data_service.hpp" namespace ams::spl { - class ManuService : public RsaService { + class ManuService : public DeviceUniqueDataService { public: - ManuService() : RsaService() { /* ... */ } - - virtual ~ManuService() { /* ... */ } - protected: /* Actual commands. */ - virtual Result ReEncryptRsaPrivateKey(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &src, AccessKey access_key_dec, KeySource source_dec, AccessKey access_key_enc, KeySource source_enc, u32 option); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetConfig), - MAKE_SERVICE_COMMAND_META(ExpMod), - MAKE_SERVICE_COMMAND_META(SetConfig), - MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(IsDevelopment), - MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GenerateAesKek), - MAKE_SERVICE_COMMAND_META(LoadAesKey), - MAKE_SERVICE_COMMAND_META(GenerateAesKey), - MAKE_SERVICE_COMMAND_META(DecryptAesKey), - MAKE_SERVICE_COMMAND_META(CryptAesCtr), - MAKE_SERVICE_COMMAND_META(ComputeCmac), - MAKE_SERVICE_COMMAND_META(AllocateAesKeyslot, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(FreeAesKeyslot, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(GetAesKeyslotAvailableEvent, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKeyDeprecated, hos::Version_4_0_0, hos::Version_4_1_0), - MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKey, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(ReEncryptRsaPrivateKey, hos::Version_5_0_0), - }; + Result ReencryptDeviceUniqueData(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &src, AccessKey access_key_dec, KeySource source_dec, AccessKey access_key_enc, KeySource source_enc, u32 option); }; + static_assert(spl::impl::IsIManuInterface); } diff --git a/stratosphere/spl/source/spl_random_service.hpp b/stratosphere/spl/source/spl_random_service.hpp index e6d71c287..fdbba30e8 100644 --- a/stratosphere/spl/source/spl_random_service.hpp +++ b/stratosphere/spl/source/spl_random_service.hpp @@ -18,21 +18,11 @@ namespace ams::spl { - class RandomService final : public sf::IServiceObject { - protected: - enum class CommandId { - GenerateRandomBytes = 0, - }; + class RandomService final { public: - RandomService() { /* ... */ } - virtual ~RandomService() { /* ... */ } - private: /* Actual commands. */ - virtual Result GenerateRandomBytes(const sf::OutBuffer &out); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), - }; + Result GenerateRandomBytes(const sf::OutBuffer &out); }; + static_assert(spl::impl::IsIRandomInterface); } diff --git a/stratosphere/spl/source/spl_rsa_service.cpp b/stratosphere/spl/source/spl_rsa_service.cpp deleted file mode 100644 index c14d01834..000000000 --- a/stratosphere/spl/source/spl_rsa_service.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2018-2020 Atmosphère-NX - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include -#include "spl_api_impl.hpp" -#include "spl_rsa_service.hpp" - -namespace ams::spl { - - Result RsaService::DecryptRsaPrivateKeyDeprecated(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source, u32 option) { - return impl::DecryptRsaPrivateKey(dst.GetPointer(), dst.GetSize(), src.GetPointer(), src.GetSize(), access_key, key_source, option); - } - - Result RsaService::DecryptRsaPrivateKey(const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { - return impl::DecryptRsaPrivateKey(dst.GetPointer(), dst.GetSize(), src.GetPointer(), src.GetSize(), access_key, key_source, static_cast(smc::DecryptOrImportMode::DecryptRsaPrivateKey)); - } - -} diff --git a/stratosphere/spl/source/spl_ssl_service.cpp b/stratosphere/spl/source/spl_ssl_service.cpp index b6c8eeb44..312291119 100644 --- a/stratosphere/spl/source/spl_ssl_service.cpp +++ b/stratosphere/spl/source/spl_ssl_service.cpp @@ -19,12 +19,12 @@ namespace ams::spl { - Result SslService::ImportSslKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { - return impl::ImportSslKey(src.GetPointer(), src.GetSize(), access_key, key_source); + Result SslService::DecryptAndStoreSslClientCertKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source) { + return impl::DecryptAndStoreSslClientCertKey(src.GetPointer(), src.GetSize(), access_key, key_source); } - Result SslService::SslExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod) { - return impl::SslExpMod(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize()); + Result SslService::ModularExponentiateWithSslClientCertKey(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod) { + return impl::ModularExponentiateWithSslClientCertKey(out.GetPointer(), out.GetSize(), base.GetPointer(), base.GetSize(), mod.GetPointer(), mod.GetSize()); } } diff --git a/stratosphere/spl/source/spl_ssl_service.hpp b/stratosphere/spl/source/spl_ssl_service.hpp index ba213b309..c06f38dfb 100644 --- a/stratosphere/spl/source/spl_ssl_service.hpp +++ b/stratosphere/spl/source/spl_ssl_service.hpp @@ -14,42 +14,16 @@ * along with this program. If not, see . */ #pragma once -#include "spl_rsa_service.hpp" +#include "spl_device_unique_data_service.hpp" namespace ams::spl { - class SslService : public RsaService { + class SslService : public DeviceUniqueDataService { public: - SslService() : RsaService() { /* ... */ } - virtual ~SslService() { /* ... */ } - protected: /* Actual commands. */ - virtual Result ImportSslKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); - virtual Result SslExpMod(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(GetConfig), - MAKE_SERVICE_COMMAND_META(ExpMod), - MAKE_SERVICE_COMMAND_META(SetConfig), - MAKE_SERVICE_COMMAND_META(GenerateRandomBytes), - MAKE_SERVICE_COMMAND_META(IsDevelopment), - MAKE_SERVICE_COMMAND_META(SetBootReason, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GetBootReason, hos::Version_3_0_0), - MAKE_SERVICE_COMMAND_META(GenerateAesKek), - MAKE_SERVICE_COMMAND_META(LoadAesKey), - MAKE_SERVICE_COMMAND_META(GenerateAesKey), - MAKE_SERVICE_COMMAND_META(DecryptAesKey), - MAKE_SERVICE_COMMAND_META(CryptAesCtr), - MAKE_SERVICE_COMMAND_META(ComputeCmac), - MAKE_SERVICE_COMMAND_META(AllocateAesKeyslot, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(FreeAesKeyslot, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(GetAesKeyslotAvailableEvent, hos::Version_2_0_0), - MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKeyDeprecated, hos::Version_4_0_0, hos::Version_4_1_0), - MAKE_SERVICE_COMMAND_META(DecryptRsaPrivateKey, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(ImportSslKey, hos::Version_5_0_0), - MAKE_SERVICE_COMMAND_META(SslExpMod, hos::Version_5_0_0), - - }; + Result DecryptAndStoreSslClientCertKey(const sf::InPointerBuffer &src, AccessKey access_key, KeySource key_source); + Result ModularExponentiateWithSslClientCertKey(const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod); }; + static_assert(spl::impl::IsISslInterface); }